blob: 5e706e4d17377434e83bf86ead1408e2494f5651 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Tobin Davisc9b443d2006-11-14 12:13:39 +010028#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010029#include <sound/jack.h>
30
Tobin Davisc9b443d2006-11-14 12:13:39 +010031#include "hda_codec.h"
32#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020033#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010034
35#define CXT_PIN_DIR_IN 0x00
36#define CXT_PIN_DIR_OUT 0x01
37#define CXT_PIN_DIR_INOUT 0x02
38#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
39#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
40
41#define CONEXANT_HP_EVENT 0x37
42#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020043#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010044
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010045/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010046
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010047#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010048#define CXT5051_PORTB_EVENT 0x38
49#define CXT5051_PORTC_EVENT 0x39
50
Takashi Iwaifaddaa52010-01-23 22:31:36 +010051#define AUTO_MIC_PORTB (1 << 1)
52#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010053
Takashi Iwaif2e57312010-09-15 10:07:08 +020054struct pin_dac_pair {
55 hda_nid_t pin;
56 hda_nid_t dac;
57 int type;
58};
59
Takashi Iwai47ad1f42011-05-17 09:15:55 +020060struct imux_info {
61 hda_nid_t pin; /* input pin NID */
62 hda_nid_t adc; /* connected ADC NID */
63 hda_nid_t boost; /* optional boost volume NID */
64 int index; /* corresponding to autocfg.input */
65};
66
Tobin Davisc9b443d2006-11-14 12:13:39 +010067struct conexant_spec {
68
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020069 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010070 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010071 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010072
73 const struct hda_verb *init_verbs[5]; /* initialization verbs
74 * don't forget NULL
75 * termination!
76 */
77 unsigned int num_init_verbs;
78
79 /* playback */
80 struct hda_multi_out multiout; /* playback set-up
81 * max_channels, dacs must be set
82 * dig_out_nid and hp_nid are optional
83 */
84 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010085 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020086 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010087 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020088 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020089 int auto_mic_dock; /* imux_pins[] index for dock mic */
90 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010091 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050092 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010093
94 /* capture */
95 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020096 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010097 hda_nid_t dig_in_nid; /* digital-in NID; optional */
98
Takashi Iwai461e2c72008-01-25 11:35:17 +010099 unsigned int cur_adc_idx;
100 hda_nid_t cur_adc;
101 unsigned int cur_adc_stream_tag;
102 unsigned int cur_adc_format;
103
Takashi Iwai6764bce2011-05-13 16:52:25 +0200104 const struct hda_pcm_stream *capture_stream;
105
Tobin Davisc9b443d2006-11-14 12:13:39 +0100106 /* capture source */
107 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200108 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100109 unsigned int cur_mux[3];
110
111 /* channel model */
112 const struct hda_channel_mode *channel_mode;
113 int num_channel_mode;
114
115 /* PCM information */
116 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
117
Tobin Davisc9b443d2006-11-14 12:13:39 +0100118 unsigned int spdif_route;
119
120 /* dynamic controls, init_verbs and input_mux */
121 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100122 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200123 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200124 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200125 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200126 struct pin_dac_pair dac_info[8];
127 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100128
Daniel Drake0fb67e92009-07-16 14:46:57 +0100129 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200130 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200131 unsigned int detect_line:1; /* Line-out detection enabled */
132 unsigned int automute_lines:1; /* automute line-out as well */
133 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200134 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500135 unsigned int dell_vostro:1;
136 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200137 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200138 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100139 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200140 unsigned int pin_eapd_ctrls:1;
Takashi Iwai6b452142011-10-14 15:26:20 +0200141 unsigned int single_adc_amp:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100142
Takashi Iwai6764bce2011-05-13 16:52:25 +0200143 unsigned int adc_switching:1;
144
Daniel Drake75f89912010-01-07 13:46:25 +0100145 unsigned int ext_mic_present;
146 unsigned int recording;
147 void (*capture_prepare)(struct hda_codec *codec);
148 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100149
150 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
151 * through the microphone jack.
152 * When the user enables this through a mixer switch, both internal and
153 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
154 * we also allow the bias to be configured through a separate mixer
155 * control. */
156 unsigned int dc_enable;
157 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
158 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200159
160 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200161
162 /* extra EAPD pins */
163 unsigned int num_eapds;
164 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100165};
166
167static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
168 struct hda_codec *codec,
169 struct snd_pcm_substream *substream)
170{
171 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100172 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
173 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100174}
175
176static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 unsigned int stream_tag,
179 unsigned int format,
180 struct snd_pcm_substream *substream)
181{
182 struct conexant_spec *spec = codec->spec;
183 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
184 stream_tag,
185 format, substream);
186}
187
188static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
190 struct snd_pcm_substream *substream)
191{
192 struct conexant_spec *spec = codec->spec;
193 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
194}
195
196/*
197 * Digital out
198 */
199static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
200 struct hda_codec *codec,
201 struct snd_pcm_substream *substream)
202{
203 struct conexant_spec *spec = codec->spec;
204 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
205}
206
207static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
208 struct hda_codec *codec,
209 struct snd_pcm_substream *substream)
210{
211 struct conexant_spec *spec = codec->spec;
212 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
213}
214
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200215static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
216 struct hda_codec *codec,
217 unsigned int stream_tag,
218 unsigned int format,
219 struct snd_pcm_substream *substream)
220{
221 struct conexant_spec *spec = codec->spec;
222 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
223 stream_tag,
224 format, substream);
225}
226
Tobin Davisc9b443d2006-11-14 12:13:39 +0100227/*
228 * Analog capture
229 */
230static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 unsigned int stream_tag,
233 unsigned int format,
234 struct snd_pcm_substream *substream)
235{
236 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100237 if (spec->capture_prepare)
238 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100239 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
240 stream_tag, 0, format);
241 return 0;
242}
243
244static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
245 struct hda_codec *codec,
246 struct snd_pcm_substream *substream)
247{
248 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100249 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100250 if (spec->capture_cleanup)
251 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100252 return 0;
253}
254
255
256
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200257static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100258 .substreams = 1,
259 .channels_min = 2,
260 .channels_max = 2,
261 .nid = 0, /* fill later */
262 .ops = {
263 .open = conexant_playback_pcm_open,
264 .prepare = conexant_playback_pcm_prepare,
265 .cleanup = conexant_playback_pcm_cleanup
266 },
267};
268
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200269static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100270 .substreams = 1,
271 .channels_min = 2,
272 .channels_max = 2,
273 .nid = 0, /* fill later */
274 .ops = {
275 .prepare = conexant_capture_pcm_prepare,
276 .cleanup = conexant_capture_pcm_cleanup
277 },
278};
279
280
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200281static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100282 .substreams = 1,
283 .channels_min = 2,
284 .channels_max = 2,
285 .nid = 0, /* fill later */
286 .ops = {
287 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200288 .close = conexant_dig_playback_pcm_close,
289 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100290 },
291};
292
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200293static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100294 .substreams = 1,
295 .channels_min = 2,
296 .channels_max = 2,
297 /* NID is set in alc_build_pcms */
298};
299
Takashi Iwai461e2c72008-01-25 11:35:17 +0100300static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
301 struct hda_codec *codec,
302 unsigned int stream_tag,
303 unsigned int format,
304 struct snd_pcm_substream *substream)
305{
306 struct conexant_spec *spec = codec->spec;
307 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
308 spec->cur_adc_stream_tag = stream_tag;
309 spec->cur_adc_format = format;
310 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
311 return 0;
312}
313
314static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
315 struct hda_codec *codec,
316 struct snd_pcm_substream *substream)
317{
318 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100319 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100320 spec->cur_adc = 0;
321 return 0;
322}
323
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200324static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100325 .substreams = 1,
326 .channels_min = 2,
327 .channels_max = 2,
328 .nid = 0, /* fill later */
329 .ops = {
330 .prepare = cx5051_capture_pcm_prepare,
331 .cleanup = cx5051_capture_pcm_cleanup
332 },
333};
334
Tobin Davisc9b443d2006-11-14 12:13:39 +0100335static int conexant_build_pcms(struct hda_codec *codec)
336{
337 struct conexant_spec *spec = codec->spec;
338 struct hda_pcm *info = spec->pcm_rec;
339
340 codec->num_pcms = 1;
341 codec->pcm_info = info;
342
343 info->name = "CONEXANT Analog";
344 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
346 spec->multiout.max_channels;
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
348 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200349 if (spec->capture_stream)
350 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
351 else {
352 if (codec->vendor_id == 0x14f15051)
353 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
354 cx5051_pcm_analog_capture;
355 else {
356 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
357 conexant_pcm_analog_capture;
358 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
359 spec->num_adc_nids;
360 }
361 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
363
364 if (spec->multiout.dig_out_nid) {
365 info++;
366 codec->num_pcms++;
367 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
370 conexant_pcm_digital_playback;
371 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
372 spec->multiout.dig_out_nid;
373 if (spec->dig_in_nid) {
374 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
375 conexant_pcm_digital_capture;
376 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
377 spec->dig_in_nid;
378 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500379 if (spec->slave_dig_outs[0])
380 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100381 }
382
383 return 0;
384}
385
386static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
387 struct snd_ctl_elem_info *uinfo)
388{
389 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
390 struct conexant_spec *spec = codec->spec;
391
392 return snd_hda_input_mux_info(spec->input_mux, uinfo);
393}
394
395static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
396 struct snd_ctl_elem_value *ucontrol)
397{
398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399 struct conexant_spec *spec = codec->spec;
400 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
401
402 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
403 return 0;
404}
405
406static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
407 struct snd_ctl_elem_value *ucontrol)
408{
409 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410 struct conexant_spec *spec = codec->spec;
411 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412
413 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
414 spec->capsrc_nids[adc_idx],
415 &spec->cur_mux[adc_idx]);
416}
417
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100418static int conexant_init_jacks(struct hda_codec *codec)
419{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100420#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100421 struct conexant_spec *spec = codec->spec;
422 int i;
423
424 for (i = 0; i < spec->num_init_verbs; i++) {
425 const struct hda_verb *hv;
426
427 hv = spec->init_verbs[i];
428 while (hv->nid) {
429 int err = 0;
430 switch (hv->param ^ AC_USRSP_EN) {
431 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100432 err = snd_hda_input_jack_add(codec, hv->nid,
433 SND_JACK_HEADPHONE, NULL);
434 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100435 break;
436 case CXT5051_PORTC_EVENT:
437 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100438 err = snd_hda_input_jack_add(codec, hv->nid,
439 SND_JACK_MICROPHONE, NULL);
440 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100441 break;
442 }
443 if (err < 0)
444 return err;
445 ++hv;
446 }
447 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100448#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100449 return 0;
450}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100451
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200452static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
453 unsigned int power_state)
454{
455 if (power_state == AC_PWRST_D3)
456 msleep(100);
457 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
458 power_state);
459 /* partial workaround for "azx_get_response timeout" */
460 if (power_state == AC_PWRST_D0)
461 msleep(10);
462 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
463}
464
Tobin Davisc9b443d2006-11-14 12:13:39 +0100465static int conexant_init(struct hda_codec *codec)
466{
467 struct conexant_spec *spec = codec->spec;
468 int i;
469
470 for (i = 0; i < spec->num_init_verbs; i++)
471 snd_hda_sequence_write(codec, spec->init_verbs[i]);
472 return 0;
473}
474
475static void conexant_free(struct hda_codec *codec)
476{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100477 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200478 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100479 kfree(codec->spec);
480}
481
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200482static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100483 {
484 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
485 .name = "Capture Source",
486 .info = conexant_mux_enum_info,
487 .get = conexant_mux_enum_get,
488 .put = conexant_mux_enum_put
489 },
490 {}
491};
492
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200493#ifdef CONFIG_SND_HDA_INPUT_BEEP
494/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200495static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200496 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
497 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
498 { } /* end */
499};
500#endif
501
Takashi Iwaiea734962011-01-17 11:29:34 +0100502static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100503 "Headphone Playback Volume",
504 "Speaker Playback Volume",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200505 "Front Playback Volume",
506 "Surround Playback Volume",
507 "CLFE Playback Volume",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100508 NULL
509};
510
Takashi Iwaiea734962011-01-17 11:29:34 +0100511static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100512 "Headphone Playback Switch",
513 "Speaker Playback Switch",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200514 "Front Playback Switch",
515 "Surround Playback Switch",
516 "CLFE Playback Switch",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100517 NULL
518};
519
Tobin Davisc9b443d2006-11-14 12:13:39 +0100520static int conexant_build_controls(struct hda_codec *codec)
521{
522 struct conexant_spec *spec = codec->spec;
523 unsigned int i;
524 int err;
525
526 for (i = 0; i < spec->num_mixers; i++) {
527 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
528 if (err < 0)
529 return err;
530 }
531 if (spec->multiout.dig_out_nid) {
532 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600533 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100534 spec->multiout.dig_out_nid);
535 if (err < 0)
536 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100537 err = snd_hda_create_spdif_share_sw(codec,
538 &spec->multiout);
539 if (err < 0)
540 return err;
541 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100542 }
543 if (spec->dig_in_nid) {
544 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
545 if (err < 0)
546 return err;
547 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100548
549 /* if we have no master control, let's create it */
550 if (spec->vmaster_nid &&
551 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
552 unsigned int vmaster_tlv[4];
553 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
554 HDA_OUTPUT, vmaster_tlv);
555 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
556 vmaster_tlv, slave_vols);
557 if (err < 0)
558 return err;
559 }
560 if (spec->vmaster_nid &&
561 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
562 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
563 NULL, slave_sws);
564 if (err < 0)
565 return err;
566 }
567
Takashi Iwaib880c742009-03-10 14:41:05 +0100568 if (spec->input_mux) {
569 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
570 if (err < 0)
571 return err;
572 }
573
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200574#ifdef CONFIG_SND_HDA_INPUT_BEEP
575 /* create beep controls if needed */
576 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200577 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200578 for (knew = cxt_beep_mixer; knew->name; knew++) {
579 struct snd_kcontrol *kctl;
580 kctl = snd_ctl_new1(knew, codec);
581 if (!kctl)
582 return -ENOMEM;
583 kctl->private_value = spec->beep_amp;
584 err = snd_hda_ctl_add(codec, 0, kctl);
585 if (err < 0)
586 return err;
587 }
588 }
589#endif
590
Tobin Davisc9b443d2006-11-14 12:13:39 +0100591 return 0;
592}
593
Takashi Iwai697c3732010-07-30 11:28:02 +0200594#ifdef CONFIG_SND_HDA_POWER_SAVE
595static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
596{
597 snd_hda_shutup_pins(codec);
598 return 0;
599}
600#endif
601
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200602static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100603 .build_controls = conexant_build_controls,
604 .build_pcms = conexant_build_pcms,
605 .init = conexant_init,
606 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200607 .set_power_state = conexant_set_power,
Takashi Iwai697c3732010-07-30 11:28:02 +0200608#ifdef CONFIG_SND_HDA_POWER_SAVE
609 .suspend = conexant_suspend,
610#endif
611 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100612};
613
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200614#ifdef CONFIG_SND_HDA_INPUT_BEEP
615#define set_beep_amp(spec, nid, idx, dir) \
616 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
617#else
618#define set_beep_amp(spec, nid, idx, dir) /* NOP */
619#endif
620
Takashi Iwai6764bce2011-05-13 16:52:25 +0200621static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100622/*
623 * EAPD control
624 * the private value = nid | (invert << 8)
625 */
626
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200627#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100628
Tobin Davis82f30042007-02-13 12:45:44 +0100629static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100630 struct snd_ctl_elem_value *ucontrol)
631{
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct conexant_spec *spec = codec->spec;
634 int invert = (kcontrol->private_value >> 8) & 1;
635 if (invert)
636 ucontrol->value.integer.value[0] = !spec->cur_eapd;
637 else
638 ucontrol->value.integer.value[0] = spec->cur_eapd;
639 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100640
Tobin Davisc9b443d2006-11-14 12:13:39 +0100641}
642
Tobin Davis82f30042007-02-13 12:45:44 +0100643static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct conexant_spec *spec = codec->spec;
648 int invert = (kcontrol->private_value >> 8) & 1;
649 hda_nid_t nid = kcontrol->private_value & 0xff;
650 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100651
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100652 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100653 if (invert)
654 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200655 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100656 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100657
Tobin Davisc9b443d2006-11-14 12:13:39 +0100658 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200659 snd_hda_codec_write_cache(codec, nid,
660 0, AC_VERB_SET_EAPD_BTLENABLE,
661 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100662 return 1;
663}
664
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100665/* controls for test mode */
666#ifdef CONFIG_SND_DEBUG
667
Tobin Davis82f30042007-02-13 12:45:44 +0100668#define CXT_EAPD_SWITCH(xname, nid, mask) \
669 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
670 .info = cxt_eapd_info, \
671 .get = cxt_eapd_get, \
672 .put = cxt_eapd_put, \
673 .private_value = nid | (mask<<16) }
674
675
676
Tobin Davisc9b443d2006-11-14 12:13:39 +0100677static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
678 struct snd_ctl_elem_info *uinfo)
679{
680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
681 struct conexant_spec *spec = codec->spec;
682 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
683 spec->num_channel_mode);
684}
685
686static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
687 struct snd_ctl_elem_value *ucontrol)
688{
689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
690 struct conexant_spec *spec = codec->spec;
691 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
692 spec->num_channel_mode,
693 spec->multiout.max_channels);
694}
695
696static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
697 struct snd_ctl_elem_value *ucontrol)
698{
699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700 struct conexant_spec *spec = codec->spec;
701 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
702 spec->num_channel_mode,
703 &spec->multiout.max_channels);
704 if (err >= 0 && spec->need_dac_fix)
705 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
706 return err;
707}
708
709#define CXT_PIN_MODE(xname, nid, dir) \
710 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
711 .info = conexant_ch_mode_info, \
712 .get = conexant_ch_mode_get, \
713 .put = conexant_ch_mode_put, \
714 .private_value = nid | (dir<<16) }
715
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100716#endif /* CONFIG_SND_DEBUG */
717
Tobin Davisc9b443d2006-11-14 12:13:39 +0100718/* Conexant 5045 specific */
719
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200720static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
721static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
722static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100723#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100724
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200725static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100726 { 2, NULL },
727};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100728
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200729static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100730 .num_items = 2,
731 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100732 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100733 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734 }
735};
736
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200737static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200738 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100739 .items = {
740 { "IntMic", 0x1 },
741 { "ExtMic", 0x2 },
742 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200743 { "CD", 0x4 },
744 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100745 }
746};
747
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200748static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100749 .num_items = 2,
750 .items = {
751 { "ExtMic", 0x1 },
752 { "IntMic", 0x2 },
753 }
754};
755
Tobin Davisc9b443d2006-11-14 12:13:39 +0100756/* turn on/off EAPD (+ mute HP) as a master switch */
757static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
758 struct snd_ctl_elem_value *ucontrol)
759{
760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
761 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100762 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100763
Tobin Davis82f30042007-02-13 12:45:44 +0100764 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100765 return 0;
766
Tobin Davis82f30042007-02-13 12:45:44 +0100767 /* toggle internal speakers mute depending of presence of
768 * the headphone jack
769 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200770 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
771 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
772 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100773
Takashi Iwai47fd8302007-08-10 17:11:07 +0200774 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
775 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
776 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100777 return 1;
778}
779
780/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200781static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200782 .ops = &snd_hda_bind_vol,
783 .values = {
784 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
785 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
786 0
787 },
788};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100789
Tobin Davis7f296732007-03-12 11:39:01 +0100790/* toggle input of built-in and mic jack appropriately */
791static void cxt5045_hp_automic(struct hda_codec *codec)
792{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200793 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
795 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
796 {}
797 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200798 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100799 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
801 {}
802 };
803 unsigned int present;
804
Takashi Iwaid56757a2009-11-18 08:00:14 +0100805 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100806 if (present)
807 snd_hda_sequence_write(codec, mic_jack_on);
808 else
809 snd_hda_sequence_write(codec, mic_jack_off);
810}
811
Tobin Davisc9b443d2006-11-14 12:13:39 +0100812
813/* mute internal speaker if HP is plugged */
814static void cxt5045_hp_automute(struct hda_codec *codec)
815{
Tobin Davis82f30042007-02-13 12:45:44 +0100816 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100817 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818
Takashi Iwaid56757a2009-11-18 08:00:14 +0100819 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100820
Takashi Iwai47fd8302007-08-10 17:11:07 +0200821 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
822 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
823 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100824}
825
826/* unsolicited event for HP jack sensing */
827static void cxt5045_hp_unsol_event(struct hda_codec *codec,
828 unsigned int res)
829{
830 res >>= 26;
831 switch (res) {
832 case CONEXANT_HP_EVENT:
833 cxt5045_hp_automute(codec);
834 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100835 case CONEXANT_MIC_EVENT:
836 cxt5045_hp_automic(codec);
837 break;
838
Tobin Davisc9b443d2006-11-14 12:13:39 +0100839 }
840}
841
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200842static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100843 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
844 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100845 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
846 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200847 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
848 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100849 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
850 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100851 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
852 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200853 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100854 {
855 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
856 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100857 .info = cxt_eapd_info,
858 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100859 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100860 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100861 },
862
863 {}
864};
865
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200866static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200867 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
868 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
869 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
870 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
871
Jiang Zhe5218c892008-01-17 11:18:41 +0100872 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
873 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
874 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
875 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
876
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200877 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
878 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
879
Jiang Zhe5218c892008-01-17 11:18:41 +0100880 {}
881};
882
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200883static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100884 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
885 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100886 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
887 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100888 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
889 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100890 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
891 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100892 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
893 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100894 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
895 {
896 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
897 .name = "Master Playback Switch",
898 .info = cxt_eapd_info,
899 .get = cxt_eapd_get,
900 .put = cxt5045_hp_master_sw_put,
901 .private_value = 0x10,
902 },
903
904 {}
905};
906
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200907static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100908 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200909 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100910 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100911 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200912 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
913 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
914 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
915 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
917 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
918 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
919 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
920 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100921 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100922 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100923 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100924 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
925 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100926 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100927 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100929 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100930 { } /* end */
931};
932
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200933static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100934 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100935 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
936 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
937 /* Line In,HP, Amp */
938 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
939 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
940 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
941 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
942 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
943 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
944 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
945 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
946 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100947 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100948 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
949 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
950 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
951 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100952 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100953 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
954 /* EAPD */
955 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
956 { } /* end */
957};
Tobin Davis7f296732007-03-12 11:39:01 +0100958
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200959static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100960 /* pin sensing on HP jack */
961 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200962 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100963};
964
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200965static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100966 /* pin sensing on HP jack */
967 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200968 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100969};
970
Tobin Davisc9b443d2006-11-14 12:13:39 +0100971#ifdef CONFIG_SND_DEBUG
972/* Test configuration for debugging, modelled after the ALC260 test
973 * configuration.
974 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200975static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100976 .num_items = 5,
977 .items = {
978 { "MIXER", 0x0 },
979 { "MIC1 pin", 0x1 },
980 { "LINE1 pin", 0x2 },
981 { "HP-OUT pin", 0x3 },
982 { "CD pin", 0x4 },
983 },
984};
985
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200986static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100987
988 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100989 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
990 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100991 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
992 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
993 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
994 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100995
996 /* Modes for retasking pin widgets */
997 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
998 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
999
Tobin Davis82f30042007-02-13 12:45:44 +01001000 /* EAPD Switch Control */
1001 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1002
Tobin Davisc9b443d2006-11-14 12:13:39 +01001003 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001004
Tobin Davis7f296732007-03-12 11:39:01 +01001005 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1006 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1007 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1008 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1009 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1010 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1011 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1012 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1013 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1014 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001015 {
1016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1017 .name = "Input Source",
1018 .info = conexant_mux_enum_info,
1019 .get = conexant_mux_enum_get,
1020 .put = conexant_mux_enum_put,
1021 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001022 /* Audio input controls */
1023 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1024 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1025 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1026 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1027 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1028 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1029 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1030 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1031 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1032 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001033 { } /* end */
1034};
1035
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001036static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001037 /* Set connections */
1038 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1039 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1040 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001041 /* Enable retasking pins as output, initially without power amp */
1042 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001043 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001044
1045 /* Disable digital (SPDIF) pins initially, but users can enable
1046 * them via a mixer switch. In the case of SPDIF-out, this initverb
1047 * payload also sets the generation to 0, output to be in "consumer"
1048 * PCM format, copyright asserted, no pre-emphasis and no validity
1049 * control.
1050 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001051 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1052 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001053
1054 /* Start with output sum widgets muted and their output gains at min */
1055 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1056 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1057
1058 /* Unmute retasking pin widget output buffers since the default
1059 * state appears to be output. As the pin mode is changed by the
1060 * user the pin mode control will take care of enabling the pin's
1061 * input/output buffers as needed.
1062 */
1063 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1064 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1065
1066 /* Mute capture amp left and right */
1067 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1068
1069 /* Set ADC connection select to match default mixer setting (mic1
1070 * pin)
1071 */
1072 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001073 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001074
1075 /* Mute all inputs to mixer widget (even unconnected ones) */
1076 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1077 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1078 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1079 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1080 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1081
1082 { }
1083};
1084#endif
1085
1086
1087/* initialize jack-sensing, too */
1088static int cxt5045_init(struct hda_codec *codec)
1089{
1090 conexant_init(codec);
1091 cxt5045_hp_automute(codec);
1092 return 0;
1093}
1094
1095
1096enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001097 CXT5045_LAPTOP_HPSENSE,
1098 CXT5045_LAPTOP_MICSENSE,
1099 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001100 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001101 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001102#ifdef CONFIG_SND_DEBUG
1103 CXT5045_TEST,
1104#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001105 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001106 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001107};
1108
Takashi Iwaiea734962011-01-17 11:29:34 +01001109static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001110 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1111 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1112 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1113 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001114 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001115#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001116 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001117#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001118 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001119};
1120
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001121static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001122 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001123 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1124 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001125 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001126 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001127 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1128 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001129 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1130 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001131 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1132 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1133 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001134 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1135 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001136 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137 {}
1138};
1139
1140static int patch_cxt5045(struct hda_codec *codec)
1141{
1142 struct conexant_spec *spec;
1143 int board_config;
1144
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001145 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1146 cxt5045_models,
1147 cxt5045_cfg_tbl);
1148 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001149 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001150 if (board_config == CXT5045_AUTO)
1151 return patch_conexant_auto(codec);
1152
Tobin Davisc9b443d2006-11-14 12:13:39 +01001153 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1154 if (!spec)
1155 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001156 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001157 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001158
1159 spec->multiout.max_channels = 2;
1160 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1161 spec->multiout.dac_nids = cxt5045_dac_nids;
1162 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1163 spec->num_adc_nids = 1;
1164 spec->adc_nids = cxt5045_adc_nids;
1165 spec->capsrc_nids = cxt5045_capsrc_nids;
1166 spec->input_mux = &cxt5045_capture_source;
1167 spec->num_mixers = 1;
1168 spec->mixers[0] = cxt5045_mixers;
1169 spec->num_init_verbs = 1;
1170 spec->init_verbs[0] = cxt5045_init_verbs;
1171 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001172 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1173 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001174
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001175 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001176
1177 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001178
Tobin Davisc9b443d2006-11-14 12:13:39 +01001179 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001180 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001181 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001182 spec->input_mux = &cxt5045_capture_source;
1183 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001184 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1185 spec->mixers[0] = cxt5045_mixers;
1186 codec->patch_ops.init = cxt5045_init;
1187 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001188 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001189 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001190 spec->input_mux = &cxt5045_capture_source;
1191 spec->num_init_verbs = 2;
1192 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193 spec->mixers[0] = cxt5045_mixers;
1194 codec->patch_ops.init = cxt5045_init;
1195 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001196 default:
1197 case CXT5045_LAPTOP_HPMICSENSE:
1198 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1199 spec->input_mux = &cxt5045_capture_source;
1200 spec->num_init_verbs = 3;
1201 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1202 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1203 spec->mixers[0] = cxt5045_mixers;
1204 codec->patch_ops.init = cxt5045_init;
1205 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001206 case CXT5045_BENQ:
1207 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1208 spec->input_mux = &cxt5045_capture_source_benq;
1209 spec->num_init_verbs = 1;
1210 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1211 spec->mixers[0] = cxt5045_mixers;
1212 spec->mixers[1] = cxt5045_benq_mixers;
1213 spec->num_mixers = 2;
1214 codec->patch_ops.init = cxt5045_init;
1215 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001216 case CXT5045_LAPTOP_HP530:
1217 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1218 spec->input_mux = &cxt5045_capture_source_hp530;
1219 spec->num_init_verbs = 2;
1220 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1221 spec->mixers[0] = cxt5045_mixers_hp530;
1222 codec->patch_ops.init = cxt5045_init;
1223 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001224#ifdef CONFIG_SND_DEBUG
1225 case CXT5045_TEST:
1226 spec->input_mux = &cxt5045_test_capture_source;
1227 spec->mixers[0] = cxt5045_test_mixer;
1228 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001229 break;
1230
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231#endif
1232 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001233
Takashi Iwai031005f2008-06-26 14:49:58 +02001234 switch (codec->subsystem_id >> 16) {
1235 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001236 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001237 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001238 case 0x17aa:
1239 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1240 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1241 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001242 */
1243 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1244 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1245 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1246 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1247 (1 << AC_AMPCAP_MUTE_SHIFT));
1248 break;
1249 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001250
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001251 if (spec->beep_amp)
1252 snd_hda_attach_beep_device(codec, spec->beep_amp);
1253
Tobin Davisc9b443d2006-11-14 12:13:39 +01001254 return 0;
1255}
1256
1257
1258/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001259#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001260
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001261static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1262static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1263static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001264
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001265static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001266 { 2, NULL },
1267};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001268
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001269static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001270 .num_items = 2,
1271 .items = {
1272 { "ExtMic", 0x2 },
1273 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001274 }
1275};
1276
1277/* turn on/off EAPD (+ mute HP) as a master switch */
1278static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1279 struct snd_ctl_elem_value *ucontrol)
1280{
1281 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1282 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001283 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001284
Tobin Davis82f30042007-02-13 12:45:44 +01001285 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286 return 0;
1287
Tobin Davis82f30042007-02-13 12:45:44 +01001288 /* toggle internal speakers mute depending of presence of
1289 * the headphone jack
1290 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001291 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001292 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1293 * pin widgets unlike other codecs. In this case, we need to
1294 * set index 0x01 for the volume from the mixer amp 0x19.
1295 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001296 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001297 HDA_AMP_MUTE, bits);
1298 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1299 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1300 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001301 return 1;
1302}
1303
Tobin Davisc9b443d2006-11-14 12:13:39 +01001304/* mute internal speaker if HP is plugged */
1305static void cxt5047_hp_automute(struct hda_codec *codec)
1306{
Tobin Davis82f30042007-02-13 12:45:44 +01001307 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001308 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001309
Takashi Iwaid56757a2009-11-18 08:00:14 +01001310 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001311
Takashi Iwai47fd8302007-08-10 17:11:07 +02001312 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001313 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001314 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001315 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316}
1317
1318/* toggle input of built-in and mic jack appropriately */
1319static void cxt5047_hp_automic(struct hda_codec *codec)
1320{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001321 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001322 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1323 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001324 {}
1325 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001326 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001327 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1328 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001329 {}
1330 };
1331 unsigned int present;
1332
Takashi Iwaid56757a2009-11-18 08:00:14 +01001333 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001334 if (present)
1335 snd_hda_sequence_write(codec, mic_jack_on);
1336 else
1337 snd_hda_sequence_write(codec, mic_jack_off);
1338}
1339
1340/* unsolicited event for HP jack sensing */
1341static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1342 unsigned int res)
1343{
Marc Boucher9f113e02008-01-22 15:18:08 +01001344 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001345 case CONEXANT_HP_EVENT:
1346 cxt5047_hp_automute(codec);
1347 break;
1348 case CONEXANT_MIC_EVENT:
1349 cxt5047_hp_automic(codec);
1350 break;
1351 }
1352}
1353
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001354static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001355 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1356 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001357 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001358 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1359 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1360 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1361 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001362 {
1363 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1364 .name = "Master Playback Switch",
1365 .info = cxt_eapd_info,
1366 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 .put = cxt5047_hp_master_sw_put,
1368 .private_value = 0x13,
1369 },
1370
1371 {}
1372};
1373
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001374static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001375 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001376 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001377 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1378 {}
1379};
1380
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001381static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001383 { } /* end */
1384};
1385
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001386static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387 /* Line in, Mic, Built-in Mic */
1388 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1389 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1390 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001391 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001392 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001393 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1394 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001395 /* Record selector: Mic */
1396 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1397 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1398 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1399 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001400 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1401 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1402 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1403 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001404 /* SPDIF route: PCM */
1405 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001406 /* Enable unsolicited events */
1407 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1408 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001409 { } /* end */
1410};
1411
1412/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001413static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001414 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 {}
1416};
1417
1418/* Test configuration for debugging, modelled after the ALC260 test
1419 * configuration.
1420 */
1421#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001422static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001423 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001424 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001425 { "LINE1 pin", 0x0 },
1426 { "MIC1 pin", 0x1 },
1427 { "MIC2 pin", 0x2 },
1428 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001429 },
1430};
1431
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001432static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001433
1434 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001435 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1436 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1437 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1438 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001439 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1440 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1441 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1442 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001443 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1444 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1445 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1446 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001447
1448 /* Modes for retasking pin widgets */
1449 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1450 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1451
Tobin Davis82f30042007-02-13 12:45:44 +01001452 /* EAPD Switch Control */
1453 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1454
Tobin Davisc9b443d2006-11-14 12:13:39 +01001455 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001456 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1457 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1458 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1459 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1460 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1461 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1462 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1463 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001464
Tobin Davis82f30042007-02-13 12:45:44 +01001465 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1466 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1467 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1468 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1469 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1470 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1471 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1472 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001473 {
1474 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1475 .name = "Input Source",
1476 .info = conexant_mux_enum_info,
1477 .get = conexant_mux_enum_get,
1478 .put = conexant_mux_enum_put,
1479 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001480 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001481
Tobin Davisc9b443d2006-11-14 12:13:39 +01001482 { } /* end */
1483};
1484
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001485static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001486 /* Enable retasking pins as output, initially without power amp */
1487 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1490
1491 /* Disable digital (SPDIF) pins initially, but users can enable
1492 * them via a mixer switch. In the case of SPDIF-out, this initverb
1493 * payload also sets the generation to 0, output to be in "consumer"
1494 * PCM format, copyright asserted, no pre-emphasis and no validity
1495 * control.
1496 */
1497 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1498
1499 /* Ensure mic1, mic2, line1 pin widgets take input from the
1500 * OUT1 sum bus when acting as an output.
1501 */
1502 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1503 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1504
1505 /* Start with output sum widgets muted and their output gains at min */
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1507 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1508
1509 /* Unmute retasking pin widget output buffers since the default
1510 * state appears to be output. As the pin mode is changed by the
1511 * user the pin mode control will take care of enabling the pin's
1512 * input/output buffers as needed.
1513 */
1514 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1517
1518 /* Mute capture amp left and right */
1519 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1520
1521 /* Set ADC connection select to match default mixer setting (mic1
1522 * pin)
1523 */
1524 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1525
1526 /* Mute all inputs to mixer widget (even unconnected ones) */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1535
1536 { }
1537};
1538#endif
1539
1540
1541/* initialize jack-sensing, too */
1542static int cxt5047_hp_init(struct hda_codec *codec)
1543{
1544 conexant_init(codec);
1545 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001546 return 0;
1547}
1548
1549
1550enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001551 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1552 CXT5047_LAPTOP_HP, /* Some HP laptops */
1553 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001554#ifdef CONFIG_SND_DEBUG
1555 CXT5047_TEST,
1556#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001557 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001558 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001559};
1560
Takashi Iwaiea734962011-01-17 11:29:34 +01001561static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001562 [CXT5047_LAPTOP] = "laptop",
1563 [CXT5047_LAPTOP_HP] = "laptop-hp",
1564 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001565#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001566 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001567#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001568 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001569};
1570
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001571static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001572 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001573 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1574 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001575 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576 {}
1577};
1578
1579static int patch_cxt5047(struct hda_codec *codec)
1580{
1581 struct conexant_spec *spec;
1582 int board_config;
1583
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001584 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1585 cxt5047_models,
1586 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001587 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001588 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001589 if (board_config == CXT5047_AUTO)
1590 return patch_conexant_auto(codec);
1591
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1593 if (!spec)
1594 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001595 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001596 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001597
1598 spec->multiout.max_channels = 2;
1599 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1600 spec->multiout.dac_nids = cxt5047_dac_nids;
1601 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1602 spec->num_adc_nids = 1;
1603 spec->adc_nids = cxt5047_adc_nids;
1604 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001605 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001606 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001607 spec->num_init_verbs = 1;
1608 spec->init_verbs[0] = cxt5047_init_verbs;
1609 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001610 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1611 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001612
1613 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614
Tobin Davisc9b443d2006-11-14 12:13:39 +01001615 switch (board_config) {
1616 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001617 spec->num_mixers = 2;
1618 spec->mixers[1] = cxt5047_hp_spk_mixers;
1619 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001620 break;
1621 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001622 spec->num_mixers = 2;
1623 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001624 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001625 codec->patch_ops.init = cxt5047_hp_init;
1626 break;
1627 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001628 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001629 spec->num_mixers = 2;
1630 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001631 spec->num_init_verbs = 2;
1632 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001633 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001634 break;
1635#ifdef CONFIG_SND_DEBUG
1636 case CXT5047_TEST:
1637 spec->input_mux = &cxt5047_test_capture_source;
1638 spec->mixers[0] = cxt5047_test_mixer;
1639 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001640 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001641#endif
1642 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001643 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001644
1645 switch (codec->subsystem_id >> 16) {
1646 case 0x103c:
1647 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1648 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1649 * with 0 dB offset 0x17)
1650 */
1651 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1652 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1653 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1654 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1655 (1 << AC_AMPCAP_MUTE_SHIFT));
1656 break;
1657 }
1658
Tobin Davisc9b443d2006-11-14 12:13:39 +01001659 return 0;
1660}
1661
Takashi Iwai461e2c72008-01-25 11:35:17 +01001662/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001663static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1664static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001665
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001666static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001667 { 2, NULL },
1668};
1669
1670static void cxt5051_update_speaker(struct hda_codec *codec)
1671{
1672 struct conexant_spec *spec = codec->spec;
1673 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001674 /* headphone pin */
1675 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1676 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1677 pinctl);
1678 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1680 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1681 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001682 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1683 if (spec->ideapad)
1684 snd_hda_codec_write(codec, 0x1b, 0,
1685 AC_VERB_SET_PIN_WIDGET_CONTROL,
1686 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001687}
1688
1689/* turn on/off EAPD (+ mute HP) as a master switch */
1690static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1691 struct snd_ctl_elem_value *ucontrol)
1692{
1693 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1694
1695 if (!cxt_eapd_put(kcontrol, ucontrol))
1696 return 0;
1697 cxt5051_update_speaker(codec);
1698 return 1;
1699}
1700
1701/* toggle input of built-in and mic jack appropriately */
1702static void cxt5051_portb_automic(struct hda_codec *codec)
1703{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001704 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001705 unsigned int present;
1706
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001707 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001708 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001709 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001710 snd_hda_codec_write(codec, 0x14, 0,
1711 AC_VERB_SET_CONNECT_SEL,
1712 present ? 0x01 : 0x00);
1713}
1714
1715/* switch the current ADC according to the jack state */
1716static void cxt5051_portc_automic(struct hda_codec *codec)
1717{
1718 struct conexant_spec *spec = codec->spec;
1719 unsigned int present;
1720 hda_nid_t new_adc;
1721
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001722 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001723 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001724 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001725 if (present)
1726 spec->cur_adc_idx = 1;
1727 else
1728 spec->cur_adc_idx = 0;
1729 new_adc = spec->adc_nids[spec->cur_adc_idx];
1730 if (spec->cur_adc && spec->cur_adc != new_adc) {
1731 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001732 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001733 spec->cur_adc = new_adc;
1734 snd_hda_codec_setup_stream(codec, new_adc,
1735 spec->cur_adc_stream_tag, 0,
1736 spec->cur_adc_format);
1737 }
1738}
1739
1740/* mute internal speaker if HP is plugged */
1741static void cxt5051_hp_automute(struct hda_codec *codec)
1742{
1743 struct conexant_spec *spec = codec->spec;
1744
Takashi Iwaid56757a2009-11-18 08:00:14 +01001745 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001746 cxt5051_update_speaker(codec);
1747}
1748
1749/* unsolicited event for HP jack sensing */
1750static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1751 unsigned int res)
1752{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001753 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001754 switch (res >> 26) {
1755 case CONEXANT_HP_EVENT:
1756 cxt5051_hp_automute(codec);
1757 break;
1758 case CXT5051_PORTB_EVENT:
1759 cxt5051_portb_automic(codec);
1760 break;
1761 case CXT5051_PORTC_EVENT:
1762 cxt5051_portc_automic(codec);
1763 break;
1764 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001765 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001766}
1767
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001768static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001769 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1770 {
1771 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1772 .name = "Master Playback Switch",
1773 .info = cxt_eapd_info,
1774 .get = cxt_eapd_get,
1775 .put = cxt5051_hp_master_sw_put,
1776 .private_value = 0x1a,
1777 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001778 {}
1779};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001780
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001781static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001782 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1783 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001784 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1785 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001786 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1787 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001788 {}
1789};
1790
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001791static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001792 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1793 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001794 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1795 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001796 {}
1797};
1798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001799static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001800 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1801 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001802 {}
1803};
1804
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001805static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001806 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1807 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001808 {}
1809};
1810
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001811static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001812 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1813 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001814 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1815 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001816 {}
1817};
1818
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001819static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001820 /* Line in, Mic */
1821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1822 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1823 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1824 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1825 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1826 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1827 /* SPK */
1828 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1829 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1830 /* HP, Amp */
1831 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1832 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1833 /* DAC1 */
1834 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001835 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001836 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1837 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1838 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1839 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001840 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001841 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1842 /* EAPD */
1843 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1844 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001845 { } /* end */
1846};
1847
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001848static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001849 /* Line in, Mic */
1850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1851 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1852 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1853 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1854 /* SPK */
1855 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1856 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1857 /* HP, Amp */
1858 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1859 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1860 /* DAC1 */
1861 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001862 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001863 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1864 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1865 /* SPDIF route: PCM */
1866 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1867 /* EAPD */
1868 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1869 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001870 { } /* end */
1871};
1872
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001873static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001874 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001876 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1877 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1878 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1879 /* SPK */
1880 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1881 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1882 /* HP, Amp */
1883 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1884 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1885 /* DAC1 */
1886 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001887 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001888 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1889 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1890 /* SPDIF route: PCM */
1891 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1892 /* EAPD */
1893 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1894 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001895 { } /* end */
1896};
1897
Takashi Iwai6953e552010-01-24 11:00:27 +01001898static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1899 unsigned int event)
1900{
1901 snd_hda_codec_write(codec, nid, 0,
1902 AC_VERB_SET_UNSOLICITED_ENABLE,
1903 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001904 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1905 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001906}
1907
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001908static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001909 /* Subwoofer */
1910 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1911 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1912 { } /* end */
1913};
1914
Takashi Iwai461e2c72008-01-25 11:35:17 +01001915/* initialize jack-sensing, too */
1916static int cxt5051_init(struct hda_codec *codec)
1917{
Takashi Iwai6953e552010-01-24 11:00:27 +01001918 struct conexant_spec *spec = codec->spec;
1919
Takashi Iwai461e2c72008-01-25 11:35:17 +01001920 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001921 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001922
1923 if (spec->auto_mic & AUTO_MIC_PORTB)
1924 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1925 if (spec->auto_mic & AUTO_MIC_PORTC)
1926 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1927
Takashi Iwai461e2c72008-01-25 11:35:17 +01001928 if (codec->patch_ops.unsol_event) {
1929 cxt5051_hp_automute(codec);
1930 cxt5051_portb_automic(codec);
1931 cxt5051_portc_automic(codec);
1932 }
1933 return 0;
1934}
1935
1936
1937enum {
1938 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1939 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001940 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001941 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001942 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001943 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001944 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001945 CXT5051_MODELS
1946};
1947
Takashi Iwaiea734962011-01-17 11:29:34 +01001948static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001949 [CXT5051_LAPTOP] = "laptop",
1950 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001951 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001952 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001953 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001954 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001955 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001956};
1957
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001958static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001959 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001960 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001961 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001962 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001963 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1964 CXT5051_LAPTOP),
1965 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001966 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001967 {}
1968};
1969
1970static int patch_cxt5051(struct hda_codec *codec)
1971{
1972 struct conexant_spec *spec;
1973 int board_config;
1974
Takashi Iwai6764bce2011-05-13 16:52:25 +02001975 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1976 cxt5051_models,
1977 cxt5051_cfg_tbl);
1978 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001979 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001980 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001981 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001982
Takashi Iwai461e2c72008-01-25 11:35:17 +01001983 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1984 if (!spec)
1985 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001986 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001987 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001988
1989 codec->patch_ops = conexant_patch_ops;
1990 codec->patch_ops.init = cxt5051_init;
1991
1992 spec->multiout.max_channels = 2;
1993 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1994 spec->multiout.dac_nids = cxt5051_dac_nids;
1995 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1996 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1997 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001998 spec->num_mixers = 2;
1999 spec->mixers[0] = cxt5051_capture_mixers;
2000 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002001 spec->num_init_verbs = 1;
2002 spec->init_verbs[0] = cxt5051_init_verbs;
2003 spec->spdif_route = 0;
2004 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2005 spec->channel_mode = cxt5051_modes;
2006 spec->cur_adc = 0;
2007 spec->cur_adc_idx = 0;
2008
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002009 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2010
Takashi Iwai79d7d532009-03-04 09:03:50 +01002011 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2012
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002013 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002014 switch (board_config) {
2015 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002016 spec->mixers[0] = cxt5051_hp_mixers;
2017 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002018 case CXT5051_HP_DV6736:
2019 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2020 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002021 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002022 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002023 case CXT5051_F700:
2024 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2025 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002026 spec->auto_mic = 0;
2027 break;
2028 case CXT5051_TOSHIBA:
2029 spec->mixers[0] = cxt5051_toshiba_mixers;
2030 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002031 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03002032 case CXT5051_IDEAPAD:
2033 spec->init_verbs[spec->num_init_verbs++] =
2034 cxt5051_ideapad_init_verbs;
2035 spec->ideapad = 1;
2036 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002037 }
2038
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002039 if (spec->beep_amp)
2040 snd_hda_attach_beep_device(codec, spec->beep_amp);
2041
Takashi Iwai461e2c72008-01-25 11:35:17 +01002042 return 0;
2043}
2044
Daniel Drake0fb67e92009-07-16 14:46:57 +01002045/* Conexant 5066 specific */
2046
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002047static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2048static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2049static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2050static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002051
Daniel Drakedbaccc02009-11-09 15:17:24 +00002052/* OLPC's microphone port is DC coupled for use with external sensors,
2053 * therefore we use a 50% mic bias in order to center the input signal with
2054 * the DC input range of the codec. */
2055#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2056
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002057static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002058 { 2, NULL },
2059};
2060
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002061#define HP_PRESENT_PORT_A (1 << 0)
2062#define HP_PRESENT_PORT_D (1 << 1)
2063#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2064#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2065
Daniel Drake0fb67e92009-07-16 14:46:57 +01002066static void cxt5066_update_speaker(struct hda_codec *codec)
2067{
2068 struct conexant_spec *spec = codec->spec;
2069 unsigned int pinctl;
2070
John Baboval3a253442010-12-02 11:21:31 -05002071 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2072 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002073
2074 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002075 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002076 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2077 pinctl);
2078
2079 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002080 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2081 if (spec->dell_automute || spec->thinkpad) {
2082 /* Mute if Port A is connected */
2083 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002084 pinctl = 0;
2085 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002086 /* Thinkpad/Dell doesn't give pin-D status */
2087 if (!hp_port_d_present(spec))
2088 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002089 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002090 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2091 pinctl);
2092
2093 /* CLASS_D AMP */
2094 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2095 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2096 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002097}
2098
2099/* turn on/off EAPD (+ mute HP) as a master switch */
2100static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2101 struct snd_ctl_elem_value *ucontrol)
2102{
2103 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2104
2105 if (!cxt_eapd_put(kcontrol, ucontrol))
2106 return 0;
2107
2108 cxt5066_update_speaker(codec);
2109 return 1;
2110}
2111
Daniel Drakec4cfe662010-01-07 13:47:04 +01002112static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2113 .num_items = 3,
2114 .items = {
2115 { "Off", PIN_IN },
2116 { "50%", PIN_VREF50 },
2117 { "80%", PIN_VREF80 },
2118 },
2119};
2120
2121static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2122{
2123 struct conexant_spec *spec = codec->spec;
2124 /* Even though port F is the DC input, the bias is controlled on port B.
2125 * we also leave that port as an active input (but unselected) in DC mode
2126 * just in case that is necessary to make the bias setting take effect. */
2127 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2128 AC_VERB_SET_PIN_WIDGET_CONTROL,
2129 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2130}
2131
Daniel Drake75f89912010-01-07 13:46:25 +01002132/* OLPC defers mic widget control until when capture is started because the
2133 * microphone LED comes on as soon as these settings are put in place. if we
2134 * did this before recording, it would give the false indication that recording
2135 * is happening when it is not. */
2136static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002137{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002138 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002139 if (!spec->recording)
2140 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002141
Daniel Drakec4cfe662010-01-07 13:47:04 +01002142 if (spec->dc_enable) {
2143 /* in DC mode we ignore presence detection and just use the jack
2144 * through our special DC port */
2145 const struct hda_verb enable_dc_mode[] = {
2146 /* disble internal mic, port C */
2147 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2148
2149 /* enable DC capture, port F */
2150 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2151 {},
2152 };
2153
2154 snd_hda_sequence_write(codec, enable_dc_mode);
2155 /* port B input disabled (and bias set) through the following call */
2156 cxt5066_set_olpc_dc_bias(codec);
2157 return;
2158 }
2159
2160 /* disable DC (port F) */
2161 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2162
Daniel Drake75f89912010-01-07 13:46:25 +01002163 /* external mic, port B */
2164 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2165 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002166
Daniel Drake75f89912010-01-07 13:46:25 +01002167 /* internal mic, port C */
2168 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2169 spec->ext_mic_present ? 0 : PIN_VREF80);
2170}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002171
Daniel Drake75f89912010-01-07 13:46:25 +01002172/* toggle input of built-in and mic jack appropriately */
2173static void cxt5066_olpc_automic(struct hda_codec *codec)
2174{
2175 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002176 unsigned int present;
2177
Daniel Drakec4cfe662010-01-07 13:47:04 +01002178 if (spec->dc_enable) /* don't do presence detection in DC mode */
2179 return;
2180
Daniel Drake75f89912010-01-07 13:46:25 +01002181 present = snd_hda_codec_read(codec, 0x1a, 0,
2182 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2183 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002184 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002185 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002186 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002187
2188 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2189 present ? 0 : 1);
2190 spec->ext_mic_present = !!present;
2191
2192 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002193}
2194
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002195/* toggle input of built-in digital mic and mic jack appropriately */
2196static void cxt5066_vostro_automic(struct hda_codec *codec)
2197{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002198 unsigned int present;
2199
2200 struct hda_verb ext_mic_present[] = {
2201 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002202 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002203
2204 /* switch to external mic input */
2205 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2206 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2207
2208 /* disable internal digital mic */
2209 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2210 {}
2211 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002212 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002213 /* enable internal mic, port C */
2214 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2215
2216 /* switch to internal mic input */
2217 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2218
2219 /* disable external mic, port B */
2220 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2221 {}
2222 };
2223
2224 present = snd_hda_jack_detect(codec, 0x1a);
2225 if (present) {
2226 snd_printdd("CXT5066: external microphone detected\n");
2227 snd_hda_sequence_write(codec, ext_mic_present);
2228 } else {
2229 snd_printdd("CXT5066: external microphone absent\n");
2230 snd_hda_sequence_write(codec, ext_mic_absent);
2231 }
2232}
2233
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002234/* toggle input of built-in digital mic and mic jack appropriately */
2235static void cxt5066_ideapad_automic(struct hda_codec *codec)
2236{
2237 unsigned int present;
2238
2239 struct hda_verb ext_mic_present[] = {
2240 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2241 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2242 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2243 {}
2244 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002245 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002246 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2247 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2248 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2249 {}
2250 };
2251
2252 present = snd_hda_jack_detect(codec, 0x1b);
2253 if (present) {
2254 snd_printdd("CXT5066: external microphone detected\n");
2255 snd_hda_sequence_write(codec, ext_mic_present);
2256 } else {
2257 snd_printdd("CXT5066: external microphone absent\n");
2258 snd_hda_sequence_write(codec, ext_mic_absent);
2259 }
2260}
2261
David Henningssona1d69062011-01-21 13:33:28 +01002262
2263/* toggle input of built-in digital mic and mic jack appropriately */
2264static void cxt5066_asus_automic(struct hda_codec *codec)
2265{
2266 unsigned int present;
2267
2268 present = snd_hda_jack_detect(codec, 0x1b);
2269 snd_printdd("CXT5066: external microphone present=%d\n", present);
2270 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2271 present ? 1 : 0);
2272}
2273
2274
David Henningsson048e78a2010-09-02 08:35:47 +02002275/* toggle input of built-in digital mic and mic jack appropriately */
2276static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2277{
2278 unsigned int present;
2279
2280 present = snd_hda_jack_detect(codec, 0x1b);
2281 snd_printdd("CXT5066: external microphone present=%d\n", present);
2282 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2283 present ? 1 : 3);
2284}
2285
2286
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002287/* toggle input of built-in digital mic and mic jack appropriately
2288 order is: external mic -> dock mic -> interal mic */
2289static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2290{
2291 unsigned int ext_present, dock_present;
2292
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002293 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002294 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2295 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2296 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2297 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2298 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2299 {}
2300 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002301 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002302 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2303 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2304 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2305 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2307 {}
2308 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002309 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002310 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2311 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2312 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2314 {}
2315 };
2316
2317 ext_present = snd_hda_jack_detect(codec, 0x1b);
2318 dock_present = snd_hda_jack_detect(codec, 0x1a);
2319 if (ext_present) {
2320 snd_printdd("CXT5066: external microphone detected\n");
2321 snd_hda_sequence_write(codec, ext_mic_present);
2322 } else if (dock_present) {
2323 snd_printdd("CXT5066: dock microphone detected\n");
2324 snd_hda_sequence_write(codec, dock_mic_present);
2325 } else {
2326 snd_printdd("CXT5066: external microphone absent\n");
2327 snd_hda_sequence_write(codec, ext_mic_absent);
2328 }
2329}
2330
Daniel Drake0fb67e92009-07-16 14:46:57 +01002331/* mute internal speaker if HP is plugged */
2332static void cxt5066_hp_automute(struct hda_codec *codec)
2333{
2334 struct conexant_spec *spec = codec->spec;
2335 unsigned int portA, portD;
2336
2337 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002338 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002339
2340 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002341 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002342
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002343 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2344 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002345 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2346 portA, portD, spec->hp_present);
2347 cxt5066_update_speaker(codec);
2348}
2349
David Henningsson02b6b5b2011-01-21 13:27:39 +01002350/* Dispatch the right mic autoswitch function */
2351static void cxt5066_automic(struct hda_codec *codec)
2352{
2353 struct conexant_spec *spec = codec->spec;
2354
2355 if (spec->dell_vostro)
2356 cxt5066_vostro_automic(codec);
2357 else if (spec->ideapad)
2358 cxt5066_ideapad_automic(codec);
2359 else if (spec->thinkpad)
2360 cxt5066_thinkpad_automic(codec);
2361 else if (spec->hp_laptop)
2362 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002363 else if (spec->asus)
2364 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002365}
2366
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002368static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002369{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002370 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002371 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2372 switch (res >> 26) {
2373 case CONEXANT_HP_EVENT:
2374 cxt5066_hp_automute(codec);
2375 break;
2376 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002377 /* ignore mic events in DC mode; we're always using the jack */
2378 if (!spec->dc_enable)
2379 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002380 break;
2381 }
2382}
2383
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002384/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002385static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002386{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002387 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002388 switch (res >> 26) {
2389 case CONEXANT_HP_EVENT:
2390 cxt5066_hp_automute(codec);
2391 break;
2392 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002393 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002394 break;
2395 }
2396}
2397
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002398
Daniel Drake0fb67e92009-07-16 14:46:57 +01002399static const struct hda_input_mux cxt5066_analog_mic_boost = {
2400 .num_items = 5,
2401 .items = {
2402 { "0dB", 0 },
2403 { "10dB", 1 },
2404 { "20dB", 2 },
2405 { "30dB", 3 },
2406 { "40dB", 4 },
2407 },
2408};
2409
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002410static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002411{
2412 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002413 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002414 AC_VERB_SET_AMP_GAIN_MUTE,
2415 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2416 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002417 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002418 /* adjust the internal mic as well...it is not through 0x17 */
2419 snd_hda_codec_write_cache(codec, 0x23, 0,
2420 AC_VERB_SET_AMP_GAIN_MUTE,
2421 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2422 cxt5066_analog_mic_boost.
2423 items[spec->mic_boost].index);
2424 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002425}
2426
Daniel Drake0fb67e92009-07-16 14:46:57 +01002427static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2428 struct snd_ctl_elem_info *uinfo)
2429{
2430 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2431}
2432
2433static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2434 struct snd_ctl_elem_value *ucontrol)
2435{
2436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002437 struct conexant_spec *spec = codec->spec;
2438 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002439 return 0;
2440}
2441
2442static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2443 struct snd_ctl_elem_value *ucontrol)
2444{
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002446 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002447 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2448 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002449 idx = ucontrol->value.enumerated.item[0];
2450 if (idx >= imux->num_items)
2451 idx = imux->num_items - 1;
2452
Daniel Drakec4cfe662010-01-07 13:47:04 +01002453 spec->mic_boost = idx;
2454 if (!spec->dc_enable)
2455 cxt5066_set_mic_boost(codec);
2456 return 1;
2457}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002458
Daniel Drakec4cfe662010-01-07 13:47:04 +01002459static void cxt5066_enable_dc(struct hda_codec *codec)
2460{
2461 const struct hda_verb enable_dc_mode[] = {
2462 /* disable gain */
2463 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2464
2465 /* switch to DC input */
2466 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2467 {}
2468 };
2469
2470 /* configure as input source */
2471 snd_hda_sequence_write(codec, enable_dc_mode);
2472 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2473}
2474
2475static void cxt5066_disable_dc(struct hda_codec *codec)
2476{
2477 /* reconfigure input source */
2478 cxt5066_set_mic_boost(codec);
2479 /* automic also selects the right mic if we're recording */
2480 cxt5066_olpc_automic(codec);
2481}
2482
2483static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2484 struct snd_ctl_elem_value *ucontrol)
2485{
2486 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2487 struct conexant_spec *spec = codec->spec;
2488 ucontrol->value.integer.value[0] = spec->dc_enable;
2489 return 0;
2490}
2491
2492static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2493 struct snd_ctl_elem_value *ucontrol)
2494{
2495 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2496 struct conexant_spec *spec = codec->spec;
2497 int dc_enable = !!ucontrol->value.integer.value[0];
2498
2499 if (dc_enable == spec->dc_enable)
2500 return 0;
2501
2502 spec->dc_enable = dc_enable;
2503 if (dc_enable)
2504 cxt5066_enable_dc(codec);
2505 else
2506 cxt5066_disable_dc(codec);
2507
2508 return 1;
2509}
2510
2511static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2512 struct snd_ctl_elem_info *uinfo)
2513{
2514 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2515}
2516
2517static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2518 struct snd_ctl_elem_value *ucontrol)
2519{
2520 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2521 struct conexant_spec *spec = codec->spec;
2522 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2523 return 0;
2524}
2525
2526static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2527 struct snd_ctl_elem_value *ucontrol)
2528{
2529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2530 struct conexant_spec *spec = codec->spec;
2531 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2532 unsigned int idx;
2533
2534 idx = ucontrol->value.enumerated.item[0];
2535 if (idx >= imux->num_items)
2536 idx = imux->num_items - 1;
2537
2538 spec->dc_input_bias = idx;
2539 if (spec->dc_enable)
2540 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002541 return 1;
2542}
2543
Daniel Drake75f89912010-01-07 13:46:25 +01002544static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2545{
2546 struct conexant_spec *spec = codec->spec;
2547 /* mark as recording and configure the microphone widget so that the
2548 * recording LED comes on. */
2549 spec->recording = 1;
2550 cxt5066_olpc_select_mic(codec);
2551}
2552
2553static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2554{
2555 struct conexant_spec *spec = codec->spec;
2556 const struct hda_verb disable_mics[] = {
2557 /* disable external mic, port B */
2558 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2559
2560 /* disble internal mic, port C */
2561 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002562
2563 /* disable DC capture, port F */
2564 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002565 {},
2566 };
2567
2568 snd_hda_sequence_write(codec, disable_mics);
2569 spec->recording = 0;
2570}
2571
Andy Robinsonf6a24912011-01-24 10:12:37 -05002572static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002573 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002574 int num_pins)
2575{
2576 struct conexant_spec *spec = codec->spec;
2577 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2578 int i;
2579
2580 for (i = 0; i < num_pins; i++, dig_pins++) {
2581 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2582 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2583 continue;
2584 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2585 continue;
2586 if (spec->slave_dig_outs[0])
2587 nid_loc++;
2588 else
2589 nid_loc = spec->slave_dig_outs;
2590 }
2591}
2592
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002593static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002594 .num_items = 4,
2595 .items = {
2596 { "Mic B", 0 },
2597 { "Mic C", 1 },
2598 { "Mic E", 2 },
2599 { "Mic F", 3 },
2600 },
2601};
2602
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002603static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002604 .ops = &snd_hda_bind_vol,
2605 .values = {
2606 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2607 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2608 0
2609 },
2610};
2611
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002612static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002613 .ops = &snd_hda_bind_sw,
2614 .values = {
2615 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2616 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2617 0
2618 },
2619};
2620
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002621static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002622 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2623 {}
2624};
2625
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002626static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002627 {
2628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2629 .name = "Master Playback Volume",
2630 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2631 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2632 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002633 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002634 .info = snd_hda_mixer_amp_volume_info,
2635 .get = snd_hda_mixer_amp_volume_get,
2636 .put = snd_hda_mixer_amp_volume_put,
2637 .tlv = { .c = snd_hda_mixer_amp_tlv },
2638 /* offset by 28 volume steps to limit minimum gain to -46dB */
2639 .private_value =
2640 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2641 },
2642 {}
2643};
2644
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002645static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002646 {
2647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2648 .name = "DC Mode Enable Switch",
2649 .info = snd_ctl_boolean_mono_info,
2650 .get = cxt5066_olpc_dc_get,
2651 .put = cxt5066_olpc_dc_put,
2652 },
2653 {
2654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2655 .name = "DC Input Bias Enum",
2656 .info = cxt5066_olpc_dc_bias_enum_info,
2657 .get = cxt5066_olpc_dc_bias_enum_get,
2658 .put = cxt5066_olpc_dc_bias_enum_put,
2659 },
2660 {}
2661};
2662
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002663static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002664 {
2665 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2666 .name = "Master Playback Switch",
2667 .info = cxt_eapd_info,
2668 .get = cxt_eapd_get,
2669 .put = cxt5066_hp_master_sw_put,
2670 .private_value = 0x1d,
2671 },
2672
2673 {
2674 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002675 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002676 .info = cxt5066_mic_boost_mux_enum_info,
2677 .get = cxt5066_mic_boost_mux_enum_get,
2678 .put = cxt5066_mic_boost_mux_enum_put,
2679 },
2680
2681 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2682 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2683 {}
2684};
2685
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002686static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002687 {
2688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002689 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002690 .info = cxt5066_mic_boost_mux_enum_info,
2691 .get = cxt5066_mic_boost_mux_enum_get,
2692 .put = cxt5066_mic_boost_mux_enum_put,
2693 .private_value = 0x23 | 0x100,
2694 },
2695 {}
2696};
2697
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002698static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002699 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2700 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2701 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2702 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2703
2704 /* Speakers */
2705 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2706 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2707
2708 /* HP, Amp */
2709 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2710 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2711
2712 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2713 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2714
2715 /* DAC1 */
2716 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2717
2718 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2722 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2723 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2724
2725 /* no digital microphone support yet */
2726 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727
2728 /* Audio input selector */
2729 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2730
2731 /* SPDIF route: PCM */
2732 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2733 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2734
2735 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2736 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2737
2738 /* EAPD */
2739 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2740
2741 /* not handling these yet */
2742 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2744 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2745 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2746 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2747 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2748 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2749 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2750 { } /* end */
2751};
2752
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002753static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002754 /* Port A: headphones */
2755 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2756 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2757
2758 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002759 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002760
2761 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002762 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002763
2764 /* Port D: unused */
2765 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2766
2767 /* Port E: unused, but has primary EAPD */
2768 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2769 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2770
Daniel Drakec4cfe662010-01-07 13:47:04 +01002771 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002772 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2773
2774 /* Port G: internal speakers */
2775 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2776 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2777
2778 /* DAC1 */
2779 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2780
2781 /* DAC2: unused */
2782 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2783
2784 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2785 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2787 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2788 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2789 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2790 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2791 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2792 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2793 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2794 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2795 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2796
2797 /* Disable digital microphone port */
2798 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2799
2800 /* Audio input selectors */
2801 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2802 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2803
2804 /* Disable SPDIF */
2805 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2806 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2807
2808 /* enable unsolicited events for Port A and B */
2809 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2810 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2811 { } /* end */
2812};
2813
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002814static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002815 /* Port A: headphones */
2816 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2817 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2818
2819 /* Port B: external microphone */
2820 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821
2822 /* Port C: unused */
2823 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824
2825 /* Port D: unused */
2826 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2827
2828 /* Port E: unused, but has primary EAPD */
2829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2830 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2831
2832 /* Port F: unused */
2833 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2834
2835 /* Port G: internal speakers */
2836 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2837 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2838
2839 /* DAC1 */
2840 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2841
2842 /* DAC2: unused */
2843 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2844
2845 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2847 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2848 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2849 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2851 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2853 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2854 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2855 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2856 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2857
2858 /* Digital microphone port */
2859 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2860
2861 /* Audio input selectors */
2862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2863 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2864
2865 /* Disable SPDIF */
2866 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2867 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2868
2869 /* enable unsolicited events for Port A and B */
2870 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2871 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2872 { } /* end */
2873};
2874
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002875static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002876 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2877 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2878 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2879 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2880
2881 /* Speakers */
2882 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2883 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2884
2885 /* HP, Amp */
2886 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2887 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2888
2889 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2890 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2891
2892 /* DAC1 */
2893 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2894
2895 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2897 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2898 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2899 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2900 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2901 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2902
2903 /* Audio input selector */
2904 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2905 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2906
2907 /* SPDIF route: PCM */
2908 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2909 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2910
2911 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2912 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2913
2914 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002915 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002916
2917 /* EAPD */
2918 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2919
2920 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2921 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2922 { } /* end */
2923};
2924
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002925static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002926 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2927 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2928
2929 /* Port G: internal speakers */
2930 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2931 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2932
2933 /* Port A: HP, Amp */
2934 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2935 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2936
2937 /* Port B: Mic Dock */
2938 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2939
2940 /* Port C: Mic */
2941 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2942
2943 /* Port D: HP Dock, Amp */
2944 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2945 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2946
2947 /* DAC1 */
2948 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2949
2950 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2951 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2952 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2953 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2954 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2955 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2956 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2957
2958 /* Audio input selector */
2959 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2960 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2961
2962 /* SPDIF route: PCM */
2963 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2964 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2965
2966 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2967 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2968
2969 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002970 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002971
2972 /* EAPD */
2973 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2974
2975 /* enable unsolicited events for Port A, B, C and D */
2976 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2977 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2978 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2979 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2980 { } /* end */
2981};
2982
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002983static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002984 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2985 { } /* end */
2986};
2987
David Henningsson048e78a2010-09-02 08:35:47 +02002988
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002989static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002990 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2991 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2992 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2993 { } /* end */
2994};
2995
Daniel Drake0fb67e92009-07-16 14:46:57 +01002996/* initialize jack-sensing, too */
2997static int cxt5066_init(struct hda_codec *codec)
2998{
2999 snd_printdd("CXT5066: init\n");
3000 conexant_init(codec);
3001 if (codec->patch_ops.unsol_event) {
3002 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003003 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003004 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003005 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003006 return 0;
3007}
3008
Daniel Drake75f89912010-01-07 13:46:25 +01003009static int cxt5066_olpc_init(struct hda_codec *codec)
3010{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003011 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003012 snd_printdd("CXT5066: init\n");
3013 conexant_init(codec);
3014 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003015 if (!spec->dc_enable) {
3016 cxt5066_set_mic_boost(codec);
3017 cxt5066_olpc_automic(codec);
3018 } else {
3019 cxt5066_enable_dc(codec);
3020 }
Daniel Drake75f89912010-01-07 13:46:25 +01003021 return 0;
3022}
3023
Daniel Drake0fb67e92009-07-16 14:46:57 +01003024enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003025 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003026 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3027 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003028 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003029 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003030 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003031 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003032 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003033 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003034 CXT5066_MODELS
3035};
3036
Takashi Iwaiea734962011-01-17 11:29:34 +01003037static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003038 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003039 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3040 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003041 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003042 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003043 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003044 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003045 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003046 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003047};
3048
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003049static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02003050 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003051 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003052 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003053 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003054 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003055 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003056 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003057 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3058 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003059 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003060 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003061 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003062 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003063 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003064 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003065 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003066 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3067 CXT5066_LAPTOP),
3068 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003069 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003070 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003071 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003072 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
Daniel Suchyca201c02011-10-18 11:09:44 +02003073 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02003074 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003075 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003076 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003077 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003078 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
David Henningsson22f21d52011-01-07 07:53:39 +01003079 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003080 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003081 {}
3082};
3083
3084static int patch_cxt5066(struct hda_codec *codec)
3085{
3086 struct conexant_spec *spec;
3087 int board_config;
3088
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003089 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3090 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003091 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003092 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003093 if (board_config == CXT5066_AUTO)
3094 return patch_conexant_auto(codec);
3095
Daniel Drake0fb67e92009-07-16 14:46:57 +01003096 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3097 if (!spec)
3098 return -ENOMEM;
3099 codec->spec = spec;
3100
3101 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003102 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003103
3104 spec->dell_automute = 0;
3105 spec->multiout.max_channels = 2;
3106 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3107 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003108 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3109 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003110 spec->num_adc_nids = 1;
3111 spec->adc_nids = cxt5066_adc_nids;
3112 spec->capsrc_nids = cxt5066_capsrc_nids;
3113 spec->input_mux = &cxt5066_capture_source;
3114
3115 spec->port_d_mode = PIN_HP;
3116
3117 spec->num_init_verbs = 1;
3118 spec->init_verbs[0] = cxt5066_init_verbs;
3119 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3120 spec->channel_mode = cxt5066_modes;
3121 spec->cur_adc = 0;
3122 spec->cur_adc_idx = 0;
3123
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003124 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3125
Daniel Drake0fb67e92009-07-16 14:46:57 +01003126 switch (board_config) {
3127 default:
3128 case CXT5066_LAPTOP:
3129 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3130 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3131 break;
3132 case CXT5066_DELL_LAPTOP:
3133 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3134 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3135
3136 spec->port_d_mode = PIN_OUT;
3137 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3138 spec->num_init_verbs++;
3139 spec->dell_automute = 1;
3140 break;
David Henningssona1d69062011-01-21 13:33:28 +01003141 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003142 case CXT5066_HP_LAPTOP:
3143 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003144 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003145 spec->init_verbs[spec->num_init_verbs] =
3146 cxt5066_init_verbs_hp_laptop;
3147 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003148 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3149 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003150 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3152 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003153 if (board_config == CXT5066_HP_LAPTOP)
3154 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003155 /* input source automatically selected */
3156 spec->input_mux = NULL;
3157 spec->port_d_mode = 0;
3158 spec->mic_boost = 3; /* default 30dB gain */
3159 break;
3160
Daniel Drake0fb67e92009-07-16 14:46:57 +01003161 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003162 codec->patch_ops.init = cxt5066_olpc_init;
3163 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003164 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3165 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003166 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003167 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3168 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003169 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003170
3171 /* no S/PDIF out */
3172 spec->multiout.dig_out_nid = 0;
3173
3174 /* input source automatically selected */
3175 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003176
3177 /* our capture hooks which allow us to turn on the microphone LED
3178 * at the right time */
3179 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3180 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003181 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003182 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003183 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003184 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003185 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3186 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3187 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003188 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003189 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003190 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003191 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003192
3193 /* no S/PDIF out */
3194 spec->multiout.dig_out_nid = 0;
3195
3196 /* input source automatically selected */
3197 spec->input_mux = NULL;
3198 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003199 case CXT5066_IDEAPAD:
3200 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003201 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003202 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3203 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3204 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3205 spec->port_d_mode = 0;
3206 spec->ideapad = 1;
3207 spec->mic_boost = 2; /* default 20dB gain */
3208
3209 /* no S/PDIF out */
3210 spec->multiout.dig_out_nid = 0;
3211
3212 /* input source automatically selected */
3213 spec->input_mux = NULL;
3214 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003215 case CXT5066_THINKPAD:
3216 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003217 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003218 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3219 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3220 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3221 spec->thinkpad = 1;
3222 spec->port_d_mode = PIN_OUT;
3223 spec->mic_boost = 2; /* default 20dB gain */
3224
3225 /* no S/PDIF out */
3226 spec->multiout.dig_out_nid = 0;
3227
3228 /* input source automatically selected */
3229 spec->input_mux = NULL;
3230 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003231 }
3232
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003233 if (spec->beep_amp)
3234 snd_hda_attach_beep_device(codec, spec->beep_amp);
3235
Daniel Drake0fb67e92009-07-16 14:46:57 +01003236 return 0;
3237}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003238
3239/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003240 * Automatic parser for CX20641 & co
3241 */
3242
Takashi Iwai6764bce2011-05-13 16:52:25 +02003243static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3244 struct hda_codec *codec,
3245 unsigned int stream_tag,
3246 unsigned int format,
3247 struct snd_pcm_substream *substream)
3248{
3249 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003250 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003251 if (spec->adc_switching) {
3252 spec->cur_adc = adc;
3253 spec->cur_adc_stream_tag = stream_tag;
3254 spec->cur_adc_format = format;
3255 }
3256 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3257 return 0;
3258}
3259
3260static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3261 struct hda_codec *codec,
3262 struct snd_pcm_substream *substream)
3263{
3264 struct conexant_spec *spec = codec->spec;
3265 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3266 spec->cur_adc = 0;
3267 return 0;
3268}
3269
3270static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3271 .substreams = 1,
3272 .channels_min = 2,
3273 .channels_max = 2,
3274 .nid = 0, /* fill later */
3275 .ops = {
3276 .prepare = cx_auto_capture_pcm_prepare,
3277 .cleanup = cx_auto_capture_pcm_cleanup
3278 },
3279};
3280
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003281static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003282
Takashi Iwai8d087c72011-06-28 12:45:47 +02003283#define get_connection_index(codec, mux, nid)\
3284 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003285
3286/* get an unassigned DAC from the given list.
3287 * Return the nid if found and reduce the DAC list, or return zero if
3288 * not found
3289 */
3290static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3291 hda_nid_t *dacs, int *num_dacs)
3292{
3293 int i, nums = *num_dacs;
3294 hda_nid_t ret = 0;
3295
3296 for (i = 0; i < nums; i++) {
3297 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3298 ret = dacs[i];
3299 break;
3300 }
3301 }
3302 if (!ret)
3303 return 0;
3304 if (--nums > 0)
3305 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3306 *num_dacs = nums;
3307 return ret;
3308}
3309
3310#define MAX_AUTO_DACS 5
3311
Takashi Iwai1f015f52011-08-23 14:57:08 +02003312#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3313
Takashi Iwaif2e57312010-09-15 10:07:08 +02003314/* fill analog DAC list from the widget tree */
3315static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3316{
3317 hda_nid_t nid, end_nid;
3318 int nums = 0;
3319
3320 end_nid = codec->start_nid + codec->num_nodes;
3321 for (nid = codec->start_nid; nid < end_nid; nid++) {
3322 unsigned int wcaps = get_wcaps(codec, nid);
3323 unsigned int type = get_wcaps_type(wcaps);
3324 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3325 dacs[nums++] = nid;
3326 if (nums >= MAX_AUTO_DACS)
3327 break;
3328 }
3329 }
3330 return nums;
3331}
3332
3333/* fill pin_dac_pair list from the pin and dac list */
3334static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3335 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003336 struct pin_dac_pair *filled, int nums,
3337 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003338{
David Henningsson468c5452011-08-25 13:16:02 +02003339 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003340
David Henningsson468c5452011-08-25 13:16:02 +02003341 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003342 filled[nums].pin = pins[i];
3343 filled[nums].type = type;
3344 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003345 if (filled[nums].dac)
3346 continue;
3347 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3348 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3349 continue;
3350 }
3351 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003352 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003353 continue;
3354 }
3355 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003356 }
3357 return nums;
3358}
3359
3360/* parse analog output paths */
3361static void cx_auto_parse_output(struct hda_codec *codec)
3362{
3363 struct conexant_spec *spec = codec->spec;
3364 struct auto_pin_cfg *cfg = &spec->autocfg;
3365 hda_nid_t dacs[MAX_AUTO_DACS];
3366 int i, j, nums, rest;
3367
3368 rest = fill_cx_auto_dacs(codec, dacs);
3369 /* parse all analog output pins */
3370 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003371 dacs, &rest, spec->dac_info, 0,
3372 AUTO_PIN_LINE_OUT);
3373 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3374 dacs, &rest, spec->dac_info, nums,
3375 AUTO_PIN_HP_OUT);
3376 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3377 dacs, &rest, spec->dac_info, nums,
3378 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003379 spec->dac_info_filled = nums;
3380 /* fill multiout struct */
3381 for (i = 0; i < nums; i++) {
3382 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003383 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003384 continue;
3385 switch (spec->dac_info[i].type) {
3386 case AUTO_PIN_LINE_OUT:
3387 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3388 spec->multiout.num_dacs++;
3389 break;
3390 case AUTO_PIN_HP_OUT:
3391 case AUTO_PIN_SPEAKER_OUT:
3392 if (!spec->multiout.hp_nid) {
3393 spec->multiout.hp_nid = dac;
3394 break;
3395 }
3396 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3397 if (!spec->multiout.extra_out_nid[j]) {
3398 spec->multiout.extra_out_nid[j] = dac;
3399 break;
3400 }
3401 break;
3402 }
3403 }
3404 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003405 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003406
Takashi Iwai03697e22011-05-17 09:53:31 +02003407 for (i = 0; i < cfg->hp_outs; i++) {
3408 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3409 spec->auto_mute = 1;
3410 break;
3411 }
3412 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003413 if (spec->auto_mute &&
3414 cfg->line_out_pins[0] &&
3415 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003416 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3417 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3418 for (i = 0; i < cfg->line_outs; i++) {
3419 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3420 spec->detect_line = 1;
3421 break;
3422 }
3423 }
3424 spec->automute_lines = spec->detect_line;
3425 }
3426
Takashi Iwaif2e57312010-09-15 10:07:08 +02003427 spec->vmaster_nid = spec->private_dac_nids[0];
3428}
3429
Takashi Iwaida339862011-05-13 16:24:15 +02003430static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3431 hda_nid_t *pins, bool on);
3432
Takashi Iwai03697e22011-05-17 09:53:31 +02003433static void do_automute(struct hda_codec *codec, int num_pins,
3434 hda_nid_t *pins, bool on)
3435{
Takashi Iwai254f2962011-10-14 15:22:34 +02003436 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003437 int i;
3438 for (i = 0; i < num_pins; i++)
3439 snd_hda_codec_write(codec, pins[i], 0,
3440 AC_VERB_SET_PIN_WIDGET_CONTROL,
3441 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003442 if (spec->pin_eapd_ctrls)
3443 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003444}
3445
3446static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3447{
3448 int i, present = 0;
3449
3450 for (i = 0; i < num_pins; i++) {
3451 hda_nid_t nid = pins[i];
3452 if (!nid || !is_jack_detectable(codec, nid))
3453 break;
3454 snd_hda_input_jack_report(codec, nid);
3455 present |= snd_hda_jack_detect(codec, nid);
3456 }
3457 return present;
3458}
3459
Takashi Iwaif2e57312010-09-15 10:07:08 +02003460/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003461static void cx_auto_update_speakers(struct hda_codec *codec)
3462{
3463 struct conexant_spec *spec = codec->spec;
3464 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003465 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003466
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003467 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003468 if (spec->pin_eapd_ctrls) {
3469 if (spec->auto_mute)
3470 on = spec->hp_present;
3471 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3472 }
3473
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003474 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3475 if (spec->auto_mute)
3476 on = !(spec->hp_present ||
3477 (spec->detect_line && spec->line_present));
3478 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003479
3480 /* toggle line-out mutes if needed, too */
3481 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3482 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3483 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3484 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003485 if (spec->auto_mute) {
3486 /* mute LO in auto-mode when HP jack is present */
3487 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3488 spec->automute_lines)
3489 on = !spec->hp_present;
3490 else
3491 on = 1;
3492 }
3493 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003494}
3495
Takashi Iwaif2e57312010-09-15 10:07:08 +02003496static void cx_auto_hp_automute(struct hda_codec *codec)
3497{
3498 struct conexant_spec *spec = codec->spec;
3499 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003500
3501 if (!spec->auto_mute)
3502 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003503 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3504 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003505}
3506
Takashi Iwai03697e22011-05-17 09:53:31 +02003507static void cx_auto_line_automute(struct hda_codec *codec)
3508{
3509 struct conexant_spec *spec = codec->spec;
3510 struct auto_pin_cfg *cfg = &spec->autocfg;
3511
3512 if (!spec->auto_mute || !spec->detect_line)
3513 return;
3514 spec->line_present = detect_jacks(codec, cfg->line_outs,
3515 cfg->line_out_pins);
3516 cx_auto_update_speakers(codec);
3517}
3518
3519static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3520 struct snd_ctl_elem_info *uinfo)
3521{
3522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3523 struct conexant_spec *spec = codec->spec;
3524 static const char * const texts2[] = {
3525 "Disabled", "Enabled"
3526 };
3527 static const char * const texts3[] = {
3528 "Disabled", "Speaker Only", "Line-Out+Speaker"
3529 };
3530 const char * const *texts;
3531
3532 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3533 uinfo->count = 1;
3534 if (spec->automute_hp_lo) {
3535 uinfo->value.enumerated.items = 3;
3536 texts = texts3;
3537 } else {
3538 uinfo->value.enumerated.items = 2;
3539 texts = texts2;
3540 }
3541 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3542 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3543 strcpy(uinfo->value.enumerated.name,
3544 texts[uinfo->value.enumerated.item]);
3545 return 0;
3546}
3547
3548static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3549 struct snd_ctl_elem_value *ucontrol)
3550{
3551 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3552 struct conexant_spec *spec = codec->spec;
3553 unsigned int val;
3554 if (!spec->auto_mute)
3555 val = 0;
3556 else if (!spec->automute_lines)
3557 val = 1;
3558 else
3559 val = 2;
3560 ucontrol->value.enumerated.item[0] = val;
3561 return 0;
3562}
3563
3564static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3565 struct snd_ctl_elem_value *ucontrol)
3566{
3567 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3568 struct conexant_spec *spec = codec->spec;
3569
3570 switch (ucontrol->value.enumerated.item[0]) {
3571 case 0:
3572 if (!spec->auto_mute)
3573 return 0;
3574 spec->auto_mute = 0;
3575 break;
3576 case 1:
3577 if (spec->auto_mute && !spec->automute_lines)
3578 return 0;
3579 spec->auto_mute = 1;
3580 spec->automute_lines = 0;
3581 break;
3582 case 2:
3583 if (!spec->automute_hp_lo)
3584 return -EINVAL;
3585 if (spec->auto_mute && spec->automute_lines)
3586 return 0;
3587 spec->auto_mute = 1;
3588 spec->automute_lines = 1;
3589 break;
3590 default:
3591 return -EINVAL;
3592 }
3593 cx_auto_update_speakers(codec);
3594 return 1;
3595}
3596
3597static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3598 {
3599 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3600 .name = "Auto-Mute Mode",
3601 .info = cx_automute_mode_info,
3602 .get = cx_automute_mode_get,
3603 .put = cx_automute_mode_put,
3604 },
3605 { }
3606};
3607
Takashi Iwai6764bce2011-05-13 16:52:25 +02003608static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3609 struct snd_ctl_elem_info *uinfo)
3610{
3611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3612 struct conexant_spec *spec = codec->spec;
3613
3614 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3615}
3616
3617static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3618 struct snd_ctl_elem_value *ucontrol)
3619{
3620 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3621 struct conexant_spec *spec = codec->spec;
3622
3623 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3624 return 0;
3625}
3626
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003627/* look for the route the given pin from mux and return the index;
3628 * if do_select is set, actually select the route.
3629 */
3630static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003631 hda_nid_t pin, hda_nid_t *srcp,
3632 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003633{
3634 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3635 int i, nums;
3636
Takashi Iwaicf27f292011-05-16 11:33:02 +02003637 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3638 case AC_WID_AUD_IN:
3639 case AC_WID_AUD_SEL:
3640 case AC_WID_AUD_MIX:
3641 break;
3642 default:
3643 return -1;
3644 }
3645
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003646 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3647 for (i = 0; i < nums; i++)
3648 if (conn[i] == pin) {
3649 if (do_select)
3650 snd_hda_codec_write(codec, mux, 0,
3651 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003652 if (srcp)
3653 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003654 return i;
3655 }
3656 depth++;
3657 if (depth == 2)
3658 return -1;
3659 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003660 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003661 do_select, depth);
3662 if (ret >= 0) {
3663 if (do_select)
3664 snd_hda_codec_write(codec, mux, 0,
3665 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003666 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003667 }
3668 }
3669 return -1;
3670}
3671
3672static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3673 hda_nid_t pin)
3674{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003675 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003676}
3677
3678static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3679 hda_nid_t pin)
3680{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003681 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003682}
3683
Takashi Iwai6764bce2011-05-13 16:52:25 +02003684static int cx_auto_mux_enum_update(struct hda_codec *codec,
3685 const struct hda_input_mux *imux,
3686 unsigned int idx)
3687{
3688 struct conexant_spec *spec = codec->spec;
3689 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003690 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003691
3692 if (!imux->num_items)
3693 return 0;
3694 if (idx >= imux->num_items)
3695 idx = imux->num_items - 1;
3696 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003697 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003698 adc = spec->imux_info[idx].adc;
3699 select_input_connection(codec, spec->imux_info[idx].adc,
3700 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003701 if (spec->cur_adc && spec->cur_adc != adc) {
3702 /* stream is running, let's swap the current ADC */
3703 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3704 spec->cur_adc = adc;
3705 snd_hda_codec_setup_stream(codec, adc,
3706 spec->cur_adc_stream_tag, 0,
3707 spec->cur_adc_format);
3708 }
3709 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003710 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003711}
3712
3713static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3714 struct snd_ctl_elem_value *ucontrol)
3715{
3716 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3717 struct conexant_spec *spec = codec->spec;
3718
3719 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3720 ucontrol->value.enumerated.item[0]);
3721}
3722
3723static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3724 {
3725 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3726 .name = "Capture Source",
3727 .info = cx_auto_mux_enum_info,
3728 .get = cx_auto_mux_enum_get,
3729 .put = cx_auto_mux_enum_put
3730 },
3731 {}
3732};
3733
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003734static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3735{
3736 struct conexant_spec *spec = codec->spec;
3737 if (idx < 0)
3738 return false;
3739 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3740 return false;
3741 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3742 return true;
3743}
3744
Takashi Iwaif2e57312010-09-15 10:07:08 +02003745/* automatic switch internal and external mic */
3746static void cx_auto_automic(struct hda_codec *codec)
3747{
3748 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003749
3750 if (!spec->auto_mic)
3751 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003752 if (!select_automic(codec, spec->auto_mic_ext, true))
3753 if (!select_automic(codec, spec->auto_mic_dock, true))
3754 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003755}
3756
3757static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3758{
3759 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3760 switch (res >> 26) {
3761 case CONEXANT_HP_EVENT:
3762 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003763 break;
3764 case CONEXANT_LINE_EVENT:
3765 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003766 break;
3767 case CONEXANT_MIC_EVENT:
3768 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003769 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003770 break;
3771 }
3772}
3773
Takashi Iwaif2e57312010-09-15 10:07:08 +02003774/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003775 * auto-mic is enabled only when one int-mic and one ext- and/or
3776 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003777 */
3778static void cx_auto_check_auto_mic(struct hda_codec *codec)
3779{
3780 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003781 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3782 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003783
Takashi Iwai506a4192011-05-23 20:07:15 +02003784 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003785 pset[i] = -1;
3786 for (i = 0; i < spec->private_imux.num_items; i++) {
3787 hda_nid_t pin = spec->imux_info[i].pin;
3788 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003789 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003790 attr = snd_hda_get_input_pin_attr(def_conf);
3791 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003792 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003793 if (attr > INPUT_PIN_ATTR_NORMAL)
3794 attr = INPUT_PIN_ATTR_NORMAL;
3795 if (attr != INPUT_PIN_ATTR_INT &&
3796 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003797 return; /* non-detectable pin */
3798 type = get_defcfg_device(def_conf);
3799 if (type != AC_JACK_MIC_IN &&
3800 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3801 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003802 if (pset[attr] >= 0)
3803 return; /* already occupied */
3804 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003805 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003806 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3807 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3808 return; /* no input to switch*/
3809 spec->auto_mic = 1;
3810 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3811 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3812 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003813}
3814
3815static void cx_auto_parse_input(struct hda_codec *codec)
3816{
3817 struct conexant_spec *spec = codec->spec;
3818 struct auto_pin_cfg *cfg = &spec->autocfg;
3819 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003820 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003821
3822 imux = &spec->private_imux;
3823 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003824 for (j = 0; j < spec->num_adc_nids; j++) {
3825 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003826 int idx = get_input_connection(codec, adc,
3827 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003828 if (idx >= 0) {
3829 const char *label;
3830 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003831 spec->imux_info[imux->num_items].index = i;
3832 spec->imux_info[imux->num_items].boost = 0;
3833 spec->imux_info[imux->num_items].adc = adc;
3834 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003835 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003836 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003837 break;
3838 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003839 }
3840 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003841 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003842 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003843 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003844 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003845 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003846 spec->adc_switching = 1;
3847 break;
3848 }
3849 }
3850 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003851}
3852
3853/* get digital-input audio widget corresponding to the given pin */
3854static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3855{
3856 hda_nid_t nid, end_nid;
3857
3858 end_nid = codec->start_nid + codec->num_nodes;
3859 for (nid = codec->start_nid; nid < end_nid; nid++) {
3860 unsigned int wcaps = get_wcaps(codec, nid);
3861 unsigned int type = get_wcaps_type(wcaps);
3862 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3863 if (get_connection_index(codec, nid, pin) >= 0)
3864 return nid;
3865 }
3866 }
3867 return 0;
3868}
3869
3870static void cx_auto_parse_digital(struct hda_codec *codec)
3871{
3872 struct conexant_spec *spec = codec->spec;
3873 struct auto_pin_cfg *cfg = &spec->autocfg;
3874 hda_nid_t nid;
3875
3876 if (cfg->dig_outs &&
3877 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3878 spec->multiout.dig_out_nid = nid;
3879 if (cfg->dig_in_pin)
3880 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3881}
3882
3883#ifdef CONFIG_SND_HDA_INPUT_BEEP
3884static void cx_auto_parse_beep(struct hda_codec *codec)
3885{
3886 struct conexant_spec *spec = codec->spec;
3887 hda_nid_t nid, end_nid;
3888
3889 end_nid = codec->start_nid + codec->num_nodes;
3890 for (nid = codec->start_nid; nid < end_nid; nid++)
3891 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3892 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3893 break;
3894 }
3895}
3896#else
3897#define cx_auto_parse_beep(codec)
3898#endif
3899
Takashi Iwai254f2962011-10-14 15:22:34 +02003900/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003901static void cx_auto_parse_eapd(struct hda_codec *codec)
3902{
3903 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003904 hda_nid_t nid, end_nid;
3905
3906 end_nid = codec->start_nid + codec->num_nodes;
3907 for (nid = codec->start_nid; nid < end_nid; nid++) {
3908 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3909 continue;
3910 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3911 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003912 spec->eapds[spec->num_eapds++] = nid;
3913 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3914 break;
3915 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003916
3917 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3918 * it's a new chip, where EAPDs are supposed to be associated to
3919 * pins, and we can control EAPD per pin.
3920 * OTOH, if only one or two EAPDs are found, it's an old chip,
3921 * thus it might control over all pins.
3922 */
3923 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003924}
3925
Takashi Iwaif2e57312010-09-15 10:07:08 +02003926static int cx_auto_parse_auto_config(struct hda_codec *codec)
3927{
3928 struct conexant_spec *spec = codec->spec;
3929 int err;
3930
3931 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3932 if (err < 0)
3933 return err;
3934
3935 cx_auto_parse_output(codec);
3936 cx_auto_parse_input(codec);
3937 cx_auto_parse_digital(codec);
3938 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003939 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003940 return 0;
3941}
3942
Takashi Iwaida339862011-05-13 16:24:15 +02003943static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3944 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003945{
3946 int i;
3947 for (i = 0; i < num_pins; i++) {
3948 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3949 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003950 AC_VERB_SET_EAPD_BTLENABLE,
3951 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003952 }
3953}
3954
3955static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3956 hda_nid_t src)
3957{
3958 int idx = get_connection_index(codec, pin, src);
3959 if (idx >= 0)
3960 snd_hda_codec_write(codec, pin, 0,
3961 AC_VERB_SET_CONNECT_SEL, idx);
3962}
3963
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003964static void mute_outputs(struct hda_codec *codec, int num_nids,
3965 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003966{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003967 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003968
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003969 for (i = 0; i < num_nids; i++) {
3970 hda_nid_t nid = nids[i];
3971 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3972 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003973 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3974 val = AMP_OUT_MUTE;
3975 else
3976 val = AMP_OUT_ZERO;
3977 snd_hda_codec_write(codec, nid, 0,
3978 AC_VERB_SET_AMP_GAIN_MUTE, val);
3979 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003980}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003981
Takashi Iwai03697e22011-05-17 09:53:31 +02003982static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3983 hda_nid_t *pins, unsigned int tag)
3984{
3985 int i;
3986 for (i = 0; i < num_pins; i++)
3987 snd_hda_codec_write(codec, pins[i], 0,
3988 AC_VERB_SET_UNSOLICITED_ENABLE,
3989 AC_USRSP_EN | tag);
3990}
3991
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003992static void cx_auto_init_output(struct hda_codec *codec)
3993{
3994 struct conexant_spec *spec = codec->spec;
3995 struct auto_pin_cfg *cfg = &spec->autocfg;
3996 hda_nid_t nid;
3997 int i;
3998
3999 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004000 for (i = 0; i < cfg->hp_outs; i++)
4001 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
4002 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004003 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
4004 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
4005 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004006 for (i = 0; i < spec->dac_info_filled; i++) {
4007 nid = spec->dac_info[i].dac;
4008 if (!nid)
4009 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02004010 else if (nid & DAC_SLAVE_FLAG)
4011 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004012 select_connection(codec, spec->dac_info[i].pin, nid);
4013 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004014 if (spec->auto_mute) {
4015 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
4016 CONEXANT_HP_EVENT);
4017 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4018 cfg->hp_pins);
4019 if (spec->detect_line) {
4020 enable_unsol_pins(codec, cfg->line_outs,
4021 cfg->line_out_pins,
4022 CONEXANT_LINE_EVENT);
4023 spec->line_present =
4024 detect_jacks(codec, cfg->line_outs,
4025 cfg->line_out_pins);
4026 }
4027 }
4028 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02004029 /* turn on all EAPDs if no individual EAPD control is available */
4030 if (!spec->pin_eapd_ctrls)
4031 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004032}
4033
4034static void cx_auto_init_input(struct hda_codec *codec)
4035{
4036 struct conexant_spec *spec = codec->spec;
4037 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004038 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004039
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004040 for (i = 0; i < spec->num_adc_nids; i++) {
4041 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004042 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4043 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004044 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4045 val = AMP_IN_MUTE(0);
4046 else
4047 val = AMP_IN_UNMUTE(0);
4048 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4049 val);
4050 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004051
4052 for (i = 0; i < cfg->num_inputs; i++) {
4053 unsigned int type;
4054 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4055 type = PIN_VREF80;
4056 else
4057 type = PIN_IN;
4058 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4059 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4060 }
4061
4062 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004063 if (spec->auto_mic_ext >= 0) {
4064 snd_hda_codec_write(codec,
4065 cfg->inputs[spec->auto_mic_ext].pin, 0,
4066 AC_VERB_SET_UNSOLICITED_ENABLE,
4067 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4068 }
4069 if (spec->auto_mic_dock >= 0) {
4070 snd_hda_codec_write(codec,
4071 cfg->inputs[spec->auto_mic_dock].pin, 0,
4072 AC_VERB_SET_UNSOLICITED_ENABLE,
4073 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4074 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004075 cx_auto_automic(codec);
4076 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004077 select_input_connection(codec, spec->imux_info[0].adc,
4078 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004079 }
4080}
4081
4082static void cx_auto_init_digital(struct hda_codec *codec)
4083{
4084 struct conexant_spec *spec = codec->spec;
4085 struct auto_pin_cfg *cfg = &spec->autocfg;
4086
4087 if (spec->multiout.dig_out_nid)
4088 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4089 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4090 if (spec->dig_in_nid)
4091 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4092 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4093}
4094
4095static int cx_auto_init(struct hda_codec *codec)
4096{
4097 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4098 cx_auto_init_output(codec);
4099 cx_auto_init_input(codec);
4100 cx_auto_init_digital(codec);
4101 return 0;
4102}
4103
David Henningsson983345e2011-02-15 19:57:09 +01004104static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004105 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004106 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004107{
4108 static char name[32];
4109 static struct snd_kcontrol_new knew[] = {
4110 HDA_CODEC_VOLUME(name, 0, 0, 0),
4111 HDA_CODEC_MUTE(name, 0, 0, 0),
4112 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004113 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004114 int i, err;
4115
4116 for (i = 0; i < 2; i++) {
4117 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004118 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4119 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004120 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4121 knew[i].index = cidx;
4122 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4123 kctl = snd_ctl_new1(&knew[i], codec);
4124 if (!kctl)
4125 return -ENOMEM;
4126 err = snd_hda_ctl_add(codec, nid, kctl);
4127 if (err < 0)
4128 return err;
4129 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4130 break;
4131 }
4132 return 0;
4133}
4134
David Henningsson983345e2011-02-15 19:57:09 +01004135#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4136 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4137
Takashi Iwaif2e57312010-09-15 10:07:08 +02004138#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4139 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4140
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004141static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4142 hda_nid_t pin, const char *name, int idx)
4143{
4144 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004145 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4146 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4147 if (caps & AC_AMPCAP_NUM_STEPS)
4148 return cx_auto_add_pb_volume(codec, dac, name, idx);
4149 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004150 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4151 if (caps & AC_AMPCAP_NUM_STEPS)
4152 return cx_auto_add_pb_volume(codec, pin, name, idx);
4153 return 0;
4154}
4155
Takashi Iwaif2e57312010-09-15 10:07:08 +02004156static int cx_auto_build_output_controls(struct hda_codec *codec)
4157{
4158 struct conexant_spec *spec = codec->spec;
4159 int i, err;
4160 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004161 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004162
4163 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004164 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4165 spec->dac_info[0].pin,
4166 "Master", 0);
4167
Takashi Iwaif2e57312010-09-15 10:07:08 +02004168 for (i = 0; i < spec->dac_info_filled; i++) {
4169 const char *label;
4170 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004171 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004172 type = spec->dac_info[i].type;
4173 if (type == AUTO_PIN_LINE_OUT)
4174 type = spec->autocfg.line_out_type;
4175 switch (type) {
4176 case AUTO_PIN_LINE_OUT:
4177 default:
4178 label = texts[num_line++];
4179 idx = 0;
4180 break;
4181 case AUTO_PIN_HP_OUT:
4182 label = "Headphone";
4183 idx = num_hp++;
4184 break;
4185 case AUTO_PIN_SPEAKER_OUT:
4186 label = "Speaker";
4187 idx = num_spk++;
4188 break;
4189 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004190 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004191 spec->dac_info[i].pin,
4192 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004193 if (err < 0)
4194 return err;
4195 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004196
4197 if (spec->auto_mute) {
4198 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4199 if (err < 0)
4200 return err;
4201 }
4202
Takashi Iwaif2e57312010-09-15 10:07:08 +02004203 return 0;
4204}
4205
Takashi Iwai6764bce2011-05-13 16:52:25 +02004206static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4207 const char *label, const char *pfx,
4208 int cidx)
4209{
4210 struct conexant_spec *spec = codec->spec;
4211 int i;
4212
4213 for (i = 0; i < spec->num_adc_nids; i++) {
4214 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004215 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004216 if (idx < 0)
4217 continue;
Takashi Iwai6b452142011-10-14 15:26:20 +02004218 if (spec->single_adc_amp)
4219 idx = 0;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004220 return cx_auto_add_volume_idx(codec, label, pfx,
4221 cidx, adc_nid, HDA_INPUT, idx);
4222 }
4223 return 0;
4224}
4225
Takashi Iwaicf27f292011-05-16 11:33:02 +02004226static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4227 const char *label, int cidx)
4228{
4229 struct conexant_spec *spec = codec->spec;
4230 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004231 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004232
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004233 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004234 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4235 return cx_auto_add_volume(codec, label, " Boost", cidx,
4236 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004237 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4238 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004239 if (con < 0)
4240 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004241 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004242 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004243 return 0; /* already present */
4244 }
4245
4246 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004247 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004248 return cx_auto_add_volume(codec, label, " Boost", 0,
4249 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004250 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004251 return 0;
4252}
4253
Takashi Iwaif2e57312010-09-15 10:07:08 +02004254static int cx_auto_build_input_controls(struct hda_codec *codec)
4255{
4256 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004257 struct hda_input_mux *imux = &spec->private_imux;
4258 const char *prev_label;
4259 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004260 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004261 int multi_connection;
4262
Takashi Iwai6b452142011-10-14 15:26:20 +02004263 if (!imux->num_items)
4264 return 0;
4265
Takashi Iwaicf27f292011-05-16 11:33:02 +02004266 multi_connection = 0;
4267 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004268 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4269 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004270 if (cidx < 0)
4271 continue;
4272 input_conn[i] = spec->imux_info[i].adc;
4273 if (!spec->single_adc_amp)
4274 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004275 if (i > 0 && input_conn[i] != input_conn[0])
4276 multi_connection = 1;
4277 }
David Henningsson983345e2011-02-15 19:57:09 +01004278
Takashi Iwaif2e57312010-09-15 10:07:08 +02004279 prev_label = NULL;
4280 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004281 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004282 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004283 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004284
Takashi Iwaicf27f292011-05-16 11:33:02 +02004285 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004286 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004287 if (label == prev_label)
4288 cidx++;
4289 else
4290 cidx = 0;
4291 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004292
Takashi Iwaicf27f292011-05-16 11:33:02 +02004293 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4294 if (err < 0)
4295 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004296
Takashi Iwaicf27f292011-05-16 11:33:02 +02004297 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004298 if (i > 0)
4299 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004300 err = cx_auto_add_capture_volume(codec, nid,
4301 "Capture", "", cidx);
4302 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004303 bool dup_found = false;
4304 for (j = 0; j < i; j++) {
4305 if (input_conn[j] == input_conn[i]) {
4306 dup_found = true;
4307 break;
4308 }
4309 }
4310 if (dup_found)
4311 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004312 err = cx_auto_add_capture_volume(codec, nid,
4313 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004314 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004315 if (err < 0)
4316 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004317 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004318
4319 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4320 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4321 if (err < 0)
4322 return err;
4323 }
4324
Takashi Iwaif2e57312010-09-15 10:07:08 +02004325 return 0;
4326}
4327
4328static int cx_auto_build_controls(struct hda_codec *codec)
4329{
4330 int err;
4331
4332 err = cx_auto_build_output_controls(codec);
4333 if (err < 0)
4334 return err;
4335 err = cx_auto_build_input_controls(codec);
4336 if (err < 0)
4337 return err;
4338 return conexant_build_controls(codec);
4339}
4340
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004341static int cx_auto_search_adcs(struct hda_codec *codec)
4342{
4343 struct conexant_spec *spec = codec->spec;
4344 hda_nid_t nid, end_nid;
4345
4346 end_nid = codec->start_nid + codec->num_nodes;
4347 for (nid = codec->start_nid; nid < end_nid; nid++) {
4348 unsigned int caps = get_wcaps(codec, nid);
4349 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4350 continue;
4351 if (caps & AC_WCAP_DIGITAL)
4352 continue;
4353 if (snd_BUG_ON(spec->num_adc_nids >=
4354 ARRAY_SIZE(spec->private_adc_nids)))
4355 break;
4356 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4357 }
4358 spec->adc_nids = spec->private_adc_nids;
4359 return 0;
4360}
4361
4362
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004363static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004364 .build_controls = cx_auto_build_controls,
4365 .build_pcms = conexant_build_pcms,
4366 .init = cx_auto_init,
4367 .free = conexant_free,
4368 .unsol_event = cx_auto_unsol_event,
4369#ifdef CONFIG_SND_HDA_POWER_SAVE
4370 .suspend = conexant_suspend,
4371#endif
4372 .reboot_notify = snd_hda_shutup_pins,
4373};
4374
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004375/*
4376 * pin fix-up
4377 */
4378struct cxt_pincfg {
4379 hda_nid_t nid;
4380 u32 val;
4381};
4382
4383static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4384{
4385 for (; cfg->nid; cfg++)
4386 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4387
4388}
4389
4390static void apply_pin_fixup(struct hda_codec *codec,
4391 const struct snd_pci_quirk *quirk,
4392 const struct cxt_pincfg **table)
4393{
4394 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4395 if (quirk) {
4396 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4397 quirk->name);
4398 apply_pincfg(codec, table[quirk->value]);
4399 }
4400}
4401
4402enum {
4403 CXT_PINCFG_LENOVO_X200,
4404};
4405
4406static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4407 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4408 { 0x17, 0x21a11000 }, /* dock-mic */
4409 { 0x19, 0x2121103f }, /* dock-HP */
4410 {}
4411};
4412
4413static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4414 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4415};
4416
4417static const struct snd_pci_quirk cxt_fixups[] = {
4418 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4419 {}
4420};
4421
Takashi Iwaif2e57312010-09-15 10:07:08 +02004422static int patch_conexant_auto(struct hda_codec *codec)
4423{
4424 struct conexant_spec *spec;
4425 int err;
4426
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004427 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4428 codec->chip_name);
4429
Takashi Iwaif2e57312010-09-15 10:07:08 +02004430 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4431 if (!spec)
4432 return -ENOMEM;
4433 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004434 codec->pin_amp_workaround = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004435
Takashi Iwai6b452142011-10-14 15:26:20 +02004436 switch (codec->vendor_id) {
4437 case 0x14f15045:
4438 spec->single_adc_amp = 1;
4439 break;
4440 }
4441
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004442 apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
4443
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004444 err = cx_auto_search_adcs(codec);
4445 if (err < 0)
4446 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004447 err = cx_auto_parse_auto_config(codec);
4448 if (err < 0) {
4449 kfree(codec->spec);
4450 codec->spec = NULL;
4451 return err;
4452 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004453 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004454 codec->patch_ops = cx_auto_patch_ops;
4455 if (spec->beep_amp)
4456 snd_hda_attach_beep_device(codec, spec->beep_amp);
4457 return 0;
4458}
4459
4460/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004461 */
4462
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004463static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004464 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4465 .patch = patch_cxt5045 },
4466 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4467 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004468 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4469 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004470 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4471 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004472 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4473 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004474 { .id = 0x14f15068, .name = "CX20584",
4475 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004476 { .id = 0x14f15069, .name = "CX20585",
4477 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004478 { .id = 0x14f1506c, .name = "CX20588",
4479 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004480 { .id = 0x14f1506e, .name = "CX20590",
4481 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004482 { .id = 0x14f15097, .name = "CX20631",
4483 .patch = patch_conexant_auto },
4484 { .id = 0x14f15098, .name = "CX20632",
4485 .patch = patch_conexant_auto },
4486 { .id = 0x14f150a1, .name = "CX20641",
4487 .patch = patch_conexant_auto },
4488 { .id = 0x14f150a2, .name = "CX20642",
4489 .patch = patch_conexant_auto },
4490 { .id = 0x14f150ab, .name = "CX20651",
4491 .patch = patch_conexant_auto },
4492 { .id = 0x14f150ac, .name = "CX20652",
4493 .patch = patch_conexant_auto },
4494 { .id = 0x14f150b8, .name = "CX20664",
4495 .patch = patch_conexant_auto },
4496 { .id = 0x14f150b9, .name = "CX20665",
4497 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004498 {} /* terminator */
4499};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004500
4501MODULE_ALIAS("snd-hda-codec-id:14f15045");
4502MODULE_ALIAS("snd-hda-codec-id:14f15047");
4503MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004504MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004505MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004506MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004507MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004508MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004509MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004510MODULE_ALIAS("snd-hda-codec-id:14f15097");
4511MODULE_ALIAS("snd-hda-codec-id:14f15098");
4512MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4513MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4514MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4515MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4516MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4517MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004518
4519MODULE_LICENSE("GPL");
4520MODULE_DESCRIPTION("Conexant HD-audio codec");
4521
4522static struct hda_codec_preset_list conexant_list = {
4523 .preset = snd_hda_preset_conexant,
4524 .owner = THIS_MODULE,
4525};
4526
4527static int __init patch_conexant_init(void)
4528{
4529 return snd_hda_add_codec_preset(&conexant_list);
4530}
4531
4532static void __exit patch_conexant_exit(void)
4533{
4534 snd_hda_delete_codec_preset(&conexant_list);
4535}
4536
4537module_init(patch_conexant_init)
4538module_exit(patch_conexant_exit)