blob: 4b51c8f2fda24051ddc394c6cdfdc8659f6870a1 [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 = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200695 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100696 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200697 { "CD", 0x4 },
698 { "Internal Mic", 0x1 },
699 { "Mic", 0x2 },
700 { "Line", 0x3 },
701 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100702 }
703};
704
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200705static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100706 .num_items = 2,
707 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200708 { "Mic", 0x1 },
709 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100710 }
711};
712
Tobin Davisc9b443d2006-11-14 12:13:39 +0100713/* turn on/off EAPD (+ mute HP) as a master switch */
714static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
716{
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100719 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100720
Tobin Davis82f30042007-02-13 12:45:44 +0100721 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722 return 0;
723
Tobin Davis82f30042007-02-13 12:45:44 +0100724 /* toggle internal speakers mute depending of presence of
725 * the headphone jack
726 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200727 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
728 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
729 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100730
Takashi Iwai47fd8302007-08-10 17:11:07 +0200731 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
732 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
733 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734 return 1;
735}
736
737/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200738static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200739 .ops = &snd_hda_bind_vol,
740 .values = {
741 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
742 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
743 0
744 },
745};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746
Tobin Davis7f296732007-03-12 11:39:01 +0100747/* toggle input of built-in and mic jack appropriately */
748static void cxt5045_hp_automic(struct hda_codec *codec)
749{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200750 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
752 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
753 {}
754 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200755 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100756 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
758 {}
759 };
760 unsigned int present;
761
Takashi Iwaid56757a2009-11-18 08:00:14 +0100762 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100763 if (present)
764 snd_hda_sequence_write(codec, mic_jack_on);
765 else
766 snd_hda_sequence_write(codec, mic_jack_off);
767}
768
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769
770/* mute internal speaker if HP is plugged */
771static void cxt5045_hp_automute(struct hda_codec *codec)
772{
Tobin Davis82f30042007-02-13 12:45:44 +0100773 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100774 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775
Takashi Iwaid56757a2009-11-18 08:00:14 +0100776 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100777
Takashi Iwai47fd8302007-08-10 17:11:07 +0200778 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
779 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
780 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100781}
782
783/* unsolicited event for HP jack sensing */
784static void cxt5045_hp_unsol_event(struct hda_codec *codec,
785 unsigned int res)
786{
787 res >>= 26;
788 switch (res) {
789 case CONEXANT_HP_EVENT:
790 cxt5045_hp_automute(codec);
791 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100792 case CONEXANT_MIC_EVENT:
793 cxt5045_hp_automic(codec);
794 break;
795
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796 }
797}
798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200799static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200800 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
801 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200802 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
803 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100804 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
805 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100806 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
807 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200808 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100809 {
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100812 .info = cxt_eapd_info,
813 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100814 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100815 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100816 },
817
818 {}
819};
820
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200821static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200822 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
823 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
824
Michael Karcher3edbbb92012-04-06 15:34:16 +0200825 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
826 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Jiang Zhe5218c892008-01-17 11:18:41 +0100827
828 {}
829};
830
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200831static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200832 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
833 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100834 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
835 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100836 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
837 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100838 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
839 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100840 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
841 {
842 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
843 .name = "Master Playback Switch",
844 .info = cxt_eapd_info,
845 .get = cxt_eapd_get,
846 .put = cxt5045_hp_master_sw_put,
847 .private_value = 0x10,
848 },
849
850 {}
851};
852
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200853static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100854 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200855 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100856 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200858 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
859 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
860 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
861 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
863 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
864 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
865 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100867 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100868 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100869 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100870 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
871 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100872 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100873 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100874 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100875 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100876 { } /* end */
877};
878
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200879static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100880 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100881 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
882 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
883 /* Line In,HP, Amp */
884 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
885 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
886 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
887 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
892 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100893 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100894 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
895 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
896 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
897 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100898 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100899 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
900 /* EAPD */
901 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
902 { } /* end */
903};
Tobin Davis7f296732007-03-12 11:39:01 +0100904
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200905static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100906 /* pin sensing on HP jack */
907 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200908 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100909};
910
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200911static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100912 /* pin sensing on HP jack */
913 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200914 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100915};
916
Tobin Davisc9b443d2006-11-14 12:13:39 +0100917#ifdef CONFIG_SND_DEBUG
918/* Test configuration for debugging, modelled after the ALC260 test
919 * configuration.
920 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200921static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100922 .num_items = 5,
923 .items = {
924 { "MIXER", 0x0 },
925 { "MIC1 pin", 0x1 },
926 { "LINE1 pin", 0x2 },
927 { "HP-OUT pin", 0x3 },
928 { "CD pin", 0x4 },
929 },
930};
931
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200932static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100933
934 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100935 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
936 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100937 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
938 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
939 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
940 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941
942 /* Modes for retasking pin widgets */
943 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
944 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
945
Tobin Davis82f30042007-02-13 12:45:44 +0100946 /* EAPD Switch Control */
947 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
948
Tobin Davisc9b443d2006-11-14 12:13:39 +0100949 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100950
Tobin Davis7f296732007-03-12 11:39:01 +0100951 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
952 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
953 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
954 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
955 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
956 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
957 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
958 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
959 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
960 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100961 {
962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
963 .name = "Input Source",
964 .info = conexant_mux_enum_info,
965 .get = conexant_mux_enum_get,
966 .put = conexant_mux_enum_put,
967 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200968 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200969 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
970 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100971 { } /* end */
972};
973
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200974static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100975 /* Set connections */
976 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
977 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
978 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100979 /* Enable retasking pins as output, initially without power amp */
980 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100981 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100982
983 /* Disable digital (SPDIF) pins initially, but users can enable
984 * them via a mixer switch. In the case of SPDIF-out, this initverb
985 * payload also sets the generation to 0, output to be in "consumer"
986 * PCM format, copyright asserted, no pre-emphasis and no validity
987 * control.
988 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100989 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
990 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100991
992 /* Start with output sum widgets muted and their output gains at min */
993 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
994 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
995
996 /* Unmute retasking pin widget output buffers since the default
997 * state appears to be output. As the pin mode is changed by the
998 * user the pin mode control will take care of enabling the pin's
999 * input/output buffers as needed.
1000 */
1001 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1002 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1003
1004 /* Mute capture amp left and right */
1005 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1006
1007 /* Set ADC connection select to match default mixer setting (mic1
1008 * pin)
1009 */
1010 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001011 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001012
1013 /* Mute all inputs to mixer widget (even unconnected ones) */
1014 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1015 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1017 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1018 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1019
1020 { }
1021};
1022#endif
1023
1024
1025/* initialize jack-sensing, too */
1026static int cxt5045_init(struct hda_codec *codec)
1027{
1028 conexant_init(codec);
1029 cxt5045_hp_automute(codec);
1030 return 0;
1031}
1032
1033
1034enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001035 CXT5045_LAPTOP_HPSENSE,
1036 CXT5045_LAPTOP_MICSENSE,
1037 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001038 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001039 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001040#ifdef CONFIG_SND_DEBUG
1041 CXT5045_TEST,
1042#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001043 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001044 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001045};
1046
Takashi Iwaiea734962011-01-17 11:29:34 +01001047static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001048 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1049 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1050 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1051 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001052 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001053#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001054 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001056 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001057};
1058
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001059static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001060 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001061 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001062 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001063 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1064 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001065 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1066 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001067 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1068 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1069 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001070 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1071 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001072 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073 {}
1074};
1075
1076static int patch_cxt5045(struct hda_codec *codec)
1077{
1078 struct conexant_spec *spec;
1079 int board_config;
1080
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001081 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1082 cxt5045_models,
1083 cxt5045_cfg_tbl);
1084 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001085 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001086 if (board_config == CXT5045_AUTO)
1087 return patch_conexant_auto(codec);
1088
Tobin Davisc9b443d2006-11-14 12:13:39 +01001089 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1090 if (!spec)
1091 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001092 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001093 codec->pin_amp_workaround = 1;
Michael Karcher4f324562012-04-06 15:34:15 +02001094 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001095
1096 spec->multiout.max_channels = 2;
1097 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1098 spec->multiout.dac_nids = cxt5045_dac_nids;
1099 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1100 spec->num_adc_nids = 1;
1101 spec->adc_nids = cxt5045_adc_nids;
1102 spec->capsrc_nids = cxt5045_capsrc_nids;
1103 spec->input_mux = &cxt5045_capture_source;
1104 spec->num_mixers = 1;
1105 spec->mixers[0] = cxt5045_mixers;
1106 spec->num_init_verbs = 1;
1107 spec->init_verbs[0] = cxt5045_init_verbs;
1108 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001109 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1110 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001111
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001112 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113
1114 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001115
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001117 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001118 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001119 spec->input_mux = &cxt5045_capture_source;
1120 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001121 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1122 spec->mixers[0] = cxt5045_mixers;
1123 codec->patch_ops.init = cxt5045_init;
1124 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001125 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001126 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001127 spec->input_mux = &cxt5045_capture_source;
1128 spec->num_init_verbs = 2;
1129 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001130 spec->mixers[0] = cxt5045_mixers;
1131 codec->patch_ops.init = cxt5045_init;
1132 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001133 default:
1134 case CXT5045_LAPTOP_HPMICSENSE:
1135 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1136 spec->input_mux = &cxt5045_capture_source;
1137 spec->num_init_verbs = 3;
1138 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1139 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1140 spec->mixers[0] = cxt5045_mixers;
1141 codec->patch_ops.init = cxt5045_init;
1142 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001143 case CXT5045_BENQ:
1144 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1145 spec->input_mux = &cxt5045_capture_source_benq;
1146 spec->num_init_verbs = 1;
1147 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1148 spec->mixers[0] = cxt5045_mixers;
1149 spec->mixers[1] = cxt5045_benq_mixers;
1150 spec->num_mixers = 2;
1151 codec->patch_ops.init = cxt5045_init;
1152 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001153 case CXT5045_LAPTOP_HP530:
1154 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1155 spec->input_mux = &cxt5045_capture_source_hp530;
1156 spec->num_init_verbs = 2;
1157 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1158 spec->mixers[0] = cxt5045_mixers_hp530;
1159 codec->patch_ops.init = cxt5045_init;
1160 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001161#ifdef CONFIG_SND_DEBUG
1162 case CXT5045_TEST:
1163 spec->input_mux = &cxt5045_test_capture_source;
1164 spec->mixers[0] = cxt5045_test_mixer;
1165 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001166 break;
1167
Tobin Davisc9b443d2006-11-14 12:13:39 +01001168#endif
1169 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001170
Takashi Iwai031005f2008-06-26 14:49:58 +02001171 switch (codec->subsystem_id >> 16) {
1172 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001173 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001174 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001175 case 0x17aa:
1176 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1177 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1178 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001179 */
1180 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1181 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1182 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1183 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1184 (1 << AC_AMPCAP_MUTE_SHIFT));
1185 break;
1186 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001187
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001188 if (spec->beep_amp)
1189 snd_hda_attach_beep_device(codec, spec->beep_amp);
1190
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191 return 0;
1192}
1193
1194
1195/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001196#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001198static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1199static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1200static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001202static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001203 { 2, NULL },
1204};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001206static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001207 .num_items = 2,
1208 .items = {
1209 { "ExtMic", 0x2 },
1210 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001211 }
1212};
1213
1214/* turn on/off EAPD (+ mute HP) as a master switch */
1215static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1216 struct snd_ctl_elem_value *ucontrol)
1217{
1218 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1219 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001220 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001221
Tobin Davis82f30042007-02-13 12:45:44 +01001222 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223 return 0;
1224
Tobin Davis82f30042007-02-13 12:45:44 +01001225 /* toggle internal speakers mute depending of presence of
1226 * the headphone jack
1227 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001228 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001229 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1230 * pin widgets unlike other codecs. In this case, we need to
1231 * set index 0x01 for the volume from the mixer amp 0x19.
1232 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001233 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001234 HDA_AMP_MUTE, bits);
1235 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1236 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1237 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001238 return 1;
1239}
1240
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241/* mute internal speaker if HP is plugged */
1242static void cxt5047_hp_automute(struct hda_codec *codec)
1243{
Tobin Davis82f30042007-02-13 12:45:44 +01001244 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001245 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001246
Takashi Iwaid56757a2009-11-18 08:00:14 +01001247 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001248
Takashi Iwai47fd8302007-08-10 17:11:07 +02001249 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001250 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001251 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001252 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253}
1254
1255/* toggle input of built-in and mic jack appropriately */
1256static void cxt5047_hp_automic(struct hda_codec *codec)
1257{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001258 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001259 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1260 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001261 {}
1262 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001263 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001264 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1265 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001266 {}
1267 };
1268 unsigned int present;
1269
Takashi Iwaid56757a2009-11-18 08:00:14 +01001270 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001271 if (present)
1272 snd_hda_sequence_write(codec, mic_jack_on);
1273 else
1274 snd_hda_sequence_write(codec, mic_jack_off);
1275}
1276
1277/* unsolicited event for HP jack sensing */
1278static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1279 unsigned int res)
1280{
Marc Boucher9f113e02008-01-22 15:18:08 +01001281 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282 case CONEXANT_HP_EVENT:
1283 cxt5047_hp_automute(codec);
1284 break;
1285 case CONEXANT_MIC_EVENT:
1286 cxt5047_hp_automic(codec);
1287 break;
1288 }
1289}
1290
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001291static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001292 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1293 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001294 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001295 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1296 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1297 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1298 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001299 {
1300 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1301 .name = "Master Playback Switch",
1302 .info = cxt_eapd_info,
1303 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001304 .put = cxt5047_hp_master_sw_put,
1305 .private_value = 0x13,
1306 },
1307
1308 {}
1309};
1310
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001311static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001312 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001313 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001314 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1315 {}
1316};
1317
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001318static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001319 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001320 { } /* end */
1321};
1322
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001323static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001324 /* Line in, Mic, Built-in Mic */
1325 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1326 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1327 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001328 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001329 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001330 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1331 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001332 /* Record selector: Mic */
1333 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1334 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1335 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1336 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001337 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1338 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1339 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1340 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001341 /* SPDIF route: PCM */
1342 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001343 /* Enable unsolicited events */
1344 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1345 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 { } /* end */
1347};
1348
1349/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001350static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001351 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001352 {}
1353};
1354
1355/* Test configuration for debugging, modelled after the ALC260 test
1356 * configuration.
1357 */
1358#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001359static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001360 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001361 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001362 { "LINE1 pin", 0x0 },
1363 { "MIC1 pin", 0x1 },
1364 { "MIC2 pin", 0x2 },
1365 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 },
1367};
1368
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001369static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370
1371 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001372 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1374 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1375 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001376 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1377 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1378 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001380 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1381 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1382 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1383 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001384
1385 /* Modes for retasking pin widgets */
1386 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1387 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1388
Tobin Davis82f30042007-02-13 12:45:44 +01001389 /* EAPD Switch Control */
1390 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1391
Tobin Davisc9b443d2006-11-14 12:13:39 +01001392 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001393 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1394 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1395 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1396 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1397 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1398 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1399 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1400 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001401
Tobin Davis82f30042007-02-13 12:45:44 +01001402 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1403 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1404 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1405 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1406 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1407 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1408 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1409 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410 {
1411 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1412 .name = "Input Source",
1413 .info = conexant_mux_enum_info,
1414 .get = conexant_mux_enum_get,
1415 .put = conexant_mux_enum_put,
1416 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001417 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001418
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419 { } /* end */
1420};
1421
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001422static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001423 /* Enable retasking pins as output, initially without power amp */
1424 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1425 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1427
1428 /* Disable digital (SPDIF) pins initially, but users can enable
1429 * them via a mixer switch. In the case of SPDIF-out, this initverb
1430 * payload also sets the generation to 0, output to be in "consumer"
1431 * PCM format, copyright asserted, no pre-emphasis and no validity
1432 * control.
1433 */
1434 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1435
1436 /* Ensure mic1, mic2, line1 pin widgets take input from the
1437 * OUT1 sum bus when acting as an output.
1438 */
1439 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1440 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1441
1442 /* Start with output sum widgets muted and their output gains at min */
1443 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1444 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1445
1446 /* Unmute retasking pin widget output buffers since the default
1447 * state appears to be output. As the pin mode is changed by the
1448 * user the pin mode control will take care of enabling the pin's
1449 * input/output buffers as needed.
1450 */
1451 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1452 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1453 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1454
1455 /* Mute capture amp left and right */
1456 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1457
1458 /* Set ADC connection select to match default mixer setting (mic1
1459 * pin)
1460 */
1461 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1462
1463 /* Mute all inputs to mixer widget (even unconnected ones) */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1468 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1470 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1471 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1472
1473 { }
1474};
1475#endif
1476
1477
1478/* initialize jack-sensing, too */
1479static int cxt5047_hp_init(struct hda_codec *codec)
1480{
1481 conexant_init(codec);
1482 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001483 return 0;
1484}
1485
1486
1487enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001488 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1489 CXT5047_LAPTOP_HP, /* Some HP laptops */
1490 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001491#ifdef CONFIG_SND_DEBUG
1492 CXT5047_TEST,
1493#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001494 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001495 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001496};
1497
Takashi Iwaiea734962011-01-17 11:29:34 +01001498static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001499 [CXT5047_LAPTOP] = "laptop",
1500 [CXT5047_LAPTOP_HP] = "laptop-hp",
1501 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001502#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001503 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001504#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001505 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001506};
1507
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001508static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001509 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001510 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1511 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001512 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001513 {}
1514};
1515
1516static int patch_cxt5047(struct hda_codec *codec)
1517{
1518 struct conexant_spec *spec;
1519 int board_config;
1520
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001521 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1522 cxt5047_models,
1523 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001524 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001525 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001526 if (board_config == CXT5047_AUTO)
1527 return patch_conexant_auto(codec);
1528
Tobin Davisc9b443d2006-11-14 12:13:39 +01001529 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1530 if (!spec)
1531 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001532 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001533 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001534
1535 spec->multiout.max_channels = 2;
1536 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1537 spec->multiout.dac_nids = cxt5047_dac_nids;
1538 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1539 spec->num_adc_nids = 1;
1540 spec->adc_nids = cxt5047_adc_nids;
1541 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001542 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001543 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544 spec->num_init_verbs = 1;
1545 spec->init_verbs[0] = cxt5047_init_verbs;
1546 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001547 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1548 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001549
1550 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001551
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552 switch (board_config) {
1553 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001554 spec->num_mixers = 2;
1555 spec->mixers[1] = cxt5047_hp_spk_mixers;
1556 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557 break;
1558 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001559 spec->num_mixers = 2;
1560 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001561 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001562 codec->patch_ops.init = cxt5047_hp_init;
1563 break;
1564 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001565 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001566 spec->num_mixers = 2;
1567 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001568 spec->num_init_verbs = 2;
1569 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001570 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001571 break;
1572#ifdef CONFIG_SND_DEBUG
1573 case CXT5047_TEST:
1574 spec->input_mux = &cxt5047_test_capture_source;
1575 spec->mixers[0] = cxt5047_test_mixer;
1576 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001577 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001578#endif
1579 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001580 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001581
1582 switch (codec->subsystem_id >> 16) {
1583 case 0x103c:
1584 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1585 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1586 * with 0 dB offset 0x17)
1587 */
1588 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1589 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1590 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1591 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1592 (1 << AC_AMPCAP_MUTE_SHIFT));
1593 break;
1594 }
1595
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596 return 0;
1597}
1598
Takashi Iwai461e2c72008-01-25 11:35:17 +01001599/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001600static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1601static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001602
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001603static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001604 { 2, NULL },
1605};
1606
1607static void cxt5051_update_speaker(struct hda_codec *codec)
1608{
1609 struct conexant_spec *spec = codec->spec;
1610 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001611 /* headphone pin */
1612 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1613 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1614 pinctl);
1615 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001616 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1617 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1618 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001619 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1620 if (spec->ideapad)
1621 snd_hda_codec_write(codec, 0x1b, 0,
1622 AC_VERB_SET_PIN_WIDGET_CONTROL,
1623 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001624}
1625
1626/* turn on/off EAPD (+ mute HP) as a master switch */
1627static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1628 struct snd_ctl_elem_value *ucontrol)
1629{
1630 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1631
1632 if (!cxt_eapd_put(kcontrol, ucontrol))
1633 return 0;
1634 cxt5051_update_speaker(codec);
1635 return 1;
1636}
1637
1638/* toggle input of built-in and mic jack appropriately */
1639static void cxt5051_portb_automic(struct hda_codec *codec)
1640{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001641 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001642 unsigned int present;
1643
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001644 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001645 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001646 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001647 snd_hda_codec_write(codec, 0x14, 0,
1648 AC_VERB_SET_CONNECT_SEL,
1649 present ? 0x01 : 0x00);
1650}
1651
1652/* switch the current ADC according to the jack state */
1653static void cxt5051_portc_automic(struct hda_codec *codec)
1654{
1655 struct conexant_spec *spec = codec->spec;
1656 unsigned int present;
1657 hda_nid_t new_adc;
1658
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001659 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001660 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001661 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001662 if (present)
1663 spec->cur_adc_idx = 1;
1664 else
1665 spec->cur_adc_idx = 0;
1666 new_adc = spec->adc_nids[spec->cur_adc_idx];
1667 if (spec->cur_adc && spec->cur_adc != new_adc) {
1668 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001669 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001670 spec->cur_adc = new_adc;
1671 snd_hda_codec_setup_stream(codec, new_adc,
1672 spec->cur_adc_stream_tag, 0,
1673 spec->cur_adc_format);
1674 }
1675}
1676
1677/* mute internal speaker if HP is plugged */
1678static void cxt5051_hp_automute(struct hda_codec *codec)
1679{
1680 struct conexant_spec *spec = codec->spec;
1681
Takashi Iwaid56757a2009-11-18 08:00:14 +01001682 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001683 cxt5051_update_speaker(codec);
1684}
1685
1686/* unsolicited event for HP jack sensing */
1687static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1688 unsigned int res)
1689{
1690 switch (res >> 26) {
1691 case CONEXANT_HP_EVENT:
1692 cxt5051_hp_automute(codec);
1693 break;
1694 case CXT5051_PORTB_EVENT:
1695 cxt5051_portb_automic(codec);
1696 break;
1697 case CXT5051_PORTC_EVENT:
1698 cxt5051_portc_automic(codec);
1699 break;
1700 }
1701}
1702
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001703static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001704 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1705 {
1706 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1707 .name = "Master Playback Switch",
1708 .info = cxt_eapd_info,
1709 .get = cxt_eapd_get,
1710 .put = cxt5051_hp_master_sw_put,
1711 .private_value = 0x1a,
1712 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001713 {}
1714};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001716static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001717 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1718 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001719 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1720 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001721 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1722 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723 {}
1724};
1725
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001726static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001727 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1728 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001729 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1730 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001731 {}
1732};
1733
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001734static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001735 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001737 {}
1738};
1739
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001740static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001741 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1742 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001743 {}
1744};
1745
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001746static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001747 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1748 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001749 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1750 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001751 {}
1752};
1753
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001754static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001755 /* Line in, Mic */
1756 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1757 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1758 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1759 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1760 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1761 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1762 /* SPK */
1763 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1764 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1765 /* HP, Amp */
1766 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1767 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1768 /* DAC1 */
1769 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001770 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1773 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1774 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001775 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001776 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1777 /* EAPD */
1778 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1779 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001780 { } /* end */
1781};
1782
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001783static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001784 /* Line in, Mic */
1785 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1786 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1787 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1788 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1789 /* SPK */
1790 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1791 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1792 /* HP, Amp */
1793 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1794 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1795 /* DAC1 */
1796 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001797 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001798 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1799 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1800 /* SPDIF route: PCM */
1801 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1802 /* EAPD */
1803 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1804 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001805 { } /* end */
1806};
1807
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001808static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001809 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001810 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001811 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1812 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1813 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1814 /* SPK */
1815 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1816 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1817 /* HP, Amp */
1818 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1819 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1820 /* DAC1 */
1821 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001822 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1824 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1825 /* SPDIF route: PCM */
1826 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1827 /* EAPD */
1828 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1829 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001830 { } /* end */
1831};
1832
Takashi Iwai6953e552010-01-24 11:00:27 +01001833static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1834 unsigned int event)
1835{
1836 snd_hda_codec_write(codec, nid, 0,
1837 AC_VERB_SET_UNSOLICITED_ENABLE,
1838 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001839}
1840
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001841static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001842 /* Subwoofer */
1843 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1844 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1845 { } /* end */
1846};
1847
Takashi Iwai461e2c72008-01-25 11:35:17 +01001848/* initialize jack-sensing, too */
1849static int cxt5051_init(struct hda_codec *codec)
1850{
Takashi Iwai6953e552010-01-24 11:00:27 +01001851 struct conexant_spec *spec = codec->spec;
1852
Takashi Iwai461e2c72008-01-25 11:35:17 +01001853 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001854
1855 if (spec->auto_mic & AUTO_MIC_PORTB)
1856 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1857 if (spec->auto_mic & AUTO_MIC_PORTC)
1858 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1859
Takashi Iwai461e2c72008-01-25 11:35:17 +01001860 if (codec->patch_ops.unsol_event) {
1861 cxt5051_hp_automute(codec);
1862 cxt5051_portb_automic(codec);
1863 cxt5051_portc_automic(codec);
1864 }
1865 return 0;
1866}
1867
1868
1869enum {
1870 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1871 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001872 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001873 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001874 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001875 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001876 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001877 CXT5051_MODELS
1878};
1879
Takashi Iwaiea734962011-01-17 11:29:34 +01001880static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001881 [CXT5051_LAPTOP] = "laptop",
1882 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001883 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001884 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001885 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001886 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001887 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001888};
1889
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001890static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001891 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001892 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001893 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001894 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001895 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1896 CXT5051_LAPTOP),
1897 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001898 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001899 {}
1900};
1901
1902static int patch_cxt5051(struct hda_codec *codec)
1903{
1904 struct conexant_spec *spec;
1905 int board_config;
1906
Takashi Iwai6764bce2011-05-13 16:52:25 +02001907 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1908 cxt5051_models,
1909 cxt5051_cfg_tbl);
1910 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001911 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001912 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001913 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001914
Takashi Iwai461e2c72008-01-25 11:35:17 +01001915 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1916 if (!spec)
1917 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001918 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001919 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001920
1921 codec->patch_ops = conexant_patch_ops;
1922 codec->patch_ops.init = cxt5051_init;
1923
1924 spec->multiout.max_channels = 2;
1925 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1926 spec->multiout.dac_nids = cxt5051_dac_nids;
1927 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1928 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1929 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001930 spec->num_mixers = 2;
1931 spec->mixers[0] = cxt5051_capture_mixers;
1932 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001933 spec->num_init_verbs = 1;
1934 spec->init_verbs[0] = cxt5051_init_verbs;
1935 spec->spdif_route = 0;
1936 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1937 spec->channel_mode = cxt5051_modes;
1938 spec->cur_adc = 0;
1939 spec->cur_adc_idx = 0;
1940
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001941 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1942
Takashi Iwai79d7d532009-03-04 09:03:50 +01001943 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1944
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001945 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001946 switch (board_config) {
1947 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001948 spec->mixers[0] = cxt5051_hp_mixers;
1949 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001950 case CXT5051_HP_DV6736:
1951 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1952 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001953 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001954 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001955 case CXT5051_F700:
1956 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1957 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001958 spec->auto_mic = 0;
1959 break;
1960 case CXT5051_TOSHIBA:
1961 spec->mixers[0] = cxt5051_toshiba_mixers;
1962 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001963 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001964 case CXT5051_IDEAPAD:
1965 spec->init_verbs[spec->num_init_verbs++] =
1966 cxt5051_ideapad_init_verbs;
1967 spec->ideapad = 1;
1968 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001969 }
1970
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001971 if (spec->beep_amp)
1972 snd_hda_attach_beep_device(codec, spec->beep_amp);
1973
Takashi Iwai461e2c72008-01-25 11:35:17 +01001974 return 0;
1975}
1976
Daniel Drake0fb67e92009-07-16 14:46:57 +01001977/* Conexant 5066 specific */
1978
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001979static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1980static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1981static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1982static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001983
Daniel Drakedbaccc02009-11-09 15:17:24 +00001984/* OLPC's microphone port is DC coupled for use with external sensors,
1985 * therefore we use a 50% mic bias in order to center the input signal with
1986 * the DC input range of the codec. */
1987#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1988
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001989static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001990 { 2, NULL },
1991};
1992
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001993#define HP_PRESENT_PORT_A (1 << 0)
1994#define HP_PRESENT_PORT_D (1 << 1)
1995#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1996#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1997
Daniel Drake0fb67e92009-07-16 14:46:57 +01001998static void cxt5066_update_speaker(struct hda_codec *codec)
1999{
2000 struct conexant_spec *spec = codec->spec;
2001 unsigned int pinctl;
2002
John Baboval3a253442010-12-02 11:21:31 -05002003 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2004 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002005
2006 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002007 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002008 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2009 pinctl);
2010
2011 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002012 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2013 if (spec->dell_automute || spec->thinkpad) {
2014 /* Mute if Port A is connected */
2015 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002016 pinctl = 0;
2017 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002018 /* Thinkpad/Dell doesn't give pin-D status */
2019 if (!hp_port_d_present(spec))
2020 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002021 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002022 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2023 pinctl);
2024
2025 /* CLASS_D AMP */
2026 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2027 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2028 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002029}
2030
2031/* turn on/off EAPD (+ mute HP) as a master switch */
2032static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2033 struct snd_ctl_elem_value *ucontrol)
2034{
2035 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2036
2037 if (!cxt_eapd_put(kcontrol, ucontrol))
2038 return 0;
2039
2040 cxt5066_update_speaker(codec);
2041 return 1;
2042}
2043
Daniel Drakec4cfe662010-01-07 13:47:04 +01002044static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2045 .num_items = 3,
2046 .items = {
2047 { "Off", PIN_IN },
2048 { "50%", PIN_VREF50 },
2049 { "80%", PIN_VREF80 },
2050 },
2051};
2052
2053static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2054{
2055 struct conexant_spec *spec = codec->spec;
2056 /* Even though port F is the DC input, the bias is controlled on port B.
2057 * we also leave that port as an active input (but unselected) in DC mode
2058 * just in case that is necessary to make the bias setting take effect. */
2059 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2060 AC_VERB_SET_PIN_WIDGET_CONTROL,
2061 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2062}
2063
Daniel Drake75f89912010-01-07 13:46:25 +01002064/* OLPC defers mic widget control until when capture is started because the
2065 * microphone LED comes on as soon as these settings are put in place. if we
2066 * did this before recording, it would give the false indication that recording
2067 * is happening when it is not. */
2068static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002069{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002070 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002071 if (!spec->recording)
2072 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002073
Daniel Drakec4cfe662010-01-07 13:47:04 +01002074 if (spec->dc_enable) {
2075 /* in DC mode we ignore presence detection and just use the jack
2076 * through our special DC port */
2077 const struct hda_verb enable_dc_mode[] = {
2078 /* disble internal mic, port C */
2079 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2080
2081 /* enable DC capture, port F */
2082 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2083 {},
2084 };
2085
2086 snd_hda_sequence_write(codec, enable_dc_mode);
2087 /* port B input disabled (and bias set) through the following call */
2088 cxt5066_set_olpc_dc_bias(codec);
2089 return;
2090 }
2091
2092 /* disable DC (port F) */
2093 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2094
Daniel Drake75f89912010-01-07 13:46:25 +01002095 /* external mic, port B */
2096 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2097 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002098
Daniel Drake75f89912010-01-07 13:46:25 +01002099 /* internal mic, port C */
2100 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2101 spec->ext_mic_present ? 0 : PIN_VREF80);
2102}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002103
Daniel Drake75f89912010-01-07 13:46:25 +01002104/* toggle input of built-in and mic jack appropriately */
2105static void cxt5066_olpc_automic(struct hda_codec *codec)
2106{
2107 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002108 unsigned int present;
2109
Daniel Drakec4cfe662010-01-07 13:47:04 +01002110 if (spec->dc_enable) /* don't do presence detection in DC mode */
2111 return;
2112
Daniel Drake75f89912010-01-07 13:46:25 +01002113 present = snd_hda_codec_read(codec, 0x1a, 0,
2114 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2115 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002116 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002117 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002118 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002119
2120 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2121 present ? 0 : 1);
2122 spec->ext_mic_present = !!present;
2123
2124 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002125}
2126
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002127/* toggle input of built-in digital mic and mic jack appropriately */
2128static void cxt5066_vostro_automic(struct hda_codec *codec)
2129{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002130 unsigned int present;
2131
2132 struct hda_verb ext_mic_present[] = {
2133 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002134 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002135
2136 /* switch to external mic input */
2137 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2138 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2139
2140 /* disable internal digital mic */
2141 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2142 {}
2143 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002144 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002145 /* enable internal mic, port C */
2146 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2147
2148 /* switch to internal mic input */
2149 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2150
2151 /* disable external mic, port B */
2152 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2153 {}
2154 };
2155
2156 present = snd_hda_jack_detect(codec, 0x1a);
2157 if (present) {
2158 snd_printdd("CXT5066: external microphone detected\n");
2159 snd_hda_sequence_write(codec, ext_mic_present);
2160 } else {
2161 snd_printdd("CXT5066: external microphone absent\n");
2162 snd_hda_sequence_write(codec, ext_mic_absent);
2163 }
2164}
2165
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002166/* toggle input of built-in digital mic and mic jack appropriately */
2167static void cxt5066_ideapad_automic(struct hda_codec *codec)
2168{
2169 unsigned int present;
2170
2171 struct hda_verb ext_mic_present[] = {
2172 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2173 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2174 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2175 {}
2176 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002177 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002178 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2179 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2180 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2181 {}
2182 };
2183
2184 present = snd_hda_jack_detect(codec, 0x1b);
2185 if (present) {
2186 snd_printdd("CXT5066: external microphone detected\n");
2187 snd_hda_sequence_write(codec, ext_mic_present);
2188 } else {
2189 snd_printdd("CXT5066: external microphone absent\n");
2190 snd_hda_sequence_write(codec, ext_mic_absent);
2191 }
2192}
2193
David Henningssona1d69062011-01-21 13:33:28 +01002194
2195/* toggle input of built-in digital mic and mic jack appropriately */
2196static void cxt5066_asus_automic(struct hda_codec *codec)
2197{
2198 unsigned int present;
2199
2200 present = snd_hda_jack_detect(codec, 0x1b);
2201 snd_printdd("CXT5066: external microphone present=%d\n", present);
2202 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2203 present ? 1 : 0);
2204}
2205
2206
David Henningsson048e78a2010-09-02 08:35:47 +02002207/* toggle input of built-in digital mic and mic jack appropriately */
2208static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2209{
2210 unsigned int present;
2211
2212 present = snd_hda_jack_detect(codec, 0x1b);
2213 snd_printdd("CXT5066: external microphone present=%d\n", present);
2214 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2215 present ? 1 : 3);
2216}
2217
2218
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002219/* toggle input of built-in digital mic and mic jack appropriately
2220 order is: external mic -> dock mic -> interal mic */
2221static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2222{
2223 unsigned int ext_present, dock_present;
2224
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002225 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002226 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2227 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2228 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2229 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2230 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2231 {}
2232 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002233 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002234 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2235 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2236 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2237 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2239 {}
2240 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002241 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002242 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2243 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2244 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2245 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2246 {}
2247 };
2248
2249 ext_present = snd_hda_jack_detect(codec, 0x1b);
2250 dock_present = snd_hda_jack_detect(codec, 0x1a);
2251 if (ext_present) {
2252 snd_printdd("CXT5066: external microphone detected\n");
2253 snd_hda_sequence_write(codec, ext_mic_present);
2254 } else if (dock_present) {
2255 snd_printdd("CXT5066: dock microphone detected\n");
2256 snd_hda_sequence_write(codec, dock_mic_present);
2257 } else {
2258 snd_printdd("CXT5066: external microphone absent\n");
2259 snd_hda_sequence_write(codec, ext_mic_absent);
2260 }
2261}
2262
Daniel Drake0fb67e92009-07-16 14:46:57 +01002263/* mute internal speaker if HP is plugged */
2264static void cxt5066_hp_automute(struct hda_codec *codec)
2265{
2266 struct conexant_spec *spec = codec->spec;
2267 unsigned int portA, portD;
2268
2269 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002270 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002271
2272 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002273 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002274
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002275 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2276 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002277 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2278 portA, portD, spec->hp_present);
2279 cxt5066_update_speaker(codec);
2280}
2281
David Henningsson02b6b5b2011-01-21 13:27:39 +01002282/* Dispatch the right mic autoswitch function */
2283static void cxt5066_automic(struct hda_codec *codec)
2284{
2285 struct conexant_spec *spec = codec->spec;
2286
2287 if (spec->dell_vostro)
2288 cxt5066_vostro_automic(codec);
2289 else if (spec->ideapad)
2290 cxt5066_ideapad_automic(codec);
2291 else if (spec->thinkpad)
2292 cxt5066_thinkpad_automic(codec);
2293 else if (spec->hp_laptop)
2294 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002295 else if (spec->asus)
2296 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002297}
2298
Daniel Drake0fb67e92009-07-16 14:46:57 +01002299/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002300static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002301{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002302 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002303 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2304 switch (res >> 26) {
2305 case CONEXANT_HP_EVENT:
2306 cxt5066_hp_automute(codec);
2307 break;
2308 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002309 /* ignore mic events in DC mode; we're always using the jack */
2310 if (!spec->dc_enable)
2311 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002312 break;
2313 }
2314}
2315
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002316/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002317static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002318{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002319 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002320 switch (res >> 26) {
2321 case CONEXANT_HP_EVENT:
2322 cxt5066_hp_automute(codec);
2323 break;
2324 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002325 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002326 break;
2327 }
2328}
2329
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002330
Daniel Drake0fb67e92009-07-16 14:46:57 +01002331static const struct hda_input_mux cxt5066_analog_mic_boost = {
2332 .num_items = 5,
2333 .items = {
2334 { "0dB", 0 },
2335 { "10dB", 1 },
2336 { "20dB", 2 },
2337 { "30dB", 3 },
2338 { "40dB", 4 },
2339 },
2340};
2341
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002342static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002343{
2344 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002345 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002346 AC_VERB_SET_AMP_GAIN_MUTE,
2347 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2348 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002349 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002350 /* adjust the internal mic as well...it is not through 0x17 */
2351 snd_hda_codec_write_cache(codec, 0x23, 0,
2352 AC_VERB_SET_AMP_GAIN_MUTE,
2353 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2354 cxt5066_analog_mic_boost.
2355 items[spec->mic_boost].index);
2356 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002357}
2358
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2360 struct snd_ctl_elem_info *uinfo)
2361{
2362 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2363}
2364
2365static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2366 struct snd_ctl_elem_value *ucontrol)
2367{
2368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002369 struct conexant_spec *spec = codec->spec;
2370 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002371 return 0;
2372}
2373
2374static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2375 struct snd_ctl_elem_value *ucontrol)
2376{
2377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002378 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002379 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2380 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002381 idx = ucontrol->value.enumerated.item[0];
2382 if (idx >= imux->num_items)
2383 idx = imux->num_items - 1;
2384
Daniel Drakec4cfe662010-01-07 13:47:04 +01002385 spec->mic_boost = idx;
2386 if (!spec->dc_enable)
2387 cxt5066_set_mic_boost(codec);
2388 return 1;
2389}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002390
Daniel Drakec4cfe662010-01-07 13:47:04 +01002391static void cxt5066_enable_dc(struct hda_codec *codec)
2392{
2393 const struct hda_verb enable_dc_mode[] = {
2394 /* disable gain */
2395 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2396
2397 /* switch to DC input */
2398 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2399 {}
2400 };
2401
2402 /* configure as input source */
2403 snd_hda_sequence_write(codec, enable_dc_mode);
2404 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2405}
2406
2407static void cxt5066_disable_dc(struct hda_codec *codec)
2408{
2409 /* reconfigure input source */
2410 cxt5066_set_mic_boost(codec);
2411 /* automic also selects the right mic if we're recording */
2412 cxt5066_olpc_automic(codec);
2413}
2414
2415static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2416 struct snd_ctl_elem_value *ucontrol)
2417{
2418 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2419 struct conexant_spec *spec = codec->spec;
2420 ucontrol->value.integer.value[0] = spec->dc_enable;
2421 return 0;
2422}
2423
2424static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2425 struct snd_ctl_elem_value *ucontrol)
2426{
2427 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2428 struct conexant_spec *spec = codec->spec;
2429 int dc_enable = !!ucontrol->value.integer.value[0];
2430
2431 if (dc_enable == spec->dc_enable)
2432 return 0;
2433
2434 spec->dc_enable = dc_enable;
2435 if (dc_enable)
2436 cxt5066_enable_dc(codec);
2437 else
2438 cxt5066_disable_dc(codec);
2439
2440 return 1;
2441}
2442
2443static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2444 struct snd_ctl_elem_info *uinfo)
2445{
2446 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2447}
2448
2449static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2450 struct snd_ctl_elem_value *ucontrol)
2451{
2452 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2453 struct conexant_spec *spec = codec->spec;
2454 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2455 return 0;
2456}
2457
2458static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2459 struct snd_ctl_elem_value *ucontrol)
2460{
2461 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2462 struct conexant_spec *spec = codec->spec;
2463 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2464 unsigned int idx;
2465
2466 idx = ucontrol->value.enumerated.item[0];
2467 if (idx >= imux->num_items)
2468 idx = imux->num_items - 1;
2469
2470 spec->dc_input_bias = idx;
2471 if (spec->dc_enable)
2472 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002473 return 1;
2474}
2475
Daniel Drake75f89912010-01-07 13:46:25 +01002476static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2477{
2478 struct conexant_spec *spec = codec->spec;
2479 /* mark as recording and configure the microphone widget so that the
2480 * recording LED comes on. */
2481 spec->recording = 1;
2482 cxt5066_olpc_select_mic(codec);
2483}
2484
2485static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2486{
2487 struct conexant_spec *spec = codec->spec;
2488 const struct hda_verb disable_mics[] = {
2489 /* disable external mic, port B */
2490 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2491
2492 /* disble internal mic, port C */
2493 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002494
2495 /* disable DC capture, port F */
2496 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002497 {},
2498 };
2499
2500 snd_hda_sequence_write(codec, disable_mics);
2501 spec->recording = 0;
2502}
2503
Andy Robinsonf6a24912011-01-24 10:12:37 -05002504static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002505 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002506 int num_pins)
2507{
2508 struct conexant_spec *spec = codec->spec;
2509 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2510 int i;
2511
2512 for (i = 0; i < num_pins; i++, dig_pins++) {
2513 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2514 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2515 continue;
2516 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2517 continue;
2518 if (spec->slave_dig_outs[0])
2519 nid_loc++;
2520 else
2521 nid_loc = spec->slave_dig_outs;
2522 }
2523}
2524
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002525static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002526 .num_items = 4,
2527 .items = {
2528 { "Mic B", 0 },
2529 { "Mic C", 1 },
2530 { "Mic E", 2 },
2531 { "Mic F", 3 },
2532 },
2533};
2534
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002535static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002536 .ops = &snd_hda_bind_vol,
2537 .values = {
2538 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2539 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2540 0
2541 },
2542};
2543
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002544static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002545 .ops = &snd_hda_bind_sw,
2546 .values = {
2547 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2548 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2549 0
2550 },
2551};
2552
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002553static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002554 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2555 {}
2556};
2557
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002558static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002559 {
2560 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2561 .name = "Master Playback Volume",
2562 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2563 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2564 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002565 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002566 .info = snd_hda_mixer_amp_volume_info,
2567 .get = snd_hda_mixer_amp_volume_get,
2568 .put = snd_hda_mixer_amp_volume_put,
2569 .tlv = { .c = snd_hda_mixer_amp_tlv },
2570 /* offset by 28 volume steps to limit minimum gain to -46dB */
2571 .private_value =
2572 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2573 },
2574 {}
2575};
2576
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002577static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002578 {
2579 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2580 .name = "DC Mode Enable Switch",
2581 .info = snd_ctl_boolean_mono_info,
2582 .get = cxt5066_olpc_dc_get,
2583 .put = cxt5066_olpc_dc_put,
2584 },
2585 {
2586 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2587 .name = "DC Input Bias Enum",
2588 .info = cxt5066_olpc_dc_bias_enum_info,
2589 .get = cxt5066_olpc_dc_bias_enum_get,
2590 .put = cxt5066_olpc_dc_bias_enum_put,
2591 },
2592 {}
2593};
2594
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002595static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002596 {
2597 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2598 .name = "Master Playback Switch",
2599 .info = cxt_eapd_info,
2600 .get = cxt_eapd_get,
2601 .put = cxt5066_hp_master_sw_put,
2602 .private_value = 0x1d,
2603 },
2604
2605 {
2606 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002607 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002608 .info = cxt5066_mic_boost_mux_enum_info,
2609 .get = cxt5066_mic_boost_mux_enum_get,
2610 .put = cxt5066_mic_boost_mux_enum_put,
2611 },
2612
2613 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2614 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2615 {}
2616};
2617
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002618static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002619 {
2620 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002621 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002622 .info = cxt5066_mic_boost_mux_enum_info,
2623 .get = cxt5066_mic_boost_mux_enum_get,
2624 .put = cxt5066_mic_boost_mux_enum_put,
2625 .private_value = 0x23 | 0x100,
2626 },
2627 {}
2628};
2629
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002630static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002631 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2632 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2633 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2634 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2635
2636 /* Speakers */
2637 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2638 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2639
2640 /* HP, Amp */
2641 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2642 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2643
2644 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2645 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2646
2647 /* DAC1 */
2648 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2649
2650 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2651 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2652 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2653 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2654 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2655 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2656
2657 /* no digital microphone support yet */
2658 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2659
2660 /* Audio input selector */
2661 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2662
2663 /* SPDIF route: PCM */
2664 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2665 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2666
2667 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2668 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2669
2670 /* EAPD */
2671 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2672
2673 /* not handling these yet */
2674 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2675 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2676 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2677 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2678 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2679 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2680 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2681 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2682 { } /* end */
2683};
2684
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002685static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002686 /* Port A: headphones */
2687 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2688 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2689
2690 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002691 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002692
2693 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002694 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002695
2696 /* Port D: unused */
2697 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2698
2699 /* Port E: unused, but has primary EAPD */
2700 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2701 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2702
Daniel Drakec4cfe662010-01-07 13:47:04 +01002703 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002704 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2705
2706 /* Port G: internal speakers */
2707 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2708 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2709
2710 /* DAC1 */
2711 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2712
2713 /* DAC2: unused */
2714 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2715
2716 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2718 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2720 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2721 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2722 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2723 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2724 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2725 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2726 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2727 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2728
2729 /* Disable digital microphone port */
2730 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2731
2732 /* Audio input selectors */
2733 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2734 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2735
2736 /* Disable SPDIF */
2737 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2738 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2739
2740 /* enable unsolicited events for Port A and B */
2741 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2742 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2743 { } /* end */
2744};
2745
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002746static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002747 /* Port A: headphones */
2748 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2749 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2750
2751 /* Port B: external microphone */
2752 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2753
2754 /* Port C: unused */
2755 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2756
2757 /* Port D: unused */
2758 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2759
2760 /* Port E: unused, but has primary EAPD */
2761 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2762 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2763
2764 /* Port F: unused */
2765 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2766
2767 /* Port G: internal speakers */
2768 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2769 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2770
2771 /* DAC1 */
2772 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2773
2774 /* DAC2: unused */
2775 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2776
2777 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2781 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2782 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2784 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2785 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2786 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2787 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2788 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2789
2790 /* Digital microphone port */
2791 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2792
2793 /* Audio input selectors */
2794 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2795 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2796
2797 /* Disable SPDIF */
2798 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2799 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2800
2801 /* enable unsolicited events for Port A and B */
2802 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2803 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2804 { } /* end */
2805};
2806
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002807static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002808 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2809 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2810 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2811 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2812
2813 /* Speakers */
2814 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2815 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2816
2817 /* HP, Amp */
2818 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2819 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2820
2821 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2822 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2823
2824 /* DAC1 */
2825 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2826
2827 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2828 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2829 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2830 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2831 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2832 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2833 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2834
2835 /* Audio input selector */
2836 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2837 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2838
2839 /* SPDIF route: PCM */
2840 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2841 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2842
2843 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2844 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2845
2846 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002847 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002848
2849 /* EAPD */
2850 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2851
2852 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2853 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2854 { } /* end */
2855};
2856
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002857static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002858 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2859 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2860
2861 /* Port G: internal speakers */
2862 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2863 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2864
2865 /* Port A: HP, Amp */
2866 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2867 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2868
2869 /* Port B: Mic Dock */
2870 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2871
2872 /* Port C: Mic */
2873 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2874
2875 /* Port D: HP Dock, Amp */
2876 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2877 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2878
2879 /* DAC1 */
2880 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2881
2882 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2883 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2884 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2885 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2887 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2888 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2889
2890 /* Audio input selector */
2891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2892 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2893
2894 /* SPDIF route: PCM */
2895 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2896 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2897
2898 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2899 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2900
2901 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002902 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002903
2904 /* EAPD */
2905 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2906
2907 /* enable unsolicited events for Port A, B, C and D */
2908 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2909 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2910 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2911 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2912 { } /* end */
2913};
2914
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002915static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002916 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2917 { } /* end */
2918};
2919
David Henningsson048e78a2010-09-02 08:35:47 +02002920
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002921static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002922 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2923 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2924 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2925 { } /* end */
2926};
2927
Daniel Drake0fb67e92009-07-16 14:46:57 +01002928/* initialize jack-sensing, too */
2929static int cxt5066_init(struct hda_codec *codec)
2930{
2931 snd_printdd("CXT5066: init\n");
2932 conexant_init(codec);
2933 if (codec->patch_ops.unsol_event) {
2934 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002935 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002936 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002937 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002938 return 0;
2939}
2940
Daniel Drake75f89912010-01-07 13:46:25 +01002941static int cxt5066_olpc_init(struct hda_codec *codec)
2942{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002943 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002944 snd_printdd("CXT5066: init\n");
2945 conexant_init(codec);
2946 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002947 if (!spec->dc_enable) {
2948 cxt5066_set_mic_boost(codec);
2949 cxt5066_olpc_automic(codec);
2950 } else {
2951 cxt5066_enable_dc(codec);
2952 }
Daniel Drake75f89912010-01-07 13:46:25 +01002953 return 0;
2954}
2955
Daniel Drake0fb67e92009-07-16 14:46:57 +01002956enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002957 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002958 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2959 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002960 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002961 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002962 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002963 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002964 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002965 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002966 CXT5066_MODELS
2967};
2968
Takashi Iwaiea734962011-01-17 11:29:34 +01002969static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002970 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002971 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2972 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002973 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002974 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002975 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002976 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002977 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002978 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002979};
2980
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002981static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02002982 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002983 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002984 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002985 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002986 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02002987 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002988 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002989 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2990 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002991 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002992 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002993 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002994 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002995 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002996 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002997 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2998 CXT5066_LAPTOP),
2999 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003000 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003001 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003002 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson29c5fbb2012-01-23 16:39:55 +01003003 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO),
Daniel Suchyca201c02011-10-18 11:09:44 +02003004 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02003005 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003006 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003007 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003008 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003009 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003010 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003011 {}
3012};
3013
3014static int patch_cxt5066(struct hda_codec *codec)
3015{
3016 struct conexant_spec *spec;
3017 int board_config;
3018
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003019 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3020 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003021 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003022 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003023 if (board_config == CXT5066_AUTO)
3024 return patch_conexant_auto(codec);
3025
Daniel Drake0fb67e92009-07-16 14:46:57 +01003026 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3027 if (!spec)
3028 return -ENOMEM;
3029 codec->spec = spec;
3030
3031 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003032 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003033
3034 spec->dell_automute = 0;
3035 spec->multiout.max_channels = 2;
3036 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3037 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003038 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3039 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003040 spec->num_adc_nids = 1;
3041 spec->adc_nids = cxt5066_adc_nids;
3042 spec->capsrc_nids = cxt5066_capsrc_nids;
3043 spec->input_mux = &cxt5066_capture_source;
3044
3045 spec->port_d_mode = PIN_HP;
3046
3047 spec->num_init_verbs = 1;
3048 spec->init_verbs[0] = cxt5066_init_verbs;
3049 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3050 spec->channel_mode = cxt5066_modes;
3051 spec->cur_adc = 0;
3052 spec->cur_adc_idx = 0;
3053
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003054 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3055
Daniel Drake0fb67e92009-07-16 14:46:57 +01003056 switch (board_config) {
3057 default:
3058 case CXT5066_LAPTOP:
3059 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3060 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3061 break;
3062 case CXT5066_DELL_LAPTOP:
3063 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3064 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3065
3066 spec->port_d_mode = PIN_OUT;
3067 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3068 spec->num_init_verbs++;
3069 spec->dell_automute = 1;
3070 break;
David Henningssona1d69062011-01-21 13:33:28 +01003071 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003072 case CXT5066_HP_LAPTOP:
3073 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003074 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003075 spec->init_verbs[spec->num_init_verbs] =
3076 cxt5066_init_verbs_hp_laptop;
3077 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003078 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3079 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003080 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3081 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3082 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003083 if (board_config == CXT5066_HP_LAPTOP)
3084 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003085 /* input source automatically selected */
3086 spec->input_mux = NULL;
3087 spec->port_d_mode = 0;
3088 spec->mic_boost = 3; /* default 30dB gain */
3089 break;
3090
Daniel Drake0fb67e92009-07-16 14:46:57 +01003091 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003092 codec->patch_ops.init = cxt5066_olpc_init;
3093 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003094 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3095 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003096 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003097 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3098 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003099 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003100
3101 /* no S/PDIF out */
3102 spec->multiout.dig_out_nid = 0;
3103
3104 /* input source automatically selected */
3105 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003106
3107 /* our capture hooks which allow us to turn on the microphone LED
3108 * at the right time */
3109 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3110 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003111 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003112 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003113 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003114 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003115 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3116 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3117 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003118 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003119 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003120 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003121 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003122
3123 /* no S/PDIF out */
3124 spec->multiout.dig_out_nid = 0;
3125
3126 /* input source automatically selected */
3127 spec->input_mux = NULL;
3128 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003129 case CXT5066_IDEAPAD:
3130 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003131 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003132 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3133 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3134 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3135 spec->port_d_mode = 0;
3136 spec->ideapad = 1;
3137 spec->mic_boost = 2; /* default 20dB gain */
3138
3139 /* no S/PDIF out */
3140 spec->multiout.dig_out_nid = 0;
3141
3142 /* input source automatically selected */
3143 spec->input_mux = NULL;
3144 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003145 case CXT5066_THINKPAD:
3146 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003147 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003148 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3149 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3150 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3151 spec->thinkpad = 1;
3152 spec->port_d_mode = PIN_OUT;
3153 spec->mic_boost = 2; /* default 20dB gain */
3154
3155 /* no S/PDIF out */
3156 spec->multiout.dig_out_nid = 0;
3157
3158 /* input source automatically selected */
3159 spec->input_mux = NULL;
3160 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003161 }
3162
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003163 if (spec->beep_amp)
3164 snd_hda_attach_beep_device(codec, spec->beep_amp);
3165
Daniel Drake0fb67e92009-07-16 14:46:57 +01003166 return 0;
3167}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003168
3169/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003170 * Automatic parser for CX20641 & co
3171 */
3172
Takashi Iwai6764bce2011-05-13 16:52:25 +02003173static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3174 struct hda_codec *codec,
3175 unsigned int stream_tag,
3176 unsigned int format,
3177 struct snd_pcm_substream *substream)
3178{
3179 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003180 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003181 if (spec->adc_switching) {
3182 spec->cur_adc = adc;
3183 spec->cur_adc_stream_tag = stream_tag;
3184 spec->cur_adc_format = format;
3185 }
3186 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3187 return 0;
3188}
3189
3190static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3191 struct hda_codec *codec,
3192 struct snd_pcm_substream *substream)
3193{
3194 struct conexant_spec *spec = codec->spec;
3195 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3196 spec->cur_adc = 0;
3197 return 0;
3198}
3199
3200static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3201 .substreams = 1,
3202 .channels_min = 2,
3203 .channels_max = 2,
3204 .nid = 0, /* fill later */
3205 .ops = {
3206 .prepare = cx_auto_capture_pcm_prepare,
3207 .cleanup = cx_auto_capture_pcm_cleanup
3208 },
3209};
3210
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003211static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003212
Takashi Iwai8d087c72011-06-28 12:45:47 +02003213#define get_connection_index(codec, mux, nid)\
3214 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003215
3216/* get an unassigned DAC from the given list.
3217 * Return the nid if found and reduce the DAC list, or return zero if
3218 * not found
3219 */
3220static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3221 hda_nid_t *dacs, int *num_dacs)
3222{
3223 int i, nums = *num_dacs;
3224 hda_nid_t ret = 0;
3225
3226 for (i = 0; i < nums; i++) {
3227 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3228 ret = dacs[i];
3229 break;
3230 }
3231 }
3232 if (!ret)
3233 return 0;
3234 if (--nums > 0)
3235 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3236 *num_dacs = nums;
3237 return ret;
3238}
3239
3240#define MAX_AUTO_DACS 5
3241
Takashi Iwai1f015f52011-08-23 14:57:08 +02003242#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3243
Takashi Iwaif2e57312010-09-15 10:07:08 +02003244/* fill analog DAC list from the widget tree */
3245static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3246{
3247 hda_nid_t nid, end_nid;
3248 int nums = 0;
3249
3250 end_nid = codec->start_nid + codec->num_nodes;
3251 for (nid = codec->start_nid; nid < end_nid; nid++) {
3252 unsigned int wcaps = get_wcaps(codec, nid);
3253 unsigned int type = get_wcaps_type(wcaps);
3254 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3255 dacs[nums++] = nid;
3256 if (nums >= MAX_AUTO_DACS)
3257 break;
3258 }
3259 }
3260 return nums;
3261}
3262
3263/* fill pin_dac_pair list from the pin and dac list */
3264static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3265 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003266 struct pin_dac_pair *filled, int nums,
3267 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003268{
David Henningsson468c5452011-08-25 13:16:02 +02003269 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003270
David Henningsson468c5452011-08-25 13:16:02 +02003271 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003272 filled[nums].pin = pins[i];
3273 filled[nums].type = type;
3274 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003275 if (filled[nums].dac)
3276 continue;
3277 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3278 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3279 continue;
3280 }
3281 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003282 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003283 continue;
3284 }
3285 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003286 }
3287 return nums;
3288}
3289
3290/* parse analog output paths */
3291static void cx_auto_parse_output(struct hda_codec *codec)
3292{
3293 struct conexant_spec *spec = codec->spec;
3294 struct auto_pin_cfg *cfg = &spec->autocfg;
3295 hda_nid_t dacs[MAX_AUTO_DACS];
3296 int i, j, nums, rest;
3297
3298 rest = fill_cx_auto_dacs(codec, dacs);
3299 /* parse all analog output pins */
3300 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003301 dacs, &rest, spec->dac_info, 0,
3302 AUTO_PIN_LINE_OUT);
3303 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3304 dacs, &rest, spec->dac_info, nums,
3305 AUTO_PIN_HP_OUT);
3306 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3307 dacs, &rest, spec->dac_info, nums,
3308 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003309 spec->dac_info_filled = nums;
3310 /* fill multiout struct */
3311 for (i = 0; i < nums; i++) {
3312 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003313 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003314 continue;
3315 switch (spec->dac_info[i].type) {
3316 case AUTO_PIN_LINE_OUT:
3317 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3318 spec->multiout.num_dacs++;
3319 break;
3320 case AUTO_PIN_HP_OUT:
3321 case AUTO_PIN_SPEAKER_OUT:
3322 if (!spec->multiout.hp_nid) {
3323 spec->multiout.hp_nid = dac;
3324 break;
3325 }
3326 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3327 if (!spec->multiout.extra_out_nid[j]) {
3328 spec->multiout.extra_out_nid[j] = dac;
3329 break;
3330 }
3331 break;
3332 }
3333 }
3334 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003335 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003336
Takashi Iwai03697e22011-05-17 09:53:31 +02003337 for (i = 0; i < cfg->hp_outs; i++) {
3338 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3339 spec->auto_mute = 1;
3340 break;
3341 }
3342 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003343 if (spec->auto_mute &&
3344 cfg->line_out_pins[0] &&
3345 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003346 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3347 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3348 for (i = 0; i < cfg->line_outs; i++) {
3349 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3350 spec->detect_line = 1;
3351 break;
3352 }
3353 }
3354 spec->automute_lines = spec->detect_line;
3355 }
3356
Takashi Iwaif2e57312010-09-15 10:07:08 +02003357 spec->vmaster_nid = spec->private_dac_nids[0];
3358}
3359
Takashi Iwaida339862011-05-13 16:24:15 +02003360static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3361 hda_nid_t *pins, bool on);
3362
Takashi Iwai03697e22011-05-17 09:53:31 +02003363static void do_automute(struct hda_codec *codec, int num_pins,
3364 hda_nid_t *pins, bool on)
3365{
Takashi Iwai254f2962011-10-14 15:22:34 +02003366 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003367 int i;
3368 for (i = 0; i < num_pins; i++)
3369 snd_hda_codec_write(codec, pins[i], 0,
3370 AC_VERB_SET_PIN_WIDGET_CONTROL,
3371 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003372 if (spec->pin_eapd_ctrls)
3373 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003374}
3375
3376static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3377{
3378 int i, present = 0;
3379
3380 for (i = 0; i < num_pins; i++) {
3381 hda_nid_t nid = pins[i];
3382 if (!nid || !is_jack_detectable(codec, nid))
3383 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003384 present |= snd_hda_jack_detect(codec, nid);
3385 }
3386 return present;
3387}
3388
Takashi Iwaif2e57312010-09-15 10:07:08 +02003389/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003390static void cx_auto_update_speakers(struct hda_codec *codec)
3391{
3392 struct conexant_spec *spec = codec->spec;
3393 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003394 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003395
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003396 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003397 if (spec->pin_eapd_ctrls) {
3398 if (spec->auto_mute)
3399 on = spec->hp_present;
3400 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3401 }
3402
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003403 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3404 if (spec->auto_mute)
3405 on = !(spec->hp_present ||
3406 (spec->detect_line && spec->line_present));
3407 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003408
3409 /* toggle line-out mutes if needed, too */
3410 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3411 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3412 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3413 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003414 if (spec->auto_mute) {
3415 /* mute LO in auto-mode when HP jack is present */
3416 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3417 spec->automute_lines)
3418 on = !spec->hp_present;
3419 else
3420 on = 1;
3421 }
3422 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003423}
3424
Takashi Iwaif2e57312010-09-15 10:07:08 +02003425static void cx_auto_hp_automute(struct hda_codec *codec)
3426{
3427 struct conexant_spec *spec = codec->spec;
3428 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003429
3430 if (!spec->auto_mute)
3431 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003432 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3433 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003434}
3435
Takashi Iwai03697e22011-05-17 09:53:31 +02003436static void cx_auto_line_automute(struct hda_codec *codec)
3437{
3438 struct conexant_spec *spec = codec->spec;
3439 struct auto_pin_cfg *cfg = &spec->autocfg;
3440
3441 if (!spec->auto_mute || !spec->detect_line)
3442 return;
3443 spec->line_present = detect_jacks(codec, cfg->line_outs,
3444 cfg->line_out_pins);
3445 cx_auto_update_speakers(codec);
3446}
3447
3448static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3449 struct snd_ctl_elem_info *uinfo)
3450{
3451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3452 struct conexant_spec *spec = codec->spec;
3453 static const char * const texts2[] = {
3454 "Disabled", "Enabled"
3455 };
3456 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003457 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003458 };
3459 const char * const *texts;
3460
3461 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3462 uinfo->count = 1;
3463 if (spec->automute_hp_lo) {
3464 uinfo->value.enumerated.items = 3;
3465 texts = texts3;
3466 } else {
3467 uinfo->value.enumerated.items = 2;
3468 texts = texts2;
3469 }
3470 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3471 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3472 strcpy(uinfo->value.enumerated.name,
3473 texts[uinfo->value.enumerated.item]);
3474 return 0;
3475}
3476
3477static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3478 struct snd_ctl_elem_value *ucontrol)
3479{
3480 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3481 struct conexant_spec *spec = codec->spec;
3482 unsigned int val;
3483 if (!spec->auto_mute)
3484 val = 0;
3485 else if (!spec->automute_lines)
3486 val = 1;
3487 else
3488 val = 2;
3489 ucontrol->value.enumerated.item[0] = val;
3490 return 0;
3491}
3492
3493static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3494 struct snd_ctl_elem_value *ucontrol)
3495{
3496 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3497 struct conexant_spec *spec = codec->spec;
3498
3499 switch (ucontrol->value.enumerated.item[0]) {
3500 case 0:
3501 if (!spec->auto_mute)
3502 return 0;
3503 spec->auto_mute = 0;
3504 break;
3505 case 1:
3506 if (spec->auto_mute && !spec->automute_lines)
3507 return 0;
3508 spec->auto_mute = 1;
3509 spec->automute_lines = 0;
3510 break;
3511 case 2:
3512 if (!spec->automute_hp_lo)
3513 return -EINVAL;
3514 if (spec->auto_mute && spec->automute_lines)
3515 return 0;
3516 spec->auto_mute = 1;
3517 spec->automute_lines = 1;
3518 break;
3519 default:
3520 return -EINVAL;
3521 }
3522 cx_auto_update_speakers(codec);
3523 return 1;
3524}
3525
3526static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3527 {
3528 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3529 .name = "Auto-Mute Mode",
3530 .info = cx_automute_mode_info,
3531 .get = cx_automute_mode_get,
3532 .put = cx_automute_mode_put,
3533 },
3534 { }
3535};
3536
Takashi Iwai6764bce2011-05-13 16:52:25 +02003537static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3538 struct snd_ctl_elem_info *uinfo)
3539{
3540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3541 struct conexant_spec *spec = codec->spec;
3542
3543 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3544}
3545
3546static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3547 struct snd_ctl_elem_value *ucontrol)
3548{
3549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3550 struct conexant_spec *spec = codec->spec;
3551
3552 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3553 return 0;
3554}
3555
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003556/* look for the route the given pin from mux and return the index;
3557 * if do_select is set, actually select the route.
3558 */
3559static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003560 hda_nid_t pin, hda_nid_t *srcp,
3561 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003562{
3563 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3564 int i, nums;
3565
Takashi Iwaicf27f292011-05-16 11:33:02 +02003566 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3567 case AC_WID_AUD_IN:
3568 case AC_WID_AUD_SEL:
3569 case AC_WID_AUD_MIX:
3570 break;
3571 default:
3572 return -1;
3573 }
3574
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003575 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3576 for (i = 0; i < nums; i++)
3577 if (conn[i] == pin) {
3578 if (do_select)
3579 snd_hda_codec_write(codec, mux, 0,
3580 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003581 if (srcp)
3582 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003583 return i;
3584 }
3585 depth++;
3586 if (depth == 2)
3587 return -1;
3588 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003589 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003590 do_select, depth);
3591 if (ret >= 0) {
3592 if (do_select)
3593 snd_hda_codec_write(codec, mux, 0,
3594 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003595 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003596 }
3597 }
3598 return -1;
3599}
3600
3601static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3602 hda_nid_t pin)
3603{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003604 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003605}
3606
3607static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3608 hda_nid_t pin)
3609{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003610 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003611}
3612
Takashi Iwai6764bce2011-05-13 16:52:25 +02003613static int cx_auto_mux_enum_update(struct hda_codec *codec,
3614 const struct hda_input_mux *imux,
3615 unsigned int idx)
3616{
3617 struct conexant_spec *spec = codec->spec;
3618 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003619 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003620
3621 if (!imux->num_items)
3622 return 0;
3623 if (idx >= imux->num_items)
3624 idx = imux->num_items - 1;
3625 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003626 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003627 adc = spec->imux_info[idx].adc;
3628 select_input_connection(codec, spec->imux_info[idx].adc,
3629 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003630 if (spec->cur_adc && spec->cur_adc != adc) {
3631 /* stream is running, let's swap the current ADC */
3632 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3633 spec->cur_adc = adc;
3634 snd_hda_codec_setup_stream(codec, adc,
3635 spec->cur_adc_stream_tag, 0,
3636 spec->cur_adc_format);
3637 }
3638 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003639 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003640}
3641
3642static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3643 struct snd_ctl_elem_value *ucontrol)
3644{
3645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3646 struct conexant_spec *spec = codec->spec;
3647
3648 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3649 ucontrol->value.enumerated.item[0]);
3650}
3651
3652static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3653 {
3654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3655 .name = "Capture Source",
3656 .info = cx_auto_mux_enum_info,
3657 .get = cx_auto_mux_enum_get,
3658 .put = cx_auto_mux_enum_put
3659 },
3660 {}
3661};
3662
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003663static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3664{
3665 struct conexant_spec *spec = codec->spec;
3666 if (idx < 0)
3667 return false;
3668 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3669 return false;
3670 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3671 return true;
3672}
3673
Takashi Iwaif2e57312010-09-15 10:07:08 +02003674/* automatic switch internal and external mic */
3675static void cx_auto_automic(struct hda_codec *codec)
3676{
3677 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003678
3679 if (!spec->auto_mic)
3680 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003681 if (!select_automic(codec, spec->auto_mic_ext, true))
3682 if (!select_automic(codec, spec->auto_mic_dock, true))
3683 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003684}
3685
3686static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3687{
Takashi Iwai3a938972011-10-28 01:16:55 +02003688 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003689 case CONEXANT_HP_EVENT:
3690 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003691 break;
3692 case CONEXANT_LINE_EVENT:
3693 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003694 break;
3695 case CONEXANT_MIC_EVENT:
3696 cx_auto_automic(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003697 break;
3698 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02003699 snd_hda_jack_report_sync(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003700}
3701
Takashi Iwaif2e57312010-09-15 10:07:08 +02003702/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003703 * auto-mic is enabled only when one int-mic and one ext- and/or
3704 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003705 */
3706static void cx_auto_check_auto_mic(struct hda_codec *codec)
3707{
3708 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003709 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3710 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003711
Takashi Iwai506a4192011-05-23 20:07:15 +02003712 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003713 pset[i] = -1;
3714 for (i = 0; i < spec->private_imux.num_items; i++) {
3715 hda_nid_t pin = spec->imux_info[i].pin;
3716 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003717 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003718 attr = snd_hda_get_input_pin_attr(def_conf);
3719 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003720 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003721 if (attr > INPUT_PIN_ATTR_NORMAL)
3722 attr = INPUT_PIN_ATTR_NORMAL;
3723 if (attr != INPUT_PIN_ATTR_INT &&
3724 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003725 return; /* non-detectable pin */
3726 type = get_defcfg_device(def_conf);
3727 if (type != AC_JACK_MIC_IN &&
3728 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3729 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003730 if (pset[attr] >= 0)
3731 return; /* already occupied */
3732 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003733 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003734 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3735 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3736 return; /* no input to switch*/
3737 spec->auto_mic = 1;
3738 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3739 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3740 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003741}
3742
3743static void cx_auto_parse_input(struct hda_codec *codec)
3744{
3745 struct conexant_spec *spec = codec->spec;
3746 struct auto_pin_cfg *cfg = &spec->autocfg;
3747 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003748 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003749
3750 imux = &spec->private_imux;
3751 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003752 for (j = 0; j < spec->num_adc_nids; j++) {
3753 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003754 int idx = get_input_connection(codec, adc,
3755 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003756 if (idx >= 0) {
3757 const char *label;
3758 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003759 spec->imux_info[imux->num_items].index = i;
3760 spec->imux_info[imux->num_items].boost = 0;
3761 spec->imux_info[imux->num_items].adc = adc;
3762 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003763 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003764 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003765 break;
3766 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003767 }
3768 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003769 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003770 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003771 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003772 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003773 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003774 spec->adc_switching = 1;
3775 break;
3776 }
3777 }
3778 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003779}
3780
3781/* get digital-input audio widget corresponding to the given pin */
3782static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3783{
3784 hda_nid_t nid, end_nid;
3785
3786 end_nid = codec->start_nid + codec->num_nodes;
3787 for (nid = codec->start_nid; nid < end_nid; nid++) {
3788 unsigned int wcaps = get_wcaps(codec, nid);
3789 unsigned int type = get_wcaps_type(wcaps);
3790 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3791 if (get_connection_index(codec, nid, pin) >= 0)
3792 return nid;
3793 }
3794 }
3795 return 0;
3796}
3797
3798static void cx_auto_parse_digital(struct hda_codec *codec)
3799{
3800 struct conexant_spec *spec = codec->spec;
3801 struct auto_pin_cfg *cfg = &spec->autocfg;
3802 hda_nid_t nid;
3803
3804 if (cfg->dig_outs &&
3805 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3806 spec->multiout.dig_out_nid = nid;
3807 if (cfg->dig_in_pin)
3808 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3809}
3810
3811#ifdef CONFIG_SND_HDA_INPUT_BEEP
3812static void cx_auto_parse_beep(struct hda_codec *codec)
3813{
3814 struct conexant_spec *spec = codec->spec;
3815 hda_nid_t nid, end_nid;
3816
3817 end_nid = codec->start_nid + codec->num_nodes;
3818 for (nid = codec->start_nid; nid < end_nid; nid++)
3819 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3820 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3821 break;
3822 }
3823}
3824#else
3825#define cx_auto_parse_beep(codec)
3826#endif
3827
Takashi Iwai254f2962011-10-14 15:22:34 +02003828/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003829static void cx_auto_parse_eapd(struct hda_codec *codec)
3830{
3831 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003832 hda_nid_t nid, end_nid;
3833
3834 end_nid = codec->start_nid + codec->num_nodes;
3835 for (nid = codec->start_nid; nid < end_nid; nid++) {
3836 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3837 continue;
3838 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3839 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003840 spec->eapds[spec->num_eapds++] = nid;
3841 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3842 break;
3843 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003844
3845 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3846 * it's a new chip, where EAPDs are supposed to be associated to
3847 * pins, and we can control EAPD per pin.
3848 * OTOH, if only one or two EAPDs are found, it's an old chip,
3849 * thus it might control over all pins.
3850 */
3851 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003852}
3853
Takashi Iwaif2e57312010-09-15 10:07:08 +02003854static int cx_auto_parse_auto_config(struct hda_codec *codec)
3855{
3856 struct conexant_spec *spec = codec->spec;
3857 int err;
3858
3859 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3860 if (err < 0)
3861 return err;
3862
3863 cx_auto_parse_output(codec);
3864 cx_auto_parse_input(codec);
3865 cx_auto_parse_digital(codec);
3866 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003867 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003868 return 0;
3869}
3870
Takashi Iwaida339862011-05-13 16:24:15 +02003871static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3872 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003873{
3874 int i;
3875 for (i = 0; i < num_pins; i++) {
3876 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3877 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003878 AC_VERB_SET_EAPD_BTLENABLE,
3879 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003880 }
3881}
3882
3883static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3884 hda_nid_t src)
3885{
3886 int idx = get_connection_index(codec, pin, src);
3887 if (idx >= 0)
3888 snd_hda_codec_write(codec, pin, 0,
3889 AC_VERB_SET_CONNECT_SEL, idx);
3890}
3891
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003892static void mute_outputs(struct hda_codec *codec, int num_nids,
3893 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003894{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003895 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003896
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003897 for (i = 0; i < num_nids; i++) {
3898 hda_nid_t nid = nids[i];
3899 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3900 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003901 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3902 val = AMP_OUT_MUTE;
3903 else
3904 val = AMP_OUT_ZERO;
3905 snd_hda_codec_write(codec, nid, 0,
3906 AC_VERB_SET_AMP_GAIN_MUTE, val);
3907 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003908}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003909
Takashi Iwai03697e22011-05-17 09:53:31 +02003910static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
Takashi Iwai3a938972011-10-28 01:16:55 +02003911 hda_nid_t *pins, unsigned int action)
Takashi Iwai03697e22011-05-17 09:53:31 +02003912{
3913 int i;
3914 for (i = 0; i < num_pins; i++)
Takashi Iwai3a938972011-10-28 01:16:55 +02003915 snd_hda_jack_detect_enable(codec, pins[i], action);
Takashi Iwai03697e22011-05-17 09:53:31 +02003916}
3917
Takashi Iwai07cafff2012-02-20 12:30:59 +01003918static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3919{
3920 int i;
3921 for (i = 0; i < nums; i++)
3922 if (list[i] == nid)
3923 return true;
3924 return false;
3925}
3926
3927/* is the given NID found in any of autocfg items? */
3928static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3929{
3930 int i;
3931
3932 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3933 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3934 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3935 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3936 return true;
3937 for (i = 0; i < cfg->num_inputs; i++)
3938 if (cfg->inputs[i].pin == nid)
3939 return true;
3940 if (cfg->dig_in_pin == nid)
3941 return true;
3942 return false;
3943}
3944
3945/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3946 * invalid unsol tags by some reason
3947 */
3948static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3949{
3950 struct conexant_spec *spec = codec->spec;
3951 struct auto_pin_cfg *cfg = &spec->autocfg;
3952 int i;
3953
3954 for (i = 0; i < codec->init_pins.used; i++) {
3955 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3956 if (!found_in_autocfg(cfg, pin->nid))
3957 snd_hda_codec_write(codec, pin->nid, 0,
3958 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3959 }
3960}
3961
Takashi Iwai527c73b2012-03-12 12:38:51 +01003962/* turn on/off EAPD according to Master switch */
3963static void cx_auto_vmaster_hook(void *private_data, int enabled)
3964{
3965 struct hda_codec *codec = private_data;
3966 struct conexant_spec *spec = codec->spec;
3967
3968 if (enabled && spec->pin_eapd_ctrls) {
3969 cx_auto_update_speakers(codec);
3970 return;
3971 }
3972 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3973}
3974
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003975static void cx_auto_init_output(struct hda_codec *codec)
3976{
3977 struct conexant_spec *spec = codec->spec;
3978 struct auto_pin_cfg *cfg = &spec->autocfg;
3979 hda_nid_t nid;
3980 int i;
3981
3982 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003983 for (i = 0; i < cfg->hp_outs; i++)
3984 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3985 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003986 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3987 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3988 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003989 for (i = 0; i < spec->dac_info_filled; i++) {
3990 nid = spec->dac_info[i].dac;
3991 if (!nid)
3992 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003993 else if (nid & DAC_SLAVE_FLAG)
3994 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003995 select_connection(codec, spec->dac_info[i].pin, nid);
3996 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003997 if (spec->auto_mute) {
3998 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3999 CONEXANT_HP_EVENT);
4000 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4001 cfg->hp_pins);
4002 if (spec->detect_line) {
4003 enable_unsol_pins(codec, cfg->line_outs,
4004 cfg->line_out_pins,
4005 CONEXANT_LINE_EVENT);
4006 spec->line_present =
4007 detect_jacks(codec, cfg->line_outs,
4008 cfg->line_out_pins);
4009 }
4010 }
4011 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02004012 /* turn on all EAPDs if no individual EAPD control is available */
4013 if (!spec->pin_eapd_ctrls)
4014 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01004015 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004016}
4017
4018static void cx_auto_init_input(struct hda_codec *codec)
4019{
4020 struct conexant_spec *spec = codec->spec;
4021 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004022 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004023
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004024 for (i = 0; i < spec->num_adc_nids; i++) {
4025 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004026 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4027 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004028 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4029 val = AMP_IN_MUTE(0);
4030 else
4031 val = AMP_IN_UNMUTE(0);
4032 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4033 val);
4034 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004035
4036 for (i = 0; i < cfg->num_inputs; i++) {
4037 unsigned int type;
4038 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4039 type = PIN_VREF80;
4040 else
4041 type = PIN_IN;
4042 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4043 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4044 }
4045
4046 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004047 if (spec->auto_mic_ext >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004048 snd_hda_jack_detect_enable(codec,
4049 cfg->inputs[spec->auto_mic_ext].pin,
4050 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004051 }
4052 if (spec->auto_mic_dock >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004053 snd_hda_jack_detect_enable(codec,
4054 cfg->inputs[spec->auto_mic_dock].pin,
4055 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004056 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004057 cx_auto_automic(codec);
4058 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004059 select_input_connection(codec, spec->imux_info[0].adc,
4060 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004061 }
4062}
4063
4064static void cx_auto_init_digital(struct hda_codec *codec)
4065{
4066 struct conexant_spec *spec = codec->spec;
4067 struct auto_pin_cfg *cfg = &spec->autocfg;
4068
4069 if (spec->multiout.dig_out_nid)
4070 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4071 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4072 if (spec->dig_in_nid)
4073 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4074 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4075}
4076
4077static int cx_auto_init(struct hda_codec *codec)
4078{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004079 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004080 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4081 cx_auto_init_output(codec);
4082 cx_auto_init_input(codec);
4083 cx_auto_init_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004084 snd_hda_jack_report_sync(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004085 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004086 return 0;
4087}
4088
David Henningsson983345e2011-02-15 19:57:09 +01004089static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004090 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004091 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004092{
4093 static char name[32];
4094 static struct snd_kcontrol_new knew[] = {
4095 HDA_CODEC_VOLUME(name, 0, 0, 0),
4096 HDA_CODEC_MUTE(name, 0, 0, 0),
4097 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004098 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004099 int i, err;
4100
4101 for (i = 0; i < 2; i++) {
4102 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004103 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4104 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004105 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4106 knew[i].index = cidx;
4107 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4108 kctl = snd_ctl_new1(&knew[i], codec);
4109 if (!kctl)
4110 return -ENOMEM;
4111 err = snd_hda_ctl_add(codec, nid, kctl);
4112 if (err < 0)
4113 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004114 if (!(query_amp_caps(codec, nid, hda_dir) &
4115 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004116 break;
4117 }
4118 return 0;
4119}
4120
David Henningsson983345e2011-02-15 19:57:09 +01004121#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4122 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4123
Takashi Iwaif2e57312010-09-15 10:07:08 +02004124#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4125 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4126
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004127static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4128 hda_nid_t pin, const char *name, int idx)
4129{
4130 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004131 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4132 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4133 if (caps & AC_AMPCAP_NUM_STEPS)
4134 return cx_auto_add_pb_volume(codec, dac, name, idx);
4135 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004136 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4137 if (caps & AC_AMPCAP_NUM_STEPS)
4138 return cx_auto_add_pb_volume(codec, pin, name, idx);
4139 return 0;
4140}
4141
Takashi Iwaif2e57312010-09-15 10:07:08 +02004142static int cx_auto_build_output_controls(struct hda_codec *codec)
4143{
4144 struct conexant_spec *spec = codec->spec;
4145 int i, err;
4146 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004147 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004148
4149 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004150 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4151 spec->dac_info[0].pin,
4152 "Master", 0);
4153
Takashi Iwaif2e57312010-09-15 10:07:08 +02004154 for (i = 0; i < spec->dac_info_filled; i++) {
4155 const char *label;
4156 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004157 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004158 type = spec->dac_info[i].type;
4159 if (type == AUTO_PIN_LINE_OUT)
4160 type = spec->autocfg.line_out_type;
4161 switch (type) {
4162 case AUTO_PIN_LINE_OUT:
4163 default:
4164 label = texts[num_line++];
4165 idx = 0;
4166 break;
4167 case AUTO_PIN_HP_OUT:
4168 label = "Headphone";
4169 idx = num_hp++;
4170 break;
4171 case AUTO_PIN_SPEAKER_OUT:
4172 label = "Speaker";
4173 idx = num_spk++;
4174 break;
4175 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004176 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004177 spec->dac_info[i].pin,
4178 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004179 if (err < 0)
4180 return err;
4181 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004182
4183 if (spec->auto_mute) {
4184 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4185 if (err < 0)
4186 return err;
4187 }
4188
Takashi Iwaif2e57312010-09-15 10:07:08 +02004189 return 0;
4190}
4191
Takashi Iwai6764bce2011-05-13 16:52:25 +02004192static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4193 const char *label, const char *pfx,
4194 int cidx)
4195{
4196 struct conexant_spec *spec = codec->spec;
4197 int i;
4198
4199 for (i = 0; i < spec->num_adc_nids; i++) {
4200 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004201 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004202 if (idx < 0)
4203 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004204 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004205 idx = 0;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004206 return cx_auto_add_volume_idx(codec, label, pfx,
4207 cidx, adc_nid, HDA_INPUT, idx);
4208 }
4209 return 0;
4210}
4211
Takashi Iwaicf27f292011-05-16 11:33:02 +02004212static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4213 const char *label, int cidx)
4214{
4215 struct conexant_spec *spec = codec->spec;
4216 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004217 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004218
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004219 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004220 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4221 return cx_auto_add_volume(codec, label, " Boost", cidx,
4222 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004223 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4224 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004225 if (con < 0)
4226 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004227 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004228 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004229 return 0; /* already present */
4230 }
4231
4232 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004233 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004234 return cx_auto_add_volume(codec, label, " Boost", 0,
4235 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004236 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004237 return 0;
4238}
4239
Takashi Iwaif2e57312010-09-15 10:07:08 +02004240static int cx_auto_build_input_controls(struct hda_codec *codec)
4241{
4242 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004243 struct hda_input_mux *imux = &spec->private_imux;
4244 const char *prev_label;
4245 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004246 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004247 int multi_connection;
4248
Takashi Iwai6b452142011-10-14 15:26:20 +02004249 if (!imux->num_items)
4250 return 0;
4251
Takashi Iwaicf27f292011-05-16 11:33:02 +02004252 multi_connection = 0;
4253 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004254 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4255 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004256 if (cidx < 0)
4257 continue;
4258 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004259 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004260 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004261 if (i > 0 && input_conn[i] != input_conn[0])
4262 multi_connection = 1;
4263 }
David Henningsson983345e2011-02-15 19:57:09 +01004264
Takashi Iwaif2e57312010-09-15 10:07:08 +02004265 prev_label = NULL;
4266 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004267 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004268 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004269 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004270
Takashi Iwaicf27f292011-05-16 11:33:02 +02004271 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004272 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004273 if (label == prev_label)
4274 cidx++;
4275 else
4276 cidx = 0;
4277 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004278
Takashi Iwaicf27f292011-05-16 11:33:02 +02004279 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4280 if (err < 0)
4281 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004282
Takashi Iwaicf27f292011-05-16 11:33:02 +02004283 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004284 if (i > 0)
4285 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004286 err = cx_auto_add_capture_volume(codec, nid,
4287 "Capture", "", cidx);
4288 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004289 bool dup_found = false;
4290 for (j = 0; j < i; j++) {
4291 if (input_conn[j] == input_conn[i]) {
4292 dup_found = true;
4293 break;
4294 }
4295 }
4296 if (dup_found)
4297 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004298 err = cx_auto_add_capture_volume(codec, nid,
4299 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004300 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004301 if (err < 0)
4302 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004303 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004304
4305 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4306 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4307 if (err < 0)
4308 return err;
4309 }
4310
Takashi Iwaif2e57312010-09-15 10:07:08 +02004311 return 0;
4312}
4313
4314static int cx_auto_build_controls(struct hda_codec *codec)
4315{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004316 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004317 int err;
4318
4319 err = cx_auto_build_output_controls(codec);
4320 if (err < 0)
4321 return err;
4322 err = cx_auto_build_input_controls(codec);
4323 if (err < 0)
4324 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004325 err = conexant_build_controls(codec);
4326 if (err < 0)
4327 return err;
4328 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4329 if (err < 0)
4330 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004331 if (spec->vmaster_mute.sw_kctl) {
4332 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4333 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4334 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004335 if (err < 0)
4336 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004337 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004338 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004339}
4340
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004341static int cx_auto_search_adcs(struct hda_codec *codec)
4342{
4343 struct conexant_spec *spec = codec->spec;
4344 hda_nid_t nid, end_nid;
4345
4346 end_nid = codec->start_nid + codec->num_nodes;
4347 for (nid = codec->start_nid; nid < end_nid; nid++) {
4348 unsigned int caps = get_wcaps(codec, nid);
4349 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4350 continue;
4351 if (caps & AC_WCAP_DIGITAL)
4352 continue;
4353 if (snd_BUG_ON(spec->num_adc_nids >=
4354 ARRAY_SIZE(spec->private_adc_nids)))
4355 break;
4356 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4357 }
4358 spec->adc_nids = spec->private_adc_nids;
4359 return 0;
4360}
4361
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004362static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004363 .build_controls = cx_auto_build_controls,
4364 .build_pcms = conexant_build_pcms,
4365 .init = cx_auto_init,
4366 .free = conexant_free,
4367 .unsol_event = cx_auto_unsol_event,
4368#ifdef CONFIG_SND_HDA_POWER_SAVE
4369 .suspend = conexant_suspend,
4370#endif
4371 .reboot_notify = snd_hda_shutup_pins,
4372};
4373
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004374/*
4375 * pin fix-up
4376 */
4377struct cxt_pincfg {
4378 hda_nid_t nid;
4379 u32 val;
4380};
4381
4382static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4383{
4384 for (; cfg->nid; cfg++)
4385 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4386
4387}
4388
4389static void apply_pin_fixup(struct hda_codec *codec,
4390 const struct snd_pci_quirk *quirk,
4391 const struct cxt_pincfg **table)
4392{
4393 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4394 if (quirk) {
4395 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4396 quirk->name);
4397 apply_pincfg(codec, table[quirk->value]);
4398 }
4399}
4400
4401enum {
4402 CXT_PINCFG_LENOVO_X200,
4403};
4404
4405static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4406 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4407 { 0x17, 0x21a11000 }, /* dock-mic */
4408 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004409 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004410 {}
4411};
4412
4413static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4414 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4415};
4416
4417static const struct snd_pci_quirk cxt_fixups[] = {
4418 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4419 {}
4420};
4421
Takashi Iwai38681372012-02-27 15:00:58 +01004422/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4423 * can be created (bko#42825)
4424 */
4425static void add_cx5051_fake_mutes(struct hda_codec *codec)
4426{
4427 static hda_nid_t out_nids[] = {
4428 0x10, 0x11, 0
4429 };
4430 hda_nid_t *p;
4431
4432 for (p = out_nids; *p; p++)
4433 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4434 AC_AMPCAP_MIN_MUTE |
4435 query_amp_caps(codec, *p, HDA_OUTPUT));
4436}
4437
Takashi Iwaif2e57312010-09-15 10:07:08 +02004438static int patch_conexant_auto(struct hda_codec *codec)
4439{
4440 struct conexant_spec *spec;
4441 int err;
4442
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004443 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4444 codec->chip_name);
4445
Takashi Iwaif2e57312010-09-15 10:07:08 +02004446 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4447 if (!spec)
4448 return -ENOMEM;
4449 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004450 codec->pin_amp_workaround = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004451
Takashi Iwai6b452142011-10-14 15:26:20 +02004452 switch (codec->vendor_id) {
4453 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004454 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004455 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004456 case 0x14f15051:
4457 add_cx5051_fake_mutes(codec);
4458 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02004459 }
4460
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004461 apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
4462
Takashi Iwaif29735c2012-03-13 07:55:10 +01004463 /* Show mute-led control only on HP laptops
4464 * This is a sort of white-list: on HP laptops, EAPD corresponds
4465 * only to the mute-LED without actualy amp function. Meanwhile,
4466 * others may use EAPD really as an amp switch, so it might be
4467 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004468 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004469 switch (codec->subsystem_id >> 16) {
4470 case 0x103c:
4471 spec->vmaster_mute_led = 1;
4472 break;
4473 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004474
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004475 err = cx_auto_search_adcs(codec);
4476 if (err < 0)
4477 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004478 err = cx_auto_parse_auto_config(codec);
4479 if (err < 0) {
4480 kfree(codec->spec);
4481 codec->spec = NULL;
4482 return err;
4483 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004484 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004485 codec->patch_ops = cx_auto_patch_ops;
4486 if (spec->beep_amp)
4487 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004488
4489 /* Some laptops with Conexant chips show stalls in S3 resume,
4490 * which falls into the single-cmd mode.
4491 * Better to make reset, then.
4492 */
4493 if (!codec->bus->sync_write) {
4494 snd_printd("hda_codec: "
4495 "Enable sync_write for stable communication\n");
4496 codec->bus->sync_write = 1;
4497 codec->bus->allow_bus_reset = 1;
4498 }
4499
Takashi Iwaif2e57312010-09-15 10:07:08 +02004500 return 0;
4501}
4502
4503/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004504 */
4505
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004506static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004507 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4508 .patch = patch_cxt5045 },
4509 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4510 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004511 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4512 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004513 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4514 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004515 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4516 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004517 { .id = 0x14f15068, .name = "CX20584",
4518 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004519 { .id = 0x14f15069, .name = "CX20585",
4520 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004521 { .id = 0x14f1506c, .name = "CX20588",
4522 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004523 { .id = 0x14f1506e, .name = "CX20590",
4524 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004525 { .id = 0x14f15097, .name = "CX20631",
4526 .patch = patch_conexant_auto },
4527 { .id = 0x14f15098, .name = "CX20632",
4528 .patch = patch_conexant_auto },
4529 { .id = 0x14f150a1, .name = "CX20641",
4530 .patch = patch_conexant_auto },
4531 { .id = 0x14f150a2, .name = "CX20642",
4532 .patch = patch_conexant_auto },
4533 { .id = 0x14f150ab, .name = "CX20651",
4534 .patch = patch_conexant_auto },
4535 { .id = 0x14f150ac, .name = "CX20652",
4536 .patch = patch_conexant_auto },
4537 { .id = 0x14f150b8, .name = "CX20664",
4538 .patch = patch_conexant_auto },
4539 { .id = 0x14f150b9, .name = "CX20665",
4540 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004541 {} /* terminator */
4542};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004543
4544MODULE_ALIAS("snd-hda-codec-id:14f15045");
4545MODULE_ALIAS("snd-hda-codec-id:14f15047");
4546MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004547MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004548MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004549MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004550MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004551MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004552MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004553MODULE_ALIAS("snd-hda-codec-id:14f15097");
4554MODULE_ALIAS("snd-hda-codec-id:14f15098");
4555MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4556MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4557MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4558MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4559MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4560MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004561
4562MODULE_LICENSE("GPL");
4563MODULE_DESCRIPTION("Conexant HD-audio codec");
4564
4565static struct hda_codec_preset_list conexant_list = {
4566 .preset = snd_hda_preset_conexant,
4567 .owner = THIS_MODULE,
4568};
4569
4570static int __init patch_conexant_init(void)
4571{
4572 return snd_hda_add_codec_preset(&conexant_list);
4573}
4574
4575static void __exit patch_conexant_exit(void)
4576{
4577 snd_hda_delete_codec_preset(&conexant_list);
4578}
4579
4580module_init(patch_conexant_init)
4581module_exit(patch_conexant_exit)