blob: 60890bfecc196600ffa15ab5979c06aef8891f9b [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 Iwai23d30f22012-05-07 17:17:32 +020070 struct hda_gen_spec gen;
Tobin Davisc9b443d2006-11-14 12:13:39 +010071
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020072 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010073 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010074 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +010075 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaif29735c2012-03-13 07:55:10 +010076 bool vmaster_mute_led;
Tobin Davisc9b443d2006-11-14 12:13:39 +010077
78 const struct hda_verb *init_verbs[5]; /* initialization verbs
79 * don't forget NULL
80 * termination!
81 */
82 unsigned int num_init_verbs;
83
84 /* playback */
85 struct hda_multi_out multiout; /* playback set-up
86 * max_channels, dacs must be set
87 * dig_out_nid and hp_nid are optional
88 */
89 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010090 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020091 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010092 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020093 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020094 int auto_mic_dock; /* imux_pins[] index for dock mic */
95 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010096 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050097 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010098
99 /* capture */
100 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200101 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100102 hda_nid_t dig_in_nid; /* digital-in NID; optional */
103
Takashi Iwai461e2c72008-01-25 11:35:17 +0100104 unsigned int cur_adc_idx;
105 hda_nid_t cur_adc;
106 unsigned int cur_adc_stream_tag;
107 unsigned int cur_adc_format;
108
Takashi Iwai6764bce2011-05-13 16:52:25 +0200109 const struct hda_pcm_stream *capture_stream;
110
Tobin Davisc9b443d2006-11-14 12:13:39 +0100111 /* capture source */
112 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200113 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100114 unsigned int cur_mux[3];
115
116 /* channel model */
117 const struct hda_channel_mode *channel_mode;
118 int num_channel_mode;
119
120 /* PCM information */
121 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
122
Tobin Davisc9b443d2006-11-14 12:13:39 +0100123 unsigned int spdif_route;
124
125 /* dynamic controls, init_verbs and input_mux */
126 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100127 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200128 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200129 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200130 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200131 struct pin_dac_pair dac_info[8];
132 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100133
Daniel Drake0fb67e92009-07-16 14:46:57 +0100134 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200135 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200136 unsigned int detect_line:1; /* Line-out detection enabled */
137 unsigned int automute_lines:1; /* automute line-out as well */
138 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200139 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500140 unsigned int dell_vostro:1;
141 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200142 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200143 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100144 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200145 unsigned int pin_eapd_ctrls:1;
David Henningsson18dcd302012-04-02 15:40:27 +0200146 unsigned int fixup_stereo_dmic:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100147
Takashi Iwai6764bce2011-05-13 16:52:25 +0200148 unsigned int adc_switching:1;
149
Daniel Drake75f89912010-01-07 13:46:25 +0100150 unsigned int ext_mic_present;
151 unsigned int recording;
152 void (*capture_prepare)(struct hda_codec *codec);
153 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100154
155 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
156 * through the microphone jack.
157 * When the user enables this through a mixer switch, both internal and
158 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
159 * we also allow the bias to be configured through a separate mixer
160 * control. */
161 unsigned int dc_enable;
162 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
163 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200164
165 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200166
167 /* extra EAPD pins */
168 unsigned int num_eapds;
169 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100170};
171
172static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec,
174 struct snd_pcm_substream *substream)
175{
176 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100177 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
178 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100179}
180
181static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
182 struct hda_codec *codec,
183 unsigned int stream_tag,
184 unsigned int format,
185 struct snd_pcm_substream *substream)
186{
187 struct conexant_spec *spec = codec->spec;
188 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
189 stream_tag,
190 format, substream);
191}
192
193static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
194 struct hda_codec *codec,
195 struct snd_pcm_substream *substream)
196{
197 struct conexant_spec *spec = codec->spec;
198 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
199}
200
201/*
202 * Digital out
203 */
204static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
205 struct hda_codec *codec,
206 struct snd_pcm_substream *substream)
207{
208 struct conexant_spec *spec = codec->spec;
209 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
210}
211
212static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
213 struct hda_codec *codec,
214 struct snd_pcm_substream *substream)
215{
216 struct conexant_spec *spec = codec->spec;
217 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
218}
219
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200220static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
221 struct hda_codec *codec,
222 unsigned int stream_tag,
223 unsigned int format,
224 struct snd_pcm_substream *substream)
225{
226 struct conexant_spec *spec = codec->spec;
227 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
228 stream_tag,
229 format, substream);
230}
231
Tobin Davisc9b443d2006-11-14 12:13:39 +0100232/*
233 * Analog capture
234 */
235static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
236 struct hda_codec *codec,
237 unsigned int stream_tag,
238 unsigned int format,
239 struct snd_pcm_substream *substream)
240{
241 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100242 if (spec->capture_prepare)
243 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100244 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
245 stream_tag, 0, format);
246 return 0;
247}
248
249static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
250 struct hda_codec *codec,
251 struct snd_pcm_substream *substream)
252{
253 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100254 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100255 if (spec->capture_cleanup)
256 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100257 return 0;
258}
259
260
261
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200262static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100263 .substreams = 1,
264 .channels_min = 2,
265 .channels_max = 2,
266 .nid = 0, /* fill later */
267 .ops = {
268 .open = conexant_playback_pcm_open,
269 .prepare = conexant_playback_pcm_prepare,
270 .cleanup = conexant_playback_pcm_cleanup
271 },
272};
273
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200274static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100275 .substreams = 1,
276 .channels_min = 2,
277 .channels_max = 2,
278 .nid = 0, /* fill later */
279 .ops = {
280 .prepare = conexant_capture_pcm_prepare,
281 .cleanup = conexant_capture_pcm_cleanup
282 },
283};
284
285
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200286static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100287 .substreams = 1,
288 .channels_min = 2,
289 .channels_max = 2,
290 .nid = 0, /* fill later */
291 .ops = {
292 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200293 .close = conexant_dig_playback_pcm_close,
294 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100295 },
296};
297
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200298static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100299 .substreams = 1,
300 .channels_min = 2,
301 .channels_max = 2,
302 /* NID is set in alc_build_pcms */
303};
304
Takashi Iwai461e2c72008-01-25 11:35:17 +0100305static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
306 struct hda_codec *codec,
307 unsigned int stream_tag,
308 unsigned int format,
309 struct snd_pcm_substream *substream)
310{
311 struct conexant_spec *spec = codec->spec;
312 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
313 spec->cur_adc_stream_tag = stream_tag;
314 spec->cur_adc_format = format;
315 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
316 return 0;
317}
318
319static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
320 struct hda_codec *codec,
321 struct snd_pcm_substream *substream)
322{
323 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100324 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100325 spec->cur_adc = 0;
326 return 0;
327}
328
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200329static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100330 .substreams = 1,
331 .channels_min = 2,
332 .channels_max = 2,
333 .nid = 0, /* fill later */
334 .ops = {
335 .prepare = cx5051_capture_pcm_prepare,
336 .cleanup = cx5051_capture_pcm_cleanup
337 },
338};
339
Takashi Iwaiee81abb2012-11-08 17:12:10 +0100340static bool is_2_1_speaker(struct conexant_spec *spec);
341
Tobin Davisc9b443d2006-11-14 12:13:39 +0100342static int conexant_build_pcms(struct hda_codec *codec)
343{
344 struct conexant_spec *spec = codec->spec;
345 struct hda_pcm *info = spec->pcm_rec;
346
347 codec->num_pcms = 1;
348 codec->pcm_info = info;
349
350 info->name = "CONEXANT Analog";
351 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
352 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
353 spec->multiout.max_channels;
354 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
355 spec->multiout.dac_nids[0];
Takashi Iwaiee81abb2012-11-08 17:12:10 +0100356 if (is_2_1_speaker(spec))
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
358 snd_pcm_2_1_chmaps;
Takashi Iwai6764bce2011-05-13 16:52:25 +0200359 if (spec->capture_stream)
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
361 else {
362 if (codec->vendor_id == 0x14f15051)
363 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
364 cx5051_pcm_analog_capture;
365 else {
366 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
367 conexant_pcm_analog_capture;
368 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
369 spec->num_adc_nids;
370 }
371 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100372 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
373
374 if (spec->multiout.dig_out_nid) {
375 info++;
376 codec->num_pcms++;
377 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100378 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100379 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
380 conexant_pcm_digital_playback;
381 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
382 spec->multiout.dig_out_nid;
383 if (spec->dig_in_nid) {
384 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
385 conexant_pcm_digital_capture;
386 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
387 spec->dig_in_nid;
388 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500389 if (spec->slave_dig_outs[0])
390 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100391 }
392
393 return 0;
394}
395
396static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_info *uinfo)
398{
399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
400 struct conexant_spec *spec = codec->spec;
401
402 return snd_hda_input_mux_info(spec->input_mux, uinfo);
403}
404
405static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_value *ucontrol)
407{
408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409 struct conexant_spec *spec = codec->spec;
410 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
411
412 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
413 return 0;
414}
415
416static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
417 struct snd_ctl_elem_value *ucontrol)
418{
419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420 struct conexant_spec *spec = codec->spec;
421 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
422
423 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
424 spec->capsrc_nids[adc_idx],
425 &spec->cur_mux[adc_idx]);
426}
427
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200428static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
429 unsigned int power_state)
430{
431 if (power_state == AC_PWRST_D3)
432 msleep(100);
433 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
434 power_state);
435 /* partial workaround for "azx_get_response timeout" */
436 if (power_state == AC_PWRST_D0)
437 msleep(10);
438 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
439}
440
Tobin Davisc9b443d2006-11-14 12:13:39 +0100441static int conexant_init(struct hda_codec *codec)
442{
443 struct conexant_spec *spec = codec->spec;
444 int i;
445
446 for (i = 0; i < spec->num_init_verbs; i++)
447 snd_hda_sequence_write(codec, spec->init_verbs[i]);
448 return 0;
449}
450
451static void conexant_free(struct hda_codec *codec)
452{
Takashi Iwaiee48df52012-06-26 14:54:32 +0200453 struct conexant_spec *spec = codec->spec;
454 snd_hda_gen_free(&spec->gen);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200455 snd_hda_detach_beep_device(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +0200456 kfree(spec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100457}
458
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200459static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100460 {
461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
462 .name = "Capture Source",
463 .info = conexant_mux_enum_info,
464 .get = conexant_mux_enum_get,
465 .put = conexant_mux_enum_put
466 },
467 {}
468};
469
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200470#ifdef CONFIG_SND_HDA_INPUT_BEEP
471/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200472static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200473 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
474 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
475 { } /* end */
476};
477#endif
478
Takashi Iwai9322ca52012-02-03 14:28:01 +0100479static const char * const slave_pfxs[] = {
Takashi Iwaif37bc7a2012-11-08 15:59:23 +0100480 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100481 NULL
482};
483
Tobin Davisc9b443d2006-11-14 12:13:39 +0100484static int conexant_build_controls(struct hda_codec *codec)
485{
486 struct conexant_spec *spec = codec->spec;
487 unsigned int i;
488 int err;
489
490 for (i = 0; i < spec->num_mixers; i++) {
491 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
492 if (err < 0)
493 return err;
494 }
495 if (spec->multiout.dig_out_nid) {
496 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600497 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100498 spec->multiout.dig_out_nid);
499 if (err < 0)
500 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100501 err = snd_hda_create_spdif_share_sw(codec,
502 &spec->multiout);
503 if (err < 0)
504 return err;
505 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100506 }
507 if (spec->dig_in_nid) {
508 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
509 if (err < 0)
510 return err;
511 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100512
513 /* if we have no master control, let's create it */
514 if (spec->vmaster_nid &&
515 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
516 unsigned int vmaster_tlv[4];
517 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
518 HDA_OUTPUT, vmaster_tlv);
519 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100520 vmaster_tlv, slave_pfxs,
521 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100522 if (err < 0)
523 return err;
524 }
525 if (spec->vmaster_nid &&
526 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai527c73b2012-03-12 12:38:51 +0100527 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
528 NULL, slave_pfxs,
529 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100530 &spec->vmaster_mute.sw_kctl);
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100531 if (err < 0)
532 return err;
533 }
534
Takashi Iwaib880c742009-03-10 14:41:05 +0100535 if (spec->input_mux) {
536 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
537 if (err < 0)
538 return err;
539 }
540
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200541#ifdef CONFIG_SND_HDA_INPUT_BEEP
542 /* create beep controls if needed */
543 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200544 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200545 for (knew = cxt_beep_mixer; knew->name; knew++) {
546 struct snd_kcontrol *kctl;
547 kctl = snd_ctl_new1(knew, codec);
548 if (!kctl)
549 return -ENOMEM;
550 kctl->private_value = spec->beep_amp;
551 err = snd_hda_ctl_add(codec, 0, kctl);
552 if (err < 0)
553 return err;
554 }
555 }
556#endif
557
Tobin Davisc9b443d2006-11-14 12:13:39 +0100558 return 0;
559}
560
Takashi Iwai83012a72012-08-24 18:38:08 +0200561#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200562static int conexant_suspend(struct hda_codec *codec)
Takashi Iwai697c3732010-07-30 11:28:02 +0200563{
564 snd_hda_shutup_pins(codec);
565 return 0;
566}
567#endif
568
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200569static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100570 .build_controls = conexant_build_controls,
571 .build_pcms = conexant_build_pcms,
572 .init = conexant_init,
573 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200574 .set_power_state = conexant_set_power,
Takashi Iwai83012a72012-08-24 18:38:08 +0200575#ifdef CONFIG_PM
Takashi Iwai697c3732010-07-30 11:28:02 +0200576 .suspend = conexant_suspend,
577#endif
578 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100579};
580
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200581#ifdef CONFIG_SND_HDA_INPUT_BEEP
582#define set_beep_amp(spec, nid, idx, dir) \
583 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
584#else
585#define set_beep_amp(spec, nid, idx, dir) /* NOP */
586#endif
587
Takashi Iwai6764bce2011-05-13 16:52:25 +0200588static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100589/*
590 * EAPD control
591 * the private value = nid | (invert << 8)
592 */
593
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200594#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100595
Tobin Davis82f30042007-02-13 12:45:44 +0100596static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100597 struct snd_ctl_elem_value *ucontrol)
598{
599 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
600 struct conexant_spec *spec = codec->spec;
601 int invert = (kcontrol->private_value >> 8) & 1;
602 if (invert)
603 ucontrol->value.integer.value[0] = !spec->cur_eapd;
604 else
605 ucontrol->value.integer.value[0] = spec->cur_eapd;
606 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100607
Tobin Davisc9b443d2006-11-14 12:13:39 +0100608}
609
Tobin Davis82f30042007-02-13 12:45:44 +0100610static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100611 struct snd_ctl_elem_value *ucontrol)
612{
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct conexant_spec *spec = codec->spec;
615 int invert = (kcontrol->private_value >> 8) & 1;
616 hda_nid_t nid = kcontrol->private_value & 0xff;
617 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100618
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100619 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100620 if (invert)
621 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200622 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100624
Tobin Davisc9b443d2006-11-14 12:13:39 +0100625 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200626 snd_hda_codec_write_cache(codec, nid,
627 0, AC_VERB_SET_EAPD_BTLENABLE,
628 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629 return 1;
630}
631
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100632/* controls for test mode */
633#ifdef CONFIG_SND_DEBUG
634
Tobin Davis82f30042007-02-13 12:45:44 +0100635#define CXT_EAPD_SWITCH(xname, nid, mask) \
636 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
637 .info = cxt_eapd_info, \
638 .get = cxt_eapd_get, \
639 .put = cxt_eapd_put, \
640 .private_value = nid | (mask<<16) }
641
642
643
Tobin Davisc9b443d2006-11-14 12:13:39 +0100644static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_info *uinfo)
646{
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct conexant_spec *spec = codec->spec;
649 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
650 spec->num_channel_mode);
651}
652
653static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol)
655{
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct conexant_spec *spec = codec->spec;
658 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
659 spec->num_channel_mode,
660 spec->multiout.max_channels);
661}
662
663static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_value *ucontrol)
665{
666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667 struct conexant_spec *spec = codec->spec;
668 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
669 spec->num_channel_mode,
670 &spec->multiout.max_channels);
671 if (err >= 0 && spec->need_dac_fix)
672 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
673 return err;
674}
675
676#define CXT_PIN_MODE(xname, nid, dir) \
677 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
678 .info = conexant_ch_mode_info, \
679 .get = conexant_ch_mode_get, \
680 .put = conexant_ch_mode_put, \
681 .private_value = nid | (dir<<16) }
682
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100683#endif /* CONFIG_SND_DEBUG */
684
Tobin Davisc9b443d2006-11-14 12:13:39 +0100685/* Conexant 5045 specific */
686
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200687static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
688static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
689static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100690#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200692static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100693 { 2, NULL },
694};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200696static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100697 .num_items = 2,
698 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200699 { "Internal Mic", 0x1 },
700 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100701 }
702};
703
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200704static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200705 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100706 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200707 { "Internal Mic", 0x1 },
708 { "Mic", 0x2 },
709 { "Line", 0x3 },
710 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100711 }
712};
713
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200714static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100715 .num_items = 2,
716 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200717 { "Mic", 0x1 },
718 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100719 }
720};
721
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722/* turn on/off EAPD (+ mute HP) as a master switch */
723static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
724 struct snd_ctl_elem_value *ucontrol)
725{
726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
727 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100728 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100729
Tobin Davis82f30042007-02-13 12:45:44 +0100730 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100731 return 0;
732
Tobin Davis82f30042007-02-13 12:45:44 +0100733 /* toggle internal speakers mute depending of presence of
734 * the headphone jack
735 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200736 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
737 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
738 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100739
Takashi Iwai47fd8302007-08-10 17:11:07 +0200740 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
741 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
742 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100743 return 1;
744}
745
746/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200747static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200748 .ops = &snd_hda_bind_vol,
749 .values = {
750 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
751 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
752 0
753 },
754};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100755
Tobin Davis7f296732007-03-12 11:39:01 +0100756/* toggle input of built-in and mic jack appropriately */
757static void cxt5045_hp_automic(struct hda_codec *codec)
758{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200759 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
761 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
762 {}
763 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200764 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100765 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
766 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
767 {}
768 };
769 unsigned int present;
770
Takashi Iwaid56757a2009-11-18 08:00:14 +0100771 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100772 if (present)
773 snd_hda_sequence_write(codec, mic_jack_on);
774 else
775 snd_hda_sequence_write(codec, mic_jack_off);
776}
777
Tobin Davisc9b443d2006-11-14 12:13:39 +0100778
779/* mute internal speaker if HP is plugged */
780static void cxt5045_hp_automute(struct hda_codec *codec)
781{
Tobin Davis82f30042007-02-13 12:45:44 +0100782 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100783 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784
Takashi Iwaid56757a2009-11-18 08:00:14 +0100785 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100786
Takashi Iwai47fd8302007-08-10 17:11:07 +0200787 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
788 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
789 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100790}
791
792/* unsolicited event for HP jack sensing */
793static void cxt5045_hp_unsol_event(struct hda_codec *codec,
794 unsigned int res)
795{
796 res >>= 26;
797 switch (res) {
798 case CONEXANT_HP_EVENT:
799 cxt5045_hp_automute(codec);
800 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100801 case CONEXANT_MIC_EVENT:
802 cxt5045_hp_automic(codec);
803 break;
804
Tobin Davisc9b443d2006-11-14 12:13:39 +0100805 }
806}
807
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200808static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200809 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
810 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200811 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
812 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100813 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
814 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100815 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
816 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200817 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 {
819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
820 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100821 .info = cxt_eapd_info,
822 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100823 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100824 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100825 },
826
827 {}
828};
829
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200830static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200831 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
832 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200833
Jiang Zhe5218c892008-01-17 11:18:41 +0100834 {}
835};
836
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200837static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200838 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
839 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100840 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
841 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100842 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
843 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100844 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
845 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100846 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
847 {
848 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
849 .name = "Master Playback Switch",
850 .info = cxt_eapd_info,
851 .get = cxt_eapd_get,
852 .put = cxt5045_hp_master_sw_put,
853 .private_value = 0x10,
854 },
855
856 {}
857};
858
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200859static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100860 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200861 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100862 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100863 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200864 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
865 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
866 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
867 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
868 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
870 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
871 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100873 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100874 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100875 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100876 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
877 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100878 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100879 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100880 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100881 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100882 { } /* end */
883};
884
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200885static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100886 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100887 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
888 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
889 /* Line In,HP, Amp */
890 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
891 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
892 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
893 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
894 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
895 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
896 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
897 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
898 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100899 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100900 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
901 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
902 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
903 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100904 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100905 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
906 /* EAPD */
907 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
908 { } /* end */
909};
Tobin Davis7f296732007-03-12 11:39:01 +0100910
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200911static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100912 /* pin sensing on HP jack */
913 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200914 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100915};
916
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200917static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100918 /* pin sensing on HP jack */
919 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200920 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100921};
922
Tobin Davisc9b443d2006-11-14 12:13:39 +0100923#ifdef CONFIG_SND_DEBUG
924/* Test configuration for debugging, modelled after the ALC260 test
925 * configuration.
926 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200927static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928 .num_items = 5,
929 .items = {
930 { "MIXER", 0x0 },
931 { "MIC1 pin", 0x1 },
932 { "LINE1 pin", 0x2 },
933 { "HP-OUT pin", 0x3 },
934 { "CD pin", 0x4 },
935 },
936};
937
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200938static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100939
940 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
942 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200943 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
944 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
945 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
946 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100947
948 /* Modes for retasking pin widgets */
949 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
950 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
951
Tobin Davis82f30042007-02-13 12:45:44 +0100952 /* EAPD Switch Control */
953 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
954
Tobin Davisc9b443d2006-11-14 12:13:39 +0100955 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100956
Michael Karcher250f3272012-04-06 15:34:20 +0200957 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
958 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
959 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
960 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
961 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
962 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
963 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
964 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
965 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
966 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100967 {
968 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
969 .name = "Input Source",
970 .info = conexant_mux_enum_info,
971 .get = conexant_mux_enum_get,
972 .put = conexant_mux_enum_put,
973 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200974 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200975 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
976 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100977 { } /* end */
978};
979
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200980static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100981 /* Set connections */
982 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
983 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
984 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100985 /* Enable retasking pins as output, initially without power amp */
986 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100987 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100988
989 /* Disable digital (SPDIF) pins initially, but users can enable
990 * them via a mixer switch. In the case of SPDIF-out, this initverb
991 * payload also sets the generation to 0, output to be in "consumer"
992 * PCM format, copyright asserted, no pre-emphasis and no validity
993 * control.
994 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100995 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
996 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100997
Tobin Davisc9b443d2006-11-14 12:13:39 +0100998 /* Unmute retasking pin widget output buffers since the default
999 * state appears to be output. As the pin mode is changed by the
1000 * user the pin mode control will take care of enabling the pin's
1001 * input/output buffers as needed.
1002 */
1003 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1004 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1005
1006 /* Mute capture amp left and right */
1007 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1008
1009 /* Set ADC connection select to match default mixer setting (mic1
1010 * pin)
1011 */
Michael Karcher250f3272012-04-06 15:34:20 +02001012 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1013 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001014
1015 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +02001016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001017 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1018 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1019 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1020 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1021
1022 { }
1023};
1024#endif
1025
1026
1027/* initialize jack-sensing, too */
1028static int cxt5045_init(struct hda_codec *codec)
1029{
1030 conexant_init(codec);
1031 cxt5045_hp_automute(codec);
1032 return 0;
1033}
1034
1035
1036enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001037 CXT5045_LAPTOP_HPSENSE,
1038 CXT5045_LAPTOP_MICSENSE,
1039 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001040 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001041 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001042#ifdef CONFIG_SND_DEBUG
1043 CXT5045_TEST,
1044#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001045 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001046 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001047};
1048
Takashi Iwaiea734962011-01-17 11:29:34 +01001049static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001050 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1051 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1052 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1053 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001054 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001056 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001057#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001058 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001059};
1060
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001061static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001062 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001063 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001064 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001065 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1066 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001067 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1068 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001069 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1070 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1071 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001072 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1073 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001074 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075 {}
1076};
1077
1078static int patch_cxt5045(struct hda_codec *codec)
1079{
1080 struct conexant_spec *spec;
1081 int board_config;
1082
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001083 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1084 cxt5045_models,
1085 cxt5045_cfg_tbl);
1086 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001087 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001088 if (board_config == CXT5045_AUTO)
1089 return patch_conexant_auto(codec);
1090
Tobin Davisc9b443d2006-11-14 12:13:39 +01001091 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1092 if (!spec)
1093 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001094 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001095 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001096
1097 spec->multiout.max_channels = 2;
1098 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1099 spec->multiout.dac_nids = cxt5045_dac_nids;
1100 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1101 spec->num_adc_nids = 1;
1102 spec->adc_nids = cxt5045_adc_nids;
1103 spec->capsrc_nids = cxt5045_capsrc_nids;
1104 spec->input_mux = &cxt5045_capture_source;
1105 spec->num_mixers = 1;
1106 spec->mixers[0] = cxt5045_mixers;
1107 spec->num_init_verbs = 1;
1108 spec->init_verbs[0] = cxt5045_init_verbs;
1109 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001110 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1111 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001112
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001113 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001114
1115 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116
Tobin Davisc9b443d2006-11-14 12:13:39 +01001117 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001118 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001119 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001120 spec->input_mux = &cxt5045_capture_source;
1121 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001122 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1123 spec->mixers[0] = cxt5045_mixers;
1124 codec->patch_ops.init = cxt5045_init;
1125 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001126 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001127 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001128 spec->input_mux = &cxt5045_capture_source;
1129 spec->num_init_verbs = 2;
1130 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131 spec->mixers[0] = cxt5045_mixers;
1132 codec->patch_ops.init = cxt5045_init;
1133 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001134 default:
1135 case CXT5045_LAPTOP_HPMICSENSE:
1136 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1137 spec->input_mux = &cxt5045_capture_source;
1138 spec->num_init_verbs = 3;
1139 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1140 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1141 spec->mixers[0] = cxt5045_mixers;
1142 codec->patch_ops.init = cxt5045_init;
1143 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001144 case CXT5045_BENQ:
1145 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1146 spec->input_mux = &cxt5045_capture_source_benq;
1147 spec->num_init_verbs = 1;
1148 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1149 spec->mixers[0] = cxt5045_mixers;
1150 spec->mixers[1] = cxt5045_benq_mixers;
1151 spec->num_mixers = 2;
1152 codec->patch_ops.init = cxt5045_init;
1153 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001154 case CXT5045_LAPTOP_HP530:
1155 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1156 spec->input_mux = &cxt5045_capture_source_hp530;
1157 spec->num_init_verbs = 2;
1158 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1159 spec->mixers[0] = cxt5045_mixers_hp530;
1160 codec->patch_ops.init = cxt5045_init;
1161 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001162#ifdef CONFIG_SND_DEBUG
1163 case CXT5045_TEST:
1164 spec->input_mux = &cxt5045_test_capture_source;
1165 spec->mixers[0] = cxt5045_test_mixer;
1166 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001167 break;
1168
Tobin Davisc9b443d2006-11-14 12:13:39 +01001169#endif
1170 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001171
Takashi Iwai031005f2008-06-26 14:49:58 +02001172 switch (codec->subsystem_id >> 16) {
1173 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001174 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001175 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001176 case 0x17aa:
1177 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1178 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1179 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001180 */
1181 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1182 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1183 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1184 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1185 (1 << AC_AMPCAP_MUTE_SHIFT));
1186 break;
1187 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001188
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001189 if (spec->beep_amp)
1190 snd_hda_attach_beep_device(codec, spec->beep_amp);
1191
Tobin Davisc9b443d2006-11-14 12:13:39 +01001192 return 0;
1193}
1194
1195
1196/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001197#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001198
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001199static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1200static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1201static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001202
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001203static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001204 { 2, NULL },
1205};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001206
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001207static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001208 .num_items = 2,
1209 .items = {
1210 { "ExtMic", 0x2 },
1211 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001212 }
1213};
1214
1215/* turn on/off EAPD (+ mute HP) as a master switch */
1216static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1217 struct snd_ctl_elem_value *ucontrol)
1218{
1219 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1220 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001221 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001222
Tobin Davis82f30042007-02-13 12:45:44 +01001223 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001224 return 0;
1225
Tobin Davis82f30042007-02-13 12:45:44 +01001226 /* toggle internal speakers mute depending of presence of
1227 * the headphone jack
1228 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001229 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001230 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1231 * pin widgets unlike other codecs. In this case, we need to
1232 * set index 0x01 for the volume from the mixer amp 0x19.
1233 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001234 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001235 HDA_AMP_MUTE, bits);
1236 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1237 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1238 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001239 return 1;
1240}
1241
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242/* mute internal speaker if HP is plugged */
1243static void cxt5047_hp_automute(struct hda_codec *codec)
1244{
Tobin Davis82f30042007-02-13 12:45:44 +01001245 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001246 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247
Takashi Iwaid56757a2009-11-18 08:00:14 +01001248 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001249
Takashi Iwai47fd8302007-08-10 17:11:07 +02001250 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001251 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001252 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001253 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001254}
1255
1256/* toggle input of built-in and mic jack appropriately */
1257static void cxt5047_hp_automic(struct hda_codec *codec)
1258{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001259 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001260 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1261 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 {}
1263 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001264 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001265 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1266 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267 {}
1268 };
1269 unsigned int present;
1270
Takashi Iwaid56757a2009-11-18 08:00:14 +01001271 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001272 if (present)
1273 snd_hda_sequence_write(codec, mic_jack_on);
1274 else
1275 snd_hda_sequence_write(codec, mic_jack_off);
1276}
1277
1278/* unsolicited event for HP jack sensing */
1279static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1280 unsigned int res)
1281{
Marc Boucher9f113e02008-01-22 15:18:08 +01001282 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283 case CONEXANT_HP_EVENT:
1284 cxt5047_hp_automute(codec);
1285 break;
1286 case CONEXANT_MIC_EVENT:
1287 cxt5047_hp_automic(codec);
1288 break;
1289 }
1290}
1291
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001292static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001293 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1294 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001295 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001296 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1297 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1298 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1299 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001300 {
1301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1302 .name = "Master Playback Switch",
1303 .info = cxt_eapd_info,
1304 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001305 .put = cxt5047_hp_master_sw_put,
1306 .private_value = 0x13,
1307 },
1308
1309 {}
1310};
1311
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001312static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001313 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001314 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001315 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1316 {}
1317};
1318
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001319static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001320 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001321 { } /* end */
1322};
1323
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001324static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325 /* Line in, Mic, Built-in Mic */
1326 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1327 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1328 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001329 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001330 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001331 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1332 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001333 /* Record selector: Mic */
1334 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1335 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1336 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1337 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001338 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1339 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1340 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1341 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 /* SPDIF route: PCM */
1343 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001344 /* Enable unsolicited events */
1345 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1346 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001347 { } /* end */
1348};
1349
1350/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001351static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001352 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001353 {}
1354};
1355
1356/* Test configuration for debugging, modelled after the ALC260 test
1357 * configuration.
1358 */
1359#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001360static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001361 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001363 { "LINE1 pin", 0x0 },
1364 { "MIC1 pin", 0x1 },
1365 { "MIC2 pin", 0x2 },
1366 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 },
1368};
1369
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001370static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001371
1372 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001373 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1375 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1376 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001377 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1378 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1380 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001381 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1382 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1383 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001385
1386 /* Modes for retasking pin widgets */
1387 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1388 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1389
Tobin Davis82f30042007-02-13 12:45:44 +01001390 /* EAPD Switch Control */
1391 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1392
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001394 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1395 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1396 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1397 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1398 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1399 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1400 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1401 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402
Tobin Davis82f30042007-02-13 12:45:44 +01001403 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1404 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1405 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1406 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1407 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1408 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1409 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1410 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001411 {
1412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1413 .name = "Input Source",
1414 .info = conexant_mux_enum_info,
1415 .get = conexant_mux_enum_get,
1416 .put = conexant_mux_enum_put,
1417 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001418 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001419
Tobin Davisc9b443d2006-11-14 12:13:39 +01001420 { } /* end */
1421};
1422
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001423static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001424 /* Enable retasking pins as output, initially without power amp */
1425 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1427 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1428
1429 /* Disable digital (SPDIF) pins initially, but users can enable
1430 * them via a mixer switch. In the case of SPDIF-out, this initverb
1431 * payload also sets the generation to 0, output to be in "consumer"
1432 * PCM format, copyright asserted, no pre-emphasis and no validity
1433 * control.
1434 */
1435 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1436
1437 /* Ensure mic1, mic2, line1 pin widgets take input from the
1438 * OUT1 sum bus when acting as an output.
1439 */
1440 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1441 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1442
1443 /* Start with output sum widgets muted and their output gains at min */
1444 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1445 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1446
1447 /* Unmute retasking pin widget output buffers since the default
1448 * state appears to be output. As the pin mode is changed by the
1449 * user the pin mode control will take care of enabling the pin's
1450 * input/output buffers as needed.
1451 */
1452 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1453 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1455
1456 /* Mute capture amp left and right */
1457 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1458
1459 /* Set ADC connection select to match default mixer setting (mic1
1460 * pin)
1461 */
1462 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1463
1464 /* Mute all inputs to mixer widget (even unconnected ones) */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1468 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1470 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1471 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1472 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1473
1474 { }
1475};
1476#endif
1477
1478
1479/* initialize jack-sensing, too */
1480static int cxt5047_hp_init(struct hda_codec *codec)
1481{
1482 conexant_init(codec);
1483 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001484 return 0;
1485}
1486
1487
1488enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001489 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1490 CXT5047_LAPTOP_HP, /* Some HP laptops */
1491 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001492#ifdef CONFIG_SND_DEBUG
1493 CXT5047_TEST,
1494#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001495 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001496 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001497};
1498
Takashi Iwaiea734962011-01-17 11:29:34 +01001499static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001500 [CXT5047_LAPTOP] = "laptop",
1501 [CXT5047_LAPTOP_HP] = "laptop-hp",
1502 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001503#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001504 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001505#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001506 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001507};
1508
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001509static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001510 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001511 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1512 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001513 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001514 {}
1515};
1516
1517static int patch_cxt5047(struct hda_codec *codec)
1518{
1519 struct conexant_spec *spec;
1520 int board_config;
1521
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001522 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1523 cxt5047_models,
1524 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001525 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001526 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001527 if (board_config == CXT5047_AUTO)
1528 return patch_conexant_auto(codec);
1529
Tobin Davisc9b443d2006-11-14 12:13:39 +01001530 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1531 if (!spec)
1532 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001533 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001534 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001535
1536 spec->multiout.max_channels = 2;
1537 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1538 spec->multiout.dac_nids = cxt5047_dac_nids;
1539 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1540 spec->num_adc_nids = 1;
1541 spec->adc_nids = cxt5047_adc_nids;
1542 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001543 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001544 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545 spec->num_init_verbs = 1;
1546 spec->init_verbs[0] = cxt5047_init_verbs;
1547 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001548 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1549 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001550
1551 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553 switch (board_config) {
1554 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001555 spec->num_mixers = 2;
1556 spec->mixers[1] = cxt5047_hp_spk_mixers;
1557 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558 break;
1559 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001560 spec->num_mixers = 2;
1561 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001562 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001563 codec->patch_ops.init = cxt5047_hp_init;
1564 break;
1565 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001566 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001567 spec->num_mixers = 2;
1568 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001569 spec->num_init_verbs = 2;
1570 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001571 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001572 break;
1573#ifdef CONFIG_SND_DEBUG
1574 case CXT5047_TEST:
1575 spec->input_mux = &cxt5047_test_capture_source;
1576 spec->mixers[0] = cxt5047_test_mixer;
1577 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001578 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001579#endif
1580 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001581 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001582
1583 switch (codec->subsystem_id >> 16) {
1584 case 0x103c:
1585 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1586 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1587 * with 0 dB offset 0x17)
1588 */
1589 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1590 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1591 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1592 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1593 (1 << AC_AMPCAP_MUTE_SHIFT));
1594 break;
1595 }
1596
Tobin Davisc9b443d2006-11-14 12:13:39 +01001597 return 0;
1598}
1599
Takashi Iwai461e2c72008-01-25 11:35:17 +01001600/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001601static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1602static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001603
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001604static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001605 { 2, NULL },
1606};
1607
1608static void cxt5051_update_speaker(struct hda_codec *codec)
1609{
1610 struct conexant_spec *spec = codec->spec;
1611 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001612 /* headphone pin */
1613 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001614 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
Takashi Iwai23d2df52010-01-24 11:19:27 +01001615 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001616 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001617 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001618 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001619 if (spec->ideapad)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001620 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001621}
1622
1623/* turn on/off EAPD (+ mute HP) as a master switch */
1624static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_value *ucontrol)
1626{
1627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1628
1629 if (!cxt_eapd_put(kcontrol, ucontrol))
1630 return 0;
1631 cxt5051_update_speaker(codec);
1632 return 1;
1633}
1634
1635/* toggle input of built-in and mic jack appropriately */
1636static void cxt5051_portb_automic(struct hda_codec *codec)
1637{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001638 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001639 unsigned int present;
1640
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001641 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001642 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001643 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001644 snd_hda_codec_write(codec, 0x14, 0,
1645 AC_VERB_SET_CONNECT_SEL,
1646 present ? 0x01 : 0x00);
1647}
1648
1649/* switch the current ADC according to the jack state */
1650static void cxt5051_portc_automic(struct hda_codec *codec)
1651{
1652 struct conexant_spec *spec = codec->spec;
1653 unsigned int present;
1654 hda_nid_t new_adc;
1655
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001656 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001657 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001658 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001659 if (present)
1660 spec->cur_adc_idx = 1;
1661 else
1662 spec->cur_adc_idx = 0;
1663 new_adc = spec->adc_nids[spec->cur_adc_idx];
1664 if (spec->cur_adc && spec->cur_adc != new_adc) {
1665 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001666 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001667 spec->cur_adc = new_adc;
1668 snd_hda_codec_setup_stream(codec, new_adc,
1669 spec->cur_adc_stream_tag, 0,
1670 spec->cur_adc_format);
1671 }
1672}
1673
1674/* mute internal speaker if HP is plugged */
1675static void cxt5051_hp_automute(struct hda_codec *codec)
1676{
1677 struct conexant_spec *spec = codec->spec;
1678
Takashi Iwaid56757a2009-11-18 08:00:14 +01001679 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001680 cxt5051_update_speaker(codec);
1681}
1682
1683/* unsolicited event for HP jack sensing */
1684static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1685 unsigned int res)
1686{
1687 switch (res >> 26) {
1688 case CONEXANT_HP_EVENT:
1689 cxt5051_hp_automute(codec);
1690 break;
1691 case CXT5051_PORTB_EVENT:
1692 cxt5051_portb_automic(codec);
1693 break;
1694 case CXT5051_PORTC_EVENT:
1695 cxt5051_portc_automic(codec);
1696 break;
1697 }
1698}
1699
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001700static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001701 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1702 {
1703 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1704 .name = "Master Playback Switch",
1705 .info = cxt_eapd_info,
1706 .get = cxt_eapd_get,
1707 .put = cxt5051_hp_master_sw_put,
1708 .private_value = 0x1a,
1709 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001710 {}
1711};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001712
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001713static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001714 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1715 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001716 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1717 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
David Henningssonc40bd912012-09-19 12:19:47 +02001718 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1719 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001720 {}
1721};
1722
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001723static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001724 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1725 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001726 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1727 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001728 {}
1729};
1730
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001731static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001732 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1733 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001734 {}
1735};
1736
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001737static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001738 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1739 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001740 {}
1741};
1742
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001743static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001744 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1745 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001746 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1747 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001748 {}
1749};
1750
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001751static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001752 /* Line in, Mic */
1753 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1754 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1755 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1756 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1757 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1758 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1759 /* SPK */
1760 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1761 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1762 /* HP, Amp */
1763 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1764 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1765 /* DAC1 */
1766 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001767 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1769 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1770 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1771 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001772 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001773 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1774 /* EAPD */
1775 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1776 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001777 { } /* end */
1778};
1779
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001780static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001781 /* Line in, Mic */
1782 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1783 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1784 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1785 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1786 /* SPK */
1787 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1788 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1789 /* HP, Amp */
1790 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1791 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1792 /* DAC1 */
1793 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001794 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001795 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1796 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1797 /* SPDIF route: PCM */
1798 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1799 /* EAPD */
1800 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1801 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001802 { } /* end */
1803};
1804
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001805static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001806 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001807 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001808 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1809 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1810 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1811 /* SPK */
1812 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1813 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1814 /* HP, Amp */
1815 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1816 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1817 /* DAC1 */
1818 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001819 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1821 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1822 /* SPDIF route: PCM */
1823 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1824 /* EAPD */
1825 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1826 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001827 { } /* end */
1828};
1829
Takashi Iwai6953e552010-01-24 11:00:27 +01001830static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1831 unsigned int event)
1832{
1833 snd_hda_codec_write(codec, nid, 0,
1834 AC_VERB_SET_UNSOLICITED_ENABLE,
1835 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001836}
1837
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001838static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001839 /* Subwoofer */
1840 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1841 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1842 { } /* end */
1843};
1844
Takashi Iwai461e2c72008-01-25 11:35:17 +01001845/* initialize jack-sensing, too */
1846static int cxt5051_init(struct hda_codec *codec)
1847{
Takashi Iwai6953e552010-01-24 11:00:27 +01001848 struct conexant_spec *spec = codec->spec;
1849
Takashi Iwai461e2c72008-01-25 11:35:17 +01001850 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001851
1852 if (spec->auto_mic & AUTO_MIC_PORTB)
1853 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1854 if (spec->auto_mic & AUTO_MIC_PORTC)
1855 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1856
Takashi Iwai461e2c72008-01-25 11:35:17 +01001857 if (codec->patch_ops.unsol_event) {
1858 cxt5051_hp_automute(codec);
1859 cxt5051_portb_automic(codec);
1860 cxt5051_portc_automic(codec);
1861 }
1862 return 0;
1863}
1864
1865
1866enum {
1867 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1868 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001869 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001870 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001871 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001872 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001873 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001874 CXT5051_MODELS
1875};
1876
Takashi Iwaiea734962011-01-17 11:29:34 +01001877static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001878 [CXT5051_LAPTOP] = "laptop",
1879 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001880 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001881 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001882 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001883 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001884 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001885};
1886
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001887static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001888 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001889 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001890 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001891 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001892 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1893 CXT5051_LAPTOP),
1894 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001895 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001896 {}
1897};
1898
1899static int patch_cxt5051(struct hda_codec *codec)
1900{
1901 struct conexant_spec *spec;
1902 int board_config;
1903
Takashi Iwai6764bce2011-05-13 16:52:25 +02001904 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1905 cxt5051_models,
1906 cxt5051_cfg_tbl);
1907 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001908 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001909 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001910 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001911
Takashi Iwai461e2c72008-01-25 11:35:17 +01001912 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1913 if (!spec)
1914 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001915 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001916 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001917
1918 codec->patch_ops = conexant_patch_ops;
1919 codec->patch_ops.init = cxt5051_init;
1920
1921 spec->multiout.max_channels = 2;
1922 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1923 spec->multiout.dac_nids = cxt5051_dac_nids;
1924 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1925 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1926 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001927 spec->num_mixers = 2;
1928 spec->mixers[0] = cxt5051_capture_mixers;
1929 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001930 spec->num_init_verbs = 1;
1931 spec->init_verbs[0] = cxt5051_init_verbs;
1932 spec->spdif_route = 0;
1933 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1934 spec->channel_mode = cxt5051_modes;
1935 spec->cur_adc = 0;
1936 spec->cur_adc_idx = 0;
1937
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001938 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1939
Takashi Iwai79d7d532009-03-04 09:03:50 +01001940 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1941
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001942 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001943 switch (board_config) {
1944 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001945 spec->mixers[0] = cxt5051_hp_mixers;
1946 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001947 case CXT5051_HP_DV6736:
1948 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1949 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001950 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001951 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001952 case CXT5051_F700:
1953 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1954 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001955 spec->auto_mic = 0;
1956 break;
1957 case CXT5051_TOSHIBA:
1958 spec->mixers[0] = cxt5051_toshiba_mixers;
1959 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001960 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001961 case CXT5051_IDEAPAD:
1962 spec->init_verbs[spec->num_init_verbs++] =
1963 cxt5051_ideapad_init_verbs;
1964 spec->ideapad = 1;
1965 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 }
1967
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001968 if (spec->beep_amp)
1969 snd_hda_attach_beep_device(codec, spec->beep_amp);
1970
Takashi Iwai461e2c72008-01-25 11:35:17 +01001971 return 0;
1972}
1973
Daniel Drake0fb67e92009-07-16 14:46:57 +01001974/* Conexant 5066 specific */
1975
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001976static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1977static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1978static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1979static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001980
Daniel Drakedbaccc02009-11-09 15:17:24 +00001981/* OLPC's microphone port is DC coupled for use with external sensors,
1982 * therefore we use a 50% mic bias in order to center the input signal with
1983 * the DC input range of the codec. */
1984#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1985
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001986static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001987 { 2, NULL },
1988};
1989
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001990#define HP_PRESENT_PORT_A (1 << 0)
1991#define HP_PRESENT_PORT_D (1 << 1)
1992#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1993#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1994
Daniel Drake0fb67e92009-07-16 14:46:57 +01001995static void cxt5066_update_speaker(struct hda_codec *codec)
1996{
1997 struct conexant_spec *spec = codec->spec;
1998 unsigned int pinctl;
1999
John Baboval3a253442010-12-02 11:21:31 -05002000 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2001 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002002
2003 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002004 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002005 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002006
2007 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002008 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2009 if (spec->dell_automute || spec->thinkpad) {
2010 /* Mute if Port A is connected */
2011 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002012 pinctl = 0;
2013 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002014 /* Thinkpad/Dell doesn't give pin-D status */
2015 if (!hp_port_d_present(spec))
2016 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002017 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002018 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002019
2020 /* CLASS_D AMP */
2021 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002022 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002023}
2024
2025/* turn on/off EAPD (+ mute HP) as a master switch */
2026static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2027 struct snd_ctl_elem_value *ucontrol)
2028{
2029 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2030
2031 if (!cxt_eapd_put(kcontrol, ucontrol))
2032 return 0;
2033
2034 cxt5066_update_speaker(codec);
2035 return 1;
2036}
2037
Daniel Drakec4cfe662010-01-07 13:47:04 +01002038static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2039 .num_items = 3,
2040 .items = {
2041 { "Off", PIN_IN },
2042 { "50%", PIN_VREF50 },
2043 { "80%", PIN_VREF80 },
2044 },
2045};
2046
2047static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2048{
2049 struct conexant_spec *spec = codec->spec;
2050 /* Even though port F is the DC input, the bias is controlled on port B.
2051 * we also leave that port as an active input (but unselected) in DC mode
2052 * just in case that is necessary to make the bias setting take effect. */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002053 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002054 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2055}
2056
Daniel Drake75f89912010-01-07 13:46:25 +01002057/* OLPC defers mic widget control until when capture is started because the
2058 * microphone LED comes on as soon as these settings are put in place. if we
2059 * did this before recording, it would give the false indication that recording
2060 * is happening when it is not. */
2061static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002062{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002063 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002064 if (!spec->recording)
2065 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002066
Daniel Drakec4cfe662010-01-07 13:47:04 +01002067 if (spec->dc_enable) {
2068 /* in DC mode we ignore presence detection and just use the jack
2069 * through our special DC port */
2070 const struct hda_verb enable_dc_mode[] = {
2071 /* disble internal mic, port C */
2072 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2073
2074 /* enable DC capture, port F */
2075 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2076 {},
2077 };
2078
2079 snd_hda_sequence_write(codec, enable_dc_mode);
2080 /* port B input disabled (and bias set) through the following call */
2081 cxt5066_set_olpc_dc_bias(codec);
2082 return;
2083 }
2084
2085 /* disable DC (port F) */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002086 snd_hda_set_pin_ctl(codec, 0x1e, 0);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002087
Daniel Drake75f89912010-01-07 13:46:25 +01002088 /* external mic, port B */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002089 snd_hda_set_pin_ctl(codec, 0x1a,
Daniel Drake75f89912010-01-07 13:46:25 +01002090 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002091
Daniel Drake75f89912010-01-07 13:46:25 +01002092 /* internal mic, port C */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002093 snd_hda_set_pin_ctl(codec, 0x1b,
Daniel Drake75f89912010-01-07 13:46:25 +01002094 spec->ext_mic_present ? 0 : PIN_VREF80);
2095}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002096
Daniel Drake75f89912010-01-07 13:46:25 +01002097/* toggle input of built-in and mic jack appropriately */
2098static void cxt5066_olpc_automic(struct hda_codec *codec)
2099{
2100 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002101 unsigned int present;
2102
Daniel Drakec4cfe662010-01-07 13:47:04 +01002103 if (spec->dc_enable) /* don't do presence detection in DC mode */
2104 return;
2105
Daniel Drake75f89912010-01-07 13:46:25 +01002106 present = snd_hda_codec_read(codec, 0x1a, 0,
2107 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2108 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002109 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002110 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002111 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002112
2113 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2114 present ? 0 : 1);
2115 spec->ext_mic_present = !!present;
2116
2117 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002118}
2119
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002120/* toggle input of built-in digital mic and mic jack appropriately */
2121static void cxt5066_vostro_automic(struct hda_codec *codec)
2122{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002123 unsigned int present;
2124
2125 struct hda_verb ext_mic_present[] = {
2126 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002127 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002128
2129 /* switch to external mic input */
2130 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2131 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2132
2133 /* disable internal digital mic */
2134 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2135 {}
2136 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002137 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002138 /* enable internal mic, port C */
2139 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2140
2141 /* switch to internal mic input */
2142 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2143
2144 /* disable external mic, port B */
2145 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2146 {}
2147 };
2148
2149 present = snd_hda_jack_detect(codec, 0x1a);
2150 if (present) {
2151 snd_printdd("CXT5066: external microphone detected\n");
2152 snd_hda_sequence_write(codec, ext_mic_present);
2153 } else {
2154 snd_printdd("CXT5066: external microphone absent\n");
2155 snd_hda_sequence_write(codec, ext_mic_absent);
2156 }
2157}
2158
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002159/* toggle input of built-in digital mic and mic jack appropriately */
2160static void cxt5066_ideapad_automic(struct hda_codec *codec)
2161{
2162 unsigned int present;
2163
2164 struct hda_verb ext_mic_present[] = {
2165 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2166 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2167 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2168 {}
2169 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002170 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002171 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2172 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2173 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2174 {}
2175 };
2176
2177 present = snd_hda_jack_detect(codec, 0x1b);
2178 if (present) {
2179 snd_printdd("CXT5066: external microphone detected\n");
2180 snd_hda_sequence_write(codec, ext_mic_present);
2181 } else {
2182 snd_printdd("CXT5066: external microphone absent\n");
2183 snd_hda_sequence_write(codec, ext_mic_absent);
2184 }
2185}
2186
David Henningssona1d69062011-01-21 13:33:28 +01002187
2188/* toggle input of built-in digital mic and mic jack appropriately */
2189static void cxt5066_asus_automic(struct hda_codec *codec)
2190{
2191 unsigned int present;
2192
2193 present = snd_hda_jack_detect(codec, 0x1b);
2194 snd_printdd("CXT5066: external microphone present=%d\n", present);
2195 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2196 present ? 1 : 0);
2197}
2198
2199
David Henningsson048e78a2010-09-02 08:35:47 +02002200/* toggle input of built-in digital mic and mic jack appropriately */
2201static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2202{
2203 unsigned int present;
2204
2205 present = snd_hda_jack_detect(codec, 0x1b);
2206 snd_printdd("CXT5066: external microphone present=%d\n", present);
2207 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2208 present ? 1 : 3);
2209}
2210
2211
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002212/* toggle input of built-in digital mic and mic jack appropriately
2213 order is: external mic -> dock mic -> interal mic */
2214static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2215{
2216 unsigned int ext_present, dock_present;
2217
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002218 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002219 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2220 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2221 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2222 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2224 {}
2225 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002226 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002227 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2228 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2229 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2230 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2231 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2232 {}
2233 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002234 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002235 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2236 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2237 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2239 {}
2240 };
2241
2242 ext_present = snd_hda_jack_detect(codec, 0x1b);
2243 dock_present = snd_hda_jack_detect(codec, 0x1a);
2244 if (ext_present) {
2245 snd_printdd("CXT5066: external microphone detected\n");
2246 snd_hda_sequence_write(codec, ext_mic_present);
2247 } else if (dock_present) {
2248 snd_printdd("CXT5066: dock microphone detected\n");
2249 snd_hda_sequence_write(codec, dock_mic_present);
2250 } else {
2251 snd_printdd("CXT5066: external microphone absent\n");
2252 snd_hda_sequence_write(codec, ext_mic_absent);
2253 }
2254}
2255
Daniel Drake0fb67e92009-07-16 14:46:57 +01002256/* mute internal speaker if HP is plugged */
2257static void cxt5066_hp_automute(struct hda_codec *codec)
2258{
2259 struct conexant_spec *spec = codec->spec;
2260 unsigned int portA, portD;
2261
2262 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002263 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002264
2265 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002266 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002267
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002268 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2269 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002270 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2271 portA, portD, spec->hp_present);
2272 cxt5066_update_speaker(codec);
2273}
2274
David Henningsson02b6b5b2011-01-21 13:27:39 +01002275/* Dispatch the right mic autoswitch function */
2276static void cxt5066_automic(struct hda_codec *codec)
2277{
2278 struct conexant_spec *spec = codec->spec;
2279
2280 if (spec->dell_vostro)
2281 cxt5066_vostro_automic(codec);
2282 else if (spec->ideapad)
2283 cxt5066_ideapad_automic(codec);
2284 else if (spec->thinkpad)
2285 cxt5066_thinkpad_automic(codec);
2286 else if (spec->hp_laptop)
2287 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002288 else if (spec->asus)
2289 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002290}
2291
Daniel Drake0fb67e92009-07-16 14:46:57 +01002292/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002293static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002294{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002295 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002296 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2297 switch (res >> 26) {
2298 case CONEXANT_HP_EVENT:
2299 cxt5066_hp_automute(codec);
2300 break;
2301 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002302 /* ignore mic events in DC mode; we're always using the jack */
2303 if (!spec->dc_enable)
2304 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002305 break;
2306 }
2307}
2308
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002309/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002310static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002311{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002312 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002313 switch (res >> 26) {
2314 case CONEXANT_HP_EVENT:
2315 cxt5066_hp_automute(codec);
2316 break;
2317 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002318 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002319 break;
2320 }
2321}
2322
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002323
Daniel Drake0fb67e92009-07-16 14:46:57 +01002324static const struct hda_input_mux cxt5066_analog_mic_boost = {
2325 .num_items = 5,
2326 .items = {
2327 { "0dB", 0 },
2328 { "10dB", 1 },
2329 { "20dB", 2 },
2330 { "30dB", 3 },
2331 { "40dB", 4 },
2332 },
2333};
2334
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002335static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002336{
2337 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002338 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002339 AC_VERB_SET_AMP_GAIN_MUTE,
2340 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2341 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002342 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002343 /* adjust the internal mic as well...it is not through 0x17 */
2344 snd_hda_codec_write_cache(codec, 0x23, 0,
2345 AC_VERB_SET_AMP_GAIN_MUTE,
2346 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2347 cxt5066_analog_mic_boost.
2348 items[spec->mic_boost].index);
2349 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002350}
2351
Daniel Drake0fb67e92009-07-16 14:46:57 +01002352static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2353 struct snd_ctl_elem_info *uinfo)
2354{
2355 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2356}
2357
2358static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2359 struct snd_ctl_elem_value *ucontrol)
2360{
2361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002362 struct conexant_spec *spec = codec->spec;
2363 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002364 return 0;
2365}
2366
2367static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2368 struct snd_ctl_elem_value *ucontrol)
2369{
2370 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002371 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002372 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2373 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002374 idx = ucontrol->value.enumerated.item[0];
2375 if (idx >= imux->num_items)
2376 idx = imux->num_items - 1;
2377
Daniel Drakec4cfe662010-01-07 13:47:04 +01002378 spec->mic_boost = idx;
2379 if (!spec->dc_enable)
2380 cxt5066_set_mic_boost(codec);
2381 return 1;
2382}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002383
Daniel Drakec4cfe662010-01-07 13:47:04 +01002384static void cxt5066_enable_dc(struct hda_codec *codec)
2385{
2386 const struct hda_verb enable_dc_mode[] = {
2387 /* disable gain */
2388 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2389
2390 /* switch to DC input */
2391 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2392 {}
2393 };
2394
2395 /* configure as input source */
2396 snd_hda_sequence_write(codec, enable_dc_mode);
2397 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2398}
2399
2400static void cxt5066_disable_dc(struct hda_codec *codec)
2401{
2402 /* reconfigure input source */
2403 cxt5066_set_mic_boost(codec);
2404 /* automic also selects the right mic if we're recording */
2405 cxt5066_olpc_automic(codec);
2406}
2407
2408static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2409 struct snd_ctl_elem_value *ucontrol)
2410{
2411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2412 struct conexant_spec *spec = codec->spec;
2413 ucontrol->value.integer.value[0] = spec->dc_enable;
2414 return 0;
2415}
2416
2417static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2418 struct snd_ctl_elem_value *ucontrol)
2419{
2420 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2421 struct conexant_spec *spec = codec->spec;
2422 int dc_enable = !!ucontrol->value.integer.value[0];
2423
2424 if (dc_enable == spec->dc_enable)
2425 return 0;
2426
2427 spec->dc_enable = dc_enable;
2428 if (dc_enable)
2429 cxt5066_enable_dc(codec);
2430 else
2431 cxt5066_disable_dc(codec);
2432
2433 return 1;
2434}
2435
2436static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2437 struct snd_ctl_elem_info *uinfo)
2438{
2439 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2440}
2441
2442static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2443 struct snd_ctl_elem_value *ucontrol)
2444{
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2446 struct conexant_spec *spec = codec->spec;
2447 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2448 return 0;
2449}
2450
2451static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2452 struct snd_ctl_elem_value *ucontrol)
2453{
2454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2455 struct conexant_spec *spec = codec->spec;
2456 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2457 unsigned int idx;
2458
2459 idx = ucontrol->value.enumerated.item[0];
2460 if (idx >= imux->num_items)
2461 idx = imux->num_items - 1;
2462
2463 spec->dc_input_bias = idx;
2464 if (spec->dc_enable)
2465 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002466 return 1;
2467}
2468
Daniel Drake75f89912010-01-07 13:46:25 +01002469static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2470{
2471 struct conexant_spec *spec = codec->spec;
2472 /* mark as recording and configure the microphone widget so that the
2473 * recording LED comes on. */
2474 spec->recording = 1;
2475 cxt5066_olpc_select_mic(codec);
2476}
2477
2478static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2479{
2480 struct conexant_spec *spec = codec->spec;
2481 const struct hda_verb disable_mics[] = {
2482 /* disable external mic, port B */
2483 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2484
2485 /* disble internal mic, port C */
2486 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002487
2488 /* disable DC capture, port F */
2489 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002490 {},
2491 };
2492
2493 snd_hda_sequence_write(codec, disable_mics);
2494 spec->recording = 0;
2495}
2496
Andy Robinsonf6a24912011-01-24 10:12:37 -05002497static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002498 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002499 int num_pins)
2500{
2501 struct conexant_spec *spec = codec->spec;
2502 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2503 int i;
2504
2505 for (i = 0; i < num_pins; i++, dig_pins++) {
2506 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2507 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2508 continue;
2509 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2510 continue;
2511 if (spec->slave_dig_outs[0])
2512 nid_loc++;
2513 else
2514 nid_loc = spec->slave_dig_outs;
2515 }
2516}
2517
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002518static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002519 .num_items = 4,
2520 .items = {
2521 { "Mic B", 0 },
2522 { "Mic C", 1 },
2523 { "Mic E", 2 },
2524 { "Mic F", 3 },
2525 },
2526};
2527
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002528static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002529 .ops = &snd_hda_bind_vol,
2530 .values = {
2531 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2532 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2533 0
2534 },
2535};
2536
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002537static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002538 .ops = &snd_hda_bind_sw,
2539 .values = {
2540 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2541 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2542 0
2543 },
2544};
2545
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002546static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002547 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2548 {}
2549};
2550
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002551static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002552 {
2553 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2554 .name = "Master Playback Volume",
2555 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2556 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2557 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002558 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002559 .info = snd_hda_mixer_amp_volume_info,
2560 .get = snd_hda_mixer_amp_volume_get,
2561 .put = snd_hda_mixer_amp_volume_put,
2562 .tlv = { .c = snd_hda_mixer_amp_tlv },
2563 /* offset by 28 volume steps to limit minimum gain to -46dB */
2564 .private_value =
2565 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2566 },
2567 {}
2568};
2569
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002570static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002571 {
2572 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2573 .name = "DC Mode Enable Switch",
2574 .info = snd_ctl_boolean_mono_info,
2575 .get = cxt5066_olpc_dc_get,
2576 .put = cxt5066_olpc_dc_put,
2577 },
2578 {
2579 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2580 .name = "DC Input Bias Enum",
2581 .info = cxt5066_olpc_dc_bias_enum_info,
2582 .get = cxt5066_olpc_dc_bias_enum_get,
2583 .put = cxt5066_olpc_dc_bias_enum_put,
2584 },
2585 {}
2586};
2587
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002588static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002589 {
2590 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2591 .name = "Master Playback Switch",
2592 .info = cxt_eapd_info,
2593 .get = cxt_eapd_get,
2594 .put = cxt5066_hp_master_sw_put,
2595 .private_value = 0x1d,
2596 },
2597
2598 {
2599 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002600 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002601 .info = cxt5066_mic_boost_mux_enum_info,
2602 .get = cxt5066_mic_boost_mux_enum_get,
2603 .put = cxt5066_mic_boost_mux_enum_put,
2604 },
2605
2606 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2607 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2608 {}
2609};
2610
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002611static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002612 {
2613 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002614 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002615 .info = cxt5066_mic_boost_mux_enum_info,
2616 .get = cxt5066_mic_boost_mux_enum_get,
2617 .put = cxt5066_mic_boost_mux_enum_put,
2618 .private_value = 0x23 | 0x100,
2619 },
2620 {}
2621};
2622
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002623static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002624 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2625 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2626 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2627 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2628
2629 /* Speakers */
2630 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2631 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2632
2633 /* HP, Amp */
2634 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2635 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2636
2637 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2638 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2639
2640 /* DAC1 */
2641 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2642
2643 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2644 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2645 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2646 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2647 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2648 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2649
2650 /* no digital microphone support yet */
2651 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2652
2653 /* Audio input selector */
2654 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2655
2656 /* SPDIF route: PCM */
2657 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2658 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2659
2660 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2661 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2662
2663 /* EAPD */
2664 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2665
2666 /* not handling these yet */
2667 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2668 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2669 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2670 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2671 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2672 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2673 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2674 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2675 { } /* end */
2676};
2677
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002678static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002679 /* Port A: headphones */
2680 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2681 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2682
2683 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002684 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002685
2686 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002687 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002688
2689 /* Port D: unused */
2690 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2691
2692 /* Port E: unused, but has primary EAPD */
2693 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2694 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2695
Daniel Drakec4cfe662010-01-07 13:47:04 +01002696 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002697 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2698
2699 /* Port G: internal speakers */
2700 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2701 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2702
2703 /* DAC1 */
2704 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2705
2706 /* DAC2: unused */
2707 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2708
2709 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2710 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2711 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2712 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2713 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2714 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2715 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2716 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2717 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2718 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2719 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2720 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2721
2722 /* Disable digital microphone port */
2723 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2724
2725 /* Audio input selectors */
2726 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2727 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2728
2729 /* Disable SPDIF */
2730 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2731 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2732
2733 /* enable unsolicited events for Port A and B */
2734 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2735 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2736 { } /* end */
2737};
2738
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002739static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002740 /* Port A: headphones */
2741 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2742 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2743
2744 /* Port B: external microphone */
2745 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2746
2747 /* Port C: unused */
2748 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2749
2750 /* Port D: unused */
2751 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2752
2753 /* Port E: unused, but has primary EAPD */
2754 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2755 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2756
2757 /* Port F: unused */
2758 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2759
2760 /* Port G: internal speakers */
2761 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2762 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2763
2764 /* DAC1 */
2765 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2766
2767 /* DAC2: unused */
2768 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2769
2770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2773 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2774 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2775 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2776 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2777 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2778 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2779 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2780 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2782
2783 /* Digital microphone port */
2784 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2785
2786 /* Audio input selectors */
2787 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2788 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2789
2790 /* Disable SPDIF */
2791 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2792 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2793
2794 /* enable unsolicited events for Port A and B */
2795 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2796 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2797 { } /* end */
2798};
2799
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002800static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002801 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2802 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2803 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2804 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2805
2806 /* Speakers */
2807 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2808 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2809
2810 /* HP, Amp */
2811 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2812 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2813
2814 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2815 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2816
2817 /* DAC1 */
2818 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2819
2820 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2821 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2822 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2825 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2826 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2827
2828 /* Audio input selector */
2829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2830 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2831
2832 /* SPDIF route: PCM */
2833 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2834 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2835
2836 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2837 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2838
2839 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002840 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002841
2842 /* EAPD */
2843 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2844
2845 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2846 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2847 { } /* end */
2848};
2849
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002850static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002851 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2852 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2853
2854 /* Port G: internal speakers */
2855 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2856 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2857
2858 /* Port A: HP, Amp */
2859 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2860 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2861
2862 /* Port B: Mic Dock */
2863 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2864
2865 /* Port C: Mic */
2866 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2867
2868 /* Port D: HP Dock, Amp */
2869 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2870 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2871
2872 /* DAC1 */
2873 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2874
2875 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2877 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2880 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2881 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2882
2883 /* Audio input selector */
2884 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2885 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2886
2887 /* SPDIF route: PCM */
2888 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2889 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2890
2891 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2892 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2893
2894 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002895 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002896
2897 /* EAPD */
2898 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2899
2900 /* enable unsolicited events for Port A, B, C and D */
2901 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2903 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2904 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2905 { } /* end */
2906};
2907
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002908static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002909 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910 { } /* end */
2911};
2912
David Henningsson048e78a2010-09-02 08:35:47 +02002913
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002914static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002915 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2916 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2917 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2918 { } /* end */
2919};
2920
Daniel Drake0fb67e92009-07-16 14:46:57 +01002921/* initialize jack-sensing, too */
2922static int cxt5066_init(struct hda_codec *codec)
2923{
2924 snd_printdd("CXT5066: init\n");
2925 conexant_init(codec);
2926 if (codec->patch_ops.unsol_event) {
2927 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002928 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002929 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002930 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002931 return 0;
2932}
2933
Daniel Drake75f89912010-01-07 13:46:25 +01002934static int cxt5066_olpc_init(struct hda_codec *codec)
2935{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002936 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002937 snd_printdd("CXT5066: init\n");
2938 conexant_init(codec);
2939 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002940 if (!spec->dc_enable) {
2941 cxt5066_set_mic_boost(codec);
2942 cxt5066_olpc_automic(codec);
2943 } else {
2944 cxt5066_enable_dc(codec);
2945 }
Daniel Drake75f89912010-01-07 13:46:25 +01002946 return 0;
2947}
2948
Daniel Drake0fb67e92009-07-16 14:46:57 +01002949enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002950 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002951 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2952 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002953 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002954 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002955 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002956 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002957 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002958 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002959 CXT5066_MODELS
2960};
2961
Takashi Iwaiea734962011-01-17 11:29:34 +01002962static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002963 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002964 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2965 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002966 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002967 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002968 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002969 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002970 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002971 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002972};
2973
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002974static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002975 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002976 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002977 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002978 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002979 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002980 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2981 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002982 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002983 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002984 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002985 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002986 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002987 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002988 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2989 CXT5066_LAPTOP),
2990 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002991 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002992 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002993 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson84012652011-03-31 09:36:19 +02002994 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002995 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002996 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002997 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002998 {}
2999};
3000
3001static int patch_cxt5066(struct hda_codec *codec)
3002{
3003 struct conexant_spec *spec;
3004 int board_config;
3005
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003006 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3007 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003008 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003009 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003010 if (board_config == CXT5066_AUTO)
3011 return patch_conexant_auto(codec);
3012
Daniel Drake0fb67e92009-07-16 14:46:57 +01003013 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3014 if (!spec)
3015 return -ENOMEM;
3016 codec->spec = spec;
3017
3018 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003019 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003020
3021 spec->dell_automute = 0;
3022 spec->multiout.max_channels = 2;
3023 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3024 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003025 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3026 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003027 spec->num_adc_nids = 1;
3028 spec->adc_nids = cxt5066_adc_nids;
3029 spec->capsrc_nids = cxt5066_capsrc_nids;
3030 spec->input_mux = &cxt5066_capture_source;
3031
3032 spec->port_d_mode = PIN_HP;
3033
3034 spec->num_init_verbs = 1;
3035 spec->init_verbs[0] = cxt5066_init_verbs;
3036 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3037 spec->channel_mode = cxt5066_modes;
3038 spec->cur_adc = 0;
3039 spec->cur_adc_idx = 0;
3040
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003041 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3042
Daniel Drake0fb67e92009-07-16 14:46:57 +01003043 switch (board_config) {
3044 default:
3045 case CXT5066_LAPTOP:
3046 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3047 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3048 break;
3049 case CXT5066_DELL_LAPTOP:
3050 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3051 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3052
3053 spec->port_d_mode = PIN_OUT;
3054 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3055 spec->num_init_verbs++;
3056 spec->dell_automute = 1;
3057 break;
David Henningssona1d69062011-01-21 13:33:28 +01003058 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003059 case CXT5066_HP_LAPTOP:
3060 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003061 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003062 spec->init_verbs[spec->num_init_verbs] =
3063 cxt5066_init_verbs_hp_laptop;
3064 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003065 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3066 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003067 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3068 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3069 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003070 if (board_config == CXT5066_HP_LAPTOP)
3071 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003072 /* input source automatically selected */
3073 spec->input_mux = NULL;
3074 spec->port_d_mode = 0;
3075 spec->mic_boost = 3; /* default 30dB gain */
3076 break;
3077
Daniel Drake0fb67e92009-07-16 14:46:57 +01003078 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003079 codec->patch_ops.init = cxt5066_olpc_init;
3080 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003081 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3082 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003083 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003084 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3085 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003086 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003087
3088 /* no S/PDIF out */
3089 spec->multiout.dig_out_nid = 0;
3090
3091 /* input source automatically selected */
3092 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003093
3094 /* our capture hooks which allow us to turn on the microphone LED
3095 * at the right time */
3096 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3097 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003098 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003099 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003100 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003101 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003102 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3103 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3104 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003105 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003106 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003107 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003108 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003109
3110 /* no S/PDIF out */
3111 spec->multiout.dig_out_nid = 0;
3112
3113 /* input source automatically selected */
3114 spec->input_mux = NULL;
3115 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003116 case CXT5066_IDEAPAD:
3117 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003118 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003119 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3120 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3121 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3122 spec->port_d_mode = 0;
3123 spec->ideapad = 1;
3124 spec->mic_boost = 2; /* default 20dB gain */
3125
3126 /* no S/PDIF out */
3127 spec->multiout.dig_out_nid = 0;
3128
3129 /* input source automatically selected */
3130 spec->input_mux = NULL;
3131 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003132 case CXT5066_THINKPAD:
3133 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003134 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003135 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3136 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3137 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3138 spec->thinkpad = 1;
3139 spec->port_d_mode = PIN_OUT;
3140 spec->mic_boost = 2; /* default 20dB gain */
3141
3142 /* no S/PDIF out */
3143 spec->multiout.dig_out_nid = 0;
3144
3145 /* input source automatically selected */
3146 spec->input_mux = NULL;
3147 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003148 }
3149
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003150 if (spec->beep_amp)
3151 snd_hda_attach_beep_device(codec, spec->beep_amp);
3152
Daniel Drake0fb67e92009-07-16 14:46:57 +01003153 return 0;
3154}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003155
3156/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003157 * Automatic parser for CX20641 & co
3158 */
3159
Takashi Iwai6764bce2011-05-13 16:52:25 +02003160static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3161 struct hda_codec *codec,
3162 unsigned int stream_tag,
3163 unsigned int format,
3164 struct snd_pcm_substream *substream)
3165{
3166 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003167 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003168 if (spec->adc_switching) {
3169 spec->cur_adc = adc;
3170 spec->cur_adc_stream_tag = stream_tag;
3171 spec->cur_adc_format = format;
3172 }
3173 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3174 return 0;
3175}
3176
3177static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3178 struct hda_codec *codec,
3179 struct snd_pcm_substream *substream)
3180{
3181 struct conexant_spec *spec = codec->spec;
3182 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3183 spec->cur_adc = 0;
3184 return 0;
3185}
3186
3187static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3188 .substreams = 1,
3189 .channels_min = 2,
3190 .channels_max = 2,
3191 .nid = 0, /* fill later */
3192 .ops = {
3193 .prepare = cx_auto_capture_pcm_prepare,
3194 .cleanup = cx_auto_capture_pcm_cleanup
3195 },
3196};
3197
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003198static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003199
Takashi Iwai8d087c72011-06-28 12:45:47 +02003200#define get_connection_index(codec, mux, nid)\
3201 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003202
3203/* get an unassigned DAC from the given list.
3204 * Return the nid if found and reduce the DAC list, or return zero if
3205 * not found
3206 */
3207static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3208 hda_nid_t *dacs, int *num_dacs)
3209{
3210 int i, nums = *num_dacs;
3211 hda_nid_t ret = 0;
3212
3213 for (i = 0; i < nums; i++) {
3214 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3215 ret = dacs[i];
3216 break;
3217 }
3218 }
3219 if (!ret)
3220 return 0;
3221 if (--nums > 0)
3222 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3223 *num_dacs = nums;
3224 return ret;
3225}
3226
3227#define MAX_AUTO_DACS 5
3228
Takashi Iwai1f015f52011-08-23 14:57:08 +02003229#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3230
Takashi Iwaif2e57312010-09-15 10:07:08 +02003231/* fill analog DAC list from the widget tree */
3232static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3233{
3234 hda_nid_t nid, end_nid;
3235 int nums = 0;
3236
3237 end_nid = codec->start_nid + codec->num_nodes;
3238 for (nid = codec->start_nid; nid < end_nid; nid++) {
3239 unsigned int wcaps = get_wcaps(codec, nid);
3240 unsigned int type = get_wcaps_type(wcaps);
3241 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3242 dacs[nums++] = nid;
3243 if (nums >= MAX_AUTO_DACS)
3244 break;
3245 }
3246 }
3247 return nums;
3248}
3249
3250/* fill pin_dac_pair list from the pin and dac list */
3251static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3252 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003253 struct pin_dac_pair *filled, int nums,
3254 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003255{
David Henningsson468c5452011-08-25 13:16:02 +02003256 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003257
David Henningsson468c5452011-08-25 13:16:02 +02003258 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003259 filled[nums].pin = pins[i];
3260 filled[nums].type = type;
3261 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003262 if (filled[nums].dac)
3263 continue;
3264 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3265 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3266 continue;
3267 }
3268 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003269 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003270 continue;
3271 }
3272 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003273 }
3274 return nums;
3275}
3276
3277/* parse analog output paths */
3278static void cx_auto_parse_output(struct hda_codec *codec)
3279{
3280 struct conexant_spec *spec = codec->spec;
3281 struct auto_pin_cfg *cfg = &spec->autocfg;
3282 hda_nid_t dacs[MAX_AUTO_DACS];
3283 int i, j, nums, rest;
3284
3285 rest = fill_cx_auto_dacs(codec, dacs);
3286 /* parse all analog output pins */
3287 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003288 dacs, &rest, spec->dac_info, 0,
3289 AUTO_PIN_LINE_OUT);
3290 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3291 dacs, &rest, spec->dac_info, nums,
3292 AUTO_PIN_HP_OUT);
3293 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3294 dacs, &rest, spec->dac_info, nums,
3295 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003296 spec->dac_info_filled = nums;
3297 /* fill multiout struct */
3298 for (i = 0; i < nums; i++) {
3299 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003300 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003301 continue;
3302 switch (spec->dac_info[i].type) {
3303 case AUTO_PIN_LINE_OUT:
3304 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3305 spec->multiout.num_dacs++;
3306 break;
3307 case AUTO_PIN_HP_OUT:
3308 case AUTO_PIN_SPEAKER_OUT:
3309 if (!spec->multiout.hp_nid) {
3310 spec->multiout.hp_nid = dac;
3311 break;
3312 }
3313 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3314 if (!spec->multiout.extra_out_nid[j]) {
3315 spec->multiout.extra_out_nid[j] = dac;
3316 break;
3317 }
3318 break;
3319 }
3320 }
3321 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003322 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003323
Takashi Iwai03697e22011-05-17 09:53:31 +02003324 for (i = 0; i < cfg->hp_outs; i++) {
3325 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3326 spec->auto_mute = 1;
3327 break;
3328 }
3329 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003330 if (spec->auto_mute &&
3331 cfg->line_out_pins[0] &&
3332 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003333 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3334 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3335 for (i = 0; i < cfg->line_outs; i++) {
3336 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3337 spec->detect_line = 1;
3338 break;
3339 }
3340 }
3341 spec->automute_lines = spec->detect_line;
3342 }
3343
Takashi Iwaif2e57312010-09-15 10:07:08 +02003344 spec->vmaster_nid = spec->private_dac_nids[0];
3345}
3346
Takashi Iwaida339862011-05-13 16:24:15 +02003347static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3348 hda_nid_t *pins, bool on);
3349
Takashi Iwai03697e22011-05-17 09:53:31 +02003350static void do_automute(struct hda_codec *codec, int num_pins,
3351 hda_nid_t *pins, bool on)
3352{
Takashi Iwai254f2962011-10-14 15:22:34 +02003353 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003354 int i;
3355 for (i = 0; i < num_pins; i++)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003356 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003357 if (spec->pin_eapd_ctrls)
3358 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003359}
3360
3361static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3362{
3363 int i, present = 0;
3364
3365 for (i = 0; i < num_pins; i++) {
3366 hda_nid_t nid = pins[i];
3367 if (!nid || !is_jack_detectable(codec, nid))
3368 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003369 present |= snd_hda_jack_detect(codec, nid);
3370 }
3371 return present;
3372}
3373
Takashi Iwaif2e57312010-09-15 10:07:08 +02003374/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003375static void cx_auto_update_speakers(struct hda_codec *codec)
3376{
3377 struct conexant_spec *spec = codec->spec;
3378 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003379 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003380
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003381 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003382 if (spec->pin_eapd_ctrls) {
3383 if (spec->auto_mute)
3384 on = spec->hp_present;
3385 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3386 }
3387
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003388 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3389 if (spec->auto_mute)
3390 on = !(spec->hp_present ||
3391 (spec->detect_line && spec->line_present));
3392 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003393
3394 /* toggle line-out mutes if needed, too */
3395 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3396 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3397 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3398 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003399 if (spec->auto_mute) {
3400 /* mute LO in auto-mode when HP jack is present */
3401 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3402 spec->automute_lines)
3403 on = !spec->hp_present;
3404 else
3405 on = 1;
3406 }
3407 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003408}
3409
David Henningsson29adc4b2012-09-25 11:31:00 +02003410static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003411{
3412 struct conexant_spec *spec = codec->spec;
3413 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003414
3415 if (!spec->auto_mute)
3416 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003417 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3418 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003419}
3420
David Henningsson29adc4b2012-09-25 11:31:00 +02003421static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwai03697e22011-05-17 09:53:31 +02003422{
3423 struct conexant_spec *spec = codec->spec;
3424 struct auto_pin_cfg *cfg = &spec->autocfg;
3425
3426 if (!spec->auto_mute || !spec->detect_line)
3427 return;
3428 spec->line_present = detect_jacks(codec, cfg->line_outs,
3429 cfg->line_out_pins);
3430 cx_auto_update_speakers(codec);
3431}
3432
3433static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3434 struct snd_ctl_elem_info *uinfo)
3435{
3436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3437 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003438 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003439 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003440 };
Takashi Iwai03697e22011-05-17 09:53:31 +02003441
Takashi Iwaidda415d2012-11-30 18:34:38 +01003442 if (spec->automute_hp_lo)
3443 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3444 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai03697e22011-05-17 09:53:31 +02003445}
3446
3447static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3448 struct snd_ctl_elem_value *ucontrol)
3449{
3450 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3451 struct conexant_spec *spec = codec->spec;
3452 unsigned int val;
3453 if (!spec->auto_mute)
3454 val = 0;
3455 else if (!spec->automute_lines)
3456 val = 1;
3457 else
3458 val = 2;
3459 ucontrol->value.enumerated.item[0] = val;
3460 return 0;
3461}
3462
3463static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3464 struct snd_ctl_elem_value *ucontrol)
3465{
3466 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3467 struct conexant_spec *spec = codec->spec;
3468
3469 switch (ucontrol->value.enumerated.item[0]) {
3470 case 0:
3471 if (!spec->auto_mute)
3472 return 0;
3473 spec->auto_mute = 0;
3474 break;
3475 case 1:
3476 if (spec->auto_mute && !spec->automute_lines)
3477 return 0;
3478 spec->auto_mute = 1;
3479 spec->automute_lines = 0;
3480 break;
3481 case 2:
3482 if (!spec->automute_hp_lo)
3483 return -EINVAL;
3484 if (spec->auto_mute && spec->automute_lines)
3485 return 0;
3486 spec->auto_mute = 1;
3487 spec->automute_lines = 1;
3488 break;
3489 default:
3490 return -EINVAL;
3491 }
3492 cx_auto_update_speakers(codec);
3493 return 1;
3494}
3495
3496static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3497 {
3498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3499 .name = "Auto-Mute Mode",
3500 .info = cx_automute_mode_info,
3501 .get = cx_automute_mode_get,
3502 .put = cx_automute_mode_put,
3503 },
3504 { }
3505};
3506
Takashi Iwai6764bce2011-05-13 16:52:25 +02003507static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3508 struct snd_ctl_elem_info *uinfo)
3509{
3510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3511 struct conexant_spec *spec = codec->spec;
3512
3513 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3514}
3515
3516static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3517 struct snd_ctl_elem_value *ucontrol)
3518{
3519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3520 struct conexant_spec *spec = codec->spec;
3521
3522 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3523 return 0;
3524}
3525
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003526/* look for the route the given pin from mux and return the index;
3527 * if do_select is set, actually select the route.
3528 */
3529static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003530 hda_nid_t pin, hda_nid_t *srcp,
3531 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003532{
David Henningsson739572a2012-09-20 15:41:21 +02003533 struct conexant_spec *spec = codec->spec;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003534 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
David Henningsson739572a2012-09-20 15:41:21 +02003535 int startidx, i, nums;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003536
Takashi Iwaicf27f292011-05-16 11:33:02 +02003537 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3538 case AC_WID_AUD_IN:
3539 case AC_WID_AUD_SEL:
3540 case AC_WID_AUD_MIX:
3541 break;
3542 default:
3543 return -1;
3544 }
3545
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003546 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3547 for (i = 0; i < nums; i++)
3548 if (conn[i] == pin) {
3549 if (do_select)
3550 snd_hda_codec_write(codec, mux, 0,
3551 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003552 if (srcp)
3553 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003554 return i;
3555 }
3556 depth++;
3557 if (depth == 2)
3558 return -1;
David Henningsson739572a2012-09-20 15:41:21 +02003559
3560 /* Try to rotate around connections to avoid one boost controlling
3561 another input path as well */
3562 startidx = 0;
3563 for (i = 0; i < spec->private_imux.num_items; i++)
3564 if (spec->imux_info[i].pin == pin) {
3565 startidx = i;
3566 break;
3567 }
3568
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003569 for (i = 0; i < nums; i++) {
David Henningsson739572a2012-09-20 15:41:21 +02003570 int j = (i + startidx) % nums;
3571 int ret = __select_input_connection(codec, conn[j], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003572 do_select, depth);
3573 if (ret >= 0) {
3574 if (do_select)
3575 snd_hda_codec_write(codec, mux, 0,
David Henningsson739572a2012-09-20 15:41:21 +02003576 AC_VERB_SET_CONNECT_SEL, j);
3577 return j;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003578 }
3579 }
3580 return -1;
3581}
3582
3583static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3584 hda_nid_t pin)
3585{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003586 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003587}
3588
3589static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3590 hda_nid_t pin)
3591{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003592 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003593}
3594
Takashi Iwai6764bce2011-05-13 16:52:25 +02003595static int cx_auto_mux_enum_update(struct hda_codec *codec,
3596 const struct hda_input_mux *imux,
3597 unsigned int idx)
3598{
3599 struct conexant_spec *spec = codec->spec;
3600 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003601 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003602
3603 if (!imux->num_items)
3604 return 0;
3605 if (idx >= imux->num_items)
3606 idx = imux->num_items - 1;
3607 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003608 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003609 adc = spec->imux_info[idx].adc;
3610 select_input_connection(codec, spec->imux_info[idx].adc,
3611 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003612 if (spec->cur_adc && spec->cur_adc != adc) {
3613 /* stream is running, let's swap the current ADC */
3614 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3615 spec->cur_adc = adc;
3616 snd_hda_codec_setup_stream(codec, adc,
3617 spec->cur_adc_stream_tag, 0,
3618 spec->cur_adc_format);
3619 }
3620 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003621 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003622}
3623
3624static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3625 struct snd_ctl_elem_value *ucontrol)
3626{
3627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3628 struct conexant_spec *spec = codec->spec;
3629
3630 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3631 ucontrol->value.enumerated.item[0]);
3632}
3633
3634static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3635 {
3636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3637 .name = "Capture Source",
3638 .info = cx_auto_mux_enum_info,
3639 .get = cx_auto_mux_enum_get,
3640 .put = cx_auto_mux_enum_put
3641 },
3642 {}
3643};
3644
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003645static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3646{
3647 struct conexant_spec *spec = codec->spec;
3648 if (idx < 0)
3649 return false;
3650 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3651 return false;
3652 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3653 return true;
3654}
3655
Takashi Iwaif2e57312010-09-15 10:07:08 +02003656/* automatic switch internal and external mic */
David Henningsson29adc4b2012-09-25 11:31:00 +02003657static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003658{
3659 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003660
3661 if (!spec->auto_mic)
3662 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003663 if (!select_automic(codec, spec->auto_mic_ext, true))
3664 if (!select_automic(codec, spec->auto_mic_dock, true))
3665 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003666}
3667
Takashi Iwaif2e57312010-09-15 10:07:08 +02003668/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003669 * auto-mic is enabled only when one int-mic and one ext- and/or
3670 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003671 */
3672static void cx_auto_check_auto_mic(struct hda_codec *codec)
3673{
3674 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003675 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3676 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003677
Takashi Iwai506a4192011-05-23 20:07:15 +02003678 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003679 pset[i] = -1;
3680 for (i = 0; i < spec->private_imux.num_items; i++) {
3681 hda_nid_t pin = spec->imux_info[i].pin;
3682 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003683 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003684 attr = snd_hda_get_input_pin_attr(def_conf);
3685 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003686 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003687 if (attr > INPUT_PIN_ATTR_NORMAL)
3688 attr = INPUT_PIN_ATTR_NORMAL;
3689 if (attr != INPUT_PIN_ATTR_INT &&
3690 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003691 return; /* non-detectable pin */
3692 type = get_defcfg_device(def_conf);
3693 if (type != AC_JACK_MIC_IN &&
3694 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3695 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003696 if (pset[attr] >= 0)
3697 return; /* already occupied */
3698 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003699 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003700 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3701 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3702 return; /* no input to switch*/
3703 spec->auto_mic = 1;
3704 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3705 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3706 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003707}
3708
3709static void cx_auto_parse_input(struct hda_codec *codec)
3710{
3711 struct conexant_spec *spec = codec->spec;
3712 struct auto_pin_cfg *cfg = &spec->autocfg;
3713 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003714 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003715
3716 imux = &spec->private_imux;
3717 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003718 for (j = 0; j < spec->num_adc_nids; j++) {
3719 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003720 int idx = get_input_connection(codec, adc,
3721 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003722 if (idx >= 0) {
3723 const char *label;
3724 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003725 spec->imux_info[imux->num_items].index = i;
3726 spec->imux_info[imux->num_items].boost = 0;
3727 spec->imux_info[imux->num_items].adc = adc;
3728 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003729 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003730 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003731 break;
3732 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003733 }
3734 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003735 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003736 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003737 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003738 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003739 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003740 spec->adc_switching = 1;
3741 break;
3742 }
3743 }
3744 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003745}
3746
3747/* get digital-input audio widget corresponding to the given pin */
3748static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3749{
3750 hda_nid_t nid, end_nid;
3751
3752 end_nid = codec->start_nid + codec->num_nodes;
3753 for (nid = codec->start_nid; nid < end_nid; nid++) {
3754 unsigned int wcaps = get_wcaps(codec, nid);
3755 unsigned int type = get_wcaps_type(wcaps);
3756 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3757 if (get_connection_index(codec, nid, pin) >= 0)
3758 return nid;
3759 }
3760 }
3761 return 0;
3762}
3763
3764static void cx_auto_parse_digital(struct hda_codec *codec)
3765{
3766 struct conexant_spec *spec = codec->spec;
3767 struct auto_pin_cfg *cfg = &spec->autocfg;
3768 hda_nid_t nid;
3769
3770 if (cfg->dig_outs &&
3771 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3772 spec->multiout.dig_out_nid = nid;
3773 if (cfg->dig_in_pin)
3774 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3775}
3776
3777#ifdef CONFIG_SND_HDA_INPUT_BEEP
3778static void cx_auto_parse_beep(struct hda_codec *codec)
3779{
3780 struct conexant_spec *spec = codec->spec;
3781 hda_nid_t nid, end_nid;
3782
3783 end_nid = codec->start_nid + codec->num_nodes;
3784 for (nid = codec->start_nid; nid < end_nid; nid++)
3785 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3786 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3787 break;
3788 }
3789}
3790#else
3791#define cx_auto_parse_beep(codec)
3792#endif
3793
Takashi Iwai254f2962011-10-14 15:22:34 +02003794/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003795static void cx_auto_parse_eapd(struct hda_codec *codec)
3796{
3797 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003798 hda_nid_t nid, end_nid;
3799
3800 end_nid = codec->start_nid + codec->num_nodes;
3801 for (nid = codec->start_nid; nid < end_nid; nid++) {
3802 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3803 continue;
3804 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3805 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003806 spec->eapds[spec->num_eapds++] = nid;
3807 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3808 break;
3809 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003810
3811 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3812 * it's a new chip, where EAPDs are supposed to be associated to
3813 * pins, and we can control EAPD per pin.
3814 * OTOH, if only one or two EAPDs are found, it's an old chip,
3815 * thus it might control over all pins.
3816 */
3817 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003818}
3819
Takashi Iwaif2e57312010-09-15 10:07:08 +02003820static int cx_auto_parse_auto_config(struct hda_codec *codec)
3821{
3822 struct conexant_spec *spec = codec->spec;
3823 int err;
3824
3825 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3826 if (err < 0)
3827 return err;
3828
3829 cx_auto_parse_output(codec);
3830 cx_auto_parse_input(codec);
3831 cx_auto_parse_digital(codec);
3832 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003833 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003834 return 0;
3835}
3836
Takashi Iwaida339862011-05-13 16:24:15 +02003837static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3838 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003839{
3840 int i;
3841 for (i = 0; i < num_pins; i++) {
3842 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3843 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003844 AC_VERB_SET_EAPD_BTLENABLE,
3845 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003846 }
3847}
3848
3849static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3850 hda_nid_t src)
3851{
3852 int idx = get_connection_index(codec, pin, src);
3853 if (idx >= 0)
3854 snd_hda_codec_write(codec, pin, 0,
3855 AC_VERB_SET_CONNECT_SEL, idx);
3856}
3857
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003858static void mute_outputs(struct hda_codec *codec, int num_nids,
3859 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003860{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003861 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003862
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003863 for (i = 0; i < num_nids; i++) {
3864 hda_nid_t nid = nids[i];
3865 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3866 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003867 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3868 val = AMP_OUT_MUTE;
3869 else
3870 val = AMP_OUT_ZERO;
3871 snd_hda_codec_write(codec, nid, 0,
3872 AC_VERB_SET_AMP_GAIN_MUTE, val);
3873 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003874}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003875
Takashi Iwai03697e22011-05-17 09:53:31 +02003876static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003877 hda_nid_t *pins, unsigned int action,
3878 hda_jack_callback cb)
Takashi Iwai03697e22011-05-17 09:53:31 +02003879{
3880 int i;
3881 for (i = 0; i < num_pins; i++)
David Henningsson29adc4b2012-09-25 11:31:00 +02003882 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb);
Takashi Iwai03697e22011-05-17 09:53:31 +02003883}
3884
Takashi Iwai07cafff2012-02-20 12:30:59 +01003885static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3886{
3887 int i;
3888 for (i = 0; i < nums; i++)
3889 if (list[i] == nid)
3890 return true;
3891 return false;
3892}
3893
3894/* is the given NID found in any of autocfg items? */
3895static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3896{
3897 int i;
3898
3899 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3900 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3901 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3902 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3903 return true;
3904 for (i = 0; i < cfg->num_inputs; i++)
3905 if (cfg->inputs[i].pin == nid)
3906 return true;
3907 if (cfg->dig_in_pin == nid)
3908 return true;
3909 return false;
3910}
3911
3912/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3913 * invalid unsol tags by some reason
3914 */
3915static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3916{
3917 struct conexant_spec *spec = codec->spec;
3918 struct auto_pin_cfg *cfg = &spec->autocfg;
3919 int i;
3920
3921 for (i = 0; i < codec->init_pins.used; i++) {
3922 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3923 if (!found_in_autocfg(cfg, pin->nid))
3924 snd_hda_codec_write(codec, pin->nid, 0,
3925 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3926 }
3927}
3928
Takashi Iwai527c73b2012-03-12 12:38:51 +01003929/* turn on/off EAPD according to Master switch */
3930static void cx_auto_vmaster_hook(void *private_data, int enabled)
3931{
3932 struct hda_codec *codec = private_data;
3933 struct conexant_spec *spec = codec->spec;
3934
3935 if (enabled && spec->pin_eapd_ctrls) {
3936 cx_auto_update_speakers(codec);
3937 return;
3938 }
3939 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3940}
3941
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003942static void cx_auto_init_output(struct hda_codec *codec)
3943{
3944 struct conexant_spec *spec = codec->spec;
3945 struct auto_pin_cfg *cfg = &spec->autocfg;
3946 hda_nid_t nid;
3947 int i;
3948
3949 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003950 for (i = 0; i < cfg->hp_outs; i++) {
3951 unsigned int val = PIN_OUT;
3952 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3953 AC_PINCAP_HP_DRV)
3954 val |= AC_PINCTL_HP_EN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003955 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003956 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003957 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3958 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3959 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003960 for (i = 0; i < spec->dac_info_filled; i++) {
3961 nid = spec->dac_info[i].dac;
3962 if (!nid)
3963 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003964 else if (nid & DAC_SLAVE_FLAG)
3965 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003966 select_connection(codec, spec->dac_info[i].pin, nid);
3967 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003968 if (spec->auto_mute) {
3969 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003970 CONEXANT_HP_EVENT, cx_auto_hp_automute);
Takashi Iwai03697e22011-05-17 09:53:31 +02003971 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3972 cfg->hp_pins);
3973 if (spec->detect_line) {
3974 enable_unsol_pins(codec, cfg->line_outs,
3975 cfg->line_out_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003976 CONEXANT_LINE_EVENT,
3977 cx_auto_line_automute);
Takashi Iwai03697e22011-05-17 09:53:31 +02003978 spec->line_present =
3979 detect_jacks(codec, cfg->line_outs,
3980 cfg->line_out_pins);
3981 }
3982 }
3983 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02003984 /* turn on all EAPDs if no individual EAPD control is available */
3985 if (!spec->pin_eapd_ctrls)
3986 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01003987 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003988}
3989
3990static void cx_auto_init_input(struct hda_codec *codec)
3991{
3992 struct conexant_spec *spec = codec->spec;
3993 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003994 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003995
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003996 for (i = 0; i < spec->num_adc_nids; i++) {
3997 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003998 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3999 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004000 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4001 val = AMP_IN_MUTE(0);
4002 else
4003 val = AMP_IN_UNMUTE(0);
4004 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4005 val);
4006 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004007
4008 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai47408602012-04-20 13:06:53 +02004009 hda_nid_t pin = cfg->inputs[i].pin;
4010 unsigned int type = PIN_IN;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004011 if (cfg->inputs[i].type == AUTO_PIN_MIC)
Takashi Iwai47408602012-04-20 13:06:53 +02004012 type |= snd_hda_get_default_vref(codec, pin);
4013 snd_hda_set_pin_ctl(codec, pin, type);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004014 }
4015
4016 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004017 if (spec->auto_mic_ext >= 0) {
David Henningsson29adc4b2012-09-25 11:31:00 +02004018 snd_hda_jack_detect_enable_callback(codec,
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004019 cfg->inputs[spec->auto_mic_ext].pin,
David Henningsson29adc4b2012-09-25 11:31:00 +02004020 CONEXANT_MIC_EVENT, cx_auto_automic);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004021 }
4022 if (spec->auto_mic_dock >= 0) {
David Henningsson29adc4b2012-09-25 11:31:00 +02004023 snd_hda_jack_detect_enable_callback(codec,
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004024 cfg->inputs[spec->auto_mic_dock].pin,
David Henningsson29adc4b2012-09-25 11:31:00 +02004025 CONEXANT_MIC_EVENT, cx_auto_automic);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004026 }
David Henningsson29adc4b2012-09-25 11:31:00 +02004027 cx_auto_automic(codec, NULL);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004028 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004029 select_input_connection(codec, spec->imux_info[0].adc,
4030 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004031 }
4032}
4033
4034static void cx_auto_init_digital(struct hda_codec *codec)
4035{
4036 struct conexant_spec *spec = codec->spec;
4037 struct auto_pin_cfg *cfg = &spec->autocfg;
4038
4039 if (spec->multiout.dig_out_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004040 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004041 if (spec->dig_in_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004042 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004043}
4044
4045static int cx_auto_init(struct hda_codec *codec)
4046{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004047 struct conexant_spec *spec = codec->spec;
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02004048 snd_hda_gen_apply_verbs(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004049 cx_auto_init_output(codec);
4050 cx_auto_init_input(codec);
4051 cx_auto_init_digital(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004052 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004053 return 0;
4054}
4055
David Henningsson983345e2011-02-15 19:57:09 +01004056static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004057 const char *dir, int cidx,
David Henningsson18dcd302012-04-02 15:40:27 +02004058 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004059{
David Henningsson18dcd302012-04-02 15:40:27 +02004060 static char name[44];
Takashi Iwaif2e57312010-09-15 10:07:08 +02004061 static struct snd_kcontrol_new knew[] = {
4062 HDA_CODEC_VOLUME(name, 0, 0, 0),
4063 HDA_CODEC_MUTE(name, 0, 0, 0),
4064 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004065 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004066 int i, err;
4067
4068 for (i = 0; i < 2; i++) {
4069 struct snd_kcontrol *kctl;
David Henningsson18dcd302012-04-02 15:40:27 +02004070 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
David Henningsson983345e2011-02-15 19:57:09 +01004071 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004072 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4073 knew[i].index = cidx;
4074 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4075 kctl = snd_ctl_new1(&knew[i], codec);
4076 if (!kctl)
4077 return -ENOMEM;
4078 err = snd_hda_ctl_add(codec, nid, kctl);
4079 if (err < 0)
4080 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004081 if (!(query_amp_caps(codec, nid, hda_dir) &
4082 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004083 break;
4084 }
4085 return 0;
4086}
4087
David Henningsson983345e2011-02-15 19:57:09 +01004088#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
David Henningsson18dcd302012-04-02 15:40:27 +02004089 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
David Henningsson983345e2011-02-15 19:57:09 +01004090
Takashi Iwaif2e57312010-09-15 10:07:08 +02004091#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4092 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4093
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004094static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4095 hda_nid_t pin, const char *name, int idx)
4096{
4097 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004098 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4099 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4100 if (caps & AC_AMPCAP_NUM_STEPS)
4101 return cx_auto_add_pb_volume(codec, dac, name, idx);
4102 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004103 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4104 if (caps & AC_AMPCAP_NUM_STEPS)
4105 return cx_auto_add_pb_volume(codec, pin, name, idx);
4106 return 0;
4107}
4108
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004109static bool is_2_1_speaker(struct conexant_spec *spec)
4110{
4111 int i, type, num_spk = 0;
4112
4113 for (i = 0; i < spec->dac_info_filled; i++) {
4114 type = spec->dac_info[i].type;
4115 if (type == AUTO_PIN_LINE_OUT)
4116 type = spec->autocfg.line_out_type;
4117 if (type == AUTO_PIN_SPEAKER_OUT)
4118 num_spk++;
4119 }
4120 return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT);
4121}
4122
Takashi Iwaif2e57312010-09-15 10:07:08 +02004123static int cx_auto_build_output_controls(struct hda_codec *codec)
4124{
4125 struct conexant_spec *spec = codec->spec;
4126 int i, err;
4127 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004128 bool speaker_2_1;
Takashi Iwaiea734962011-01-17 11:29:34 +01004129 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004130
4131 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004132 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4133 spec->dac_info[0].pin,
4134 "Master", 0);
4135
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004136 speaker_2_1 = is_2_1_speaker(spec);
4137
Takashi Iwaif2e57312010-09-15 10:07:08 +02004138 for (i = 0; i < spec->dac_info_filled; i++) {
4139 const char *label;
4140 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004141 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004142 type = spec->dac_info[i].type;
4143 if (type == AUTO_PIN_LINE_OUT)
4144 type = spec->autocfg.line_out_type;
4145 switch (type) {
4146 case AUTO_PIN_LINE_OUT:
4147 default:
4148 label = texts[num_line++];
4149 idx = 0;
4150 break;
4151 case AUTO_PIN_HP_OUT:
4152 label = "Headphone";
4153 idx = num_hp++;
4154 break;
4155 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004156 if (speaker_2_1) {
4157 label = num_spk++ ? "Bass Speaker" : "Speaker";
4158 idx = 0;
4159 } else {
4160 label = "Speaker";
4161 idx = num_spk++;
4162 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004163 break;
4164 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004165 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004166 spec->dac_info[i].pin,
4167 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004168 if (err < 0)
4169 return err;
4170 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004171
4172 if (spec->auto_mute) {
4173 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4174 if (err < 0)
4175 return err;
4176 }
4177
Takashi Iwaif2e57312010-09-15 10:07:08 +02004178 return 0;
4179}
4180
David Henningsson18dcd302012-04-02 15:40:27 +02004181/* Returns zero if this is a normal stereo channel, and non-zero if it should
4182 be split in two independent channels.
4183 dest_label must be at least 44 characters. */
4184static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4185 char *dest_label, int nid)
4186{
4187 struct conexant_spec *spec = codec->spec;
4188 int i;
4189
4190 if (!spec->fixup_stereo_dmic)
4191 return 0;
4192
4193 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4194 int def_conf;
4195 if (spec->autocfg.inputs[i].pin != nid)
4196 continue;
4197
4198 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4199 return 0;
4200 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4201 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4202 return 0;
4203
4204 /* Finally found the inverted internal mic! */
4205 snprintf(dest_label, 44, "Inverted %s", label);
4206 return 1;
4207 }
4208 return 0;
4209}
4210
Takashi Iwai6764bce2011-05-13 16:52:25 +02004211static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4212 const char *label, const char *pfx,
4213 int cidx)
4214{
4215 struct conexant_spec *spec = codec->spec;
4216 int i;
4217
4218 for (i = 0; i < spec->num_adc_nids; i++) {
David Henningsson18dcd302012-04-02 15:40:27 +02004219 char rightch_label[44];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004220 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004221 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004222 if (idx < 0)
4223 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004224 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004225 idx = 0;
David Henningsson18dcd302012-04-02 15:40:27 +02004226
4227 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4228 /* Make two independent kcontrols for left and right */
4229 int err = cx_auto_add_volume_idx(codec, label, pfx,
4230 cidx, adc_nid, HDA_INPUT, idx, 1);
4231 if (err < 0)
4232 return err;
4233 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4234 cidx, adc_nid, HDA_INPUT, idx, 2);
4235 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004236 return cx_auto_add_volume_idx(codec, label, pfx,
David Henningsson18dcd302012-04-02 15:40:27 +02004237 cidx, adc_nid, HDA_INPUT, idx, 3);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004238 }
4239 return 0;
4240}
4241
Takashi Iwaicf27f292011-05-16 11:33:02 +02004242static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4243 const char *label, int cidx)
4244{
4245 struct conexant_spec *spec = codec->spec;
4246 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004247 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004248
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004249 nid = spec->imux_info[idx].pin;
David Henningsson18dcd302012-04-02 15:40:27 +02004250 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4251 char rightch_label[44];
4252 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4253 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4254 cidx, nid, HDA_INPUT, 0, 1);
4255 if (err < 0)
4256 return err;
4257 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4258 cidx, nid, HDA_INPUT, 0, 2);
4259 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004260 return cx_auto_add_volume(codec, label, " Boost", cidx,
4261 nid, HDA_INPUT);
David Henningsson18dcd302012-04-02 15:40:27 +02004262 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004263 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4264 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004265 if (con < 0)
4266 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004267 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004268 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004269 return 0; /* already present */
4270 }
4271
4272 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004273 spec->imux_info[idx].boost = mux;
David Henningsson74d3e6972012-10-02 10:14:23 +02004274 return cx_auto_add_volume(codec, label, " Boost", cidx,
Takashi Iwaicf27f292011-05-16 11:33:02 +02004275 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004276 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004277 return 0;
4278}
4279
Takashi Iwaif2e57312010-09-15 10:07:08 +02004280static int cx_auto_build_input_controls(struct hda_codec *codec)
4281{
4282 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004283 struct hda_input_mux *imux = &spec->private_imux;
4284 const char *prev_label;
4285 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004286 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004287 int multi_connection;
4288
Takashi Iwai6b452142011-10-14 15:26:20 +02004289 if (!imux->num_items)
4290 return 0;
4291
Takashi Iwaicf27f292011-05-16 11:33:02 +02004292 multi_connection = 0;
4293 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004294 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4295 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004296 if (cidx < 0)
4297 continue;
4298 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004299 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004300 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004301 if (i > 0 && input_conn[i] != input_conn[0])
4302 multi_connection = 1;
4303 }
David Henningsson983345e2011-02-15 19:57:09 +01004304
Takashi Iwaif2e57312010-09-15 10:07:08 +02004305 prev_label = NULL;
4306 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004307 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004308 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004309 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004310
Takashi Iwaicf27f292011-05-16 11:33:02 +02004311 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004312 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004313 if (label == prev_label)
4314 cidx++;
4315 else
4316 cidx = 0;
4317 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004318
Takashi Iwaicf27f292011-05-16 11:33:02 +02004319 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4320 if (err < 0)
4321 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004322
Takashi Iwaicf27f292011-05-16 11:33:02 +02004323 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004324 if (i > 0)
4325 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004326 err = cx_auto_add_capture_volume(codec, nid,
4327 "Capture", "", cidx);
4328 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004329 bool dup_found = false;
4330 for (j = 0; j < i; j++) {
4331 if (input_conn[j] == input_conn[i]) {
4332 dup_found = true;
4333 break;
4334 }
4335 }
4336 if (dup_found)
4337 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004338 err = cx_auto_add_capture_volume(codec, nid,
4339 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004340 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004341 if (err < 0)
4342 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004343 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004344
4345 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4346 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4347 if (err < 0)
4348 return err;
4349 }
4350
Takashi Iwaif2e57312010-09-15 10:07:08 +02004351 return 0;
4352}
4353
4354static int cx_auto_build_controls(struct hda_codec *codec)
4355{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004356 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004357 int err;
4358
4359 err = cx_auto_build_output_controls(codec);
4360 if (err < 0)
4361 return err;
4362 err = cx_auto_build_input_controls(codec);
4363 if (err < 0)
4364 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004365 err = conexant_build_controls(codec);
4366 if (err < 0)
4367 return err;
4368 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4369 if (err < 0)
4370 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004371 if (spec->vmaster_mute.sw_kctl) {
4372 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4373 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4374 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004375 if (err < 0)
4376 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004377 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004378 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004379}
4380
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004381static int cx_auto_search_adcs(struct hda_codec *codec)
4382{
4383 struct conexant_spec *spec = codec->spec;
4384 hda_nid_t nid, end_nid;
4385
4386 end_nid = codec->start_nid + codec->num_nodes;
4387 for (nid = codec->start_nid; nid < end_nid; nid++) {
4388 unsigned int caps = get_wcaps(codec, nid);
4389 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4390 continue;
4391 if (caps & AC_WCAP_DIGITAL)
4392 continue;
4393 if (snd_BUG_ON(spec->num_adc_nids >=
4394 ARRAY_SIZE(spec->private_adc_nids)))
4395 break;
4396 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4397 }
4398 spec->adc_nids = spec->private_adc_nids;
4399 return 0;
4400}
4401
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004402static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004403 .build_controls = cx_auto_build_controls,
4404 .build_pcms = conexant_build_pcms,
4405 .init = cx_auto_init,
4406 .free = conexant_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02004407 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai83012a72012-08-24 18:38:08 +02004408#ifdef CONFIG_PM
Takashi Iwaif2e57312010-09-15 10:07:08 +02004409 .suspend = conexant_suspend,
4410#endif
4411 .reboot_notify = snd_hda_shutup_pins,
4412};
4413
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004414/*
4415 * pin fix-up
4416 */
David Henningsson18dcd302012-04-02 15:40:27 +02004417enum {
4418 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02004419 CXT_PINCFG_LENOVO_TP410,
Huacai Chen239fb862012-10-05 21:25:09 +08004420 CXT_PINCFG_LEMOTE_A1004,
4421 CXT_PINCFG_LEMOTE_A1205,
David Henningsson18dcd302012-04-02 15:40:27 +02004422 CXT_FIXUP_STEREO_DMIC,
Huacai Chen239fb862012-10-05 21:25:09 +08004423 CXT_FIXUP_INC_MIC_BOOST,
David Henningsson18dcd302012-04-02 15:40:27 +02004424};
4425
Takashi Iwai23d30f22012-05-07 17:17:32 +02004426static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4427 const struct hda_fixup *fix, int action)
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004428{
David Henningsson18dcd302012-04-02 15:40:27 +02004429 struct conexant_spec *spec = codec->spec;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004430 spec->fixup_stereo_dmic = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004431}
4432
Huacai Chen239fb862012-10-05 21:25:09 +08004433static void cxt5066_increase_mic_boost(struct hda_codec *codec,
4434 const struct hda_fixup *fix, int action)
4435{
4436 if (action != HDA_FIXUP_ACT_PRE_PROBE)
4437 return;
4438
4439 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
4440 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
4441 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4442 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4443 (0 << AC_AMPCAP_MUTE_SHIFT));
4444}
4445
Takashi Iwaid70f3632012-04-19 15:18:08 +02004446/* ThinkPad X200 & co with cxt5051 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02004447static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004448 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4449 { 0x17, 0x21a11000 }, /* dock-mic */
4450 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004451 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004452 {}
4453};
4454
Takashi Iwaid70f3632012-04-19 15:18:08 +02004455/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02004456static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
Takashi Iwaid70f3632012-04-19 15:18:08 +02004457 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4458 { 0x1a, 0x21a190f0 }, /* dock-mic */
4459 { 0x1c, 0x212140ff }, /* dock-HP */
4460 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004461};
4462
Huacai Chen239fb862012-10-05 21:25:09 +08004463/* Lemote A1004/A1205 with cxt5066 */
4464static const struct hda_pintbl cxt_pincfg_lemote[] = {
4465 { 0x1a, 0x90a10020 }, /* Internal mic */
4466 { 0x1b, 0x03a11020 }, /* External mic */
4467 { 0x1d, 0x400101f0 }, /* Not used */
4468 { 0x1e, 0x40a701f0 }, /* Not used */
4469 { 0x20, 0x404501f0 }, /* Not used */
4470 { 0x22, 0x404401f0 }, /* Not used */
4471 { 0x23, 0x40a701f0 }, /* Not used */
4472 {}
4473};
4474
Takashi Iwai23d30f22012-05-07 17:17:32 +02004475static const struct hda_fixup cxt_fixups[] = {
4476 [CXT_PINCFG_LENOVO_X200] = {
4477 .type = HDA_FIXUP_PINS,
4478 .v.pins = cxt_pincfg_lenovo_x200,
4479 },
4480 [CXT_PINCFG_LENOVO_TP410] = {
4481 .type = HDA_FIXUP_PINS,
4482 .v.pins = cxt_pincfg_lenovo_tp410,
4483 },
Huacai Chen239fb862012-10-05 21:25:09 +08004484 [CXT_PINCFG_LEMOTE_A1004] = {
4485 .type = HDA_FIXUP_PINS,
4486 .chained = true,
4487 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
4488 .v.pins = cxt_pincfg_lemote,
4489 },
4490 [CXT_PINCFG_LEMOTE_A1205] = {
4491 .type = HDA_FIXUP_PINS,
4492 .v.pins = cxt_pincfg_lemote,
4493 },
Takashi Iwai23d30f22012-05-07 17:17:32 +02004494 [CXT_FIXUP_STEREO_DMIC] = {
4495 .type = HDA_FIXUP_FUNC,
4496 .v.func = cxt_fixup_stereo_dmic,
4497 },
Huacai Chen239fb862012-10-05 21:25:09 +08004498 [CXT_FIXUP_INC_MIC_BOOST] = {
4499 .type = HDA_FIXUP_FUNC,
4500 .v.func = cxt5066_increase_mic_boost,
4501 },
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004502};
4503
Takashi Iwaid70f3632012-04-19 15:18:08 +02004504static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004505 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4506 {}
4507};
4508
Takashi Iwaid70f3632012-04-19 15:18:08 +02004509static const struct snd_pci_quirk cxt5066_fixups[] = {
Takashi Iwai63a077e2012-12-12 12:10:01 +01004510 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaid70f3632012-04-19 15:18:08 +02004511 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4512 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4513 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4514 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4515 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02004516 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Felix Kaechelee4db0952012-09-26 01:20:44 +02004517 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
David Henningssonb3c5dce2012-06-21 16:03:01 +02004518 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
Huacai Chen239fb862012-10-05 21:25:09 +08004519 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
4520 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
Takashi Iwaif2e57312010-09-15 10:07:08 +02004521 {}
4522};
4523
Takashi Iwai38681372012-02-27 15:00:58 +01004524/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4525 * can be created (bko#42825)
4526 */
4527static void add_cx5051_fake_mutes(struct hda_codec *codec)
4528{
4529 static hda_nid_t out_nids[] = {
4530 0x10, 0x11, 0
4531 };
4532 hda_nid_t *p;
4533
4534 for (p = out_nids; *p; p++)
4535 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4536 AC_AMPCAP_MIN_MUTE |
4537 query_amp_caps(codec, *p, HDA_OUTPUT));
4538}
4539
Takashi Iwaif2e57312010-09-15 10:07:08 +02004540static int patch_conexant_auto(struct hda_codec *codec)
4541{
4542 struct conexant_spec *spec;
4543 int err;
4544
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004545 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4546 codec->chip_name);
4547
Takashi Iwaif2e57312010-09-15 10:07:08 +02004548 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4549 if (!spec)
4550 return -ENOMEM;
4551 codec->spec = spec;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004552 snd_hda_gen_init(&spec->gen);
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004553
Takashi Iwai6b452142011-10-14 15:26:20 +02004554 switch (codec->vendor_id) {
4555 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004556 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004557 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004558 case 0x14f15051:
4559 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02004560 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004561 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
Takashi Iwai38681372012-02-27 15:00:58 +01004562 break;
Michael Karcher51969d62012-04-06 15:34:19 +02004563 default:
4564 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004565 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
4566 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02004567 }
4568
Takashi Iwai23d30f22012-05-07 17:17:32 +02004569 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4570
Takashi Iwaif29735c2012-03-13 07:55:10 +01004571 /* Show mute-led control only on HP laptops
4572 * This is a sort of white-list: on HP laptops, EAPD corresponds
4573 * only to the mute-LED without actualy amp function. Meanwhile,
4574 * others may use EAPD really as an amp switch, so it might be
4575 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004576 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004577 switch (codec->subsystem_id >> 16) {
4578 case 0x103c:
4579 spec->vmaster_mute_led = 1;
4580 break;
4581 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004582
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004583 err = cx_auto_search_adcs(codec);
4584 if (err < 0)
4585 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004586 err = cx_auto_parse_auto_config(codec);
4587 if (err < 0) {
4588 kfree(codec->spec);
4589 codec->spec = NULL;
4590 return err;
4591 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004592 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004593 codec->patch_ops = cx_auto_patch_ops;
4594 if (spec->beep_amp)
4595 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004596
4597 /* Some laptops with Conexant chips show stalls in S3 resume,
4598 * which falls into the single-cmd mode.
4599 * Better to make reset, then.
4600 */
4601 if (!codec->bus->sync_write) {
4602 snd_printd("hda_codec: "
4603 "Enable sync_write for stable communication\n");
4604 codec->bus->sync_write = 1;
4605 codec->bus->allow_bus_reset = 1;
4606 }
4607
Takashi Iwaif2e57312010-09-15 10:07:08 +02004608 return 0;
4609}
4610
4611/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004612 */
4613
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004614static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004615 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4616 .patch = patch_cxt5045 },
4617 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4618 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004619 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4620 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004621 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4622 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004623 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4624 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004625 { .id = 0x14f15068, .name = "CX20584",
4626 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004627 { .id = 0x14f15069, .name = "CX20585",
4628 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004629 { .id = 0x14f1506c, .name = "CX20588",
4630 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004631 { .id = 0x14f1506e, .name = "CX20590",
4632 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004633 { .id = 0x14f15097, .name = "CX20631",
4634 .patch = patch_conexant_auto },
4635 { .id = 0x14f15098, .name = "CX20632",
4636 .patch = patch_conexant_auto },
4637 { .id = 0x14f150a1, .name = "CX20641",
4638 .patch = patch_conexant_auto },
4639 { .id = 0x14f150a2, .name = "CX20642",
4640 .patch = patch_conexant_auto },
4641 { .id = 0x14f150ab, .name = "CX20651",
4642 .patch = patch_conexant_auto },
4643 { .id = 0x14f150ac, .name = "CX20652",
4644 .patch = patch_conexant_auto },
4645 { .id = 0x14f150b8, .name = "CX20664",
4646 .patch = patch_conexant_auto },
4647 { .id = 0x14f150b9, .name = "CX20665",
4648 .patch = patch_conexant_auto },
Takashi Iwai2d825fd2012-05-11 08:39:24 +02004649 { .id = 0x14f1510f, .name = "CX20751/2",
4650 .patch = patch_conexant_auto },
4651 { .id = 0x14f15110, .name = "CX20751/2",
4652 .patch = patch_conexant_auto },
4653 { .id = 0x14f15111, .name = "CX20753/4",
4654 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004655 {} /* terminator */
4656};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004657
4658MODULE_ALIAS("snd-hda-codec-id:14f15045");
4659MODULE_ALIAS("snd-hda-codec-id:14f15047");
4660MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004661MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004662MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004663MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004664MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004665MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004666MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004667MODULE_ALIAS("snd-hda-codec-id:14f15097");
4668MODULE_ALIAS("snd-hda-codec-id:14f15098");
4669MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4670MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4671MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4672MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4673MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4674MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai2d825fd2012-05-11 08:39:24 +02004675MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4676MODULE_ALIAS("snd-hda-codec-id:14f15110");
4677MODULE_ALIAS("snd-hda-codec-id:14f15111");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004678
4679MODULE_LICENSE("GPL");
4680MODULE_DESCRIPTION("Conexant HD-audio codec");
4681
4682static struct hda_codec_preset_list conexant_list = {
4683 .preset = snd_hda_preset_conexant,
4684 .owner = THIS_MODULE,
4685};
4686
4687static int __init patch_conexant_init(void)
4688{
4689 return snd_hda_add_codec_preset(&conexant_list);
4690}
4691
4692static void __exit patch_conexant_exit(void)
4693{
4694 snd_hda_delete_codec_preset(&conexant_list);
4695}
4696
4697module_init(patch_conexant_init)
4698module_exit(patch_conexant_exit)