blob: a52f5662f69c55e8a3696f927e4d38bf4f6d2ba4 [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"
Takashi Iwai23d30f22012-05-07 17:17:32 +020033#include "hda_auto_parser.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020034#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020035#include "hda_jack.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010036
37#define CXT_PIN_DIR_IN 0x00
38#define CXT_PIN_DIR_OUT 0x01
39#define CXT_PIN_DIR_INOUT 0x02
40#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
41#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
42
43#define CONEXANT_HP_EVENT 0x37
44#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020045#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010046
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010047/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010048
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010049#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010050#define CXT5051_PORTB_EVENT 0x38
51#define CXT5051_PORTC_EVENT 0x39
52
Takashi Iwaifaddaa52010-01-23 22:31:36 +010053#define AUTO_MIC_PORTB (1 << 1)
54#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010055
Takashi Iwaif2e57312010-09-15 10:07:08 +020056struct pin_dac_pair {
57 hda_nid_t pin;
58 hda_nid_t dac;
59 int type;
60};
61
Takashi Iwai47ad1f42011-05-17 09:15:55 +020062struct imux_info {
63 hda_nid_t pin; /* input pin NID */
64 hda_nid_t adc; /* connected ADC NID */
65 hda_nid_t boost; /* optional boost volume NID */
66 int index; /* corresponding to autocfg.input */
67};
68
Tobin Davisc9b443d2006-11-14 12:13:39 +010069struct conexant_spec {
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;
David Henningsson18dcd302012-04-02 15:40:27 +0200144 unsigned int fixup_stereo_dmic:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100145
Takashi Iwai6764bce2011-05-13 16:52:25 +0200146 unsigned int adc_switching:1;
147
Daniel Drake75f89912010-01-07 13:46:25 +0100148 unsigned int ext_mic_present;
149 unsigned int recording;
150 void (*capture_prepare)(struct hda_codec *codec);
151 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100152
153 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
154 * through the microphone jack.
155 * When the user enables this through a mixer switch, both internal and
156 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
157 * we also allow the bias to be configured through a separate mixer
158 * control. */
159 unsigned int dc_enable;
160 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
161 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200162
163 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200164
165 /* extra EAPD pins */
166 unsigned int num_eapds;
167 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100168};
169
170static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
173{
174 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100175 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
176 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100177}
178
179static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 unsigned int stream_tag,
182 unsigned int format,
183 struct snd_pcm_substream *substream)
184{
185 struct conexant_spec *spec = codec->spec;
186 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
187 stream_tag,
188 format, substream);
189}
190
191static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
194{
195 struct conexant_spec *spec = codec->spec;
196 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
197}
198
199/*
200 * Digital out
201 */
202static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 struct snd_pcm_substream *substream)
205{
206 struct conexant_spec *spec = codec->spec;
207 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
208}
209
210static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 struct snd_pcm_substream *substream)
213{
214 struct conexant_spec *spec = codec->spec;
215 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
216}
217
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200218static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
219 struct hda_codec *codec,
220 unsigned int stream_tag,
221 unsigned int format,
222 struct snd_pcm_substream *substream)
223{
224 struct conexant_spec *spec = codec->spec;
225 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
226 stream_tag,
227 format, substream);
228}
229
Tobin Davisc9b443d2006-11-14 12:13:39 +0100230/*
231 * Analog capture
232 */
233static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
234 struct hda_codec *codec,
235 unsigned int stream_tag,
236 unsigned int format,
237 struct snd_pcm_substream *substream)
238{
239 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100240 if (spec->capture_prepare)
241 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100242 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
243 stream_tag, 0, format);
244 return 0;
245}
246
247static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
248 struct hda_codec *codec,
249 struct snd_pcm_substream *substream)
250{
251 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100252 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100253 if (spec->capture_cleanup)
254 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100255 return 0;
256}
257
258
259
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200260static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100261 .substreams = 1,
262 .channels_min = 2,
263 .channels_max = 2,
264 .nid = 0, /* fill later */
265 .ops = {
266 .open = conexant_playback_pcm_open,
267 .prepare = conexant_playback_pcm_prepare,
268 .cleanup = conexant_playback_pcm_cleanup
269 },
270};
271
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200272static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100273 .substreams = 1,
274 .channels_min = 2,
275 .channels_max = 2,
276 .nid = 0, /* fill later */
277 .ops = {
278 .prepare = conexant_capture_pcm_prepare,
279 .cleanup = conexant_capture_pcm_cleanup
280 },
281};
282
283
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200284static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100285 .substreams = 1,
286 .channels_min = 2,
287 .channels_max = 2,
288 .nid = 0, /* fill later */
289 .ops = {
290 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200291 .close = conexant_dig_playback_pcm_close,
292 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100293 },
294};
295
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200296static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100297 .substreams = 1,
298 .channels_min = 2,
299 .channels_max = 2,
300 /* NID is set in alc_build_pcms */
301};
302
Takashi Iwai461e2c72008-01-25 11:35:17 +0100303static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
304 struct hda_codec *codec,
305 unsigned int stream_tag,
306 unsigned int format,
307 struct snd_pcm_substream *substream)
308{
309 struct conexant_spec *spec = codec->spec;
310 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
311 spec->cur_adc_stream_tag = stream_tag;
312 spec->cur_adc_format = format;
313 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
314 return 0;
315}
316
317static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
318 struct hda_codec *codec,
319 struct snd_pcm_substream *substream)
320{
321 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100322 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100323 spec->cur_adc = 0;
324 return 0;
325}
326
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200327static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100328 .substreams = 1,
329 .channels_min = 2,
330 .channels_max = 2,
331 .nid = 0, /* fill later */
332 .ops = {
333 .prepare = cx5051_capture_pcm_prepare,
334 .cleanup = cx5051_capture_pcm_cleanup
335 },
336};
337
Takashi Iwaiee81abb2012-11-08 17:12:10 +0100338static bool is_2_1_speaker(struct conexant_spec *spec);
339
Tobin Davisc9b443d2006-11-14 12:13:39 +0100340static int conexant_build_pcms(struct hda_codec *codec)
341{
342 struct conexant_spec *spec = codec->spec;
343 struct hda_pcm *info = spec->pcm_rec;
344
345 codec->num_pcms = 1;
346 codec->pcm_info = info;
347
348 info->name = "CONEXANT Analog";
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
351 spec->multiout.max_channels;
352 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
353 spec->multiout.dac_nids[0];
Takashi Iwaiee81abb2012-11-08 17:12:10 +0100354 if (is_2_1_speaker(spec))
355 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
356 snd_pcm_2_1_chmaps;
Takashi Iwai6764bce2011-05-13 16:52:25 +0200357 if (spec->capture_stream)
358 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
359 else {
360 if (codec->vendor_id == 0x14f15051)
361 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
362 cx5051_pcm_analog_capture;
363 else {
364 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
365 conexant_pcm_analog_capture;
366 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
367 spec->num_adc_nids;
368 }
369 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100370 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
371
372 if (spec->multiout.dig_out_nid) {
373 info++;
374 codec->num_pcms++;
375 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100376 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100377 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
378 conexant_pcm_digital_playback;
379 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
380 spec->multiout.dig_out_nid;
381 if (spec->dig_in_nid) {
382 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
383 conexant_pcm_digital_capture;
384 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
385 spec->dig_in_nid;
386 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500387 if (spec->slave_dig_outs[0])
388 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100389 }
390
391 return 0;
392}
393
394static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
395 struct snd_ctl_elem_info *uinfo)
396{
397 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398 struct conexant_spec *spec = codec->spec;
399
400 return snd_hda_input_mux_info(spec->input_mux, uinfo);
401}
402
403static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_value *ucontrol)
405{
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 struct conexant_spec *spec = codec->spec;
408 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
409
410 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
411 return 0;
412}
413
414static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
415 struct snd_ctl_elem_value *ucontrol)
416{
417 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
418 struct conexant_spec *spec = codec->spec;
419 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
420
421 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
422 spec->capsrc_nids[adc_idx],
423 &spec->cur_mux[adc_idx]);
424}
425
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200426static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
427 unsigned int power_state)
428{
429 if (power_state == AC_PWRST_D3)
430 msleep(100);
431 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
432 power_state);
433 /* partial workaround for "azx_get_response timeout" */
434 if (power_state == AC_PWRST_D0)
435 msleep(10);
436 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
437}
438
Tobin Davisc9b443d2006-11-14 12:13:39 +0100439static int conexant_init(struct hda_codec *codec)
440{
441 struct conexant_spec *spec = codec->spec;
442 int i;
443
444 for (i = 0; i < spec->num_init_verbs; i++)
445 snd_hda_sequence_write(codec, spec->init_verbs[i]);
446 return 0;
447}
448
449static void conexant_free(struct hda_codec *codec)
450{
Takashi Iwaiee48df52012-06-26 14:54:32 +0200451 struct conexant_spec *spec = codec->spec;
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200452 snd_hda_detach_beep_device(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +0200453 kfree(spec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100454}
455
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200456static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100457 {
458 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
459 .name = "Capture Source",
460 .info = conexant_mux_enum_info,
461 .get = conexant_mux_enum_get,
462 .put = conexant_mux_enum_put
463 },
464 {}
465};
466
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200467#ifdef CONFIG_SND_HDA_INPUT_BEEP
468/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200469static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200470 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
471 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
472 { } /* end */
473};
474#endif
475
Takashi Iwai9322ca52012-02-03 14:28:01 +0100476static const char * const slave_pfxs[] = {
Takashi Iwaif37bc7a2012-11-08 15:59:23 +0100477 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100478 NULL
479};
480
Tobin Davisc9b443d2006-11-14 12:13:39 +0100481static int conexant_build_controls(struct hda_codec *codec)
482{
483 struct conexant_spec *spec = codec->spec;
484 unsigned int i;
485 int err;
486
487 for (i = 0; i < spec->num_mixers; i++) {
488 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
489 if (err < 0)
490 return err;
491 }
492 if (spec->multiout.dig_out_nid) {
493 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600494 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100495 spec->multiout.dig_out_nid);
496 if (err < 0)
497 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100498 err = snd_hda_create_spdif_share_sw(codec,
499 &spec->multiout);
500 if (err < 0)
501 return err;
502 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100503 }
504 if (spec->dig_in_nid) {
505 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
506 if (err < 0)
507 return err;
508 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100509
510 /* if we have no master control, let's create it */
511 if (spec->vmaster_nid &&
512 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
513 unsigned int vmaster_tlv[4];
514 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
515 HDA_OUTPUT, vmaster_tlv);
516 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100517 vmaster_tlv, slave_pfxs,
518 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100519 if (err < 0)
520 return err;
521 }
522 if (spec->vmaster_nid &&
523 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai527c73b2012-03-12 12:38:51 +0100524 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
525 NULL, slave_pfxs,
526 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100527 &spec->vmaster_mute.sw_kctl);
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100528 if (err < 0)
529 return err;
530 }
531
Takashi Iwaib880c742009-03-10 14:41:05 +0100532 if (spec->input_mux) {
533 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
534 if (err < 0)
535 return err;
536 }
537
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200538#ifdef CONFIG_SND_HDA_INPUT_BEEP
539 /* create beep controls if needed */
540 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200541 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200542 for (knew = cxt_beep_mixer; knew->name; knew++) {
543 struct snd_kcontrol *kctl;
544 kctl = snd_ctl_new1(knew, codec);
545 if (!kctl)
546 return -ENOMEM;
547 kctl->private_value = spec->beep_amp;
548 err = snd_hda_ctl_add(codec, 0, kctl);
549 if (err < 0)
550 return err;
551 }
552 }
553#endif
554
Tobin Davisc9b443d2006-11-14 12:13:39 +0100555 return 0;
556}
557
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200558static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100559 .build_controls = conexant_build_controls,
560 .build_pcms = conexant_build_pcms,
561 .init = conexant_init,
562 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200563 .set_power_state = conexant_set_power,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100564};
565
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200566#ifdef CONFIG_SND_HDA_INPUT_BEEP
567#define set_beep_amp(spec, nid, idx, dir) \
568 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
569#else
570#define set_beep_amp(spec, nid, idx, dir) /* NOP */
571#endif
572
Takashi Iwai6764bce2011-05-13 16:52:25 +0200573static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100574/*
575 * EAPD control
576 * the private value = nid | (invert << 8)
577 */
578
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200579#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100580
Tobin Davis82f30042007-02-13 12:45:44 +0100581static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100582 struct snd_ctl_elem_value *ucontrol)
583{
584 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585 struct conexant_spec *spec = codec->spec;
586 int invert = (kcontrol->private_value >> 8) & 1;
587 if (invert)
588 ucontrol->value.integer.value[0] = !spec->cur_eapd;
589 else
590 ucontrol->value.integer.value[0] = spec->cur_eapd;
591 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100592
Tobin Davisc9b443d2006-11-14 12:13:39 +0100593}
594
Tobin Davis82f30042007-02-13 12:45:44 +0100595static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100596 struct snd_ctl_elem_value *ucontrol)
597{
598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599 struct conexant_spec *spec = codec->spec;
600 int invert = (kcontrol->private_value >> 8) & 1;
601 hda_nid_t nid = kcontrol->private_value & 0xff;
602 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100603
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100604 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100605 if (invert)
606 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200607 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100608 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100609
Tobin Davisc9b443d2006-11-14 12:13:39 +0100610 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200611 snd_hda_codec_write_cache(codec, nid,
612 0, AC_VERB_SET_EAPD_BTLENABLE,
613 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 return 1;
615}
616
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100617/* controls for test mode */
618#ifdef CONFIG_SND_DEBUG
619
Tobin Davis82f30042007-02-13 12:45:44 +0100620#define CXT_EAPD_SWITCH(xname, nid, mask) \
621 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
622 .info = cxt_eapd_info, \
623 .get = cxt_eapd_get, \
624 .put = cxt_eapd_put, \
625 .private_value = nid | (mask<<16) }
626
627
628
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_info *uinfo)
631{
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct conexant_spec *spec = codec->spec;
634 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
635 spec->num_channel_mode);
636}
637
638static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_value *ucontrol)
640{
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct conexant_spec *spec = codec->spec;
643 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
644 spec->num_channel_mode,
645 spec->multiout.max_channels);
646}
647
648static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
654 spec->num_channel_mode,
655 &spec->multiout.max_channels);
656 if (err >= 0 && spec->need_dac_fix)
657 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
658 return err;
659}
660
661#define CXT_PIN_MODE(xname, nid, dir) \
662 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
663 .info = conexant_ch_mode_info, \
664 .get = conexant_ch_mode_get, \
665 .put = conexant_ch_mode_put, \
666 .private_value = nid | (dir<<16) }
667
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100668#endif /* CONFIG_SND_DEBUG */
669
Tobin Davisc9b443d2006-11-14 12:13:39 +0100670/* Conexant 5045 specific */
671
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200672static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
673static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
674static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100675#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100676
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200677static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100678 { 2, NULL },
679};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100680
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200681static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100682 .num_items = 2,
683 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200684 { "Internal Mic", 0x1 },
685 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100686 }
687};
688
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200689static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200690 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100691 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200692 { "Internal Mic", 0x1 },
693 { "Mic", 0x2 },
694 { "Line", 0x3 },
695 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100696 }
697};
698
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200699static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100700 .num_items = 2,
701 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200702 { "Mic", 0x1 },
703 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100704 }
705};
706
Tobin Davisc9b443d2006-11-14 12:13:39 +0100707/* turn on/off EAPD (+ mute HP) as a master switch */
708static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
709 struct snd_ctl_elem_value *ucontrol)
710{
711 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
712 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100713 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100714
Tobin Davis82f30042007-02-13 12:45:44 +0100715 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100716 return 0;
717
Tobin Davis82f30042007-02-13 12:45:44 +0100718 /* toggle internal speakers mute depending of presence of
719 * the headphone jack
720 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200721 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
722 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
723 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100724
Takashi Iwai47fd8302007-08-10 17:11:07 +0200725 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
726 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
727 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100728 return 1;
729}
730
731/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200732static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200733 .ops = &snd_hda_bind_vol,
734 .values = {
735 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
736 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
737 0
738 },
739};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100740
Tobin Davis7f296732007-03-12 11:39:01 +0100741/* toggle input of built-in and mic jack appropriately */
742static void cxt5045_hp_automic(struct hda_codec *codec)
743{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200744 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100745 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
746 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
747 {}
748 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200749 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100750 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
752 {}
753 };
754 unsigned int present;
755
Takashi Iwaid56757a2009-11-18 08:00:14 +0100756 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100757 if (present)
758 snd_hda_sequence_write(codec, mic_jack_on);
759 else
760 snd_hda_sequence_write(codec, mic_jack_off);
761}
762
Tobin Davisc9b443d2006-11-14 12:13:39 +0100763
764/* mute internal speaker if HP is plugged */
765static void cxt5045_hp_automute(struct hda_codec *codec)
766{
Tobin Davis82f30042007-02-13 12:45:44 +0100767 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100768 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769
Takashi Iwaid56757a2009-11-18 08:00:14 +0100770 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100771
Takashi Iwai47fd8302007-08-10 17:11:07 +0200772 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
773 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
774 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775}
776
777/* unsolicited event for HP jack sensing */
778static void cxt5045_hp_unsol_event(struct hda_codec *codec,
779 unsigned int res)
780{
781 res >>= 26;
782 switch (res) {
783 case CONEXANT_HP_EVENT:
784 cxt5045_hp_automute(codec);
785 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100786 case CONEXANT_MIC_EVENT:
787 cxt5045_hp_automic(codec);
788 break;
789
Tobin Davisc9b443d2006-11-14 12:13:39 +0100790 }
791}
792
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200793static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200794 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
795 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200796 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
797 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100798 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
799 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100800 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
801 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200802 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100803 {
804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100806 .info = cxt_eapd_info,
807 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100808 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100809 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100810 },
811
812 {}
813};
814
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200815static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200816 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
817 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200818
Jiang Zhe5218c892008-01-17 11:18:41 +0100819 {}
820};
821
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200822static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200823 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
824 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100825 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
826 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100827 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
828 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100829 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
830 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100831 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
832 {
833 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
834 .name = "Master Playback Switch",
835 .info = cxt_eapd_info,
836 .get = cxt_eapd_get,
837 .put = cxt5045_hp_master_sw_put,
838 .private_value = 0x10,
839 },
840
841 {}
842};
843
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200844static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100845 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200846 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100847 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100848 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200849 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
850 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
851 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
852 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
853 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
854 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
857 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100858 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100859 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100860 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100861 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
862 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100863 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100864 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100865 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100866 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100867 { } /* end */
868};
869
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200870static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100871 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100872 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
873 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
874 /* Line In,HP, Amp */
875 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
876 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
877 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
878 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
881 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100884 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100885 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
886 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
887 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
888 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100889 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100890 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
891 /* EAPD */
892 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
893 { } /* end */
894};
Tobin Davis7f296732007-03-12 11:39:01 +0100895
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200896static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100897 /* pin sensing on HP jack */
898 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200899 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100900};
901
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200902static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100903 /* pin sensing on HP jack */
904 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200905 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100906};
907
Tobin Davisc9b443d2006-11-14 12:13:39 +0100908#ifdef CONFIG_SND_DEBUG
909/* Test configuration for debugging, modelled after the ALC260 test
910 * configuration.
911 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200912static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100913 .num_items = 5,
914 .items = {
915 { "MIXER", 0x0 },
916 { "MIC1 pin", 0x1 },
917 { "LINE1 pin", 0x2 },
918 { "HP-OUT pin", 0x3 },
919 { "CD pin", 0x4 },
920 },
921};
922
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200923static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100924
925 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
927 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200928 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
929 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
930 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
931 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932
933 /* Modes for retasking pin widgets */
934 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
935 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
936
Tobin Davis82f30042007-02-13 12:45:44 +0100937 /* EAPD Switch Control */
938 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
939
Tobin Davisc9b443d2006-11-14 12:13:39 +0100940 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941
Michael Karcher250f3272012-04-06 15:34:20 +0200942 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
943 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
944 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
945 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
946 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
947 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
948 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
949 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
950 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
951 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952 {
953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
954 .name = "Input Source",
955 .info = conexant_mux_enum_info,
956 .get = conexant_mux_enum_get,
957 .put = conexant_mux_enum_put,
958 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200959 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200960 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
961 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100962 { } /* end */
963};
964
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200965static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100966 /* Set connections */
967 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
968 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
969 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100970 /* Enable retasking pins as output, initially without power amp */
971 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100972 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100973
974 /* Disable digital (SPDIF) pins initially, but users can enable
975 * them via a mixer switch. In the case of SPDIF-out, this initverb
976 * payload also sets the generation to 0, output to be in "consumer"
977 * PCM format, copyright asserted, no pre-emphasis and no validity
978 * control.
979 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100980 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
981 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100982
Tobin Davisc9b443d2006-11-14 12:13:39 +0100983 /* Unmute retasking pin widget output buffers since the default
984 * state appears to be output. As the pin mode is changed by the
985 * user the pin mode control will take care of enabling the pin's
986 * input/output buffers as needed.
987 */
988 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
989 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
990
991 /* Mute capture amp left and right */
992 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
993
994 /* Set ADC connection select to match default mixer setting (mic1
995 * pin)
996 */
Michael Karcher250f3272012-04-06 15:34:20 +0200997 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
998 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100999
1000 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +02001001 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1003 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1004 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1005 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1006
1007 { }
1008};
1009#endif
1010
1011
1012/* initialize jack-sensing, too */
1013static int cxt5045_init(struct hda_codec *codec)
1014{
1015 conexant_init(codec);
1016 cxt5045_hp_automute(codec);
1017 return 0;
1018}
1019
1020
1021enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001022 CXT5045_LAPTOP_HPSENSE,
1023 CXT5045_LAPTOP_MICSENSE,
1024 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001025 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001026 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001027#ifdef CONFIG_SND_DEBUG
1028 CXT5045_TEST,
1029#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001030 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001031 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001032};
1033
Takashi Iwaiea734962011-01-17 11:29:34 +01001034static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001035 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1036 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1037 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1038 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001039 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001040#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001041 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001042#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001043 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001044};
1045
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001046static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001047 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001048 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001049 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001050 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1051 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001052 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1053 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001054 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1055 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1056 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001057 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1058 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001059 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001060 {}
1061};
1062
1063static int patch_cxt5045(struct hda_codec *codec)
1064{
1065 struct conexant_spec *spec;
1066 int board_config;
1067
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001068 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1069 cxt5045_models,
1070 cxt5045_cfg_tbl);
1071 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001072 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001073 if (board_config == CXT5045_AUTO)
1074 return patch_conexant_auto(codec);
1075
Tobin Davisc9b443d2006-11-14 12:13:39 +01001076 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1077 if (!spec)
1078 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001079 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001080 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001081
1082 spec->multiout.max_channels = 2;
1083 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1084 spec->multiout.dac_nids = cxt5045_dac_nids;
1085 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1086 spec->num_adc_nids = 1;
1087 spec->adc_nids = cxt5045_adc_nids;
1088 spec->capsrc_nids = cxt5045_capsrc_nids;
1089 spec->input_mux = &cxt5045_capture_source;
1090 spec->num_mixers = 1;
1091 spec->mixers[0] = cxt5045_mixers;
1092 spec->num_init_verbs = 1;
1093 spec->init_verbs[0] = cxt5045_init_verbs;
1094 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001095 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1096 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001097
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001098 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001099
1100 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001101
Tobin Davisc9b443d2006-11-14 12:13:39 +01001102 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001103 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001104 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001105 spec->input_mux = &cxt5045_capture_source;
1106 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001107 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1108 spec->mixers[0] = cxt5045_mixers;
1109 codec->patch_ops.init = cxt5045_init;
1110 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001111 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001112 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001113 spec->input_mux = &cxt5045_capture_source;
1114 spec->num_init_verbs = 2;
1115 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116 spec->mixers[0] = cxt5045_mixers;
1117 codec->patch_ops.init = cxt5045_init;
1118 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001119 default:
1120 case CXT5045_LAPTOP_HPMICSENSE:
1121 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1122 spec->input_mux = &cxt5045_capture_source;
1123 spec->num_init_verbs = 3;
1124 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1125 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1126 spec->mixers[0] = cxt5045_mixers;
1127 codec->patch_ops.init = cxt5045_init;
1128 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001129 case CXT5045_BENQ:
1130 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131 spec->input_mux = &cxt5045_capture_source_benq;
1132 spec->num_init_verbs = 1;
1133 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1134 spec->mixers[0] = cxt5045_mixers;
1135 spec->mixers[1] = cxt5045_benq_mixers;
1136 spec->num_mixers = 2;
1137 codec->patch_ops.init = cxt5045_init;
1138 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001139 case CXT5045_LAPTOP_HP530:
1140 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1141 spec->input_mux = &cxt5045_capture_source_hp530;
1142 spec->num_init_verbs = 2;
1143 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1144 spec->mixers[0] = cxt5045_mixers_hp530;
1145 codec->patch_ops.init = cxt5045_init;
1146 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001147#ifdef CONFIG_SND_DEBUG
1148 case CXT5045_TEST:
1149 spec->input_mux = &cxt5045_test_capture_source;
1150 spec->mixers[0] = cxt5045_test_mixer;
1151 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001152 break;
1153
Tobin Davisc9b443d2006-11-14 12:13:39 +01001154#endif
1155 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001156
Takashi Iwai031005f2008-06-26 14:49:58 +02001157 switch (codec->subsystem_id >> 16) {
1158 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001159 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001160 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001161 case 0x17aa:
1162 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1163 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1164 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001165 */
1166 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1167 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1168 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1169 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1170 (1 << AC_AMPCAP_MUTE_SHIFT));
1171 break;
1172 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001173
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001174 if (spec->beep_amp)
1175 snd_hda_attach_beep_device(codec, spec->beep_amp);
1176
Tobin Davisc9b443d2006-11-14 12:13:39 +01001177 return 0;
1178}
1179
1180
1181/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001182#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001183
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001184static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1185static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1186static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001188static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001189 { 2, NULL },
1190};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001192static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001193 .num_items = 2,
1194 .items = {
1195 { "ExtMic", 0x2 },
1196 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197 }
1198};
1199
1200/* turn on/off EAPD (+ mute HP) as a master switch */
1201static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1202 struct snd_ctl_elem_value *ucontrol)
1203{
1204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1205 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001206 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207
Tobin Davis82f30042007-02-13 12:45:44 +01001208 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209 return 0;
1210
Tobin Davis82f30042007-02-13 12:45:44 +01001211 /* toggle internal speakers mute depending of presence of
1212 * the headphone jack
1213 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001214 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001215 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1216 * pin widgets unlike other codecs. In this case, we need to
1217 * set index 0x01 for the volume from the mixer amp 0x19.
1218 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001219 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001220 HDA_AMP_MUTE, bits);
1221 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1222 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1223 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001224 return 1;
1225}
1226
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227/* mute internal speaker if HP is plugged */
1228static void cxt5047_hp_automute(struct hda_codec *codec)
1229{
Tobin Davis82f30042007-02-13 12:45:44 +01001230 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001231 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001232
Takashi Iwaid56757a2009-11-18 08:00:14 +01001233 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001234
Takashi Iwai47fd8302007-08-10 17:11:07 +02001235 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001236 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001237 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001238 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001239}
1240
1241/* toggle input of built-in and mic jack appropriately */
1242static void cxt5047_hp_automic(struct hda_codec *codec)
1243{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001244 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001245 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1246 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247 {}
1248 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001249 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001250 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1251 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001252 {}
1253 };
1254 unsigned int present;
1255
Takashi Iwaid56757a2009-11-18 08:00:14 +01001256 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257 if (present)
1258 snd_hda_sequence_write(codec, mic_jack_on);
1259 else
1260 snd_hda_sequence_write(codec, mic_jack_off);
1261}
1262
1263/* unsolicited event for HP jack sensing */
1264static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1265 unsigned int res)
1266{
Marc Boucher9f113e02008-01-22 15:18:08 +01001267 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001268 case CONEXANT_HP_EVENT:
1269 cxt5047_hp_automute(codec);
1270 break;
1271 case CONEXANT_MIC_EVENT:
1272 cxt5047_hp_automic(codec);
1273 break;
1274 }
1275}
1276
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001277static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001278 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1279 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001280 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001281 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1282 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1283 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1284 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001285 {
1286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1287 .name = "Master Playback Switch",
1288 .info = cxt_eapd_info,
1289 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001290 .put = cxt5047_hp_master_sw_put,
1291 .private_value = 0x13,
1292 },
1293
1294 {}
1295};
1296
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001297static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001298 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001299 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001300 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1301 {}
1302};
1303
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001304static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001305 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001306 { } /* end */
1307};
1308
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001309static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001310 /* Line in, Mic, Built-in Mic */
1311 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1312 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1313 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001314 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001315 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001316 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1317 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001318 /* Record selector: Mic */
1319 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1320 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1321 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1322 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001323 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1324 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1325 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1326 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327 /* SPDIF route: PCM */
1328 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001329 /* Enable unsolicited events */
1330 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1331 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332 { } /* end */
1333};
1334
1335/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001336static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001337 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001338 {}
1339};
1340
1341/* Test configuration for debugging, modelled after the ALC260 test
1342 * configuration.
1343 */
1344#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001345static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001346 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001347 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001348 { "LINE1 pin", 0x0 },
1349 { "MIC1 pin", 0x1 },
1350 { "MIC2 pin", 0x2 },
1351 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001352 },
1353};
1354
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001355static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001356
1357 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001358 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1360 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001366 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1368 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370
1371 /* Modes for retasking pin widgets */
1372 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1373 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1374
Tobin Davis82f30042007-02-13 12:45:44 +01001375 /* EAPD Switch Control */
1376 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1377
Tobin Davisc9b443d2006-11-14 12:13:39 +01001378 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001379 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1380 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1381 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1382 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1383 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1384 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1385 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1386 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387
Tobin Davis82f30042007-02-13 12:45:44 +01001388 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1389 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1390 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1391 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1392 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1393 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1394 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1395 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001396 {
1397 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1398 .name = "Input Source",
1399 .info = conexant_mux_enum_info,
1400 .get = conexant_mux_enum_get,
1401 .put = conexant_mux_enum_put,
1402 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001403 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001404
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405 { } /* end */
1406};
1407
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001408static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001409 /* Enable retasking pins as output, initially without power amp */
1410 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1411 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1412 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1413
1414 /* Disable digital (SPDIF) pins initially, but users can enable
1415 * them via a mixer switch. In the case of SPDIF-out, this initverb
1416 * payload also sets the generation to 0, output to be in "consumer"
1417 * PCM format, copyright asserted, no pre-emphasis and no validity
1418 * control.
1419 */
1420 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1421
1422 /* Ensure mic1, mic2, line1 pin widgets take input from the
1423 * OUT1 sum bus when acting as an output.
1424 */
1425 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1426 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1427
1428 /* Start with output sum widgets muted and their output gains at min */
1429 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1430 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1431
1432 /* Unmute retasking pin widget output buffers since the default
1433 * state appears to be output. As the pin mode is changed by the
1434 * user the pin mode control will take care of enabling the pin's
1435 * input/output buffers as needed.
1436 */
1437 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1438 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1439 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1440
1441 /* Mute capture amp left and right */
1442 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1443
1444 /* Set ADC connection select to match default mixer setting (mic1
1445 * pin)
1446 */
1447 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1448
1449 /* Mute all inputs to mixer widget (even unconnected ones) */
1450 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1451 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1452 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1453 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1454 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1455 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1456 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1457 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1458
1459 { }
1460};
1461#endif
1462
1463
1464/* initialize jack-sensing, too */
1465static int cxt5047_hp_init(struct hda_codec *codec)
1466{
1467 conexant_init(codec);
1468 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001469 return 0;
1470}
1471
1472
1473enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001474 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1475 CXT5047_LAPTOP_HP, /* Some HP laptops */
1476 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001477#ifdef CONFIG_SND_DEBUG
1478 CXT5047_TEST,
1479#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001480 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001481 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001482};
1483
Takashi Iwaiea734962011-01-17 11:29:34 +01001484static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001485 [CXT5047_LAPTOP] = "laptop",
1486 [CXT5047_LAPTOP_HP] = "laptop-hp",
1487 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001488#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001489 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001490#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001491 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001492};
1493
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001494static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001495 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001496 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1497 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001498 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001499 {}
1500};
1501
1502static int patch_cxt5047(struct hda_codec *codec)
1503{
1504 struct conexant_spec *spec;
1505 int board_config;
1506
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001507 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1508 cxt5047_models,
1509 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001510 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001511 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001512 if (board_config == CXT5047_AUTO)
1513 return patch_conexant_auto(codec);
1514
Tobin Davisc9b443d2006-11-14 12:13:39 +01001515 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1516 if (!spec)
1517 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001518 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001519 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001520
1521 spec->multiout.max_channels = 2;
1522 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1523 spec->multiout.dac_nids = cxt5047_dac_nids;
1524 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1525 spec->num_adc_nids = 1;
1526 spec->adc_nids = cxt5047_adc_nids;
1527 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001528 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001529 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001530 spec->num_init_verbs = 1;
1531 spec->init_verbs[0] = cxt5047_init_verbs;
1532 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001533 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1534 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001535
1536 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001537
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538 switch (board_config) {
1539 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001540 spec->num_mixers = 2;
1541 spec->mixers[1] = cxt5047_hp_spk_mixers;
1542 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001543 break;
1544 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001545 spec->num_mixers = 2;
1546 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001547 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001548 codec->patch_ops.init = cxt5047_hp_init;
1549 break;
1550 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001551 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001552 spec->num_mixers = 2;
1553 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001554 spec->num_init_verbs = 2;
1555 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001556 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557 break;
1558#ifdef CONFIG_SND_DEBUG
1559 case CXT5047_TEST:
1560 spec->input_mux = &cxt5047_test_capture_source;
1561 spec->mixers[0] = cxt5047_test_mixer;
1562 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001563 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001564#endif
1565 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001566 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001567
1568 switch (codec->subsystem_id >> 16) {
1569 case 0x103c:
1570 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1571 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1572 * with 0 dB offset 0x17)
1573 */
1574 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1575 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1576 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1577 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1578 (1 << AC_AMPCAP_MUTE_SHIFT));
1579 break;
1580 }
1581
Tobin Davisc9b443d2006-11-14 12:13:39 +01001582 return 0;
1583}
1584
Takashi Iwai461e2c72008-01-25 11:35:17 +01001585/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001586static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1587static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001588
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001589static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001590 { 2, NULL },
1591};
1592
1593static void cxt5051_update_speaker(struct hda_codec *codec)
1594{
1595 struct conexant_spec *spec = codec->spec;
1596 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001597 /* headphone pin */
1598 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001599 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
Takashi Iwai23d2df52010-01-24 11:19:27 +01001600 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001601 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001602 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001603 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001604 if (spec->ideapad)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001605 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001606}
1607
1608/* turn on/off EAPD (+ mute HP) as a master switch */
1609static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1611{
1612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1613
1614 if (!cxt_eapd_put(kcontrol, ucontrol))
1615 return 0;
1616 cxt5051_update_speaker(codec);
1617 return 1;
1618}
1619
1620/* toggle input of built-in and mic jack appropriately */
1621static void cxt5051_portb_automic(struct hda_codec *codec)
1622{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001623 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001624 unsigned int present;
1625
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001626 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001627 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001628 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001629 snd_hda_codec_write(codec, 0x14, 0,
1630 AC_VERB_SET_CONNECT_SEL,
1631 present ? 0x01 : 0x00);
1632}
1633
1634/* switch the current ADC according to the jack state */
1635static void cxt5051_portc_automic(struct hda_codec *codec)
1636{
1637 struct conexant_spec *spec = codec->spec;
1638 unsigned int present;
1639 hda_nid_t new_adc;
1640
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001641 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001642 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001643 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001644 if (present)
1645 spec->cur_adc_idx = 1;
1646 else
1647 spec->cur_adc_idx = 0;
1648 new_adc = spec->adc_nids[spec->cur_adc_idx];
1649 if (spec->cur_adc && spec->cur_adc != new_adc) {
1650 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001651 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001652 spec->cur_adc = new_adc;
1653 snd_hda_codec_setup_stream(codec, new_adc,
1654 spec->cur_adc_stream_tag, 0,
1655 spec->cur_adc_format);
1656 }
1657}
1658
1659/* mute internal speaker if HP is plugged */
1660static void cxt5051_hp_automute(struct hda_codec *codec)
1661{
1662 struct conexant_spec *spec = codec->spec;
1663
Takashi Iwaid56757a2009-11-18 08:00:14 +01001664 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001665 cxt5051_update_speaker(codec);
1666}
1667
1668/* unsolicited event for HP jack sensing */
1669static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1670 unsigned int res)
1671{
1672 switch (res >> 26) {
1673 case CONEXANT_HP_EVENT:
1674 cxt5051_hp_automute(codec);
1675 break;
1676 case CXT5051_PORTB_EVENT:
1677 cxt5051_portb_automic(codec);
1678 break;
1679 case CXT5051_PORTC_EVENT:
1680 cxt5051_portc_automic(codec);
1681 break;
1682 }
1683}
1684
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001685static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001686 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1687 {
1688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1689 .name = "Master Playback Switch",
1690 .info = cxt_eapd_info,
1691 .get = cxt_eapd_get,
1692 .put = cxt5051_hp_master_sw_put,
1693 .private_value = 0x1a,
1694 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001695 {}
1696};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001697
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001698static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001699 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1700 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001701 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1702 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
David Henningssonc40bd912012-09-19 12:19:47 +02001703 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1704 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001705 {}
1706};
1707
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001708static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001709 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1710 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001711 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1712 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001713 {}
1714};
1715
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001716static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001717 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1718 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001719 {}
1720};
1721
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001722static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001723 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1724 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001725 {}
1726};
1727
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001728static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001729 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1730 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001731 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1732 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001733 {}
1734};
1735
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001736static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001737 /* Line in, Mic */
1738 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1739 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1740 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1741 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1742 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1743 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1744 /* SPK */
1745 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1746 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1747 /* HP, Amp */
1748 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1749 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1750 /* DAC1 */
1751 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001752 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001753 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1755 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1756 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001757 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001758 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1759 /* EAPD */
1760 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1761 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001762 { } /* end */
1763};
1764
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001765static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001766 /* Line in, Mic */
1767 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1768 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1769 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1770 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1771 /* SPK */
1772 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1773 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1774 /* HP, Amp */
1775 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1776 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1777 /* DAC1 */
1778 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001779 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1781 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1782 /* SPDIF route: PCM */
1783 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1784 /* EAPD */
1785 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1786 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001787 { } /* end */
1788};
1789
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001790static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001791 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001792 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001793 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1794 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1795 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1796 /* SPK */
1797 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1798 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1799 /* HP, Amp */
1800 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1801 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1802 /* DAC1 */
1803 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001804 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1806 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1807 /* SPDIF route: PCM */
1808 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1809 /* EAPD */
1810 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1811 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001812 { } /* end */
1813};
1814
Takashi Iwai6953e552010-01-24 11:00:27 +01001815static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1816 unsigned int event)
1817{
1818 snd_hda_codec_write(codec, nid, 0,
1819 AC_VERB_SET_UNSOLICITED_ENABLE,
1820 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001821}
1822
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001823static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001824 /* Subwoofer */
1825 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1826 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1827 { } /* end */
1828};
1829
Takashi Iwai461e2c72008-01-25 11:35:17 +01001830/* initialize jack-sensing, too */
1831static int cxt5051_init(struct hda_codec *codec)
1832{
Takashi Iwai6953e552010-01-24 11:00:27 +01001833 struct conexant_spec *spec = codec->spec;
1834
Takashi Iwai461e2c72008-01-25 11:35:17 +01001835 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001836
1837 if (spec->auto_mic & AUTO_MIC_PORTB)
1838 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1839 if (spec->auto_mic & AUTO_MIC_PORTC)
1840 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1841
Takashi Iwai461e2c72008-01-25 11:35:17 +01001842 if (codec->patch_ops.unsol_event) {
1843 cxt5051_hp_automute(codec);
1844 cxt5051_portb_automic(codec);
1845 cxt5051_portc_automic(codec);
1846 }
1847 return 0;
1848}
1849
1850
1851enum {
1852 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1853 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001854 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001855 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001856 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001857 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001858 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001859 CXT5051_MODELS
1860};
1861
Takashi Iwaiea734962011-01-17 11:29:34 +01001862static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001863 [CXT5051_LAPTOP] = "laptop",
1864 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001865 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001866 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001867 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001868 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001869 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001870};
1871
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001872static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001873 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001874 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001875 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001876 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001877 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1878 CXT5051_LAPTOP),
1879 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001880 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001881 {}
1882};
1883
1884static int patch_cxt5051(struct hda_codec *codec)
1885{
1886 struct conexant_spec *spec;
1887 int board_config;
1888
Takashi Iwai6764bce2011-05-13 16:52:25 +02001889 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1890 cxt5051_models,
1891 cxt5051_cfg_tbl);
1892 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001893 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001894 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001895 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001896
Takashi Iwai461e2c72008-01-25 11:35:17 +01001897 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1898 if (!spec)
1899 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001900 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001901 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001902
1903 codec->patch_ops = conexant_patch_ops;
1904 codec->patch_ops.init = cxt5051_init;
1905
1906 spec->multiout.max_channels = 2;
1907 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1908 spec->multiout.dac_nids = cxt5051_dac_nids;
1909 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1910 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1911 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001912 spec->num_mixers = 2;
1913 spec->mixers[0] = cxt5051_capture_mixers;
1914 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001915 spec->num_init_verbs = 1;
1916 spec->init_verbs[0] = cxt5051_init_verbs;
1917 spec->spdif_route = 0;
1918 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1919 spec->channel_mode = cxt5051_modes;
1920 spec->cur_adc = 0;
1921 spec->cur_adc_idx = 0;
1922
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001923 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1924
Takashi Iwai79d7d532009-03-04 09:03:50 +01001925 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1926
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001927 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001928 switch (board_config) {
1929 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001930 spec->mixers[0] = cxt5051_hp_mixers;
1931 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001932 case CXT5051_HP_DV6736:
1933 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1934 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001935 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001936 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001937 case CXT5051_F700:
1938 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1939 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001940 spec->auto_mic = 0;
1941 break;
1942 case CXT5051_TOSHIBA:
1943 spec->mixers[0] = cxt5051_toshiba_mixers;
1944 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001945 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001946 case CXT5051_IDEAPAD:
1947 spec->init_verbs[spec->num_init_verbs++] =
1948 cxt5051_ideapad_init_verbs;
1949 spec->ideapad = 1;
1950 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001951 }
1952
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001953 if (spec->beep_amp)
1954 snd_hda_attach_beep_device(codec, spec->beep_amp);
1955
Takashi Iwai461e2c72008-01-25 11:35:17 +01001956 return 0;
1957}
1958
Daniel Drake0fb67e92009-07-16 14:46:57 +01001959/* Conexant 5066 specific */
1960
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001961static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1962static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1963static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1964static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001965
Daniel Drakedbaccc02009-11-09 15:17:24 +00001966/* OLPC's microphone port is DC coupled for use with external sensors,
1967 * therefore we use a 50% mic bias in order to center the input signal with
1968 * the DC input range of the codec. */
1969#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1970
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001971static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001972 { 2, NULL },
1973};
1974
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001975#define HP_PRESENT_PORT_A (1 << 0)
1976#define HP_PRESENT_PORT_D (1 << 1)
1977#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1978#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1979
Daniel Drake0fb67e92009-07-16 14:46:57 +01001980static void cxt5066_update_speaker(struct hda_codec *codec)
1981{
1982 struct conexant_spec *spec = codec->spec;
1983 unsigned int pinctl;
1984
John Baboval3a253442010-12-02 11:21:31 -05001985 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1986 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001987
1988 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001989 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001990 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001991
1992 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001993 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1994 if (spec->dell_automute || spec->thinkpad) {
1995 /* Mute if Port A is connected */
1996 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05001997 pinctl = 0;
1998 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001999 /* Thinkpad/Dell doesn't give pin-D status */
2000 if (!hp_port_d_present(spec))
2001 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002002 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002003 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002004
2005 /* CLASS_D AMP */
2006 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002007 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002008}
2009
2010/* turn on/off EAPD (+ mute HP) as a master switch */
2011static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2012 struct snd_ctl_elem_value *ucontrol)
2013{
2014 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2015
2016 if (!cxt_eapd_put(kcontrol, ucontrol))
2017 return 0;
2018
2019 cxt5066_update_speaker(codec);
2020 return 1;
2021}
2022
Daniel Drakec4cfe662010-01-07 13:47:04 +01002023static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2024 .num_items = 3,
2025 .items = {
2026 { "Off", PIN_IN },
2027 { "50%", PIN_VREF50 },
2028 { "80%", PIN_VREF80 },
2029 },
2030};
2031
2032static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2033{
2034 struct conexant_spec *spec = codec->spec;
2035 /* Even though port F is the DC input, the bias is controlled on port B.
2036 * we also leave that port as an active input (but unselected) in DC mode
2037 * just in case that is necessary to make the bias setting take effect. */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002038 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002039 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2040}
2041
Daniel Drake75f89912010-01-07 13:46:25 +01002042/* OLPC defers mic widget control until when capture is started because the
2043 * microphone LED comes on as soon as these settings are put in place. if we
2044 * did this before recording, it would give the false indication that recording
2045 * is happening when it is not. */
2046static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002047{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002048 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002049 if (!spec->recording)
2050 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002051
Daniel Drakec4cfe662010-01-07 13:47:04 +01002052 if (spec->dc_enable) {
2053 /* in DC mode we ignore presence detection and just use the jack
2054 * through our special DC port */
2055 const struct hda_verb enable_dc_mode[] = {
2056 /* disble internal mic, port C */
2057 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2058
2059 /* enable DC capture, port F */
2060 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2061 {},
2062 };
2063
2064 snd_hda_sequence_write(codec, enable_dc_mode);
2065 /* port B input disabled (and bias set) through the following call */
2066 cxt5066_set_olpc_dc_bias(codec);
2067 return;
2068 }
2069
2070 /* disable DC (port F) */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002071 snd_hda_set_pin_ctl(codec, 0x1e, 0);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002072
Daniel Drake75f89912010-01-07 13:46:25 +01002073 /* external mic, port B */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002074 snd_hda_set_pin_ctl(codec, 0x1a,
Daniel Drake75f89912010-01-07 13:46:25 +01002075 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002076
Daniel Drake75f89912010-01-07 13:46:25 +01002077 /* internal mic, port C */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002078 snd_hda_set_pin_ctl(codec, 0x1b,
Daniel Drake75f89912010-01-07 13:46:25 +01002079 spec->ext_mic_present ? 0 : PIN_VREF80);
2080}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002081
Daniel Drake75f89912010-01-07 13:46:25 +01002082/* toggle input of built-in and mic jack appropriately */
2083static void cxt5066_olpc_automic(struct hda_codec *codec)
2084{
2085 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002086 unsigned int present;
2087
Daniel Drakec4cfe662010-01-07 13:47:04 +01002088 if (spec->dc_enable) /* don't do presence detection in DC mode */
2089 return;
2090
Daniel Drake75f89912010-01-07 13:46:25 +01002091 present = snd_hda_codec_read(codec, 0x1a, 0,
2092 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2093 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002094 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002095 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002096 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002097
2098 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2099 present ? 0 : 1);
2100 spec->ext_mic_present = !!present;
2101
2102 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002103}
2104
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002105/* toggle input of built-in digital mic and mic jack appropriately */
2106static void cxt5066_vostro_automic(struct hda_codec *codec)
2107{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002108 unsigned int present;
2109
2110 struct hda_verb ext_mic_present[] = {
2111 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002112 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002113
2114 /* switch to external mic input */
2115 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2116 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2117
2118 /* disable internal digital mic */
2119 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2120 {}
2121 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002122 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002123 /* enable internal mic, port C */
2124 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2125
2126 /* switch to internal mic input */
2127 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2128
2129 /* disable external mic, port B */
2130 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2131 {}
2132 };
2133
2134 present = snd_hda_jack_detect(codec, 0x1a);
2135 if (present) {
2136 snd_printdd("CXT5066: external microphone detected\n");
2137 snd_hda_sequence_write(codec, ext_mic_present);
2138 } else {
2139 snd_printdd("CXT5066: external microphone absent\n");
2140 snd_hda_sequence_write(codec, ext_mic_absent);
2141 }
2142}
2143
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002144/* toggle input of built-in digital mic and mic jack appropriately */
2145static void cxt5066_ideapad_automic(struct hda_codec *codec)
2146{
2147 unsigned int present;
2148
2149 struct hda_verb ext_mic_present[] = {
2150 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2151 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2152 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2153 {}
2154 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002155 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002156 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2157 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2158 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2159 {}
2160 };
2161
2162 present = snd_hda_jack_detect(codec, 0x1b);
2163 if (present) {
2164 snd_printdd("CXT5066: external microphone detected\n");
2165 snd_hda_sequence_write(codec, ext_mic_present);
2166 } else {
2167 snd_printdd("CXT5066: external microphone absent\n");
2168 snd_hda_sequence_write(codec, ext_mic_absent);
2169 }
2170}
2171
David Henningssona1d69062011-01-21 13:33:28 +01002172
2173/* toggle input of built-in digital mic and mic jack appropriately */
2174static void cxt5066_asus_automic(struct hda_codec *codec)
2175{
2176 unsigned int present;
2177
2178 present = snd_hda_jack_detect(codec, 0x1b);
2179 snd_printdd("CXT5066: external microphone present=%d\n", present);
2180 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2181 present ? 1 : 0);
2182}
2183
2184
David Henningsson048e78a2010-09-02 08:35:47 +02002185/* toggle input of built-in digital mic and mic jack appropriately */
2186static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2187{
2188 unsigned int present;
2189
2190 present = snd_hda_jack_detect(codec, 0x1b);
2191 snd_printdd("CXT5066: external microphone present=%d\n", present);
2192 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2193 present ? 1 : 3);
2194}
2195
2196
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002197/* toggle input of built-in digital mic and mic jack appropriately
2198 order is: external mic -> dock mic -> interal mic */
2199static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2200{
2201 unsigned int ext_present, dock_present;
2202
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002203 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002204 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2205 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2206 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2207 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2208 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2209 {}
2210 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002211 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002212 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2213 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2214 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2215 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2216 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2217 {}
2218 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002219 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002220 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2221 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2222 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2224 {}
2225 };
2226
2227 ext_present = snd_hda_jack_detect(codec, 0x1b);
2228 dock_present = snd_hda_jack_detect(codec, 0x1a);
2229 if (ext_present) {
2230 snd_printdd("CXT5066: external microphone detected\n");
2231 snd_hda_sequence_write(codec, ext_mic_present);
2232 } else if (dock_present) {
2233 snd_printdd("CXT5066: dock microphone detected\n");
2234 snd_hda_sequence_write(codec, dock_mic_present);
2235 } else {
2236 snd_printdd("CXT5066: external microphone absent\n");
2237 snd_hda_sequence_write(codec, ext_mic_absent);
2238 }
2239}
2240
Daniel Drake0fb67e92009-07-16 14:46:57 +01002241/* mute internal speaker if HP is plugged */
2242static void cxt5066_hp_automute(struct hda_codec *codec)
2243{
2244 struct conexant_spec *spec = codec->spec;
2245 unsigned int portA, portD;
2246
2247 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002248 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002249
2250 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002251 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002252
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002253 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2254 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002255 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2256 portA, portD, spec->hp_present);
2257 cxt5066_update_speaker(codec);
2258}
2259
David Henningsson02b6b5b2011-01-21 13:27:39 +01002260/* Dispatch the right mic autoswitch function */
2261static void cxt5066_automic(struct hda_codec *codec)
2262{
2263 struct conexant_spec *spec = codec->spec;
2264
2265 if (spec->dell_vostro)
2266 cxt5066_vostro_automic(codec);
2267 else if (spec->ideapad)
2268 cxt5066_ideapad_automic(codec);
2269 else if (spec->thinkpad)
2270 cxt5066_thinkpad_automic(codec);
2271 else if (spec->hp_laptop)
2272 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002273 else if (spec->asus)
2274 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002275}
2276
Daniel Drake0fb67e92009-07-16 14:46:57 +01002277/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002278static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002279{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002280 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002281 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2282 switch (res >> 26) {
2283 case CONEXANT_HP_EVENT:
2284 cxt5066_hp_automute(codec);
2285 break;
2286 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002287 /* ignore mic events in DC mode; we're always using the jack */
2288 if (!spec->dc_enable)
2289 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002290 break;
2291 }
2292}
2293
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002294/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002295static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002296{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002297 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002298 switch (res >> 26) {
2299 case CONEXANT_HP_EVENT:
2300 cxt5066_hp_automute(codec);
2301 break;
2302 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002303 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002304 break;
2305 }
2306}
2307
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002308
Daniel Drake0fb67e92009-07-16 14:46:57 +01002309static const struct hda_input_mux cxt5066_analog_mic_boost = {
2310 .num_items = 5,
2311 .items = {
2312 { "0dB", 0 },
2313 { "10dB", 1 },
2314 { "20dB", 2 },
2315 { "30dB", 3 },
2316 { "40dB", 4 },
2317 },
2318};
2319
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002320static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002321{
2322 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002323 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002324 AC_VERB_SET_AMP_GAIN_MUTE,
2325 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2326 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002327 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002328 /* adjust the internal mic as well...it is not through 0x17 */
2329 snd_hda_codec_write_cache(codec, 0x23, 0,
2330 AC_VERB_SET_AMP_GAIN_MUTE,
2331 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2332 cxt5066_analog_mic_boost.
2333 items[spec->mic_boost].index);
2334 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002335}
2336
Daniel Drake0fb67e92009-07-16 14:46:57 +01002337static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2338 struct snd_ctl_elem_info *uinfo)
2339{
2340 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2341}
2342
2343static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2344 struct snd_ctl_elem_value *ucontrol)
2345{
2346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002347 struct conexant_spec *spec = codec->spec;
2348 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002349 return 0;
2350}
2351
2352static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2353 struct snd_ctl_elem_value *ucontrol)
2354{
2355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002356 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002357 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2358 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359 idx = ucontrol->value.enumerated.item[0];
2360 if (idx >= imux->num_items)
2361 idx = imux->num_items - 1;
2362
Daniel Drakec4cfe662010-01-07 13:47:04 +01002363 spec->mic_boost = idx;
2364 if (!spec->dc_enable)
2365 cxt5066_set_mic_boost(codec);
2366 return 1;
2367}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002368
Daniel Drakec4cfe662010-01-07 13:47:04 +01002369static void cxt5066_enable_dc(struct hda_codec *codec)
2370{
2371 const struct hda_verb enable_dc_mode[] = {
2372 /* disable gain */
2373 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2374
2375 /* switch to DC input */
2376 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2377 {}
2378 };
2379
2380 /* configure as input source */
2381 snd_hda_sequence_write(codec, enable_dc_mode);
2382 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2383}
2384
2385static void cxt5066_disable_dc(struct hda_codec *codec)
2386{
2387 /* reconfigure input source */
2388 cxt5066_set_mic_boost(codec);
2389 /* automic also selects the right mic if we're recording */
2390 cxt5066_olpc_automic(codec);
2391}
2392
2393static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2394 struct snd_ctl_elem_value *ucontrol)
2395{
2396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2397 struct conexant_spec *spec = codec->spec;
2398 ucontrol->value.integer.value[0] = spec->dc_enable;
2399 return 0;
2400}
2401
2402static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2403 struct snd_ctl_elem_value *ucontrol)
2404{
2405 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2406 struct conexant_spec *spec = codec->spec;
2407 int dc_enable = !!ucontrol->value.integer.value[0];
2408
2409 if (dc_enable == spec->dc_enable)
2410 return 0;
2411
2412 spec->dc_enable = dc_enable;
2413 if (dc_enable)
2414 cxt5066_enable_dc(codec);
2415 else
2416 cxt5066_disable_dc(codec);
2417
2418 return 1;
2419}
2420
2421static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2422 struct snd_ctl_elem_info *uinfo)
2423{
2424 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2425}
2426
2427static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2428 struct snd_ctl_elem_value *ucontrol)
2429{
2430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2431 struct conexant_spec *spec = codec->spec;
2432 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2433 return 0;
2434}
2435
2436static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2437 struct snd_ctl_elem_value *ucontrol)
2438{
2439 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2440 struct conexant_spec *spec = codec->spec;
2441 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2442 unsigned int idx;
2443
2444 idx = ucontrol->value.enumerated.item[0];
2445 if (idx >= imux->num_items)
2446 idx = imux->num_items - 1;
2447
2448 spec->dc_input_bias = idx;
2449 if (spec->dc_enable)
2450 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002451 return 1;
2452}
2453
Daniel Drake75f89912010-01-07 13:46:25 +01002454static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2455{
2456 struct conexant_spec *spec = codec->spec;
2457 /* mark as recording and configure the microphone widget so that the
2458 * recording LED comes on. */
2459 spec->recording = 1;
2460 cxt5066_olpc_select_mic(codec);
2461}
2462
2463static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2464{
2465 struct conexant_spec *spec = codec->spec;
2466 const struct hda_verb disable_mics[] = {
2467 /* disable external mic, port B */
2468 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2469
2470 /* disble internal mic, port C */
2471 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002472
2473 /* disable DC capture, port F */
2474 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002475 {},
2476 };
2477
2478 snd_hda_sequence_write(codec, disable_mics);
2479 spec->recording = 0;
2480}
2481
Andy Robinsonf6a24912011-01-24 10:12:37 -05002482static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002483 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002484 int num_pins)
2485{
2486 struct conexant_spec *spec = codec->spec;
2487 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2488 int i;
2489
2490 for (i = 0; i < num_pins; i++, dig_pins++) {
2491 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2492 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2493 continue;
2494 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2495 continue;
2496 if (spec->slave_dig_outs[0])
2497 nid_loc++;
2498 else
2499 nid_loc = spec->slave_dig_outs;
2500 }
2501}
2502
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002503static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002504 .num_items = 4,
2505 .items = {
2506 { "Mic B", 0 },
2507 { "Mic C", 1 },
2508 { "Mic E", 2 },
2509 { "Mic F", 3 },
2510 },
2511};
2512
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002513static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002514 .ops = &snd_hda_bind_vol,
2515 .values = {
2516 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2517 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2518 0
2519 },
2520};
2521
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002522static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002523 .ops = &snd_hda_bind_sw,
2524 .values = {
2525 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2526 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2527 0
2528 },
2529};
2530
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002531static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002532 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2533 {}
2534};
2535
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002536static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002537 {
2538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2539 .name = "Master Playback Volume",
2540 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2541 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2542 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002543 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002544 .info = snd_hda_mixer_amp_volume_info,
2545 .get = snd_hda_mixer_amp_volume_get,
2546 .put = snd_hda_mixer_amp_volume_put,
2547 .tlv = { .c = snd_hda_mixer_amp_tlv },
2548 /* offset by 28 volume steps to limit minimum gain to -46dB */
2549 .private_value =
2550 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2551 },
2552 {}
2553};
2554
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002555static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002556 {
2557 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2558 .name = "DC Mode Enable Switch",
2559 .info = snd_ctl_boolean_mono_info,
2560 .get = cxt5066_olpc_dc_get,
2561 .put = cxt5066_olpc_dc_put,
2562 },
2563 {
2564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2565 .name = "DC Input Bias Enum",
2566 .info = cxt5066_olpc_dc_bias_enum_info,
2567 .get = cxt5066_olpc_dc_bias_enum_get,
2568 .put = cxt5066_olpc_dc_bias_enum_put,
2569 },
2570 {}
2571};
2572
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002573static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002574 {
2575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2576 .name = "Master Playback Switch",
2577 .info = cxt_eapd_info,
2578 .get = cxt_eapd_get,
2579 .put = cxt5066_hp_master_sw_put,
2580 .private_value = 0x1d,
2581 },
2582
2583 {
2584 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002585 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002586 .info = cxt5066_mic_boost_mux_enum_info,
2587 .get = cxt5066_mic_boost_mux_enum_get,
2588 .put = cxt5066_mic_boost_mux_enum_put,
2589 },
2590
2591 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2592 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2593 {}
2594};
2595
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002596static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002597 {
2598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002599 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002600 .info = cxt5066_mic_boost_mux_enum_info,
2601 .get = cxt5066_mic_boost_mux_enum_get,
2602 .put = cxt5066_mic_boost_mux_enum_put,
2603 .private_value = 0x23 | 0x100,
2604 },
2605 {}
2606};
2607
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002608static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002609 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2610 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2611 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2612 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2613
2614 /* Speakers */
2615 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2616 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2617
2618 /* HP, Amp */
2619 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2620 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2621
2622 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2623 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2624
2625 /* DAC1 */
2626 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2627
2628 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2629 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2630 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2631 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2632 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2633 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2634
2635 /* no digital microphone support yet */
2636 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2637
2638 /* Audio input selector */
2639 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2640
2641 /* SPDIF route: PCM */
2642 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2643 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2644
2645 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2646 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2647
2648 /* EAPD */
2649 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2650
2651 /* not handling these yet */
2652 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2653 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2654 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2655 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2656 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2657 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2658 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2659 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2660 { } /* end */
2661};
2662
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002663static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002664 /* Port A: headphones */
2665 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2666 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2667
2668 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002669 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002670
2671 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002672 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002673
2674 /* Port D: unused */
2675 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2676
2677 /* Port E: unused, but has primary EAPD */
2678 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2679 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2680
Daniel Drakec4cfe662010-01-07 13:47:04 +01002681 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002682 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2683
2684 /* Port G: internal speakers */
2685 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2686 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2687
2688 /* DAC1 */
2689 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2690
2691 /* DAC2: unused */
2692 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2693
2694 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2695 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2696 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2697 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2698 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2699 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2700 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2701 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2702 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2703 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2704 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2705 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2706
2707 /* Disable digital microphone port */
2708 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2709
2710 /* Audio input selectors */
2711 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2712 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2713
2714 /* Disable SPDIF */
2715 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2716 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2717
2718 /* enable unsolicited events for Port A and B */
2719 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2720 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2721 { } /* end */
2722};
2723
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002724static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002725 /* Port A: headphones */
2726 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2728
2729 /* Port B: external microphone */
2730 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2731
2732 /* Port C: unused */
2733 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2734
2735 /* Port D: unused */
2736 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2737
2738 /* Port E: unused, but has primary EAPD */
2739 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2740 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2741
2742 /* Port F: unused */
2743 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2744
2745 /* Port G: internal speakers */
2746 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2747 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2748
2749 /* DAC1 */
2750 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2751
2752 /* DAC2: unused */
2753 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2754
2755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2759 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2760 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2761 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2762 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2763 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2764 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2765 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2766 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2767
2768 /* Digital microphone port */
2769 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2770
2771 /* Audio input selectors */
2772 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2773 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2774
2775 /* Disable SPDIF */
2776 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2777 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2778
2779 /* enable unsolicited events for Port A and B */
2780 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2781 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2782 { } /* end */
2783};
2784
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002785static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002786 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2787 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2788 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2789 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2790
2791 /* Speakers */
2792 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2793 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2794
2795 /* HP, Amp */
2796 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2797 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2798
2799 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2800 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2801
2802 /* DAC1 */
2803 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2804
2805 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2811 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2812
2813 /* Audio input selector */
2814 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2815 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2816
2817 /* SPDIF route: PCM */
2818 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2819 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2820
2821 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2822 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2823
2824 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002825 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002826
2827 /* EAPD */
2828 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2829
2830 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2831 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2832 { } /* end */
2833};
2834
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002835static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002836 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2837 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2838
2839 /* Port G: internal speakers */
2840 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2841 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2842
2843 /* Port A: HP, Amp */
2844 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2845 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2846
2847 /* Port B: Mic Dock */
2848 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2849
2850 /* Port C: Mic */
2851 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2852
2853 /* Port D: HP Dock, Amp */
2854 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2856
2857 /* DAC1 */
2858 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2859
2860 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2861 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2862 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2863 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2864 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2866 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2867
2868 /* Audio input selector */
2869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2870 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2871
2872 /* SPDIF route: PCM */
2873 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2874 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2875
2876 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2877 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2878
2879 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002880 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002881
2882 /* EAPD */
2883 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2884
2885 /* enable unsolicited events for Port A, B, C and D */
2886 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2887 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2888 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2889 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2890 { } /* end */
2891};
2892
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002893static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002894 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2895 { } /* end */
2896};
2897
David Henningsson048e78a2010-09-02 08:35:47 +02002898
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002899static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002900 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2901 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2903 { } /* end */
2904};
2905
Daniel Drake0fb67e92009-07-16 14:46:57 +01002906/* initialize jack-sensing, too */
2907static int cxt5066_init(struct hda_codec *codec)
2908{
2909 snd_printdd("CXT5066: init\n");
2910 conexant_init(codec);
2911 if (codec->patch_ops.unsol_event) {
2912 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002913 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002914 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002915 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002916 return 0;
2917}
2918
Daniel Drake75f89912010-01-07 13:46:25 +01002919static int cxt5066_olpc_init(struct hda_codec *codec)
2920{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002921 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002922 snd_printdd("CXT5066: init\n");
2923 conexant_init(codec);
2924 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002925 if (!spec->dc_enable) {
2926 cxt5066_set_mic_boost(codec);
2927 cxt5066_olpc_automic(codec);
2928 } else {
2929 cxt5066_enable_dc(codec);
2930 }
Daniel Drake75f89912010-01-07 13:46:25 +01002931 return 0;
2932}
2933
Daniel Drake0fb67e92009-07-16 14:46:57 +01002934enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002935 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002936 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2937 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002938 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002939 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002940 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002941 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002942 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002943 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002944 CXT5066_MODELS
2945};
2946
Takashi Iwaiea734962011-01-17 11:29:34 +01002947static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002948 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002949 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2950 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002951 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002952 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002953 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002954 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002955 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002956 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002957};
2958
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002959static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002960 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002961 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002962 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002963 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
Anisse Astier231f50bc2010-04-28 18:05:06 +02002964 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002965 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2966 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002967 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002968 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002969 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002970 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002971 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002972 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002973 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2974 CXT5066_LAPTOP),
2975 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002976 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002977 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002978 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson84012652011-03-31 09:36:19 +02002979 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002980 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002981 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002982 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002983 {}
2984};
2985
2986static int patch_cxt5066(struct hda_codec *codec)
2987{
2988 struct conexant_spec *spec;
2989 int board_config;
2990
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002991 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2992 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002993 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02002994 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002995 if (board_config == CXT5066_AUTO)
2996 return patch_conexant_auto(codec);
2997
Daniel Drake0fb67e92009-07-16 14:46:57 +01002998 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2999 if (!spec)
3000 return -ENOMEM;
3001 codec->spec = spec;
3002
3003 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003004 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003005
3006 spec->dell_automute = 0;
3007 spec->multiout.max_channels = 2;
3008 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3009 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003010 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3011 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003012 spec->num_adc_nids = 1;
3013 spec->adc_nids = cxt5066_adc_nids;
3014 spec->capsrc_nids = cxt5066_capsrc_nids;
3015 spec->input_mux = &cxt5066_capture_source;
3016
3017 spec->port_d_mode = PIN_HP;
3018
3019 spec->num_init_verbs = 1;
3020 spec->init_verbs[0] = cxt5066_init_verbs;
3021 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3022 spec->channel_mode = cxt5066_modes;
3023 spec->cur_adc = 0;
3024 spec->cur_adc_idx = 0;
3025
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003026 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3027
Daniel Drake0fb67e92009-07-16 14:46:57 +01003028 switch (board_config) {
3029 default:
3030 case CXT5066_LAPTOP:
3031 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3032 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3033 break;
3034 case CXT5066_DELL_LAPTOP:
3035 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3036 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3037
3038 spec->port_d_mode = PIN_OUT;
3039 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3040 spec->num_init_verbs++;
3041 spec->dell_automute = 1;
3042 break;
David Henningssona1d69062011-01-21 13:33:28 +01003043 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003044 case CXT5066_HP_LAPTOP:
3045 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003046 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003047 spec->init_verbs[spec->num_init_verbs] =
3048 cxt5066_init_verbs_hp_laptop;
3049 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003050 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3051 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003052 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3053 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3054 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003055 if (board_config == CXT5066_HP_LAPTOP)
3056 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003057 /* input source automatically selected */
3058 spec->input_mux = NULL;
3059 spec->port_d_mode = 0;
3060 spec->mic_boost = 3; /* default 30dB gain */
3061 break;
3062
Daniel Drake0fb67e92009-07-16 14:46:57 +01003063 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003064 codec->patch_ops.init = cxt5066_olpc_init;
3065 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003066 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3067 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003068 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003069 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3070 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003071 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003072
3073 /* no S/PDIF out */
3074 spec->multiout.dig_out_nid = 0;
3075
3076 /* input source automatically selected */
3077 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003078
3079 /* our capture hooks which allow us to turn on the microphone LED
3080 * at the right time */
3081 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3082 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003083 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003084 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003085 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003086 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003087 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3088 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3089 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003090 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003091 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003092 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003093 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003094
3095 /* no S/PDIF out */
3096 spec->multiout.dig_out_nid = 0;
3097
3098 /* input source automatically selected */
3099 spec->input_mux = NULL;
3100 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003101 case CXT5066_IDEAPAD:
3102 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003103 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003104 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3105 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3106 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3107 spec->port_d_mode = 0;
3108 spec->ideapad = 1;
3109 spec->mic_boost = 2; /* default 20dB gain */
3110
3111 /* no S/PDIF out */
3112 spec->multiout.dig_out_nid = 0;
3113
3114 /* input source automatically selected */
3115 spec->input_mux = NULL;
3116 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003117 case CXT5066_THINKPAD:
3118 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003119 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003120 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3121 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3122 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3123 spec->thinkpad = 1;
3124 spec->port_d_mode = PIN_OUT;
3125 spec->mic_boost = 2; /* default 20dB gain */
3126
3127 /* no S/PDIF out */
3128 spec->multiout.dig_out_nid = 0;
3129
3130 /* input source automatically selected */
3131 spec->input_mux = NULL;
3132 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003133 }
3134
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003135 if (spec->beep_amp)
3136 snd_hda_attach_beep_device(codec, spec->beep_amp);
3137
Daniel Drake0fb67e92009-07-16 14:46:57 +01003138 return 0;
3139}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003140
3141/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003142 * Automatic parser for CX20641 & co
3143 */
3144
Takashi Iwai6764bce2011-05-13 16:52:25 +02003145static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3146 struct hda_codec *codec,
3147 unsigned int stream_tag,
3148 unsigned int format,
3149 struct snd_pcm_substream *substream)
3150{
3151 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003152 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003153 if (spec->adc_switching) {
3154 spec->cur_adc = adc;
3155 spec->cur_adc_stream_tag = stream_tag;
3156 spec->cur_adc_format = format;
3157 }
3158 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3159 return 0;
3160}
3161
3162static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3163 struct hda_codec *codec,
3164 struct snd_pcm_substream *substream)
3165{
3166 struct conexant_spec *spec = codec->spec;
3167 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3168 spec->cur_adc = 0;
3169 return 0;
3170}
3171
3172static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3173 .substreams = 1,
3174 .channels_min = 2,
3175 .channels_max = 2,
3176 .nid = 0, /* fill later */
3177 .ops = {
3178 .prepare = cx_auto_capture_pcm_prepare,
3179 .cleanup = cx_auto_capture_pcm_cleanup
3180 },
3181};
3182
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003183static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003184
Takashi Iwai8d087c72011-06-28 12:45:47 +02003185#define get_connection_index(codec, mux, nid)\
3186 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003187
3188/* get an unassigned DAC from the given list.
3189 * Return the nid if found and reduce the DAC list, or return zero if
3190 * not found
3191 */
3192static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3193 hda_nid_t *dacs, int *num_dacs)
3194{
3195 int i, nums = *num_dacs;
3196 hda_nid_t ret = 0;
3197
3198 for (i = 0; i < nums; i++) {
3199 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3200 ret = dacs[i];
3201 break;
3202 }
3203 }
3204 if (!ret)
3205 return 0;
3206 if (--nums > 0)
3207 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3208 *num_dacs = nums;
3209 return ret;
3210}
3211
3212#define MAX_AUTO_DACS 5
3213
Takashi Iwai1f015f52011-08-23 14:57:08 +02003214#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3215
Takashi Iwaif2e57312010-09-15 10:07:08 +02003216/* fill analog DAC list from the widget tree */
3217static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3218{
3219 hda_nid_t nid, end_nid;
3220 int nums = 0;
3221
3222 end_nid = codec->start_nid + codec->num_nodes;
3223 for (nid = codec->start_nid; nid < end_nid; nid++) {
3224 unsigned int wcaps = get_wcaps(codec, nid);
3225 unsigned int type = get_wcaps_type(wcaps);
3226 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3227 dacs[nums++] = nid;
3228 if (nums >= MAX_AUTO_DACS)
3229 break;
3230 }
3231 }
3232 return nums;
3233}
3234
3235/* fill pin_dac_pair list from the pin and dac list */
3236static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3237 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003238 struct pin_dac_pair *filled, int nums,
3239 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003240{
David Henningsson468c5452011-08-25 13:16:02 +02003241 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003242
David Henningsson468c5452011-08-25 13:16:02 +02003243 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003244 filled[nums].pin = pins[i];
3245 filled[nums].type = type;
3246 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003247 if (filled[nums].dac)
3248 continue;
3249 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3250 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3251 continue;
3252 }
3253 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003254 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003255 continue;
3256 }
3257 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003258 }
3259 return nums;
3260}
3261
3262/* parse analog output paths */
3263static void cx_auto_parse_output(struct hda_codec *codec)
3264{
3265 struct conexant_spec *spec = codec->spec;
3266 struct auto_pin_cfg *cfg = &spec->autocfg;
3267 hda_nid_t dacs[MAX_AUTO_DACS];
3268 int i, j, nums, rest;
3269
3270 rest = fill_cx_auto_dacs(codec, dacs);
3271 /* parse all analog output pins */
3272 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003273 dacs, &rest, spec->dac_info, 0,
3274 AUTO_PIN_LINE_OUT);
3275 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3276 dacs, &rest, spec->dac_info, nums,
3277 AUTO_PIN_HP_OUT);
3278 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3279 dacs, &rest, spec->dac_info, nums,
3280 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003281 spec->dac_info_filled = nums;
3282 /* fill multiout struct */
3283 for (i = 0; i < nums; i++) {
3284 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003285 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003286 continue;
3287 switch (spec->dac_info[i].type) {
3288 case AUTO_PIN_LINE_OUT:
3289 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3290 spec->multiout.num_dacs++;
3291 break;
3292 case AUTO_PIN_HP_OUT:
3293 case AUTO_PIN_SPEAKER_OUT:
3294 if (!spec->multiout.hp_nid) {
3295 spec->multiout.hp_nid = dac;
3296 break;
3297 }
3298 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3299 if (!spec->multiout.extra_out_nid[j]) {
3300 spec->multiout.extra_out_nid[j] = dac;
3301 break;
3302 }
3303 break;
3304 }
3305 }
3306 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003307 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003308
Takashi Iwai03697e22011-05-17 09:53:31 +02003309 for (i = 0; i < cfg->hp_outs; i++) {
3310 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3311 spec->auto_mute = 1;
3312 break;
3313 }
3314 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003315 if (spec->auto_mute &&
3316 cfg->line_out_pins[0] &&
3317 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003318 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3319 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3320 for (i = 0; i < cfg->line_outs; i++) {
3321 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3322 spec->detect_line = 1;
3323 break;
3324 }
3325 }
3326 spec->automute_lines = spec->detect_line;
3327 }
3328
Takashi Iwaif2e57312010-09-15 10:07:08 +02003329 spec->vmaster_nid = spec->private_dac_nids[0];
3330}
3331
Takashi Iwaida339862011-05-13 16:24:15 +02003332static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3333 hda_nid_t *pins, bool on);
3334
Takashi Iwai03697e22011-05-17 09:53:31 +02003335static void do_automute(struct hda_codec *codec, int num_pins,
3336 hda_nid_t *pins, bool on)
3337{
Takashi Iwai254f2962011-10-14 15:22:34 +02003338 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003339 int i;
3340 for (i = 0; i < num_pins; i++)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003341 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003342 if (spec->pin_eapd_ctrls)
3343 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003344}
3345
3346static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3347{
3348 int i, present = 0;
3349
3350 for (i = 0; i < num_pins; i++) {
3351 hda_nid_t nid = pins[i];
3352 if (!nid || !is_jack_detectable(codec, nid))
3353 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003354 present |= snd_hda_jack_detect(codec, nid);
3355 }
3356 return present;
3357}
3358
Takashi Iwaif2e57312010-09-15 10:07:08 +02003359/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003360static void cx_auto_update_speakers(struct hda_codec *codec)
3361{
3362 struct conexant_spec *spec = codec->spec;
3363 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003364 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003365
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003366 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003367 if (spec->pin_eapd_ctrls) {
3368 if (spec->auto_mute)
3369 on = spec->hp_present;
3370 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3371 }
3372
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003373 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3374 if (spec->auto_mute)
3375 on = !(spec->hp_present ||
3376 (spec->detect_line && spec->line_present));
3377 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003378
3379 /* toggle line-out mutes if needed, too */
3380 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3381 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3382 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3383 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003384 if (spec->auto_mute) {
3385 /* mute LO in auto-mode when HP jack is present */
3386 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3387 spec->automute_lines)
3388 on = !spec->hp_present;
3389 else
3390 on = 1;
3391 }
3392 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003393}
3394
David Henningsson29adc4b2012-09-25 11:31:00 +02003395static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003396{
3397 struct conexant_spec *spec = codec->spec;
3398 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003399
3400 if (!spec->auto_mute)
3401 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003402 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3403 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003404}
3405
David Henningsson29adc4b2012-09-25 11:31:00 +02003406static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwai03697e22011-05-17 09:53:31 +02003407{
3408 struct conexant_spec *spec = codec->spec;
3409 struct auto_pin_cfg *cfg = &spec->autocfg;
3410
3411 if (!spec->auto_mute || !spec->detect_line)
3412 return;
3413 spec->line_present = detect_jacks(codec, cfg->line_outs,
3414 cfg->line_out_pins);
3415 cx_auto_update_speakers(codec);
3416}
3417
3418static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3419 struct snd_ctl_elem_info *uinfo)
3420{
3421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3422 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003423 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003424 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003425 };
Takashi Iwai03697e22011-05-17 09:53:31 +02003426
Takashi Iwaidda415d2012-11-30 18:34:38 +01003427 if (spec->automute_hp_lo)
3428 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3429 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai03697e22011-05-17 09:53:31 +02003430}
3431
3432static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3433 struct snd_ctl_elem_value *ucontrol)
3434{
3435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3436 struct conexant_spec *spec = codec->spec;
3437 unsigned int val;
3438 if (!spec->auto_mute)
3439 val = 0;
3440 else if (!spec->automute_lines)
3441 val = 1;
3442 else
3443 val = 2;
3444 ucontrol->value.enumerated.item[0] = val;
3445 return 0;
3446}
3447
3448static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3449 struct snd_ctl_elem_value *ucontrol)
3450{
3451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3452 struct conexant_spec *spec = codec->spec;
3453
3454 switch (ucontrol->value.enumerated.item[0]) {
3455 case 0:
3456 if (!spec->auto_mute)
3457 return 0;
3458 spec->auto_mute = 0;
3459 break;
3460 case 1:
3461 if (spec->auto_mute && !spec->automute_lines)
3462 return 0;
3463 spec->auto_mute = 1;
3464 spec->automute_lines = 0;
3465 break;
3466 case 2:
3467 if (!spec->automute_hp_lo)
3468 return -EINVAL;
3469 if (spec->auto_mute && spec->automute_lines)
3470 return 0;
3471 spec->auto_mute = 1;
3472 spec->automute_lines = 1;
3473 break;
3474 default:
3475 return -EINVAL;
3476 }
3477 cx_auto_update_speakers(codec);
3478 return 1;
3479}
3480
3481static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3482 {
3483 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3484 .name = "Auto-Mute Mode",
3485 .info = cx_automute_mode_info,
3486 .get = cx_automute_mode_get,
3487 .put = cx_automute_mode_put,
3488 },
3489 { }
3490};
3491
Takashi Iwai6764bce2011-05-13 16:52:25 +02003492static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3493 struct snd_ctl_elem_info *uinfo)
3494{
3495 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3496 struct conexant_spec *spec = codec->spec;
3497
3498 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3499}
3500
3501static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3502 struct snd_ctl_elem_value *ucontrol)
3503{
3504 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3505 struct conexant_spec *spec = codec->spec;
3506
3507 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3508 return 0;
3509}
3510
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003511/* look for the route the given pin from mux and return the index;
3512 * if do_select is set, actually select the route.
3513 */
3514static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003515 hda_nid_t pin, hda_nid_t *srcp,
3516 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003517{
David Henningsson739572a2012-09-20 15:41:21 +02003518 struct conexant_spec *spec = codec->spec;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003519 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
David Henningsson739572a2012-09-20 15:41:21 +02003520 int startidx, i, nums;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003521
Takashi Iwaicf27f292011-05-16 11:33:02 +02003522 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3523 case AC_WID_AUD_IN:
3524 case AC_WID_AUD_SEL:
3525 case AC_WID_AUD_MIX:
3526 break;
3527 default:
3528 return -1;
3529 }
3530
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003531 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3532 for (i = 0; i < nums; i++)
3533 if (conn[i] == pin) {
3534 if (do_select)
3535 snd_hda_codec_write(codec, mux, 0,
3536 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003537 if (srcp)
3538 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003539 return i;
3540 }
3541 depth++;
3542 if (depth == 2)
3543 return -1;
David Henningsson739572a2012-09-20 15:41:21 +02003544
3545 /* Try to rotate around connections to avoid one boost controlling
3546 another input path as well */
3547 startidx = 0;
3548 for (i = 0; i < spec->private_imux.num_items; i++)
3549 if (spec->imux_info[i].pin == pin) {
3550 startidx = i;
3551 break;
3552 }
3553
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003554 for (i = 0; i < nums; i++) {
David Henningsson739572a2012-09-20 15:41:21 +02003555 int j = (i + startidx) % nums;
3556 int ret = __select_input_connection(codec, conn[j], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003557 do_select, depth);
3558 if (ret >= 0) {
3559 if (do_select)
3560 snd_hda_codec_write(codec, mux, 0,
David Henningsson739572a2012-09-20 15:41:21 +02003561 AC_VERB_SET_CONNECT_SEL, j);
3562 return j;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003563 }
3564 }
3565 return -1;
3566}
3567
3568static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3569 hda_nid_t pin)
3570{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003571 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003572}
3573
3574static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3575 hda_nid_t pin)
3576{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003577 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003578}
3579
Takashi Iwai6764bce2011-05-13 16:52:25 +02003580static int cx_auto_mux_enum_update(struct hda_codec *codec,
3581 const struct hda_input_mux *imux,
3582 unsigned int idx)
3583{
3584 struct conexant_spec *spec = codec->spec;
3585 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003586 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003587
3588 if (!imux->num_items)
3589 return 0;
3590 if (idx >= imux->num_items)
3591 idx = imux->num_items - 1;
3592 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003593 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003594 adc = spec->imux_info[idx].adc;
3595 select_input_connection(codec, spec->imux_info[idx].adc,
3596 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003597 if (spec->cur_adc && spec->cur_adc != adc) {
3598 /* stream is running, let's swap the current ADC */
3599 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3600 spec->cur_adc = adc;
3601 snd_hda_codec_setup_stream(codec, adc,
3602 spec->cur_adc_stream_tag, 0,
3603 spec->cur_adc_format);
3604 }
3605 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003606 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003607}
3608
3609static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3610 struct snd_ctl_elem_value *ucontrol)
3611{
3612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3613 struct conexant_spec *spec = codec->spec;
3614
3615 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3616 ucontrol->value.enumerated.item[0]);
3617}
3618
3619static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3620 {
3621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3622 .name = "Capture Source",
3623 .info = cx_auto_mux_enum_info,
3624 .get = cx_auto_mux_enum_get,
3625 .put = cx_auto_mux_enum_put
3626 },
3627 {}
3628};
3629
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003630static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3631{
3632 struct conexant_spec *spec = codec->spec;
3633 if (idx < 0)
3634 return false;
3635 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3636 return false;
3637 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3638 return true;
3639}
3640
Takashi Iwaif2e57312010-09-15 10:07:08 +02003641/* automatic switch internal and external mic */
David Henningsson29adc4b2012-09-25 11:31:00 +02003642static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003643{
3644 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003645
3646 if (!spec->auto_mic)
3647 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003648 if (!select_automic(codec, spec->auto_mic_ext, true))
3649 if (!select_automic(codec, spec->auto_mic_dock, true))
3650 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003651}
3652
Takashi Iwaif2e57312010-09-15 10:07:08 +02003653/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003654 * auto-mic is enabled only when one int-mic and one ext- and/or
3655 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003656 */
3657static void cx_auto_check_auto_mic(struct hda_codec *codec)
3658{
3659 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003660 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3661 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003662
Takashi Iwai506a4192011-05-23 20:07:15 +02003663 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003664 pset[i] = -1;
3665 for (i = 0; i < spec->private_imux.num_items; i++) {
3666 hda_nid_t pin = spec->imux_info[i].pin;
3667 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003668 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003669 attr = snd_hda_get_input_pin_attr(def_conf);
3670 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003671 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003672 if (attr > INPUT_PIN_ATTR_NORMAL)
3673 attr = INPUT_PIN_ATTR_NORMAL;
3674 if (attr != INPUT_PIN_ATTR_INT &&
3675 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003676 return; /* non-detectable pin */
3677 type = get_defcfg_device(def_conf);
3678 if (type != AC_JACK_MIC_IN &&
3679 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3680 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003681 if (pset[attr] >= 0)
3682 return; /* already occupied */
3683 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003684 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003685 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3686 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3687 return; /* no input to switch*/
3688 spec->auto_mic = 1;
3689 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3690 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3691 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003692}
3693
3694static void cx_auto_parse_input(struct hda_codec *codec)
3695{
3696 struct conexant_spec *spec = codec->spec;
3697 struct auto_pin_cfg *cfg = &spec->autocfg;
3698 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003699 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003700
3701 imux = &spec->private_imux;
3702 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003703 for (j = 0; j < spec->num_adc_nids; j++) {
3704 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003705 int idx = get_input_connection(codec, adc,
3706 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003707 if (idx >= 0) {
3708 const char *label;
3709 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003710 spec->imux_info[imux->num_items].index = i;
3711 spec->imux_info[imux->num_items].boost = 0;
3712 spec->imux_info[imux->num_items].adc = adc;
3713 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003714 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003715 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003716 break;
3717 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003718 }
3719 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003720 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003721 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003722 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003723 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003724 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003725 spec->adc_switching = 1;
3726 break;
3727 }
3728 }
3729 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003730}
3731
3732/* get digital-input audio widget corresponding to the given pin */
3733static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3734{
3735 hda_nid_t nid, end_nid;
3736
3737 end_nid = codec->start_nid + codec->num_nodes;
3738 for (nid = codec->start_nid; nid < end_nid; nid++) {
3739 unsigned int wcaps = get_wcaps(codec, nid);
3740 unsigned int type = get_wcaps_type(wcaps);
3741 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3742 if (get_connection_index(codec, nid, pin) >= 0)
3743 return nid;
3744 }
3745 }
3746 return 0;
3747}
3748
3749static void cx_auto_parse_digital(struct hda_codec *codec)
3750{
3751 struct conexant_spec *spec = codec->spec;
3752 struct auto_pin_cfg *cfg = &spec->autocfg;
3753 hda_nid_t nid;
3754
3755 if (cfg->dig_outs &&
3756 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3757 spec->multiout.dig_out_nid = nid;
3758 if (cfg->dig_in_pin)
3759 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3760}
3761
3762#ifdef CONFIG_SND_HDA_INPUT_BEEP
3763static void cx_auto_parse_beep(struct hda_codec *codec)
3764{
3765 struct conexant_spec *spec = codec->spec;
3766 hda_nid_t nid, end_nid;
3767
3768 end_nid = codec->start_nid + codec->num_nodes;
3769 for (nid = codec->start_nid; nid < end_nid; nid++)
3770 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3771 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3772 break;
3773 }
3774}
3775#else
3776#define cx_auto_parse_beep(codec)
3777#endif
3778
Takashi Iwai254f2962011-10-14 15:22:34 +02003779/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003780static void cx_auto_parse_eapd(struct hda_codec *codec)
3781{
3782 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003783 hda_nid_t nid, end_nid;
3784
3785 end_nid = codec->start_nid + codec->num_nodes;
3786 for (nid = codec->start_nid; nid < end_nid; nid++) {
3787 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3788 continue;
3789 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3790 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003791 spec->eapds[spec->num_eapds++] = nid;
3792 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3793 break;
3794 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003795
3796 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3797 * it's a new chip, where EAPDs are supposed to be associated to
3798 * pins, and we can control EAPD per pin.
3799 * OTOH, if only one or two EAPDs are found, it's an old chip,
3800 * thus it might control over all pins.
3801 */
3802 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003803}
3804
Takashi Iwaif2e57312010-09-15 10:07:08 +02003805static int cx_auto_parse_auto_config(struct hda_codec *codec)
3806{
3807 struct conexant_spec *spec = codec->spec;
3808 int err;
3809
3810 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3811 if (err < 0)
3812 return err;
3813
3814 cx_auto_parse_output(codec);
3815 cx_auto_parse_input(codec);
3816 cx_auto_parse_digital(codec);
3817 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003818 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003819 return 0;
3820}
3821
Takashi Iwaida339862011-05-13 16:24:15 +02003822static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3823 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003824{
3825 int i;
3826 for (i = 0; i < num_pins; i++) {
3827 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3828 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003829 AC_VERB_SET_EAPD_BTLENABLE,
3830 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003831 }
3832}
3833
3834static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3835 hda_nid_t src)
3836{
3837 int idx = get_connection_index(codec, pin, src);
3838 if (idx >= 0)
3839 snd_hda_codec_write(codec, pin, 0,
3840 AC_VERB_SET_CONNECT_SEL, idx);
3841}
3842
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003843static void mute_outputs(struct hda_codec *codec, int num_nids,
3844 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003845{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003846 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003847
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003848 for (i = 0; i < num_nids; i++) {
3849 hda_nid_t nid = nids[i];
3850 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3851 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003852 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3853 val = AMP_OUT_MUTE;
3854 else
3855 val = AMP_OUT_ZERO;
3856 snd_hda_codec_write(codec, nid, 0,
3857 AC_VERB_SET_AMP_GAIN_MUTE, val);
3858 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003859}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003860
Takashi Iwai03697e22011-05-17 09:53:31 +02003861static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003862 hda_nid_t *pins, unsigned int action,
3863 hda_jack_callback cb)
Takashi Iwai03697e22011-05-17 09:53:31 +02003864{
3865 int i;
3866 for (i = 0; i < num_pins; i++)
David Henningsson29adc4b2012-09-25 11:31:00 +02003867 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb);
Takashi Iwai03697e22011-05-17 09:53:31 +02003868}
3869
Takashi Iwai07cafff2012-02-20 12:30:59 +01003870static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3871{
3872 int i;
3873 for (i = 0; i < nums; i++)
3874 if (list[i] == nid)
3875 return true;
3876 return false;
3877}
3878
3879/* is the given NID found in any of autocfg items? */
3880static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3881{
3882 int i;
3883
3884 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3885 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3886 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3887 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3888 return true;
3889 for (i = 0; i < cfg->num_inputs; i++)
3890 if (cfg->inputs[i].pin == nid)
3891 return true;
3892 if (cfg->dig_in_pin == nid)
3893 return true;
3894 return false;
3895}
3896
3897/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3898 * invalid unsol tags by some reason
3899 */
3900static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3901{
3902 struct conexant_spec *spec = codec->spec;
3903 struct auto_pin_cfg *cfg = &spec->autocfg;
3904 int i;
3905
3906 for (i = 0; i < codec->init_pins.used; i++) {
3907 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3908 if (!found_in_autocfg(cfg, pin->nid))
3909 snd_hda_codec_write(codec, pin->nid, 0,
3910 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3911 }
3912}
3913
Takashi Iwai527c73b2012-03-12 12:38:51 +01003914/* turn on/off EAPD according to Master switch */
3915static void cx_auto_vmaster_hook(void *private_data, int enabled)
3916{
3917 struct hda_codec *codec = private_data;
3918 struct conexant_spec *spec = codec->spec;
3919
3920 if (enabled && spec->pin_eapd_ctrls) {
3921 cx_auto_update_speakers(codec);
3922 return;
3923 }
3924 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3925}
3926
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003927static void cx_auto_init_output(struct hda_codec *codec)
3928{
3929 struct conexant_spec *spec = codec->spec;
3930 struct auto_pin_cfg *cfg = &spec->autocfg;
3931 hda_nid_t nid;
3932 int i;
3933
3934 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003935 for (i = 0; i < cfg->hp_outs; i++) {
3936 unsigned int val = PIN_OUT;
3937 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3938 AC_PINCAP_HP_DRV)
3939 val |= AC_PINCTL_HP_EN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003940 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003941 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003942 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3943 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3944 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003945 for (i = 0; i < spec->dac_info_filled; i++) {
3946 nid = spec->dac_info[i].dac;
3947 if (!nid)
3948 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003949 else if (nid & DAC_SLAVE_FLAG)
3950 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003951 select_connection(codec, spec->dac_info[i].pin, nid);
3952 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003953 if (spec->auto_mute) {
3954 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003955 CONEXANT_HP_EVENT, cx_auto_hp_automute);
Takashi Iwai03697e22011-05-17 09:53:31 +02003956 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3957 cfg->hp_pins);
3958 if (spec->detect_line) {
3959 enable_unsol_pins(codec, cfg->line_outs,
3960 cfg->line_out_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003961 CONEXANT_LINE_EVENT,
3962 cx_auto_line_automute);
Takashi Iwai03697e22011-05-17 09:53:31 +02003963 spec->line_present =
3964 detect_jacks(codec, cfg->line_outs,
3965 cfg->line_out_pins);
3966 }
3967 }
3968 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02003969 /* turn on all EAPDs if no individual EAPD control is available */
3970 if (!spec->pin_eapd_ctrls)
3971 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01003972 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003973}
3974
3975static void cx_auto_init_input(struct hda_codec *codec)
3976{
3977 struct conexant_spec *spec = codec->spec;
3978 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003979 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003980
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003981 for (i = 0; i < spec->num_adc_nids; i++) {
3982 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003983 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3984 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003985 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3986 val = AMP_IN_MUTE(0);
3987 else
3988 val = AMP_IN_UNMUTE(0);
3989 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3990 val);
3991 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003992
3993 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai47408602012-04-20 13:06:53 +02003994 hda_nid_t pin = cfg->inputs[i].pin;
3995 unsigned int type = PIN_IN;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003996 if (cfg->inputs[i].type == AUTO_PIN_MIC)
Takashi Iwai47408602012-04-20 13:06:53 +02003997 type |= snd_hda_get_default_vref(codec, pin);
3998 snd_hda_set_pin_ctl(codec, pin, type);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003999 }
4000
4001 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004002 if (spec->auto_mic_ext >= 0) {
David Henningsson29adc4b2012-09-25 11:31:00 +02004003 snd_hda_jack_detect_enable_callback(codec,
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004004 cfg->inputs[spec->auto_mic_ext].pin,
David Henningsson29adc4b2012-09-25 11:31:00 +02004005 CONEXANT_MIC_EVENT, cx_auto_automic);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004006 }
4007 if (spec->auto_mic_dock >= 0) {
David Henningsson29adc4b2012-09-25 11:31:00 +02004008 snd_hda_jack_detect_enable_callback(codec,
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004009 cfg->inputs[spec->auto_mic_dock].pin,
David Henningsson29adc4b2012-09-25 11:31:00 +02004010 CONEXANT_MIC_EVENT, cx_auto_automic);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004011 }
David Henningsson29adc4b2012-09-25 11:31:00 +02004012 cx_auto_automic(codec, NULL);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004013 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004014 select_input_connection(codec, spec->imux_info[0].adc,
4015 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004016 }
4017}
4018
4019static void cx_auto_init_digital(struct hda_codec *codec)
4020{
4021 struct conexant_spec *spec = codec->spec;
4022 struct auto_pin_cfg *cfg = &spec->autocfg;
4023
4024 if (spec->multiout.dig_out_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004025 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004026 if (spec->dig_in_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004027 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004028}
4029
4030static int cx_auto_init(struct hda_codec *codec)
4031{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004032 struct conexant_spec *spec = codec->spec;
Takashi Iwaic9ce6b22012-12-18 18:12:44 +01004033 snd_hda_apply_verbs(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004034 cx_auto_init_output(codec);
4035 cx_auto_init_input(codec);
4036 cx_auto_init_digital(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004037 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004038 return 0;
4039}
4040
David Henningsson983345e2011-02-15 19:57:09 +01004041static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004042 const char *dir, int cidx,
David Henningsson18dcd302012-04-02 15:40:27 +02004043 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004044{
David Henningsson18dcd302012-04-02 15:40:27 +02004045 static char name[44];
Takashi Iwaif2e57312010-09-15 10:07:08 +02004046 static struct snd_kcontrol_new knew[] = {
4047 HDA_CODEC_VOLUME(name, 0, 0, 0),
4048 HDA_CODEC_MUTE(name, 0, 0, 0),
4049 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004050 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004051 int i, err;
4052
4053 for (i = 0; i < 2; i++) {
4054 struct snd_kcontrol *kctl;
David Henningsson18dcd302012-04-02 15:40:27 +02004055 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
David Henningsson983345e2011-02-15 19:57:09 +01004056 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004057 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4058 knew[i].index = cidx;
4059 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4060 kctl = snd_ctl_new1(&knew[i], codec);
4061 if (!kctl)
4062 return -ENOMEM;
4063 err = snd_hda_ctl_add(codec, nid, kctl);
4064 if (err < 0)
4065 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004066 if (!(query_amp_caps(codec, nid, hda_dir) &
4067 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004068 break;
4069 }
4070 return 0;
4071}
4072
David Henningsson983345e2011-02-15 19:57:09 +01004073#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
David Henningsson18dcd302012-04-02 15:40:27 +02004074 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
David Henningsson983345e2011-02-15 19:57:09 +01004075
Takashi Iwaif2e57312010-09-15 10:07:08 +02004076#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4077 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4078
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004079static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4080 hda_nid_t pin, const char *name, int idx)
4081{
4082 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004083 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4084 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4085 if (caps & AC_AMPCAP_NUM_STEPS)
4086 return cx_auto_add_pb_volume(codec, dac, name, idx);
4087 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004088 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4089 if (caps & AC_AMPCAP_NUM_STEPS)
4090 return cx_auto_add_pb_volume(codec, pin, name, idx);
4091 return 0;
4092}
4093
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004094static bool is_2_1_speaker(struct conexant_spec *spec)
4095{
4096 int i, type, num_spk = 0;
4097
4098 for (i = 0; i < spec->dac_info_filled; i++) {
4099 type = spec->dac_info[i].type;
4100 if (type == AUTO_PIN_LINE_OUT)
4101 type = spec->autocfg.line_out_type;
4102 if (type == AUTO_PIN_SPEAKER_OUT)
4103 num_spk++;
4104 }
4105 return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT);
4106}
4107
Takashi Iwaif2e57312010-09-15 10:07:08 +02004108static int cx_auto_build_output_controls(struct hda_codec *codec)
4109{
4110 struct conexant_spec *spec = codec->spec;
4111 int i, err;
4112 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004113 bool speaker_2_1;
Takashi Iwaiea734962011-01-17 11:29:34 +01004114 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004115
4116 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004117 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4118 spec->dac_info[0].pin,
4119 "Master", 0);
4120
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004121 speaker_2_1 = is_2_1_speaker(spec);
4122
Takashi Iwaif2e57312010-09-15 10:07:08 +02004123 for (i = 0; i < spec->dac_info_filled; i++) {
4124 const char *label;
4125 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004126 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004127 type = spec->dac_info[i].type;
4128 if (type == AUTO_PIN_LINE_OUT)
4129 type = spec->autocfg.line_out_type;
4130 switch (type) {
4131 case AUTO_PIN_LINE_OUT:
4132 default:
4133 label = texts[num_line++];
4134 idx = 0;
4135 break;
4136 case AUTO_PIN_HP_OUT:
4137 label = "Headphone";
4138 idx = num_hp++;
4139 break;
4140 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004141 if (speaker_2_1) {
4142 label = num_spk++ ? "Bass Speaker" : "Speaker";
4143 idx = 0;
4144 } else {
4145 label = "Speaker";
4146 idx = num_spk++;
4147 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004148 break;
4149 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004150 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004151 spec->dac_info[i].pin,
4152 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004153 if (err < 0)
4154 return err;
4155 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004156
4157 if (spec->auto_mute) {
4158 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4159 if (err < 0)
4160 return err;
4161 }
4162
Takashi Iwaif2e57312010-09-15 10:07:08 +02004163 return 0;
4164}
4165
David Henningsson18dcd302012-04-02 15:40:27 +02004166/* Returns zero if this is a normal stereo channel, and non-zero if it should
4167 be split in two independent channels.
4168 dest_label must be at least 44 characters. */
4169static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4170 char *dest_label, int nid)
4171{
4172 struct conexant_spec *spec = codec->spec;
4173 int i;
4174
4175 if (!spec->fixup_stereo_dmic)
4176 return 0;
4177
4178 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4179 int def_conf;
4180 if (spec->autocfg.inputs[i].pin != nid)
4181 continue;
4182
4183 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4184 return 0;
4185 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4186 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4187 return 0;
4188
4189 /* Finally found the inverted internal mic! */
4190 snprintf(dest_label, 44, "Inverted %s", label);
4191 return 1;
4192 }
4193 return 0;
4194}
4195
Takashi Iwai6764bce2011-05-13 16:52:25 +02004196static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4197 const char *label, const char *pfx,
4198 int cidx)
4199{
4200 struct conexant_spec *spec = codec->spec;
4201 int i;
4202
4203 for (i = 0; i < spec->num_adc_nids; i++) {
David Henningsson18dcd302012-04-02 15:40:27 +02004204 char rightch_label[44];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004205 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004206 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004207 if (idx < 0)
4208 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004209 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004210 idx = 0;
David Henningsson18dcd302012-04-02 15:40:27 +02004211
4212 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4213 /* Make two independent kcontrols for left and right */
4214 int err = cx_auto_add_volume_idx(codec, label, pfx,
4215 cidx, adc_nid, HDA_INPUT, idx, 1);
4216 if (err < 0)
4217 return err;
4218 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4219 cidx, adc_nid, HDA_INPUT, idx, 2);
4220 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004221 return cx_auto_add_volume_idx(codec, label, pfx,
David Henningsson18dcd302012-04-02 15:40:27 +02004222 cidx, adc_nid, HDA_INPUT, idx, 3);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004223 }
4224 return 0;
4225}
4226
Takashi Iwaicf27f292011-05-16 11:33:02 +02004227static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4228 const char *label, int cidx)
4229{
4230 struct conexant_spec *spec = codec->spec;
4231 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004232 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004233
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004234 nid = spec->imux_info[idx].pin;
David Henningsson18dcd302012-04-02 15:40:27 +02004235 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4236 char rightch_label[44];
4237 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4238 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4239 cidx, nid, HDA_INPUT, 0, 1);
4240 if (err < 0)
4241 return err;
4242 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4243 cidx, nid, HDA_INPUT, 0, 2);
4244 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004245 return cx_auto_add_volume(codec, label, " Boost", cidx,
4246 nid, HDA_INPUT);
David Henningsson18dcd302012-04-02 15:40:27 +02004247 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004248 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4249 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004250 if (con < 0)
4251 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004252 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004253 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004254 return 0; /* already present */
4255 }
4256
4257 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004258 spec->imux_info[idx].boost = mux;
David Henningsson74d3e692012-10-02 10:14:23 +02004259 return cx_auto_add_volume(codec, label, " Boost", cidx,
Takashi Iwaicf27f292011-05-16 11:33:02 +02004260 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004261 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004262 return 0;
4263}
4264
Takashi Iwaif2e57312010-09-15 10:07:08 +02004265static int cx_auto_build_input_controls(struct hda_codec *codec)
4266{
4267 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004268 struct hda_input_mux *imux = &spec->private_imux;
4269 const char *prev_label;
4270 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004271 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004272 int multi_connection;
4273
Takashi Iwai6b452142011-10-14 15:26:20 +02004274 if (!imux->num_items)
4275 return 0;
4276
Takashi Iwaicf27f292011-05-16 11:33:02 +02004277 multi_connection = 0;
4278 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004279 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4280 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004281 if (cidx < 0)
4282 continue;
4283 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004284 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004285 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004286 if (i > 0 && input_conn[i] != input_conn[0])
4287 multi_connection = 1;
4288 }
David Henningsson983345e2011-02-15 19:57:09 +01004289
Takashi Iwaif2e57312010-09-15 10:07:08 +02004290 prev_label = NULL;
4291 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004292 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004293 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004294 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004295
Takashi Iwaicf27f292011-05-16 11:33:02 +02004296 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004297 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004298 if (label == prev_label)
4299 cidx++;
4300 else
4301 cidx = 0;
4302 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004303
Takashi Iwaicf27f292011-05-16 11:33:02 +02004304 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4305 if (err < 0)
4306 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004307
Takashi Iwaicf27f292011-05-16 11:33:02 +02004308 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004309 if (i > 0)
4310 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004311 err = cx_auto_add_capture_volume(codec, nid,
4312 "Capture", "", cidx);
4313 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004314 bool dup_found = false;
4315 for (j = 0; j < i; j++) {
4316 if (input_conn[j] == input_conn[i]) {
4317 dup_found = true;
4318 break;
4319 }
4320 }
4321 if (dup_found)
4322 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004323 err = cx_auto_add_capture_volume(codec, nid,
4324 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004325 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004326 if (err < 0)
4327 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004328 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004329
4330 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4331 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4332 if (err < 0)
4333 return err;
4334 }
4335
Takashi Iwaif2e57312010-09-15 10:07:08 +02004336 return 0;
4337}
4338
4339static int cx_auto_build_controls(struct hda_codec *codec)
4340{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004341 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004342 int err;
4343
4344 err = cx_auto_build_output_controls(codec);
4345 if (err < 0)
4346 return err;
4347 err = cx_auto_build_input_controls(codec);
4348 if (err < 0)
4349 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004350 err = conexant_build_controls(codec);
4351 if (err < 0)
4352 return err;
4353 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4354 if (err < 0)
4355 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004356 if (spec->vmaster_mute.sw_kctl) {
4357 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4358 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4359 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004360 if (err < 0)
4361 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004362 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004363 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004364}
4365
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004366static int cx_auto_search_adcs(struct hda_codec *codec)
4367{
4368 struct conexant_spec *spec = codec->spec;
4369 hda_nid_t nid, end_nid;
4370
4371 end_nid = codec->start_nid + codec->num_nodes;
4372 for (nid = codec->start_nid; nid < end_nid; nid++) {
4373 unsigned int caps = get_wcaps(codec, nid);
4374 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4375 continue;
4376 if (caps & AC_WCAP_DIGITAL)
4377 continue;
4378 if (snd_BUG_ON(spec->num_adc_nids >=
4379 ARRAY_SIZE(spec->private_adc_nids)))
4380 break;
4381 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4382 }
4383 spec->adc_nids = spec->private_adc_nids;
4384 return 0;
4385}
4386
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004387static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004388 .build_controls = cx_auto_build_controls,
4389 .build_pcms = conexant_build_pcms,
4390 .init = cx_auto_init,
4391 .free = conexant_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02004392 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004393};
4394
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004395/*
4396 * pin fix-up
4397 */
David Henningsson18dcd302012-04-02 15:40:27 +02004398enum {
4399 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02004400 CXT_PINCFG_LENOVO_TP410,
Huacai Chen239fb862012-10-05 21:25:09 +08004401 CXT_PINCFG_LEMOTE_A1004,
4402 CXT_PINCFG_LEMOTE_A1205,
David Henningsson18dcd302012-04-02 15:40:27 +02004403 CXT_FIXUP_STEREO_DMIC,
Huacai Chen239fb862012-10-05 21:25:09 +08004404 CXT_FIXUP_INC_MIC_BOOST,
David Henningsson18dcd302012-04-02 15:40:27 +02004405};
4406
Takashi Iwai23d30f22012-05-07 17:17:32 +02004407static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4408 const struct hda_fixup *fix, int action)
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004409{
David Henningsson18dcd302012-04-02 15:40:27 +02004410 struct conexant_spec *spec = codec->spec;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004411 spec->fixup_stereo_dmic = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004412}
4413
Huacai Chen239fb862012-10-05 21:25:09 +08004414static void cxt5066_increase_mic_boost(struct hda_codec *codec,
4415 const struct hda_fixup *fix, int action)
4416{
4417 if (action != HDA_FIXUP_ACT_PRE_PROBE)
4418 return;
4419
4420 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
4421 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
4422 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4423 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4424 (0 << AC_AMPCAP_MUTE_SHIFT));
4425}
4426
Takashi Iwaid70f36322012-04-19 15:18:08 +02004427/* ThinkPad X200 & co with cxt5051 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02004428static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004429 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4430 { 0x17, 0x21a11000 }, /* dock-mic */
4431 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004432 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004433 {}
4434};
4435
Takashi Iwaid70f36322012-04-19 15:18:08 +02004436/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02004437static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
Takashi Iwaid70f36322012-04-19 15:18:08 +02004438 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4439 { 0x1a, 0x21a190f0 }, /* dock-mic */
4440 { 0x1c, 0x212140ff }, /* dock-HP */
4441 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004442};
4443
Huacai Chen239fb862012-10-05 21:25:09 +08004444/* Lemote A1004/A1205 with cxt5066 */
4445static const struct hda_pintbl cxt_pincfg_lemote[] = {
4446 { 0x1a, 0x90a10020 }, /* Internal mic */
4447 { 0x1b, 0x03a11020 }, /* External mic */
4448 { 0x1d, 0x400101f0 }, /* Not used */
4449 { 0x1e, 0x40a701f0 }, /* Not used */
4450 { 0x20, 0x404501f0 }, /* Not used */
4451 { 0x22, 0x404401f0 }, /* Not used */
4452 { 0x23, 0x40a701f0 }, /* Not used */
4453 {}
4454};
4455
Takashi Iwai23d30f22012-05-07 17:17:32 +02004456static const struct hda_fixup cxt_fixups[] = {
4457 [CXT_PINCFG_LENOVO_X200] = {
4458 .type = HDA_FIXUP_PINS,
4459 .v.pins = cxt_pincfg_lenovo_x200,
4460 },
4461 [CXT_PINCFG_LENOVO_TP410] = {
4462 .type = HDA_FIXUP_PINS,
4463 .v.pins = cxt_pincfg_lenovo_tp410,
4464 },
Huacai Chen239fb862012-10-05 21:25:09 +08004465 [CXT_PINCFG_LEMOTE_A1004] = {
4466 .type = HDA_FIXUP_PINS,
4467 .chained = true,
4468 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
4469 .v.pins = cxt_pincfg_lemote,
4470 },
4471 [CXT_PINCFG_LEMOTE_A1205] = {
4472 .type = HDA_FIXUP_PINS,
4473 .v.pins = cxt_pincfg_lemote,
4474 },
Takashi Iwai23d30f22012-05-07 17:17:32 +02004475 [CXT_FIXUP_STEREO_DMIC] = {
4476 .type = HDA_FIXUP_FUNC,
4477 .v.func = cxt_fixup_stereo_dmic,
4478 },
Huacai Chen239fb862012-10-05 21:25:09 +08004479 [CXT_FIXUP_INC_MIC_BOOST] = {
4480 .type = HDA_FIXUP_FUNC,
4481 .v.func = cxt5066_increase_mic_boost,
4482 },
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004483};
4484
Takashi Iwaid70f36322012-04-19 15:18:08 +02004485static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004486 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4487 {}
4488};
4489
Takashi Iwaid70f36322012-04-19 15:18:08 +02004490static const struct snd_pci_quirk cxt5066_fixups[] = {
Takashi Iwai63a077e2012-12-12 12:10:01 +01004491 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaid70f36322012-04-19 15:18:08 +02004492 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4493 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4494 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4495 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4496 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02004497 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Felix Kaechelee4db0952012-09-26 01:20:44 +02004498 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
David Henningssonb3c5dce2012-06-21 16:03:01 +02004499 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
Huacai Chen239fb862012-10-05 21:25:09 +08004500 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
4501 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
Takashi Iwaif2e57312010-09-15 10:07:08 +02004502 {}
4503};
4504
Takashi Iwai38681372012-02-27 15:00:58 +01004505/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4506 * can be created (bko#42825)
4507 */
4508static void add_cx5051_fake_mutes(struct hda_codec *codec)
4509{
4510 static hda_nid_t out_nids[] = {
4511 0x10, 0x11, 0
4512 };
4513 hda_nid_t *p;
4514
4515 for (p = out_nids; *p; p++)
4516 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4517 AC_AMPCAP_MIN_MUTE |
4518 query_amp_caps(codec, *p, HDA_OUTPUT));
4519}
4520
Takashi Iwaif2e57312010-09-15 10:07:08 +02004521static int patch_conexant_auto(struct hda_codec *codec)
4522{
4523 struct conexant_spec *spec;
4524 int err;
4525
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004526 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4527 codec->chip_name);
4528
Takashi Iwaif2e57312010-09-15 10:07:08 +02004529 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4530 if (!spec)
4531 return -ENOMEM;
4532 codec->spec = spec;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004533
Takashi Iwai6b452142011-10-14 15:26:20 +02004534 switch (codec->vendor_id) {
4535 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004536 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004537 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004538 case 0x14f15051:
4539 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02004540 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004541 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
Takashi Iwai38681372012-02-27 15:00:58 +01004542 break;
Michael Karcher51969d62012-04-06 15:34:19 +02004543 default:
4544 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004545 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
4546 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02004547 }
4548
Takashi Iwai23d30f22012-05-07 17:17:32 +02004549 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4550
Takashi Iwaif29735c2012-03-13 07:55:10 +01004551 /* Show mute-led control only on HP laptops
4552 * This is a sort of white-list: on HP laptops, EAPD corresponds
4553 * only to the mute-LED without actualy amp function. Meanwhile,
4554 * others may use EAPD really as an amp switch, so it might be
4555 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004556 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004557 switch (codec->subsystem_id >> 16) {
4558 case 0x103c:
4559 spec->vmaster_mute_led = 1;
4560 break;
4561 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004562
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004563 err = cx_auto_search_adcs(codec);
4564 if (err < 0)
4565 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004566 err = cx_auto_parse_auto_config(codec);
4567 if (err < 0) {
4568 kfree(codec->spec);
4569 codec->spec = NULL;
4570 return err;
4571 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004572 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004573 codec->patch_ops = cx_auto_patch_ops;
4574 if (spec->beep_amp)
4575 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004576
4577 /* Some laptops with Conexant chips show stalls in S3 resume,
4578 * which falls into the single-cmd mode.
4579 * Better to make reset, then.
4580 */
4581 if (!codec->bus->sync_write) {
4582 snd_printd("hda_codec: "
4583 "Enable sync_write for stable communication\n");
4584 codec->bus->sync_write = 1;
4585 codec->bus->allow_bus_reset = 1;
4586 }
4587
Takashi Iwaif2e57312010-09-15 10:07:08 +02004588 return 0;
4589}
4590
4591/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004592 */
4593
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004594static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004595 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4596 .patch = patch_cxt5045 },
4597 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4598 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004599 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4600 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004601 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4602 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004603 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4604 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004605 { .id = 0x14f15068, .name = "CX20584",
4606 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004607 { .id = 0x14f15069, .name = "CX20585",
4608 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004609 { .id = 0x14f1506c, .name = "CX20588",
4610 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004611 { .id = 0x14f1506e, .name = "CX20590",
4612 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004613 { .id = 0x14f15097, .name = "CX20631",
4614 .patch = patch_conexant_auto },
4615 { .id = 0x14f15098, .name = "CX20632",
4616 .patch = patch_conexant_auto },
4617 { .id = 0x14f150a1, .name = "CX20641",
4618 .patch = patch_conexant_auto },
4619 { .id = 0x14f150a2, .name = "CX20642",
4620 .patch = patch_conexant_auto },
4621 { .id = 0x14f150ab, .name = "CX20651",
4622 .patch = patch_conexant_auto },
4623 { .id = 0x14f150ac, .name = "CX20652",
4624 .patch = patch_conexant_auto },
4625 { .id = 0x14f150b8, .name = "CX20664",
4626 .patch = patch_conexant_auto },
4627 { .id = 0x14f150b9, .name = "CX20665",
4628 .patch = patch_conexant_auto },
Takashi Iwai2d825fd2012-05-11 08:39:24 +02004629 { .id = 0x14f1510f, .name = "CX20751/2",
4630 .patch = patch_conexant_auto },
4631 { .id = 0x14f15110, .name = "CX20751/2",
4632 .patch = patch_conexant_auto },
4633 { .id = 0x14f15111, .name = "CX20753/4",
4634 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004635 {} /* terminator */
4636};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004637
4638MODULE_ALIAS("snd-hda-codec-id:14f15045");
4639MODULE_ALIAS("snd-hda-codec-id:14f15047");
4640MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004641MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004642MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004643MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004644MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004645MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004646MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004647MODULE_ALIAS("snd-hda-codec-id:14f15097");
4648MODULE_ALIAS("snd-hda-codec-id:14f15098");
4649MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4650MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4651MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4652MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4653MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4654MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai2d825fd2012-05-11 08:39:24 +02004655MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4656MODULE_ALIAS("snd-hda-codec-id:14f15110");
4657MODULE_ALIAS("snd-hda-codec-id:14f15111");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004658
4659MODULE_LICENSE("GPL");
4660MODULE_DESCRIPTION("Conexant HD-audio codec");
4661
4662static struct hda_codec_preset_list conexant_list = {
4663 .preset = snd_hda_preset_conexant,
4664 .owner = THIS_MODULE,
4665};
4666
4667static int __init patch_conexant_init(void)
4668{
4669 return snd_hda_add_codec_preset(&conexant_list);
4670}
4671
4672static void __exit patch_conexant_exit(void)
4673{
4674 snd_hda_delete_codec_preset(&conexant_list);
4675}
4676
4677module_init(patch_conexant_init)
4678module_exit(patch_conexant_exit)