blob: 9867afc7895ef44bcba437850300abd648673bee [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020032#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010033
34#define CXT_PIN_DIR_IN 0x00
35#define CXT_PIN_DIR_OUT 0x01
36#define CXT_PIN_DIR_INOUT 0x02
37#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39
40#define CONEXANT_HP_EVENT 0x37
41#define CONEXANT_MIC_EVENT 0x38
42
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010043/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010044
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010045#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046#define CXT5051_PORTB_EVENT 0x38
47#define CXT5051_PORTC_EVENT 0x39
48
Takashi Iwaifaddaa52010-01-23 22:31:36 +010049#define AUTO_MIC_PORTB (1 << 1)
50#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010051
52struct conexant_jack {
53
54 hda_nid_t nid;
55 int type;
56 struct snd_jack *jack;
57
58};
Tobin Davisc9b443d2006-11-14 12:13:39 +010059
Takashi Iwaif2e57312010-09-15 10:07:08 +020060struct pin_dac_pair {
61 hda_nid_t pin;
62 hda_nid_t dac;
63 int type;
64};
65
Tobin Davisc9b443d2006-11-14 12:13:39 +010066struct conexant_spec {
67
68 struct snd_kcontrol_new *mixers[5];
69 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010070 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010071
72 const struct hda_verb *init_verbs[5]; /* initialization verbs
73 * don't forget NULL
74 * termination!
75 */
76 unsigned int num_init_verbs;
77
78 /* playback */
79 struct hda_multi_out multiout; /* playback set-up
80 * max_channels, dacs must be set
81 * dig_out_nid and hp_nid are optional
82 */
83 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010084 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010085 unsigned int auto_mic;
Takashi Iwaif2e57312010-09-15 10:07:08 +020086 int auto_mic_ext; /* autocfg.inputs[] index for ext mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010087 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050088 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010089
90 /* capture */
91 unsigned int num_adc_nids;
92 hda_nid_t *adc_nids;
93 hda_nid_t dig_in_nid; /* digital-in NID; optional */
94
Takashi Iwai461e2c72008-01-25 11:35:17 +010095 unsigned int cur_adc_idx;
96 hda_nid_t cur_adc;
97 unsigned int cur_adc_stream_tag;
98 unsigned int cur_adc_format;
99
Tobin Davisc9b443d2006-11-14 12:13:39 +0100100 /* capture source */
101 const struct hda_input_mux *input_mux;
102 hda_nid_t *capsrc_nids;
103 unsigned int cur_mux[3];
104
105 /* channel model */
106 const struct hda_channel_mode *channel_mode;
107 int num_channel_mode;
108
109 /* PCM information */
110 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
111
Tobin Davisc9b443d2006-11-14 12:13:39 +0100112 unsigned int spdif_route;
113
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100114 /* jack detection */
115 struct snd_array jacks;
116
Tobin Davisc9b443d2006-11-14 12:13:39 +0100117 /* dynamic controls, init_verbs and input_mux */
118 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100119 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200120 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200121 struct pin_dac_pair dac_info[8];
122 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100123
Daniel Drake0fb67e92009-07-16 14:46:57 +0100124 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200125 unsigned int auto_mute:1; /* used in auto-parser */
126 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500127 unsigned int dell_vostro:1;
128 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200129 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200130 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100131 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100132
133 unsigned int ext_mic_present;
134 unsigned int recording;
135 void (*capture_prepare)(struct hda_codec *codec);
136 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100137
138 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
139 * through the microphone jack.
140 * When the user enables this through a mixer switch, both internal and
141 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
142 * we also allow the bias to be configured through a separate mixer
143 * control. */
144 unsigned int dc_enable;
145 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
146 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200147
148 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100149};
150
151static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
152 struct hda_codec *codec,
153 struct snd_pcm_substream *substream)
154{
155 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100156 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
157 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100158}
159
160static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
161 struct hda_codec *codec,
162 unsigned int stream_tag,
163 unsigned int format,
164 struct snd_pcm_substream *substream)
165{
166 struct conexant_spec *spec = codec->spec;
167 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
168 stream_tag,
169 format, substream);
170}
171
172static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec,
174 struct snd_pcm_substream *substream)
175{
176 struct conexant_spec *spec = codec->spec;
177 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
178}
179
180/*
181 * Digital out
182 */
183static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
184 struct hda_codec *codec,
185 struct snd_pcm_substream *substream)
186{
187 struct conexant_spec *spec = codec->spec;
188 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
189}
190
191static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
194{
195 struct conexant_spec *spec = codec->spec;
196 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
197}
198
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200199static int conexant_dig_playback_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;
206 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
207 stream_tag,
208 format, substream);
209}
210
Tobin Davisc9b443d2006-11-14 12:13:39 +0100211/*
212 * Analog capture
213 */
214static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
215 struct hda_codec *codec,
216 unsigned int stream_tag,
217 unsigned int format,
218 struct snd_pcm_substream *substream)
219{
220 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100221 if (spec->capture_prepare)
222 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100223 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
224 stream_tag, 0, format);
225 return 0;
226}
227
228static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
229 struct hda_codec *codec,
230 struct snd_pcm_substream *substream)
231{
232 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100233 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100234 if (spec->capture_cleanup)
235 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100236 return 0;
237}
238
239
240
241static struct hda_pcm_stream conexant_pcm_analog_playback = {
242 .substreams = 1,
243 .channels_min = 2,
244 .channels_max = 2,
245 .nid = 0, /* fill later */
246 .ops = {
247 .open = conexant_playback_pcm_open,
248 .prepare = conexant_playback_pcm_prepare,
249 .cleanup = conexant_playback_pcm_cleanup
250 },
251};
252
253static struct hda_pcm_stream conexant_pcm_analog_capture = {
254 .substreams = 1,
255 .channels_min = 2,
256 .channels_max = 2,
257 .nid = 0, /* fill later */
258 .ops = {
259 .prepare = conexant_capture_pcm_prepare,
260 .cleanup = conexant_capture_pcm_cleanup
261 },
262};
263
264
265static struct hda_pcm_stream conexant_pcm_digital_playback = {
266 .substreams = 1,
267 .channels_min = 2,
268 .channels_max = 2,
269 .nid = 0, /* fill later */
270 .ops = {
271 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200272 .close = conexant_dig_playback_pcm_close,
273 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100274 },
275};
276
277static struct hda_pcm_stream conexant_pcm_digital_capture = {
278 .substreams = 1,
279 .channels_min = 2,
280 .channels_max = 2,
281 /* NID is set in alc_build_pcms */
282};
283
Takashi Iwai461e2c72008-01-25 11:35:17 +0100284static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
285 struct hda_codec *codec,
286 unsigned int stream_tag,
287 unsigned int format,
288 struct snd_pcm_substream *substream)
289{
290 struct conexant_spec *spec = codec->spec;
291 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
292 spec->cur_adc_stream_tag = stream_tag;
293 spec->cur_adc_format = format;
294 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
295 return 0;
296}
297
298static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
299 struct hda_codec *codec,
300 struct snd_pcm_substream *substream)
301{
302 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100303 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100304 spec->cur_adc = 0;
305 return 0;
306}
307
308static struct hda_pcm_stream cx5051_pcm_analog_capture = {
309 .substreams = 1,
310 .channels_min = 2,
311 .channels_max = 2,
312 .nid = 0, /* fill later */
313 .ops = {
314 .prepare = cx5051_capture_pcm_prepare,
315 .cleanup = cx5051_capture_pcm_cleanup
316 },
317};
318
Tobin Davisc9b443d2006-11-14 12:13:39 +0100319static int conexant_build_pcms(struct hda_codec *codec)
320{
321 struct conexant_spec *spec = codec->spec;
322 struct hda_pcm *info = spec->pcm_rec;
323
324 codec->num_pcms = 1;
325 codec->pcm_info = info;
326
327 info->name = "CONEXANT Analog";
328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
330 spec->multiout.max_channels;
331 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
332 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100333 if (codec->vendor_id == 0x14f15051)
334 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
335 cx5051_pcm_analog_capture;
336 else
337 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
338 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100339 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
340 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
341
342 if (spec->multiout.dig_out_nid) {
343 info++;
344 codec->num_pcms++;
345 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100346 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
348 conexant_pcm_digital_playback;
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
350 spec->multiout.dig_out_nid;
351 if (spec->dig_in_nid) {
352 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
353 conexant_pcm_digital_capture;
354 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
355 spec->dig_in_nid;
356 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500357 if (spec->slave_dig_outs[0])
358 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100359 }
360
361 return 0;
362}
363
364static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
365 struct snd_ctl_elem_info *uinfo)
366{
367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368 struct conexant_spec *spec = codec->spec;
369
370 return snd_hda_input_mux_info(spec->input_mux, uinfo);
371}
372
373static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
375{
376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377 struct conexant_spec *spec = codec->spec;
378 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379
380 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
381 return 0;
382}
383
384static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_value *ucontrol)
386{
387 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388 struct conexant_spec *spec = codec->spec;
389 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
390
391 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
392 spec->capsrc_nids[adc_idx],
393 &spec->cur_mux[adc_idx]);
394}
395
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200396#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200397static void conexant_free_jack_priv(struct snd_jack *jack)
398{
399 struct conexant_jack *jacks = jack->private_data;
400 jacks->nid = 0;
401 jacks->jack = NULL;
402}
403
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100404static int conexant_add_jack(struct hda_codec *codec,
405 hda_nid_t nid, int type)
406{
407 struct conexant_spec *spec;
408 struct conexant_jack *jack;
409 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200410 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100411
412 spec = codec->spec;
413 snd_array_init(&spec->jacks, sizeof(*jack), 32);
414 jack = snd_array_new(&spec->jacks);
415 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
416
417 if (!jack)
418 return -ENOMEM;
419
420 jack->nid = nid;
421 jack->type = type;
422
Takashi Iwai95c09092009-04-14 16:15:29 +0200423 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
424 if (err < 0)
425 return err;
426 jack->jack->private_data = jack;
427 jack->jack->private_free = conexant_free_jack_priv;
428 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100429}
430
431static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
432{
433 struct conexant_spec *spec = codec->spec;
434 struct conexant_jack *jacks = spec->jacks.list;
435
436 if (jacks) {
437 int i;
438 for (i = 0; i < spec->jacks.used; i++) {
439 if (jacks->nid == nid) {
440 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100441 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100442
443 present = (present) ? jacks->type : 0 ;
444
445 snd_jack_report(jacks->jack,
446 present);
447 }
448 jacks++;
449 }
450 }
451}
452
453static int conexant_init_jacks(struct hda_codec *codec)
454{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100455 struct conexant_spec *spec = codec->spec;
456 int i;
457
458 for (i = 0; i < spec->num_init_verbs; i++) {
459 const struct hda_verb *hv;
460
461 hv = spec->init_verbs[i];
462 while (hv->nid) {
463 int err = 0;
464 switch (hv->param ^ AC_USRSP_EN) {
465 case CONEXANT_HP_EVENT:
466 err = conexant_add_jack(codec, hv->nid,
467 SND_JACK_HEADPHONE);
468 conexant_report_jack(codec, hv->nid);
469 break;
470 case CXT5051_PORTC_EVENT:
471 case CONEXANT_MIC_EVENT:
472 err = conexant_add_jack(codec, hv->nid,
473 SND_JACK_MICROPHONE);
474 conexant_report_jack(codec, hv->nid);
475 break;
476 }
477 if (err < 0)
478 return err;
479 ++hv;
480 }
481 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100482 return 0;
483
484}
Takashi Iwai5801f992009-01-27 12:53:22 +0100485#else
486static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
487{
488}
489
490static inline int conexant_init_jacks(struct hda_codec *codec)
491{
492 return 0;
493}
494#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100495
Tobin Davisc9b443d2006-11-14 12:13:39 +0100496static int conexant_init(struct hda_codec *codec)
497{
498 struct conexant_spec *spec = codec->spec;
499 int i;
500
501 for (i = 0; i < spec->num_init_verbs; i++)
502 snd_hda_sequence_write(codec, spec->init_verbs[i]);
503 return 0;
504}
505
506static void conexant_free(struct hda_codec *codec)
507{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200508#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100509 struct conexant_spec *spec = codec->spec;
510 if (spec->jacks.list) {
511 struct conexant_jack *jacks = spec->jacks.list;
512 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200513 for (i = 0; i < spec->jacks.used; i++, jacks++) {
514 if (jacks->jack)
515 snd_device_free(codec->bus->card, jacks->jack);
516 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100517 snd_array_free(&spec->jacks);
518 }
519#endif
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200520 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100521 kfree(codec->spec);
522}
523
Takashi Iwaib880c742009-03-10 14:41:05 +0100524static struct snd_kcontrol_new cxt_capture_mixers[] = {
525 {
526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
527 .name = "Capture Source",
528 .info = conexant_mux_enum_info,
529 .get = conexant_mux_enum_get,
530 .put = conexant_mux_enum_put
531 },
532 {}
533};
534
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200535#ifdef CONFIG_SND_HDA_INPUT_BEEP
536/* additional beep mixers; the actual parameters are overwritten at build */
537static struct snd_kcontrol_new cxt_beep_mixer[] = {
538 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
539 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
540 { } /* end */
541};
542#endif
543
Takashi Iwaiea734962011-01-17 11:29:34 +0100544static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100545 "Headphone Playback Volume",
546 "Speaker Playback Volume",
547 NULL
548};
549
Takashi Iwaiea734962011-01-17 11:29:34 +0100550static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100551 "Headphone Playback Switch",
552 "Speaker Playback Switch",
553 NULL
554};
555
Tobin Davisc9b443d2006-11-14 12:13:39 +0100556static int conexant_build_controls(struct hda_codec *codec)
557{
558 struct conexant_spec *spec = codec->spec;
559 unsigned int i;
560 int err;
561
562 for (i = 0; i < spec->num_mixers; i++) {
563 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
564 if (err < 0)
565 return err;
566 }
567 if (spec->multiout.dig_out_nid) {
568 err = snd_hda_create_spdif_out_ctls(codec,
569 spec->multiout.dig_out_nid);
570 if (err < 0)
571 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100572 err = snd_hda_create_spdif_share_sw(codec,
573 &spec->multiout);
574 if (err < 0)
575 return err;
576 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100577 }
578 if (spec->dig_in_nid) {
579 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
580 if (err < 0)
581 return err;
582 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100583
584 /* if we have no master control, let's create it */
585 if (spec->vmaster_nid &&
586 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
587 unsigned int vmaster_tlv[4];
588 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
589 HDA_OUTPUT, vmaster_tlv);
590 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
591 vmaster_tlv, slave_vols);
592 if (err < 0)
593 return err;
594 }
595 if (spec->vmaster_nid &&
596 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
597 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
598 NULL, slave_sws);
599 if (err < 0)
600 return err;
601 }
602
Takashi Iwaib880c742009-03-10 14:41:05 +0100603 if (spec->input_mux) {
604 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
605 if (err < 0)
606 return err;
607 }
608
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200609#ifdef CONFIG_SND_HDA_INPUT_BEEP
610 /* create beep controls if needed */
611 if (spec->beep_amp) {
612 struct snd_kcontrol_new *knew;
613 for (knew = cxt_beep_mixer; knew->name; knew++) {
614 struct snd_kcontrol *kctl;
615 kctl = snd_ctl_new1(knew, codec);
616 if (!kctl)
617 return -ENOMEM;
618 kctl->private_value = spec->beep_amp;
619 err = snd_hda_ctl_add(codec, 0, kctl);
620 if (err < 0)
621 return err;
622 }
623 }
624#endif
625
Tobin Davisc9b443d2006-11-14 12:13:39 +0100626 return 0;
627}
628
Takashi Iwai697c3732010-07-30 11:28:02 +0200629#ifdef CONFIG_SND_HDA_POWER_SAVE
630static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
631{
632 snd_hda_shutup_pins(codec);
633 return 0;
634}
635#endif
636
Tobin Davisc9b443d2006-11-14 12:13:39 +0100637static struct hda_codec_ops conexant_patch_ops = {
638 .build_controls = conexant_build_controls,
639 .build_pcms = conexant_build_pcms,
640 .init = conexant_init,
641 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200642#ifdef CONFIG_SND_HDA_POWER_SAVE
643 .suspend = conexant_suspend,
644#endif
645 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100646};
647
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200648#ifdef CONFIG_SND_HDA_INPUT_BEEP
649#define set_beep_amp(spec, nid, idx, dir) \
650 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
651#else
652#define set_beep_amp(spec, nid, idx, dir) /* NOP */
653#endif
654
Tobin Davisc9b443d2006-11-14 12:13:39 +0100655/*
656 * EAPD control
657 * the private value = nid | (invert << 8)
658 */
659
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200660#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100661
Tobin Davis82f30042007-02-13 12:45:44 +0100662static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100663 struct snd_ctl_elem_value *ucontrol)
664{
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct conexant_spec *spec = codec->spec;
667 int invert = (kcontrol->private_value >> 8) & 1;
668 if (invert)
669 ucontrol->value.integer.value[0] = !spec->cur_eapd;
670 else
671 ucontrol->value.integer.value[0] = spec->cur_eapd;
672 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100673
Tobin Davisc9b443d2006-11-14 12:13:39 +0100674}
675
Tobin Davis82f30042007-02-13 12:45:44 +0100676static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100677 struct snd_ctl_elem_value *ucontrol)
678{
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 struct conexant_spec *spec = codec->spec;
681 int invert = (kcontrol->private_value >> 8) & 1;
682 hda_nid_t nid = kcontrol->private_value & 0xff;
683 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100684
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100685 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100686 if (invert)
687 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200688 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100689 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100690
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200692 snd_hda_codec_write_cache(codec, nid,
693 0, AC_VERB_SET_EAPD_BTLENABLE,
694 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100695 return 1;
696}
697
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100698/* controls for test mode */
699#ifdef CONFIG_SND_DEBUG
700
Tobin Davis82f30042007-02-13 12:45:44 +0100701#define CXT_EAPD_SWITCH(xname, nid, mask) \
702 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
703 .info = cxt_eapd_info, \
704 .get = cxt_eapd_get, \
705 .put = cxt_eapd_put, \
706 .private_value = nid | (mask<<16) }
707
708
709
Tobin Davisc9b443d2006-11-14 12:13:39 +0100710static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_info *uinfo)
712{
713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714 struct conexant_spec *spec = codec->spec;
715 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
716 spec->num_channel_mode);
717}
718
719static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
720 struct snd_ctl_elem_value *ucontrol)
721{
722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
723 struct conexant_spec *spec = codec->spec;
724 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
725 spec->num_channel_mode,
726 spec->multiout.max_channels);
727}
728
729static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_value *ucontrol)
731{
732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
733 struct conexant_spec *spec = codec->spec;
734 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
735 spec->num_channel_mode,
736 &spec->multiout.max_channels);
737 if (err >= 0 && spec->need_dac_fix)
738 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
739 return err;
740}
741
742#define CXT_PIN_MODE(xname, nid, dir) \
743 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
744 .info = conexant_ch_mode_info, \
745 .get = conexant_ch_mode_get, \
746 .put = conexant_ch_mode_put, \
747 .private_value = nid | (dir<<16) }
748
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100749#endif /* CONFIG_SND_DEBUG */
750
Tobin Davisc9b443d2006-11-14 12:13:39 +0100751/* Conexant 5045 specific */
752
753static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
754static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
755static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100756#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100757
Tobin Davis5cd57522006-11-20 17:42:09 +0100758static struct hda_channel_mode cxt5045_modes[1] = {
759 { 2, NULL },
760};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100761
762static struct hda_input_mux cxt5045_capture_source = {
763 .num_items = 2,
764 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100765 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100766 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100767 }
768};
769
Jiang Zhe5218c892008-01-17 11:18:41 +0100770static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200771 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100772 .items = {
773 { "IntMic", 0x1 },
774 { "ExtMic", 0x2 },
775 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200776 { "CD", 0x4 },
777 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100778 }
779};
780
Jiang zhe2de3c232008-03-06 11:09:09 +0100781static struct hda_input_mux cxt5045_capture_source_hp530 = {
782 .num_items = 2,
783 .items = {
784 { "ExtMic", 0x1 },
785 { "IntMic", 0x2 },
786 }
787};
788
Tobin Davisc9b443d2006-11-14 12:13:39 +0100789/* turn on/off EAPD (+ mute HP) as a master switch */
790static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
791 struct snd_ctl_elem_value *ucontrol)
792{
793 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
794 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100795 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796
Tobin Davis82f30042007-02-13 12:45:44 +0100797 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100798 return 0;
799
Tobin Davis82f30042007-02-13 12:45:44 +0100800 /* toggle internal speakers mute depending of presence of
801 * the headphone jack
802 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200803 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
804 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
805 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100806
Takashi Iwai47fd8302007-08-10 17:11:07 +0200807 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
808 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
809 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100810 return 1;
811}
812
813/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200814static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
815 .ops = &snd_hda_bind_vol,
816 .values = {
817 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
818 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
819 0
820 },
821};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100822
Tobin Davis7f296732007-03-12 11:39:01 +0100823/* toggle input of built-in and mic jack appropriately */
824static void cxt5045_hp_automic(struct hda_codec *codec)
825{
826 static struct hda_verb mic_jack_on[] = {
827 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
828 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
829 {}
830 };
831 static struct hda_verb mic_jack_off[] = {
832 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
834 {}
835 };
836 unsigned int present;
837
Takashi Iwaid56757a2009-11-18 08:00:14 +0100838 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100839 if (present)
840 snd_hda_sequence_write(codec, mic_jack_on);
841 else
842 snd_hda_sequence_write(codec, mic_jack_off);
843}
844
Tobin Davisc9b443d2006-11-14 12:13:39 +0100845
846/* mute internal speaker if HP is plugged */
847static void cxt5045_hp_automute(struct hda_codec *codec)
848{
Tobin Davis82f30042007-02-13 12:45:44 +0100849 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100850 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100851
Takashi Iwaid56757a2009-11-18 08:00:14 +0100852 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100853
Takashi Iwai47fd8302007-08-10 17:11:07 +0200854 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
855 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
856 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857}
858
859/* unsolicited event for HP jack sensing */
860static void cxt5045_hp_unsol_event(struct hda_codec *codec,
861 unsigned int res)
862{
863 res >>= 26;
864 switch (res) {
865 case CONEXANT_HP_EVENT:
866 cxt5045_hp_automute(codec);
867 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100868 case CONEXANT_MIC_EVENT:
869 cxt5045_hp_automic(codec);
870 break;
871
Tobin Davisc9b443d2006-11-14 12:13:39 +0100872 }
873}
874
875static struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100876 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
877 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100878 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
879 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200880 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
881 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100882 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
883 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100884 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
885 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200886 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100887 {
888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
889 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100890 .info = cxt_eapd_info,
891 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100892 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100893 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100894 },
895
896 {}
897};
898
Jiang Zhe5218c892008-01-17 11:18:41 +0100899static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200900 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
901 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
902 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
903 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
904
Jiang Zhe5218c892008-01-17 11:18:41 +0100905 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
906 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
907 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
908 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
909
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200910 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
911 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
912
Jiang Zhe5218c892008-01-17 11:18:41 +0100913 {}
914};
915
Jiang zhe2de3c232008-03-06 11:09:09 +0100916static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100917 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
918 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100919 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
920 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100921 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
922 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100923 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
924 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100925 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
926 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100927 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
928 {
929 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
930 .name = "Master Playback Switch",
931 .info = cxt_eapd_info,
932 .get = cxt_eapd_get,
933 .put = cxt5045_hp_master_sw_put,
934 .private_value = 0x10,
935 },
936
937 {}
938};
939
Tobin Davisc9b443d2006-11-14 12:13:39 +0100940static struct hda_verb cxt5045_init_verbs[] = {
941 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200942 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100943 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100944 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200945 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
946 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
947 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
948 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
950 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
951 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
952 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
953 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100954 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100955 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100956 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100957 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
958 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100959 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100961 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100962 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100963 { } /* end */
964};
965
Jiang Zhe5218c892008-01-17 11:18:41 +0100966static struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100967 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100968 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
969 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
970 /* Line In,HP, Amp */
971 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
972 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
973 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
974 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
976 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
977 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
978 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
979 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100980 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100981 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
982 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
983 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
984 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100985 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100986 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
987 /* EAPD */
988 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
989 { } /* end */
990};
Tobin Davis7f296732007-03-12 11:39:01 +0100991
992static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
993 /* pin sensing on HP jack */
994 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200995 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100996};
997
998static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
999 /* pin sensing on HP jack */
1000 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +02001001 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +01001002};
1003
Tobin Davisc9b443d2006-11-14 12:13:39 +01001004#ifdef CONFIG_SND_DEBUG
1005/* Test configuration for debugging, modelled after the ALC260 test
1006 * configuration.
1007 */
1008static struct hda_input_mux cxt5045_test_capture_source = {
1009 .num_items = 5,
1010 .items = {
1011 { "MIXER", 0x0 },
1012 { "MIC1 pin", 0x1 },
1013 { "LINE1 pin", 0x2 },
1014 { "HP-OUT pin", 0x3 },
1015 { "CD pin", 0x4 },
1016 },
1017};
1018
1019static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1020
1021 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001022 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1023 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001024 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1025 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1026 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1027 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001028
1029 /* Modes for retasking pin widgets */
1030 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1031 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1032
Tobin Davis82f30042007-02-13 12:45:44 +01001033 /* EAPD Switch Control */
1034 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1035
Tobin Davisc9b443d2006-11-14 12:13:39 +01001036 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001037
Tobin Davis7f296732007-03-12 11:39:01 +01001038 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1039 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1040 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1041 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1042 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1043 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1044 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1045 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1046 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1047 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001048 {
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 .name = "Input Source",
1051 .info = conexant_mux_enum_info,
1052 .get = conexant_mux_enum_get,
1053 .put = conexant_mux_enum_put,
1054 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001055 /* Audio input controls */
1056 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1057 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1058 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1059 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1060 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1061 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1062 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1063 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1064 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1065 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001066 { } /* end */
1067};
1068
1069static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001070 /* Set connections */
1071 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1072 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1073 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001074 /* Enable retasking pins as output, initially without power amp */
1075 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001076 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001077
1078 /* Disable digital (SPDIF) pins initially, but users can enable
1079 * them via a mixer switch. In the case of SPDIF-out, this initverb
1080 * payload also sets the generation to 0, output to be in "consumer"
1081 * PCM format, copyright asserted, no pre-emphasis and no validity
1082 * control.
1083 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001084 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1085 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086
1087 /* Start with output sum widgets muted and their output gains at min */
1088 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1089 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1090
1091 /* Unmute retasking pin widget output buffers since the default
1092 * state appears to be output. As the pin mode is changed by the
1093 * user the pin mode control will take care of enabling the pin's
1094 * input/output buffers as needed.
1095 */
1096 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1097 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1098
1099 /* Mute capture amp left and right */
1100 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1101
1102 /* Set ADC connection select to match default mixer setting (mic1
1103 * pin)
1104 */
1105 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001106 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001107
1108 /* Mute all inputs to mixer widget (even unconnected ones) */
1109 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1110 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1111 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1112 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1113 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1114
1115 { }
1116};
1117#endif
1118
1119
1120/* initialize jack-sensing, too */
1121static int cxt5045_init(struct hda_codec *codec)
1122{
1123 conexant_init(codec);
1124 cxt5045_hp_automute(codec);
1125 return 0;
1126}
1127
1128
1129enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001130 CXT5045_LAPTOP_HPSENSE,
1131 CXT5045_LAPTOP_MICSENSE,
1132 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001133 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001134 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135#ifdef CONFIG_SND_DEBUG
1136 CXT5045_TEST,
1137#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001138 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001139};
1140
Takashi Iwaiea734962011-01-17 11:29:34 +01001141static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001142 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1143 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1144 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1145 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001146 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001147#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001148 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001149#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001150};
1151
1152static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001153 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001154 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1155 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001156 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001157 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001158 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1159 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001160 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1161 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001162 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1163 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1164 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001165 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1166 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001167 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001168 {}
1169};
1170
1171static int patch_cxt5045(struct hda_codec *codec)
1172{
1173 struct conexant_spec *spec;
1174 int board_config;
1175
1176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1177 if (!spec)
1178 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001179 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001180 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181
1182 spec->multiout.max_channels = 2;
1183 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1184 spec->multiout.dac_nids = cxt5045_dac_nids;
1185 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1186 spec->num_adc_nids = 1;
1187 spec->adc_nids = cxt5045_adc_nids;
1188 spec->capsrc_nids = cxt5045_capsrc_nids;
1189 spec->input_mux = &cxt5045_capture_source;
1190 spec->num_mixers = 1;
1191 spec->mixers[0] = cxt5045_mixers;
1192 spec->num_init_verbs = 1;
1193 spec->init_verbs[0] = cxt5045_init_verbs;
1194 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001195 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1196 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001197
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001198 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001199
1200 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001202 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1203 cxt5045_models,
1204 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001206 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001207 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001208 spec->input_mux = &cxt5045_capture_source;
1209 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001210 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1211 spec->mixers[0] = cxt5045_mixers;
1212 codec->patch_ops.init = cxt5045_init;
1213 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001214 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001215 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001216 spec->input_mux = &cxt5045_capture_source;
1217 spec->num_init_verbs = 2;
1218 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001219 spec->mixers[0] = cxt5045_mixers;
1220 codec->patch_ops.init = cxt5045_init;
1221 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001222 default:
1223 case CXT5045_LAPTOP_HPMICSENSE:
1224 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1225 spec->input_mux = &cxt5045_capture_source;
1226 spec->num_init_verbs = 3;
1227 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1228 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1229 spec->mixers[0] = cxt5045_mixers;
1230 codec->patch_ops.init = cxt5045_init;
1231 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001232 case CXT5045_BENQ:
1233 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1234 spec->input_mux = &cxt5045_capture_source_benq;
1235 spec->num_init_verbs = 1;
1236 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1237 spec->mixers[0] = cxt5045_mixers;
1238 spec->mixers[1] = cxt5045_benq_mixers;
1239 spec->num_mixers = 2;
1240 codec->patch_ops.init = cxt5045_init;
1241 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001242 case CXT5045_LAPTOP_HP530:
1243 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1244 spec->input_mux = &cxt5045_capture_source_hp530;
1245 spec->num_init_verbs = 2;
1246 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1247 spec->mixers[0] = cxt5045_mixers_hp530;
1248 codec->patch_ops.init = cxt5045_init;
1249 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001250#ifdef CONFIG_SND_DEBUG
1251 case CXT5045_TEST:
1252 spec->input_mux = &cxt5045_test_capture_source;
1253 spec->mixers[0] = cxt5045_test_mixer;
1254 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001255 break;
1256
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257#endif
1258 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001259
Takashi Iwai031005f2008-06-26 14:49:58 +02001260 switch (codec->subsystem_id >> 16) {
1261 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001262 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001263 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001264 case 0x17aa:
1265 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1266 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1267 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001268 */
1269 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1270 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1271 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1272 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1273 (1 << AC_AMPCAP_MUTE_SHIFT));
1274 break;
1275 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001276
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001277 if (spec->beep_amp)
1278 snd_hda_attach_beep_device(codec, spec->beep_amp);
1279
Tobin Davisc9b443d2006-11-14 12:13:39 +01001280 return 0;
1281}
1282
1283
1284/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001285#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001287static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001288static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1289static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001290
Tobin Davis5cd57522006-11-20 17:42:09 +01001291static struct hda_channel_mode cxt5047_modes[1] = {
1292 { 2, NULL },
1293};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001294
Tobin Davis82f30042007-02-13 12:45:44 +01001295static struct hda_input_mux cxt5047_toshiba_capture_source = {
1296 .num_items = 2,
1297 .items = {
1298 { "ExtMic", 0x2 },
1299 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 }
1301};
1302
1303/* turn on/off EAPD (+ mute HP) as a master switch */
1304static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1305 struct snd_ctl_elem_value *ucontrol)
1306{
1307 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1308 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001309 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001310
Tobin Davis82f30042007-02-13 12:45:44 +01001311 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001312 return 0;
1313
Tobin Davis82f30042007-02-13 12:45:44 +01001314 /* toggle internal speakers mute depending of presence of
1315 * the headphone jack
1316 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001317 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001318 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1319 * pin widgets unlike other codecs. In this case, we need to
1320 * set index 0x01 for the volume from the mixer amp 0x19.
1321 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001322 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001323 HDA_AMP_MUTE, bits);
1324 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1325 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1326 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327 return 1;
1328}
1329
Tobin Davisc9b443d2006-11-14 12:13:39 +01001330/* mute internal speaker if HP is plugged */
1331static void cxt5047_hp_automute(struct hda_codec *codec)
1332{
Tobin Davis82f30042007-02-13 12:45:44 +01001333 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001334 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001335
Takashi Iwaid56757a2009-11-18 08:00:14 +01001336 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001337
Takashi Iwai47fd8302007-08-10 17:11:07 +02001338 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001339 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001340 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001341 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342}
1343
1344/* toggle input of built-in and mic jack appropriately */
1345static void cxt5047_hp_automic(struct hda_codec *codec)
1346{
1347 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001348 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1349 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001350 {}
1351 };
1352 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001353 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1354 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001355 {}
1356 };
1357 unsigned int present;
1358
Takashi Iwaid56757a2009-11-18 08:00:14 +01001359 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001360 if (present)
1361 snd_hda_sequence_write(codec, mic_jack_on);
1362 else
1363 snd_hda_sequence_write(codec, mic_jack_off);
1364}
1365
1366/* unsolicited event for HP jack sensing */
1367static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1368 unsigned int res)
1369{
Marc Boucher9f113e02008-01-22 15:18:08 +01001370 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001371 case CONEXANT_HP_EVENT:
1372 cxt5047_hp_automute(codec);
1373 break;
1374 case CONEXANT_MIC_EVENT:
1375 cxt5047_hp_automic(codec);
1376 break;
1377 }
1378}
1379
Takashi Iwaidf481e42009-03-10 15:35:35 +01001380static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1381 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1382 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001383 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001384 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1385 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1386 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1387 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001388 {
1389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1390 .name = "Master Playback Switch",
1391 .info = cxt_eapd_info,
1392 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393 .put = cxt5047_hp_master_sw_put,
1394 .private_value = 0x13,
1395 },
1396
1397 {}
1398};
1399
Takashi Iwaidf481e42009-03-10 15:35:35 +01001400static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001401 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001402 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001403 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1404 {}
1405};
1406
1407static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001408 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001409 { } /* end */
1410};
1411
1412static struct hda_verb cxt5047_init_verbs[] = {
1413 /* Line in, Mic, Built-in Mic */
1414 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1415 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1416 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001417 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001418 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001419 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1420 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001421 /* Record selector: Mic */
1422 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1423 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1424 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1425 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001426 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1427 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1428 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1429 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001430 /* SPDIF route: PCM */
1431 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001432 /* Enable unsolicited events */
1433 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1434 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001435 { } /* end */
1436};
1437
1438/* configuration for Toshiba Laptops */
1439static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001440 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001441 {}
1442};
1443
1444/* Test configuration for debugging, modelled after the ALC260 test
1445 * configuration.
1446 */
1447#ifdef CONFIG_SND_DEBUG
1448static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001449 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001450 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001451 { "LINE1 pin", 0x0 },
1452 { "MIC1 pin", 0x1 },
1453 { "MIC2 pin", 0x2 },
1454 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001455 },
1456};
1457
1458static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1459
1460 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001461 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1462 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1463 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1464 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001465 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1466 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1467 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1468 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001469 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1470 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1471 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1472 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001473
1474 /* Modes for retasking pin widgets */
1475 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1476 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1477
Tobin Davis82f30042007-02-13 12:45:44 +01001478 /* EAPD Switch Control */
1479 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1480
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001482 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1483 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1484 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1485 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1486 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1487 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1488 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1489 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001490
Tobin Davis82f30042007-02-13 12:45:44 +01001491 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1492 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1493 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1494 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1495 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1496 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1497 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1498 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001499 {
1500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1501 .name = "Input Source",
1502 .info = conexant_mux_enum_info,
1503 .get = conexant_mux_enum_get,
1504 .put = conexant_mux_enum_put,
1505 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001506 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001507
Tobin Davisc9b443d2006-11-14 12:13:39 +01001508 { } /* end */
1509};
1510
1511static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001512 /* Enable retasking pins as output, initially without power amp */
1513 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1514 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1515 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1516
1517 /* Disable digital (SPDIF) pins initially, but users can enable
1518 * them via a mixer switch. In the case of SPDIF-out, this initverb
1519 * payload also sets the generation to 0, output to be in "consumer"
1520 * PCM format, copyright asserted, no pre-emphasis and no validity
1521 * control.
1522 */
1523 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1524
1525 /* Ensure mic1, mic2, line1 pin widgets take input from the
1526 * OUT1 sum bus when acting as an output.
1527 */
1528 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1529 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1530
1531 /* Start with output sum widgets muted and their output gains at min */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1534
1535 /* Unmute retasking pin widget output buffers since the default
1536 * state appears to be output. As the pin mode is changed by the
1537 * user the pin mode control will take care of enabling the pin's
1538 * input/output buffers as needed.
1539 */
1540 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1541 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1542 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1543
1544 /* Mute capture amp left and right */
1545 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1546
1547 /* Set ADC connection select to match default mixer setting (mic1
1548 * pin)
1549 */
1550 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1551
1552 /* Mute all inputs to mixer widget (even unconnected ones) */
1553 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1554 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1555 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1556 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1557 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1558 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1559 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1560 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1561
1562 { }
1563};
1564#endif
1565
1566
1567/* initialize jack-sensing, too */
1568static int cxt5047_hp_init(struct hda_codec *codec)
1569{
1570 conexant_init(codec);
1571 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001572 return 0;
1573}
1574
1575
1576enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001577 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1578 CXT5047_LAPTOP_HP, /* Some HP laptops */
1579 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580#ifdef CONFIG_SND_DEBUG
1581 CXT5047_TEST,
1582#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001583 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001584};
1585
Takashi Iwaiea734962011-01-17 11:29:34 +01001586static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001587 [CXT5047_LAPTOP] = "laptop",
1588 [CXT5047_LAPTOP_HP] = "laptop-hp",
1589 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001590#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001591 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001593};
1594
1595static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001596 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001597 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1598 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001599 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001600 {}
1601};
1602
1603static int patch_cxt5047(struct hda_codec *codec)
1604{
1605 struct conexant_spec *spec;
1606 int board_config;
1607
1608 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1609 if (!spec)
1610 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001611 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001612 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001613
1614 spec->multiout.max_channels = 2;
1615 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1616 spec->multiout.dac_nids = cxt5047_dac_nids;
1617 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1618 spec->num_adc_nids = 1;
1619 spec->adc_nids = cxt5047_adc_nids;
1620 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001621 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001622 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001623 spec->num_init_verbs = 1;
1624 spec->init_verbs[0] = cxt5047_init_verbs;
1625 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001626 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1627 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001628
1629 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001630
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001631 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1632 cxt5047_models,
1633 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001634 switch (board_config) {
1635 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001636 spec->num_mixers = 2;
1637 spec->mixers[1] = cxt5047_hp_spk_mixers;
1638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001639 break;
1640 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001641 spec->num_mixers = 2;
1642 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001643 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001644 codec->patch_ops.init = cxt5047_hp_init;
1645 break;
1646 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001647 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001648 spec->num_mixers = 2;
1649 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001650 spec->num_init_verbs = 2;
1651 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001652 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001653 break;
1654#ifdef CONFIG_SND_DEBUG
1655 case CXT5047_TEST:
1656 spec->input_mux = &cxt5047_test_capture_source;
1657 spec->mixers[0] = cxt5047_test_mixer;
1658 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001659 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001660#endif
1661 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001662 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001663
1664 switch (codec->subsystem_id >> 16) {
1665 case 0x103c:
1666 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1667 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1668 * with 0 dB offset 0x17)
1669 */
1670 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1671 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1672 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1673 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1674 (1 << AC_AMPCAP_MUTE_SHIFT));
1675 break;
1676 }
1677
Tobin Davisc9b443d2006-11-14 12:13:39 +01001678 return 0;
1679}
1680
Takashi Iwai461e2c72008-01-25 11:35:17 +01001681/* Conexant 5051 specific */
1682static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1683static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001684
1685static struct hda_channel_mode cxt5051_modes[1] = {
1686 { 2, NULL },
1687};
1688
1689static void cxt5051_update_speaker(struct hda_codec *codec)
1690{
1691 struct conexant_spec *spec = codec->spec;
1692 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001693 /* headphone pin */
1694 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1695 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1696 pinctl);
1697 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001698 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1699 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1700 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001701 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1702 if (spec->ideapad)
1703 snd_hda_codec_write(codec, 0x1b, 0,
1704 AC_VERB_SET_PIN_WIDGET_CONTROL,
1705 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001706}
1707
1708/* turn on/off EAPD (+ mute HP) as a master switch */
1709static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1710 struct snd_ctl_elem_value *ucontrol)
1711{
1712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1713
1714 if (!cxt_eapd_put(kcontrol, ucontrol))
1715 return 0;
1716 cxt5051_update_speaker(codec);
1717 return 1;
1718}
1719
1720/* toggle input of built-in and mic jack appropriately */
1721static void cxt5051_portb_automic(struct hda_codec *codec)
1722{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001723 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001724 unsigned int present;
1725
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001726 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001727 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001728 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001729 snd_hda_codec_write(codec, 0x14, 0,
1730 AC_VERB_SET_CONNECT_SEL,
1731 present ? 0x01 : 0x00);
1732}
1733
1734/* switch the current ADC according to the jack state */
1735static void cxt5051_portc_automic(struct hda_codec *codec)
1736{
1737 struct conexant_spec *spec = codec->spec;
1738 unsigned int present;
1739 hda_nid_t new_adc;
1740
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001741 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001742 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001743 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001744 if (present)
1745 spec->cur_adc_idx = 1;
1746 else
1747 spec->cur_adc_idx = 0;
1748 new_adc = spec->adc_nids[spec->cur_adc_idx];
1749 if (spec->cur_adc && spec->cur_adc != new_adc) {
1750 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001751 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001752 spec->cur_adc = new_adc;
1753 snd_hda_codec_setup_stream(codec, new_adc,
1754 spec->cur_adc_stream_tag, 0,
1755 spec->cur_adc_format);
1756 }
1757}
1758
1759/* mute internal speaker if HP is plugged */
1760static void cxt5051_hp_automute(struct hda_codec *codec)
1761{
1762 struct conexant_spec *spec = codec->spec;
1763
Takashi Iwaid56757a2009-11-18 08:00:14 +01001764 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001765 cxt5051_update_speaker(codec);
1766}
1767
1768/* unsolicited event for HP jack sensing */
1769static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1770 unsigned int res)
1771{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001772 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001773 switch (res >> 26) {
1774 case CONEXANT_HP_EVENT:
1775 cxt5051_hp_automute(codec);
1776 break;
1777 case CXT5051_PORTB_EVENT:
1778 cxt5051_portb_automic(codec);
1779 break;
1780 case CXT5051_PORTC_EVENT:
1781 cxt5051_portc_automic(codec);
1782 break;
1783 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001784 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001785}
1786
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001787static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001788 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1789 {
1790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1791 .name = "Master Playback Switch",
1792 .info = cxt_eapd_info,
1793 .get = cxt_eapd_get,
1794 .put = cxt5051_hp_master_sw_put,
1795 .private_value = 0x1a,
1796 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001797 {}
1798};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001799
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001800static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1801 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1802 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001803 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1804 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001805 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1806 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001807 {}
1808};
1809
1810static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1811 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1812 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001813 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1814 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001815 {}
1816};
1817
Takashi Iwai79d7d532009-03-04 09:03:50 +01001818static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001819 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1820 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001821 {}
1822};
1823
Ken Proxcd9d95a2010-01-08 09:01:47 +01001824static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001825 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1826 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001827 {}
1828};
1829
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001830static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1831 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1832 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001833 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1834 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001835 {}
1836};
1837
Takashi Iwai461e2c72008-01-25 11:35:17 +01001838static struct hda_verb cxt5051_init_verbs[] = {
1839 /* Line in, Mic */
1840 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1841 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1842 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1843 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1844 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1845 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1846 /* SPK */
1847 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1849 /* HP, Amp */
1850 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1851 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1852 /* DAC1 */
1853 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001854 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1857 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1858 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001859 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001860 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1861 /* EAPD */
1862 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1863 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001864 { } /* end */
1865};
1866
Takashi Iwai79d7d532009-03-04 09:03:50 +01001867static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1868 /* Line in, Mic */
1869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1870 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1871 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1872 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1873 /* SPK */
1874 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1875 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1876 /* HP, Amp */
1877 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1878 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1879 /* DAC1 */
1880 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001881 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001882 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1883 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1884 /* SPDIF route: PCM */
1885 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1886 /* EAPD */
1887 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1888 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001889 { } /* end */
1890};
1891
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001892static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1893 /* Line in, Mic */
1894 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1895 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1896 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1897 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1898 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1899 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1900 /* SPK */
1901 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1902 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1903 /* HP, Amp */
1904 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1905 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1906 /* Docking HP */
1907 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1908 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1909 /* DAC1 */
1910 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001911 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001912 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1914 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1915 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001916 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001917 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1918 /* EAPD */
1919 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1920 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001921 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1922 { } /* end */
1923};
1924
Ken Proxcd9d95a2010-01-08 09:01:47 +01001925static struct hda_verb cxt5051_f700_init_verbs[] = {
1926 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001927 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001928 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1929 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1930 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1931 /* SPK */
1932 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1933 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1934 /* HP, Amp */
1935 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1936 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1937 /* DAC1 */
1938 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001939 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001940 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1941 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1942 /* SPDIF route: PCM */
1943 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1944 /* EAPD */
1945 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1946 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001947 { } /* end */
1948};
1949
Takashi Iwai6953e552010-01-24 11:00:27 +01001950static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1951 unsigned int event)
1952{
1953 snd_hda_codec_write(codec, nid, 0,
1954 AC_VERB_SET_UNSOLICITED_ENABLE,
1955 AC_USRSP_EN | event);
1956#ifdef CONFIG_SND_HDA_INPUT_JACK
1957 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1958 conexant_report_jack(codec, nid);
1959#endif
1960}
1961
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001962static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1963 /* Subwoofer */
1964 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1965 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1966 { } /* end */
1967};
1968
Takashi Iwai461e2c72008-01-25 11:35:17 +01001969/* initialize jack-sensing, too */
1970static int cxt5051_init(struct hda_codec *codec)
1971{
Takashi Iwai6953e552010-01-24 11:00:27 +01001972 struct conexant_spec *spec = codec->spec;
1973
Takashi Iwai461e2c72008-01-25 11:35:17 +01001974 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001975 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001976
1977 if (spec->auto_mic & AUTO_MIC_PORTB)
1978 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1979 if (spec->auto_mic & AUTO_MIC_PORTC)
1980 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1981
Takashi Iwai461e2c72008-01-25 11:35:17 +01001982 if (codec->patch_ops.unsol_event) {
1983 cxt5051_hp_automute(codec);
1984 cxt5051_portb_automic(codec);
1985 cxt5051_portc_automic(codec);
1986 }
1987 return 0;
1988}
1989
1990
1991enum {
1992 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1993 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001994 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001995 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001996 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001997 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001998 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001999 CXT5051_MODELS
2000};
2001
Takashi Iwaiea734962011-01-17 11:29:34 +01002002static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01002003 [CXT5051_LAPTOP] = "laptop",
2004 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01002005 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002006 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002007 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002008 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002009 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai461e2c72008-01-25 11:35:17 +01002010};
2011
2012static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01002013 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01002014 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002015 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002016 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002017 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2018 CXT5051_LAPTOP),
2019 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002020 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002021 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002022 {}
2023};
2024
2025static int patch_cxt5051(struct hda_codec *codec)
2026{
2027 struct conexant_spec *spec;
2028 int board_config;
2029
2030 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2031 if (!spec)
2032 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002033 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002034 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002035
2036 codec->patch_ops = conexant_patch_ops;
2037 codec->patch_ops.init = cxt5051_init;
2038
2039 spec->multiout.max_channels = 2;
2040 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2041 spec->multiout.dac_nids = cxt5051_dac_nids;
2042 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2043 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2044 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002045 spec->num_mixers = 2;
2046 spec->mixers[0] = cxt5051_capture_mixers;
2047 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002048 spec->num_init_verbs = 1;
2049 spec->init_verbs[0] = cxt5051_init_verbs;
2050 spec->spdif_route = 0;
2051 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2052 spec->channel_mode = cxt5051_modes;
2053 spec->cur_adc = 0;
2054 spec->cur_adc_idx = 0;
2055
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002056 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2057
Takashi Iwai79d7d532009-03-04 09:03:50 +01002058 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2059
Takashi Iwai461e2c72008-01-25 11:35:17 +01002060 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2061 cxt5051_models,
2062 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002063 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002064 switch (board_config) {
2065 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002066 spec->mixers[0] = cxt5051_hp_mixers;
2067 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002068 case CXT5051_HP_DV6736:
2069 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2070 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002071 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002072 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002073 case CXT5051_LENOVO_X200:
2074 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002075 /* Thinkpad X301 does not have S/PDIF wired and no ability
2076 to use a docking station. */
2077 if (codec->subsystem_id == 0x17aa211f)
2078 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002079 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002080 case CXT5051_F700:
2081 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2082 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002083 spec->auto_mic = 0;
2084 break;
2085 case CXT5051_TOSHIBA:
2086 spec->mixers[0] = cxt5051_toshiba_mixers;
2087 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002088 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002089 case CXT5051_IDEAPAD:
2090 spec->init_verbs[spec->num_init_verbs++] =
2091 cxt5051_ideapad_init_verbs;
2092 spec->ideapad = 1;
2093 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002094 }
2095
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002096 if (spec->beep_amp)
2097 snd_hda_attach_beep_device(codec, spec->beep_amp);
2098
Takashi Iwai461e2c72008-01-25 11:35:17 +01002099 return 0;
2100}
2101
Daniel Drake0fb67e92009-07-16 14:46:57 +01002102/* Conexant 5066 specific */
2103
2104static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2105static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2106static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
Andy Robinsonf6a24912011-01-24 10:12:37 -05002107static hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002108
Daniel Drakedbaccc02009-11-09 15:17:24 +00002109/* OLPC's microphone port is DC coupled for use with external sensors,
2110 * therefore we use a 50% mic bias in order to center the input signal with
2111 * the DC input range of the codec. */
2112#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2113
Daniel Drake0fb67e92009-07-16 14:46:57 +01002114static struct hda_channel_mode cxt5066_modes[1] = {
2115 { 2, NULL },
2116};
2117
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002118#define HP_PRESENT_PORT_A (1 << 0)
2119#define HP_PRESENT_PORT_D (1 << 1)
2120#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2121#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2122
Daniel Drake0fb67e92009-07-16 14:46:57 +01002123static void cxt5066_update_speaker(struct hda_codec *codec)
2124{
2125 struct conexant_spec *spec = codec->spec;
2126 unsigned int pinctl;
2127
John Baboval3a253442010-12-02 11:21:31 -05002128 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2129 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002130
2131 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002132 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002133 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2134 pinctl);
2135
2136 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002137 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2138 if (spec->dell_automute || spec->thinkpad) {
2139 /* Mute if Port A is connected */
2140 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002141 pinctl = 0;
2142 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002143 /* Thinkpad/Dell doesn't give pin-D status */
2144 if (!hp_port_d_present(spec))
2145 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002146 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002147 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2148 pinctl);
2149
2150 /* CLASS_D AMP */
2151 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2152 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2153 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002154}
2155
2156/* turn on/off EAPD (+ mute HP) as a master switch */
2157static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2158 struct snd_ctl_elem_value *ucontrol)
2159{
2160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2161
2162 if (!cxt_eapd_put(kcontrol, ucontrol))
2163 return 0;
2164
2165 cxt5066_update_speaker(codec);
2166 return 1;
2167}
2168
Daniel Drakec4cfe662010-01-07 13:47:04 +01002169static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2170 .num_items = 3,
2171 .items = {
2172 { "Off", PIN_IN },
2173 { "50%", PIN_VREF50 },
2174 { "80%", PIN_VREF80 },
2175 },
2176};
2177
2178static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2179{
2180 struct conexant_spec *spec = codec->spec;
2181 /* Even though port F is the DC input, the bias is controlled on port B.
2182 * we also leave that port as an active input (but unselected) in DC mode
2183 * just in case that is necessary to make the bias setting take effect. */
2184 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2185 AC_VERB_SET_PIN_WIDGET_CONTROL,
2186 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2187}
2188
Daniel Drake75f89912010-01-07 13:46:25 +01002189/* OLPC defers mic widget control until when capture is started because the
2190 * microphone LED comes on as soon as these settings are put in place. if we
2191 * did this before recording, it would give the false indication that recording
2192 * is happening when it is not. */
2193static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002194{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002195 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002196 if (!spec->recording)
2197 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002198
Daniel Drakec4cfe662010-01-07 13:47:04 +01002199 if (spec->dc_enable) {
2200 /* in DC mode we ignore presence detection and just use the jack
2201 * through our special DC port */
2202 const struct hda_verb enable_dc_mode[] = {
2203 /* disble internal mic, port C */
2204 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2205
2206 /* enable DC capture, port F */
2207 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2208 {},
2209 };
2210
2211 snd_hda_sequence_write(codec, enable_dc_mode);
2212 /* port B input disabled (and bias set) through the following call */
2213 cxt5066_set_olpc_dc_bias(codec);
2214 return;
2215 }
2216
2217 /* disable DC (port F) */
2218 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2219
Daniel Drake75f89912010-01-07 13:46:25 +01002220 /* external mic, port B */
2221 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2222 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002223
Daniel Drake75f89912010-01-07 13:46:25 +01002224 /* internal mic, port C */
2225 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2226 spec->ext_mic_present ? 0 : PIN_VREF80);
2227}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002228
Daniel Drake75f89912010-01-07 13:46:25 +01002229/* toggle input of built-in and mic jack appropriately */
2230static void cxt5066_olpc_automic(struct hda_codec *codec)
2231{
2232 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002233 unsigned int present;
2234
Daniel Drakec4cfe662010-01-07 13:47:04 +01002235 if (spec->dc_enable) /* don't do presence detection in DC mode */
2236 return;
2237
Daniel Drake75f89912010-01-07 13:46:25 +01002238 present = snd_hda_codec_read(codec, 0x1a, 0,
2239 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2240 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002241 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002242 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002243 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002244
2245 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2246 present ? 0 : 1);
2247 spec->ext_mic_present = !!present;
2248
2249 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002250}
2251
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002252/* toggle input of built-in digital mic and mic jack appropriately */
2253static void cxt5066_vostro_automic(struct hda_codec *codec)
2254{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002255 unsigned int present;
2256
2257 struct hda_verb ext_mic_present[] = {
2258 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002259 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002260
2261 /* switch to external mic input */
2262 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2263 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2264
2265 /* disable internal digital mic */
2266 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2267 {}
2268 };
2269 static struct hda_verb ext_mic_absent[] = {
2270 /* enable internal mic, port C */
2271 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272
2273 /* switch to internal mic input */
2274 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2275
2276 /* disable external mic, port B */
2277 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2278 {}
2279 };
2280
2281 present = snd_hda_jack_detect(codec, 0x1a);
2282 if (present) {
2283 snd_printdd("CXT5066: external microphone detected\n");
2284 snd_hda_sequence_write(codec, ext_mic_present);
2285 } else {
2286 snd_printdd("CXT5066: external microphone absent\n");
2287 snd_hda_sequence_write(codec, ext_mic_absent);
2288 }
2289}
2290
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002291/* toggle input of built-in digital mic and mic jack appropriately */
2292static void cxt5066_ideapad_automic(struct hda_codec *codec)
2293{
2294 unsigned int present;
2295
2296 struct hda_verb ext_mic_present[] = {
2297 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2298 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2299 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2300 {}
2301 };
2302 static struct hda_verb ext_mic_absent[] = {
2303 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2304 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2305 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306 {}
2307 };
2308
2309 present = snd_hda_jack_detect(codec, 0x1b);
2310 if (present) {
2311 snd_printdd("CXT5066: external microphone detected\n");
2312 snd_hda_sequence_write(codec, ext_mic_present);
2313 } else {
2314 snd_printdd("CXT5066: external microphone absent\n");
2315 snd_hda_sequence_write(codec, ext_mic_absent);
2316 }
2317}
2318
David Henningssona1d69062011-01-21 13:33:28 +01002319
2320/* toggle input of built-in digital mic and mic jack appropriately */
2321static void cxt5066_asus_automic(struct hda_codec *codec)
2322{
2323 unsigned int present;
2324
2325 present = snd_hda_jack_detect(codec, 0x1b);
2326 snd_printdd("CXT5066: external microphone present=%d\n", present);
2327 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2328 present ? 1 : 0);
2329}
2330
2331
David Henningsson048e78a2010-09-02 08:35:47 +02002332/* toggle input of built-in digital mic and mic jack appropriately */
2333static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2334{
2335 unsigned int present;
2336
2337 present = snd_hda_jack_detect(codec, 0x1b);
2338 snd_printdd("CXT5066: external microphone present=%d\n", present);
2339 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2340 present ? 1 : 3);
2341}
2342
2343
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002344/* toggle input of built-in digital mic and mic jack appropriately
2345 order is: external mic -> dock mic -> interal mic */
2346static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2347{
2348 unsigned int ext_present, dock_present;
2349
2350 static struct hda_verb ext_mic_present[] = {
2351 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2352 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2353 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2354 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2355 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2356 {}
2357 };
2358 static struct hda_verb dock_mic_present[] = {
2359 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2360 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2361 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2362 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2363 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2364 {}
2365 };
2366 static struct hda_verb ext_mic_absent[] = {
2367 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2368 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2369 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2370 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2371 {}
2372 };
2373
2374 ext_present = snd_hda_jack_detect(codec, 0x1b);
2375 dock_present = snd_hda_jack_detect(codec, 0x1a);
2376 if (ext_present) {
2377 snd_printdd("CXT5066: external microphone detected\n");
2378 snd_hda_sequence_write(codec, ext_mic_present);
2379 } else if (dock_present) {
2380 snd_printdd("CXT5066: dock microphone detected\n");
2381 snd_hda_sequence_write(codec, dock_mic_present);
2382 } else {
2383 snd_printdd("CXT5066: external microphone absent\n");
2384 snd_hda_sequence_write(codec, ext_mic_absent);
2385 }
2386}
2387
Daniel Drake0fb67e92009-07-16 14:46:57 +01002388/* mute internal speaker if HP is plugged */
2389static void cxt5066_hp_automute(struct hda_codec *codec)
2390{
2391 struct conexant_spec *spec = codec->spec;
2392 unsigned int portA, portD;
2393
2394 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002395 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002396
2397 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002398 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002399
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002400 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2401 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002402 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2403 portA, portD, spec->hp_present);
2404 cxt5066_update_speaker(codec);
2405}
2406
David Henningsson02b6b5b2011-01-21 13:27:39 +01002407/* Dispatch the right mic autoswitch function */
2408static void cxt5066_automic(struct hda_codec *codec)
2409{
2410 struct conexant_spec *spec = codec->spec;
2411
2412 if (spec->dell_vostro)
2413 cxt5066_vostro_automic(codec);
2414 else if (spec->ideapad)
2415 cxt5066_ideapad_automic(codec);
2416 else if (spec->thinkpad)
2417 cxt5066_thinkpad_automic(codec);
2418 else if (spec->hp_laptop)
2419 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002420 else if (spec->asus)
2421 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002422}
2423
Daniel Drake0fb67e92009-07-16 14:46:57 +01002424/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002425static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002426{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002427 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002428 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2429 switch (res >> 26) {
2430 case CONEXANT_HP_EVENT:
2431 cxt5066_hp_automute(codec);
2432 break;
2433 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002434 /* ignore mic events in DC mode; we're always using the jack */
2435 if (!spec->dc_enable)
2436 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002437 break;
2438 }
2439}
2440
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002441/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002442static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002443{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002444 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002445 switch (res >> 26) {
2446 case CONEXANT_HP_EVENT:
2447 cxt5066_hp_automute(codec);
2448 break;
2449 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002450 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002451 break;
2452 }
2453}
2454
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002455
Daniel Drake0fb67e92009-07-16 14:46:57 +01002456static const struct hda_input_mux cxt5066_analog_mic_boost = {
2457 .num_items = 5,
2458 .items = {
2459 { "0dB", 0 },
2460 { "10dB", 1 },
2461 { "20dB", 2 },
2462 { "30dB", 3 },
2463 { "40dB", 4 },
2464 },
2465};
2466
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002467static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002468{
2469 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002470 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002471 AC_VERB_SET_AMP_GAIN_MUTE,
2472 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2473 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002474 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002475 /* adjust the internal mic as well...it is not through 0x17 */
2476 snd_hda_codec_write_cache(codec, 0x23, 0,
2477 AC_VERB_SET_AMP_GAIN_MUTE,
2478 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2479 cxt5066_analog_mic_boost.
2480 items[spec->mic_boost].index);
2481 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002482}
2483
Daniel Drake0fb67e92009-07-16 14:46:57 +01002484static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2485 struct snd_ctl_elem_info *uinfo)
2486{
2487 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2488}
2489
2490static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2491 struct snd_ctl_elem_value *ucontrol)
2492{
2493 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002494 struct conexant_spec *spec = codec->spec;
2495 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002496 return 0;
2497}
2498
2499static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2500 struct snd_ctl_elem_value *ucontrol)
2501{
2502 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002503 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002504 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2505 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002506 idx = ucontrol->value.enumerated.item[0];
2507 if (idx >= imux->num_items)
2508 idx = imux->num_items - 1;
2509
Daniel Drakec4cfe662010-01-07 13:47:04 +01002510 spec->mic_boost = idx;
2511 if (!spec->dc_enable)
2512 cxt5066_set_mic_boost(codec);
2513 return 1;
2514}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002515
Daniel Drakec4cfe662010-01-07 13:47:04 +01002516static void cxt5066_enable_dc(struct hda_codec *codec)
2517{
2518 const struct hda_verb enable_dc_mode[] = {
2519 /* disable gain */
2520 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2521
2522 /* switch to DC input */
2523 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2524 {}
2525 };
2526
2527 /* configure as input source */
2528 snd_hda_sequence_write(codec, enable_dc_mode);
2529 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2530}
2531
2532static void cxt5066_disable_dc(struct hda_codec *codec)
2533{
2534 /* reconfigure input source */
2535 cxt5066_set_mic_boost(codec);
2536 /* automic also selects the right mic if we're recording */
2537 cxt5066_olpc_automic(codec);
2538}
2539
2540static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2541 struct snd_ctl_elem_value *ucontrol)
2542{
2543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2544 struct conexant_spec *spec = codec->spec;
2545 ucontrol->value.integer.value[0] = spec->dc_enable;
2546 return 0;
2547}
2548
2549static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2550 struct snd_ctl_elem_value *ucontrol)
2551{
2552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2553 struct conexant_spec *spec = codec->spec;
2554 int dc_enable = !!ucontrol->value.integer.value[0];
2555
2556 if (dc_enable == spec->dc_enable)
2557 return 0;
2558
2559 spec->dc_enable = dc_enable;
2560 if (dc_enable)
2561 cxt5066_enable_dc(codec);
2562 else
2563 cxt5066_disable_dc(codec);
2564
2565 return 1;
2566}
2567
2568static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2569 struct snd_ctl_elem_info *uinfo)
2570{
2571 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2572}
2573
2574static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2575 struct snd_ctl_elem_value *ucontrol)
2576{
2577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2578 struct conexant_spec *spec = codec->spec;
2579 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2580 return 0;
2581}
2582
2583static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2584 struct snd_ctl_elem_value *ucontrol)
2585{
2586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2587 struct conexant_spec *spec = codec->spec;
2588 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2589 unsigned int idx;
2590
2591 idx = ucontrol->value.enumerated.item[0];
2592 if (idx >= imux->num_items)
2593 idx = imux->num_items - 1;
2594
2595 spec->dc_input_bias = idx;
2596 if (spec->dc_enable)
2597 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002598 return 1;
2599}
2600
Daniel Drake75f89912010-01-07 13:46:25 +01002601static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2602{
2603 struct conexant_spec *spec = codec->spec;
2604 /* mark as recording and configure the microphone widget so that the
2605 * recording LED comes on. */
2606 spec->recording = 1;
2607 cxt5066_olpc_select_mic(codec);
2608}
2609
2610static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2611{
2612 struct conexant_spec *spec = codec->spec;
2613 const struct hda_verb disable_mics[] = {
2614 /* disable external mic, port B */
2615 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2616
2617 /* disble internal mic, port C */
2618 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002619
2620 /* disable DC capture, port F */
2621 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002622 {},
2623 };
2624
2625 snd_hda_sequence_write(codec, disable_mics);
2626 spec->recording = 0;
2627}
2628
Andy Robinsonf6a24912011-01-24 10:12:37 -05002629static void conexant_check_dig_outs(struct hda_codec *codec,
2630 hda_nid_t *dig_pins,
2631 int num_pins)
2632{
2633 struct conexant_spec *spec = codec->spec;
2634 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2635 int i;
2636
2637 for (i = 0; i < num_pins; i++, dig_pins++) {
2638 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2639 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2640 continue;
2641 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2642 continue;
2643 if (spec->slave_dig_outs[0])
2644 nid_loc++;
2645 else
2646 nid_loc = spec->slave_dig_outs;
2647 }
2648}
2649
Daniel Drake0fb67e92009-07-16 14:46:57 +01002650static struct hda_input_mux cxt5066_capture_source = {
2651 .num_items = 4,
2652 .items = {
2653 { "Mic B", 0 },
2654 { "Mic C", 1 },
2655 { "Mic E", 2 },
2656 { "Mic F", 3 },
2657 },
2658};
2659
2660static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2661 .ops = &snd_hda_bind_vol,
2662 .values = {
2663 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2664 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2665 0
2666 },
2667};
2668
2669static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2670 .ops = &snd_hda_bind_sw,
2671 .values = {
2672 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2673 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2674 0
2675 },
2676};
2677
2678static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2679 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2680 {}
2681};
2682
2683static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2684 {
2685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2686 .name = "Master Playback Volume",
2687 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2688 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2689 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002690 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002691 .info = snd_hda_mixer_amp_volume_info,
2692 .get = snd_hda_mixer_amp_volume_get,
2693 .put = snd_hda_mixer_amp_volume_put,
2694 .tlv = { .c = snd_hda_mixer_amp_tlv },
2695 /* offset by 28 volume steps to limit minimum gain to -46dB */
2696 .private_value =
2697 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2698 },
2699 {}
2700};
2701
Daniel Drakec4cfe662010-01-07 13:47:04 +01002702static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2703 {
2704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2705 .name = "DC Mode Enable Switch",
2706 .info = snd_ctl_boolean_mono_info,
2707 .get = cxt5066_olpc_dc_get,
2708 .put = cxt5066_olpc_dc_put,
2709 },
2710 {
2711 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2712 .name = "DC Input Bias Enum",
2713 .info = cxt5066_olpc_dc_bias_enum_info,
2714 .get = cxt5066_olpc_dc_bias_enum_get,
2715 .put = cxt5066_olpc_dc_bias_enum_put,
2716 },
2717 {}
2718};
2719
Daniel Drake0fb67e92009-07-16 14:46:57 +01002720static struct snd_kcontrol_new cxt5066_mixers[] = {
2721 {
2722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2723 .name = "Master Playback Switch",
2724 .info = cxt_eapd_info,
2725 .get = cxt_eapd_get,
2726 .put = cxt5066_hp_master_sw_put,
2727 .private_value = 0x1d,
2728 },
2729
2730 {
2731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002732 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002733 .info = cxt5066_mic_boost_mux_enum_info,
2734 .get = cxt5066_mic_boost_mux_enum_get,
2735 .put = cxt5066_mic_boost_mux_enum_put,
2736 },
2737
2738 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2739 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2740 {}
2741};
2742
Einar Rünkaru254bba62009-12-16 22:16:13 +02002743static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2744 {
2745 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002746 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002747 .info = cxt5066_mic_boost_mux_enum_info,
2748 .get = cxt5066_mic_boost_mux_enum_get,
2749 .put = cxt5066_mic_boost_mux_enum_put,
2750 .private_value = 0x23 | 0x100,
2751 },
2752 {}
2753};
2754
Daniel Drake0fb67e92009-07-16 14:46:57 +01002755static struct hda_verb cxt5066_init_verbs[] = {
2756 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2757 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2758 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2759 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2760
2761 /* Speakers */
2762 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2763 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2764
2765 /* HP, Amp */
2766 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2767 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2768
2769 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2770 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2771
2772 /* DAC1 */
2773 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2774
2775 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2776 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2777 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2781
2782 /* no digital microphone support yet */
2783 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2784
2785 /* Audio input selector */
2786 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2787
2788 /* SPDIF route: PCM */
2789 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2790 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2791
2792 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2793 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2794
2795 /* EAPD */
2796 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2797
2798 /* not handling these yet */
2799 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2800 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2801 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2802 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2803 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2804 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2805 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2806 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2807 { } /* end */
2808};
2809
2810static struct hda_verb cxt5066_init_verbs_olpc[] = {
2811 /* Port A: headphones */
2812 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2813 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2814
2815 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002816 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002817
2818 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002819 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002820
2821 /* Port D: unused */
2822 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2823
2824 /* Port E: unused, but has primary EAPD */
2825 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2826 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2827
Daniel Drakec4cfe662010-01-07 13:47:04 +01002828 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002829 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2830
2831 /* Port G: internal speakers */
2832 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2833 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2834
2835 /* DAC1 */
2836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2837
2838 /* DAC2: unused */
2839 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2840
2841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2851 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2853
2854 /* Disable digital microphone port */
2855 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2856
2857 /* Audio input selectors */
2858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2859 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2860
2861 /* Disable SPDIF */
2862 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2864
2865 /* enable unsolicited events for Port A and B */
2866 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2867 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2868 { } /* end */
2869};
2870
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002871static struct hda_verb cxt5066_init_verbs_vostro[] = {
2872 /* Port A: headphones */
2873 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2874 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2875
2876 /* Port B: external microphone */
2877 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2878
2879 /* Port C: unused */
2880 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2881
2882 /* Port D: unused */
2883 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2884
2885 /* Port E: unused, but has primary EAPD */
2886 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2887 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2888
2889 /* Port F: unused */
2890 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2891
2892 /* Port G: internal speakers */
2893 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2894 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2895
2896 /* DAC1 */
2897 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2898
2899 /* DAC2: unused */
2900 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2901
2902 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2903 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2906 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2907 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2908 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2909 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2910 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2911 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2912 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2913 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2914
2915 /* Digital microphone port */
2916 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2917
2918 /* Audio input selectors */
2919 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2920 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2921
2922 /* Disable SPDIF */
2923 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2924 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2925
2926 /* enable unsolicited events for Port A and B */
2927 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2928 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2929 { } /* end */
2930};
2931
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002932static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2933 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2934 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2935 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2936 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2937
2938 /* Speakers */
2939 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2940 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2941
2942 /* HP, Amp */
2943 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2944 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2945
2946 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2947 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2948
2949 /* DAC1 */
2950 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2951
2952 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2953 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2954 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2955 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2956 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2957 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2958 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2959
2960 /* Audio input selector */
2961 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2962 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2963
2964 /* SPDIF route: PCM */
2965 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2966 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2967
2968 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2969 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2970
2971 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002972 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002973
2974 /* EAPD */
2975 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2976
2977 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2978 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2979 { } /* end */
2980};
2981
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002982static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2983 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2984 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2985
2986 /* Port G: internal speakers */
2987 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2988 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2989
2990 /* Port A: HP, Amp */
2991 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2992 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2993
2994 /* Port B: Mic Dock */
2995 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2996
2997 /* Port C: Mic */
2998 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2999
3000 /* Port D: HP Dock, Amp */
3001 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3002 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
3003
3004 /* DAC1 */
3005 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3006
3007 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
3008 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
3009 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3010 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
3011 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3012 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3013 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
3014
3015 /* Audio input selector */
3016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
3017 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
3018
3019 /* SPDIF route: PCM */
3020 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
3021 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
3022
3023 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3024 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3025
3026 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01003027 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003028
3029 /* EAPD */
3030 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
3031
3032 /* enable unsolicited events for Port A, B, C and D */
3033 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3034 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3035 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3036 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3037 { } /* end */
3038};
3039
Daniel Drake0fb67e92009-07-16 14:46:57 +01003040static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
3041 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3042 { } /* end */
3043};
3044
David Henningsson048e78a2010-09-02 08:35:47 +02003045
3046static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3047 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3048 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3049 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3050 { } /* end */
3051};
3052
Daniel Drake0fb67e92009-07-16 14:46:57 +01003053/* initialize jack-sensing, too */
3054static int cxt5066_init(struct hda_codec *codec)
3055{
3056 snd_printdd("CXT5066: init\n");
3057 conexant_init(codec);
3058 if (codec->patch_ops.unsol_event) {
3059 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003060 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003061 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003062 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003063 return 0;
3064}
3065
Daniel Drake75f89912010-01-07 13:46:25 +01003066static int cxt5066_olpc_init(struct hda_codec *codec)
3067{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003068 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003069 snd_printdd("CXT5066: init\n");
3070 conexant_init(codec);
3071 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003072 if (!spec->dc_enable) {
3073 cxt5066_set_mic_boost(codec);
3074 cxt5066_olpc_automic(codec);
3075 } else {
3076 cxt5066_enable_dc(codec);
3077 }
Daniel Drake75f89912010-01-07 13:46:25 +01003078 return 0;
3079}
3080
Daniel Drake0fb67e92009-07-16 14:46:57 +01003081enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003082 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003083 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3084 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003085 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003086 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003087 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003088 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003089 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003090 CXT5066_MODELS
3091};
3092
Takashi Iwaiea734962011-01-17 11:29:34 +01003093static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003094 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003095 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3096 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003097 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003098 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003099 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003100 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003101 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003102};
3103
3104static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003105 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003106 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003107 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003108 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003109 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003110 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003111 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003112 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003113 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003114 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003115 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003116 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003117 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003118 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3119 CXT5066_LAPTOP),
3120 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003121 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003122 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
Jerone Youngab854572010-07-19 08:30:58 -05003123 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003124 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003125 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003126 {}
3127};
3128
3129static int patch_cxt5066(struct hda_codec *codec)
3130{
3131 struct conexant_spec *spec;
3132 int board_config;
3133
3134 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3135 if (!spec)
3136 return -ENOMEM;
3137 codec->spec = spec;
3138
3139 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003140 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003141
3142 spec->dell_automute = 0;
3143 spec->multiout.max_channels = 2;
3144 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3145 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003146 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3147 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003148 spec->num_adc_nids = 1;
3149 spec->adc_nids = cxt5066_adc_nids;
3150 spec->capsrc_nids = cxt5066_capsrc_nids;
3151 spec->input_mux = &cxt5066_capture_source;
3152
3153 spec->port_d_mode = PIN_HP;
3154
3155 spec->num_init_verbs = 1;
3156 spec->init_verbs[0] = cxt5066_init_verbs;
3157 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3158 spec->channel_mode = cxt5066_modes;
3159 spec->cur_adc = 0;
3160 spec->cur_adc_idx = 0;
3161
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003162 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3163
Daniel Drake0fb67e92009-07-16 14:46:57 +01003164 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3165 cxt5066_models, cxt5066_cfg_tbl);
3166 switch (board_config) {
3167 default:
3168 case CXT5066_LAPTOP:
3169 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3170 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3171 break;
3172 case CXT5066_DELL_LAPTOP:
3173 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3174 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3175
3176 spec->port_d_mode = PIN_OUT;
3177 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3178 spec->num_init_verbs++;
3179 spec->dell_automute = 1;
3180 break;
David Henningssona1d69062011-01-21 13:33:28 +01003181 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003182 case CXT5066_HP_LAPTOP:
3183 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003184 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003185 spec->init_verbs[spec->num_init_verbs] =
3186 cxt5066_init_verbs_hp_laptop;
3187 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003188 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3189 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003190 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3191 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3192 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003193 if (board_config == CXT5066_HP_LAPTOP)
3194 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003195 /* input source automatically selected */
3196 spec->input_mux = NULL;
3197 spec->port_d_mode = 0;
3198 spec->mic_boost = 3; /* default 30dB gain */
3199 break;
3200
Daniel Drake0fb67e92009-07-16 14:46:57 +01003201 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003202 codec->patch_ops.init = cxt5066_olpc_init;
3203 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003204 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3205 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003206 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003207 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3208 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003209 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003210
3211 /* no S/PDIF out */
3212 spec->multiout.dig_out_nid = 0;
3213
3214 /* input source automatically selected */
3215 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003216
3217 /* our capture hooks which allow us to turn on the microphone LED
3218 * at the right time */
3219 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3220 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003221 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003222 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003223 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003224 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003225 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3226 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3227 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003228 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003229 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003230 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003231 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003232
3233 /* no S/PDIF out */
3234 spec->multiout.dig_out_nid = 0;
3235
3236 /* input source automatically selected */
3237 spec->input_mux = NULL;
3238 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003239 case CXT5066_IDEAPAD:
3240 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003241 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003242 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3243 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3244 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3245 spec->port_d_mode = 0;
3246 spec->ideapad = 1;
3247 spec->mic_boost = 2; /* default 20dB gain */
3248
3249 /* no S/PDIF out */
3250 spec->multiout.dig_out_nid = 0;
3251
3252 /* input source automatically selected */
3253 spec->input_mux = NULL;
3254 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003255 case CXT5066_THINKPAD:
3256 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003257 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003258 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3259 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3260 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3261 spec->thinkpad = 1;
3262 spec->port_d_mode = PIN_OUT;
3263 spec->mic_boost = 2; /* default 20dB gain */
3264
3265 /* no S/PDIF out */
3266 spec->multiout.dig_out_nid = 0;
3267
3268 /* input source automatically selected */
3269 spec->input_mux = NULL;
3270 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003271 }
3272
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003273 if (spec->beep_amp)
3274 snd_hda_attach_beep_device(codec, spec->beep_amp);
3275
Daniel Drake0fb67e92009-07-16 14:46:57 +01003276 return 0;
3277}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003278
3279/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003280 * Automatic parser for CX20641 & co
3281 */
3282
3283static hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3284
3285/* get the connection index of @nid in the widget @mux */
3286static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3287 hda_nid_t nid)
3288{
3289 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3290 int i, nums;
3291
3292 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3293 for (i = 0; i < nums; i++)
3294 if (conn[i] == nid)
3295 return i;
3296 return -1;
3297}
3298
3299/* get an unassigned DAC from the given list.
3300 * Return the nid if found and reduce the DAC list, or return zero if
3301 * not found
3302 */
3303static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3304 hda_nid_t *dacs, int *num_dacs)
3305{
3306 int i, nums = *num_dacs;
3307 hda_nid_t ret = 0;
3308
3309 for (i = 0; i < nums; i++) {
3310 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3311 ret = dacs[i];
3312 break;
3313 }
3314 }
3315 if (!ret)
3316 return 0;
3317 if (--nums > 0)
3318 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3319 *num_dacs = nums;
3320 return ret;
3321}
3322
3323#define MAX_AUTO_DACS 5
3324
3325/* fill analog DAC list from the widget tree */
3326static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3327{
3328 hda_nid_t nid, end_nid;
3329 int nums = 0;
3330
3331 end_nid = codec->start_nid + codec->num_nodes;
3332 for (nid = codec->start_nid; nid < end_nid; nid++) {
3333 unsigned int wcaps = get_wcaps(codec, nid);
3334 unsigned int type = get_wcaps_type(wcaps);
3335 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3336 dacs[nums++] = nid;
3337 if (nums >= MAX_AUTO_DACS)
3338 break;
3339 }
3340 }
3341 return nums;
3342}
3343
3344/* fill pin_dac_pair list from the pin and dac list */
3345static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3346 int num_pins, hda_nid_t *dacs, int *rest,
3347 struct pin_dac_pair *filled, int type)
3348{
3349 int i, nums;
3350
3351 nums = 0;
3352 for (i = 0; i < num_pins; i++) {
3353 filled[nums].pin = pins[i];
3354 filled[nums].type = type;
3355 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3356 nums++;
3357 }
3358 return nums;
3359}
3360
3361/* parse analog output paths */
3362static void cx_auto_parse_output(struct hda_codec *codec)
3363{
3364 struct conexant_spec *spec = codec->spec;
3365 struct auto_pin_cfg *cfg = &spec->autocfg;
3366 hda_nid_t dacs[MAX_AUTO_DACS];
3367 int i, j, nums, rest;
3368
3369 rest = fill_cx_auto_dacs(codec, dacs);
3370 /* parse all analog output pins */
3371 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3372 dacs, &rest, spec->dac_info,
3373 AUTO_PIN_LINE_OUT);
3374 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3375 dacs, &rest, spec->dac_info + nums,
3376 AUTO_PIN_HP_OUT);
3377 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3378 dacs, &rest, spec->dac_info + nums,
3379 AUTO_PIN_SPEAKER_OUT);
3380 spec->dac_info_filled = nums;
3381 /* fill multiout struct */
3382 for (i = 0; i < nums; i++) {
3383 hda_nid_t dac = spec->dac_info[i].dac;
3384 if (!dac)
3385 continue;
3386 switch (spec->dac_info[i].type) {
3387 case AUTO_PIN_LINE_OUT:
3388 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3389 spec->multiout.num_dacs++;
3390 break;
3391 case AUTO_PIN_HP_OUT:
3392 case AUTO_PIN_SPEAKER_OUT:
3393 if (!spec->multiout.hp_nid) {
3394 spec->multiout.hp_nid = dac;
3395 break;
3396 }
3397 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3398 if (!spec->multiout.extra_out_nid[j]) {
3399 spec->multiout.extra_out_nid[j] = dac;
3400 break;
3401 }
3402 break;
3403 }
3404 }
3405 spec->multiout.dac_nids = spec->private_dac_nids;
3406 spec->multiout.max_channels = nums * 2;
3407
3408 if (cfg->hp_outs > 0)
3409 spec->auto_mute = 1;
3410 spec->vmaster_nid = spec->private_dac_nids[0];
3411}
3412
3413/* auto-mute/unmute speaker and line outs according to headphone jack */
3414static void cx_auto_hp_automute(struct hda_codec *codec)
3415{
3416 struct conexant_spec *spec = codec->spec;
3417 struct auto_pin_cfg *cfg = &spec->autocfg;
3418 int i, present;
3419
3420 if (!spec->auto_mute)
3421 return;
3422 present = 0;
3423 for (i = 0; i < cfg->hp_outs; i++) {
3424 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3425 present = 1;
3426 break;
3427 }
3428 }
3429 for (i = 0; i < cfg->line_outs; i++) {
3430 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3431 AC_VERB_SET_PIN_WIDGET_CONTROL,
3432 present ? 0 : PIN_OUT);
3433 }
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003434 for (i = 0; !present && i < cfg->line_outs; i++)
3435 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3436 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003437 for (i = 0; i < cfg->speaker_outs; i++) {
3438 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3439 AC_VERB_SET_PIN_WIDGET_CONTROL,
3440 present ? 0 : PIN_OUT);
3441 }
3442}
3443
3444/* automatic switch internal and external mic */
3445static void cx_auto_automic(struct hda_codec *codec)
3446{
3447 struct conexant_spec *spec = codec->spec;
3448 struct auto_pin_cfg *cfg = &spec->autocfg;
3449 struct hda_input_mux *imux = &spec->private_imux;
3450 int ext_idx = spec->auto_mic_ext;
3451
3452 if (!spec->auto_mic)
3453 return;
3454 if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) {
3455 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3456 AC_VERB_SET_CONNECT_SEL,
3457 imux->items[ext_idx].index);
3458 } else {
3459 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3460 AC_VERB_SET_CONNECT_SEL,
3461 imux->items[!ext_idx].index);
3462 }
3463}
3464
3465static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3466{
3467 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3468 switch (res >> 26) {
3469 case CONEXANT_HP_EVENT:
3470 cx_auto_hp_automute(codec);
3471 conexant_report_jack(codec, nid);
3472 break;
3473 case CONEXANT_MIC_EVENT:
3474 cx_auto_automic(codec);
3475 conexant_report_jack(codec, nid);
3476 break;
3477 }
3478}
3479
Takashi Iwaif2e57312010-09-15 10:07:08 +02003480/* return true if it's an internal-mic pin */
3481static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3482{
3483 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3484 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003485 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003486}
3487
3488/* return true if it's an external-mic pin */
3489static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3490{
3491 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3492 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003493 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3494 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003495}
3496
3497/* check whether the pin config is suitable for auto-mic switching;
3498 * auto-mic is enabled only when one int-mic and one-ext mic exist
3499 */
3500static void cx_auto_check_auto_mic(struct hda_codec *codec)
3501{
3502 struct conexant_spec *spec = codec->spec;
3503 struct auto_pin_cfg *cfg = &spec->autocfg;
3504
3505 if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3506 is_int_mic(codec, cfg->inputs[1].pin)) {
3507 spec->auto_mic = 1;
3508 spec->auto_mic_ext = 1;
3509 return;
3510 }
3511 if (is_int_mic(codec, cfg->inputs[1].pin) &&
3512 is_ext_mic(codec, cfg->inputs[0].pin)) {
3513 spec->auto_mic = 1;
3514 spec->auto_mic_ext = 0;
3515 return;
3516 }
3517}
3518
3519static void cx_auto_parse_input(struct hda_codec *codec)
3520{
3521 struct conexant_spec *spec = codec->spec;
3522 struct auto_pin_cfg *cfg = &spec->autocfg;
3523 struct hda_input_mux *imux;
3524 int i;
3525
3526 imux = &spec->private_imux;
3527 for (i = 0; i < cfg->num_inputs; i++) {
3528 int idx = get_connection_index(codec, spec->adc_nids[0],
3529 cfg->inputs[i].pin);
3530 if (idx >= 0) {
3531 const char *label;
3532 label = hda_get_autocfg_input_label(codec, cfg, i);
3533 snd_hda_add_imux_item(imux, label, idx, NULL);
3534 }
3535 }
3536 if (imux->num_items == 2 && cfg->num_inputs == 2)
3537 cx_auto_check_auto_mic(codec);
3538 if (imux->num_items > 1 && !spec->auto_mic)
3539 spec->input_mux = imux;
3540}
3541
3542/* get digital-input audio widget corresponding to the given pin */
3543static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3544{
3545 hda_nid_t nid, end_nid;
3546
3547 end_nid = codec->start_nid + codec->num_nodes;
3548 for (nid = codec->start_nid; nid < end_nid; nid++) {
3549 unsigned int wcaps = get_wcaps(codec, nid);
3550 unsigned int type = get_wcaps_type(wcaps);
3551 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3552 if (get_connection_index(codec, nid, pin) >= 0)
3553 return nid;
3554 }
3555 }
3556 return 0;
3557}
3558
3559static void cx_auto_parse_digital(struct hda_codec *codec)
3560{
3561 struct conexant_spec *spec = codec->spec;
3562 struct auto_pin_cfg *cfg = &spec->autocfg;
3563 hda_nid_t nid;
3564
3565 if (cfg->dig_outs &&
3566 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3567 spec->multiout.dig_out_nid = nid;
3568 if (cfg->dig_in_pin)
3569 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3570}
3571
3572#ifdef CONFIG_SND_HDA_INPUT_BEEP
3573static void cx_auto_parse_beep(struct hda_codec *codec)
3574{
3575 struct conexant_spec *spec = codec->spec;
3576 hda_nid_t nid, end_nid;
3577
3578 end_nid = codec->start_nid + codec->num_nodes;
3579 for (nid = codec->start_nid; nid < end_nid; nid++)
3580 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3581 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3582 break;
3583 }
3584}
3585#else
3586#define cx_auto_parse_beep(codec)
3587#endif
3588
3589static int cx_auto_parse_auto_config(struct hda_codec *codec)
3590{
3591 struct conexant_spec *spec = codec->spec;
3592 int err;
3593
3594 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3595 if (err < 0)
3596 return err;
3597
3598 cx_auto_parse_output(codec);
3599 cx_auto_parse_input(codec);
3600 cx_auto_parse_digital(codec);
3601 cx_auto_parse_beep(codec);
3602 return 0;
3603}
3604
3605static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins,
3606 hda_nid_t *pins)
3607{
3608 int i;
3609 for (i = 0; i < num_pins; i++) {
3610 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3611 snd_hda_codec_write(codec, pins[i], 0,
3612 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3613 }
3614}
3615
3616static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3617 hda_nid_t src)
3618{
3619 int idx = get_connection_index(codec, pin, src);
3620 if (idx >= 0)
3621 snd_hda_codec_write(codec, pin, 0,
3622 AC_VERB_SET_CONNECT_SEL, idx);
3623}
3624
3625static void cx_auto_init_output(struct hda_codec *codec)
3626{
3627 struct conexant_spec *spec = codec->spec;
3628 struct auto_pin_cfg *cfg = &spec->autocfg;
3629 hda_nid_t nid;
3630 int i;
3631
3632 for (i = 0; i < spec->multiout.num_dacs; i++)
3633 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
3634 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3635
3636 for (i = 0; i < cfg->hp_outs; i++)
3637 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3638 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3639 if (spec->auto_mute) {
3640 for (i = 0; i < cfg->hp_outs; i++) {
3641 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3642 AC_VERB_SET_UNSOLICITED_ENABLE,
3643 AC_USRSP_EN | CONEXANT_HP_EVENT);
3644 }
3645 cx_auto_hp_automute(codec);
3646 } else {
3647 for (i = 0; i < cfg->line_outs; i++)
3648 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3649 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3650 for (i = 0; i < cfg->speaker_outs; i++)
3651 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3652 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3653 }
3654
3655 for (i = 0; i < spec->dac_info_filled; i++) {
3656 nid = spec->dac_info[i].dac;
3657 if (!nid)
3658 nid = spec->multiout.dac_nids[0];
3659 select_connection(codec, spec->dac_info[i].pin, nid);
3660 }
3661
3662 /* turn on EAPD */
3663 cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins);
3664 cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins);
3665 cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins);
3666}
3667
3668static void cx_auto_init_input(struct hda_codec *codec)
3669{
3670 struct conexant_spec *spec = codec->spec;
3671 struct auto_pin_cfg *cfg = &spec->autocfg;
3672 int i;
3673
3674 for (i = 0; i < spec->num_adc_nids; i++)
3675 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3676 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0));
3677
3678 for (i = 0; i < cfg->num_inputs; i++) {
3679 unsigned int type;
3680 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3681 type = PIN_VREF80;
3682 else
3683 type = PIN_IN;
3684 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3685 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3686 }
3687
3688 if (spec->auto_mic) {
3689 int ext_idx = spec->auto_mic_ext;
3690 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3691 AC_VERB_SET_UNSOLICITED_ENABLE,
3692 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3693 cx_auto_automic(codec);
3694 } else {
3695 for (i = 0; i < spec->num_adc_nids; i++) {
3696 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3697 AC_VERB_SET_CONNECT_SEL,
3698 spec->private_imux.items[0].index);
3699 }
3700 }
3701}
3702
3703static void cx_auto_init_digital(struct hda_codec *codec)
3704{
3705 struct conexant_spec *spec = codec->spec;
3706 struct auto_pin_cfg *cfg = &spec->autocfg;
3707
3708 if (spec->multiout.dig_out_nid)
3709 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3710 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3711 if (spec->dig_in_nid)
3712 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3713 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3714}
3715
3716static int cx_auto_init(struct hda_codec *codec)
3717{
3718 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3719 cx_auto_init_output(codec);
3720 cx_auto_init_input(codec);
3721 cx_auto_init_digital(codec);
3722 return 0;
3723}
3724
3725static int cx_auto_add_volume(struct hda_codec *codec, const char *basename,
3726 const char *dir, int cidx,
3727 hda_nid_t nid, int hda_dir)
3728{
3729 static char name[32];
3730 static struct snd_kcontrol_new knew[] = {
3731 HDA_CODEC_VOLUME(name, 0, 0, 0),
3732 HDA_CODEC_MUTE(name, 0, 0, 0),
3733 };
3734 static char *sfx[2] = { "Volume", "Switch" };
3735 int i, err;
3736
3737 for (i = 0; i < 2; i++) {
3738 struct snd_kcontrol *kctl;
3739 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir);
3740 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3741 knew[i].index = cidx;
3742 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3743 kctl = snd_ctl_new1(&knew[i], codec);
3744 if (!kctl)
3745 return -ENOMEM;
3746 err = snd_hda_ctl_add(codec, nid, kctl);
3747 if (err < 0)
3748 return err;
3749 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3750 break;
3751 }
3752 return 0;
3753}
3754
3755#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3756 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3757
3758static int cx_auto_build_output_controls(struct hda_codec *codec)
3759{
3760 struct conexant_spec *spec = codec->spec;
3761 int i, err;
3762 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003763 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003764
3765 if (spec->dac_info_filled == 1)
3766 return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3767 "Master", 0);
3768 for (i = 0; i < spec->dac_info_filled; i++) {
3769 const char *label;
3770 int idx, type;
3771 if (!spec->dac_info[i].dac)
3772 continue;
3773 type = spec->dac_info[i].type;
3774 if (type == AUTO_PIN_LINE_OUT)
3775 type = spec->autocfg.line_out_type;
3776 switch (type) {
3777 case AUTO_PIN_LINE_OUT:
3778 default:
3779 label = texts[num_line++];
3780 idx = 0;
3781 break;
3782 case AUTO_PIN_HP_OUT:
3783 label = "Headphone";
3784 idx = num_hp++;
3785 break;
3786 case AUTO_PIN_SPEAKER_OUT:
3787 label = "Speaker";
3788 idx = num_spk++;
3789 break;
3790 }
3791 err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3792 label, idx);
3793 if (err < 0)
3794 return err;
3795 }
3796 return 0;
3797}
3798
3799static int cx_auto_build_input_controls(struct hda_codec *codec)
3800{
3801 struct conexant_spec *spec = codec->spec;
3802 struct auto_pin_cfg *cfg = &spec->autocfg;
3803 static const char *prev_label;
3804 int i, err, cidx;
3805
3806 err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0],
3807 HDA_INPUT);
3808 if (err < 0)
3809 return err;
3810 prev_label = NULL;
3811 cidx = 0;
3812 for (i = 0; i < cfg->num_inputs; i++) {
3813 hda_nid_t nid = cfg->inputs[i].pin;
3814 const char *label;
3815 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3816 continue;
3817 label = hda_get_autocfg_input_label(codec, cfg, i);
3818 if (label == prev_label)
3819 cidx++;
3820 else
3821 cidx = 0;
3822 prev_label = label;
3823 err = cx_auto_add_volume(codec, label, " Capture", cidx,
3824 nid, HDA_INPUT);
3825 if (err < 0)
3826 return err;
3827 }
3828 return 0;
3829}
3830
3831static int cx_auto_build_controls(struct hda_codec *codec)
3832{
3833 int err;
3834
3835 err = cx_auto_build_output_controls(codec);
3836 if (err < 0)
3837 return err;
3838 err = cx_auto_build_input_controls(codec);
3839 if (err < 0)
3840 return err;
3841 return conexant_build_controls(codec);
3842}
3843
3844static struct hda_codec_ops cx_auto_patch_ops = {
3845 .build_controls = cx_auto_build_controls,
3846 .build_pcms = conexant_build_pcms,
3847 .init = cx_auto_init,
3848 .free = conexant_free,
3849 .unsol_event = cx_auto_unsol_event,
3850#ifdef CONFIG_SND_HDA_POWER_SAVE
3851 .suspend = conexant_suspend,
3852#endif
3853 .reboot_notify = snd_hda_shutup_pins,
3854};
3855
3856static int patch_conexant_auto(struct hda_codec *codec)
3857{
3858 struct conexant_spec *spec;
3859 int err;
3860
3861 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3862 if (!spec)
3863 return -ENOMEM;
3864 codec->spec = spec;
3865 spec->adc_nids = cx_auto_adc_nids;
3866 spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3867 spec->capsrc_nids = spec->adc_nids;
3868 err = cx_auto_parse_auto_config(codec);
3869 if (err < 0) {
3870 kfree(codec->spec);
3871 codec->spec = NULL;
3872 return err;
3873 }
3874 codec->patch_ops = cx_auto_patch_ops;
3875 if (spec->beep_amp)
3876 snd_hda_attach_beep_device(codec, spec->beep_amp);
3877 return 0;
3878}
3879
3880/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01003881 */
3882
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003883static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003884 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3885 .patch = patch_cxt5045 },
3886 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3887 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003888 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3889 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003890 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3891 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003892 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3893 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02003894 { .id = 0x14f15068, .name = "CX20584",
3895 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003896 { .id = 0x14f15069, .name = "CX20585",
3897 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02003898 { .id = 0x14f15097, .name = "CX20631",
3899 .patch = patch_conexant_auto },
3900 { .id = 0x14f15098, .name = "CX20632",
3901 .patch = patch_conexant_auto },
3902 { .id = 0x14f150a1, .name = "CX20641",
3903 .patch = patch_conexant_auto },
3904 { .id = 0x14f150a2, .name = "CX20642",
3905 .patch = patch_conexant_auto },
3906 { .id = 0x14f150ab, .name = "CX20651",
3907 .patch = patch_conexant_auto },
3908 { .id = 0x14f150ac, .name = "CX20652",
3909 .patch = patch_conexant_auto },
3910 { .id = 0x14f150b8, .name = "CX20664",
3911 .patch = patch_conexant_auto },
3912 { .id = 0x14f150b9, .name = "CX20665",
3913 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003914 {} /* terminator */
3915};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003916
3917MODULE_ALIAS("snd-hda-codec-id:14f15045");
3918MODULE_ALIAS("snd-hda-codec-id:14f15047");
3919MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003920MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003921MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02003922MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003923MODULE_ALIAS("snd-hda-codec-id:14f15069");
Takashi Iwaif2e57312010-09-15 10:07:08 +02003924MODULE_ALIAS("snd-hda-codec-id:14f15097");
3925MODULE_ALIAS("snd-hda-codec-id:14f15098");
3926MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3927MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3928MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3929MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3930MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3931MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003932
3933MODULE_LICENSE("GPL");
3934MODULE_DESCRIPTION("Conexant HD-audio codec");
3935
3936static struct hda_codec_preset_list conexant_list = {
3937 .preset = snd_hda_preset_conexant,
3938 .owner = THIS_MODULE,
3939};
3940
3941static int __init patch_conexant_init(void)
3942{
3943 return snd_hda_add_codec_preset(&conexant_list);
3944}
3945
3946static void __exit patch_conexant_exit(void)
3947{
3948 snd_hda_delete_codec_preset(&conexant_list);
3949}
3950
3951module_init(patch_conexant_init)
3952module_exit(patch_conexant_exit)