blob: a21a485a413ce395ce50c0c90dc6dbdbbec11b94 [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"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020034#include "hda_jack.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010035
36#define CXT_PIN_DIR_IN 0x00
37#define CXT_PIN_DIR_OUT 0x01
38#define CXT_PIN_DIR_INOUT 0x02
39#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
40#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
41
42#define CONEXANT_HP_EVENT 0x37
43#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020044#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010045
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010047
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010048#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010049#define CXT5051_PORTB_EVENT 0x38
50#define CXT5051_PORTC_EVENT 0x39
51
Takashi Iwaifaddaa52010-01-23 22:31:36 +010052#define AUTO_MIC_PORTB (1 << 1)
53#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010054
Takashi Iwaif2e57312010-09-15 10:07:08 +020055struct pin_dac_pair {
56 hda_nid_t pin;
57 hda_nid_t dac;
58 int type;
59};
60
Takashi Iwai47ad1f42011-05-17 09:15:55 +020061struct imux_info {
62 hda_nid_t pin; /* input pin NID */
63 hda_nid_t adc; /* connected ADC NID */
64 hda_nid_t boost; /* optional boost volume NID */
65 int index; /* corresponding to autocfg.input */
66};
67
Tobin Davisc9b443d2006-11-14 12:13:39 +010068struct conexant_spec {
69
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020070 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010071 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010072 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +010073 struct hda_vmaster_mute_hook vmaster_mute;
Tobin Davisc9b443d2006-11-14 12:13:39 +010074
75 const struct hda_verb *init_verbs[5]; /* initialization verbs
76 * don't forget NULL
77 * termination!
78 */
79 unsigned int num_init_verbs;
80
81 /* playback */
82 struct hda_multi_out multiout; /* playback set-up
83 * max_channels, dacs must be set
84 * dig_out_nid and hp_nid are optional
85 */
86 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010087 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020088 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010089 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020090 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020091 int auto_mic_dock; /* imux_pins[] index for dock mic */
92 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010093 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050094 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010095
96 /* capture */
97 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020098 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010099 hda_nid_t dig_in_nid; /* digital-in NID; optional */
100
Takashi Iwai461e2c72008-01-25 11:35:17 +0100101 unsigned int cur_adc_idx;
102 hda_nid_t cur_adc;
103 unsigned int cur_adc_stream_tag;
104 unsigned int cur_adc_format;
105
Takashi Iwai6764bce2011-05-13 16:52:25 +0200106 const struct hda_pcm_stream *capture_stream;
107
Tobin Davisc9b443d2006-11-14 12:13:39 +0100108 /* capture source */
109 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200110 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100111 unsigned int cur_mux[3];
112
113 /* channel model */
114 const struct hda_channel_mode *channel_mode;
115 int num_channel_mode;
116
117 /* PCM information */
118 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
119
Tobin Davisc9b443d2006-11-14 12:13:39 +0100120 unsigned int spdif_route;
121
122 /* dynamic controls, init_verbs and input_mux */
123 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100124 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200125 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200126 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200127 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200128 struct pin_dac_pair dac_info[8];
129 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100130
Daniel Drake0fb67e92009-07-16 14:46:57 +0100131 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200132 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200133 unsigned int detect_line:1; /* Line-out detection enabled */
134 unsigned int automute_lines:1; /* automute line-out as well */
135 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200136 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500137 unsigned int dell_vostro:1;
138 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200139 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200140 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100141 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200142 unsigned int pin_eapd_ctrls:1;
Takashi Iwai6b452142011-10-14 15:26:20 +0200143 unsigned int single_adc_amp:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100144
Takashi Iwai6764bce2011-05-13 16:52:25 +0200145 unsigned int adc_switching:1;
146
Daniel Drake75f89912010-01-07 13:46:25 +0100147 unsigned int ext_mic_present;
148 unsigned int recording;
149 void (*capture_prepare)(struct hda_codec *codec);
150 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100151
152 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
153 * through the microphone jack.
154 * When the user enables this through a mixer switch, both internal and
155 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
156 * we also allow the bias to be configured through a separate mixer
157 * control. */
158 unsigned int dc_enable;
159 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
160 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200161
162 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200163
164 /* extra EAPD pins */
165 unsigned int num_eapds;
166 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100167};
168
169static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
170 struct hda_codec *codec,
171 struct snd_pcm_substream *substream)
172{
173 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100174 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
175 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100176}
177
178static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
179 struct hda_codec *codec,
180 unsigned int stream_tag,
181 unsigned int format,
182 struct snd_pcm_substream *substream)
183{
184 struct conexant_spec *spec = codec->spec;
185 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
186 stream_tag,
187 format, substream);
188}
189
190static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
191 struct hda_codec *codec,
192 struct snd_pcm_substream *substream)
193{
194 struct conexant_spec *spec = codec->spec;
195 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
196}
197
198/*
199 * Digital out
200 */
201static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
202 struct hda_codec *codec,
203 struct snd_pcm_substream *substream)
204{
205 struct conexant_spec *spec = codec->spec;
206 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
207}
208
209static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
210 struct hda_codec *codec,
211 struct snd_pcm_substream *substream)
212{
213 struct conexant_spec *spec = codec->spec;
214 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
215}
216
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200217static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
218 struct hda_codec *codec,
219 unsigned int stream_tag,
220 unsigned int format,
221 struct snd_pcm_substream *substream)
222{
223 struct conexant_spec *spec = codec->spec;
224 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
225 stream_tag,
226 format, substream);
227}
228
Tobin Davisc9b443d2006-11-14 12:13:39 +0100229/*
230 * Analog capture
231 */
232static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
233 struct hda_codec *codec,
234 unsigned int stream_tag,
235 unsigned int format,
236 struct snd_pcm_substream *substream)
237{
238 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100239 if (spec->capture_prepare)
240 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100241 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
242 stream_tag, 0, format);
243 return 0;
244}
245
246static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
247 struct hda_codec *codec,
248 struct snd_pcm_substream *substream)
249{
250 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100251 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100252 if (spec->capture_cleanup)
253 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100254 return 0;
255}
256
257
258
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200259static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100260 .substreams = 1,
261 .channels_min = 2,
262 .channels_max = 2,
263 .nid = 0, /* fill later */
264 .ops = {
265 .open = conexant_playback_pcm_open,
266 .prepare = conexant_playback_pcm_prepare,
267 .cleanup = conexant_playback_pcm_cleanup
268 },
269};
270
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200271static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100272 .substreams = 1,
273 .channels_min = 2,
274 .channels_max = 2,
275 .nid = 0, /* fill later */
276 .ops = {
277 .prepare = conexant_capture_pcm_prepare,
278 .cleanup = conexant_capture_pcm_cleanup
279 },
280};
281
282
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200283static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100284 .substreams = 1,
285 .channels_min = 2,
286 .channels_max = 2,
287 .nid = 0, /* fill later */
288 .ops = {
289 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200290 .close = conexant_dig_playback_pcm_close,
291 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100292 },
293};
294
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200295static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100296 .substreams = 1,
297 .channels_min = 2,
298 .channels_max = 2,
299 /* NID is set in alc_build_pcms */
300};
301
Takashi Iwai461e2c72008-01-25 11:35:17 +0100302static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
303 struct hda_codec *codec,
304 unsigned int stream_tag,
305 unsigned int format,
306 struct snd_pcm_substream *substream)
307{
308 struct conexant_spec *spec = codec->spec;
309 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
310 spec->cur_adc_stream_tag = stream_tag;
311 spec->cur_adc_format = format;
312 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
313 return 0;
314}
315
316static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
317 struct hda_codec *codec,
318 struct snd_pcm_substream *substream)
319{
320 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100321 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100322 spec->cur_adc = 0;
323 return 0;
324}
325
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200326static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100327 .substreams = 1,
328 .channels_min = 2,
329 .channels_max = 2,
330 .nid = 0, /* fill later */
331 .ops = {
332 .prepare = cx5051_capture_pcm_prepare,
333 .cleanup = cx5051_capture_pcm_cleanup
334 },
335};
336
Tobin Davisc9b443d2006-11-14 12:13:39 +0100337static int conexant_build_pcms(struct hda_codec *codec)
338{
339 struct conexant_spec *spec = codec->spec;
340 struct hda_pcm *info = spec->pcm_rec;
341
342 codec->num_pcms = 1;
343 codec->pcm_info = info;
344
345 info->name = "CONEXANT Analog";
346 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
348 spec->multiout.max_channels;
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
350 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200351 if (spec->capture_stream)
352 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
353 else {
354 if (codec->vendor_id == 0x14f15051)
355 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
356 cx5051_pcm_analog_capture;
357 else {
358 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
359 conexant_pcm_analog_capture;
360 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
361 spec->num_adc_nids;
362 }
363 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100364 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
365
366 if (spec->multiout.dig_out_nid) {
367 info++;
368 codec->num_pcms++;
369 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100370 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100371 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
372 conexant_pcm_digital_playback;
373 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
374 spec->multiout.dig_out_nid;
375 if (spec->dig_in_nid) {
376 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
377 conexant_pcm_digital_capture;
378 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
379 spec->dig_in_nid;
380 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500381 if (spec->slave_dig_outs[0])
382 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100383 }
384
385 return 0;
386}
387
388static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
389 struct snd_ctl_elem_info *uinfo)
390{
391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
392 struct conexant_spec *spec = codec->spec;
393
394 return snd_hda_input_mux_info(spec->input_mux, uinfo);
395}
396
397static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
398 struct snd_ctl_elem_value *ucontrol)
399{
400 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
401 struct conexant_spec *spec = codec->spec;
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403
404 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
405 return 0;
406}
407
408static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
409 struct snd_ctl_elem_value *ucontrol)
410{
411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
412 struct conexant_spec *spec = codec->spec;
413 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
414
415 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
416 spec->capsrc_nids[adc_idx],
417 &spec->cur_mux[adc_idx]);
418}
419
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200420static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
421 unsigned int power_state)
422{
423 if (power_state == AC_PWRST_D3)
424 msleep(100);
425 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
426 power_state);
427 /* partial workaround for "azx_get_response timeout" */
428 if (power_state == AC_PWRST_D0)
429 msleep(10);
430 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
431}
432
Tobin Davisc9b443d2006-11-14 12:13:39 +0100433static int conexant_init(struct hda_codec *codec)
434{
435 struct conexant_spec *spec = codec->spec;
436 int i;
437
438 for (i = 0; i < spec->num_init_verbs; i++)
439 snd_hda_sequence_write(codec, spec->init_verbs[i]);
440 return 0;
441}
442
443static void conexant_free(struct hda_codec *codec)
444{
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200445 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100446 kfree(codec->spec);
447}
448
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200449static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100450 {
451 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
452 .name = "Capture Source",
453 .info = conexant_mux_enum_info,
454 .get = conexant_mux_enum_get,
455 .put = conexant_mux_enum_put
456 },
457 {}
458};
459
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200460#ifdef CONFIG_SND_HDA_INPUT_BEEP
461/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200462static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200463 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
464 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
465 { } /* end */
466};
467#endif
468
Takashi Iwai9322ca52012-02-03 14:28:01 +0100469static const char * const slave_pfxs[] = {
470 "Headphone", "Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100471 NULL
472};
473
Tobin Davisc9b443d2006-11-14 12:13:39 +0100474static int conexant_build_controls(struct hda_codec *codec)
475{
476 struct conexant_spec *spec = codec->spec;
477 unsigned int i;
478 int err;
479
480 for (i = 0; i < spec->num_mixers; i++) {
481 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
482 if (err < 0)
483 return err;
484 }
485 if (spec->multiout.dig_out_nid) {
486 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600487 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100488 spec->multiout.dig_out_nid);
489 if (err < 0)
490 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100491 err = snd_hda_create_spdif_share_sw(codec,
492 &spec->multiout);
493 if (err < 0)
494 return err;
495 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100496 }
497 if (spec->dig_in_nid) {
498 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
499 if (err < 0)
500 return err;
501 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100502
503 /* if we have no master control, let's create it */
504 if (spec->vmaster_nid &&
505 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
506 unsigned int vmaster_tlv[4];
507 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
508 HDA_OUTPUT, vmaster_tlv);
509 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100510 vmaster_tlv, slave_pfxs,
511 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100512 if (err < 0)
513 return err;
514 }
515 if (spec->vmaster_nid &&
516 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai527c73b2012-03-12 12:38:51 +0100517 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
518 NULL, slave_pfxs,
519 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100520 &spec->vmaster_mute.sw_kctl);
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100521 if (err < 0)
522 return err;
523 }
524
Takashi Iwaib880c742009-03-10 14:41:05 +0100525 if (spec->input_mux) {
526 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
527 if (err < 0)
528 return err;
529 }
530
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200531#ifdef CONFIG_SND_HDA_INPUT_BEEP
532 /* create beep controls if needed */
533 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200534 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200535 for (knew = cxt_beep_mixer; knew->name; knew++) {
536 struct snd_kcontrol *kctl;
537 kctl = snd_ctl_new1(knew, codec);
538 if (!kctl)
539 return -ENOMEM;
540 kctl->private_value = spec->beep_amp;
541 err = snd_hda_ctl_add(codec, 0, kctl);
542 if (err < 0)
543 return err;
544 }
545 }
546#endif
547
Tobin Davisc9b443d2006-11-14 12:13:39 +0100548 return 0;
549}
550
Takashi Iwai697c3732010-07-30 11:28:02 +0200551#ifdef CONFIG_SND_HDA_POWER_SAVE
552static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
553{
554 snd_hda_shutup_pins(codec);
555 return 0;
556}
557#endif
558
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200559static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100560 .build_controls = conexant_build_controls,
561 .build_pcms = conexant_build_pcms,
562 .init = conexant_init,
563 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200564 .set_power_state = conexant_set_power,
Takashi Iwai697c3732010-07-30 11:28:02 +0200565#ifdef CONFIG_SND_HDA_POWER_SAVE
566 .suspend = conexant_suspend,
567#endif
568 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100569};
570
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200571#ifdef CONFIG_SND_HDA_INPUT_BEEP
572#define set_beep_amp(spec, nid, idx, dir) \
573 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
574#else
575#define set_beep_amp(spec, nid, idx, dir) /* NOP */
576#endif
577
Takashi Iwai6764bce2011-05-13 16:52:25 +0200578static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100579/*
580 * EAPD control
581 * the private value = nid | (invert << 8)
582 */
583
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200584#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100585
Tobin Davis82f30042007-02-13 12:45:44 +0100586static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100587 struct snd_ctl_elem_value *ucontrol)
588{
589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590 struct conexant_spec *spec = codec->spec;
591 int invert = (kcontrol->private_value >> 8) & 1;
592 if (invert)
593 ucontrol->value.integer.value[0] = !spec->cur_eapd;
594 else
595 ucontrol->value.integer.value[0] = spec->cur_eapd;
596 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100597
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598}
599
Tobin Davis82f30042007-02-13 12:45:44 +0100600static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct conexant_spec *spec = codec->spec;
605 int invert = (kcontrol->private_value >> 8) & 1;
606 hda_nid_t nid = kcontrol->private_value & 0xff;
607 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100608
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100609 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100610 if (invert)
611 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200612 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100613 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100614
Tobin Davisc9b443d2006-11-14 12:13:39 +0100615 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200616 snd_hda_codec_write_cache(codec, nid,
617 0, AC_VERB_SET_EAPD_BTLENABLE,
618 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100619 return 1;
620}
621
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100622/* controls for test mode */
623#ifdef CONFIG_SND_DEBUG
624
Tobin Davis82f30042007-02-13 12:45:44 +0100625#define CXT_EAPD_SWITCH(xname, nid, mask) \
626 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
627 .info = cxt_eapd_info, \
628 .get = cxt_eapd_get, \
629 .put = cxt_eapd_put, \
630 .private_value = nid | (mask<<16) }
631
632
633
Tobin Davisc9b443d2006-11-14 12:13:39 +0100634static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_info *uinfo)
636{
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct conexant_spec *spec = codec->spec;
639 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
640 spec->num_channel_mode);
641}
642
643static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct conexant_spec *spec = codec->spec;
648 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
649 spec->num_channel_mode,
650 spec->multiout.max_channels);
651}
652
653static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol)
655{
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct conexant_spec *spec = codec->spec;
658 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
659 spec->num_channel_mode,
660 &spec->multiout.max_channels);
661 if (err >= 0 && spec->need_dac_fix)
662 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
663 return err;
664}
665
666#define CXT_PIN_MODE(xname, nid, dir) \
667 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
668 .info = conexant_ch_mode_info, \
669 .get = conexant_ch_mode_get, \
670 .put = conexant_ch_mode_put, \
671 .private_value = nid | (dir<<16) }
672
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100673#endif /* CONFIG_SND_DEBUG */
674
Tobin Davisc9b443d2006-11-14 12:13:39 +0100675/* Conexant 5045 specific */
676
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200677static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
678static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
679static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100680#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200682static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100683 { 2, NULL },
684};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100685
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200686static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100687 .num_items = 2,
688 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100689 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100690 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691 }
692};
693
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200694static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200695 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100696 .items = {
697 { "IntMic", 0x1 },
698 { "ExtMic", 0x2 },
699 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200700 { "CD", 0x4 },
701 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100702 }
703};
704
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200705static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100706 .num_items = 2,
707 .items = {
708 { "ExtMic", 0x1 },
709 { "IntMic", 0x2 },
710 }
711};
712
Tobin Davisc9b443d2006-11-14 12:13:39 +0100713/* turn on/off EAPD (+ mute HP) as a master switch */
714static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
716{
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100719 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100720
Tobin Davis82f30042007-02-13 12:45:44 +0100721 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722 return 0;
723
Tobin Davis82f30042007-02-13 12:45:44 +0100724 /* toggle internal speakers mute depending of presence of
725 * the headphone jack
726 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200727 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
728 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
729 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100730
Takashi Iwai47fd8302007-08-10 17:11:07 +0200731 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
732 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
733 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734 return 1;
735}
736
737/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200738static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200739 .ops = &snd_hda_bind_vol,
740 .values = {
741 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
742 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
743 0
744 },
745};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746
Tobin Davis7f296732007-03-12 11:39:01 +0100747/* toggle input of built-in and mic jack appropriately */
748static void cxt5045_hp_automic(struct hda_codec *codec)
749{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200750 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
752 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
753 {}
754 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200755 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100756 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
758 {}
759 };
760 unsigned int present;
761
Takashi Iwaid56757a2009-11-18 08:00:14 +0100762 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100763 if (present)
764 snd_hda_sequence_write(codec, mic_jack_on);
765 else
766 snd_hda_sequence_write(codec, mic_jack_off);
767}
768
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769
770/* mute internal speaker if HP is plugged */
771static void cxt5045_hp_automute(struct hda_codec *codec)
772{
Tobin Davis82f30042007-02-13 12:45:44 +0100773 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100774 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775
Takashi Iwaid56757a2009-11-18 08:00:14 +0100776 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100777
Takashi Iwai47fd8302007-08-10 17:11:07 +0200778 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
779 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
780 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100781}
782
783/* unsolicited event for HP jack sensing */
784static void cxt5045_hp_unsol_event(struct hda_codec *codec,
785 unsigned int res)
786{
787 res >>= 26;
788 switch (res) {
789 case CONEXANT_HP_EVENT:
790 cxt5045_hp_automute(codec);
791 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100792 case CONEXANT_MIC_EVENT:
793 cxt5045_hp_automic(codec);
794 break;
795
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796 }
797}
798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200799static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100800 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
801 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100802 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
803 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200804 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
805 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100806 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
807 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100808 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
809 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200810 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100811 {
812 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
813 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100814 .info = cxt_eapd_info,
815 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100816 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100817 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 },
819
820 {}
821};
822
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200823static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200824 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
825 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
826 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
827 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
828
Jiang Zhe5218c892008-01-17 11:18:41 +0100829 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
830 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
831 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
832 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
833
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200834 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
835 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
836
Jiang Zhe5218c892008-01-17 11:18:41 +0100837 {}
838};
839
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200840static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100841 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
842 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100843 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
844 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100845 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
846 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100847 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
848 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100849 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
850 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100851 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
852 {
853 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
854 .name = "Master Playback Switch",
855 .info = cxt_eapd_info,
856 .get = cxt_eapd_get,
857 .put = cxt5045_hp_master_sw_put,
858 .private_value = 0x10,
859 },
860
861 {}
862};
863
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200864static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100865 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200866 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100867 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100868 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200869 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
870 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
871 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
872 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
873 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
874 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
876 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
877 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100878 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100879 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100880 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100881 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
882 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100883 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100884 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100885 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100886 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100887 { } /* end */
888};
889
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200890static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100891 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100892 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
893 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
894 /* Line In,HP, Amp */
895 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
896 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
897 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
898 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
899 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
901 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
902 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
903 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100904 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100905 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
906 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
907 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
908 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100909 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100910 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
911 /* EAPD */
912 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
913 { } /* end */
914};
Tobin Davis7f296732007-03-12 11:39:01 +0100915
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200916static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100917 /* pin sensing on HP jack */
918 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200919 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100920};
921
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200922static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100923 /* pin sensing on HP jack */
924 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200925 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100926};
927
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928#ifdef CONFIG_SND_DEBUG
929/* Test configuration for debugging, modelled after the ALC260 test
930 * configuration.
931 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200932static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100933 .num_items = 5,
934 .items = {
935 { "MIXER", 0x0 },
936 { "MIC1 pin", 0x1 },
937 { "LINE1 pin", 0x2 },
938 { "HP-OUT pin", 0x3 },
939 { "CD pin", 0x4 },
940 },
941};
942
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200943static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100944
945 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
947 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100948 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
949 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
950 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
951 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952
953 /* Modes for retasking pin widgets */
954 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
955 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
956
Tobin Davis82f30042007-02-13 12:45:44 +0100957 /* EAPD Switch Control */
958 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
959
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100961
Tobin Davis7f296732007-03-12 11:39:01 +0100962 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
963 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
964 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
965 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
966 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
967 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
968 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
969 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
970 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
971 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972 {
973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
974 .name = "Input Source",
975 .info = conexant_mux_enum_info,
976 .get = conexant_mux_enum_get,
977 .put = conexant_mux_enum_put,
978 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200979 /* Audio input controls */
980 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
981 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
982 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
983 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
984 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
985 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
986 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
987 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
988 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
989 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990 { } /* end */
991};
992
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200993static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100994 /* Set connections */
995 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
996 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
997 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100998 /* Enable retasking pins as output, initially without power amp */
999 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001000 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001
1002 /* Disable digital (SPDIF) pins initially, but users can enable
1003 * them via a mixer switch. In the case of SPDIF-out, this initverb
1004 * payload also sets the generation to 0, output to be in "consumer"
1005 * PCM format, copyright asserted, no pre-emphasis and no validity
1006 * control.
1007 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001008 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1009 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001010
1011 /* Start with output sum widgets muted and their output gains at min */
1012 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1013 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1014
1015 /* Unmute retasking pin widget output buffers since the default
1016 * state appears to be output. As the pin mode is changed by the
1017 * user the pin mode control will take care of enabling the pin's
1018 * input/output buffers as needed.
1019 */
1020 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1021 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1022
1023 /* Mute capture amp left and right */
1024 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1025
1026 /* Set ADC connection select to match default mixer setting (mic1
1027 * pin)
1028 */
1029 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001030 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001031
1032 /* Mute all inputs to mixer widget (even unconnected ones) */
1033 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1034 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1035 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1036 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1037 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1038
1039 { }
1040};
1041#endif
1042
1043
1044/* initialize jack-sensing, too */
1045static int cxt5045_init(struct hda_codec *codec)
1046{
1047 conexant_init(codec);
1048 cxt5045_hp_automute(codec);
1049 return 0;
1050}
1051
1052
1053enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001054 CXT5045_LAPTOP_HPSENSE,
1055 CXT5045_LAPTOP_MICSENSE,
1056 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001057 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001058 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001059#ifdef CONFIG_SND_DEBUG
1060 CXT5045_TEST,
1061#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001062 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001063 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001064};
1065
Takashi Iwaiea734962011-01-17 11:29:34 +01001066static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001067 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1068 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1069 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1070 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001071 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001073 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001074#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001075 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001076};
1077
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001078static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001079 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001080 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001081 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001082 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1083 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001084 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1085 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001086 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1087 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1088 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001089 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1090 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001091 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001092 {}
1093};
1094
1095static int patch_cxt5045(struct hda_codec *codec)
1096{
1097 struct conexant_spec *spec;
1098 int board_config;
1099
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001100 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1101 cxt5045_models,
1102 cxt5045_cfg_tbl);
1103 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001104 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001105 if (board_config == CXT5045_AUTO)
1106 return patch_conexant_auto(codec);
1107
Tobin Davisc9b443d2006-11-14 12:13:39 +01001108 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1109 if (!spec)
1110 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001112 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113
1114 spec->multiout.max_channels = 2;
1115 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1116 spec->multiout.dac_nids = cxt5045_dac_nids;
1117 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1118 spec->num_adc_nids = 1;
1119 spec->adc_nids = cxt5045_adc_nids;
1120 spec->capsrc_nids = cxt5045_capsrc_nids;
1121 spec->input_mux = &cxt5045_capture_source;
1122 spec->num_mixers = 1;
1123 spec->mixers[0] = cxt5045_mixers;
1124 spec->num_init_verbs = 1;
1125 spec->init_verbs[0] = cxt5045_init_verbs;
1126 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001127 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1128 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001129
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001130 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131
1132 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001133
Tobin Davisc9b443d2006-11-14 12:13:39 +01001134 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001135 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001136 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137 spec->input_mux = &cxt5045_capture_source;
1138 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001139 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1140 spec->mixers[0] = cxt5045_mixers;
1141 codec->patch_ops.init = cxt5045_init;
1142 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001143 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001144 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001145 spec->input_mux = &cxt5045_capture_source;
1146 spec->num_init_verbs = 2;
1147 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001148 spec->mixers[0] = cxt5045_mixers;
1149 codec->patch_ops.init = cxt5045_init;
1150 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001151 default:
1152 case CXT5045_LAPTOP_HPMICSENSE:
1153 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1154 spec->input_mux = &cxt5045_capture_source;
1155 spec->num_init_verbs = 3;
1156 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1157 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1158 spec->mixers[0] = cxt5045_mixers;
1159 codec->patch_ops.init = cxt5045_init;
1160 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001161 case CXT5045_BENQ:
1162 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1163 spec->input_mux = &cxt5045_capture_source_benq;
1164 spec->num_init_verbs = 1;
1165 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1166 spec->mixers[0] = cxt5045_mixers;
1167 spec->mixers[1] = cxt5045_benq_mixers;
1168 spec->num_mixers = 2;
1169 codec->patch_ops.init = cxt5045_init;
1170 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001171 case CXT5045_LAPTOP_HP530:
1172 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1173 spec->input_mux = &cxt5045_capture_source_hp530;
1174 spec->num_init_verbs = 2;
1175 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1176 spec->mixers[0] = cxt5045_mixers_hp530;
1177 codec->patch_ops.init = cxt5045_init;
1178 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001179#ifdef CONFIG_SND_DEBUG
1180 case CXT5045_TEST:
1181 spec->input_mux = &cxt5045_test_capture_source;
1182 spec->mixers[0] = cxt5045_test_mixer;
1183 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001184 break;
1185
Tobin Davisc9b443d2006-11-14 12:13:39 +01001186#endif
1187 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001188
Takashi Iwai031005f2008-06-26 14:49:58 +02001189 switch (codec->subsystem_id >> 16) {
1190 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001191 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001192 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001193 case 0x17aa:
1194 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1195 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1196 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001197 */
1198 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1199 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1200 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1201 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1202 (1 << AC_AMPCAP_MUTE_SHIFT));
1203 break;
1204 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001205
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001206 if (spec->beep_amp)
1207 snd_hda_attach_beep_device(codec, spec->beep_amp);
1208
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209 return 0;
1210}
1211
1212
1213/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001214#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001215
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001216static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1217static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1218static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001219
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001220static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001221 { 2, NULL },
1222};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001224static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001225 .num_items = 2,
1226 .items = {
1227 { "ExtMic", 0x2 },
1228 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001229 }
1230};
1231
1232/* turn on/off EAPD (+ mute HP) as a master switch */
1233static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1234 struct snd_ctl_elem_value *ucontrol)
1235{
1236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1237 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001238 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001239
Tobin Davis82f30042007-02-13 12:45:44 +01001240 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241 return 0;
1242
Tobin Davis82f30042007-02-13 12:45:44 +01001243 /* toggle internal speakers mute depending of presence of
1244 * the headphone jack
1245 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001246 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001247 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1248 * pin widgets unlike other codecs. In this case, we need to
1249 * set index 0x01 for the volume from the mixer amp 0x19.
1250 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001251 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001252 HDA_AMP_MUTE, bits);
1253 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1254 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1255 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001256 return 1;
1257}
1258
Tobin Davisc9b443d2006-11-14 12:13:39 +01001259/* mute internal speaker if HP is plugged */
1260static void cxt5047_hp_automute(struct hda_codec *codec)
1261{
Tobin Davis82f30042007-02-13 12:45:44 +01001262 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001263 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001264
Takashi Iwaid56757a2009-11-18 08:00:14 +01001265 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001266
Takashi Iwai47fd8302007-08-10 17:11:07 +02001267 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001268 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001269 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001270 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001271}
1272
1273/* toggle input of built-in and mic jack appropriately */
1274static void cxt5047_hp_automic(struct hda_codec *codec)
1275{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001276 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001277 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1278 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001279 {}
1280 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001281 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001282 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1283 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001284 {}
1285 };
1286 unsigned int present;
1287
Takashi Iwaid56757a2009-11-18 08:00:14 +01001288 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001289 if (present)
1290 snd_hda_sequence_write(codec, mic_jack_on);
1291 else
1292 snd_hda_sequence_write(codec, mic_jack_off);
1293}
1294
1295/* unsolicited event for HP jack sensing */
1296static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1297 unsigned int res)
1298{
Marc Boucher9f113e02008-01-22 15:18:08 +01001299 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 case CONEXANT_HP_EVENT:
1301 cxt5047_hp_automute(codec);
1302 break;
1303 case CONEXANT_MIC_EVENT:
1304 cxt5047_hp_automic(codec);
1305 break;
1306 }
1307}
1308
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001309static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001310 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1311 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001312 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001313 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1314 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1315 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1316 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001317 {
1318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1319 .name = "Master Playback Switch",
1320 .info = cxt_eapd_info,
1321 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001322 .put = cxt5047_hp_master_sw_put,
1323 .private_value = 0x13,
1324 },
1325
1326 {}
1327};
1328
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001329static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001330 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001331 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001332 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1333 {}
1334};
1335
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001336static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001337 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001338 { } /* end */
1339};
1340
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001341static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 /* Line in, Mic, Built-in Mic */
1343 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1344 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1345 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001346 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001347 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001348 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1349 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001350 /* Record selector: Mic */
1351 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1352 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1353 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1354 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001355 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1356 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1357 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1358 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001359 /* SPDIF route: PCM */
1360 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001361 /* Enable unsolicited events */
1362 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1363 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001364 { } /* end */
1365};
1366
1367/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001368static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001369 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370 {}
1371};
1372
1373/* Test configuration for debugging, modelled after the ALC260 test
1374 * configuration.
1375 */
1376#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001377static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001378 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001379 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001380 { "LINE1 pin", 0x0 },
1381 { "MIC1 pin", 0x1 },
1382 { "MIC2 pin", 0x2 },
1383 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001384 },
1385};
1386
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001387static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001388
1389 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001390 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1391 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1392 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1393 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001394 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1395 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1396 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001398 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1400 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402
1403 /* Modes for retasking pin widgets */
1404 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1405 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1406
Tobin Davis82f30042007-02-13 12:45:44 +01001407 /* EAPD Switch Control */
1408 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1409
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001411 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1412 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1413 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1414 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1415 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1416 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1417 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1418 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419
Tobin Davis82f30042007-02-13 12:45:44 +01001420 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1421 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1422 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1423 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1425 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1427 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001428 {
1429 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1430 .name = "Input Source",
1431 .info = conexant_mux_enum_info,
1432 .get = conexant_mux_enum_get,
1433 .put = conexant_mux_enum_put,
1434 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001435 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001436
Tobin Davisc9b443d2006-11-14 12:13:39 +01001437 { } /* end */
1438};
1439
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001440static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001441 /* Enable retasking pins as output, initially without power amp */
1442 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1443 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1444 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1445
1446 /* Disable digital (SPDIF) pins initially, but users can enable
1447 * them via a mixer switch. In the case of SPDIF-out, this initverb
1448 * payload also sets the generation to 0, output to be in "consumer"
1449 * PCM format, copyright asserted, no pre-emphasis and no validity
1450 * control.
1451 */
1452 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1453
1454 /* Ensure mic1, mic2, line1 pin widgets take input from the
1455 * OUT1 sum bus when acting as an output.
1456 */
1457 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1458 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1459
1460 /* Start with output sum widgets muted and their output gains at min */
1461 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1462 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1463
1464 /* Unmute retasking pin widget output buffers since the default
1465 * state appears to be output. As the pin mode is changed by the
1466 * user the pin mode control will take care of enabling the pin's
1467 * input/output buffers as needed.
1468 */
1469 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1470 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1471 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1472
1473 /* Mute capture amp left and right */
1474 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1475
1476 /* Set ADC connection select to match default mixer setting (mic1
1477 * pin)
1478 */
1479 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1480
1481 /* Mute all inputs to mixer widget (even unconnected ones) */
1482 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1483 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1484 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1490
1491 { }
1492};
1493#endif
1494
1495
1496/* initialize jack-sensing, too */
1497static int cxt5047_hp_init(struct hda_codec *codec)
1498{
1499 conexant_init(codec);
1500 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001501 return 0;
1502}
1503
1504
1505enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001506 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1507 CXT5047_LAPTOP_HP, /* Some HP laptops */
1508 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509#ifdef CONFIG_SND_DEBUG
1510 CXT5047_TEST,
1511#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001512 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001513 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001514};
1515
Takashi Iwaiea734962011-01-17 11:29:34 +01001516static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001517 [CXT5047_LAPTOP] = "laptop",
1518 [CXT5047_LAPTOP_HP] = "laptop-hp",
1519 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001520#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001521 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001522#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001523 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001524};
1525
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001526static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001527 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001528 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1529 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001531 {}
1532};
1533
1534static int patch_cxt5047(struct hda_codec *codec)
1535{
1536 struct conexant_spec *spec;
1537 int board_config;
1538
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001539 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1540 cxt5047_models,
1541 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001542 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001543 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001544 if (board_config == CXT5047_AUTO)
1545 return patch_conexant_auto(codec);
1546
Tobin Davisc9b443d2006-11-14 12:13:39 +01001547 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1548 if (!spec)
1549 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001550 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001551 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552
1553 spec->multiout.max_channels = 2;
1554 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1555 spec->multiout.dac_nids = cxt5047_dac_nids;
1556 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1557 spec->num_adc_nids = 1;
1558 spec->adc_nids = cxt5047_adc_nids;
1559 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001561 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001562 spec->num_init_verbs = 1;
1563 spec->init_verbs[0] = cxt5047_init_verbs;
1564 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001565 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1566 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001567
1568 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001569
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 switch (board_config) {
1571 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001572 spec->num_mixers = 2;
1573 spec->mixers[1] = cxt5047_hp_spk_mixers;
1574 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575 break;
1576 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001577 spec->num_mixers = 2;
1578 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001579 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580 codec->patch_ops.init = cxt5047_hp_init;
1581 break;
1582 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001583 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001584 spec->num_mixers = 2;
1585 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001586 spec->num_init_verbs = 2;
1587 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001588 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001589 break;
1590#ifdef CONFIG_SND_DEBUG
1591 case CXT5047_TEST:
1592 spec->input_mux = &cxt5047_test_capture_source;
1593 spec->mixers[0] = cxt5047_test_mixer;
1594 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001595 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596#endif
1597 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001598 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001599
1600 switch (codec->subsystem_id >> 16) {
1601 case 0x103c:
1602 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1603 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1604 * with 0 dB offset 0x17)
1605 */
1606 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1607 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1608 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1609 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1610 (1 << AC_AMPCAP_MUTE_SHIFT));
1611 break;
1612 }
1613
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614 return 0;
1615}
1616
Takashi Iwai461e2c72008-01-25 11:35:17 +01001617/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001618static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1619static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001620
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001621static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001622 { 2, NULL },
1623};
1624
1625static void cxt5051_update_speaker(struct hda_codec *codec)
1626{
1627 struct conexant_spec *spec = codec->spec;
1628 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001629 /* headphone pin */
1630 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1631 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1632 pinctl);
1633 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001634 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1635 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1636 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001637 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1638 if (spec->ideapad)
1639 snd_hda_codec_write(codec, 0x1b, 0,
1640 AC_VERB_SET_PIN_WIDGET_CONTROL,
1641 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001642}
1643
1644/* turn on/off EAPD (+ mute HP) as a master switch */
1645static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol)
1647{
1648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1649
1650 if (!cxt_eapd_put(kcontrol, ucontrol))
1651 return 0;
1652 cxt5051_update_speaker(codec);
1653 return 1;
1654}
1655
1656/* toggle input of built-in and mic jack appropriately */
1657static void cxt5051_portb_automic(struct hda_codec *codec)
1658{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001659 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001660 unsigned int present;
1661
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001662 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001663 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001664 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001665 snd_hda_codec_write(codec, 0x14, 0,
1666 AC_VERB_SET_CONNECT_SEL,
1667 present ? 0x01 : 0x00);
1668}
1669
1670/* switch the current ADC according to the jack state */
1671static void cxt5051_portc_automic(struct hda_codec *codec)
1672{
1673 struct conexant_spec *spec = codec->spec;
1674 unsigned int present;
1675 hda_nid_t new_adc;
1676
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001677 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001678 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001679 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001680 if (present)
1681 spec->cur_adc_idx = 1;
1682 else
1683 spec->cur_adc_idx = 0;
1684 new_adc = spec->adc_nids[spec->cur_adc_idx];
1685 if (spec->cur_adc && spec->cur_adc != new_adc) {
1686 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001687 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001688 spec->cur_adc = new_adc;
1689 snd_hda_codec_setup_stream(codec, new_adc,
1690 spec->cur_adc_stream_tag, 0,
1691 spec->cur_adc_format);
1692 }
1693}
1694
1695/* mute internal speaker if HP is plugged */
1696static void cxt5051_hp_automute(struct hda_codec *codec)
1697{
1698 struct conexant_spec *spec = codec->spec;
1699
Takashi Iwaid56757a2009-11-18 08:00:14 +01001700 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001701 cxt5051_update_speaker(codec);
1702}
1703
1704/* unsolicited event for HP jack sensing */
1705static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1706 unsigned int res)
1707{
1708 switch (res >> 26) {
1709 case CONEXANT_HP_EVENT:
1710 cxt5051_hp_automute(codec);
1711 break;
1712 case CXT5051_PORTB_EVENT:
1713 cxt5051_portb_automic(codec);
1714 break;
1715 case CXT5051_PORTC_EVENT:
1716 cxt5051_portc_automic(codec);
1717 break;
1718 }
1719}
1720
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001721static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001722 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1723 {
1724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1725 .name = "Master Playback Switch",
1726 .info = cxt_eapd_info,
1727 .get = cxt_eapd_get,
1728 .put = cxt5051_hp_master_sw_put,
1729 .private_value = 0x1a,
1730 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001731 {}
1732};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001733
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001734static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001735 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001737 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1738 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001739 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1740 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001741 {}
1742};
1743
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001744static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001745 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1746 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001747 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1748 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001749 {}
1750};
1751
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001752static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001753 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1754 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001755 {}
1756};
1757
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001758static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001759 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1760 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001761 {}
1762};
1763
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001764static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001765 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1766 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001767 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1768 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001769 {}
1770};
1771
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001772static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001773 /* Line in, Mic */
1774 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1775 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1776 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1777 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1778 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1779 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1780 /* SPK */
1781 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1782 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1783 /* HP, Amp */
1784 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1785 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1786 /* DAC1 */
1787 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001788 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1790 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1791 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1792 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001793 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001794 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1795 /* EAPD */
1796 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1797 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001798 { } /* end */
1799};
1800
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001801static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001802 /* Line in, Mic */
1803 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1804 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1805 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1806 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1807 /* SPK */
1808 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1809 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1810 /* HP, Amp */
1811 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1812 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1813 /* DAC1 */
1814 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001815 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1817 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1818 /* SPDIF route: PCM */
1819 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1820 /* EAPD */
1821 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1822 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001823 { } /* end */
1824};
1825
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001826static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001827 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001828 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001829 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1830 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1831 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1832 /* SPK */
1833 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1834 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 /* HP, Amp */
1836 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1837 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1838 /* DAC1 */
1839 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001840 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1842 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1843 /* SPDIF route: PCM */
1844 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1845 /* EAPD */
1846 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1847 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001848 { } /* end */
1849};
1850
Takashi Iwai6953e552010-01-24 11:00:27 +01001851static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1852 unsigned int event)
1853{
1854 snd_hda_codec_write(codec, nid, 0,
1855 AC_VERB_SET_UNSOLICITED_ENABLE,
1856 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001857}
1858
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001859static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001860 /* Subwoofer */
1861 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1862 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1863 { } /* end */
1864};
1865
Takashi Iwai461e2c72008-01-25 11:35:17 +01001866/* initialize jack-sensing, too */
1867static int cxt5051_init(struct hda_codec *codec)
1868{
Takashi Iwai6953e552010-01-24 11:00:27 +01001869 struct conexant_spec *spec = codec->spec;
1870
Takashi Iwai461e2c72008-01-25 11:35:17 +01001871 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001872
1873 if (spec->auto_mic & AUTO_MIC_PORTB)
1874 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1875 if (spec->auto_mic & AUTO_MIC_PORTC)
1876 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1877
Takashi Iwai461e2c72008-01-25 11:35:17 +01001878 if (codec->patch_ops.unsol_event) {
1879 cxt5051_hp_automute(codec);
1880 cxt5051_portb_automic(codec);
1881 cxt5051_portc_automic(codec);
1882 }
1883 return 0;
1884}
1885
1886
1887enum {
1888 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1889 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001890 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001891 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001892 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001893 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001894 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001895 CXT5051_MODELS
1896};
1897
Takashi Iwaiea734962011-01-17 11:29:34 +01001898static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001899 [CXT5051_LAPTOP] = "laptop",
1900 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001901 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001902 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001903 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001904 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001905 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001906};
1907
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001908static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001909 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001910 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001911 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001912 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001913 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1914 CXT5051_LAPTOP),
1915 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001916 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001917 {}
1918};
1919
1920static int patch_cxt5051(struct hda_codec *codec)
1921{
1922 struct conexant_spec *spec;
1923 int board_config;
1924
Takashi Iwai6764bce2011-05-13 16:52:25 +02001925 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1926 cxt5051_models,
1927 cxt5051_cfg_tbl);
1928 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001929 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001930 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001931 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001932
Takashi Iwai461e2c72008-01-25 11:35:17 +01001933 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1934 if (!spec)
1935 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001936 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001937 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001938
1939 codec->patch_ops = conexant_patch_ops;
1940 codec->patch_ops.init = cxt5051_init;
1941
1942 spec->multiout.max_channels = 2;
1943 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1944 spec->multiout.dac_nids = cxt5051_dac_nids;
1945 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1946 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1947 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001948 spec->num_mixers = 2;
1949 spec->mixers[0] = cxt5051_capture_mixers;
1950 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001951 spec->num_init_verbs = 1;
1952 spec->init_verbs[0] = cxt5051_init_verbs;
1953 spec->spdif_route = 0;
1954 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1955 spec->channel_mode = cxt5051_modes;
1956 spec->cur_adc = 0;
1957 spec->cur_adc_idx = 0;
1958
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001959 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1960
Takashi Iwai79d7d532009-03-04 09:03:50 +01001961 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1962
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001963 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001964 switch (board_config) {
1965 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 spec->mixers[0] = cxt5051_hp_mixers;
1967 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001968 case CXT5051_HP_DV6736:
1969 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1970 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001971 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001972 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001973 case CXT5051_F700:
1974 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1975 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001976 spec->auto_mic = 0;
1977 break;
1978 case CXT5051_TOSHIBA:
1979 spec->mixers[0] = cxt5051_toshiba_mixers;
1980 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001981 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001982 case CXT5051_IDEAPAD:
1983 spec->init_verbs[spec->num_init_verbs++] =
1984 cxt5051_ideapad_init_verbs;
1985 spec->ideapad = 1;
1986 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001987 }
1988
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001989 if (spec->beep_amp)
1990 snd_hda_attach_beep_device(codec, spec->beep_amp);
1991
Takashi Iwai461e2c72008-01-25 11:35:17 +01001992 return 0;
1993}
1994
Daniel Drake0fb67e92009-07-16 14:46:57 +01001995/* Conexant 5066 specific */
1996
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001997static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1998static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1999static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2000static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002001
Daniel Drakedbaccc02009-11-09 15:17:24 +00002002/* OLPC's microphone port is DC coupled for use with external sensors,
2003 * therefore we use a 50% mic bias in order to center the input signal with
2004 * the DC input range of the codec. */
2005#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2006
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002007static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002008 { 2, NULL },
2009};
2010
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002011#define HP_PRESENT_PORT_A (1 << 0)
2012#define HP_PRESENT_PORT_D (1 << 1)
2013#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2014#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2015
Daniel Drake0fb67e92009-07-16 14:46:57 +01002016static void cxt5066_update_speaker(struct hda_codec *codec)
2017{
2018 struct conexant_spec *spec = codec->spec;
2019 unsigned int pinctl;
2020
John Baboval3a253442010-12-02 11:21:31 -05002021 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2022 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002023
2024 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002025 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002026 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2027 pinctl);
2028
2029 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002030 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2031 if (spec->dell_automute || spec->thinkpad) {
2032 /* Mute if Port A is connected */
2033 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002034 pinctl = 0;
2035 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002036 /* Thinkpad/Dell doesn't give pin-D status */
2037 if (!hp_port_d_present(spec))
2038 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002039 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002040 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2041 pinctl);
2042
2043 /* CLASS_D AMP */
2044 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2045 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2046 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002047}
2048
2049/* turn on/off EAPD (+ mute HP) as a master switch */
2050static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2051 struct snd_ctl_elem_value *ucontrol)
2052{
2053 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2054
2055 if (!cxt_eapd_put(kcontrol, ucontrol))
2056 return 0;
2057
2058 cxt5066_update_speaker(codec);
2059 return 1;
2060}
2061
Daniel Drakec4cfe662010-01-07 13:47:04 +01002062static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2063 .num_items = 3,
2064 .items = {
2065 { "Off", PIN_IN },
2066 { "50%", PIN_VREF50 },
2067 { "80%", PIN_VREF80 },
2068 },
2069};
2070
2071static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2072{
2073 struct conexant_spec *spec = codec->spec;
2074 /* Even though port F is the DC input, the bias is controlled on port B.
2075 * we also leave that port as an active input (but unselected) in DC mode
2076 * just in case that is necessary to make the bias setting take effect. */
2077 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2078 AC_VERB_SET_PIN_WIDGET_CONTROL,
2079 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2080}
2081
Daniel Drake75f89912010-01-07 13:46:25 +01002082/* OLPC defers mic widget control until when capture is started because the
2083 * microphone LED comes on as soon as these settings are put in place. if we
2084 * did this before recording, it would give the false indication that recording
2085 * is happening when it is not. */
2086static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002087{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002088 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002089 if (!spec->recording)
2090 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002091
Daniel Drakec4cfe662010-01-07 13:47:04 +01002092 if (spec->dc_enable) {
2093 /* in DC mode we ignore presence detection and just use the jack
2094 * through our special DC port */
2095 const struct hda_verb enable_dc_mode[] = {
2096 /* disble internal mic, port C */
2097 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2098
2099 /* enable DC capture, port F */
2100 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2101 {},
2102 };
2103
2104 snd_hda_sequence_write(codec, enable_dc_mode);
2105 /* port B input disabled (and bias set) through the following call */
2106 cxt5066_set_olpc_dc_bias(codec);
2107 return;
2108 }
2109
2110 /* disable DC (port F) */
2111 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2112
Daniel Drake75f89912010-01-07 13:46:25 +01002113 /* external mic, port B */
2114 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2115 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002116
Daniel Drake75f89912010-01-07 13:46:25 +01002117 /* internal mic, port C */
2118 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2119 spec->ext_mic_present ? 0 : PIN_VREF80);
2120}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002121
Daniel Drake75f89912010-01-07 13:46:25 +01002122/* toggle input of built-in and mic jack appropriately */
2123static void cxt5066_olpc_automic(struct hda_codec *codec)
2124{
2125 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002126 unsigned int present;
2127
Daniel Drakec4cfe662010-01-07 13:47:04 +01002128 if (spec->dc_enable) /* don't do presence detection in DC mode */
2129 return;
2130
Daniel Drake75f89912010-01-07 13:46:25 +01002131 present = snd_hda_codec_read(codec, 0x1a, 0,
2132 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2133 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002134 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002135 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002136 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002137
2138 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2139 present ? 0 : 1);
2140 spec->ext_mic_present = !!present;
2141
2142 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002143}
2144
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002145/* toggle input of built-in digital mic and mic jack appropriately */
2146static void cxt5066_vostro_automic(struct hda_codec *codec)
2147{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002148 unsigned int present;
2149
2150 struct hda_verb ext_mic_present[] = {
2151 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002152 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002153
2154 /* switch to external mic input */
2155 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2156 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2157
2158 /* disable internal digital mic */
2159 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2160 {}
2161 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002162 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002163 /* enable internal mic, port C */
2164 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2165
2166 /* switch to internal mic input */
2167 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2168
2169 /* disable external mic, port B */
2170 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2171 {}
2172 };
2173
2174 present = snd_hda_jack_detect(codec, 0x1a);
2175 if (present) {
2176 snd_printdd("CXT5066: external microphone detected\n");
2177 snd_hda_sequence_write(codec, ext_mic_present);
2178 } else {
2179 snd_printdd("CXT5066: external microphone absent\n");
2180 snd_hda_sequence_write(codec, ext_mic_absent);
2181 }
2182}
2183
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002184/* toggle input of built-in digital mic and mic jack appropriately */
2185static void cxt5066_ideapad_automic(struct hda_codec *codec)
2186{
2187 unsigned int present;
2188
2189 struct hda_verb ext_mic_present[] = {
2190 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2191 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2192 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2193 {}
2194 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002195 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002196 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2197 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2198 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2199 {}
2200 };
2201
2202 present = snd_hda_jack_detect(codec, 0x1b);
2203 if (present) {
2204 snd_printdd("CXT5066: external microphone detected\n");
2205 snd_hda_sequence_write(codec, ext_mic_present);
2206 } else {
2207 snd_printdd("CXT5066: external microphone absent\n");
2208 snd_hda_sequence_write(codec, ext_mic_absent);
2209 }
2210}
2211
David Henningssona1d69062011-01-21 13:33:28 +01002212
2213/* toggle input of built-in digital mic and mic jack appropriately */
2214static void cxt5066_asus_automic(struct hda_codec *codec)
2215{
2216 unsigned int present;
2217
2218 present = snd_hda_jack_detect(codec, 0x1b);
2219 snd_printdd("CXT5066: external microphone present=%d\n", present);
2220 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2221 present ? 1 : 0);
2222}
2223
2224
David Henningsson048e78a2010-09-02 08:35:47 +02002225/* toggle input of built-in digital mic and mic jack appropriately */
2226static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2227{
2228 unsigned int present;
2229
2230 present = snd_hda_jack_detect(codec, 0x1b);
2231 snd_printdd("CXT5066: external microphone present=%d\n", present);
2232 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2233 present ? 1 : 3);
2234}
2235
2236
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002237/* toggle input of built-in digital mic and mic jack appropriately
2238 order is: external mic -> dock mic -> interal mic */
2239static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2240{
2241 unsigned int ext_present, dock_present;
2242
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002243 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002244 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2245 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2246 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2247 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2248 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2249 {}
2250 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002251 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002252 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2253 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2254 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2255 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2256 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2257 {}
2258 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002259 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002260 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2261 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2262 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2263 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2264 {}
2265 };
2266
2267 ext_present = snd_hda_jack_detect(codec, 0x1b);
2268 dock_present = snd_hda_jack_detect(codec, 0x1a);
2269 if (ext_present) {
2270 snd_printdd("CXT5066: external microphone detected\n");
2271 snd_hda_sequence_write(codec, ext_mic_present);
2272 } else if (dock_present) {
2273 snd_printdd("CXT5066: dock microphone detected\n");
2274 snd_hda_sequence_write(codec, dock_mic_present);
2275 } else {
2276 snd_printdd("CXT5066: external microphone absent\n");
2277 snd_hda_sequence_write(codec, ext_mic_absent);
2278 }
2279}
2280
Daniel Drake0fb67e92009-07-16 14:46:57 +01002281/* mute internal speaker if HP is plugged */
2282static void cxt5066_hp_automute(struct hda_codec *codec)
2283{
2284 struct conexant_spec *spec = codec->spec;
2285 unsigned int portA, portD;
2286
2287 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002288 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002289
2290 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002291 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002292
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002293 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2294 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002295 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2296 portA, portD, spec->hp_present);
2297 cxt5066_update_speaker(codec);
2298}
2299
David Henningsson02b6b5b2011-01-21 13:27:39 +01002300/* Dispatch the right mic autoswitch function */
2301static void cxt5066_automic(struct hda_codec *codec)
2302{
2303 struct conexant_spec *spec = codec->spec;
2304
2305 if (spec->dell_vostro)
2306 cxt5066_vostro_automic(codec);
2307 else if (spec->ideapad)
2308 cxt5066_ideapad_automic(codec);
2309 else if (spec->thinkpad)
2310 cxt5066_thinkpad_automic(codec);
2311 else if (spec->hp_laptop)
2312 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002313 else if (spec->asus)
2314 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002315}
2316
Daniel Drake0fb67e92009-07-16 14:46:57 +01002317/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002318static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002319{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002320 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002321 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2322 switch (res >> 26) {
2323 case CONEXANT_HP_EVENT:
2324 cxt5066_hp_automute(codec);
2325 break;
2326 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002327 /* ignore mic events in DC mode; we're always using the jack */
2328 if (!spec->dc_enable)
2329 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002330 break;
2331 }
2332}
2333
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002334/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002335static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002336{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002337 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002338 switch (res >> 26) {
2339 case CONEXANT_HP_EVENT:
2340 cxt5066_hp_automute(codec);
2341 break;
2342 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002343 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002344 break;
2345 }
2346}
2347
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002348
Daniel Drake0fb67e92009-07-16 14:46:57 +01002349static const struct hda_input_mux cxt5066_analog_mic_boost = {
2350 .num_items = 5,
2351 .items = {
2352 { "0dB", 0 },
2353 { "10dB", 1 },
2354 { "20dB", 2 },
2355 { "30dB", 3 },
2356 { "40dB", 4 },
2357 },
2358};
2359
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002360static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002361{
2362 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002363 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002364 AC_VERB_SET_AMP_GAIN_MUTE,
2365 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2366 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002367 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002368 /* adjust the internal mic as well...it is not through 0x17 */
2369 snd_hda_codec_write_cache(codec, 0x23, 0,
2370 AC_VERB_SET_AMP_GAIN_MUTE,
2371 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2372 cxt5066_analog_mic_boost.
2373 items[spec->mic_boost].index);
2374 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002375}
2376
Daniel Drake0fb67e92009-07-16 14:46:57 +01002377static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2378 struct snd_ctl_elem_info *uinfo)
2379{
2380 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2381}
2382
2383static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2384 struct snd_ctl_elem_value *ucontrol)
2385{
2386 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002387 struct conexant_spec *spec = codec->spec;
2388 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002389 return 0;
2390}
2391
2392static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2393 struct snd_ctl_elem_value *ucontrol)
2394{
2395 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002396 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002397 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2398 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002399 idx = ucontrol->value.enumerated.item[0];
2400 if (idx >= imux->num_items)
2401 idx = imux->num_items - 1;
2402
Daniel Drakec4cfe662010-01-07 13:47:04 +01002403 spec->mic_boost = idx;
2404 if (!spec->dc_enable)
2405 cxt5066_set_mic_boost(codec);
2406 return 1;
2407}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002408
Daniel Drakec4cfe662010-01-07 13:47:04 +01002409static void cxt5066_enable_dc(struct hda_codec *codec)
2410{
2411 const struct hda_verb enable_dc_mode[] = {
2412 /* disable gain */
2413 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2414
2415 /* switch to DC input */
2416 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2417 {}
2418 };
2419
2420 /* configure as input source */
2421 snd_hda_sequence_write(codec, enable_dc_mode);
2422 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2423}
2424
2425static void cxt5066_disable_dc(struct hda_codec *codec)
2426{
2427 /* reconfigure input source */
2428 cxt5066_set_mic_boost(codec);
2429 /* automic also selects the right mic if we're recording */
2430 cxt5066_olpc_automic(codec);
2431}
2432
2433static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2434 struct snd_ctl_elem_value *ucontrol)
2435{
2436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2437 struct conexant_spec *spec = codec->spec;
2438 ucontrol->value.integer.value[0] = spec->dc_enable;
2439 return 0;
2440}
2441
2442static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2443 struct snd_ctl_elem_value *ucontrol)
2444{
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2446 struct conexant_spec *spec = codec->spec;
2447 int dc_enable = !!ucontrol->value.integer.value[0];
2448
2449 if (dc_enable == spec->dc_enable)
2450 return 0;
2451
2452 spec->dc_enable = dc_enable;
2453 if (dc_enable)
2454 cxt5066_enable_dc(codec);
2455 else
2456 cxt5066_disable_dc(codec);
2457
2458 return 1;
2459}
2460
2461static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2462 struct snd_ctl_elem_info *uinfo)
2463{
2464 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2465}
2466
2467static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2468 struct snd_ctl_elem_value *ucontrol)
2469{
2470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2471 struct conexant_spec *spec = codec->spec;
2472 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2473 return 0;
2474}
2475
2476static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2477 struct snd_ctl_elem_value *ucontrol)
2478{
2479 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2480 struct conexant_spec *spec = codec->spec;
2481 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2482 unsigned int idx;
2483
2484 idx = ucontrol->value.enumerated.item[0];
2485 if (idx >= imux->num_items)
2486 idx = imux->num_items - 1;
2487
2488 spec->dc_input_bias = idx;
2489 if (spec->dc_enable)
2490 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002491 return 1;
2492}
2493
Daniel Drake75f89912010-01-07 13:46:25 +01002494static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2495{
2496 struct conexant_spec *spec = codec->spec;
2497 /* mark as recording and configure the microphone widget so that the
2498 * recording LED comes on. */
2499 spec->recording = 1;
2500 cxt5066_olpc_select_mic(codec);
2501}
2502
2503static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2504{
2505 struct conexant_spec *spec = codec->spec;
2506 const struct hda_verb disable_mics[] = {
2507 /* disable external mic, port B */
2508 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2509
2510 /* disble internal mic, port C */
2511 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002512
2513 /* disable DC capture, port F */
2514 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002515 {},
2516 };
2517
2518 snd_hda_sequence_write(codec, disable_mics);
2519 spec->recording = 0;
2520}
2521
Andy Robinsonf6a24912011-01-24 10:12:37 -05002522static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002523 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002524 int num_pins)
2525{
2526 struct conexant_spec *spec = codec->spec;
2527 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2528 int i;
2529
2530 for (i = 0; i < num_pins; i++, dig_pins++) {
2531 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2532 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2533 continue;
2534 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2535 continue;
2536 if (spec->slave_dig_outs[0])
2537 nid_loc++;
2538 else
2539 nid_loc = spec->slave_dig_outs;
2540 }
2541}
2542
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002543static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002544 .num_items = 4,
2545 .items = {
2546 { "Mic B", 0 },
2547 { "Mic C", 1 },
2548 { "Mic E", 2 },
2549 { "Mic F", 3 },
2550 },
2551};
2552
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002553static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002554 .ops = &snd_hda_bind_vol,
2555 .values = {
2556 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2557 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2558 0
2559 },
2560};
2561
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002562static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002563 .ops = &snd_hda_bind_sw,
2564 .values = {
2565 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2566 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2567 0
2568 },
2569};
2570
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002571static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002572 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2573 {}
2574};
2575
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002576static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002577 {
2578 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2579 .name = "Master Playback Volume",
2580 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2581 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2582 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002583 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002584 .info = snd_hda_mixer_amp_volume_info,
2585 .get = snd_hda_mixer_amp_volume_get,
2586 .put = snd_hda_mixer_amp_volume_put,
2587 .tlv = { .c = snd_hda_mixer_amp_tlv },
2588 /* offset by 28 volume steps to limit minimum gain to -46dB */
2589 .private_value =
2590 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2591 },
2592 {}
2593};
2594
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002595static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002596 {
2597 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2598 .name = "DC Mode Enable Switch",
2599 .info = snd_ctl_boolean_mono_info,
2600 .get = cxt5066_olpc_dc_get,
2601 .put = cxt5066_olpc_dc_put,
2602 },
2603 {
2604 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2605 .name = "DC Input Bias Enum",
2606 .info = cxt5066_olpc_dc_bias_enum_info,
2607 .get = cxt5066_olpc_dc_bias_enum_get,
2608 .put = cxt5066_olpc_dc_bias_enum_put,
2609 },
2610 {}
2611};
2612
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002613static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002614 {
2615 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2616 .name = "Master Playback Switch",
2617 .info = cxt_eapd_info,
2618 .get = cxt_eapd_get,
2619 .put = cxt5066_hp_master_sw_put,
2620 .private_value = 0x1d,
2621 },
2622
2623 {
2624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002625 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002626 .info = cxt5066_mic_boost_mux_enum_info,
2627 .get = cxt5066_mic_boost_mux_enum_get,
2628 .put = cxt5066_mic_boost_mux_enum_put,
2629 },
2630
2631 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2632 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2633 {}
2634};
2635
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002636static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002637 {
2638 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002639 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002640 .info = cxt5066_mic_boost_mux_enum_info,
2641 .get = cxt5066_mic_boost_mux_enum_get,
2642 .put = cxt5066_mic_boost_mux_enum_put,
2643 .private_value = 0x23 | 0x100,
2644 },
2645 {}
2646};
2647
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002648static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002649 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2650 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2651 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2652 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2653
2654 /* Speakers */
2655 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2656 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2657
2658 /* HP, Amp */
2659 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2660 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2661
2662 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2663 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2664
2665 /* DAC1 */
2666 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2667
2668 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2669 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2670 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2671 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2672 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2673 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2674
2675 /* no digital microphone support yet */
2676 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2677
2678 /* Audio input selector */
2679 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2680
2681 /* SPDIF route: PCM */
2682 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2683 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2684
2685 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2686 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2687
2688 /* EAPD */
2689 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2690
2691 /* not handling these yet */
2692 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2693 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2694 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2695 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2696 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2697 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2698 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2699 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2700 { } /* end */
2701};
2702
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002703static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002704 /* Port A: headphones */
2705 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2706 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2707
2708 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002709 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002710
2711 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002712 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002713
2714 /* Port D: unused */
2715 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2716
2717 /* Port E: unused, but has primary EAPD */
2718 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2719 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2720
Daniel Drakec4cfe662010-01-07 13:47:04 +01002721 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002722 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2723
2724 /* Port G: internal speakers */
2725 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2726 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2727
2728 /* DAC1 */
2729 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2730
2731 /* DAC2: unused */
2732 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2733
2734 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2735 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2736 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2737 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2738 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2739 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2740 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2741 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2742 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2743 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2744 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2745 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2746
2747 /* Disable digital microphone port */
2748 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2749
2750 /* Audio input selectors */
2751 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2752 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2753
2754 /* Disable SPDIF */
2755 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2756 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2757
2758 /* enable unsolicited events for Port A and B */
2759 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2760 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2761 { } /* end */
2762};
2763
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002764static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002765 /* Port A: headphones */
2766 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2767 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2768
2769 /* Port B: external microphone */
2770 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2771
2772 /* Port C: unused */
2773 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2774
2775 /* Port D: unused */
2776 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2777
2778 /* Port E: unused, but has primary EAPD */
2779 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2780 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2781
2782 /* Port F: unused */
2783 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2784
2785 /* Port G: internal speakers */
2786 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2787 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2788
2789 /* DAC1 */
2790 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2791
2792 /* DAC2: unused */
2793 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2794
2795 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2796 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2797 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2798 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2799 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2800 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2801 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2802 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2803 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2804 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2805 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2806 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2807
2808 /* Digital microphone port */
2809 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2810
2811 /* Audio input selectors */
2812 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2813 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2814
2815 /* Disable SPDIF */
2816 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2817 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2818
2819 /* enable unsolicited events for Port A and B */
2820 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2821 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2822 { } /* end */
2823};
2824
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002825static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002826 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2827 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2828 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2830
2831 /* Speakers */
2832 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2833 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2834
2835 /* HP, Amp */
2836 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2837 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2838
2839 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2840 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2841
2842 /* DAC1 */
2843 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2844
2845 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2847 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2848 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2849 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2850 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2851 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2852
2853 /* Audio input selector */
2854 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2855 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2856
2857 /* SPDIF route: PCM */
2858 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2859 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2860
2861 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2862 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2863
2864 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002865 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002866
2867 /* EAPD */
2868 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2869
2870 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2871 {0x1b, 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_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002876 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2877 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2878
2879 /* Port G: internal speakers */
2880 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2881 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2882
2883 /* Port A: HP, Amp */
2884 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2885 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2886
2887 /* Port B: Mic Dock */
2888 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2889
2890 /* Port C: Mic */
2891 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2892
2893 /* Port D: HP Dock, Amp */
2894 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2895 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2896
2897 /* DAC1 */
2898 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2899
2900 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2901 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2902 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2903 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2906 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2907
2908 /* Audio input selector */
2909 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2910 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2911
2912 /* SPDIF route: PCM */
2913 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2914 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2915
2916 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2917 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2918
2919 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002920 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002921
2922 /* EAPD */
2923 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2924
2925 /* enable unsolicited events for Port A, B, C and D */
2926 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2927 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2928 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2929 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2930 { } /* end */
2931};
2932
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002933static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002934 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2935 { } /* end */
2936};
2937
David Henningsson048e78a2010-09-02 08:35:47 +02002938
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002939static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002940 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2941 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2942 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2943 { } /* end */
2944};
2945
Daniel Drake0fb67e92009-07-16 14:46:57 +01002946/* initialize jack-sensing, too */
2947static int cxt5066_init(struct hda_codec *codec)
2948{
2949 snd_printdd("CXT5066: init\n");
2950 conexant_init(codec);
2951 if (codec->patch_ops.unsol_event) {
2952 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002953 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002954 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002955 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002956 return 0;
2957}
2958
Daniel Drake75f89912010-01-07 13:46:25 +01002959static int cxt5066_olpc_init(struct hda_codec *codec)
2960{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002961 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002962 snd_printdd("CXT5066: init\n");
2963 conexant_init(codec);
2964 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002965 if (!spec->dc_enable) {
2966 cxt5066_set_mic_boost(codec);
2967 cxt5066_olpc_automic(codec);
2968 } else {
2969 cxt5066_enable_dc(codec);
2970 }
Daniel Drake75f89912010-01-07 13:46:25 +01002971 return 0;
2972}
2973
Daniel Drake0fb67e92009-07-16 14:46:57 +01002974enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002975 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002976 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2977 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002978 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002979 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002980 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002981 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002982 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002983 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002984 CXT5066_MODELS
2985};
2986
Takashi Iwaiea734962011-01-17 11:29:34 +01002987static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002988 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002989 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2990 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002991 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002992 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002993 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002994 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002995 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002996 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002997};
2998
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002999static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02003000 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003001 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003002 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003003 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003004 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003005 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003006 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003007 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3008 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003009 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003010 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003011 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003012 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003013 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003014 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003015 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3016 CXT5066_LAPTOP),
3017 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003018 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003019 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003020 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson29c5fbb2012-01-23 16:39:55 +01003021 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO),
Daniel Suchyca201c02011-10-18 11:09:44 +02003022 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02003023 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003024 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003025 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003026 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003027 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003028 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003029 {}
3030};
3031
3032static int patch_cxt5066(struct hda_codec *codec)
3033{
3034 struct conexant_spec *spec;
3035 int board_config;
3036
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003037 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3038 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003039 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003040 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003041 if (board_config == CXT5066_AUTO)
3042 return patch_conexant_auto(codec);
3043
Daniel Drake0fb67e92009-07-16 14:46:57 +01003044 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3045 if (!spec)
3046 return -ENOMEM;
3047 codec->spec = spec;
3048
3049 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003050 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003051
3052 spec->dell_automute = 0;
3053 spec->multiout.max_channels = 2;
3054 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3055 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003056 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3057 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003058 spec->num_adc_nids = 1;
3059 spec->adc_nids = cxt5066_adc_nids;
3060 spec->capsrc_nids = cxt5066_capsrc_nids;
3061 spec->input_mux = &cxt5066_capture_source;
3062
3063 spec->port_d_mode = PIN_HP;
3064
3065 spec->num_init_verbs = 1;
3066 spec->init_verbs[0] = cxt5066_init_verbs;
3067 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3068 spec->channel_mode = cxt5066_modes;
3069 spec->cur_adc = 0;
3070 spec->cur_adc_idx = 0;
3071
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003072 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3073
Daniel Drake0fb67e92009-07-16 14:46:57 +01003074 switch (board_config) {
3075 default:
3076 case CXT5066_LAPTOP:
3077 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3078 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3079 break;
3080 case CXT5066_DELL_LAPTOP:
3081 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3082 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3083
3084 spec->port_d_mode = PIN_OUT;
3085 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3086 spec->num_init_verbs++;
3087 spec->dell_automute = 1;
3088 break;
David Henningssona1d69062011-01-21 13:33:28 +01003089 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003090 case CXT5066_HP_LAPTOP:
3091 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003092 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003093 spec->init_verbs[spec->num_init_verbs] =
3094 cxt5066_init_verbs_hp_laptop;
3095 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003096 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3097 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003098 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3099 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3100 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003101 if (board_config == CXT5066_HP_LAPTOP)
3102 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003103 /* input source automatically selected */
3104 spec->input_mux = NULL;
3105 spec->port_d_mode = 0;
3106 spec->mic_boost = 3; /* default 30dB gain */
3107 break;
3108
Daniel Drake0fb67e92009-07-16 14:46:57 +01003109 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003110 codec->patch_ops.init = cxt5066_olpc_init;
3111 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003112 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3113 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003114 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003115 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3116 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003117 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003118
3119 /* no S/PDIF out */
3120 spec->multiout.dig_out_nid = 0;
3121
3122 /* input source automatically selected */
3123 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003124
3125 /* our capture hooks which allow us to turn on the microphone LED
3126 * at the right time */
3127 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3128 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003129 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003130 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003131 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003132 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003133 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3134 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3135 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003136 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003137 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003138 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003139 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003140
3141 /* no S/PDIF out */
3142 spec->multiout.dig_out_nid = 0;
3143
3144 /* input source automatically selected */
3145 spec->input_mux = NULL;
3146 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003147 case CXT5066_IDEAPAD:
3148 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003149 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003150 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3152 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3153 spec->port_d_mode = 0;
3154 spec->ideapad = 1;
3155 spec->mic_boost = 2; /* default 20dB gain */
3156
3157 /* no S/PDIF out */
3158 spec->multiout.dig_out_nid = 0;
3159
3160 /* input source automatically selected */
3161 spec->input_mux = NULL;
3162 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003163 case CXT5066_THINKPAD:
3164 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003165 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003166 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3167 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3168 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3169 spec->thinkpad = 1;
3170 spec->port_d_mode = PIN_OUT;
3171 spec->mic_boost = 2; /* default 20dB gain */
3172
3173 /* no S/PDIF out */
3174 spec->multiout.dig_out_nid = 0;
3175
3176 /* input source automatically selected */
3177 spec->input_mux = NULL;
3178 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003179 }
3180
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003181 if (spec->beep_amp)
3182 snd_hda_attach_beep_device(codec, spec->beep_amp);
3183
Daniel Drake0fb67e92009-07-16 14:46:57 +01003184 return 0;
3185}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003186
3187/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003188 * Automatic parser for CX20641 & co
3189 */
3190
Takashi Iwai6764bce2011-05-13 16:52:25 +02003191static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3192 struct hda_codec *codec,
3193 unsigned int stream_tag,
3194 unsigned int format,
3195 struct snd_pcm_substream *substream)
3196{
3197 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003198 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003199 if (spec->adc_switching) {
3200 spec->cur_adc = adc;
3201 spec->cur_adc_stream_tag = stream_tag;
3202 spec->cur_adc_format = format;
3203 }
3204 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3205 return 0;
3206}
3207
3208static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3209 struct hda_codec *codec,
3210 struct snd_pcm_substream *substream)
3211{
3212 struct conexant_spec *spec = codec->spec;
3213 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3214 spec->cur_adc = 0;
3215 return 0;
3216}
3217
3218static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3219 .substreams = 1,
3220 .channels_min = 2,
3221 .channels_max = 2,
3222 .nid = 0, /* fill later */
3223 .ops = {
3224 .prepare = cx_auto_capture_pcm_prepare,
3225 .cleanup = cx_auto_capture_pcm_cleanup
3226 },
3227};
3228
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003229static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003230
Takashi Iwai8d087c72011-06-28 12:45:47 +02003231#define get_connection_index(codec, mux, nid)\
3232 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003233
3234/* get an unassigned DAC from the given list.
3235 * Return the nid if found and reduce the DAC list, or return zero if
3236 * not found
3237 */
3238static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3239 hda_nid_t *dacs, int *num_dacs)
3240{
3241 int i, nums = *num_dacs;
3242 hda_nid_t ret = 0;
3243
3244 for (i = 0; i < nums; i++) {
3245 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3246 ret = dacs[i];
3247 break;
3248 }
3249 }
3250 if (!ret)
3251 return 0;
3252 if (--nums > 0)
3253 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3254 *num_dacs = nums;
3255 return ret;
3256}
3257
3258#define MAX_AUTO_DACS 5
3259
Takashi Iwai1f015f52011-08-23 14:57:08 +02003260#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3261
Takashi Iwaif2e57312010-09-15 10:07:08 +02003262/* fill analog DAC list from the widget tree */
3263static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3264{
3265 hda_nid_t nid, end_nid;
3266 int nums = 0;
3267
3268 end_nid = codec->start_nid + codec->num_nodes;
3269 for (nid = codec->start_nid; nid < end_nid; nid++) {
3270 unsigned int wcaps = get_wcaps(codec, nid);
3271 unsigned int type = get_wcaps_type(wcaps);
3272 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3273 dacs[nums++] = nid;
3274 if (nums >= MAX_AUTO_DACS)
3275 break;
3276 }
3277 }
3278 return nums;
3279}
3280
3281/* fill pin_dac_pair list from the pin and dac list */
3282static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3283 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003284 struct pin_dac_pair *filled, int nums,
3285 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003286{
David Henningsson468c5452011-08-25 13:16:02 +02003287 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003288
David Henningsson468c5452011-08-25 13:16:02 +02003289 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003290 filled[nums].pin = pins[i];
3291 filled[nums].type = type;
3292 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003293 if (filled[nums].dac)
3294 continue;
3295 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3296 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3297 continue;
3298 }
3299 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003300 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003301 continue;
3302 }
3303 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003304 }
3305 return nums;
3306}
3307
3308/* parse analog output paths */
3309static void cx_auto_parse_output(struct hda_codec *codec)
3310{
3311 struct conexant_spec *spec = codec->spec;
3312 struct auto_pin_cfg *cfg = &spec->autocfg;
3313 hda_nid_t dacs[MAX_AUTO_DACS];
3314 int i, j, nums, rest;
3315
3316 rest = fill_cx_auto_dacs(codec, dacs);
3317 /* parse all analog output pins */
3318 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003319 dacs, &rest, spec->dac_info, 0,
3320 AUTO_PIN_LINE_OUT);
3321 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3322 dacs, &rest, spec->dac_info, nums,
3323 AUTO_PIN_HP_OUT);
3324 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3325 dacs, &rest, spec->dac_info, nums,
3326 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003327 spec->dac_info_filled = nums;
3328 /* fill multiout struct */
3329 for (i = 0; i < nums; i++) {
3330 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003331 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003332 continue;
3333 switch (spec->dac_info[i].type) {
3334 case AUTO_PIN_LINE_OUT:
3335 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3336 spec->multiout.num_dacs++;
3337 break;
3338 case AUTO_PIN_HP_OUT:
3339 case AUTO_PIN_SPEAKER_OUT:
3340 if (!spec->multiout.hp_nid) {
3341 spec->multiout.hp_nid = dac;
3342 break;
3343 }
3344 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3345 if (!spec->multiout.extra_out_nid[j]) {
3346 spec->multiout.extra_out_nid[j] = dac;
3347 break;
3348 }
3349 break;
3350 }
3351 }
3352 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003353 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003354
Takashi Iwai03697e22011-05-17 09:53:31 +02003355 for (i = 0; i < cfg->hp_outs; i++) {
3356 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3357 spec->auto_mute = 1;
3358 break;
3359 }
3360 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003361 if (spec->auto_mute &&
3362 cfg->line_out_pins[0] &&
3363 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003364 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3365 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3366 for (i = 0; i < cfg->line_outs; i++) {
3367 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3368 spec->detect_line = 1;
3369 break;
3370 }
3371 }
3372 spec->automute_lines = spec->detect_line;
3373 }
3374
Takashi Iwaif2e57312010-09-15 10:07:08 +02003375 spec->vmaster_nid = spec->private_dac_nids[0];
3376}
3377
Takashi Iwaida339862011-05-13 16:24:15 +02003378static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3379 hda_nid_t *pins, bool on);
3380
Takashi Iwai03697e22011-05-17 09:53:31 +02003381static void do_automute(struct hda_codec *codec, int num_pins,
3382 hda_nid_t *pins, bool on)
3383{
Takashi Iwai254f2962011-10-14 15:22:34 +02003384 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003385 int i;
3386 for (i = 0; i < num_pins; i++)
3387 snd_hda_codec_write(codec, pins[i], 0,
3388 AC_VERB_SET_PIN_WIDGET_CONTROL,
3389 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003390 if (spec->pin_eapd_ctrls)
3391 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003392}
3393
3394static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3395{
3396 int i, present = 0;
3397
3398 for (i = 0; i < num_pins; i++) {
3399 hda_nid_t nid = pins[i];
3400 if (!nid || !is_jack_detectable(codec, nid))
3401 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003402 present |= snd_hda_jack_detect(codec, nid);
3403 }
3404 return present;
3405}
3406
Takashi Iwaif2e57312010-09-15 10:07:08 +02003407/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003408static void cx_auto_update_speakers(struct hda_codec *codec)
3409{
3410 struct conexant_spec *spec = codec->spec;
3411 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003412 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003413
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003414 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003415 if (spec->pin_eapd_ctrls) {
3416 if (spec->auto_mute)
3417 on = spec->hp_present;
3418 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3419 }
3420
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003421 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3422 if (spec->auto_mute)
3423 on = !(spec->hp_present ||
3424 (spec->detect_line && spec->line_present));
3425 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003426
3427 /* toggle line-out mutes if needed, too */
3428 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3429 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3430 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3431 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003432 if (spec->auto_mute) {
3433 /* mute LO in auto-mode when HP jack is present */
3434 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3435 spec->automute_lines)
3436 on = !spec->hp_present;
3437 else
3438 on = 1;
3439 }
3440 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003441}
3442
Takashi Iwaif2e57312010-09-15 10:07:08 +02003443static void cx_auto_hp_automute(struct hda_codec *codec)
3444{
3445 struct conexant_spec *spec = codec->spec;
3446 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003447
3448 if (!spec->auto_mute)
3449 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003450 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3451 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003452}
3453
Takashi Iwai03697e22011-05-17 09:53:31 +02003454static void cx_auto_line_automute(struct hda_codec *codec)
3455{
3456 struct conexant_spec *spec = codec->spec;
3457 struct auto_pin_cfg *cfg = &spec->autocfg;
3458
3459 if (!spec->auto_mute || !spec->detect_line)
3460 return;
3461 spec->line_present = detect_jacks(codec, cfg->line_outs,
3462 cfg->line_out_pins);
3463 cx_auto_update_speakers(codec);
3464}
3465
3466static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3467 struct snd_ctl_elem_info *uinfo)
3468{
3469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3470 struct conexant_spec *spec = codec->spec;
3471 static const char * const texts2[] = {
3472 "Disabled", "Enabled"
3473 };
3474 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003475 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003476 };
3477 const char * const *texts;
3478
3479 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3480 uinfo->count = 1;
3481 if (spec->automute_hp_lo) {
3482 uinfo->value.enumerated.items = 3;
3483 texts = texts3;
3484 } else {
3485 uinfo->value.enumerated.items = 2;
3486 texts = texts2;
3487 }
3488 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3489 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3490 strcpy(uinfo->value.enumerated.name,
3491 texts[uinfo->value.enumerated.item]);
3492 return 0;
3493}
3494
3495static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3496 struct snd_ctl_elem_value *ucontrol)
3497{
3498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3499 struct conexant_spec *spec = codec->spec;
3500 unsigned int val;
3501 if (!spec->auto_mute)
3502 val = 0;
3503 else if (!spec->automute_lines)
3504 val = 1;
3505 else
3506 val = 2;
3507 ucontrol->value.enumerated.item[0] = val;
3508 return 0;
3509}
3510
3511static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3512 struct snd_ctl_elem_value *ucontrol)
3513{
3514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3515 struct conexant_spec *spec = codec->spec;
3516
3517 switch (ucontrol->value.enumerated.item[0]) {
3518 case 0:
3519 if (!spec->auto_mute)
3520 return 0;
3521 spec->auto_mute = 0;
3522 break;
3523 case 1:
3524 if (spec->auto_mute && !spec->automute_lines)
3525 return 0;
3526 spec->auto_mute = 1;
3527 spec->automute_lines = 0;
3528 break;
3529 case 2:
3530 if (!spec->automute_hp_lo)
3531 return -EINVAL;
3532 if (spec->auto_mute && spec->automute_lines)
3533 return 0;
3534 spec->auto_mute = 1;
3535 spec->automute_lines = 1;
3536 break;
3537 default:
3538 return -EINVAL;
3539 }
3540 cx_auto_update_speakers(codec);
3541 return 1;
3542}
3543
3544static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3545 {
3546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3547 .name = "Auto-Mute Mode",
3548 .info = cx_automute_mode_info,
3549 .get = cx_automute_mode_get,
3550 .put = cx_automute_mode_put,
3551 },
3552 { }
3553};
3554
Takashi Iwai6764bce2011-05-13 16:52:25 +02003555static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3556 struct snd_ctl_elem_info *uinfo)
3557{
3558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3559 struct conexant_spec *spec = codec->spec;
3560
3561 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3562}
3563
3564static int cx_auto_mux_enum_get(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 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3571 return 0;
3572}
3573
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003574/* look for the route the given pin from mux and return the index;
3575 * if do_select is set, actually select the route.
3576 */
3577static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003578 hda_nid_t pin, hda_nid_t *srcp,
3579 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003580{
3581 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3582 int i, nums;
3583
Takashi Iwaicf27f292011-05-16 11:33:02 +02003584 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3585 case AC_WID_AUD_IN:
3586 case AC_WID_AUD_SEL:
3587 case AC_WID_AUD_MIX:
3588 break;
3589 default:
3590 return -1;
3591 }
3592
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003593 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3594 for (i = 0; i < nums; i++)
3595 if (conn[i] == pin) {
3596 if (do_select)
3597 snd_hda_codec_write(codec, mux, 0,
3598 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003599 if (srcp)
3600 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003601 return i;
3602 }
3603 depth++;
3604 if (depth == 2)
3605 return -1;
3606 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003607 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003608 do_select, depth);
3609 if (ret >= 0) {
3610 if (do_select)
3611 snd_hda_codec_write(codec, mux, 0,
3612 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003613 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003614 }
3615 }
3616 return -1;
3617}
3618
3619static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3620 hda_nid_t pin)
3621{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003622 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003623}
3624
3625static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3626 hda_nid_t pin)
3627{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003628 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003629}
3630
Takashi Iwai6764bce2011-05-13 16:52:25 +02003631static int cx_auto_mux_enum_update(struct hda_codec *codec,
3632 const struct hda_input_mux *imux,
3633 unsigned int idx)
3634{
3635 struct conexant_spec *spec = codec->spec;
3636 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003637 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003638
3639 if (!imux->num_items)
3640 return 0;
3641 if (idx >= imux->num_items)
3642 idx = imux->num_items - 1;
3643 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003644 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003645 adc = spec->imux_info[idx].adc;
3646 select_input_connection(codec, spec->imux_info[idx].adc,
3647 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003648 if (spec->cur_adc && spec->cur_adc != adc) {
3649 /* stream is running, let's swap the current ADC */
3650 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3651 spec->cur_adc = adc;
3652 snd_hda_codec_setup_stream(codec, adc,
3653 spec->cur_adc_stream_tag, 0,
3654 spec->cur_adc_format);
3655 }
3656 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003657 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003658}
3659
3660static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3661 struct snd_ctl_elem_value *ucontrol)
3662{
3663 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3664 struct conexant_spec *spec = codec->spec;
3665
3666 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3667 ucontrol->value.enumerated.item[0]);
3668}
3669
3670static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3671 {
3672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3673 .name = "Capture Source",
3674 .info = cx_auto_mux_enum_info,
3675 .get = cx_auto_mux_enum_get,
3676 .put = cx_auto_mux_enum_put
3677 },
3678 {}
3679};
3680
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003681static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3682{
3683 struct conexant_spec *spec = codec->spec;
3684 if (idx < 0)
3685 return false;
3686 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3687 return false;
3688 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3689 return true;
3690}
3691
Takashi Iwaif2e57312010-09-15 10:07:08 +02003692/* automatic switch internal and external mic */
3693static void cx_auto_automic(struct hda_codec *codec)
3694{
3695 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003696
3697 if (!spec->auto_mic)
3698 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003699 if (!select_automic(codec, spec->auto_mic_ext, true))
3700 if (!select_automic(codec, spec->auto_mic_dock, true))
3701 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003702}
3703
3704static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3705{
Takashi Iwai3a938972011-10-28 01:16:55 +02003706 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003707 case CONEXANT_HP_EVENT:
3708 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003709 break;
3710 case CONEXANT_LINE_EVENT:
3711 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003712 break;
3713 case CONEXANT_MIC_EVENT:
3714 cx_auto_automic(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003715 break;
3716 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02003717 snd_hda_jack_report_sync(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003718}
3719
Takashi Iwaif2e57312010-09-15 10:07:08 +02003720/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003721 * auto-mic is enabled only when one int-mic and one ext- and/or
3722 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003723 */
3724static void cx_auto_check_auto_mic(struct hda_codec *codec)
3725{
3726 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003727 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3728 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003729
Takashi Iwai506a4192011-05-23 20:07:15 +02003730 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003731 pset[i] = -1;
3732 for (i = 0; i < spec->private_imux.num_items; i++) {
3733 hda_nid_t pin = spec->imux_info[i].pin;
3734 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003735 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003736 attr = snd_hda_get_input_pin_attr(def_conf);
3737 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003738 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003739 if (attr > INPUT_PIN_ATTR_NORMAL)
3740 attr = INPUT_PIN_ATTR_NORMAL;
3741 if (attr != INPUT_PIN_ATTR_INT &&
3742 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003743 return; /* non-detectable pin */
3744 type = get_defcfg_device(def_conf);
3745 if (type != AC_JACK_MIC_IN &&
3746 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3747 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003748 if (pset[attr] >= 0)
3749 return; /* already occupied */
3750 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003751 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003752 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3753 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3754 return; /* no input to switch*/
3755 spec->auto_mic = 1;
3756 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3757 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3758 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003759}
3760
3761static void cx_auto_parse_input(struct hda_codec *codec)
3762{
3763 struct conexant_spec *spec = codec->spec;
3764 struct auto_pin_cfg *cfg = &spec->autocfg;
3765 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003766 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003767
3768 imux = &spec->private_imux;
3769 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003770 for (j = 0; j < spec->num_adc_nids; j++) {
3771 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003772 int idx = get_input_connection(codec, adc,
3773 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003774 if (idx >= 0) {
3775 const char *label;
3776 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003777 spec->imux_info[imux->num_items].index = i;
3778 spec->imux_info[imux->num_items].boost = 0;
3779 spec->imux_info[imux->num_items].adc = adc;
3780 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003781 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003782 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003783 break;
3784 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003785 }
3786 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003787 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003788 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003789 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003790 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003791 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003792 spec->adc_switching = 1;
3793 break;
3794 }
3795 }
3796 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003797}
3798
3799/* get digital-input audio widget corresponding to the given pin */
3800static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3801{
3802 hda_nid_t nid, end_nid;
3803
3804 end_nid = codec->start_nid + codec->num_nodes;
3805 for (nid = codec->start_nid; nid < end_nid; nid++) {
3806 unsigned int wcaps = get_wcaps(codec, nid);
3807 unsigned int type = get_wcaps_type(wcaps);
3808 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3809 if (get_connection_index(codec, nid, pin) >= 0)
3810 return nid;
3811 }
3812 }
3813 return 0;
3814}
3815
3816static void cx_auto_parse_digital(struct hda_codec *codec)
3817{
3818 struct conexant_spec *spec = codec->spec;
3819 struct auto_pin_cfg *cfg = &spec->autocfg;
3820 hda_nid_t nid;
3821
3822 if (cfg->dig_outs &&
3823 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3824 spec->multiout.dig_out_nid = nid;
3825 if (cfg->dig_in_pin)
3826 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3827}
3828
3829#ifdef CONFIG_SND_HDA_INPUT_BEEP
3830static void cx_auto_parse_beep(struct hda_codec *codec)
3831{
3832 struct conexant_spec *spec = codec->spec;
3833 hda_nid_t nid, end_nid;
3834
3835 end_nid = codec->start_nid + codec->num_nodes;
3836 for (nid = codec->start_nid; nid < end_nid; nid++)
3837 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3838 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3839 break;
3840 }
3841}
3842#else
3843#define cx_auto_parse_beep(codec)
3844#endif
3845
Takashi Iwai254f2962011-10-14 15:22:34 +02003846/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003847static void cx_auto_parse_eapd(struct hda_codec *codec)
3848{
3849 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003850 hda_nid_t nid, end_nid;
3851
3852 end_nid = codec->start_nid + codec->num_nodes;
3853 for (nid = codec->start_nid; nid < end_nid; nid++) {
3854 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3855 continue;
3856 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3857 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003858 spec->eapds[spec->num_eapds++] = nid;
3859 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3860 break;
3861 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003862
3863 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3864 * it's a new chip, where EAPDs are supposed to be associated to
3865 * pins, and we can control EAPD per pin.
3866 * OTOH, if only one or two EAPDs are found, it's an old chip,
3867 * thus it might control over all pins.
3868 */
3869 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003870}
3871
Takashi Iwaif2e57312010-09-15 10:07:08 +02003872static int cx_auto_parse_auto_config(struct hda_codec *codec)
3873{
3874 struct conexant_spec *spec = codec->spec;
3875 int err;
3876
3877 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3878 if (err < 0)
3879 return err;
3880
3881 cx_auto_parse_output(codec);
3882 cx_auto_parse_input(codec);
3883 cx_auto_parse_digital(codec);
3884 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003885 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003886 return 0;
3887}
3888
Takashi Iwaida339862011-05-13 16:24:15 +02003889static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3890 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003891{
3892 int i;
3893 for (i = 0; i < num_pins; i++) {
3894 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3895 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003896 AC_VERB_SET_EAPD_BTLENABLE,
3897 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003898 }
3899}
3900
3901static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3902 hda_nid_t src)
3903{
3904 int idx = get_connection_index(codec, pin, src);
3905 if (idx >= 0)
3906 snd_hda_codec_write(codec, pin, 0,
3907 AC_VERB_SET_CONNECT_SEL, idx);
3908}
3909
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003910static void mute_outputs(struct hda_codec *codec, int num_nids,
3911 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003912{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003913 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003914
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003915 for (i = 0; i < num_nids; i++) {
3916 hda_nid_t nid = nids[i];
3917 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3918 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003919 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3920 val = AMP_OUT_MUTE;
3921 else
3922 val = AMP_OUT_ZERO;
3923 snd_hda_codec_write(codec, nid, 0,
3924 AC_VERB_SET_AMP_GAIN_MUTE, val);
3925 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003926}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003927
Takashi Iwai03697e22011-05-17 09:53:31 +02003928static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
Takashi Iwai3a938972011-10-28 01:16:55 +02003929 hda_nid_t *pins, unsigned int action)
Takashi Iwai03697e22011-05-17 09:53:31 +02003930{
3931 int i;
3932 for (i = 0; i < num_pins; i++)
Takashi Iwai3a938972011-10-28 01:16:55 +02003933 snd_hda_jack_detect_enable(codec, pins[i], action);
Takashi Iwai03697e22011-05-17 09:53:31 +02003934}
3935
Takashi Iwai07cafff2012-02-20 12:30:59 +01003936static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3937{
3938 int i;
3939 for (i = 0; i < nums; i++)
3940 if (list[i] == nid)
3941 return true;
3942 return false;
3943}
3944
3945/* is the given NID found in any of autocfg items? */
3946static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3947{
3948 int i;
3949
3950 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3951 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3952 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3953 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3954 return true;
3955 for (i = 0; i < cfg->num_inputs; i++)
3956 if (cfg->inputs[i].pin == nid)
3957 return true;
3958 if (cfg->dig_in_pin == nid)
3959 return true;
3960 return false;
3961}
3962
3963/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3964 * invalid unsol tags by some reason
3965 */
3966static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3967{
3968 struct conexant_spec *spec = codec->spec;
3969 struct auto_pin_cfg *cfg = &spec->autocfg;
3970 int i;
3971
3972 for (i = 0; i < codec->init_pins.used; i++) {
3973 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3974 if (!found_in_autocfg(cfg, pin->nid))
3975 snd_hda_codec_write(codec, pin->nid, 0,
3976 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3977 }
3978}
3979
Takashi Iwai527c73b2012-03-12 12:38:51 +01003980/* turn on/off EAPD according to Master switch */
3981static void cx_auto_vmaster_hook(void *private_data, int enabled)
3982{
3983 struct hda_codec *codec = private_data;
3984 struct conexant_spec *spec = codec->spec;
3985
3986 if (enabled && spec->pin_eapd_ctrls) {
3987 cx_auto_update_speakers(codec);
3988 return;
3989 }
3990 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3991}
3992
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003993static void cx_auto_init_output(struct hda_codec *codec)
3994{
3995 struct conexant_spec *spec = codec->spec;
3996 struct auto_pin_cfg *cfg = &spec->autocfg;
3997 hda_nid_t nid;
3998 int i;
3999
4000 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004001 for (i = 0; i < cfg->hp_outs; i++)
4002 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
4003 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004004 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
4005 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
4006 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004007 for (i = 0; i < spec->dac_info_filled; i++) {
4008 nid = spec->dac_info[i].dac;
4009 if (!nid)
4010 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02004011 else if (nid & DAC_SLAVE_FLAG)
4012 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004013 select_connection(codec, spec->dac_info[i].pin, nid);
4014 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004015 if (spec->auto_mute) {
4016 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
4017 CONEXANT_HP_EVENT);
4018 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4019 cfg->hp_pins);
4020 if (spec->detect_line) {
4021 enable_unsol_pins(codec, cfg->line_outs,
4022 cfg->line_out_pins,
4023 CONEXANT_LINE_EVENT);
4024 spec->line_present =
4025 detect_jacks(codec, cfg->line_outs,
4026 cfg->line_out_pins);
4027 }
4028 }
4029 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02004030 /* turn on all EAPDs if no individual EAPD control is available */
4031 if (!spec->pin_eapd_ctrls)
4032 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01004033 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004034}
4035
4036static void cx_auto_init_input(struct hda_codec *codec)
4037{
4038 struct conexant_spec *spec = codec->spec;
4039 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004040 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004041
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004042 for (i = 0; i < spec->num_adc_nids; i++) {
4043 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004044 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4045 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004046 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4047 val = AMP_IN_MUTE(0);
4048 else
4049 val = AMP_IN_UNMUTE(0);
4050 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4051 val);
4052 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004053
4054 for (i = 0; i < cfg->num_inputs; i++) {
4055 unsigned int type;
4056 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4057 type = PIN_VREF80;
4058 else
4059 type = PIN_IN;
4060 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4061 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4062 }
4063
4064 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004065 if (spec->auto_mic_ext >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004066 snd_hda_jack_detect_enable(codec,
4067 cfg->inputs[spec->auto_mic_ext].pin,
4068 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004069 }
4070 if (spec->auto_mic_dock >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004071 snd_hda_jack_detect_enable(codec,
4072 cfg->inputs[spec->auto_mic_dock].pin,
4073 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004074 }
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{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004097 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004098 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4099 cx_auto_init_output(codec);
4100 cx_auto_init_input(codec);
4101 cx_auto_init_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004102 snd_hda_jack_report_sync(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004103 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004104 return 0;
4105}
4106
David Henningsson983345e2011-02-15 19:57:09 +01004107static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004108 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004109 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004110{
4111 static char name[32];
4112 static struct snd_kcontrol_new knew[] = {
4113 HDA_CODEC_VOLUME(name, 0, 0, 0),
4114 HDA_CODEC_MUTE(name, 0, 0, 0),
4115 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004116 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004117 int i, err;
4118
4119 for (i = 0; i < 2; i++) {
4120 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004121 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4122 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004123 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4124 knew[i].index = cidx;
4125 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4126 kctl = snd_ctl_new1(&knew[i], codec);
4127 if (!kctl)
4128 return -ENOMEM;
4129 err = snd_hda_ctl_add(codec, nid, kctl);
4130 if (err < 0)
4131 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004132 if (!(query_amp_caps(codec, nid, hda_dir) &
4133 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004134 break;
4135 }
4136 return 0;
4137}
4138
David Henningsson983345e2011-02-15 19:57:09 +01004139#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4140 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4141
Takashi Iwaif2e57312010-09-15 10:07:08 +02004142#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4143 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4144
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004145static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4146 hda_nid_t pin, const char *name, int idx)
4147{
4148 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004149 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4150 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4151 if (caps & AC_AMPCAP_NUM_STEPS)
4152 return cx_auto_add_pb_volume(codec, dac, name, idx);
4153 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004154 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4155 if (caps & AC_AMPCAP_NUM_STEPS)
4156 return cx_auto_add_pb_volume(codec, pin, name, idx);
4157 return 0;
4158}
4159
Takashi Iwaif2e57312010-09-15 10:07:08 +02004160static int cx_auto_build_output_controls(struct hda_codec *codec)
4161{
4162 struct conexant_spec *spec = codec->spec;
4163 int i, err;
4164 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004165 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004166
4167 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004168 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4169 spec->dac_info[0].pin,
4170 "Master", 0);
4171
Takashi Iwaif2e57312010-09-15 10:07:08 +02004172 for (i = 0; i < spec->dac_info_filled; i++) {
4173 const char *label;
4174 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004175 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004176 type = spec->dac_info[i].type;
4177 if (type == AUTO_PIN_LINE_OUT)
4178 type = spec->autocfg.line_out_type;
4179 switch (type) {
4180 case AUTO_PIN_LINE_OUT:
4181 default:
4182 label = texts[num_line++];
4183 idx = 0;
4184 break;
4185 case AUTO_PIN_HP_OUT:
4186 label = "Headphone";
4187 idx = num_hp++;
4188 break;
4189 case AUTO_PIN_SPEAKER_OUT:
4190 label = "Speaker";
4191 idx = num_spk++;
4192 break;
4193 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004194 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004195 spec->dac_info[i].pin,
4196 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004197 if (err < 0)
4198 return err;
4199 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004200
4201 if (spec->auto_mute) {
4202 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4203 if (err < 0)
4204 return err;
4205 }
4206
Takashi Iwaif2e57312010-09-15 10:07:08 +02004207 return 0;
4208}
4209
Takashi Iwai6764bce2011-05-13 16:52:25 +02004210static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4211 const char *label, const char *pfx,
4212 int cidx)
4213{
4214 struct conexant_spec *spec = codec->spec;
4215 int i;
4216
4217 for (i = 0; i < spec->num_adc_nids; i++) {
4218 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004219 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004220 if (idx < 0)
4221 continue;
Takashi Iwai6b452142011-10-14 15:26:20 +02004222 if (spec->single_adc_amp)
4223 idx = 0;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004224 return cx_auto_add_volume_idx(codec, label, pfx,
4225 cidx, adc_nid, HDA_INPUT, idx);
4226 }
4227 return 0;
4228}
4229
Takashi Iwaicf27f292011-05-16 11:33:02 +02004230static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4231 const char *label, int cidx)
4232{
4233 struct conexant_spec *spec = codec->spec;
4234 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004235 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004236
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004237 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004238 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4239 return cx_auto_add_volume(codec, label, " Boost", cidx,
4240 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004241 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4242 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004243 if (con < 0)
4244 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004245 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004246 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004247 return 0; /* already present */
4248 }
4249
4250 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004251 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004252 return cx_auto_add_volume(codec, label, " Boost", 0,
4253 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004254 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004255 return 0;
4256}
4257
Takashi Iwaif2e57312010-09-15 10:07:08 +02004258static int cx_auto_build_input_controls(struct hda_codec *codec)
4259{
4260 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004261 struct hda_input_mux *imux = &spec->private_imux;
4262 const char *prev_label;
4263 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004264 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004265 int multi_connection;
4266
Takashi Iwai6b452142011-10-14 15:26:20 +02004267 if (!imux->num_items)
4268 return 0;
4269
Takashi Iwaicf27f292011-05-16 11:33:02 +02004270 multi_connection = 0;
4271 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004272 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4273 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004274 if (cidx < 0)
4275 continue;
4276 input_conn[i] = spec->imux_info[i].adc;
4277 if (!spec->single_adc_amp)
4278 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004279 if (i > 0 && input_conn[i] != input_conn[0])
4280 multi_connection = 1;
4281 }
David Henningsson983345e2011-02-15 19:57:09 +01004282
Takashi Iwaif2e57312010-09-15 10:07:08 +02004283 prev_label = NULL;
4284 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004285 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004286 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004287 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004288
Takashi Iwaicf27f292011-05-16 11:33:02 +02004289 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004290 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004291 if (label == prev_label)
4292 cidx++;
4293 else
4294 cidx = 0;
4295 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004296
Takashi Iwaicf27f292011-05-16 11:33:02 +02004297 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4298 if (err < 0)
4299 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004300
Takashi Iwaicf27f292011-05-16 11:33:02 +02004301 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004302 if (i > 0)
4303 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004304 err = cx_auto_add_capture_volume(codec, nid,
4305 "Capture", "", cidx);
4306 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004307 bool dup_found = false;
4308 for (j = 0; j < i; j++) {
4309 if (input_conn[j] == input_conn[i]) {
4310 dup_found = true;
4311 break;
4312 }
4313 }
4314 if (dup_found)
4315 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004316 err = cx_auto_add_capture_volume(codec, nid,
4317 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004318 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004319 if (err < 0)
4320 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004321 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004322
4323 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4324 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4325 if (err < 0)
4326 return err;
4327 }
4328
Takashi Iwaif2e57312010-09-15 10:07:08 +02004329 return 0;
4330}
4331
4332static int cx_auto_build_controls(struct hda_codec *codec)
4333{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004334 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004335 int err;
4336
4337 err = cx_auto_build_output_controls(codec);
4338 if (err < 0)
4339 return err;
4340 err = cx_auto_build_input_controls(codec);
4341 if (err < 0)
4342 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004343 err = conexant_build_controls(codec);
4344 if (err < 0)
4345 return err;
4346 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4347 if (err < 0)
4348 return err;
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004349 if (spec->vmaster_mute.hook && spec->vmaster_mute.sw_kctl) {
4350 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute);
4351 if (err < 0)
4352 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004353 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004354 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004355}
4356
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004357static int cx_auto_search_adcs(struct hda_codec *codec)
4358{
4359 struct conexant_spec *spec = codec->spec;
4360 hda_nid_t nid, end_nid;
4361
4362 end_nid = codec->start_nid + codec->num_nodes;
4363 for (nid = codec->start_nid; nid < end_nid; nid++) {
4364 unsigned int caps = get_wcaps(codec, nid);
4365 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4366 continue;
4367 if (caps & AC_WCAP_DIGITAL)
4368 continue;
4369 if (snd_BUG_ON(spec->num_adc_nids >=
4370 ARRAY_SIZE(spec->private_adc_nids)))
4371 break;
4372 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4373 }
4374 spec->adc_nids = spec->private_adc_nids;
4375 return 0;
4376}
4377
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004378static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004379 .build_controls = cx_auto_build_controls,
4380 .build_pcms = conexant_build_pcms,
4381 .init = cx_auto_init,
4382 .free = conexant_free,
4383 .unsol_event = cx_auto_unsol_event,
4384#ifdef CONFIG_SND_HDA_POWER_SAVE
4385 .suspend = conexant_suspend,
4386#endif
4387 .reboot_notify = snd_hda_shutup_pins,
4388};
4389
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004390/*
4391 * pin fix-up
4392 */
4393struct cxt_pincfg {
4394 hda_nid_t nid;
4395 u32 val;
4396};
4397
4398static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4399{
4400 for (; cfg->nid; cfg++)
4401 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4402
4403}
4404
4405static void apply_pin_fixup(struct hda_codec *codec,
4406 const struct snd_pci_quirk *quirk,
4407 const struct cxt_pincfg **table)
4408{
4409 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4410 if (quirk) {
4411 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4412 quirk->name);
4413 apply_pincfg(codec, table[quirk->value]);
4414 }
4415}
4416
4417enum {
4418 CXT_PINCFG_LENOVO_X200,
4419};
4420
4421static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4422 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4423 { 0x17, 0x21a11000 }, /* dock-mic */
4424 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004425 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004426 {}
4427};
4428
4429static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4430 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4431};
4432
4433static const struct snd_pci_quirk cxt_fixups[] = {
4434 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4435 {}
4436};
4437
Takashi Iwai38681372012-02-27 15:00:58 +01004438/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4439 * can be created (bko#42825)
4440 */
4441static void add_cx5051_fake_mutes(struct hda_codec *codec)
4442{
4443 static hda_nid_t out_nids[] = {
4444 0x10, 0x11, 0
4445 };
4446 hda_nid_t *p;
4447
4448 for (p = out_nids; *p; p++)
4449 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4450 AC_AMPCAP_MIN_MUTE |
4451 query_amp_caps(codec, *p, HDA_OUTPUT));
4452}
4453
Takashi Iwaif2e57312010-09-15 10:07:08 +02004454static int patch_conexant_auto(struct hda_codec *codec)
4455{
4456 struct conexant_spec *spec;
4457 int err;
4458
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004459 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4460 codec->chip_name);
4461
Takashi Iwaif2e57312010-09-15 10:07:08 +02004462 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4463 if (!spec)
4464 return -ENOMEM;
4465 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004466 codec->pin_amp_workaround = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004467
Takashi Iwai6b452142011-10-14 15:26:20 +02004468 switch (codec->vendor_id) {
4469 case 0x14f15045:
4470 spec->single_adc_amp = 1;
4471 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004472 case 0x14f15051:
4473 add_cx5051_fake_mutes(codec);
4474 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02004475 }
4476
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004477 apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
4478
Takashi Iwai527c73b2012-03-12 12:38:51 +01004479 /* add EAPD vmaster hook to all HP machines */
4480 /* NOTE: this should be applied via fixup once when the generic
4481 * fixup code is merged to hda_codec.c
4482 */
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004483 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004484
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004485 err = cx_auto_search_adcs(codec);
4486 if (err < 0)
4487 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004488 err = cx_auto_parse_auto_config(codec);
4489 if (err < 0) {
4490 kfree(codec->spec);
4491 codec->spec = NULL;
4492 return err;
4493 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004494 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004495 codec->patch_ops = cx_auto_patch_ops;
4496 if (spec->beep_amp)
4497 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004498
4499 /* Some laptops with Conexant chips show stalls in S3 resume,
4500 * which falls into the single-cmd mode.
4501 * Better to make reset, then.
4502 */
4503 if (!codec->bus->sync_write) {
4504 snd_printd("hda_codec: "
4505 "Enable sync_write for stable communication\n");
4506 codec->bus->sync_write = 1;
4507 codec->bus->allow_bus_reset = 1;
4508 }
4509
Takashi Iwaif2e57312010-09-15 10:07:08 +02004510 return 0;
4511}
4512
4513/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004514 */
4515
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004516static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004517 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4518 .patch = patch_cxt5045 },
4519 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4520 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004521 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4522 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004523 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4524 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004525 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4526 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004527 { .id = 0x14f15068, .name = "CX20584",
4528 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004529 { .id = 0x14f15069, .name = "CX20585",
4530 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004531 { .id = 0x14f1506c, .name = "CX20588",
4532 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004533 { .id = 0x14f1506e, .name = "CX20590",
4534 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004535 { .id = 0x14f15097, .name = "CX20631",
4536 .patch = patch_conexant_auto },
4537 { .id = 0x14f15098, .name = "CX20632",
4538 .patch = patch_conexant_auto },
4539 { .id = 0x14f150a1, .name = "CX20641",
4540 .patch = patch_conexant_auto },
4541 { .id = 0x14f150a2, .name = "CX20642",
4542 .patch = patch_conexant_auto },
4543 { .id = 0x14f150ab, .name = "CX20651",
4544 .patch = patch_conexant_auto },
4545 { .id = 0x14f150ac, .name = "CX20652",
4546 .patch = patch_conexant_auto },
4547 { .id = 0x14f150b8, .name = "CX20664",
4548 .patch = patch_conexant_auto },
4549 { .id = 0x14f150b9, .name = "CX20665",
4550 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004551 {} /* terminator */
4552};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004553
4554MODULE_ALIAS("snd-hda-codec-id:14f15045");
4555MODULE_ALIAS("snd-hda-codec-id:14f15047");
4556MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004557MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004558MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004559MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004560MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004561MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004562MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004563MODULE_ALIAS("snd-hda-codec-id:14f15097");
4564MODULE_ALIAS("snd-hda-codec-id:14f15098");
4565MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4566MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4567MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4568MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4569MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4570MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004571
4572MODULE_LICENSE("GPL");
4573MODULE_DESCRIPTION("Conexant HD-audio codec");
4574
4575static struct hda_codec_preset_list conexant_list = {
4576 .preset = snd_hda_preset_conexant,
4577 .owner = THIS_MODULE,
4578};
4579
4580static int __init patch_conexant_init(void)
4581{
4582 return snd_hda_add_codec_preset(&conexant_list);
4583}
4584
4585static void __exit patch_conexant_exit(void)
4586{
4587 snd_hda_delete_codec_preset(&conexant_list);
4588}
4589
4590module_init(patch_conexant_init)
4591module_exit(patch_conexant_exit)