blob: 1d69a3e0ce2ca743f645c0cd1056cfb5802be8a9 [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
Takashi Iwai03697e22011-05-17 09:53:31 +020042#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010043
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010044/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010045
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010046#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010047#define CXT5051_PORTB_EVENT 0x38
48#define CXT5051_PORTC_EVENT 0x39
49
Takashi Iwaifaddaa52010-01-23 22:31:36 +010050#define AUTO_MIC_PORTB (1 << 1)
51#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010052
Takashi Iwaif2e57312010-09-15 10:07:08 +020053struct pin_dac_pair {
54 hda_nid_t pin;
55 hda_nid_t dac;
56 int type;
57};
58
Takashi Iwai47ad1f42011-05-17 09:15:55 +020059struct imux_info {
60 hda_nid_t pin; /* input pin NID */
61 hda_nid_t adc; /* connected ADC NID */
62 hda_nid_t boost; /* optional boost volume NID */
63 int index; /* corresponding to autocfg.input */
64};
65
Tobin Davisc9b443d2006-11-14 12:13:39 +010066struct conexant_spec {
67
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020068 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010069 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 Iwai03697e22011-05-17 09:53:31 +020085 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010086 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020087 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020088 int auto_mic_dock; /* imux_pins[] index for dock mic */
89 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010090 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050091 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010092
93 /* capture */
94 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020095 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010096 hda_nid_t dig_in_nid; /* digital-in NID; optional */
97
Takashi Iwai461e2c72008-01-25 11:35:17 +010098 unsigned int cur_adc_idx;
99 hda_nid_t cur_adc;
100 unsigned int cur_adc_stream_tag;
101 unsigned int cur_adc_format;
102
Takashi Iwai6764bce2011-05-13 16:52:25 +0200103 const struct hda_pcm_stream *capture_stream;
104
Tobin Davisc9b443d2006-11-14 12:13:39 +0100105 /* capture source */
106 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200107 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100108 unsigned int cur_mux[3];
109
110 /* channel model */
111 const struct hda_channel_mode *channel_mode;
112 int num_channel_mode;
113
114 /* PCM information */
115 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
116
Tobin Davisc9b443d2006-11-14 12:13:39 +0100117 unsigned int spdif_route;
118
119 /* dynamic controls, init_verbs and input_mux */
120 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100121 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200122 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200123 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200124 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200125 struct pin_dac_pair dac_info[8];
126 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100127
Daniel Drake0fb67e92009-07-16 14:46:57 +0100128 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200129 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200130 unsigned int detect_line:1; /* Line-out detection enabled */
131 unsigned int automute_lines:1; /* automute line-out as well */
132 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200133 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500134 unsigned int dell_vostro:1;
135 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200136 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200137 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100138 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200139 unsigned int pin_eapd_ctrls:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100140
Takashi Iwai6764bce2011-05-13 16:52:25 +0200141 unsigned int adc_switching:1;
142
Daniel Drake75f89912010-01-07 13:46:25 +0100143 unsigned int ext_mic_present;
144 unsigned int recording;
145 void (*capture_prepare)(struct hda_codec *codec);
146 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100147
148 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
149 * through the microphone jack.
150 * When the user enables this through a mixer switch, both internal and
151 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
152 * we also allow the bias to be configured through a separate mixer
153 * control. */
154 unsigned int dc_enable;
155 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
156 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200157
158 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200159
160 /* extra EAPD pins */
161 unsigned int num_eapds;
162 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100163};
164
165static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
166 struct hda_codec *codec,
167 struct snd_pcm_substream *substream)
168{
169 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100170 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
171 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100172}
173
174static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
175 struct hda_codec *codec,
176 unsigned int stream_tag,
177 unsigned int format,
178 struct snd_pcm_substream *substream)
179{
180 struct conexant_spec *spec = codec->spec;
181 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
182 stream_tag,
183 format, substream);
184}
185
186static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
187 struct hda_codec *codec,
188 struct snd_pcm_substream *substream)
189{
190 struct conexant_spec *spec = codec->spec;
191 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
192}
193
194/*
195 * Digital out
196 */
197static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
198 struct hda_codec *codec,
199 struct snd_pcm_substream *substream)
200{
201 struct conexant_spec *spec = codec->spec;
202 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
203}
204
205static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
206 struct hda_codec *codec,
207 struct snd_pcm_substream *substream)
208{
209 struct conexant_spec *spec = codec->spec;
210 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
211}
212
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200213static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
214 struct hda_codec *codec,
215 unsigned int stream_tag,
216 unsigned int format,
217 struct snd_pcm_substream *substream)
218{
219 struct conexant_spec *spec = codec->spec;
220 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
221 stream_tag,
222 format, substream);
223}
224
Tobin Davisc9b443d2006-11-14 12:13:39 +0100225/*
226 * Analog capture
227 */
228static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
229 struct hda_codec *codec,
230 unsigned int stream_tag,
231 unsigned int format,
232 struct snd_pcm_substream *substream)
233{
234 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100235 if (spec->capture_prepare)
236 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100237 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
238 stream_tag, 0, format);
239 return 0;
240}
241
242static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
243 struct hda_codec *codec,
244 struct snd_pcm_substream *substream)
245{
246 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100247 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100248 if (spec->capture_cleanup)
249 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100250 return 0;
251}
252
253
254
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200255static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100256 .substreams = 1,
257 .channels_min = 2,
258 .channels_max = 2,
259 .nid = 0, /* fill later */
260 .ops = {
261 .open = conexant_playback_pcm_open,
262 .prepare = conexant_playback_pcm_prepare,
263 .cleanup = conexant_playback_pcm_cleanup
264 },
265};
266
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200267static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100268 .substreams = 1,
269 .channels_min = 2,
270 .channels_max = 2,
271 .nid = 0, /* fill later */
272 .ops = {
273 .prepare = conexant_capture_pcm_prepare,
274 .cleanup = conexant_capture_pcm_cleanup
275 },
276};
277
278
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200279static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100280 .substreams = 1,
281 .channels_min = 2,
282 .channels_max = 2,
283 .nid = 0, /* fill later */
284 .ops = {
285 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200286 .close = conexant_dig_playback_pcm_close,
287 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100288 },
289};
290
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200291static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100292 .substreams = 1,
293 .channels_min = 2,
294 .channels_max = 2,
295 /* NID is set in alc_build_pcms */
296};
297
Takashi Iwai461e2c72008-01-25 11:35:17 +0100298static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
299 struct hda_codec *codec,
300 unsigned int stream_tag,
301 unsigned int format,
302 struct snd_pcm_substream *substream)
303{
304 struct conexant_spec *spec = codec->spec;
305 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
306 spec->cur_adc_stream_tag = stream_tag;
307 spec->cur_adc_format = format;
308 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
309 return 0;
310}
311
312static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
313 struct hda_codec *codec,
314 struct snd_pcm_substream *substream)
315{
316 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100317 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100318 spec->cur_adc = 0;
319 return 0;
320}
321
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200322static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100323 .substreams = 1,
324 .channels_min = 2,
325 .channels_max = 2,
326 .nid = 0, /* fill later */
327 .ops = {
328 .prepare = cx5051_capture_pcm_prepare,
329 .cleanup = cx5051_capture_pcm_cleanup
330 },
331};
332
Tobin Davisc9b443d2006-11-14 12:13:39 +0100333static int conexant_build_pcms(struct hda_codec *codec)
334{
335 struct conexant_spec *spec = codec->spec;
336 struct hda_pcm *info = spec->pcm_rec;
337
338 codec->num_pcms = 1;
339 codec->pcm_info = info;
340
341 info->name = "CONEXANT Analog";
342 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
343 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
344 spec->multiout.max_channels;
345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
346 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200347 if (spec->capture_stream)
348 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
349 else {
350 if (codec->vendor_id == 0x14f15051)
351 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
352 cx5051_pcm_analog_capture;
353 else {
354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
355 conexant_pcm_analog_capture;
356 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
357 spec->num_adc_nids;
358 }
359 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100360 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
361
362 if (spec->multiout.dig_out_nid) {
363 info++;
364 codec->num_pcms++;
365 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100366 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100367 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
368 conexant_pcm_digital_playback;
369 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
370 spec->multiout.dig_out_nid;
371 if (spec->dig_in_nid) {
372 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
373 conexant_pcm_digital_capture;
374 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
375 spec->dig_in_nid;
376 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500377 if (spec->slave_dig_outs[0])
378 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100379 }
380
381 return 0;
382}
383
384static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_info *uinfo)
386{
387 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388 struct conexant_spec *spec = codec->spec;
389
390 return snd_hda_input_mux_info(spec->input_mux, uinfo);
391}
392
393static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
394 struct snd_ctl_elem_value *ucontrol)
395{
396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
397 struct conexant_spec *spec = codec->spec;
398 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
399
400 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
401 return 0;
402}
403
404static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
405 struct snd_ctl_elem_value *ucontrol)
406{
407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
408 struct conexant_spec *spec = codec->spec;
409 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
410
411 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
412 spec->capsrc_nids[adc_idx],
413 &spec->cur_mux[adc_idx]);
414}
415
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100416static int conexant_init_jacks(struct hda_codec *codec)
417{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100418#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100419 struct conexant_spec *spec = codec->spec;
420 int i;
421
422 for (i = 0; i < spec->num_init_verbs; i++) {
423 const struct hda_verb *hv;
424
425 hv = spec->init_verbs[i];
426 while (hv->nid) {
427 int err = 0;
428 switch (hv->param ^ AC_USRSP_EN) {
429 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100430 err = snd_hda_input_jack_add(codec, hv->nid,
431 SND_JACK_HEADPHONE, NULL);
432 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100433 break;
434 case CXT5051_PORTC_EVENT:
435 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100436 err = snd_hda_input_jack_add(codec, hv->nid,
437 SND_JACK_MICROPHONE, NULL);
438 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100439 break;
440 }
441 if (err < 0)
442 return err;
443 ++hv;
444 }
445 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100446#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100447 return 0;
448}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100449
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200450static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
451 unsigned int power_state)
452{
453 if (power_state == AC_PWRST_D3)
454 msleep(100);
455 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
456 power_state);
457 /* partial workaround for "azx_get_response timeout" */
458 if (power_state == AC_PWRST_D0)
459 msleep(10);
460 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
461}
462
Tobin Davisc9b443d2006-11-14 12:13:39 +0100463static int conexant_init(struct hda_codec *codec)
464{
465 struct conexant_spec *spec = codec->spec;
466 int i;
467
468 for (i = 0; i < spec->num_init_verbs; i++)
469 snd_hda_sequence_write(codec, spec->init_verbs[i]);
470 return 0;
471}
472
473static void conexant_free(struct hda_codec *codec)
474{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100475 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200476 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100477 kfree(codec->spec);
478}
479
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200480static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100481 {
482 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
483 .name = "Capture Source",
484 .info = conexant_mux_enum_info,
485 .get = conexant_mux_enum_get,
486 .put = conexant_mux_enum_put
487 },
488 {}
489};
490
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200491#ifdef CONFIG_SND_HDA_INPUT_BEEP
492/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200493static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200494 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
495 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
496 { } /* end */
497};
498#endif
499
Takashi Iwaiea734962011-01-17 11:29:34 +0100500static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100501 "Headphone Playback Volume",
502 "Speaker Playback Volume",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200503 "Front Playback Volume",
504 "Surround Playback Volume",
505 "CLFE Playback Volume",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100506 NULL
507};
508
Takashi Iwaiea734962011-01-17 11:29:34 +0100509static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100510 "Headphone Playback Switch",
511 "Speaker Playback Switch",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200512 "Front Playback Switch",
513 "Surround Playback Switch",
514 "CLFE Playback Switch",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100515 NULL
516};
517
Tobin Davisc9b443d2006-11-14 12:13:39 +0100518static int conexant_build_controls(struct hda_codec *codec)
519{
520 struct conexant_spec *spec = codec->spec;
521 unsigned int i;
522 int err;
523
524 for (i = 0; i < spec->num_mixers; i++) {
525 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
526 if (err < 0)
527 return err;
528 }
529 if (spec->multiout.dig_out_nid) {
530 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600531 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100532 spec->multiout.dig_out_nid);
533 if (err < 0)
534 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100535 err = snd_hda_create_spdif_share_sw(codec,
536 &spec->multiout);
537 if (err < 0)
538 return err;
539 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100540 }
541 if (spec->dig_in_nid) {
542 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
543 if (err < 0)
544 return err;
545 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100546
547 /* if we have no master control, let's create it */
548 if (spec->vmaster_nid &&
549 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
550 unsigned int vmaster_tlv[4];
551 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
552 HDA_OUTPUT, vmaster_tlv);
553 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
554 vmaster_tlv, slave_vols);
555 if (err < 0)
556 return err;
557 }
558 if (spec->vmaster_nid &&
559 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
560 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
561 NULL, slave_sws);
562 if (err < 0)
563 return err;
564 }
565
Takashi Iwaib880c742009-03-10 14:41:05 +0100566 if (spec->input_mux) {
567 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
568 if (err < 0)
569 return err;
570 }
571
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200572#ifdef CONFIG_SND_HDA_INPUT_BEEP
573 /* create beep controls if needed */
574 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200575 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200576 for (knew = cxt_beep_mixer; knew->name; knew++) {
577 struct snd_kcontrol *kctl;
578 kctl = snd_ctl_new1(knew, codec);
579 if (!kctl)
580 return -ENOMEM;
581 kctl->private_value = spec->beep_amp;
582 err = snd_hda_ctl_add(codec, 0, kctl);
583 if (err < 0)
584 return err;
585 }
586 }
587#endif
588
Tobin Davisc9b443d2006-11-14 12:13:39 +0100589 return 0;
590}
591
Takashi Iwai697c3732010-07-30 11:28:02 +0200592#ifdef CONFIG_SND_HDA_POWER_SAVE
593static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
594{
595 snd_hda_shutup_pins(codec);
596 return 0;
597}
598#endif
599
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200600static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 .build_controls = conexant_build_controls,
602 .build_pcms = conexant_build_pcms,
603 .init = conexant_init,
604 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200605 .set_power_state = conexant_set_power,
Takashi Iwai697c3732010-07-30 11:28:02 +0200606#ifdef CONFIG_SND_HDA_POWER_SAVE
607 .suspend = conexant_suspend,
608#endif
609 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100610};
611
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200612#ifdef CONFIG_SND_HDA_INPUT_BEEP
613#define set_beep_amp(spec, nid, idx, dir) \
614 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
615#else
616#define set_beep_amp(spec, nid, idx, dir) /* NOP */
617#endif
618
Takashi Iwai6764bce2011-05-13 16:52:25 +0200619static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100620/*
621 * EAPD control
622 * the private value = nid | (invert << 8)
623 */
624
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200625#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100626
Tobin Davis82f30042007-02-13 12:45:44 +0100627static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100628 struct snd_ctl_elem_value *ucontrol)
629{
630 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
631 struct conexant_spec *spec = codec->spec;
632 int invert = (kcontrol->private_value >> 8) & 1;
633 if (invert)
634 ucontrol->value.integer.value[0] = !spec->cur_eapd;
635 else
636 ucontrol->value.integer.value[0] = spec->cur_eapd;
637 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100638
Tobin Davisc9b443d2006-11-14 12:13:39 +0100639}
640
Tobin Davis82f30042007-02-13 12:45:44 +0100641static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100642 struct snd_ctl_elem_value *ucontrol)
643{
644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645 struct conexant_spec *spec = codec->spec;
646 int invert = (kcontrol->private_value >> 8) & 1;
647 hda_nid_t nid = kcontrol->private_value & 0xff;
648 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100649
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100650 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100651 if (invert)
652 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200653 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100654 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100655
Tobin Davisc9b443d2006-11-14 12:13:39 +0100656 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200657 snd_hda_codec_write_cache(codec, nid,
658 0, AC_VERB_SET_EAPD_BTLENABLE,
659 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100660 return 1;
661}
662
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100663/* controls for test mode */
664#ifdef CONFIG_SND_DEBUG
665
Tobin Davis82f30042007-02-13 12:45:44 +0100666#define CXT_EAPD_SWITCH(xname, nid, mask) \
667 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
668 .info = cxt_eapd_info, \
669 .get = cxt_eapd_get, \
670 .put = cxt_eapd_put, \
671 .private_value = nid | (mask<<16) }
672
673
674
Tobin Davisc9b443d2006-11-14 12:13:39 +0100675static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_info *uinfo)
677{
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct conexant_spec *spec = codec->spec;
680 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
681 spec->num_channel_mode);
682}
683
684static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
685 struct snd_ctl_elem_value *ucontrol)
686{
687 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
688 struct conexant_spec *spec = codec->spec;
689 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
690 spec->num_channel_mode,
691 spec->multiout.max_channels);
692}
693
694static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
695 struct snd_ctl_elem_value *ucontrol)
696{
697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
698 struct conexant_spec *spec = codec->spec;
699 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
700 spec->num_channel_mode,
701 &spec->multiout.max_channels);
702 if (err >= 0 && spec->need_dac_fix)
703 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
704 return err;
705}
706
707#define CXT_PIN_MODE(xname, nid, dir) \
708 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
709 .info = conexant_ch_mode_info, \
710 .get = conexant_ch_mode_get, \
711 .put = conexant_ch_mode_put, \
712 .private_value = nid | (dir<<16) }
713
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100714#endif /* CONFIG_SND_DEBUG */
715
Tobin Davisc9b443d2006-11-14 12:13:39 +0100716/* Conexant 5045 specific */
717
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200718static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
719static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
720static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100721#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200723static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100724 { 2, NULL },
725};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100726
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200727static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100728 .num_items = 2,
729 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100730 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100731 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100732 }
733};
734
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200735static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200736 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100737 .items = {
738 { "IntMic", 0x1 },
739 { "ExtMic", 0x2 },
740 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200741 { "CD", 0x4 },
742 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100743 }
744};
745
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200746static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100747 .num_items = 2,
748 .items = {
749 { "ExtMic", 0x1 },
750 { "IntMic", 0x2 },
751 }
752};
753
Tobin Davisc9b443d2006-11-14 12:13:39 +0100754/* turn on/off EAPD (+ mute HP) as a master switch */
755static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
756 struct snd_ctl_elem_value *ucontrol)
757{
758 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
759 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100760 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100761
Tobin Davis82f30042007-02-13 12:45:44 +0100762 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100763 return 0;
764
Tobin Davis82f30042007-02-13 12:45:44 +0100765 /* toggle internal speakers mute depending of presence of
766 * the headphone jack
767 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200768 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
769 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
770 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100771
Takashi Iwai47fd8302007-08-10 17:11:07 +0200772 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
773 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
774 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775 return 1;
776}
777
778/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200779static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200780 .ops = &snd_hda_bind_vol,
781 .values = {
782 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
783 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
784 0
785 },
786};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100787
Tobin Davis7f296732007-03-12 11:39:01 +0100788/* toggle input of built-in and mic jack appropriately */
789static void cxt5045_hp_automic(struct hda_codec *codec)
790{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200791 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100792 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
793 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
794 {}
795 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200796 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100797 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
798 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
799 {}
800 };
801 unsigned int present;
802
Takashi Iwaid56757a2009-11-18 08:00:14 +0100803 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100804 if (present)
805 snd_hda_sequence_write(codec, mic_jack_on);
806 else
807 snd_hda_sequence_write(codec, mic_jack_off);
808}
809
Tobin Davisc9b443d2006-11-14 12:13:39 +0100810
811/* mute internal speaker if HP is plugged */
812static void cxt5045_hp_automute(struct hda_codec *codec)
813{
Tobin Davis82f30042007-02-13 12:45:44 +0100814 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100815 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100816
Takashi Iwaid56757a2009-11-18 08:00:14 +0100817 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100818
Takashi Iwai47fd8302007-08-10 17:11:07 +0200819 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
820 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
821 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100822}
823
824/* unsolicited event for HP jack sensing */
825static void cxt5045_hp_unsol_event(struct hda_codec *codec,
826 unsigned int res)
827{
828 res >>= 26;
829 switch (res) {
830 case CONEXANT_HP_EVENT:
831 cxt5045_hp_automute(codec);
832 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100833 case CONEXANT_MIC_EVENT:
834 cxt5045_hp_automic(codec);
835 break;
836
Tobin Davisc9b443d2006-11-14 12:13:39 +0100837 }
838}
839
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200840static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100841 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
842 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100843 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
844 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200845 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
846 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100847 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
848 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100849 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
850 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200851 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100852 {
853 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
854 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100855 .info = cxt_eapd_info,
856 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100858 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100859 },
860
861 {}
862};
863
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200864static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200865 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
866 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
867 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
868 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
869
Jiang Zhe5218c892008-01-17 11:18:41 +0100870 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
871 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
872 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
873 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
874
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200875 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
876 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
877
Jiang Zhe5218c892008-01-17 11:18:41 +0100878 {}
879};
880
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200881static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100882 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
883 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100884 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
885 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100886 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
887 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100888 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
889 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100890 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
891 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100892 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
893 {
894 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
895 .name = "Master Playback Switch",
896 .info = cxt_eapd_info,
897 .get = cxt_eapd_get,
898 .put = cxt5045_hp_master_sw_put,
899 .private_value = 0x10,
900 },
901
902 {}
903};
904
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200905static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100906 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200907 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100908 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100909 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200910 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
911 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
912 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
913 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
915 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
917 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
918 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100919 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100920 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100921 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100922 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
923 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100924 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100925 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100927 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928 { } /* end */
929};
930
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200931static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100932 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100933 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
934 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
935 /* Line In,HP, Amp */
936 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
937 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
938 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
939 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
940 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
941 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
942 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
943 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
944 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100945 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100946 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
947 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
948 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
949 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100950 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100951 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
952 /* EAPD */
953 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
954 { } /* end */
955};
Tobin Davis7f296732007-03-12 11:39:01 +0100956
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200957static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100958 /* pin sensing on HP jack */
959 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200960 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100961};
962
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200963static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100964 /* pin sensing on HP jack */
965 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200966 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100967};
968
Tobin Davisc9b443d2006-11-14 12:13:39 +0100969#ifdef CONFIG_SND_DEBUG
970/* Test configuration for debugging, modelled after the ALC260 test
971 * configuration.
972 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200973static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100974 .num_items = 5,
975 .items = {
976 { "MIXER", 0x0 },
977 { "MIC1 pin", 0x1 },
978 { "LINE1 pin", 0x2 },
979 { "HP-OUT pin", 0x3 },
980 { "CD pin", 0x4 },
981 },
982};
983
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200984static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100985
986 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100987 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
988 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100989 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
990 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
991 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
992 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100993
994 /* Modes for retasking pin widgets */
995 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
996 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
997
Tobin Davis82f30042007-02-13 12:45:44 +0100998 /* EAPD Switch Control */
999 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1000
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002
Tobin Davis7f296732007-03-12 11:39:01 +01001003 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1004 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1005 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1006 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1007 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1008 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1009 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1010 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1011 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1012 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001013 {
1014 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1015 .name = "Input Source",
1016 .info = conexant_mux_enum_info,
1017 .get = conexant_mux_enum_get,
1018 .put = conexant_mux_enum_put,
1019 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001020 /* Audio input controls */
1021 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1022 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1023 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1024 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1025 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1026 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1027 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1028 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1029 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1030 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001031 { } /* end */
1032};
1033
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001034static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001035 /* Set connections */
1036 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1037 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1038 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001039 /* Enable retasking pins as output, initially without power amp */
1040 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001041 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001042
1043 /* Disable digital (SPDIF) pins initially, but users can enable
1044 * them via a mixer switch. In the case of SPDIF-out, this initverb
1045 * payload also sets the generation to 0, output to be in "consumer"
1046 * PCM format, copyright asserted, no pre-emphasis and no validity
1047 * control.
1048 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001049 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1050 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001051
1052 /* Start with output sum widgets muted and their output gains at min */
1053 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1054 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1055
1056 /* Unmute retasking pin widget output buffers since the default
1057 * state appears to be output. As the pin mode is changed by the
1058 * user the pin mode control will take care of enabling the pin's
1059 * input/output buffers as needed.
1060 */
1061 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1062 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1063
1064 /* Mute capture amp left and right */
1065 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1066
1067 /* Set ADC connection select to match default mixer setting (mic1
1068 * pin)
1069 */
1070 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001071 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072
1073 /* Mute all inputs to mixer widget (even unconnected ones) */
1074 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1075 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1076 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1077 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1078 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1079
1080 { }
1081};
1082#endif
1083
1084
1085/* initialize jack-sensing, too */
1086static int cxt5045_init(struct hda_codec *codec)
1087{
1088 conexant_init(codec);
1089 cxt5045_hp_automute(codec);
1090 return 0;
1091}
1092
1093
1094enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001095 CXT5045_LAPTOP_HPSENSE,
1096 CXT5045_LAPTOP_MICSENSE,
1097 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001098 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001099 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001100#ifdef CONFIG_SND_DEBUG
1101 CXT5045_TEST,
1102#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001103 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001104 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001105};
1106
Takashi Iwaiea734962011-01-17 11:29:34 +01001107static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001108 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1109 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1110 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1111 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001112 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001114 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001115#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001116 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001117};
1118
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001119static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001120 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001121 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1122 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001123 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001124 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001125 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1126 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001127 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1128 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001129 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1130 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1131 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001132 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1133 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001134 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135 {}
1136};
1137
1138static int patch_cxt5045(struct hda_codec *codec)
1139{
1140 struct conexant_spec *spec;
1141 int board_config;
1142
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001143 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1144 cxt5045_models,
1145 cxt5045_cfg_tbl);
1146 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001147 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001148 if (board_config == CXT5045_AUTO)
1149 return patch_conexant_auto(codec);
1150
Tobin Davisc9b443d2006-11-14 12:13:39 +01001151 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1152 if (!spec)
1153 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001154 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001155 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001156
1157 spec->multiout.max_channels = 2;
1158 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1159 spec->multiout.dac_nids = cxt5045_dac_nids;
1160 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1161 spec->num_adc_nids = 1;
1162 spec->adc_nids = cxt5045_adc_nids;
1163 spec->capsrc_nids = cxt5045_capsrc_nids;
1164 spec->input_mux = &cxt5045_capture_source;
1165 spec->num_mixers = 1;
1166 spec->mixers[0] = cxt5045_mixers;
1167 spec->num_init_verbs = 1;
1168 spec->init_verbs[0] = cxt5045_init_verbs;
1169 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001170 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1171 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001172
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001173 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001174
1175 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001176
Tobin Davisc9b443d2006-11-14 12:13:39 +01001177 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001178 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001179 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001180 spec->input_mux = &cxt5045_capture_source;
1181 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001182 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1183 spec->mixers[0] = cxt5045_mixers;
1184 codec->patch_ops.init = cxt5045_init;
1185 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001186 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001187 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001188 spec->input_mux = &cxt5045_capture_source;
1189 spec->num_init_verbs = 2;
1190 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191 spec->mixers[0] = cxt5045_mixers;
1192 codec->patch_ops.init = cxt5045_init;
1193 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001194 default:
1195 case CXT5045_LAPTOP_HPMICSENSE:
1196 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1197 spec->input_mux = &cxt5045_capture_source;
1198 spec->num_init_verbs = 3;
1199 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1200 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1201 spec->mixers[0] = cxt5045_mixers;
1202 codec->patch_ops.init = cxt5045_init;
1203 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001204 case CXT5045_BENQ:
1205 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1206 spec->input_mux = &cxt5045_capture_source_benq;
1207 spec->num_init_verbs = 1;
1208 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1209 spec->mixers[0] = cxt5045_mixers;
1210 spec->mixers[1] = cxt5045_benq_mixers;
1211 spec->num_mixers = 2;
1212 codec->patch_ops.init = cxt5045_init;
1213 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001214 case CXT5045_LAPTOP_HP530:
1215 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1216 spec->input_mux = &cxt5045_capture_source_hp530;
1217 spec->num_init_verbs = 2;
1218 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1219 spec->mixers[0] = cxt5045_mixers_hp530;
1220 codec->patch_ops.init = cxt5045_init;
1221 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001222#ifdef CONFIG_SND_DEBUG
1223 case CXT5045_TEST:
1224 spec->input_mux = &cxt5045_test_capture_source;
1225 spec->mixers[0] = cxt5045_test_mixer;
1226 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001227 break;
1228
Tobin Davisc9b443d2006-11-14 12:13:39 +01001229#endif
1230 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001231
Takashi Iwai031005f2008-06-26 14:49:58 +02001232 switch (codec->subsystem_id >> 16) {
1233 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001234 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001235 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001236 case 0x17aa:
1237 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1238 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1239 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001240 */
1241 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1242 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1243 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1244 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1245 (1 << AC_AMPCAP_MUTE_SHIFT));
1246 break;
1247 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001248
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001249 if (spec->beep_amp)
1250 snd_hda_attach_beep_device(codec, spec->beep_amp);
1251
Tobin Davisc9b443d2006-11-14 12:13:39 +01001252 return 0;
1253}
1254
1255
1256/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001257#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001258
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001259static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1260static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1261static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001263static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001264 { 2, NULL },
1265};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001266
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001267static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001268 .num_items = 2,
1269 .items = {
1270 { "ExtMic", 0x2 },
1271 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001272 }
1273};
1274
1275/* turn on/off EAPD (+ mute HP) as a master switch */
1276static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1277 struct snd_ctl_elem_value *ucontrol)
1278{
1279 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1280 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001281 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282
Tobin Davis82f30042007-02-13 12:45:44 +01001283 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001284 return 0;
1285
Tobin Davis82f30042007-02-13 12:45:44 +01001286 /* toggle internal speakers mute depending of presence of
1287 * the headphone jack
1288 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001289 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001290 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1291 * pin widgets unlike other codecs. In this case, we need to
1292 * set index 0x01 for the volume from the mixer amp 0x19.
1293 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001294 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001295 HDA_AMP_MUTE, bits);
1296 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1297 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1298 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001299 return 1;
1300}
1301
Tobin Davisc9b443d2006-11-14 12:13:39 +01001302/* mute internal speaker if HP is plugged */
1303static void cxt5047_hp_automute(struct hda_codec *codec)
1304{
Tobin Davis82f30042007-02-13 12:45:44 +01001305 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001306 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001307
Takashi Iwaid56757a2009-11-18 08:00:14 +01001308 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001309
Takashi Iwai47fd8302007-08-10 17:11:07 +02001310 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001311 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001312 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001313 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001314}
1315
1316/* toggle input of built-in and mic jack appropriately */
1317static void cxt5047_hp_automic(struct hda_codec *codec)
1318{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001319 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001320 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1321 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001322 {}
1323 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001324 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001325 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1326 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327 {}
1328 };
1329 unsigned int present;
1330
Takashi Iwaid56757a2009-11-18 08:00:14 +01001331 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332 if (present)
1333 snd_hda_sequence_write(codec, mic_jack_on);
1334 else
1335 snd_hda_sequence_write(codec, mic_jack_off);
1336}
1337
1338/* unsolicited event for HP jack sensing */
1339static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1340 unsigned int res)
1341{
Marc Boucher9f113e02008-01-22 15:18:08 +01001342 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001343 case CONEXANT_HP_EVENT:
1344 cxt5047_hp_automute(codec);
1345 break;
1346 case CONEXANT_MIC_EVENT:
1347 cxt5047_hp_automic(codec);
1348 break;
1349 }
1350}
1351
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001352static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001353 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1354 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001355 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001356 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1357 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1358 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001360 {
1361 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1362 .name = "Master Playback Switch",
1363 .info = cxt_eapd_info,
1364 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001365 .put = cxt5047_hp_master_sw_put,
1366 .private_value = 0x13,
1367 },
1368
1369 {}
1370};
1371
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001372static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001373 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001374 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001375 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1376 {}
1377};
1378
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001379static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001380 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 { } /* end */
1382};
1383
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001384static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001385 /* Line in, Mic, Built-in Mic */
1386 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1387 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1388 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001389 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001390 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001391 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1392 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001393 /* Record selector: Mic */
1394 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1395 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1396 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1397 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001398 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1399 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1400 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1401 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402 /* SPDIF route: PCM */
1403 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001404 /* Enable unsolicited events */
1405 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1406 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001407 { } /* end */
1408};
1409
1410/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001411static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001412 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001413 {}
1414};
1415
1416/* Test configuration for debugging, modelled after the ALC260 test
1417 * configuration.
1418 */
1419#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001420static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001421 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001422 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001423 { "LINE1 pin", 0x0 },
1424 { "MIC1 pin", 0x1 },
1425 { "MIC2 pin", 0x2 },
1426 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001427 },
1428};
1429
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001430static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001431
1432 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001433 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1434 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1435 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1436 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001437 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1438 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1439 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1440 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001441 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1442 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1443 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1444 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001445
1446 /* Modes for retasking pin widgets */
1447 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1448 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1449
Tobin Davis82f30042007-02-13 12:45:44 +01001450 /* EAPD Switch Control */
1451 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1452
Tobin Davisc9b443d2006-11-14 12:13:39 +01001453 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001454 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1455 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1456 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1457 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1458 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1459 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1460 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1461 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001462
Tobin Davis82f30042007-02-13 12:45:44 +01001463 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1464 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1465 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1466 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1467 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1468 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1469 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1470 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001471 {
1472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1473 .name = "Input Source",
1474 .info = conexant_mux_enum_info,
1475 .get = conexant_mux_enum_get,
1476 .put = conexant_mux_enum_put,
1477 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001478 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001479
Tobin Davisc9b443d2006-11-14 12:13:39 +01001480 { } /* end */
1481};
1482
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001483static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001484 /* Enable retasking pins as output, initially without power amp */
1485 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488
1489 /* Disable digital (SPDIF) pins initially, but users can enable
1490 * them via a mixer switch. In the case of SPDIF-out, this initverb
1491 * payload also sets the generation to 0, output to be in "consumer"
1492 * PCM format, copyright asserted, no pre-emphasis and no validity
1493 * control.
1494 */
1495 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1496
1497 /* Ensure mic1, mic2, line1 pin widgets take input from the
1498 * OUT1 sum bus when acting as an output.
1499 */
1500 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1501 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1502
1503 /* Start with output sum widgets muted and their output gains at min */
1504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1506
1507 /* Unmute retasking pin widget output buffers since the default
1508 * state appears to be output. As the pin mode is changed by the
1509 * user the pin mode control will take care of enabling the pin's
1510 * input/output buffers as needed.
1511 */
1512 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515
1516 /* Mute capture amp left and right */
1517 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1518
1519 /* Set ADC connection select to match default mixer setting (mic1
1520 * pin)
1521 */
1522 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1523
1524 /* Mute all inputs to mixer widget (even unconnected ones) */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1533
1534 { }
1535};
1536#endif
1537
1538
1539/* initialize jack-sensing, too */
1540static int cxt5047_hp_init(struct hda_codec *codec)
1541{
1542 conexant_init(codec);
1543 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544 return 0;
1545}
1546
1547
1548enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001549 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1550 CXT5047_LAPTOP_HP, /* Some HP laptops */
1551 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552#ifdef CONFIG_SND_DEBUG
1553 CXT5047_TEST,
1554#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001555 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001556 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557};
1558
Takashi Iwaiea734962011-01-17 11:29:34 +01001559static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001560 [CXT5047_LAPTOP] = "laptop",
1561 [CXT5047_LAPTOP_HP] = "laptop-hp",
1562 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001563#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001564 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001565#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001566 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001567};
1568
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001569static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001570 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001571 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1572 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001573 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001574 {}
1575};
1576
1577static int patch_cxt5047(struct hda_codec *codec)
1578{
1579 struct conexant_spec *spec;
1580 int board_config;
1581
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001582 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1583 cxt5047_models,
1584 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001585 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001586 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001587 if (board_config == CXT5047_AUTO)
1588 return patch_conexant_auto(codec);
1589
Tobin Davisc9b443d2006-11-14 12:13:39 +01001590 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1591 if (!spec)
1592 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001593 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001594 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001595
1596 spec->multiout.max_channels = 2;
1597 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1598 spec->multiout.dac_nids = cxt5047_dac_nids;
1599 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1600 spec->num_adc_nids = 1;
1601 spec->adc_nids = cxt5047_adc_nids;
1602 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001603 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001604 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001605 spec->num_init_verbs = 1;
1606 spec->init_verbs[0] = cxt5047_init_verbs;
1607 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001608 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1609 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610
1611 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001612
Tobin Davisc9b443d2006-11-14 12:13:39 +01001613 switch (board_config) {
1614 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001615 spec->num_mixers = 2;
1616 spec->mixers[1] = cxt5047_hp_spk_mixers;
1617 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001618 break;
1619 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001620 spec->num_mixers = 2;
1621 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001622 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001623 codec->patch_ops.init = cxt5047_hp_init;
1624 break;
1625 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001626 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001627 spec->num_mixers = 2;
1628 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001629 spec->num_init_verbs = 2;
1630 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001631 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001632 break;
1633#ifdef CONFIG_SND_DEBUG
1634 case CXT5047_TEST:
1635 spec->input_mux = &cxt5047_test_capture_source;
1636 spec->mixers[0] = cxt5047_test_mixer;
1637 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001639#endif
1640 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001641 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001642
1643 switch (codec->subsystem_id >> 16) {
1644 case 0x103c:
1645 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1646 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1647 * with 0 dB offset 0x17)
1648 */
1649 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1650 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1651 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1652 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1653 (1 << AC_AMPCAP_MUTE_SHIFT));
1654 break;
1655 }
1656
Tobin Davisc9b443d2006-11-14 12:13:39 +01001657 return 0;
1658}
1659
Takashi Iwai461e2c72008-01-25 11:35:17 +01001660/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001661static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1662static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001663
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001664static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001665 { 2, NULL },
1666};
1667
1668static void cxt5051_update_speaker(struct hda_codec *codec)
1669{
1670 struct conexant_spec *spec = codec->spec;
1671 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001672 /* headphone pin */
1673 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1674 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1675 pinctl);
1676 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001677 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1678 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1679 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001680 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1681 if (spec->ideapad)
1682 snd_hda_codec_write(codec, 0x1b, 0,
1683 AC_VERB_SET_PIN_WIDGET_CONTROL,
1684 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001685}
1686
1687/* turn on/off EAPD (+ mute HP) as a master switch */
1688static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1689 struct snd_ctl_elem_value *ucontrol)
1690{
1691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1692
1693 if (!cxt_eapd_put(kcontrol, ucontrol))
1694 return 0;
1695 cxt5051_update_speaker(codec);
1696 return 1;
1697}
1698
1699/* toggle input of built-in and mic jack appropriately */
1700static void cxt5051_portb_automic(struct hda_codec *codec)
1701{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001702 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001703 unsigned int present;
1704
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001705 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001706 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001707 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001708 snd_hda_codec_write(codec, 0x14, 0,
1709 AC_VERB_SET_CONNECT_SEL,
1710 present ? 0x01 : 0x00);
1711}
1712
1713/* switch the current ADC according to the jack state */
1714static void cxt5051_portc_automic(struct hda_codec *codec)
1715{
1716 struct conexant_spec *spec = codec->spec;
1717 unsigned int present;
1718 hda_nid_t new_adc;
1719
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001720 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001721 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001722 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723 if (present)
1724 spec->cur_adc_idx = 1;
1725 else
1726 spec->cur_adc_idx = 0;
1727 new_adc = spec->adc_nids[spec->cur_adc_idx];
1728 if (spec->cur_adc && spec->cur_adc != new_adc) {
1729 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001730 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001731 spec->cur_adc = new_adc;
1732 snd_hda_codec_setup_stream(codec, new_adc,
1733 spec->cur_adc_stream_tag, 0,
1734 spec->cur_adc_format);
1735 }
1736}
1737
1738/* mute internal speaker if HP is plugged */
1739static void cxt5051_hp_automute(struct hda_codec *codec)
1740{
1741 struct conexant_spec *spec = codec->spec;
1742
Takashi Iwaid56757a2009-11-18 08:00:14 +01001743 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001744 cxt5051_update_speaker(codec);
1745}
1746
1747/* unsolicited event for HP jack sensing */
1748static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1749 unsigned int res)
1750{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001751 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001752 switch (res >> 26) {
1753 case CONEXANT_HP_EVENT:
1754 cxt5051_hp_automute(codec);
1755 break;
1756 case CXT5051_PORTB_EVENT:
1757 cxt5051_portb_automic(codec);
1758 break;
1759 case CXT5051_PORTC_EVENT:
1760 cxt5051_portc_automic(codec);
1761 break;
1762 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001763 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001764}
1765
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001766static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001767 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1768 {
1769 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1770 .name = "Master Playback Switch",
1771 .info = cxt_eapd_info,
1772 .get = cxt_eapd_get,
1773 .put = cxt5051_hp_master_sw_put,
1774 .private_value = 0x1a,
1775 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001776 {}
1777};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001778
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001779static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001780 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1781 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001782 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1783 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001784 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1785 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001786 {}
1787};
1788
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001789static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001790 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1791 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001792 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1793 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001794 {}
1795};
1796
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001797static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001798 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1799 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001800 {}
1801};
1802
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001803static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001804 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1805 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001806 {}
1807};
1808
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001809static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001810 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1811 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001812 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1813 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001814 {}
1815};
1816
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001817static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001818 /* Line in, Mic */
1819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1820 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1821 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1822 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1823 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1824 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1825 /* SPK */
1826 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1827 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1828 /* HP, Amp */
1829 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1830 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1831 /* DAC1 */
1832 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001833 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001834 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1835 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1836 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1837 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001838 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001839 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1840 /* EAPD */
1841 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1842 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001843 { } /* end */
1844};
1845
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001846static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001847 /* Line in, Mic */
1848 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1849 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1850 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1851 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1852 /* SPK */
1853 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1854 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1855 /* HP, Amp */
1856 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1857 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1858 /* DAC1 */
1859 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001860 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001861 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1862 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1863 /* SPDIF route: PCM */
1864 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1865 /* EAPD */
1866 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1867 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001868 { } /* end */
1869};
1870
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001871static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001872 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001873 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001874 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1875 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1876 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1877 /* SPK */
1878 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1879 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1880 /* HP, Amp */
1881 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1882 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1883 /* DAC1 */
1884 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001885 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1887 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1888 /* SPDIF route: PCM */
1889 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1890 /* EAPD */
1891 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1892 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001893 { } /* end */
1894};
1895
Takashi Iwai6953e552010-01-24 11:00:27 +01001896static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1897 unsigned int event)
1898{
1899 snd_hda_codec_write(codec, nid, 0,
1900 AC_VERB_SET_UNSOLICITED_ENABLE,
1901 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001902 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1903 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001904}
1905
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001906static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001907 /* Subwoofer */
1908 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1909 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1910 { } /* end */
1911};
1912
Takashi Iwai461e2c72008-01-25 11:35:17 +01001913/* initialize jack-sensing, too */
1914static int cxt5051_init(struct hda_codec *codec)
1915{
Takashi Iwai6953e552010-01-24 11:00:27 +01001916 struct conexant_spec *spec = codec->spec;
1917
Takashi Iwai461e2c72008-01-25 11:35:17 +01001918 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001919 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001920
1921 if (spec->auto_mic & AUTO_MIC_PORTB)
1922 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1923 if (spec->auto_mic & AUTO_MIC_PORTC)
1924 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1925
Takashi Iwai461e2c72008-01-25 11:35:17 +01001926 if (codec->patch_ops.unsol_event) {
1927 cxt5051_hp_automute(codec);
1928 cxt5051_portb_automic(codec);
1929 cxt5051_portc_automic(codec);
1930 }
1931 return 0;
1932}
1933
1934
1935enum {
1936 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1937 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001938 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001939 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001940 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001941 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001942 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001943 CXT5051_MODELS
1944};
1945
Takashi Iwaiea734962011-01-17 11:29:34 +01001946static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001947 [CXT5051_LAPTOP] = "laptop",
1948 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001949 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001950 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001951 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001952 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001953 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001954};
1955
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001956static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001957 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001958 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001959 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001960 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001961 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1962 CXT5051_LAPTOP),
1963 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001964 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001965 {}
1966};
1967
1968static int patch_cxt5051(struct hda_codec *codec)
1969{
1970 struct conexant_spec *spec;
1971 int board_config;
1972
Takashi Iwai6764bce2011-05-13 16:52:25 +02001973 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1974 cxt5051_models,
1975 cxt5051_cfg_tbl);
1976 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001977 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001978 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001979 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001980
Takashi Iwai461e2c72008-01-25 11:35:17 +01001981 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1982 if (!spec)
1983 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001984 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001985 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001986
1987 codec->patch_ops = conexant_patch_ops;
1988 codec->patch_ops.init = cxt5051_init;
1989
1990 spec->multiout.max_channels = 2;
1991 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1992 spec->multiout.dac_nids = cxt5051_dac_nids;
1993 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1994 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1995 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001996 spec->num_mixers = 2;
1997 spec->mixers[0] = cxt5051_capture_mixers;
1998 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001999 spec->num_init_verbs = 1;
2000 spec->init_verbs[0] = cxt5051_init_verbs;
2001 spec->spdif_route = 0;
2002 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2003 spec->channel_mode = cxt5051_modes;
2004 spec->cur_adc = 0;
2005 spec->cur_adc_idx = 0;
2006
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002007 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2008
Takashi Iwai79d7d532009-03-04 09:03:50 +01002009 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2010
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002011 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002012 switch (board_config) {
2013 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002014 spec->mixers[0] = cxt5051_hp_mixers;
2015 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002016 case CXT5051_HP_DV6736:
2017 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2018 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002019 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002020 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002021 case CXT5051_F700:
2022 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2023 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002024 spec->auto_mic = 0;
2025 break;
2026 case CXT5051_TOSHIBA:
2027 spec->mixers[0] = cxt5051_toshiba_mixers;
2028 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002029 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03002030 case CXT5051_IDEAPAD:
2031 spec->init_verbs[spec->num_init_verbs++] =
2032 cxt5051_ideapad_init_verbs;
2033 spec->ideapad = 1;
2034 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002035 }
2036
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002037 if (spec->beep_amp)
2038 snd_hda_attach_beep_device(codec, spec->beep_amp);
2039
Takashi Iwai461e2c72008-01-25 11:35:17 +01002040 return 0;
2041}
2042
Daniel Drake0fb67e92009-07-16 14:46:57 +01002043/* Conexant 5066 specific */
2044
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002045static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2046static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2047static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2048static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002049
Daniel Drakedbaccc02009-11-09 15:17:24 +00002050/* OLPC's microphone port is DC coupled for use with external sensors,
2051 * therefore we use a 50% mic bias in order to center the input signal with
2052 * the DC input range of the codec. */
2053#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2054
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002055static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002056 { 2, NULL },
2057};
2058
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002059#define HP_PRESENT_PORT_A (1 << 0)
2060#define HP_PRESENT_PORT_D (1 << 1)
2061#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2062#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2063
Daniel Drake0fb67e92009-07-16 14:46:57 +01002064static void cxt5066_update_speaker(struct hda_codec *codec)
2065{
2066 struct conexant_spec *spec = codec->spec;
2067 unsigned int pinctl;
2068
John Baboval3a253442010-12-02 11:21:31 -05002069 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2070 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002071
2072 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002073 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002074 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2075 pinctl);
2076
2077 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002078 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2079 if (spec->dell_automute || spec->thinkpad) {
2080 /* Mute if Port A is connected */
2081 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002082 pinctl = 0;
2083 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002084 /* Thinkpad/Dell doesn't give pin-D status */
2085 if (!hp_port_d_present(spec))
2086 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002087 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002088 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2089 pinctl);
2090
2091 /* CLASS_D AMP */
2092 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2093 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2094 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002095}
2096
2097/* turn on/off EAPD (+ mute HP) as a master switch */
2098static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2099 struct snd_ctl_elem_value *ucontrol)
2100{
2101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2102
2103 if (!cxt_eapd_put(kcontrol, ucontrol))
2104 return 0;
2105
2106 cxt5066_update_speaker(codec);
2107 return 1;
2108}
2109
Daniel Drakec4cfe662010-01-07 13:47:04 +01002110static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2111 .num_items = 3,
2112 .items = {
2113 { "Off", PIN_IN },
2114 { "50%", PIN_VREF50 },
2115 { "80%", PIN_VREF80 },
2116 },
2117};
2118
2119static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2120{
2121 struct conexant_spec *spec = codec->spec;
2122 /* Even though port F is the DC input, the bias is controlled on port B.
2123 * we also leave that port as an active input (but unselected) in DC mode
2124 * just in case that is necessary to make the bias setting take effect. */
2125 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2126 AC_VERB_SET_PIN_WIDGET_CONTROL,
2127 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2128}
2129
Daniel Drake75f89912010-01-07 13:46:25 +01002130/* OLPC defers mic widget control until when capture is started because the
2131 * microphone LED comes on as soon as these settings are put in place. if we
2132 * did this before recording, it would give the false indication that recording
2133 * is happening when it is not. */
2134static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002135{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002136 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002137 if (!spec->recording)
2138 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002139
Daniel Drakec4cfe662010-01-07 13:47:04 +01002140 if (spec->dc_enable) {
2141 /* in DC mode we ignore presence detection and just use the jack
2142 * through our special DC port */
2143 const struct hda_verb enable_dc_mode[] = {
2144 /* disble internal mic, port C */
2145 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2146
2147 /* enable DC capture, port F */
2148 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2149 {},
2150 };
2151
2152 snd_hda_sequence_write(codec, enable_dc_mode);
2153 /* port B input disabled (and bias set) through the following call */
2154 cxt5066_set_olpc_dc_bias(codec);
2155 return;
2156 }
2157
2158 /* disable DC (port F) */
2159 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2160
Daniel Drake75f89912010-01-07 13:46:25 +01002161 /* external mic, port B */
2162 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2163 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002164
Daniel Drake75f89912010-01-07 13:46:25 +01002165 /* internal mic, port C */
2166 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2167 spec->ext_mic_present ? 0 : PIN_VREF80);
2168}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002169
Daniel Drake75f89912010-01-07 13:46:25 +01002170/* toggle input of built-in and mic jack appropriately */
2171static void cxt5066_olpc_automic(struct hda_codec *codec)
2172{
2173 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002174 unsigned int present;
2175
Daniel Drakec4cfe662010-01-07 13:47:04 +01002176 if (spec->dc_enable) /* don't do presence detection in DC mode */
2177 return;
2178
Daniel Drake75f89912010-01-07 13:46:25 +01002179 present = snd_hda_codec_read(codec, 0x1a, 0,
2180 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2181 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002182 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002183 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002184 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002185
2186 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2187 present ? 0 : 1);
2188 spec->ext_mic_present = !!present;
2189
2190 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002191}
2192
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002193/* toggle input of built-in digital mic and mic jack appropriately */
2194static void cxt5066_vostro_automic(struct hda_codec *codec)
2195{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002196 unsigned int present;
2197
2198 struct hda_verb ext_mic_present[] = {
2199 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002200 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002201
2202 /* switch to external mic input */
2203 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2204 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2205
2206 /* disable internal digital mic */
2207 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2208 {}
2209 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002210 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002211 /* enable internal mic, port C */
2212 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2213
2214 /* switch to internal mic input */
2215 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2216
2217 /* disable external mic, port B */
2218 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2219 {}
2220 };
2221
2222 present = snd_hda_jack_detect(codec, 0x1a);
2223 if (present) {
2224 snd_printdd("CXT5066: external microphone detected\n");
2225 snd_hda_sequence_write(codec, ext_mic_present);
2226 } else {
2227 snd_printdd("CXT5066: external microphone absent\n");
2228 snd_hda_sequence_write(codec, ext_mic_absent);
2229 }
2230}
2231
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002232/* toggle input of built-in digital mic and mic jack appropriately */
2233static void cxt5066_ideapad_automic(struct hda_codec *codec)
2234{
2235 unsigned int present;
2236
2237 struct hda_verb ext_mic_present[] = {
2238 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2239 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2240 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2241 {}
2242 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002243 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002244 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2245 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2246 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2247 {}
2248 };
2249
2250 present = snd_hda_jack_detect(codec, 0x1b);
2251 if (present) {
2252 snd_printdd("CXT5066: external microphone detected\n");
2253 snd_hda_sequence_write(codec, ext_mic_present);
2254 } else {
2255 snd_printdd("CXT5066: external microphone absent\n");
2256 snd_hda_sequence_write(codec, ext_mic_absent);
2257 }
2258}
2259
David Henningssona1d69062011-01-21 13:33:28 +01002260
2261/* toggle input of built-in digital mic and mic jack appropriately */
2262static void cxt5066_asus_automic(struct hda_codec *codec)
2263{
2264 unsigned int present;
2265
2266 present = snd_hda_jack_detect(codec, 0x1b);
2267 snd_printdd("CXT5066: external microphone present=%d\n", present);
2268 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2269 present ? 1 : 0);
2270}
2271
2272
David Henningsson048e78a2010-09-02 08:35:47 +02002273/* toggle input of built-in digital mic and mic jack appropriately */
2274static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2275{
2276 unsigned int present;
2277
2278 present = snd_hda_jack_detect(codec, 0x1b);
2279 snd_printdd("CXT5066: external microphone present=%d\n", present);
2280 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2281 present ? 1 : 3);
2282}
2283
2284
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002285/* toggle input of built-in digital mic and mic jack appropriately
2286 order is: external mic -> dock mic -> interal mic */
2287static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2288{
2289 unsigned int ext_present, dock_present;
2290
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002291 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002292 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2293 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2294 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2295 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2296 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2297 {}
2298 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002299 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002300 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2301 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2302 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2303 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2304 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2305 {}
2306 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002307 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002308 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2309 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2310 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2311 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2312 {}
2313 };
2314
2315 ext_present = snd_hda_jack_detect(codec, 0x1b);
2316 dock_present = snd_hda_jack_detect(codec, 0x1a);
2317 if (ext_present) {
2318 snd_printdd("CXT5066: external microphone detected\n");
2319 snd_hda_sequence_write(codec, ext_mic_present);
2320 } else if (dock_present) {
2321 snd_printdd("CXT5066: dock microphone detected\n");
2322 snd_hda_sequence_write(codec, dock_mic_present);
2323 } else {
2324 snd_printdd("CXT5066: external microphone absent\n");
2325 snd_hda_sequence_write(codec, ext_mic_absent);
2326 }
2327}
2328
Daniel Drake0fb67e92009-07-16 14:46:57 +01002329/* mute internal speaker if HP is plugged */
2330static void cxt5066_hp_automute(struct hda_codec *codec)
2331{
2332 struct conexant_spec *spec = codec->spec;
2333 unsigned int portA, portD;
2334
2335 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002336 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002337
2338 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002339 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002340
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002341 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2342 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002343 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2344 portA, portD, spec->hp_present);
2345 cxt5066_update_speaker(codec);
2346}
2347
David Henningsson02b6b5b2011-01-21 13:27:39 +01002348/* Dispatch the right mic autoswitch function */
2349static void cxt5066_automic(struct hda_codec *codec)
2350{
2351 struct conexant_spec *spec = codec->spec;
2352
2353 if (spec->dell_vostro)
2354 cxt5066_vostro_automic(codec);
2355 else if (spec->ideapad)
2356 cxt5066_ideapad_automic(codec);
2357 else if (spec->thinkpad)
2358 cxt5066_thinkpad_automic(codec);
2359 else if (spec->hp_laptop)
2360 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002361 else if (spec->asus)
2362 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002363}
2364
Daniel Drake0fb67e92009-07-16 14:46:57 +01002365/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002366static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002368 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002369 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2370 switch (res >> 26) {
2371 case CONEXANT_HP_EVENT:
2372 cxt5066_hp_automute(codec);
2373 break;
2374 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002375 /* ignore mic events in DC mode; we're always using the jack */
2376 if (!spec->dc_enable)
2377 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002378 break;
2379 }
2380}
2381
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002382/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002383static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002384{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002385 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002386 switch (res >> 26) {
2387 case CONEXANT_HP_EVENT:
2388 cxt5066_hp_automute(codec);
2389 break;
2390 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002391 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002392 break;
2393 }
2394}
2395
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002396
Daniel Drake0fb67e92009-07-16 14:46:57 +01002397static const struct hda_input_mux cxt5066_analog_mic_boost = {
2398 .num_items = 5,
2399 .items = {
2400 { "0dB", 0 },
2401 { "10dB", 1 },
2402 { "20dB", 2 },
2403 { "30dB", 3 },
2404 { "40dB", 4 },
2405 },
2406};
2407
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002408static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002409{
2410 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002411 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002412 AC_VERB_SET_AMP_GAIN_MUTE,
2413 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2414 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002415 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002416 /* adjust the internal mic as well...it is not through 0x17 */
2417 snd_hda_codec_write_cache(codec, 0x23, 0,
2418 AC_VERB_SET_AMP_GAIN_MUTE,
2419 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2420 cxt5066_analog_mic_boost.
2421 items[spec->mic_boost].index);
2422 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002423}
2424
Daniel Drake0fb67e92009-07-16 14:46:57 +01002425static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2426 struct snd_ctl_elem_info *uinfo)
2427{
2428 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2429}
2430
2431static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2432 struct snd_ctl_elem_value *ucontrol)
2433{
2434 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002435 struct conexant_spec *spec = codec->spec;
2436 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002437 return 0;
2438}
2439
2440static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2441 struct snd_ctl_elem_value *ucontrol)
2442{
2443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002444 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002445 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2446 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002447 idx = ucontrol->value.enumerated.item[0];
2448 if (idx >= imux->num_items)
2449 idx = imux->num_items - 1;
2450
Daniel Drakec4cfe662010-01-07 13:47:04 +01002451 spec->mic_boost = idx;
2452 if (!spec->dc_enable)
2453 cxt5066_set_mic_boost(codec);
2454 return 1;
2455}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002456
Daniel Drakec4cfe662010-01-07 13:47:04 +01002457static void cxt5066_enable_dc(struct hda_codec *codec)
2458{
2459 const struct hda_verb enable_dc_mode[] = {
2460 /* disable gain */
2461 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2462
2463 /* switch to DC input */
2464 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2465 {}
2466 };
2467
2468 /* configure as input source */
2469 snd_hda_sequence_write(codec, enable_dc_mode);
2470 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2471}
2472
2473static void cxt5066_disable_dc(struct hda_codec *codec)
2474{
2475 /* reconfigure input source */
2476 cxt5066_set_mic_boost(codec);
2477 /* automic also selects the right mic if we're recording */
2478 cxt5066_olpc_automic(codec);
2479}
2480
2481static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2482 struct snd_ctl_elem_value *ucontrol)
2483{
2484 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2485 struct conexant_spec *spec = codec->spec;
2486 ucontrol->value.integer.value[0] = spec->dc_enable;
2487 return 0;
2488}
2489
2490static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2491 struct snd_ctl_elem_value *ucontrol)
2492{
2493 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2494 struct conexant_spec *spec = codec->spec;
2495 int dc_enable = !!ucontrol->value.integer.value[0];
2496
2497 if (dc_enable == spec->dc_enable)
2498 return 0;
2499
2500 spec->dc_enable = dc_enable;
2501 if (dc_enable)
2502 cxt5066_enable_dc(codec);
2503 else
2504 cxt5066_disable_dc(codec);
2505
2506 return 1;
2507}
2508
2509static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2510 struct snd_ctl_elem_info *uinfo)
2511{
2512 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2513}
2514
2515static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2516 struct snd_ctl_elem_value *ucontrol)
2517{
2518 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2519 struct conexant_spec *spec = codec->spec;
2520 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2521 return 0;
2522}
2523
2524static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2525 struct snd_ctl_elem_value *ucontrol)
2526{
2527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2528 struct conexant_spec *spec = codec->spec;
2529 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2530 unsigned int idx;
2531
2532 idx = ucontrol->value.enumerated.item[0];
2533 if (idx >= imux->num_items)
2534 idx = imux->num_items - 1;
2535
2536 spec->dc_input_bias = idx;
2537 if (spec->dc_enable)
2538 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002539 return 1;
2540}
2541
Daniel Drake75f89912010-01-07 13:46:25 +01002542static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2543{
2544 struct conexant_spec *spec = codec->spec;
2545 /* mark as recording and configure the microphone widget so that the
2546 * recording LED comes on. */
2547 spec->recording = 1;
2548 cxt5066_olpc_select_mic(codec);
2549}
2550
2551static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2552{
2553 struct conexant_spec *spec = codec->spec;
2554 const struct hda_verb disable_mics[] = {
2555 /* disable external mic, port B */
2556 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2557
2558 /* disble internal mic, port C */
2559 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002560
2561 /* disable DC capture, port F */
2562 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002563 {},
2564 };
2565
2566 snd_hda_sequence_write(codec, disable_mics);
2567 spec->recording = 0;
2568}
2569
Andy Robinsonf6a24912011-01-24 10:12:37 -05002570static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002571 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002572 int num_pins)
2573{
2574 struct conexant_spec *spec = codec->spec;
2575 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2576 int i;
2577
2578 for (i = 0; i < num_pins; i++, dig_pins++) {
2579 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2580 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2581 continue;
2582 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2583 continue;
2584 if (spec->slave_dig_outs[0])
2585 nid_loc++;
2586 else
2587 nid_loc = spec->slave_dig_outs;
2588 }
2589}
2590
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002591static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002592 .num_items = 4,
2593 .items = {
2594 { "Mic B", 0 },
2595 { "Mic C", 1 },
2596 { "Mic E", 2 },
2597 { "Mic F", 3 },
2598 },
2599};
2600
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002601static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002602 .ops = &snd_hda_bind_vol,
2603 .values = {
2604 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2605 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2606 0
2607 },
2608};
2609
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002610static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002611 .ops = &snd_hda_bind_sw,
2612 .values = {
2613 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2614 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2615 0
2616 },
2617};
2618
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002619static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002620 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2621 {}
2622};
2623
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002624static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002625 {
2626 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2627 .name = "Master Playback Volume",
2628 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2629 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2630 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002631 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002632 .info = snd_hda_mixer_amp_volume_info,
2633 .get = snd_hda_mixer_amp_volume_get,
2634 .put = snd_hda_mixer_amp_volume_put,
2635 .tlv = { .c = snd_hda_mixer_amp_tlv },
2636 /* offset by 28 volume steps to limit minimum gain to -46dB */
2637 .private_value =
2638 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2639 },
2640 {}
2641};
2642
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002643static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002644 {
2645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2646 .name = "DC Mode Enable Switch",
2647 .info = snd_ctl_boolean_mono_info,
2648 .get = cxt5066_olpc_dc_get,
2649 .put = cxt5066_olpc_dc_put,
2650 },
2651 {
2652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2653 .name = "DC Input Bias Enum",
2654 .info = cxt5066_olpc_dc_bias_enum_info,
2655 .get = cxt5066_olpc_dc_bias_enum_get,
2656 .put = cxt5066_olpc_dc_bias_enum_put,
2657 },
2658 {}
2659};
2660
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002661static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002662 {
2663 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2664 .name = "Master Playback Switch",
2665 .info = cxt_eapd_info,
2666 .get = cxt_eapd_get,
2667 .put = cxt5066_hp_master_sw_put,
2668 .private_value = 0x1d,
2669 },
2670
2671 {
2672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002673 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002674 .info = cxt5066_mic_boost_mux_enum_info,
2675 .get = cxt5066_mic_boost_mux_enum_get,
2676 .put = cxt5066_mic_boost_mux_enum_put,
2677 },
2678
2679 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2680 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2681 {}
2682};
2683
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002684static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002685 {
2686 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002687 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002688 .info = cxt5066_mic_boost_mux_enum_info,
2689 .get = cxt5066_mic_boost_mux_enum_get,
2690 .put = cxt5066_mic_boost_mux_enum_put,
2691 .private_value = 0x23 | 0x100,
2692 },
2693 {}
2694};
2695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002696static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002697 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2698 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2699 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2700 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2701
2702 /* Speakers */
2703 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2704 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2705
2706 /* HP, Amp */
2707 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2708 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2709
2710 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2711 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2712
2713 /* DAC1 */
2714 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2715
2716 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2718 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2722
2723 /* no digital microphone support yet */
2724 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2725
2726 /* Audio input selector */
2727 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2728
2729 /* SPDIF route: PCM */
2730 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2731 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2732
2733 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2734 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2735
2736 /* EAPD */
2737 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2738
2739 /* not handling these yet */
2740 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2741 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2742 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2744 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2745 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2746 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2747 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2748 { } /* end */
2749};
2750
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002751static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002752 /* Port A: headphones */
2753 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2754 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2755
2756 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002757 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002758
2759 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002760 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002761
2762 /* Port D: unused */
2763 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2764
2765 /* Port E: unused, but has primary EAPD */
2766 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2767 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2768
Daniel Drakec4cfe662010-01-07 13:47:04 +01002769 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002770 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2771
2772 /* Port G: internal speakers */
2773 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2774 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2775
2776 /* DAC1 */
2777 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2778
2779 /* DAC2: unused */
2780 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2781
2782 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2784 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2785 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2786 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2787 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2788 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2789 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2790 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2791 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2792 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2793 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2794
2795 /* Disable digital microphone port */
2796 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2797
2798 /* Audio input selectors */
2799 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2800 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2801
2802 /* Disable SPDIF */
2803 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2804 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2805
2806 /* enable unsolicited events for Port A and B */
2807 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2808 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2809 { } /* end */
2810};
2811
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002812static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002813 /* Port A: headphones */
2814 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2816
2817 /* Port B: external microphone */
2818 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2819
2820 /* Port C: unused */
2821 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2822
2823 /* Port D: unused */
2824 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2825
2826 /* Port E: unused, but has primary EAPD */
2827 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2828 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2829
2830 /* Port F: unused */
2831 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2832
2833 /* Port G: internal speakers */
2834 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2835 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2836
2837 /* DAC1 */
2838 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2839
2840 /* DAC2: unused */
2841 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2842
2843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2845 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2849 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2850 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2851 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2853 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2854 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2855
2856 /* Digital microphone port */
2857 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2858
2859 /* Audio input selectors */
2860 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2861 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2862
2863 /* Disable SPDIF */
2864 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2865 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2866
2867 /* enable unsolicited events for Port A and B */
2868 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2869 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2870 { } /* end */
2871};
2872
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002873static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002874 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2875 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2876 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2877 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2878
2879 /* Speakers */
2880 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2881 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2882
2883 /* HP, Amp */
2884 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2885 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2886
2887 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2888 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2889
2890 /* DAC1 */
2891 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2892
2893 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2894 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2895 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2897 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2898 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2899 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2900
2901 /* Audio input selector */
2902 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2903 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2904
2905 /* SPDIF route: PCM */
2906 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2907 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2908
2909 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2911
2912 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002913 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002914
2915 /* EAPD */
2916 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2917
2918 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2919 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2920 { } /* end */
2921};
2922
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002923static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002924 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2925 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2926
2927 /* Port G: internal speakers */
2928 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2929 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2930
2931 /* Port A: HP, Amp */
2932 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2933 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2934
2935 /* Port B: Mic Dock */
2936 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2937
2938 /* Port C: Mic */
2939 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2940
2941 /* Port D: HP Dock, Amp */
2942 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2943 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2944
2945 /* DAC1 */
2946 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2947
2948 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2949 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2950 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2951 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2952 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2953 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2954 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2955
2956 /* Audio input selector */
2957 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2958 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2959
2960 /* SPDIF route: PCM */
2961 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2962 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2963
2964 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2965 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2966
2967 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002968 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002969
2970 /* EAPD */
2971 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2972
2973 /* enable unsolicited events for Port A, B, C and D */
2974 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2975 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2976 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2977 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2978 { } /* end */
2979};
2980
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002981static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002982 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2983 { } /* end */
2984};
2985
David Henningsson048e78a2010-09-02 08:35:47 +02002986
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002987static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002988 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2989 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2990 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2991 { } /* end */
2992};
2993
Daniel Drake0fb67e92009-07-16 14:46:57 +01002994/* initialize jack-sensing, too */
2995static int cxt5066_init(struct hda_codec *codec)
2996{
2997 snd_printdd("CXT5066: init\n");
2998 conexant_init(codec);
2999 if (codec->patch_ops.unsol_event) {
3000 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003001 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003002 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003003 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003004 return 0;
3005}
3006
Daniel Drake75f89912010-01-07 13:46:25 +01003007static int cxt5066_olpc_init(struct hda_codec *codec)
3008{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003009 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003010 snd_printdd("CXT5066: init\n");
3011 conexant_init(codec);
3012 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003013 if (!spec->dc_enable) {
3014 cxt5066_set_mic_boost(codec);
3015 cxt5066_olpc_automic(codec);
3016 } else {
3017 cxt5066_enable_dc(codec);
3018 }
Daniel Drake75f89912010-01-07 13:46:25 +01003019 return 0;
3020}
3021
Daniel Drake0fb67e92009-07-16 14:46:57 +01003022enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003023 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003024 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3025 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003026 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003027 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003028 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003029 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003030 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003031 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003032 CXT5066_MODELS
3033};
3034
Takashi Iwaiea734962011-01-17 11:29:34 +01003035static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003036 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003037 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3038 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003039 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003040 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003041 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003042 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003043 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003044 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003045};
3046
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003047static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02003048 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003049 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003050 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003051 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003052 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003053 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003054 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003055 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3056 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003057 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003058 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003059 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003060 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003061 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003062 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003063 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003064 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3065 CXT5066_LAPTOP),
3066 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003067 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003068 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003069 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003070 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
Daniel Suchyca201c02011-10-18 11:09:44 +02003071 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02003072 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003073 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003074 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003075 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003076 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
David Henningsson22f21d52011-01-07 07:53:39 +01003077 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003078 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003079 {}
3080};
3081
3082static int patch_cxt5066(struct hda_codec *codec)
3083{
3084 struct conexant_spec *spec;
3085 int board_config;
3086
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003087 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3088 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003089 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003090 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003091 if (board_config == CXT5066_AUTO)
3092 return patch_conexant_auto(codec);
3093
Daniel Drake0fb67e92009-07-16 14:46:57 +01003094 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3095 if (!spec)
3096 return -ENOMEM;
3097 codec->spec = spec;
3098
3099 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003100 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003101
3102 spec->dell_automute = 0;
3103 spec->multiout.max_channels = 2;
3104 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3105 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003106 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3107 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003108 spec->num_adc_nids = 1;
3109 spec->adc_nids = cxt5066_adc_nids;
3110 spec->capsrc_nids = cxt5066_capsrc_nids;
3111 spec->input_mux = &cxt5066_capture_source;
3112
3113 spec->port_d_mode = PIN_HP;
3114
3115 spec->num_init_verbs = 1;
3116 spec->init_verbs[0] = cxt5066_init_verbs;
3117 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3118 spec->channel_mode = cxt5066_modes;
3119 spec->cur_adc = 0;
3120 spec->cur_adc_idx = 0;
3121
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003122 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3123
Daniel Drake0fb67e92009-07-16 14:46:57 +01003124 switch (board_config) {
3125 default:
3126 case CXT5066_LAPTOP:
3127 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3128 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3129 break;
3130 case CXT5066_DELL_LAPTOP:
3131 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3132 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3133
3134 spec->port_d_mode = PIN_OUT;
3135 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3136 spec->num_init_verbs++;
3137 spec->dell_automute = 1;
3138 break;
David Henningssona1d69062011-01-21 13:33:28 +01003139 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003140 case CXT5066_HP_LAPTOP:
3141 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003142 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003143 spec->init_verbs[spec->num_init_verbs] =
3144 cxt5066_init_verbs_hp_laptop;
3145 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003146 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3147 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003148 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3149 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3150 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003151 if (board_config == CXT5066_HP_LAPTOP)
3152 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003153 /* input source automatically selected */
3154 spec->input_mux = NULL;
3155 spec->port_d_mode = 0;
3156 spec->mic_boost = 3; /* default 30dB gain */
3157 break;
3158
Daniel Drake0fb67e92009-07-16 14:46:57 +01003159 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003160 codec->patch_ops.init = cxt5066_olpc_init;
3161 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003162 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3163 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003164 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003165 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3166 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003167 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003168
3169 /* no S/PDIF out */
3170 spec->multiout.dig_out_nid = 0;
3171
3172 /* input source automatically selected */
3173 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003174
3175 /* our capture hooks which allow us to turn on the microphone LED
3176 * at the right time */
3177 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3178 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003179 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003180 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003181 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003182 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003183 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3184 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3185 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003186 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003187 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003188 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003189 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003190
3191 /* no S/PDIF out */
3192 spec->multiout.dig_out_nid = 0;
3193
3194 /* input source automatically selected */
3195 spec->input_mux = NULL;
3196 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003197 case CXT5066_IDEAPAD:
3198 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003199 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003200 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3201 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3202 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3203 spec->port_d_mode = 0;
3204 spec->ideapad = 1;
3205 spec->mic_boost = 2; /* default 20dB gain */
3206
3207 /* no S/PDIF out */
3208 spec->multiout.dig_out_nid = 0;
3209
3210 /* input source automatically selected */
3211 spec->input_mux = NULL;
3212 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003213 case CXT5066_THINKPAD:
3214 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003215 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003216 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3217 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3218 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3219 spec->thinkpad = 1;
3220 spec->port_d_mode = PIN_OUT;
3221 spec->mic_boost = 2; /* default 20dB gain */
3222
3223 /* no S/PDIF out */
3224 spec->multiout.dig_out_nid = 0;
3225
3226 /* input source automatically selected */
3227 spec->input_mux = NULL;
3228 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003229 }
3230
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003231 if (spec->beep_amp)
3232 snd_hda_attach_beep_device(codec, spec->beep_amp);
3233
Daniel Drake0fb67e92009-07-16 14:46:57 +01003234 return 0;
3235}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003236
3237/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003238 * Automatic parser for CX20641 & co
3239 */
3240
Takashi Iwai6764bce2011-05-13 16:52:25 +02003241static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3242 struct hda_codec *codec,
3243 unsigned int stream_tag,
3244 unsigned int format,
3245 struct snd_pcm_substream *substream)
3246{
3247 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003248 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003249 if (spec->adc_switching) {
3250 spec->cur_adc = adc;
3251 spec->cur_adc_stream_tag = stream_tag;
3252 spec->cur_adc_format = format;
3253 }
3254 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3255 return 0;
3256}
3257
3258static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3259 struct hda_codec *codec,
3260 struct snd_pcm_substream *substream)
3261{
3262 struct conexant_spec *spec = codec->spec;
3263 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3264 spec->cur_adc = 0;
3265 return 0;
3266}
3267
3268static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3269 .substreams = 1,
3270 .channels_min = 2,
3271 .channels_max = 2,
3272 .nid = 0, /* fill later */
3273 .ops = {
3274 .prepare = cx_auto_capture_pcm_prepare,
3275 .cleanup = cx_auto_capture_pcm_cleanup
3276 },
3277};
3278
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003279static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003280
Takashi Iwai8d087c72011-06-28 12:45:47 +02003281#define get_connection_index(codec, mux, nid)\
3282 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003283
3284/* get an unassigned DAC from the given list.
3285 * Return the nid if found and reduce the DAC list, or return zero if
3286 * not found
3287 */
3288static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3289 hda_nid_t *dacs, int *num_dacs)
3290{
3291 int i, nums = *num_dacs;
3292 hda_nid_t ret = 0;
3293
3294 for (i = 0; i < nums; i++) {
3295 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3296 ret = dacs[i];
3297 break;
3298 }
3299 }
3300 if (!ret)
3301 return 0;
3302 if (--nums > 0)
3303 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3304 *num_dacs = nums;
3305 return ret;
3306}
3307
3308#define MAX_AUTO_DACS 5
3309
Takashi Iwai1f015f52011-08-23 14:57:08 +02003310#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3311
Takashi Iwaif2e57312010-09-15 10:07:08 +02003312/* fill analog DAC list from the widget tree */
3313static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3314{
3315 hda_nid_t nid, end_nid;
3316 int nums = 0;
3317
3318 end_nid = codec->start_nid + codec->num_nodes;
3319 for (nid = codec->start_nid; nid < end_nid; nid++) {
3320 unsigned int wcaps = get_wcaps(codec, nid);
3321 unsigned int type = get_wcaps_type(wcaps);
3322 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3323 dacs[nums++] = nid;
3324 if (nums >= MAX_AUTO_DACS)
3325 break;
3326 }
3327 }
3328 return nums;
3329}
3330
3331/* fill pin_dac_pair list from the pin and dac list */
3332static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3333 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003334 struct pin_dac_pair *filled, int nums,
3335 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003336{
David Henningsson468c5452011-08-25 13:16:02 +02003337 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003338
David Henningsson468c5452011-08-25 13:16:02 +02003339 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003340 filled[nums].pin = pins[i];
3341 filled[nums].type = type;
3342 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003343 if (filled[nums].dac)
3344 continue;
3345 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3346 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3347 continue;
3348 }
3349 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003350 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003351 continue;
3352 }
3353 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003354 }
3355 return nums;
3356}
3357
3358/* parse analog output paths */
3359static void cx_auto_parse_output(struct hda_codec *codec)
3360{
3361 struct conexant_spec *spec = codec->spec;
3362 struct auto_pin_cfg *cfg = &spec->autocfg;
3363 hda_nid_t dacs[MAX_AUTO_DACS];
3364 int i, j, nums, rest;
3365
3366 rest = fill_cx_auto_dacs(codec, dacs);
3367 /* parse all analog output pins */
3368 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003369 dacs, &rest, spec->dac_info, 0,
3370 AUTO_PIN_LINE_OUT);
3371 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3372 dacs, &rest, spec->dac_info, nums,
3373 AUTO_PIN_HP_OUT);
3374 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3375 dacs, &rest, spec->dac_info, nums,
3376 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003377 spec->dac_info_filled = nums;
3378 /* fill multiout struct */
3379 for (i = 0; i < nums; i++) {
3380 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003381 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003382 continue;
3383 switch (spec->dac_info[i].type) {
3384 case AUTO_PIN_LINE_OUT:
3385 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3386 spec->multiout.num_dacs++;
3387 break;
3388 case AUTO_PIN_HP_OUT:
3389 case AUTO_PIN_SPEAKER_OUT:
3390 if (!spec->multiout.hp_nid) {
3391 spec->multiout.hp_nid = dac;
3392 break;
3393 }
3394 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3395 if (!spec->multiout.extra_out_nid[j]) {
3396 spec->multiout.extra_out_nid[j] = dac;
3397 break;
3398 }
3399 break;
3400 }
3401 }
3402 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003403 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003404
Takashi Iwai03697e22011-05-17 09:53:31 +02003405 for (i = 0; i < cfg->hp_outs; i++) {
3406 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3407 spec->auto_mute = 1;
3408 break;
3409 }
3410 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003411 if (spec->auto_mute &&
3412 cfg->line_out_pins[0] &&
3413 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003414 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3415 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3416 for (i = 0; i < cfg->line_outs; i++) {
3417 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3418 spec->detect_line = 1;
3419 break;
3420 }
3421 }
3422 spec->automute_lines = spec->detect_line;
3423 }
3424
Takashi Iwaif2e57312010-09-15 10:07:08 +02003425 spec->vmaster_nid = spec->private_dac_nids[0];
3426}
3427
Takashi Iwaida339862011-05-13 16:24:15 +02003428static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3429 hda_nid_t *pins, bool on);
3430
Takashi Iwai03697e22011-05-17 09:53:31 +02003431static void do_automute(struct hda_codec *codec, int num_pins,
3432 hda_nid_t *pins, bool on)
3433{
Takashi Iwai254f2962011-10-14 15:22:34 +02003434 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003435 int i;
3436 for (i = 0; i < num_pins; i++)
3437 snd_hda_codec_write(codec, pins[i], 0,
3438 AC_VERB_SET_PIN_WIDGET_CONTROL,
3439 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003440 if (spec->pin_eapd_ctrls)
3441 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003442}
3443
3444static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3445{
3446 int i, present = 0;
3447
3448 for (i = 0; i < num_pins; i++) {
3449 hda_nid_t nid = pins[i];
3450 if (!nid || !is_jack_detectable(codec, nid))
3451 break;
3452 snd_hda_input_jack_report(codec, nid);
3453 present |= snd_hda_jack_detect(codec, nid);
3454 }
3455 return present;
3456}
3457
Takashi Iwaif2e57312010-09-15 10:07:08 +02003458/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003459static void cx_auto_update_speakers(struct hda_codec *codec)
3460{
3461 struct conexant_spec *spec = codec->spec;
3462 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003463 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003464
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003465 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003466 if (spec->pin_eapd_ctrls) {
3467 if (spec->auto_mute)
3468 on = spec->hp_present;
3469 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3470 }
3471
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003472 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3473 if (spec->auto_mute)
3474 on = !(spec->hp_present ||
3475 (spec->detect_line && spec->line_present));
3476 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003477
3478 /* toggle line-out mutes if needed, too */
3479 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3480 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3481 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3482 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003483 if (spec->auto_mute) {
3484 /* mute LO in auto-mode when HP jack is present */
3485 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3486 spec->automute_lines)
3487 on = !spec->hp_present;
3488 else
3489 on = 1;
3490 }
3491 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003492}
3493
Takashi Iwaif2e57312010-09-15 10:07:08 +02003494static void cx_auto_hp_automute(struct hda_codec *codec)
3495{
3496 struct conexant_spec *spec = codec->spec;
3497 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003498
3499 if (!spec->auto_mute)
3500 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003501 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3502 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003503}
3504
Takashi Iwai03697e22011-05-17 09:53:31 +02003505static void cx_auto_line_automute(struct hda_codec *codec)
3506{
3507 struct conexant_spec *spec = codec->spec;
3508 struct auto_pin_cfg *cfg = &spec->autocfg;
3509
3510 if (!spec->auto_mute || !spec->detect_line)
3511 return;
3512 spec->line_present = detect_jacks(codec, cfg->line_outs,
3513 cfg->line_out_pins);
3514 cx_auto_update_speakers(codec);
3515}
3516
3517static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3518 struct snd_ctl_elem_info *uinfo)
3519{
3520 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3521 struct conexant_spec *spec = codec->spec;
3522 static const char * const texts2[] = {
3523 "Disabled", "Enabled"
3524 };
3525 static const char * const texts3[] = {
3526 "Disabled", "Speaker Only", "Line-Out+Speaker"
3527 };
3528 const char * const *texts;
3529
3530 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3531 uinfo->count = 1;
3532 if (spec->automute_hp_lo) {
3533 uinfo->value.enumerated.items = 3;
3534 texts = texts3;
3535 } else {
3536 uinfo->value.enumerated.items = 2;
3537 texts = texts2;
3538 }
3539 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3540 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3541 strcpy(uinfo->value.enumerated.name,
3542 texts[uinfo->value.enumerated.item]);
3543 return 0;
3544}
3545
3546static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3547 struct snd_ctl_elem_value *ucontrol)
3548{
3549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3550 struct conexant_spec *spec = codec->spec;
3551 unsigned int val;
3552 if (!spec->auto_mute)
3553 val = 0;
3554 else if (!spec->automute_lines)
3555 val = 1;
3556 else
3557 val = 2;
3558 ucontrol->value.enumerated.item[0] = val;
3559 return 0;
3560}
3561
3562static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3563 struct snd_ctl_elem_value *ucontrol)
3564{
3565 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3566 struct conexant_spec *spec = codec->spec;
3567
3568 switch (ucontrol->value.enumerated.item[0]) {
3569 case 0:
3570 if (!spec->auto_mute)
3571 return 0;
3572 spec->auto_mute = 0;
3573 break;
3574 case 1:
3575 if (spec->auto_mute && !spec->automute_lines)
3576 return 0;
3577 spec->auto_mute = 1;
3578 spec->automute_lines = 0;
3579 break;
3580 case 2:
3581 if (!spec->automute_hp_lo)
3582 return -EINVAL;
3583 if (spec->auto_mute && spec->automute_lines)
3584 return 0;
3585 spec->auto_mute = 1;
3586 spec->automute_lines = 1;
3587 break;
3588 default:
3589 return -EINVAL;
3590 }
3591 cx_auto_update_speakers(codec);
3592 return 1;
3593}
3594
3595static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3596 {
3597 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3598 .name = "Auto-Mute Mode",
3599 .info = cx_automute_mode_info,
3600 .get = cx_automute_mode_get,
3601 .put = cx_automute_mode_put,
3602 },
3603 { }
3604};
3605
Takashi Iwai6764bce2011-05-13 16:52:25 +02003606static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3607 struct snd_ctl_elem_info *uinfo)
3608{
3609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3610 struct conexant_spec *spec = codec->spec;
3611
3612 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3613}
3614
3615static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3616 struct snd_ctl_elem_value *ucontrol)
3617{
3618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3619 struct conexant_spec *spec = codec->spec;
3620
3621 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3622 return 0;
3623}
3624
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003625/* look for the route the given pin from mux and return the index;
3626 * if do_select is set, actually select the route.
3627 */
3628static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003629 hda_nid_t pin, hda_nid_t *srcp,
3630 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003631{
3632 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3633 int i, nums;
3634
Takashi Iwaicf27f292011-05-16 11:33:02 +02003635 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3636 case AC_WID_AUD_IN:
3637 case AC_WID_AUD_SEL:
3638 case AC_WID_AUD_MIX:
3639 break;
3640 default:
3641 return -1;
3642 }
3643
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003644 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3645 for (i = 0; i < nums; i++)
3646 if (conn[i] == pin) {
3647 if (do_select)
3648 snd_hda_codec_write(codec, mux, 0,
3649 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003650 if (srcp)
3651 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003652 return i;
3653 }
3654 depth++;
3655 if (depth == 2)
3656 return -1;
3657 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003658 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003659 do_select, depth);
3660 if (ret >= 0) {
3661 if (do_select)
3662 snd_hda_codec_write(codec, mux, 0,
3663 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003664 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003665 }
3666 }
3667 return -1;
3668}
3669
3670static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3671 hda_nid_t pin)
3672{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003673 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003674}
3675
3676static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3677 hda_nid_t pin)
3678{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003679 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003680}
3681
Takashi Iwai6764bce2011-05-13 16:52:25 +02003682static int cx_auto_mux_enum_update(struct hda_codec *codec,
3683 const struct hda_input_mux *imux,
3684 unsigned int idx)
3685{
3686 struct conexant_spec *spec = codec->spec;
3687 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003688 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003689
3690 if (!imux->num_items)
3691 return 0;
3692 if (idx >= imux->num_items)
3693 idx = imux->num_items - 1;
3694 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003695 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003696 adc = spec->imux_info[idx].adc;
3697 select_input_connection(codec, spec->imux_info[idx].adc,
3698 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003699 if (spec->cur_adc && spec->cur_adc != adc) {
3700 /* stream is running, let's swap the current ADC */
3701 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3702 spec->cur_adc = adc;
3703 snd_hda_codec_setup_stream(codec, adc,
3704 spec->cur_adc_stream_tag, 0,
3705 spec->cur_adc_format);
3706 }
3707 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003708 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003709}
3710
3711static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3712 struct snd_ctl_elem_value *ucontrol)
3713{
3714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3715 struct conexant_spec *spec = codec->spec;
3716
3717 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3718 ucontrol->value.enumerated.item[0]);
3719}
3720
3721static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3722 {
3723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3724 .name = "Capture Source",
3725 .info = cx_auto_mux_enum_info,
3726 .get = cx_auto_mux_enum_get,
3727 .put = cx_auto_mux_enum_put
3728 },
3729 {}
3730};
3731
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003732static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3733{
3734 struct conexant_spec *spec = codec->spec;
3735 if (idx < 0)
3736 return false;
3737 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3738 return false;
3739 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3740 return true;
3741}
3742
Takashi Iwaif2e57312010-09-15 10:07:08 +02003743/* automatic switch internal and external mic */
3744static void cx_auto_automic(struct hda_codec *codec)
3745{
3746 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003747
3748 if (!spec->auto_mic)
3749 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003750 if (!select_automic(codec, spec->auto_mic_ext, true))
3751 if (!select_automic(codec, spec->auto_mic_dock, true))
3752 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003753}
3754
3755static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3756{
3757 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3758 switch (res >> 26) {
3759 case CONEXANT_HP_EVENT:
3760 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003761 break;
3762 case CONEXANT_LINE_EVENT:
3763 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003764 break;
3765 case CONEXANT_MIC_EVENT:
3766 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003767 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003768 break;
3769 }
3770}
3771
Takashi Iwaif2e57312010-09-15 10:07:08 +02003772/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003773 * auto-mic is enabled only when one int-mic and one ext- and/or
3774 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003775 */
3776static void cx_auto_check_auto_mic(struct hda_codec *codec)
3777{
3778 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003779 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3780 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003781
Takashi Iwai506a4192011-05-23 20:07:15 +02003782 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003783 pset[i] = -1;
3784 for (i = 0; i < spec->private_imux.num_items; i++) {
3785 hda_nid_t pin = spec->imux_info[i].pin;
3786 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003787 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003788 attr = snd_hda_get_input_pin_attr(def_conf);
3789 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003790 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003791 if (attr > INPUT_PIN_ATTR_NORMAL)
3792 attr = INPUT_PIN_ATTR_NORMAL;
3793 if (attr != INPUT_PIN_ATTR_INT &&
3794 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003795 return; /* non-detectable pin */
3796 type = get_defcfg_device(def_conf);
3797 if (type != AC_JACK_MIC_IN &&
3798 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3799 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003800 if (pset[attr] >= 0)
3801 return; /* already occupied */
3802 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003803 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003804 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3805 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3806 return; /* no input to switch*/
3807 spec->auto_mic = 1;
3808 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3809 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3810 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003811}
3812
3813static void cx_auto_parse_input(struct hda_codec *codec)
3814{
3815 struct conexant_spec *spec = codec->spec;
3816 struct auto_pin_cfg *cfg = &spec->autocfg;
3817 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003818 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003819
3820 imux = &spec->private_imux;
3821 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003822 for (j = 0; j < spec->num_adc_nids; j++) {
3823 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003824 int idx = get_input_connection(codec, adc,
3825 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003826 if (idx >= 0) {
3827 const char *label;
3828 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003829 spec->imux_info[imux->num_items].index = i;
3830 spec->imux_info[imux->num_items].boost = 0;
3831 spec->imux_info[imux->num_items].adc = adc;
3832 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003833 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003834 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003835 break;
3836 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003837 }
3838 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003839 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003840 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003841 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003842 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003843 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003844 spec->adc_switching = 1;
3845 break;
3846 }
3847 }
3848 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003849}
3850
3851/* get digital-input audio widget corresponding to the given pin */
3852static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3853{
3854 hda_nid_t nid, end_nid;
3855
3856 end_nid = codec->start_nid + codec->num_nodes;
3857 for (nid = codec->start_nid; nid < end_nid; nid++) {
3858 unsigned int wcaps = get_wcaps(codec, nid);
3859 unsigned int type = get_wcaps_type(wcaps);
3860 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3861 if (get_connection_index(codec, nid, pin) >= 0)
3862 return nid;
3863 }
3864 }
3865 return 0;
3866}
3867
3868static void cx_auto_parse_digital(struct hda_codec *codec)
3869{
3870 struct conexant_spec *spec = codec->spec;
3871 struct auto_pin_cfg *cfg = &spec->autocfg;
3872 hda_nid_t nid;
3873
3874 if (cfg->dig_outs &&
3875 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3876 spec->multiout.dig_out_nid = nid;
3877 if (cfg->dig_in_pin)
3878 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3879}
3880
3881#ifdef CONFIG_SND_HDA_INPUT_BEEP
3882static void cx_auto_parse_beep(struct hda_codec *codec)
3883{
3884 struct conexant_spec *spec = codec->spec;
3885 hda_nid_t nid, end_nid;
3886
3887 end_nid = codec->start_nid + codec->num_nodes;
3888 for (nid = codec->start_nid; nid < end_nid; nid++)
3889 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3890 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3891 break;
3892 }
3893}
3894#else
3895#define cx_auto_parse_beep(codec)
3896#endif
3897
Takashi Iwai254f2962011-10-14 15:22:34 +02003898/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003899static void cx_auto_parse_eapd(struct hda_codec *codec)
3900{
3901 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003902 hda_nid_t nid, end_nid;
3903
3904 end_nid = codec->start_nid + codec->num_nodes;
3905 for (nid = codec->start_nid; nid < end_nid; nid++) {
3906 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3907 continue;
3908 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3909 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003910 spec->eapds[spec->num_eapds++] = nid;
3911 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3912 break;
3913 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003914
3915 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3916 * it's a new chip, where EAPDs are supposed to be associated to
3917 * pins, and we can control EAPD per pin.
3918 * OTOH, if only one or two EAPDs are found, it's an old chip,
3919 * thus it might control over all pins.
3920 */
3921 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003922}
3923
Takashi Iwaif2e57312010-09-15 10:07:08 +02003924static int cx_auto_parse_auto_config(struct hda_codec *codec)
3925{
3926 struct conexant_spec *spec = codec->spec;
3927 int err;
3928
3929 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3930 if (err < 0)
3931 return err;
3932
3933 cx_auto_parse_output(codec);
3934 cx_auto_parse_input(codec);
3935 cx_auto_parse_digital(codec);
3936 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003937 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003938 return 0;
3939}
3940
Takashi Iwaida339862011-05-13 16:24:15 +02003941static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3942 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003943{
3944 int i;
3945 for (i = 0; i < num_pins; i++) {
3946 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3947 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003948 AC_VERB_SET_EAPD_BTLENABLE,
3949 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003950 }
3951}
3952
3953static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3954 hda_nid_t src)
3955{
3956 int idx = get_connection_index(codec, pin, src);
3957 if (idx >= 0)
3958 snd_hda_codec_write(codec, pin, 0,
3959 AC_VERB_SET_CONNECT_SEL, idx);
3960}
3961
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003962static void mute_outputs(struct hda_codec *codec, int num_nids,
3963 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003964{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003965 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003966
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003967 for (i = 0; i < num_nids; i++) {
3968 hda_nid_t nid = nids[i];
3969 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3970 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003971 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3972 val = AMP_OUT_MUTE;
3973 else
3974 val = AMP_OUT_ZERO;
3975 snd_hda_codec_write(codec, nid, 0,
3976 AC_VERB_SET_AMP_GAIN_MUTE, val);
3977 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003978}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003979
Takashi Iwai03697e22011-05-17 09:53:31 +02003980static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3981 hda_nid_t *pins, unsigned int tag)
3982{
3983 int i;
3984 for (i = 0; i < num_pins; i++)
3985 snd_hda_codec_write(codec, pins[i], 0,
3986 AC_VERB_SET_UNSOLICITED_ENABLE,
3987 AC_USRSP_EN | tag);
3988}
3989
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003990static void cx_auto_init_output(struct hda_codec *codec)
3991{
3992 struct conexant_spec *spec = codec->spec;
3993 struct auto_pin_cfg *cfg = &spec->autocfg;
3994 hda_nid_t nid;
3995 int i;
3996
3997 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003998 for (i = 0; i < cfg->hp_outs; i++)
3999 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
4000 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004001 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
4002 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
4003 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004004 for (i = 0; i < spec->dac_info_filled; i++) {
4005 nid = spec->dac_info[i].dac;
4006 if (!nid)
4007 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02004008 else if (nid & DAC_SLAVE_FLAG)
4009 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004010 select_connection(codec, spec->dac_info[i].pin, nid);
4011 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004012 if (spec->auto_mute) {
4013 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
4014 CONEXANT_HP_EVENT);
4015 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4016 cfg->hp_pins);
4017 if (spec->detect_line) {
4018 enable_unsol_pins(codec, cfg->line_outs,
4019 cfg->line_out_pins,
4020 CONEXANT_LINE_EVENT);
4021 spec->line_present =
4022 detect_jacks(codec, cfg->line_outs,
4023 cfg->line_out_pins);
4024 }
4025 }
4026 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02004027 /* turn on all EAPDs if no individual EAPD control is available */
4028 if (!spec->pin_eapd_ctrls)
4029 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004030}
4031
4032static void cx_auto_init_input(struct hda_codec *codec)
4033{
4034 struct conexant_spec *spec = codec->spec;
4035 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004036 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004037
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004038 for (i = 0; i < spec->num_adc_nids; i++) {
4039 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004040 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4041 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004042 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4043 val = AMP_IN_MUTE(0);
4044 else
4045 val = AMP_IN_UNMUTE(0);
4046 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4047 val);
4048 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004049
4050 for (i = 0; i < cfg->num_inputs; i++) {
4051 unsigned int type;
4052 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4053 type = PIN_VREF80;
4054 else
4055 type = PIN_IN;
4056 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4057 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4058 }
4059
4060 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004061 if (spec->auto_mic_ext >= 0) {
4062 snd_hda_codec_write(codec,
4063 cfg->inputs[spec->auto_mic_ext].pin, 0,
4064 AC_VERB_SET_UNSOLICITED_ENABLE,
4065 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4066 }
4067 if (spec->auto_mic_dock >= 0) {
4068 snd_hda_codec_write(codec,
4069 cfg->inputs[spec->auto_mic_dock].pin, 0,
4070 AC_VERB_SET_UNSOLICITED_ENABLE,
4071 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4072 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004073 cx_auto_automic(codec);
4074 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004075 select_input_connection(codec, spec->imux_info[0].adc,
4076 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004077 }
4078}
4079
4080static void cx_auto_init_digital(struct hda_codec *codec)
4081{
4082 struct conexant_spec *spec = codec->spec;
4083 struct auto_pin_cfg *cfg = &spec->autocfg;
4084
4085 if (spec->multiout.dig_out_nid)
4086 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4087 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4088 if (spec->dig_in_nid)
4089 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4090 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4091}
4092
4093static int cx_auto_init(struct hda_codec *codec)
4094{
4095 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4096 cx_auto_init_output(codec);
4097 cx_auto_init_input(codec);
4098 cx_auto_init_digital(codec);
4099 return 0;
4100}
4101
David Henningsson983345e2011-02-15 19:57:09 +01004102static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004103 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004104 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004105{
4106 static char name[32];
4107 static struct snd_kcontrol_new knew[] = {
4108 HDA_CODEC_VOLUME(name, 0, 0, 0),
4109 HDA_CODEC_MUTE(name, 0, 0, 0),
4110 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004111 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004112 int i, err;
4113
4114 for (i = 0; i < 2; i++) {
4115 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004116 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4117 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004118 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4119 knew[i].index = cidx;
4120 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4121 kctl = snd_ctl_new1(&knew[i], codec);
4122 if (!kctl)
4123 return -ENOMEM;
4124 err = snd_hda_ctl_add(codec, nid, kctl);
4125 if (err < 0)
4126 return err;
4127 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4128 break;
4129 }
4130 return 0;
4131}
4132
David Henningsson983345e2011-02-15 19:57:09 +01004133#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4134 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4135
Takashi Iwaif2e57312010-09-15 10:07:08 +02004136#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4137 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4138
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004139static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4140 hda_nid_t pin, const char *name, int idx)
4141{
4142 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004143 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4144 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4145 if (caps & AC_AMPCAP_NUM_STEPS)
4146 return cx_auto_add_pb_volume(codec, dac, name, idx);
4147 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004148 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4149 if (caps & AC_AMPCAP_NUM_STEPS)
4150 return cx_auto_add_pb_volume(codec, pin, name, idx);
4151 return 0;
4152}
4153
Takashi Iwaif2e57312010-09-15 10:07:08 +02004154static int cx_auto_build_output_controls(struct hda_codec *codec)
4155{
4156 struct conexant_spec *spec = codec->spec;
4157 int i, err;
4158 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004159 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004160
4161 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004162 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4163 spec->dac_info[0].pin,
4164 "Master", 0);
4165
Takashi Iwaif2e57312010-09-15 10:07:08 +02004166 for (i = 0; i < spec->dac_info_filled; i++) {
4167 const char *label;
4168 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004169 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004170 type = spec->dac_info[i].type;
4171 if (type == AUTO_PIN_LINE_OUT)
4172 type = spec->autocfg.line_out_type;
4173 switch (type) {
4174 case AUTO_PIN_LINE_OUT:
4175 default:
4176 label = texts[num_line++];
4177 idx = 0;
4178 break;
4179 case AUTO_PIN_HP_OUT:
4180 label = "Headphone";
4181 idx = num_hp++;
4182 break;
4183 case AUTO_PIN_SPEAKER_OUT:
4184 label = "Speaker";
4185 idx = num_spk++;
4186 break;
4187 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004188 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004189 spec->dac_info[i].pin,
4190 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004191 if (err < 0)
4192 return err;
4193 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004194
4195 if (spec->auto_mute) {
4196 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4197 if (err < 0)
4198 return err;
4199 }
4200
Takashi Iwaif2e57312010-09-15 10:07:08 +02004201 return 0;
4202}
4203
Takashi Iwai6764bce2011-05-13 16:52:25 +02004204static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4205 const char *label, const char *pfx,
4206 int cidx)
4207{
4208 struct conexant_spec *spec = codec->spec;
4209 int i;
4210
4211 for (i = 0; i < spec->num_adc_nids; i++) {
4212 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004213 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004214 if (idx < 0)
4215 continue;
4216 return cx_auto_add_volume_idx(codec, label, pfx,
4217 cidx, adc_nid, HDA_INPUT, idx);
4218 }
4219 return 0;
4220}
4221
Takashi Iwaicf27f292011-05-16 11:33:02 +02004222static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4223 const char *label, int cidx)
4224{
4225 struct conexant_spec *spec = codec->spec;
4226 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004227 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004228
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004229 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004230 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4231 return cx_auto_add_volume(codec, label, " Boost", cidx,
4232 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004233 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4234 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004235 if (con < 0)
4236 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004237 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004238 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004239 return 0; /* already present */
4240 }
4241
4242 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004243 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004244 return cx_auto_add_volume(codec, label, " Boost", 0,
4245 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004246 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004247 return 0;
4248}
4249
Takashi Iwaif2e57312010-09-15 10:07:08 +02004250static int cx_auto_build_input_controls(struct hda_codec *codec)
4251{
4252 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004253 struct hda_input_mux *imux = &spec->private_imux;
4254 const char *prev_label;
4255 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004256 int i, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004257 int multi_connection;
4258
4259 multi_connection = 0;
4260 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004261 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4262 spec->imux_info[i].pin);
4263 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004264 if (i > 0 && input_conn[i] != input_conn[0])
4265 multi_connection = 1;
4266 }
David Henningsson983345e2011-02-15 19:57:09 +01004267
Takashi Iwaif2e57312010-09-15 10:07:08 +02004268 prev_label = NULL;
4269 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004270 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004271 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004272 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004273
Takashi Iwaicf27f292011-05-16 11:33:02 +02004274 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004275 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004276 if (label == prev_label)
4277 cidx++;
4278 else
4279 cidx = 0;
4280 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004281
Takashi Iwaicf27f292011-05-16 11:33:02 +02004282 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4283 if (err < 0)
4284 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004285
Takashi Iwaicf27f292011-05-16 11:33:02 +02004286 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004287 if (i > 0)
4288 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004289 err = cx_auto_add_capture_volume(codec, nid,
4290 "Capture", "", cidx);
4291 } else {
4292 err = cx_auto_add_capture_volume(codec, nid,
4293 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004294 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004295 if (err < 0)
4296 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004297 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004298
4299 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4300 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4301 if (err < 0)
4302 return err;
4303 }
4304
Takashi Iwaif2e57312010-09-15 10:07:08 +02004305 return 0;
4306}
4307
4308static int cx_auto_build_controls(struct hda_codec *codec)
4309{
4310 int err;
4311
4312 err = cx_auto_build_output_controls(codec);
4313 if (err < 0)
4314 return err;
4315 err = cx_auto_build_input_controls(codec);
4316 if (err < 0)
4317 return err;
4318 return conexant_build_controls(codec);
4319}
4320
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004321static int cx_auto_search_adcs(struct hda_codec *codec)
4322{
4323 struct conexant_spec *spec = codec->spec;
4324 hda_nid_t nid, end_nid;
4325
4326 end_nid = codec->start_nid + codec->num_nodes;
4327 for (nid = codec->start_nid; nid < end_nid; nid++) {
4328 unsigned int caps = get_wcaps(codec, nid);
4329 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4330 continue;
4331 if (caps & AC_WCAP_DIGITAL)
4332 continue;
4333 if (snd_BUG_ON(spec->num_adc_nids >=
4334 ARRAY_SIZE(spec->private_adc_nids)))
4335 break;
4336 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4337 }
4338 spec->adc_nids = spec->private_adc_nids;
4339 return 0;
4340}
4341
4342
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004343static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004344 .build_controls = cx_auto_build_controls,
4345 .build_pcms = conexant_build_pcms,
4346 .init = cx_auto_init,
4347 .free = conexant_free,
4348 .unsol_event = cx_auto_unsol_event,
4349#ifdef CONFIG_SND_HDA_POWER_SAVE
4350 .suspend = conexant_suspend,
4351#endif
4352 .reboot_notify = snd_hda_shutup_pins,
4353};
4354
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004355/*
4356 * pin fix-up
4357 */
4358struct cxt_pincfg {
4359 hda_nid_t nid;
4360 u32 val;
4361};
4362
4363static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4364{
4365 for (; cfg->nid; cfg++)
4366 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4367
4368}
4369
4370static void apply_pin_fixup(struct hda_codec *codec,
4371 const struct snd_pci_quirk *quirk,
4372 const struct cxt_pincfg **table)
4373{
4374 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4375 if (quirk) {
4376 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4377 quirk->name);
4378 apply_pincfg(codec, table[quirk->value]);
4379 }
4380}
4381
4382enum {
4383 CXT_PINCFG_LENOVO_X200,
4384};
4385
4386static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4387 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4388 { 0x17, 0x21a11000 }, /* dock-mic */
4389 { 0x19, 0x2121103f }, /* dock-HP */
4390 {}
4391};
4392
4393static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4394 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4395};
4396
4397static const struct snd_pci_quirk cxt_fixups[] = {
4398 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4399 {}
4400};
4401
Takashi Iwaif2e57312010-09-15 10:07:08 +02004402static int patch_conexant_auto(struct hda_codec *codec)
4403{
4404 struct conexant_spec *spec;
4405 int err;
4406
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004407 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4408 codec->chip_name);
4409
Takashi Iwaif2e57312010-09-15 10:07:08 +02004410 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4411 if (!spec)
4412 return -ENOMEM;
4413 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004414 codec->pin_amp_workaround = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004415
4416 apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
4417
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004418 err = cx_auto_search_adcs(codec);
4419 if (err < 0)
4420 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004421 err = cx_auto_parse_auto_config(codec);
4422 if (err < 0) {
4423 kfree(codec->spec);
4424 codec->spec = NULL;
4425 return err;
4426 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004427 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004428 codec->patch_ops = cx_auto_patch_ops;
4429 if (spec->beep_amp)
4430 snd_hda_attach_beep_device(codec, spec->beep_amp);
4431 return 0;
4432}
4433
4434/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004435 */
4436
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004437static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004438 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4439 .patch = patch_cxt5045 },
4440 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4441 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004442 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4443 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004444 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4445 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004446 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4447 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004448 { .id = 0x14f15068, .name = "CX20584",
4449 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004450 { .id = 0x14f15069, .name = "CX20585",
4451 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004452 { .id = 0x14f1506c, .name = "CX20588",
4453 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004454 { .id = 0x14f1506e, .name = "CX20590",
4455 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004456 { .id = 0x14f15097, .name = "CX20631",
4457 .patch = patch_conexant_auto },
4458 { .id = 0x14f15098, .name = "CX20632",
4459 .patch = patch_conexant_auto },
4460 { .id = 0x14f150a1, .name = "CX20641",
4461 .patch = patch_conexant_auto },
4462 { .id = 0x14f150a2, .name = "CX20642",
4463 .patch = patch_conexant_auto },
4464 { .id = 0x14f150ab, .name = "CX20651",
4465 .patch = patch_conexant_auto },
4466 { .id = 0x14f150ac, .name = "CX20652",
4467 .patch = patch_conexant_auto },
4468 { .id = 0x14f150b8, .name = "CX20664",
4469 .patch = patch_conexant_auto },
4470 { .id = 0x14f150b9, .name = "CX20665",
4471 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004472 {} /* terminator */
4473};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004474
4475MODULE_ALIAS("snd-hda-codec-id:14f15045");
4476MODULE_ALIAS("snd-hda-codec-id:14f15047");
4477MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004478MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004479MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004480MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004481MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004482MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004483MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004484MODULE_ALIAS("snd-hda-codec-id:14f15097");
4485MODULE_ALIAS("snd-hda-codec-id:14f15098");
4486MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4487MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4488MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4489MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4490MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4491MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004492
4493MODULE_LICENSE("GPL");
4494MODULE_DESCRIPTION("Conexant HD-audio codec");
4495
4496static struct hda_codec_preset_list conexant_list = {
4497 .preset = snd_hda_preset_conexant,
4498 .owner = THIS_MODULE,
4499};
4500
4501static int __init patch_conexant_init(void)
4502{
4503 return snd_hda_add_codec_preset(&conexant_list);
4504}
4505
4506static void __exit patch_conexant_exit(void)
4507{
4508 snd_hda_delete_codec_preset(&conexant_list);
4509}
4510
4511module_init(patch_conexant_init)
4512module_exit(patch_conexant_exit)