blob: 4b365488c58bf7098e8a4d131ecb5573b192b915 [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;
Takashi Iwaif29735c2012-03-13 07:55:10 +010074 bool vmaster_mute_led;
Tobin Davisc9b443d2006-11-14 12:13:39 +010075
76 const struct hda_verb *init_verbs[5]; /* initialization verbs
77 * don't forget NULL
78 * termination!
79 */
80 unsigned int num_init_verbs;
81
82 /* playback */
83 struct hda_multi_out multiout; /* playback set-up
84 * max_channels, dacs must be set
85 * dig_out_nid and hp_nid are optional
86 */
87 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010088 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020089 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010090 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020091 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020092 int auto_mic_dock; /* imux_pins[] index for dock mic */
93 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010094 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050095 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010096
97 /* capture */
98 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020099 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100100 hda_nid_t dig_in_nid; /* digital-in NID; optional */
101
Takashi Iwai461e2c72008-01-25 11:35:17 +0100102 unsigned int cur_adc_idx;
103 hda_nid_t cur_adc;
104 unsigned int cur_adc_stream_tag;
105 unsigned int cur_adc_format;
106
Takashi Iwai6764bce2011-05-13 16:52:25 +0200107 const struct hda_pcm_stream *capture_stream;
108
Tobin Davisc9b443d2006-11-14 12:13:39 +0100109 /* capture source */
110 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200111 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100112 unsigned int cur_mux[3];
113
114 /* channel model */
115 const struct hda_channel_mode *channel_mode;
116 int num_channel_mode;
117
118 /* PCM information */
119 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
120
Tobin Davisc9b443d2006-11-14 12:13:39 +0100121 unsigned int spdif_route;
122
123 /* dynamic controls, init_verbs and input_mux */
124 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100125 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200126 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200127 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200128 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200129 struct pin_dac_pair dac_info[8];
130 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100131
Daniel Drake0fb67e92009-07-16 14:46:57 +0100132 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200133 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200134 unsigned int detect_line:1; /* Line-out detection enabled */
135 unsigned int automute_lines:1; /* automute line-out as well */
136 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200137 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500138 unsigned int dell_vostro:1;
139 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200140 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200141 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100142 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200143 unsigned int pin_eapd_ctrls: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 = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200689 { "Internal Mic", 0x1 },
690 { "Mic", 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 = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200695 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100696 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200697 { "Internal Mic", 0x1 },
698 { "Mic", 0x2 },
699 { "Line", 0x3 },
700 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100701 }
702};
703
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200704static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100705 .num_items = 2,
706 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200707 { "Mic", 0x1 },
708 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100709 }
710};
711
Tobin Davisc9b443d2006-11-14 12:13:39 +0100712/* turn on/off EAPD (+ mute HP) as a master switch */
713static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
714 struct snd_ctl_elem_value *ucontrol)
715{
716 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
717 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100718 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100719
Tobin Davis82f30042007-02-13 12:45:44 +0100720 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100721 return 0;
722
Tobin Davis82f30042007-02-13 12:45:44 +0100723 /* toggle internal speakers mute depending of presence of
724 * the headphone jack
725 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200726 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
727 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
728 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100729
Takashi Iwai47fd8302007-08-10 17:11:07 +0200730 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
731 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
732 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100733 return 1;
734}
735
736/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200737static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200738 .ops = &snd_hda_bind_vol,
739 .values = {
740 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
741 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
742 0
743 },
744};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100745
Tobin Davis7f296732007-03-12 11:39:01 +0100746/* toggle input of built-in and mic jack appropriately */
747static void cxt5045_hp_automic(struct hda_codec *codec)
748{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200749 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100750 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
751 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
752 {}
753 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200754 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100755 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
757 {}
758 };
759 unsigned int present;
760
Takashi Iwaid56757a2009-11-18 08:00:14 +0100761 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100762 if (present)
763 snd_hda_sequence_write(codec, mic_jack_on);
764 else
765 snd_hda_sequence_write(codec, mic_jack_off);
766}
767
Tobin Davisc9b443d2006-11-14 12:13:39 +0100768
769/* mute internal speaker if HP is plugged */
770static void cxt5045_hp_automute(struct hda_codec *codec)
771{
Tobin Davis82f30042007-02-13 12:45:44 +0100772 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100773 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100774
Takashi Iwaid56757a2009-11-18 08:00:14 +0100775 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100776
Takashi Iwai47fd8302007-08-10 17:11:07 +0200777 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
778 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
779 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100780}
781
782/* unsolicited event for HP jack sensing */
783static void cxt5045_hp_unsol_event(struct hda_codec *codec,
784 unsigned int res)
785{
786 res >>= 26;
787 switch (res) {
788 case CONEXANT_HP_EVENT:
789 cxt5045_hp_automute(codec);
790 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100791 case CONEXANT_MIC_EVENT:
792 cxt5045_hp_automic(codec);
793 break;
794
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795 }
796}
797
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200798static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200799 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
800 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200801 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
802 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100803 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
804 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100805 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
806 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200807 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100808 {
809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
810 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100811 .info = cxt_eapd_info,
812 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100813 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100814 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100815 },
816
817 {}
818};
819
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200820static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200821 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
822 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Jiang Zhe5218c892008-01-17 11:18:41 +0100823
824 {}
825};
826
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200827static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200828 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
829 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100830 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
831 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100832 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
833 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100834 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
835 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100836 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
837 {
838 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
839 .name = "Master Playback Switch",
840 .info = cxt_eapd_info,
841 .get = cxt_eapd_get,
842 .put = cxt5045_hp_master_sw_put,
843 .private_value = 0x10,
844 },
845
846 {}
847};
848
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200849static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100850 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200851 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100852 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100853 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200854 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
855 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
856 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
857 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
859 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
860 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
861 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100863 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100864 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100865 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100866 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
867 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100868 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100869 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100870 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100871 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100872 { } /* end */
873};
874
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200875static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100876 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100877 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
878 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
879 /* Line In,HP, Amp */
880 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
881 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
882 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
883 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
884 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
885 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
886 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100889 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100890 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
891 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
892 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
893 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100894 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100895 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
896 /* EAPD */
897 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
898 { } /* end */
899};
Tobin Davis7f296732007-03-12 11:39:01 +0100900
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200901static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100902 /* pin sensing on HP jack */
903 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200904 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100905};
906
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200907static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100908 /* pin sensing on HP jack */
909 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200910 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100911};
912
Tobin Davisc9b443d2006-11-14 12:13:39 +0100913#ifdef CONFIG_SND_DEBUG
914/* Test configuration for debugging, modelled after the ALC260 test
915 * configuration.
916 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200917static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100918 .num_items = 5,
919 .items = {
920 { "MIXER", 0x0 },
921 { "MIC1 pin", 0x1 },
922 { "LINE1 pin", 0x2 },
923 { "HP-OUT pin", 0x3 },
924 { "CD pin", 0x4 },
925 },
926};
927
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200928static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929
930 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100931 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
932 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100933 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
934 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
935 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
936 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100937
938 /* Modes for retasking pin widgets */
939 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
940 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
941
Tobin Davis82f30042007-02-13 12:45:44 +0100942 /* EAPD Switch Control */
943 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
944
Tobin Davisc9b443d2006-11-14 12:13:39 +0100945 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946
Tobin Davis7f296732007-03-12 11:39:01 +0100947 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
948 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
949 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
950 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
951 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
952 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
953 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
954 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
955 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
956 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100957 {
958 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
959 .name = "Input Source",
960 .info = conexant_mux_enum_info,
961 .get = conexant_mux_enum_get,
962 .put = conexant_mux_enum_put,
963 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200964 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200965 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
966 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100967 { } /* end */
968};
969
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200970static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100971 /* Set connections */
972 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
973 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
974 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100975 /* Enable retasking pins as output, initially without power amp */
976 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100977 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100978
979 /* Disable digital (SPDIF) pins initially, but users can enable
980 * them via a mixer switch. In the case of SPDIF-out, this initverb
981 * payload also sets the generation to 0, output to be in "consumer"
982 * PCM format, copyright asserted, no pre-emphasis and no validity
983 * control.
984 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100985 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
986 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100987
988 /* Start with output sum widgets muted and their output gains at min */
989 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
990 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
991
992 /* Unmute retasking pin widget output buffers since the default
993 * state appears to be output. As the pin mode is changed by the
994 * user the pin mode control will take care of enabling the pin's
995 * input/output buffers as needed.
996 */
997 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
998 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
999
1000 /* Mute capture amp left and right */
1001 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1002
1003 /* Set ADC connection select to match default mixer setting (mic1
1004 * pin)
1005 */
1006 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001007 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001008
1009 /* Mute all inputs to mixer widget (even unconnected ones) */
1010 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1011 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1012 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1013 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1014 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1015
1016 { }
1017};
1018#endif
1019
1020
1021/* initialize jack-sensing, too */
1022static int cxt5045_init(struct hda_codec *codec)
1023{
1024 conexant_init(codec);
1025 cxt5045_hp_automute(codec);
1026 return 0;
1027}
1028
1029
1030enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001031 CXT5045_LAPTOP_HPSENSE,
1032 CXT5045_LAPTOP_MICSENSE,
1033 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001034 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001035 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001036#ifdef CONFIG_SND_DEBUG
1037 CXT5045_TEST,
1038#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001039 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001040 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001041};
1042
Takashi Iwaiea734962011-01-17 11:29:34 +01001043static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001044 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1045 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1046 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1047 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001048 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001049#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001050 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001051#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001052 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001053};
1054
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001055static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001056 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001057 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001058 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001059 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1060 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001061 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1062 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001063 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1064 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1065 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001066 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1067 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001068 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001069 {}
1070};
1071
1072static int patch_cxt5045(struct hda_codec *codec)
1073{
1074 struct conexant_spec *spec;
1075 int board_config;
1076
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001077 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1078 cxt5045_models,
1079 cxt5045_cfg_tbl);
1080 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001081 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001082 if (board_config == CXT5045_AUTO)
1083 return patch_conexant_auto(codec);
1084
Tobin Davisc9b443d2006-11-14 12:13:39 +01001085 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1086 if (!spec)
1087 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001088 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001089 codec->pin_amp_workaround = 1;
Michael Karcher4f324562012-04-06 15:34:15 +02001090 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001091
1092 spec->multiout.max_channels = 2;
1093 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1094 spec->multiout.dac_nids = cxt5045_dac_nids;
1095 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1096 spec->num_adc_nids = 1;
1097 spec->adc_nids = cxt5045_adc_nids;
1098 spec->capsrc_nids = cxt5045_capsrc_nids;
1099 spec->input_mux = &cxt5045_capture_source;
1100 spec->num_mixers = 1;
1101 spec->mixers[0] = cxt5045_mixers;
1102 spec->num_init_verbs = 1;
1103 spec->init_verbs[0] = cxt5045_init_verbs;
1104 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001105 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1106 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001107
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001108 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001109
1110 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111
Tobin Davisc9b443d2006-11-14 12:13:39 +01001112 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001113 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001114 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001115 spec->input_mux = &cxt5045_capture_source;
1116 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001117 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1118 spec->mixers[0] = cxt5045_mixers;
1119 codec->patch_ops.init = cxt5045_init;
1120 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001121 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001122 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001123 spec->input_mux = &cxt5045_capture_source;
1124 spec->num_init_verbs = 2;
1125 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001126 spec->mixers[0] = cxt5045_mixers;
1127 codec->patch_ops.init = cxt5045_init;
1128 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001129 default:
1130 case CXT5045_LAPTOP_HPMICSENSE:
1131 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1132 spec->input_mux = &cxt5045_capture_source;
1133 spec->num_init_verbs = 3;
1134 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1135 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1136 spec->mixers[0] = cxt5045_mixers;
1137 codec->patch_ops.init = cxt5045_init;
1138 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001139 case CXT5045_BENQ:
1140 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1141 spec->input_mux = &cxt5045_capture_source_benq;
1142 spec->num_init_verbs = 1;
1143 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1144 spec->mixers[0] = cxt5045_mixers;
1145 spec->mixers[1] = cxt5045_benq_mixers;
1146 spec->num_mixers = 2;
1147 codec->patch_ops.init = cxt5045_init;
1148 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001149 case CXT5045_LAPTOP_HP530:
1150 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1151 spec->input_mux = &cxt5045_capture_source_hp530;
1152 spec->num_init_verbs = 2;
1153 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1154 spec->mixers[0] = cxt5045_mixers_hp530;
1155 codec->patch_ops.init = cxt5045_init;
1156 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157#ifdef CONFIG_SND_DEBUG
1158 case CXT5045_TEST:
1159 spec->input_mux = &cxt5045_test_capture_source;
1160 spec->mixers[0] = cxt5045_test_mixer;
1161 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001162 break;
1163
Tobin Davisc9b443d2006-11-14 12:13:39 +01001164#endif
1165 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001166
Takashi Iwai031005f2008-06-26 14:49:58 +02001167 switch (codec->subsystem_id >> 16) {
1168 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001169 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001170 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001171 case 0x17aa:
1172 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1173 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1174 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001175 */
1176 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1177 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1178 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1179 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1180 (1 << AC_AMPCAP_MUTE_SHIFT));
1181 break;
1182 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001183
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001184 if (spec->beep_amp)
1185 snd_hda_attach_beep_device(codec, spec->beep_amp);
1186
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187 return 0;
1188}
1189
1190
1191/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001192#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001194static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1195static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1196static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001198static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001199 { 2, NULL },
1200};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001202static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001203 .num_items = 2,
1204 .items = {
1205 { "ExtMic", 0x2 },
1206 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207 }
1208};
1209
1210/* turn on/off EAPD (+ mute HP) as a master switch */
1211static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1212 struct snd_ctl_elem_value *ucontrol)
1213{
1214 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1215 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001216 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217
Tobin Davis82f30042007-02-13 12:45:44 +01001218 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001219 return 0;
1220
Tobin Davis82f30042007-02-13 12:45:44 +01001221 /* toggle internal speakers mute depending of presence of
1222 * the headphone jack
1223 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001224 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001225 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1226 * pin widgets unlike other codecs. In this case, we need to
1227 * set index 0x01 for the volume from the mixer amp 0x19.
1228 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001229 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001230 HDA_AMP_MUTE, bits);
1231 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1232 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1233 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 return 1;
1235}
1236
Tobin Davisc9b443d2006-11-14 12:13:39 +01001237/* mute internal speaker if HP is plugged */
1238static void cxt5047_hp_automute(struct hda_codec *codec)
1239{
Tobin Davis82f30042007-02-13 12:45:44 +01001240 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001241 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242
Takashi Iwaid56757a2009-11-18 08:00:14 +01001243 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001244
Takashi Iwai47fd8302007-08-10 17:11:07 +02001245 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001246 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001247 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001248 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001249}
1250
1251/* toggle input of built-in and mic jack appropriately */
1252static void cxt5047_hp_automic(struct hda_codec *codec)
1253{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001254 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001255 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1256 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257 {}
1258 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001259 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001260 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1261 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 {}
1263 };
1264 unsigned int present;
1265
Takashi Iwaid56757a2009-11-18 08:00:14 +01001266 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267 if (present)
1268 snd_hda_sequence_write(codec, mic_jack_on);
1269 else
1270 snd_hda_sequence_write(codec, mic_jack_off);
1271}
1272
1273/* unsolicited event for HP jack sensing */
1274static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1275 unsigned int res)
1276{
Marc Boucher9f113e02008-01-22 15:18:08 +01001277 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001278 case CONEXANT_HP_EVENT:
1279 cxt5047_hp_automute(codec);
1280 break;
1281 case CONEXANT_MIC_EVENT:
1282 cxt5047_hp_automic(codec);
1283 break;
1284 }
1285}
1286
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001287static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001288 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1289 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001290 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1292 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1293 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001295 {
1296 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1297 .name = "Master Playback Switch",
1298 .info = cxt_eapd_info,
1299 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 .put = cxt5047_hp_master_sw_put,
1301 .private_value = 0x13,
1302 },
1303
1304 {}
1305};
1306
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001307static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001308 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001309 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001310 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1311 {}
1312};
1313
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001314static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316 { } /* end */
1317};
1318
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001319static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001320 /* Line in, Mic, Built-in Mic */
1321 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1322 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1323 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001324 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001325 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001326 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1327 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001328 /* Record selector: Mic */
1329 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1330 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1331 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1332 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001333 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1334 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1335 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1336 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001337 /* SPDIF route: PCM */
1338 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001339 /* Enable unsolicited events */
1340 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1341 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 { } /* end */
1343};
1344
1345/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001346static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001347 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001348 {}
1349};
1350
1351/* Test configuration for debugging, modelled after the ALC260 test
1352 * configuration.
1353 */
1354#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001355static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001356 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001358 { "LINE1 pin", 0x0 },
1359 { "MIC1 pin", 0x1 },
1360 { "MIC2 pin", 0x2 },
1361 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 },
1363};
1364
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001365static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366
1367 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001368 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1375 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001376 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1377 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1378 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001380
1381 /* Modes for retasking pin widgets */
1382 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1383 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1384
Tobin Davis82f30042007-02-13 12:45:44 +01001385 /* EAPD Switch Control */
1386 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1387
Tobin Davisc9b443d2006-11-14 12:13:39 +01001388 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001389 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1390 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1391 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1392 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1393 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1394 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1395 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1396 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001397
Tobin Davis82f30042007-02-13 12:45:44 +01001398 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1399 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1400 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1401 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1402 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1403 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1404 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1405 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001406 {
1407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1408 .name = "Input Source",
1409 .info = conexant_mux_enum_info,
1410 .get = conexant_mux_enum_get,
1411 .put = conexant_mux_enum_put,
1412 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001413 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001414
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 { } /* end */
1416};
1417
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001418static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419 /* Enable retasking pins as output, initially without power amp */
1420 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1421 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1422 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1423
1424 /* Disable digital (SPDIF) pins initially, but users can enable
1425 * them via a mixer switch. In the case of SPDIF-out, this initverb
1426 * payload also sets the generation to 0, output to be in "consumer"
1427 * PCM format, copyright asserted, no pre-emphasis and no validity
1428 * control.
1429 */
1430 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1431
1432 /* Ensure mic1, mic2, line1 pin widgets take input from the
1433 * OUT1 sum bus when acting as an output.
1434 */
1435 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1436 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1437
1438 /* Start with output sum widgets muted and their output gains at min */
1439 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1440 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1441
1442 /* Unmute retasking pin widget output buffers since the default
1443 * state appears to be output. As the pin mode is changed by the
1444 * user the pin mode control will take care of enabling the pin's
1445 * input/output buffers as needed.
1446 */
1447 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1448 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1449 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1450
1451 /* Mute capture amp left and right */
1452 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1453
1454 /* Set ADC connection select to match default mixer setting (mic1
1455 * pin)
1456 */
1457 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1458
1459 /* Mute all inputs to mixer widget (even unconnected ones) */
1460 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1461 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1462 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1468
1469 { }
1470};
1471#endif
1472
1473
1474/* initialize jack-sensing, too */
1475static int cxt5047_hp_init(struct hda_codec *codec)
1476{
1477 conexant_init(codec);
1478 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001479 return 0;
1480}
1481
1482
1483enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001484 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1485 CXT5047_LAPTOP_HP, /* Some HP laptops */
1486 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001487#ifdef CONFIG_SND_DEBUG
1488 CXT5047_TEST,
1489#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001490 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001491 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001492};
1493
Takashi Iwaiea734962011-01-17 11:29:34 +01001494static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001495 [CXT5047_LAPTOP] = "laptop",
1496 [CXT5047_LAPTOP_HP] = "laptop-hp",
1497 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001498#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001499 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001500#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001501 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001502};
1503
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001504static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001505 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001506 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1507 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001508 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509 {}
1510};
1511
1512static int patch_cxt5047(struct hda_codec *codec)
1513{
1514 struct conexant_spec *spec;
1515 int board_config;
1516
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001517 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1518 cxt5047_models,
1519 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001520 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001521 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001522 if (board_config == CXT5047_AUTO)
1523 return patch_conexant_auto(codec);
1524
Tobin Davisc9b443d2006-11-14 12:13:39 +01001525 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1526 if (!spec)
1527 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001528 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001529 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001530
1531 spec->multiout.max_channels = 2;
1532 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1533 spec->multiout.dac_nids = cxt5047_dac_nids;
1534 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1535 spec->num_adc_nids = 1;
1536 spec->adc_nids = cxt5047_adc_nids;
1537 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001539 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001540 spec->num_init_verbs = 1;
1541 spec->init_verbs[0] = cxt5047_init_verbs;
1542 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001543 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1544 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545
1546 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001547
Tobin Davisc9b443d2006-11-14 12:13:39 +01001548 switch (board_config) {
1549 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001550 spec->num_mixers = 2;
1551 spec->mixers[1] = cxt5047_hp_spk_mixers;
1552 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553 break;
1554 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001555 spec->num_mixers = 2;
1556 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001557 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558 codec->patch_ops.init = cxt5047_hp_init;
1559 break;
1560 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001561 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001562 spec->num_mixers = 2;
1563 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001564 spec->num_init_verbs = 2;
1565 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001566 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001567 break;
1568#ifdef CONFIG_SND_DEBUG
1569 case CXT5047_TEST:
1570 spec->input_mux = &cxt5047_test_capture_source;
1571 spec->mixers[0] = cxt5047_test_mixer;
1572 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001573 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001574#endif
1575 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001576 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001577
1578 switch (codec->subsystem_id >> 16) {
1579 case 0x103c:
1580 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1581 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1582 * with 0 dB offset 0x17)
1583 */
1584 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1585 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1586 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1587 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1588 (1 << AC_AMPCAP_MUTE_SHIFT));
1589 break;
1590 }
1591
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592 return 0;
1593}
1594
Takashi Iwai461e2c72008-01-25 11:35:17 +01001595/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001596static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1597static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001598
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001599static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001600 { 2, NULL },
1601};
1602
1603static void cxt5051_update_speaker(struct hda_codec *codec)
1604{
1605 struct conexant_spec *spec = codec->spec;
1606 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001607 /* headphone pin */
1608 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1609 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1610 pinctl);
1611 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001612 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1613 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1614 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001615 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1616 if (spec->ideapad)
1617 snd_hda_codec_write(codec, 0x1b, 0,
1618 AC_VERB_SET_PIN_WIDGET_CONTROL,
1619 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001620}
1621
1622/* turn on/off EAPD (+ mute HP) as a master switch */
1623static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1625{
1626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1627
1628 if (!cxt_eapd_put(kcontrol, ucontrol))
1629 return 0;
1630 cxt5051_update_speaker(codec);
1631 return 1;
1632}
1633
1634/* toggle input of built-in and mic jack appropriately */
1635static void cxt5051_portb_automic(struct hda_codec *codec)
1636{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001637 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001638 unsigned int present;
1639
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001640 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001641 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001642 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001643 snd_hda_codec_write(codec, 0x14, 0,
1644 AC_VERB_SET_CONNECT_SEL,
1645 present ? 0x01 : 0x00);
1646}
1647
1648/* switch the current ADC according to the jack state */
1649static void cxt5051_portc_automic(struct hda_codec *codec)
1650{
1651 struct conexant_spec *spec = codec->spec;
1652 unsigned int present;
1653 hda_nid_t new_adc;
1654
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001655 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001656 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001657 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001658 if (present)
1659 spec->cur_adc_idx = 1;
1660 else
1661 spec->cur_adc_idx = 0;
1662 new_adc = spec->adc_nids[spec->cur_adc_idx];
1663 if (spec->cur_adc && spec->cur_adc != new_adc) {
1664 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001665 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001666 spec->cur_adc = new_adc;
1667 snd_hda_codec_setup_stream(codec, new_adc,
1668 spec->cur_adc_stream_tag, 0,
1669 spec->cur_adc_format);
1670 }
1671}
1672
1673/* mute internal speaker if HP is plugged */
1674static void cxt5051_hp_automute(struct hda_codec *codec)
1675{
1676 struct conexant_spec *spec = codec->spec;
1677
Takashi Iwaid56757a2009-11-18 08:00:14 +01001678 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679 cxt5051_update_speaker(codec);
1680}
1681
1682/* unsolicited event for HP jack sensing */
1683static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1684 unsigned int res)
1685{
1686 switch (res >> 26) {
1687 case CONEXANT_HP_EVENT:
1688 cxt5051_hp_automute(codec);
1689 break;
1690 case CXT5051_PORTB_EVENT:
1691 cxt5051_portb_automic(codec);
1692 break;
1693 case CXT5051_PORTC_EVENT:
1694 cxt5051_portc_automic(codec);
1695 break;
1696 }
1697}
1698
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001699static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001700 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1701 {
1702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1703 .name = "Master Playback Switch",
1704 .info = cxt_eapd_info,
1705 .get = cxt_eapd_get,
1706 .put = cxt5051_hp_master_sw_put,
1707 .private_value = 0x1a,
1708 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001709 {}
1710};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001711
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001712static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001713 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1714 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001715 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1716 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001717 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1718 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 {}
1720};
1721
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001722static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1724 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001725 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1726 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001727 {}
1728};
1729
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001730static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001731 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1732 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001733 {}
1734};
1735
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001736static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001737 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1738 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001739 {}
1740};
1741
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001742static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001743 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1744 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001745 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1746 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001747 {}
1748};
1749
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001750static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001751 /* Line in, Mic */
1752 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1753 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1754 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1755 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1756 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1757 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1758 /* SPK */
1759 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1760 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1761 /* HP, Amp */
1762 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1763 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1764 /* DAC1 */
1765 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001766 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001767 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1769 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1770 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001771 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001772 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1773 /* EAPD */
1774 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1775 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001776 { } /* end */
1777};
1778
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001779static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001780 /* Line in, Mic */
1781 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1782 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1783 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1784 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1785 /* SPK */
1786 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1787 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1788 /* HP, Amp */
1789 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1790 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1791 /* DAC1 */
1792 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001793 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1795 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1796 /* SPDIF route: PCM */
1797 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1798 /* EAPD */
1799 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1800 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001801 { } /* end */
1802};
1803
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001804static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001805 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001806 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001807 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1808 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1809 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1810 /* SPK */
1811 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1812 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1813 /* HP, Amp */
1814 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1815 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1816 /* DAC1 */
1817 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001818 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1820 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1821 /* SPDIF route: PCM */
1822 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1823 /* EAPD */
1824 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1825 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001826 { } /* end */
1827};
1828
Takashi Iwai6953e552010-01-24 11:00:27 +01001829static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1830 unsigned int event)
1831{
1832 snd_hda_codec_write(codec, nid, 0,
1833 AC_VERB_SET_UNSOLICITED_ENABLE,
1834 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001835}
1836
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001837static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001838 /* Subwoofer */
1839 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1840 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1841 { } /* end */
1842};
1843
Takashi Iwai461e2c72008-01-25 11:35:17 +01001844/* initialize jack-sensing, too */
1845static int cxt5051_init(struct hda_codec *codec)
1846{
Takashi Iwai6953e552010-01-24 11:00:27 +01001847 struct conexant_spec *spec = codec->spec;
1848
Takashi Iwai461e2c72008-01-25 11:35:17 +01001849 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001850
1851 if (spec->auto_mic & AUTO_MIC_PORTB)
1852 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1853 if (spec->auto_mic & AUTO_MIC_PORTC)
1854 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1855
Takashi Iwai461e2c72008-01-25 11:35:17 +01001856 if (codec->patch_ops.unsol_event) {
1857 cxt5051_hp_automute(codec);
1858 cxt5051_portb_automic(codec);
1859 cxt5051_portc_automic(codec);
1860 }
1861 return 0;
1862}
1863
1864
1865enum {
1866 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1867 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001868 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001869 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001870 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001871 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001872 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001873 CXT5051_MODELS
1874};
1875
Takashi Iwaiea734962011-01-17 11:29:34 +01001876static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001877 [CXT5051_LAPTOP] = "laptop",
1878 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001879 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001880 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001881 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001882 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001883 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001884};
1885
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001886static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001887 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001888 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001889 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001890 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001891 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1892 CXT5051_LAPTOP),
1893 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001894 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001895 {}
1896};
1897
1898static int patch_cxt5051(struct hda_codec *codec)
1899{
1900 struct conexant_spec *spec;
1901 int board_config;
1902
Takashi Iwai6764bce2011-05-13 16:52:25 +02001903 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1904 cxt5051_models,
1905 cxt5051_cfg_tbl);
1906 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001907 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001908 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001909 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001910
Takashi Iwai461e2c72008-01-25 11:35:17 +01001911 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1912 if (!spec)
1913 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001914 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001915 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001916
1917 codec->patch_ops = conexant_patch_ops;
1918 codec->patch_ops.init = cxt5051_init;
1919
1920 spec->multiout.max_channels = 2;
1921 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1922 spec->multiout.dac_nids = cxt5051_dac_nids;
1923 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1924 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1925 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001926 spec->num_mixers = 2;
1927 spec->mixers[0] = cxt5051_capture_mixers;
1928 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001929 spec->num_init_verbs = 1;
1930 spec->init_verbs[0] = cxt5051_init_verbs;
1931 spec->spdif_route = 0;
1932 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1933 spec->channel_mode = cxt5051_modes;
1934 spec->cur_adc = 0;
1935 spec->cur_adc_idx = 0;
1936
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001937 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1938
Takashi Iwai79d7d532009-03-04 09:03:50 +01001939 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1940
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001941 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001942 switch (board_config) {
1943 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001944 spec->mixers[0] = cxt5051_hp_mixers;
1945 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001946 case CXT5051_HP_DV6736:
1947 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1948 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001949 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001950 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001951 case CXT5051_F700:
1952 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1953 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001954 spec->auto_mic = 0;
1955 break;
1956 case CXT5051_TOSHIBA:
1957 spec->mixers[0] = cxt5051_toshiba_mixers;
1958 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001959 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001960 case CXT5051_IDEAPAD:
1961 spec->init_verbs[spec->num_init_verbs++] =
1962 cxt5051_ideapad_init_verbs;
1963 spec->ideapad = 1;
1964 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001965 }
1966
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001967 if (spec->beep_amp)
1968 snd_hda_attach_beep_device(codec, spec->beep_amp);
1969
Takashi Iwai461e2c72008-01-25 11:35:17 +01001970 return 0;
1971}
1972
Daniel Drake0fb67e92009-07-16 14:46:57 +01001973/* Conexant 5066 specific */
1974
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001975static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1976static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1977static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1978static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001979
Daniel Drakedbaccc02009-11-09 15:17:24 +00001980/* OLPC's microphone port is DC coupled for use with external sensors,
1981 * therefore we use a 50% mic bias in order to center the input signal with
1982 * the DC input range of the codec. */
1983#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1984
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001985static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001986 { 2, NULL },
1987};
1988
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001989#define HP_PRESENT_PORT_A (1 << 0)
1990#define HP_PRESENT_PORT_D (1 << 1)
1991#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1992#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1993
Daniel Drake0fb67e92009-07-16 14:46:57 +01001994static void cxt5066_update_speaker(struct hda_codec *codec)
1995{
1996 struct conexant_spec *spec = codec->spec;
1997 unsigned int pinctl;
1998
John Baboval3a253442010-12-02 11:21:31 -05001999 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2000 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002001
2002 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002003 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002004 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2005 pinctl);
2006
2007 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002008 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2009 if (spec->dell_automute || spec->thinkpad) {
2010 /* Mute if Port A is connected */
2011 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002012 pinctl = 0;
2013 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002014 /* Thinkpad/Dell doesn't give pin-D status */
2015 if (!hp_port_d_present(spec))
2016 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002017 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002018 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2019 pinctl);
2020
2021 /* CLASS_D AMP */
2022 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2023 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2024 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002025}
2026
2027/* turn on/off EAPD (+ mute HP) as a master switch */
2028static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2029 struct snd_ctl_elem_value *ucontrol)
2030{
2031 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2032
2033 if (!cxt_eapd_put(kcontrol, ucontrol))
2034 return 0;
2035
2036 cxt5066_update_speaker(codec);
2037 return 1;
2038}
2039
Daniel Drakec4cfe662010-01-07 13:47:04 +01002040static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2041 .num_items = 3,
2042 .items = {
2043 { "Off", PIN_IN },
2044 { "50%", PIN_VREF50 },
2045 { "80%", PIN_VREF80 },
2046 },
2047};
2048
2049static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2050{
2051 struct conexant_spec *spec = codec->spec;
2052 /* Even though port F is the DC input, the bias is controlled on port B.
2053 * we also leave that port as an active input (but unselected) in DC mode
2054 * just in case that is necessary to make the bias setting take effect. */
2055 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2056 AC_VERB_SET_PIN_WIDGET_CONTROL,
2057 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2058}
2059
Daniel Drake75f89912010-01-07 13:46:25 +01002060/* OLPC defers mic widget control until when capture is started because the
2061 * microphone LED comes on as soon as these settings are put in place. if we
2062 * did this before recording, it would give the false indication that recording
2063 * is happening when it is not. */
2064static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002065{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002066 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002067 if (!spec->recording)
2068 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002069
Daniel Drakec4cfe662010-01-07 13:47:04 +01002070 if (spec->dc_enable) {
2071 /* in DC mode we ignore presence detection and just use the jack
2072 * through our special DC port */
2073 const struct hda_verb enable_dc_mode[] = {
2074 /* disble internal mic, port C */
2075 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2076
2077 /* enable DC capture, port F */
2078 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2079 {},
2080 };
2081
2082 snd_hda_sequence_write(codec, enable_dc_mode);
2083 /* port B input disabled (and bias set) through the following call */
2084 cxt5066_set_olpc_dc_bias(codec);
2085 return;
2086 }
2087
2088 /* disable DC (port F) */
2089 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2090
Daniel Drake75f89912010-01-07 13:46:25 +01002091 /* external mic, port B */
2092 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2093 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002094
Daniel Drake75f89912010-01-07 13:46:25 +01002095 /* internal mic, port C */
2096 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2097 spec->ext_mic_present ? 0 : PIN_VREF80);
2098}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002099
Daniel Drake75f89912010-01-07 13:46:25 +01002100/* toggle input of built-in and mic jack appropriately */
2101static void cxt5066_olpc_automic(struct hda_codec *codec)
2102{
2103 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002104 unsigned int present;
2105
Daniel Drakec4cfe662010-01-07 13:47:04 +01002106 if (spec->dc_enable) /* don't do presence detection in DC mode */
2107 return;
2108
Daniel Drake75f89912010-01-07 13:46:25 +01002109 present = snd_hda_codec_read(codec, 0x1a, 0,
2110 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2111 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002112 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002113 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002114 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002115
2116 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2117 present ? 0 : 1);
2118 spec->ext_mic_present = !!present;
2119
2120 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002121}
2122
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002123/* toggle input of built-in digital mic and mic jack appropriately */
2124static void cxt5066_vostro_automic(struct hda_codec *codec)
2125{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002126 unsigned int present;
2127
2128 struct hda_verb ext_mic_present[] = {
2129 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002130 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002131
2132 /* switch to external mic input */
2133 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2134 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2135
2136 /* disable internal digital mic */
2137 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2138 {}
2139 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002140 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002141 /* enable internal mic, port C */
2142 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2143
2144 /* switch to internal mic input */
2145 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2146
2147 /* disable external mic, port B */
2148 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2149 {}
2150 };
2151
2152 present = snd_hda_jack_detect(codec, 0x1a);
2153 if (present) {
2154 snd_printdd("CXT5066: external microphone detected\n");
2155 snd_hda_sequence_write(codec, ext_mic_present);
2156 } else {
2157 snd_printdd("CXT5066: external microphone absent\n");
2158 snd_hda_sequence_write(codec, ext_mic_absent);
2159 }
2160}
2161
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002162/* toggle input of built-in digital mic and mic jack appropriately */
2163static void cxt5066_ideapad_automic(struct hda_codec *codec)
2164{
2165 unsigned int present;
2166
2167 struct hda_verb ext_mic_present[] = {
2168 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2169 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2170 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2171 {}
2172 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002173 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002174 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2175 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2176 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2177 {}
2178 };
2179
2180 present = snd_hda_jack_detect(codec, 0x1b);
2181 if (present) {
2182 snd_printdd("CXT5066: external microphone detected\n");
2183 snd_hda_sequence_write(codec, ext_mic_present);
2184 } else {
2185 snd_printdd("CXT5066: external microphone absent\n");
2186 snd_hda_sequence_write(codec, ext_mic_absent);
2187 }
2188}
2189
David Henningssona1d69062011-01-21 13:33:28 +01002190
2191/* toggle input of built-in digital mic and mic jack appropriately */
2192static void cxt5066_asus_automic(struct hda_codec *codec)
2193{
2194 unsigned int present;
2195
2196 present = snd_hda_jack_detect(codec, 0x1b);
2197 snd_printdd("CXT5066: external microphone present=%d\n", present);
2198 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2199 present ? 1 : 0);
2200}
2201
2202
David Henningsson048e78a2010-09-02 08:35:47 +02002203/* toggle input of built-in digital mic and mic jack appropriately */
2204static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2205{
2206 unsigned int present;
2207
2208 present = snd_hda_jack_detect(codec, 0x1b);
2209 snd_printdd("CXT5066: external microphone present=%d\n", present);
2210 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2211 present ? 1 : 3);
2212}
2213
2214
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002215/* toggle input of built-in digital mic and mic jack appropriately
2216 order is: external mic -> dock mic -> interal mic */
2217static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2218{
2219 unsigned int ext_present, dock_present;
2220
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002221 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002222 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2223 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2224 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2225 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2226 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2227 {}
2228 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002229 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002230 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2231 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2232 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2233 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2234 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2235 {}
2236 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002237 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002238 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2239 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2240 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2241 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2242 {}
2243 };
2244
2245 ext_present = snd_hda_jack_detect(codec, 0x1b);
2246 dock_present = snd_hda_jack_detect(codec, 0x1a);
2247 if (ext_present) {
2248 snd_printdd("CXT5066: external microphone detected\n");
2249 snd_hda_sequence_write(codec, ext_mic_present);
2250 } else if (dock_present) {
2251 snd_printdd("CXT5066: dock microphone detected\n");
2252 snd_hda_sequence_write(codec, dock_mic_present);
2253 } else {
2254 snd_printdd("CXT5066: external microphone absent\n");
2255 snd_hda_sequence_write(codec, ext_mic_absent);
2256 }
2257}
2258
Daniel Drake0fb67e92009-07-16 14:46:57 +01002259/* mute internal speaker if HP is plugged */
2260static void cxt5066_hp_automute(struct hda_codec *codec)
2261{
2262 struct conexant_spec *spec = codec->spec;
2263 unsigned int portA, portD;
2264
2265 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002266 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002267
2268 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002269 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002270
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002271 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2272 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002273 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2274 portA, portD, spec->hp_present);
2275 cxt5066_update_speaker(codec);
2276}
2277
David Henningsson02b6b5b2011-01-21 13:27:39 +01002278/* Dispatch the right mic autoswitch function */
2279static void cxt5066_automic(struct hda_codec *codec)
2280{
2281 struct conexant_spec *spec = codec->spec;
2282
2283 if (spec->dell_vostro)
2284 cxt5066_vostro_automic(codec);
2285 else if (spec->ideapad)
2286 cxt5066_ideapad_automic(codec);
2287 else if (spec->thinkpad)
2288 cxt5066_thinkpad_automic(codec);
2289 else if (spec->hp_laptop)
2290 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002291 else if (spec->asus)
2292 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002293}
2294
Daniel Drake0fb67e92009-07-16 14:46:57 +01002295/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002296static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002297{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002298 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002299 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2300 switch (res >> 26) {
2301 case CONEXANT_HP_EVENT:
2302 cxt5066_hp_automute(codec);
2303 break;
2304 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002305 /* ignore mic events in DC mode; we're always using the jack */
2306 if (!spec->dc_enable)
2307 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002308 break;
2309 }
2310}
2311
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002312/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002313static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002314{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002315 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002316 switch (res >> 26) {
2317 case CONEXANT_HP_EVENT:
2318 cxt5066_hp_automute(codec);
2319 break;
2320 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002321 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002322 break;
2323 }
2324}
2325
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002326
Daniel Drake0fb67e92009-07-16 14:46:57 +01002327static const struct hda_input_mux cxt5066_analog_mic_boost = {
2328 .num_items = 5,
2329 .items = {
2330 { "0dB", 0 },
2331 { "10dB", 1 },
2332 { "20dB", 2 },
2333 { "30dB", 3 },
2334 { "40dB", 4 },
2335 },
2336};
2337
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002338static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002339{
2340 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002341 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002342 AC_VERB_SET_AMP_GAIN_MUTE,
2343 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2344 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002345 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002346 /* adjust the internal mic as well...it is not through 0x17 */
2347 snd_hda_codec_write_cache(codec, 0x23, 0,
2348 AC_VERB_SET_AMP_GAIN_MUTE,
2349 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2350 cxt5066_analog_mic_boost.
2351 items[spec->mic_boost].index);
2352 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002353}
2354
Daniel Drake0fb67e92009-07-16 14:46:57 +01002355static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2356 struct snd_ctl_elem_info *uinfo)
2357{
2358 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2359}
2360
2361static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2362 struct snd_ctl_elem_value *ucontrol)
2363{
2364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002365 struct conexant_spec *spec = codec->spec;
2366 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367 return 0;
2368}
2369
2370static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2371 struct snd_ctl_elem_value *ucontrol)
2372{
2373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002374 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002375 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2376 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002377 idx = ucontrol->value.enumerated.item[0];
2378 if (idx >= imux->num_items)
2379 idx = imux->num_items - 1;
2380
Daniel Drakec4cfe662010-01-07 13:47:04 +01002381 spec->mic_boost = idx;
2382 if (!spec->dc_enable)
2383 cxt5066_set_mic_boost(codec);
2384 return 1;
2385}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002386
Daniel Drakec4cfe662010-01-07 13:47:04 +01002387static void cxt5066_enable_dc(struct hda_codec *codec)
2388{
2389 const struct hda_verb enable_dc_mode[] = {
2390 /* disable gain */
2391 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2392
2393 /* switch to DC input */
2394 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2395 {}
2396 };
2397
2398 /* configure as input source */
2399 snd_hda_sequence_write(codec, enable_dc_mode);
2400 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2401}
2402
2403static void cxt5066_disable_dc(struct hda_codec *codec)
2404{
2405 /* reconfigure input source */
2406 cxt5066_set_mic_boost(codec);
2407 /* automic also selects the right mic if we're recording */
2408 cxt5066_olpc_automic(codec);
2409}
2410
2411static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2412 struct snd_ctl_elem_value *ucontrol)
2413{
2414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2415 struct conexant_spec *spec = codec->spec;
2416 ucontrol->value.integer.value[0] = spec->dc_enable;
2417 return 0;
2418}
2419
2420static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2421 struct snd_ctl_elem_value *ucontrol)
2422{
2423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2424 struct conexant_spec *spec = codec->spec;
2425 int dc_enable = !!ucontrol->value.integer.value[0];
2426
2427 if (dc_enable == spec->dc_enable)
2428 return 0;
2429
2430 spec->dc_enable = dc_enable;
2431 if (dc_enable)
2432 cxt5066_enable_dc(codec);
2433 else
2434 cxt5066_disable_dc(codec);
2435
2436 return 1;
2437}
2438
2439static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2440 struct snd_ctl_elem_info *uinfo)
2441{
2442 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2443}
2444
2445static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2446 struct snd_ctl_elem_value *ucontrol)
2447{
2448 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2449 struct conexant_spec *spec = codec->spec;
2450 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2451 return 0;
2452}
2453
2454static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2455 struct snd_ctl_elem_value *ucontrol)
2456{
2457 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2458 struct conexant_spec *spec = codec->spec;
2459 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2460 unsigned int idx;
2461
2462 idx = ucontrol->value.enumerated.item[0];
2463 if (idx >= imux->num_items)
2464 idx = imux->num_items - 1;
2465
2466 spec->dc_input_bias = idx;
2467 if (spec->dc_enable)
2468 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002469 return 1;
2470}
2471
Daniel Drake75f89912010-01-07 13:46:25 +01002472static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2473{
2474 struct conexant_spec *spec = codec->spec;
2475 /* mark as recording and configure the microphone widget so that the
2476 * recording LED comes on. */
2477 spec->recording = 1;
2478 cxt5066_olpc_select_mic(codec);
2479}
2480
2481static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2482{
2483 struct conexant_spec *spec = codec->spec;
2484 const struct hda_verb disable_mics[] = {
2485 /* disable external mic, port B */
2486 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2487
2488 /* disble internal mic, port C */
2489 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002490
2491 /* disable DC capture, port F */
2492 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002493 {},
2494 };
2495
2496 snd_hda_sequence_write(codec, disable_mics);
2497 spec->recording = 0;
2498}
2499
Andy Robinsonf6a24912011-01-24 10:12:37 -05002500static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002501 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002502 int num_pins)
2503{
2504 struct conexant_spec *spec = codec->spec;
2505 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2506 int i;
2507
2508 for (i = 0; i < num_pins; i++, dig_pins++) {
2509 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2510 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2511 continue;
2512 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2513 continue;
2514 if (spec->slave_dig_outs[0])
2515 nid_loc++;
2516 else
2517 nid_loc = spec->slave_dig_outs;
2518 }
2519}
2520
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002521static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002522 .num_items = 4,
2523 .items = {
2524 { "Mic B", 0 },
2525 { "Mic C", 1 },
2526 { "Mic E", 2 },
2527 { "Mic F", 3 },
2528 },
2529};
2530
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002531static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002532 .ops = &snd_hda_bind_vol,
2533 .values = {
2534 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2535 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2536 0
2537 },
2538};
2539
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002540static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002541 .ops = &snd_hda_bind_sw,
2542 .values = {
2543 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2544 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2545 0
2546 },
2547};
2548
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002549static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002550 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2551 {}
2552};
2553
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002554static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002555 {
2556 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2557 .name = "Master Playback Volume",
2558 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2559 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2560 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002561 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002562 .info = snd_hda_mixer_amp_volume_info,
2563 .get = snd_hda_mixer_amp_volume_get,
2564 .put = snd_hda_mixer_amp_volume_put,
2565 .tlv = { .c = snd_hda_mixer_amp_tlv },
2566 /* offset by 28 volume steps to limit minimum gain to -46dB */
2567 .private_value =
2568 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2569 },
2570 {}
2571};
2572
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002573static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002574 {
2575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2576 .name = "DC Mode Enable Switch",
2577 .info = snd_ctl_boolean_mono_info,
2578 .get = cxt5066_olpc_dc_get,
2579 .put = cxt5066_olpc_dc_put,
2580 },
2581 {
2582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2583 .name = "DC Input Bias Enum",
2584 .info = cxt5066_olpc_dc_bias_enum_info,
2585 .get = cxt5066_olpc_dc_bias_enum_get,
2586 .put = cxt5066_olpc_dc_bias_enum_put,
2587 },
2588 {}
2589};
2590
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002591static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002592 {
2593 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2594 .name = "Master Playback Switch",
2595 .info = cxt_eapd_info,
2596 .get = cxt_eapd_get,
2597 .put = cxt5066_hp_master_sw_put,
2598 .private_value = 0x1d,
2599 },
2600
2601 {
2602 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002603 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002604 .info = cxt5066_mic_boost_mux_enum_info,
2605 .get = cxt5066_mic_boost_mux_enum_get,
2606 .put = cxt5066_mic_boost_mux_enum_put,
2607 },
2608
2609 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2610 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2611 {}
2612};
2613
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002614static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002615 {
2616 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002617 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002618 .info = cxt5066_mic_boost_mux_enum_info,
2619 .get = cxt5066_mic_boost_mux_enum_get,
2620 .put = cxt5066_mic_boost_mux_enum_put,
2621 .private_value = 0x23 | 0x100,
2622 },
2623 {}
2624};
2625
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002626static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002627 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2628 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2629 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2630 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2631
2632 /* Speakers */
2633 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2634 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2635
2636 /* HP, Amp */
2637 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2638 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2639
2640 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2641 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2642
2643 /* DAC1 */
2644 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2645
2646 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2647 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2648 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2649 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2650 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2651 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2652
2653 /* no digital microphone support yet */
2654 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2655
2656 /* Audio input selector */
2657 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2658
2659 /* SPDIF route: PCM */
2660 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2661 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2662
2663 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2664 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2665
2666 /* EAPD */
2667 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2668
2669 /* not handling these yet */
2670 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2671 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2672 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2673 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2674 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2675 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2676 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2677 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2678 { } /* end */
2679};
2680
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002681static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002682 /* Port A: headphones */
2683 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2684 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2685
2686 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002687 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002688
2689 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002690 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002691
2692 /* Port D: unused */
2693 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2694
2695 /* Port E: unused, but has primary EAPD */
2696 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2697 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2698
Daniel Drakec4cfe662010-01-07 13:47:04 +01002699 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002700 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2701
2702 /* Port G: internal speakers */
2703 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2704 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2705
2706 /* DAC1 */
2707 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2708
2709 /* DAC2: unused */
2710 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2711
2712 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2713 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2714 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2715 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2716 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2717 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2718 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2719 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2720 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2721 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2722 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2723 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2724
2725 /* Disable digital microphone port */
2726 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727
2728 /* Audio input selectors */
2729 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2730 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2731
2732 /* Disable SPDIF */
2733 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2734 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2735
2736 /* enable unsolicited events for Port A and B */
2737 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2738 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2739 { } /* end */
2740};
2741
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002742static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002743 /* Port A: headphones */
2744 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2745 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2746
2747 /* Port B: external microphone */
2748 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2749
2750 /* Port C: unused */
2751 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2752
2753 /* Port D: unused */
2754 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2755
2756 /* Port E: unused, but has primary EAPD */
2757 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2758 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2759
2760 /* Port F: unused */
2761 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2762
2763 /* Port G: internal speakers */
2764 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2765 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2766
2767 /* DAC1 */
2768 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2769
2770 /* DAC2: unused */
2771 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2772
2773 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2774 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2776 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2777 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2778 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2779 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2780 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2782 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2783 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2784 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2785
2786 /* Digital microphone port */
2787 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2788
2789 /* Audio input selectors */
2790 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2791 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2792
2793 /* Disable SPDIF */
2794 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2795 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2796
2797 /* enable unsolicited events for Port A and B */
2798 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2799 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2800 { } /* end */
2801};
2802
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002803static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002804 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2805 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2806 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2807 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2808
2809 /* Speakers */
2810 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2811 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2812
2813 /* HP, Amp */
2814 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2815 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2816
2817 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2818 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2819
2820 /* DAC1 */
2821 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2822
2823 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2825 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2826 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2827 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2828 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2829 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2830
2831 /* Audio input selector */
2832 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2833 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2834
2835 /* SPDIF route: PCM */
2836 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2837 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2838
2839 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2840 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2841
2842 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002843 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002844
2845 /* EAPD */
2846 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2847
2848 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2849 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2850 { } /* end */
2851};
2852
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002853static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002854 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2855 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2856
2857 /* Port G: internal speakers */
2858 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2859 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2860
2861 /* Port A: HP, Amp */
2862 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2864
2865 /* Port B: Mic Dock */
2866 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2867
2868 /* Port C: Mic */
2869 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2870
2871 /* Port D: HP Dock, Amp */
2872 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2873 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2874
2875 /* DAC1 */
2876 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2877
2878 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2880 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2881 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2882 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2883 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2884 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2885
2886 /* Audio input selector */
2887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2888 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2889
2890 /* SPDIF route: PCM */
2891 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2892 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2893
2894 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2895 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2896
2897 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002898 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002899
2900 /* EAPD */
2901 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2902
2903 /* enable unsolicited events for Port A, B, C and D */
2904 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2905 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2906 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2907 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2908 { } /* end */
2909};
2910
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002911static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002912 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2913 { } /* end */
2914};
2915
David Henningsson048e78a2010-09-02 08:35:47 +02002916
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002917static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002918 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2919 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2920 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2921 { } /* end */
2922};
2923
Daniel Drake0fb67e92009-07-16 14:46:57 +01002924/* initialize jack-sensing, too */
2925static int cxt5066_init(struct hda_codec *codec)
2926{
2927 snd_printdd("CXT5066: init\n");
2928 conexant_init(codec);
2929 if (codec->patch_ops.unsol_event) {
2930 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002931 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002932 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002933 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002934 return 0;
2935}
2936
Daniel Drake75f89912010-01-07 13:46:25 +01002937static int cxt5066_olpc_init(struct hda_codec *codec)
2938{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002939 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002940 snd_printdd("CXT5066: init\n");
2941 conexant_init(codec);
2942 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002943 if (!spec->dc_enable) {
2944 cxt5066_set_mic_boost(codec);
2945 cxt5066_olpc_automic(codec);
2946 } else {
2947 cxt5066_enable_dc(codec);
2948 }
Daniel Drake75f89912010-01-07 13:46:25 +01002949 return 0;
2950}
2951
Daniel Drake0fb67e92009-07-16 14:46:57 +01002952enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002953 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002954 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2955 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002956 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002957 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002958 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002959 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002960 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002961 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002962 CXT5066_MODELS
2963};
2964
Takashi Iwaiea734962011-01-17 11:29:34 +01002965static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002966 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002967 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2968 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002969 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002970 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002971 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002972 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002973 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002974 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002975};
2976
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002977static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02002978 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002979 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002980 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002981 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002982 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02002983 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002984 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002985 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2986 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002987 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002988 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002989 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002990 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002991 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002992 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002993 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2994 CXT5066_LAPTOP),
2995 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002996 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002997 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002998 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson29c5fbb2012-01-23 16:39:55 +01002999 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO),
Daniel Suchyca201c02011-10-18 11:09:44 +02003000 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02003001 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003002 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003003 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003004 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003005 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003006 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003007 {}
3008};
3009
3010static int patch_cxt5066(struct hda_codec *codec)
3011{
3012 struct conexant_spec *spec;
3013 int board_config;
3014
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003015 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3016 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003017 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003018 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003019 if (board_config == CXT5066_AUTO)
3020 return patch_conexant_auto(codec);
3021
Daniel Drake0fb67e92009-07-16 14:46:57 +01003022 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3023 if (!spec)
3024 return -ENOMEM;
3025 codec->spec = spec;
3026
3027 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003028 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003029
3030 spec->dell_automute = 0;
3031 spec->multiout.max_channels = 2;
3032 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3033 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003034 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3035 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003036 spec->num_adc_nids = 1;
3037 spec->adc_nids = cxt5066_adc_nids;
3038 spec->capsrc_nids = cxt5066_capsrc_nids;
3039 spec->input_mux = &cxt5066_capture_source;
3040
3041 spec->port_d_mode = PIN_HP;
3042
3043 spec->num_init_verbs = 1;
3044 spec->init_verbs[0] = cxt5066_init_verbs;
3045 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3046 spec->channel_mode = cxt5066_modes;
3047 spec->cur_adc = 0;
3048 spec->cur_adc_idx = 0;
3049
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003050 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3051
Daniel Drake0fb67e92009-07-16 14:46:57 +01003052 switch (board_config) {
3053 default:
3054 case CXT5066_LAPTOP:
3055 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3056 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3057 break;
3058 case CXT5066_DELL_LAPTOP:
3059 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3060 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3061
3062 spec->port_d_mode = PIN_OUT;
3063 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3064 spec->num_init_verbs++;
3065 spec->dell_automute = 1;
3066 break;
David Henningssona1d69062011-01-21 13:33:28 +01003067 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003068 case CXT5066_HP_LAPTOP:
3069 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003070 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003071 spec->init_verbs[spec->num_init_verbs] =
3072 cxt5066_init_verbs_hp_laptop;
3073 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003074 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3075 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003076 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3077 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3078 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003079 if (board_config == CXT5066_HP_LAPTOP)
3080 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003081 /* input source automatically selected */
3082 spec->input_mux = NULL;
3083 spec->port_d_mode = 0;
3084 spec->mic_boost = 3; /* default 30dB gain */
3085 break;
3086
Daniel Drake0fb67e92009-07-16 14:46:57 +01003087 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003088 codec->patch_ops.init = cxt5066_olpc_init;
3089 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003090 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3091 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003092 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003093 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3094 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003095 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003096
3097 /* no S/PDIF out */
3098 spec->multiout.dig_out_nid = 0;
3099
3100 /* input source automatically selected */
3101 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003102
3103 /* our capture hooks which allow us to turn on the microphone LED
3104 * at the right time */
3105 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3106 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003107 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003108 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003109 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003110 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003111 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3112 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3113 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003114 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003115 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003116 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003117 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003118
3119 /* no S/PDIF out */
3120 spec->multiout.dig_out_nid = 0;
3121
3122 /* input source automatically selected */
3123 spec->input_mux = NULL;
3124 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003125 case CXT5066_IDEAPAD:
3126 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003127 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003128 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3129 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3130 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3131 spec->port_d_mode = 0;
3132 spec->ideapad = 1;
3133 spec->mic_boost = 2; /* default 20dB gain */
3134
3135 /* no S/PDIF out */
3136 spec->multiout.dig_out_nid = 0;
3137
3138 /* input source automatically selected */
3139 spec->input_mux = NULL;
3140 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003141 case CXT5066_THINKPAD:
3142 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003143 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003144 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3145 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3146 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3147 spec->thinkpad = 1;
3148 spec->port_d_mode = PIN_OUT;
3149 spec->mic_boost = 2; /* default 20dB gain */
3150
3151 /* no S/PDIF out */
3152 spec->multiout.dig_out_nid = 0;
3153
3154 /* input source automatically selected */
3155 spec->input_mux = NULL;
3156 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003157 }
3158
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003159 if (spec->beep_amp)
3160 snd_hda_attach_beep_device(codec, spec->beep_amp);
3161
Daniel Drake0fb67e92009-07-16 14:46:57 +01003162 return 0;
3163}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003164
3165/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003166 * Automatic parser for CX20641 & co
3167 */
3168
Takashi Iwai6764bce2011-05-13 16:52:25 +02003169static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3170 struct hda_codec *codec,
3171 unsigned int stream_tag,
3172 unsigned int format,
3173 struct snd_pcm_substream *substream)
3174{
3175 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003176 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003177 if (spec->adc_switching) {
3178 spec->cur_adc = adc;
3179 spec->cur_adc_stream_tag = stream_tag;
3180 spec->cur_adc_format = format;
3181 }
3182 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3183 return 0;
3184}
3185
3186static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3187 struct hda_codec *codec,
3188 struct snd_pcm_substream *substream)
3189{
3190 struct conexant_spec *spec = codec->spec;
3191 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3192 spec->cur_adc = 0;
3193 return 0;
3194}
3195
3196static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3197 .substreams = 1,
3198 .channels_min = 2,
3199 .channels_max = 2,
3200 .nid = 0, /* fill later */
3201 .ops = {
3202 .prepare = cx_auto_capture_pcm_prepare,
3203 .cleanup = cx_auto_capture_pcm_cleanup
3204 },
3205};
3206
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003207static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003208
Takashi Iwai8d087c72011-06-28 12:45:47 +02003209#define get_connection_index(codec, mux, nid)\
3210 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003211
3212/* get an unassigned DAC from the given list.
3213 * Return the nid if found and reduce the DAC list, or return zero if
3214 * not found
3215 */
3216static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3217 hda_nid_t *dacs, int *num_dacs)
3218{
3219 int i, nums = *num_dacs;
3220 hda_nid_t ret = 0;
3221
3222 for (i = 0; i < nums; i++) {
3223 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3224 ret = dacs[i];
3225 break;
3226 }
3227 }
3228 if (!ret)
3229 return 0;
3230 if (--nums > 0)
3231 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3232 *num_dacs = nums;
3233 return ret;
3234}
3235
3236#define MAX_AUTO_DACS 5
3237
Takashi Iwai1f015f52011-08-23 14:57:08 +02003238#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3239
Takashi Iwaif2e57312010-09-15 10:07:08 +02003240/* fill analog DAC list from the widget tree */
3241static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3242{
3243 hda_nid_t nid, end_nid;
3244 int nums = 0;
3245
3246 end_nid = codec->start_nid + codec->num_nodes;
3247 for (nid = codec->start_nid; nid < end_nid; nid++) {
3248 unsigned int wcaps = get_wcaps(codec, nid);
3249 unsigned int type = get_wcaps_type(wcaps);
3250 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3251 dacs[nums++] = nid;
3252 if (nums >= MAX_AUTO_DACS)
3253 break;
3254 }
3255 }
3256 return nums;
3257}
3258
3259/* fill pin_dac_pair list from the pin and dac list */
3260static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3261 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003262 struct pin_dac_pair *filled, int nums,
3263 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003264{
David Henningsson468c5452011-08-25 13:16:02 +02003265 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003266
David Henningsson468c5452011-08-25 13:16:02 +02003267 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003268 filled[nums].pin = pins[i];
3269 filled[nums].type = type;
3270 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003271 if (filled[nums].dac)
3272 continue;
3273 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3274 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3275 continue;
3276 }
3277 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003278 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003279 continue;
3280 }
3281 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003282 }
3283 return nums;
3284}
3285
3286/* parse analog output paths */
3287static void cx_auto_parse_output(struct hda_codec *codec)
3288{
3289 struct conexant_spec *spec = codec->spec;
3290 struct auto_pin_cfg *cfg = &spec->autocfg;
3291 hda_nid_t dacs[MAX_AUTO_DACS];
3292 int i, j, nums, rest;
3293
3294 rest = fill_cx_auto_dacs(codec, dacs);
3295 /* parse all analog output pins */
3296 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003297 dacs, &rest, spec->dac_info, 0,
3298 AUTO_PIN_LINE_OUT);
3299 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3300 dacs, &rest, spec->dac_info, nums,
3301 AUTO_PIN_HP_OUT);
3302 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3303 dacs, &rest, spec->dac_info, nums,
3304 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003305 spec->dac_info_filled = nums;
3306 /* fill multiout struct */
3307 for (i = 0; i < nums; i++) {
3308 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003309 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003310 continue;
3311 switch (spec->dac_info[i].type) {
3312 case AUTO_PIN_LINE_OUT:
3313 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3314 spec->multiout.num_dacs++;
3315 break;
3316 case AUTO_PIN_HP_OUT:
3317 case AUTO_PIN_SPEAKER_OUT:
3318 if (!spec->multiout.hp_nid) {
3319 spec->multiout.hp_nid = dac;
3320 break;
3321 }
3322 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3323 if (!spec->multiout.extra_out_nid[j]) {
3324 spec->multiout.extra_out_nid[j] = dac;
3325 break;
3326 }
3327 break;
3328 }
3329 }
3330 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003331 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003332
Takashi Iwai03697e22011-05-17 09:53:31 +02003333 for (i = 0; i < cfg->hp_outs; i++) {
3334 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3335 spec->auto_mute = 1;
3336 break;
3337 }
3338 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003339 if (spec->auto_mute &&
3340 cfg->line_out_pins[0] &&
3341 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003342 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3343 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3344 for (i = 0; i < cfg->line_outs; i++) {
3345 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3346 spec->detect_line = 1;
3347 break;
3348 }
3349 }
3350 spec->automute_lines = spec->detect_line;
3351 }
3352
Takashi Iwaif2e57312010-09-15 10:07:08 +02003353 spec->vmaster_nid = spec->private_dac_nids[0];
3354}
3355
Takashi Iwaida339862011-05-13 16:24:15 +02003356static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3357 hda_nid_t *pins, bool on);
3358
Takashi Iwai03697e22011-05-17 09:53:31 +02003359static void do_automute(struct hda_codec *codec, int num_pins,
3360 hda_nid_t *pins, bool on)
3361{
Takashi Iwai254f2962011-10-14 15:22:34 +02003362 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003363 int i;
3364 for (i = 0; i < num_pins; i++)
3365 snd_hda_codec_write(codec, pins[i], 0,
3366 AC_VERB_SET_PIN_WIDGET_CONTROL,
3367 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003368 if (spec->pin_eapd_ctrls)
3369 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003370}
3371
3372static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3373{
3374 int i, present = 0;
3375
3376 for (i = 0; i < num_pins; i++) {
3377 hda_nid_t nid = pins[i];
3378 if (!nid || !is_jack_detectable(codec, nid))
3379 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003380 present |= snd_hda_jack_detect(codec, nid);
3381 }
3382 return present;
3383}
3384
Takashi Iwaif2e57312010-09-15 10:07:08 +02003385/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003386static void cx_auto_update_speakers(struct hda_codec *codec)
3387{
3388 struct conexant_spec *spec = codec->spec;
3389 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003390 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003391
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003392 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003393 if (spec->pin_eapd_ctrls) {
3394 if (spec->auto_mute)
3395 on = spec->hp_present;
3396 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3397 }
3398
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003399 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3400 if (spec->auto_mute)
3401 on = !(spec->hp_present ||
3402 (spec->detect_line && spec->line_present));
3403 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003404
3405 /* toggle line-out mutes if needed, too */
3406 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3407 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3408 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3409 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003410 if (spec->auto_mute) {
3411 /* mute LO in auto-mode when HP jack is present */
3412 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3413 spec->automute_lines)
3414 on = !spec->hp_present;
3415 else
3416 on = 1;
3417 }
3418 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003419}
3420
Takashi Iwaif2e57312010-09-15 10:07:08 +02003421static void cx_auto_hp_automute(struct hda_codec *codec)
3422{
3423 struct conexant_spec *spec = codec->spec;
3424 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003425
3426 if (!spec->auto_mute)
3427 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003428 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3429 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003430}
3431
Takashi Iwai03697e22011-05-17 09:53:31 +02003432static void cx_auto_line_automute(struct hda_codec *codec)
3433{
3434 struct conexant_spec *spec = codec->spec;
3435 struct auto_pin_cfg *cfg = &spec->autocfg;
3436
3437 if (!spec->auto_mute || !spec->detect_line)
3438 return;
3439 spec->line_present = detect_jacks(codec, cfg->line_outs,
3440 cfg->line_out_pins);
3441 cx_auto_update_speakers(codec);
3442}
3443
3444static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3445 struct snd_ctl_elem_info *uinfo)
3446{
3447 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3448 struct conexant_spec *spec = codec->spec;
3449 static const char * const texts2[] = {
3450 "Disabled", "Enabled"
3451 };
3452 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003453 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003454 };
3455 const char * const *texts;
3456
3457 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3458 uinfo->count = 1;
3459 if (spec->automute_hp_lo) {
3460 uinfo->value.enumerated.items = 3;
3461 texts = texts3;
3462 } else {
3463 uinfo->value.enumerated.items = 2;
3464 texts = texts2;
3465 }
3466 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3467 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3468 strcpy(uinfo->value.enumerated.name,
3469 texts[uinfo->value.enumerated.item]);
3470 return 0;
3471}
3472
3473static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3474 struct snd_ctl_elem_value *ucontrol)
3475{
3476 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3477 struct conexant_spec *spec = codec->spec;
3478 unsigned int val;
3479 if (!spec->auto_mute)
3480 val = 0;
3481 else if (!spec->automute_lines)
3482 val = 1;
3483 else
3484 val = 2;
3485 ucontrol->value.enumerated.item[0] = val;
3486 return 0;
3487}
3488
3489static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3490 struct snd_ctl_elem_value *ucontrol)
3491{
3492 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3493 struct conexant_spec *spec = codec->spec;
3494
3495 switch (ucontrol->value.enumerated.item[0]) {
3496 case 0:
3497 if (!spec->auto_mute)
3498 return 0;
3499 spec->auto_mute = 0;
3500 break;
3501 case 1:
3502 if (spec->auto_mute && !spec->automute_lines)
3503 return 0;
3504 spec->auto_mute = 1;
3505 spec->automute_lines = 0;
3506 break;
3507 case 2:
3508 if (!spec->automute_hp_lo)
3509 return -EINVAL;
3510 if (spec->auto_mute && spec->automute_lines)
3511 return 0;
3512 spec->auto_mute = 1;
3513 spec->automute_lines = 1;
3514 break;
3515 default:
3516 return -EINVAL;
3517 }
3518 cx_auto_update_speakers(codec);
3519 return 1;
3520}
3521
3522static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3523 {
3524 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3525 .name = "Auto-Mute Mode",
3526 .info = cx_automute_mode_info,
3527 .get = cx_automute_mode_get,
3528 .put = cx_automute_mode_put,
3529 },
3530 { }
3531};
3532
Takashi Iwai6764bce2011-05-13 16:52:25 +02003533static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3534 struct snd_ctl_elem_info *uinfo)
3535{
3536 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3537 struct conexant_spec *spec = codec->spec;
3538
3539 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3540}
3541
3542static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3543 struct snd_ctl_elem_value *ucontrol)
3544{
3545 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3546 struct conexant_spec *spec = codec->spec;
3547
3548 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3549 return 0;
3550}
3551
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003552/* look for the route the given pin from mux and return the index;
3553 * if do_select is set, actually select the route.
3554 */
3555static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003556 hda_nid_t pin, hda_nid_t *srcp,
3557 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003558{
3559 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3560 int i, nums;
3561
Takashi Iwaicf27f292011-05-16 11:33:02 +02003562 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3563 case AC_WID_AUD_IN:
3564 case AC_WID_AUD_SEL:
3565 case AC_WID_AUD_MIX:
3566 break;
3567 default:
3568 return -1;
3569 }
3570
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003571 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3572 for (i = 0; i < nums; i++)
3573 if (conn[i] == pin) {
3574 if (do_select)
3575 snd_hda_codec_write(codec, mux, 0,
3576 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003577 if (srcp)
3578 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003579 return i;
3580 }
3581 depth++;
3582 if (depth == 2)
3583 return -1;
3584 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003585 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003586 do_select, depth);
3587 if (ret >= 0) {
3588 if (do_select)
3589 snd_hda_codec_write(codec, mux, 0,
3590 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003591 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003592 }
3593 }
3594 return -1;
3595}
3596
3597static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3598 hda_nid_t pin)
3599{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003600 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003601}
3602
3603static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3604 hda_nid_t pin)
3605{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003606 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003607}
3608
Takashi Iwai6764bce2011-05-13 16:52:25 +02003609static int cx_auto_mux_enum_update(struct hda_codec *codec,
3610 const struct hda_input_mux *imux,
3611 unsigned int idx)
3612{
3613 struct conexant_spec *spec = codec->spec;
3614 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003615 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003616
3617 if (!imux->num_items)
3618 return 0;
3619 if (idx >= imux->num_items)
3620 idx = imux->num_items - 1;
3621 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003622 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003623 adc = spec->imux_info[idx].adc;
3624 select_input_connection(codec, spec->imux_info[idx].adc,
3625 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003626 if (spec->cur_adc && spec->cur_adc != adc) {
3627 /* stream is running, let's swap the current ADC */
3628 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3629 spec->cur_adc = adc;
3630 snd_hda_codec_setup_stream(codec, adc,
3631 spec->cur_adc_stream_tag, 0,
3632 spec->cur_adc_format);
3633 }
3634 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003635 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003636}
3637
3638static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3639 struct snd_ctl_elem_value *ucontrol)
3640{
3641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3642 struct conexant_spec *spec = codec->spec;
3643
3644 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3645 ucontrol->value.enumerated.item[0]);
3646}
3647
3648static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3649 {
3650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3651 .name = "Capture Source",
3652 .info = cx_auto_mux_enum_info,
3653 .get = cx_auto_mux_enum_get,
3654 .put = cx_auto_mux_enum_put
3655 },
3656 {}
3657};
3658
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003659static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3660{
3661 struct conexant_spec *spec = codec->spec;
3662 if (idx < 0)
3663 return false;
3664 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3665 return false;
3666 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3667 return true;
3668}
3669
Takashi Iwaif2e57312010-09-15 10:07:08 +02003670/* automatic switch internal and external mic */
3671static void cx_auto_automic(struct hda_codec *codec)
3672{
3673 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003674
3675 if (!spec->auto_mic)
3676 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003677 if (!select_automic(codec, spec->auto_mic_ext, true))
3678 if (!select_automic(codec, spec->auto_mic_dock, true))
3679 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003680}
3681
3682static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3683{
Takashi Iwai3a938972011-10-28 01:16:55 +02003684 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003685 case CONEXANT_HP_EVENT:
3686 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003687 break;
3688 case CONEXANT_LINE_EVENT:
3689 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003690 break;
3691 case CONEXANT_MIC_EVENT:
3692 cx_auto_automic(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003693 break;
3694 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02003695 snd_hda_jack_report_sync(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003696}
3697
Takashi Iwaif2e57312010-09-15 10:07:08 +02003698/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003699 * auto-mic is enabled only when one int-mic and one ext- and/or
3700 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003701 */
3702static void cx_auto_check_auto_mic(struct hda_codec *codec)
3703{
3704 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003705 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3706 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003707
Takashi Iwai506a4192011-05-23 20:07:15 +02003708 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003709 pset[i] = -1;
3710 for (i = 0; i < spec->private_imux.num_items; i++) {
3711 hda_nid_t pin = spec->imux_info[i].pin;
3712 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003713 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003714 attr = snd_hda_get_input_pin_attr(def_conf);
3715 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003716 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003717 if (attr > INPUT_PIN_ATTR_NORMAL)
3718 attr = INPUT_PIN_ATTR_NORMAL;
3719 if (attr != INPUT_PIN_ATTR_INT &&
3720 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003721 return; /* non-detectable pin */
3722 type = get_defcfg_device(def_conf);
3723 if (type != AC_JACK_MIC_IN &&
3724 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3725 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003726 if (pset[attr] >= 0)
3727 return; /* already occupied */
3728 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003729 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003730 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3731 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3732 return; /* no input to switch*/
3733 spec->auto_mic = 1;
3734 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3735 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3736 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003737}
3738
3739static void cx_auto_parse_input(struct hda_codec *codec)
3740{
3741 struct conexant_spec *spec = codec->spec;
3742 struct auto_pin_cfg *cfg = &spec->autocfg;
3743 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003744 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003745
3746 imux = &spec->private_imux;
3747 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003748 for (j = 0; j < spec->num_adc_nids; j++) {
3749 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003750 int idx = get_input_connection(codec, adc,
3751 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003752 if (idx >= 0) {
3753 const char *label;
3754 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003755 spec->imux_info[imux->num_items].index = i;
3756 spec->imux_info[imux->num_items].boost = 0;
3757 spec->imux_info[imux->num_items].adc = adc;
3758 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003759 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003760 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003761 break;
3762 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003763 }
3764 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003765 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003766 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003767 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003768 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003769 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003770 spec->adc_switching = 1;
3771 break;
3772 }
3773 }
3774 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003775}
3776
3777/* get digital-input audio widget corresponding to the given pin */
3778static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3779{
3780 hda_nid_t nid, end_nid;
3781
3782 end_nid = codec->start_nid + codec->num_nodes;
3783 for (nid = codec->start_nid; nid < end_nid; nid++) {
3784 unsigned int wcaps = get_wcaps(codec, nid);
3785 unsigned int type = get_wcaps_type(wcaps);
3786 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3787 if (get_connection_index(codec, nid, pin) >= 0)
3788 return nid;
3789 }
3790 }
3791 return 0;
3792}
3793
3794static void cx_auto_parse_digital(struct hda_codec *codec)
3795{
3796 struct conexant_spec *spec = codec->spec;
3797 struct auto_pin_cfg *cfg = &spec->autocfg;
3798 hda_nid_t nid;
3799
3800 if (cfg->dig_outs &&
3801 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3802 spec->multiout.dig_out_nid = nid;
3803 if (cfg->dig_in_pin)
3804 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3805}
3806
3807#ifdef CONFIG_SND_HDA_INPUT_BEEP
3808static void cx_auto_parse_beep(struct hda_codec *codec)
3809{
3810 struct conexant_spec *spec = codec->spec;
3811 hda_nid_t nid, end_nid;
3812
3813 end_nid = codec->start_nid + codec->num_nodes;
3814 for (nid = codec->start_nid; nid < end_nid; nid++)
3815 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3816 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3817 break;
3818 }
3819}
3820#else
3821#define cx_auto_parse_beep(codec)
3822#endif
3823
Takashi Iwai254f2962011-10-14 15:22:34 +02003824/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003825static void cx_auto_parse_eapd(struct hda_codec *codec)
3826{
3827 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003828 hda_nid_t nid, end_nid;
3829
3830 end_nid = codec->start_nid + codec->num_nodes;
3831 for (nid = codec->start_nid; nid < end_nid; nid++) {
3832 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3833 continue;
3834 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3835 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003836 spec->eapds[spec->num_eapds++] = nid;
3837 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3838 break;
3839 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003840
3841 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3842 * it's a new chip, where EAPDs are supposed to be associated to
3843 * pins, and we can control EAPD per pin.
3844 * OTOH, if only one or two EAPDs are found, it's an old chip,
3845 * thus it might control over all pins.
3846 */
3847 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003848}
3849
Takashi Iwaif2e57312010-09-15 10:07:08 +02003850static int cx_auto_parse_auto_config(struct hda_codec *codec)
3851{
3852 struct conexant_spec *spec = codec->spec;
3853 int err;
3854
3855 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3856 if (err < 0)
3857 return err;
3858
3859 cx_auto_parse_output(codec);
3860 cx_auto_parse_input(codec);
3861 cx_auto_parse_digital(codec);
3862 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003863 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003864 return 0;
3865}
3866
Takashi Iwaida339862011-05-13 16:24:15 +02003867static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3868 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003869{
3870 int i;
3871 for (i = 0; i < num_pins; i++) {
3872 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3873 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003874 AC_VERB_SET_EAPD_BTLENABLE,
3875 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003876 }
3877}
3878
3879static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3880 hda_nid_t src)
3881{
3882 int idx = get_connection_index(codec, pin, src);
3883 if (idx >= 0)
3884 snd_hda_codec_write(codec, pin, 0,
3885 AC_VERB_SET_CONNECT_SEL, idx);
3886}
3887
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003888static void mute_outputs(struct hda_codec *codec, int num_nids,
3889 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003890{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003891 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003892
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003893 for (i = 0; i < num_nids; i++) {
3894 hda_nid_t nid = nids[i];
3895 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3896 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003897 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3898 val = AMP_OUT_MUTE;
3899 else
3900 val = AMP_OUT_ZERO;
3901 snd_hda_codec_write(codec, nid, 0,
3902 AC_VERB_SET_AMP_GAIN_MUTE, val);
3903 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003904}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003905
Takashi Iwai03697e22011-05-17 09:53:31 +02003906static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
Takashi Iwai3a938972011-10-28 01:16:55 +02003907 hda_nid_t *pins, unsigned int action)
Takashi Iwai03697e22011-05-17 09:53:31 +02003908{
3909 int i;
3910 for (i = 0; i < num_pins; i++)
Takashi Iwai3a938972011-10-28 01:16:55 +02003911 snd_hda_jack_detect_enable(codec, pins[i], action);
Takashi Iwai03697e22011-05-17 09:53:31 +02003912}
3913
Takashi Iwai07cafff2012-02-20 12:30:59 +01003914static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3915{
3916 int i;
3917 for (i = 0; i < nums; i++)
3918 if (list[i] == nid)
3919 return true;
3920 return false;
3921}
3922
3923/* is the given NID found in any of autocfg items? */
3924static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3925{
3926 int i;
3927
3928 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3929 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3930 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3931 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3932 return true;
3933 for (i = 0; i < cfg->num_inputs; i++)
3934 if (cfg->inputs[i].pin == nid)
3935 return true;
3936 if (cfg->dig_in_pin == nid)
3937 return true;
3938 return false;
3939}
3940
3941/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3942 * invalid unsol tags by some reason
3943 */
3944static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3945{
3946 struct conexant_spec *spec = codec->spec;
3947 struct auto_pin_cfg *cfg = &spec->autocfg;
3948 int i;
3949
3950 for (i = 0; i < codec->init_pins.used; i++) {
3951 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3952 if (!found_in_autocfg(cfg, pin->nid))
3953 snd_hda_codec_write(codec, pin->nid, 0,
3954 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3955 }
3956}
3957
Takashi Iwai527c73b2012-03-12 12:38:51 +01003958/* turn on/off EAPD according to Master switch */
3959static void cx_auto_vmaster_hook(void *private_data, int enabled)
3960{
3961 struct hda_codec *codec = private_data;
3962 struct conexant_spec *spec = codec->spec;
3963
3964 if (enabled && spec->pin_eapd_ctrls) {
3965 cx_auto_update_speakers(codec);
3966 return;
3967 }
3968 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3969}
3970
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003971static void cx_auto_init_output(struct hda_codec *codec)
3972{
3973 struct conexant_spec *spec = codec->spec;
3974 struct auto_pin_cfg *cfg = &spec->autocfg;
3975 hda_nid_t nid;
3976 int i;
3977
3978 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003979 for (i = 0; i < cfg->hp_outs; i++)
3980 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3981 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003982 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3983 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3984 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003985 for (i = 0; i < spec->dac_info_filled; i++) {
3986 nid = spec->dac_info[i].dac;
3987 if (!nid)
3988 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003989 else if (nid & DAC_SLAVE_FLAG)
3990 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003991 select_connection(codec, spec->dac_info[i].pin, nid);
3992 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003993 if (spec->auto_mute) {
3994 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3995 CONEXANT_HP_EVENT);
3996 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3997 cfg->hp_pins);
3998 if (spec->detect_line) {
3999 enable_unsol_pins(codec, cfg->line_outs,
4000 cfg->line_out_pins,
4001 CONEXANT_LINE_EVENT);
4002 spec->line_present =
4003 detect_jacks(codec, cfg->line_outs,
4004 cfg->line_out_pins);
4005 }
4006 }
4007 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02004008 /* turn on all EAPDs if no individual EAPD control is available */
4009 if (!spec->pin_eapd_ctrls)
4010 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01004011 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004012}
4013
4014static void cx_auto_init_input(struct hda_codec *codec)
4015{
4016 struct conexant_spec *spec = codec->spec;
4017 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004018 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004019
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004020 for (i = 0; i < spec->num_adc_nids; i++) {
4021 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004022 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4023 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004024 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4025 val = AMP_IN_MUTE(0);
4026 else
4027 val = AMP_IN_UNMUTE(0);
4028 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4029 val);
4030 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004031
4032 for (i = 0; i < cfg->num_inputs; i++) {
4033 unsigned int type;
4034 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4035 type = PIN_VREF80;
4036 else
4037 type = PIN_IN;
4038 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4039 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4040 }
4041
4042 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004043 if (spec->auto_mic_ext >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004044 snd_hda_jack_detect_enable(codec,
4045 cfg->inputs[spec->auto_mic_ext].pin,
4046 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004047 }
4048 if (spec->auto_mic_dock >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004049 snd_hda_jack_detect_enable(codec,
4050 cfg->inputs[spec->auto_mic_dock].pin,
4051 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004052 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004053 cx_auto_automic(codec);
4054 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004055 select_input_connection(codec, spec->imux_info[0].adc,
4056 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004057 }
4058}
4059
4060static void cx_auto_init_digital(struct hda_codec *codec)
4061{
4062 struct conexant_spec *spec = codec->spec;
4063 struct auto_pin_cfg *cfg = &spec->autocfg;
4064
4065 if (spec->multiout.dig_out_nid)
4066 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4067 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4068 if (spec->dig_in_nid)
4069 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4070 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4071}
4072
4073static int cx_auto_init(struct hda_codec *codec)
4074{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004075 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004076 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4077 cx_auto_init_output(codec);
4078 cx_auto_init_input(codec);
4079 cx_auto_init_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004080 snd_hda_jack_report_sync(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004081 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004082 return 0;
4083}
4084
David Henningsson983345e2011-02-15 19:57:09 +01004085static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004086 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004087 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004088{
4089 static char name[32];
4090 static struct snd_kcontrol_new knew[] = {
4091 HDA_CODEC_VOLUME(name, 0, 0, 0),
4092 HDA_CODEC_MUTE(name, 0, 0, 0),
4093 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004094 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004095 int i, err;
4096
4097 for (i = 0; i < 2; i++) {
4098 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004099 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4100 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004101 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4102 knew[i].index = cidx;
4103 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4104 kctl = snd_ctl_new1(&knew[i], codec);
4105 if (!kctl)
4106 return -ENOMEM;
4107 err = snd_hda_ctl_add(codec, nid, kctl);
4108 if (err < 0)
4109 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004110 if (!(query_amp_caps(codec, nid, hda_dir) &
4111 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004112 break;
4113 }
4114 return 0;
4115}
4116
David Henningsson983345e2011-02-15 19:57:09 +01004117#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4118 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4119
Takashi Iwaif2e57312010-09-15 10:07:08 +02004120#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4121 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4122
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004123static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4124 hda_nid_t pin, const char *name, int idx)
4125{
4126 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004127 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4128 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4129 if (caps & AC_AMPCAP_NUM_STEPS)
4130 return cx_auto_add_pb_volume(codec, dac, name, idx);
4131 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004132 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4133 if (caps & AC_AMPCAP_NUM_STEPS)
4134 return cx_auto_add_pb_volume(codec, pin, name, idx);
4135 return 0;
4136}
4137
Takashi Iwaif2e57312010-09-15 10:07:08 +02004138static int cx_auto_build_output_controls(struct hda_codec *codec)
4139{
4140 struct conexant_spec *spec = codec->spec;
4141 int i, err;
4142 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004143 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004144
4145 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004146 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4147 spec->dac_info[0].pin,
4148 "Master", 0);
4149
Takashi Iwaif2e57312010-09-15 10:07:08 +02004150 for (i = 0; i < spec->dac_info_filled; i++) {
4151 const char *label;
4152 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004153 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004154 type = spec->dac_info[i].type;
4155 if (type == AUTO_PIN_LINE_OUT)
4156 type = spec->autocfg.line_out_type;
4157 switch (type) {
4158 case AUTO_PIN_LINE_OUT:
4159 default:
4160 label = texts[num_line++];
4161 idx = 0;
4162 break;
4163 case AUTO_PIN_HP_OUT:
4164 label = "Headphone";
4165 idx = num_hp++;
4166 break;
4167 case AUTO_PIN_SPEAKER_OUT:
4168 label = "Speaker";
4169 idx = num_spk++;
4170 break;
4171 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004172 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004173 spec->dac_info[i].pin,
4174 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004175 if (err < 0)
4176 return err;
4177 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004178
4179 if (spec->auto_mute) {
4180 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4181 if (err < 0)
4182 return err;
4183 }
4184
Takashi Iwaif2e57312010-09-15 10:07:08 +02004185 return 0;
4186}
4187
Takashi Iwai6764bce2011-05-13 16:52:25 +02004188static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4189 const char *label, const char *pfx,
4190 int cidx)
4191{
4192 struct conexant_spec *spec = codec->spec;
4193 int i;
4194
4195 for (i = 0; i < spec->num_adc_nids; i++) {
4196 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004197 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004198 if (idx < 0)
4199 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004200 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004201 idx = 0;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004202 return cx_auto_add_volume_idx(codec, label, pfx,
4203 cidx, adc_nid, HDA_INPUT, idx);
4204 }
4205 return 0;
4206}
4207
Takashi Iwaicf27f292011-05-16 11:33:02 +02004208static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4209 const char *label, int cidx)
4210{
4211 struct conexant_spec *spec = codec->spec;
4212 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004213 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004214
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004215 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004216 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4217 return cx_auto_add_volume(codec, label, " Boost", cidx,
4218 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004219 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4220 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004221 if (con < 0)
4222 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004223 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004224 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004225 return 0; /* already present */
4226 }
4227
4228 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004229 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004230 return cx_auto_add_volume(codec, label, " Boost", 0,
4231 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004232 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004233 return 0;
4234}
4235
Takashi Iwaif2e57312010-09-15 10:07:08 +02004236static int cx_auto_build_input_controls(struct hda_codec *codec)
4237{
4238 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004239 struct hda_input_mux *imux = &spec->private_imux;
4240 const char *prev_label;
4241 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004242 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004243 int multi_connection;
4244
Takashi Iwai6b452142011-10-14 15:26:20 +02004245 if (!imux->num_items)
4246 return 0;
4247
Takashi Iwaicf27f292011-05-16 11:33:02 +02004248 multi_connection = 0;
4249 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004250 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4251 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004252 if (cidx < 0)
4253 continue;
4254 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004255 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004256 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004257 if (i > 0 && input_conn[i] != input_conn[0])
4258 multi_connection = 1;
4259 }
David Henningsson983345e2011-02-15 19:57:09 +01004260
Takashi Iwaif2e57312010-09-15 10:07:08 +02004261 prev_label = NULL;
4262 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004263 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004264 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004265 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004266
Takashi Iwaicf27f292011-05-16 11:33:02 +02004267 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004268 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004269 if (label == prev_label)
4270 cidx++;
4271 else
4272 cidx = 0;
4273 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004274
Takashi Iwaicf27f292011-05-16 11:33:02 +02004275 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4276 if (err < 0)
4277 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004278
Takashi Iwaicf27f292011-05-16 11:33:02 +02004279 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004280 if (i > 0)
4281 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004282 err = cx_auto_add_capture_volume(codec, nid,
4283 "Capture", "", cidx);
4284 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004285 bool dup_found = false;
4286 for (j = 0; j < i; j++) {
4287 if (input_conn[j] == input_conn[i]) {
4288 dup_found = true;
4289 break;
4290 }
4291 }
4292 if (dup_found)
4293 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004294 err = cx_auto_add_capture_volume(codec, nid,
4295 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004296 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004297 if (err < 0)
4298 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004299 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004300
4301 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4302 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4303 if (err < 0)
4304 return err;
4305 }
4306
Takashi Iwaif2e57312010-09-15 10:07:08 +02004307 return 0;
4308}
4309
4310static int cx_auto_build_controls(struct hda_codec *codec)
4311{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004312 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004313 int err;
4314
4315 err = cx_auto_build_output_controls(codec);
4316 if (err < 0)
4317 return err;
4318 err = cx_auto_build_input_controls(codec);
4319 if (err < 0)
4320 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004321 err = conexant_build_controls(codec);
4322 if (err < 0)
4323 return err;
4324 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4325 if (err < 0)
4326 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004327 if (spec->vmaster_mute.sw_kctl) {
4328 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4329 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4330 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004331 if (err < 0)
4332 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004333 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004334 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004335}
4336
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004337static int cx_auto_search_adcs(struct hda_codec *codec)
4338{
4339 struct conexant_spec *spec = codec->spec;
4340 hda_nid_t nid, end_nid;
4341
4342 end_nid = codec->start_nid + codec->num_nodes;
4343 for (nid = codec->start_nid; nid < end_nid; nid++) {
4344 unsigned int caps = get_wcaps(codec, nid);
4345 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4346 continue;
4347 if (caps & AC_WCAP_DIGITAL)
4348 continue;
4349 if (snd_BUG_ON(spec->num_adc_nids >=
4350 ARRAY_SIZE(spec->private_adc_nids)))
4351 break;
4352 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4353 }
4354 spec->adc_nids = spec->private_adc_nids;
4355 return 0;
4356}
4357
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004358static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004359 .build_controls = cx_auto_build_controls,
4360 .build_pcms = conexant_build_pcms,
4361 .init = cx_auto_init,
4362 .free = conexant_free,
4363 .unsol_event = cx_auto_unsol_event,
4364#ifdef CONFIG_SND_HDA_POWER_SAVE
4365 .suspend = conexant_suspend,
4366#endif
4367 .reboot_notify = snd_hda_shutup_pins,
4368};
4369
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004370/*
4371 * pin fix-up
4372 */
4373struct cxt_pincfg {
4374 hda_nid_t nid;
4375 u32 val;
4376};
4377
4378static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4379{
4380 for (; cfg->nid; cfg++)
4381 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4382
4383}
4384
4385static void apply_pin_fixup(struct hda_codec *codec,
4386 const struct snd_pci_quirk *quirk,
4387 const struct cxt_pincfg **table)
4388{
4389 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4390 if (quirk) {
4391 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4392 quirk->name);
4393 apply_pincfg(codec, table[quirk->value]);
4394 }
4395}
4396
4397enum {
4398 CXT_PINCFG_LENOVO_X200,
4399};
4400
4401static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4402 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4403 { 0x17, 0x21a11000 }, /* dock-mic */
4404 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004405 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004406 {}
4407};
4408
4409static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4410 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4411};
4412
4413static const struct snd_pci_quirk cxt_fixups[] = {
4414 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4415 {}
4416};
4417
Takashi Iwai38681372012-02-27 15:00:58 +01004418/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4419 * can be created (bko#42825)
4420 */
4421static void add_cx5051_fake_mutes(struct hda_codec *codec)
4422{
4423 static hda_nid_t out_nids[] = {
4424 0x10, 0x11, 0
4425 };
4426 hda_nid_t *p;
4427
4428 for (p = out_nids; *p; p++)
4429 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4430 AC_AMPCAP_MIN_MUTE |
4431 query_amp_caps(codec, *p, HDA_OUTPUT));
4432}
4433
Takashi Iwaif2e57312010-09-15 10:07:08 +02004434static int patch_conexant_auto(struct hda_codec *codec)
4435{
4436 struct conexant_spec *spec;
4437 int err;
4438
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004439 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4440 codec->chip_name);
4441
Takashi Iwaif2e57312010-09-15 10:07:08 +02004442 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4443 if (!spec)
4444 return -ENOMEM;
4445 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004446 codec->pin_amp_workaround = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004447
Takashi Iwai6b452142011-10-14 15:26:20 +02004448 switch (codec->vendor_id) {
4449 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004450 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004451 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004452 case 0x14f15051:
4453 add_cx5051_fake_mutes(codec);
4454 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02004455 }
4456
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004457 apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
4458
Takashi Iwaif29735c2012-03-13 07:55:10 +01004459 /* Show mute-led control only on HP laptops
4460 * This is a sort of white-list: on HP laptops, EAPD corresponds
4461 * only to the mute-LED without actualy amp function. Meanwhile,
4462 * others may use EAPD really as an amp switch, so it might be
4463 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004464 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004465 switch (codec->subsystem_id >> 16) {
4466 case 0x103c:
4467 spec->vmaster_mute_led = 1;
4468 break;
4469 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004470
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004471 err = cx_auto_search_adcs(codec);
4472 if (err < 0)
4473 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004474 err = cx_auto_parse_auto_config(codec);
4475 if (err < 0) {
4476 kfree(codec->spec);
4477 codec->spec = NULL;
4478 return err;
4479 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004480 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004481 codec->patch_ops = cx_auto_patch_ops;
4482 if (spec->beep_amp)
4483 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004484
4485 /* Some laptops with Conexant chips show stalls in S3 resume,
4486 * which falls into the single-cmd mode.
4487 * Better to make reset, then.
4488 */
4489 if (!codec->bus->sync_write) {
4490 snd_printd("hda_codec: "
4491 "Enable sync_write for stable communication\n");
4492 codec->bus->sync_write = 1;
4493 codec->bus->allow_bus_reset = 1;
4494 }
4495
Takashi Iwaif2e57312010-09-15 10:07:08 +02004496 return 0;
4497}
4498
4499/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004500 */
4501
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004502static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004503 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4504 .patch = patch_cxt5045 },
4505 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4506 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004507 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4508 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004509 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4510 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004511 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4512 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004513 { .id = 0x14f15068, .name = "CX20584",
4514 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004515 { .id = 0x14f15069, .name = "CX20585",
4516 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004517 { .id = 0x14f1506c, .name = "CX20588",
4518 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004519 { .id = 0x14f1506e, .name = "CX20590",
4520 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004521 { .id = 0x14f15097, .name = "CX20631",
4522 .patch = patch_conexant_auto },
4523 { .id = 0x14f15098, .name = "CX20632",
4524 .patch = patch_conexant_auto },
4525 { .id = 0x14f150a1, .name = "CX20641",
4526 .patch = patch_conexant_auto },
4527 { .id = 0x14f150a2, .name = "CX20642",
4528 .patch = patch_conexant_auto },
4529 { .id = 0x14f150ab, .name = "CX20651",
4530 .patch = patch_conexant_auto },
4531 { .id = 0x14f150ac, .name = "CX20652",
4532 .patch = patch_conexant_auto },
4533 { .id = 0x14f150b8, .name = "CX20664",
4534 .patch = patch_conexant_auto },
4535 { .id = 0x14f150b9, .name = "CX20665",
4536 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004537 {} /* terminator */
4538};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004539
4540MODULE_ALIAS("snd-hda-codec-id:14f15045");
4541MODULE_ALIAS("snd-hda-codec-id:14f15047");
4542MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004543MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004544MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004545MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004546MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004547MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004548MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004549MODULE_ALIAS("snd-hda-codec-id:14f15097");
4550MODULE_ALIAS("snd-hda-codec-id:14f15098");
4551MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4552MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4553MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4554MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4555MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4556MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004557
4558MODULE_LICENSE("GPL");
4559MODULE_DESCRIPTION("Conexant HD-audio codec");
4560
4561static struct hda_codec_preset_list conexant_list = {
4562 .preset = snd_hda_preset_conexant,
4563 .owner = THIS_MODULE,
4564};
4565
4566static int __init patch_conexant_init(void)
4567{
4568 return snd_hda_add_codec_preset(&conexant_list);
4569}
4570
4571static void __exit patch_conexant_exit(void)
4572{
4573 snd_hda_delete_codec_preset(&conexant_list);
4574}
4575
4576module_init(patch_conexant_init)
4577module_exit(patch_conexant_exit)