blob: f8e9ff493dc720f4374872fb25d372532943e30f [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
Tobin Davisc9b443d2006-11-14 12:13:39 +0100340static int conexant_build_pcms(struct hda_codec *codec)
341{
342 struct conexant_spec *spec = codec->spec;
343 struct hda_pcm *info = spec->pcm_rec;
344
345 codec->num_pcms = 1;
346 codec->pcm_info = info;
347
348 info->name = "CONEXANT Analog";
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
351 spec->multiout.max_channels;
352 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
353 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200354 if (spec->capture_stream)
355 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
356 else {
357 if (codec->vendor_id == 0x14f15051)
358 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
359 cx5051_pcm_analog_capture;
360 else {
361 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
362 conexant_pcm_analog_capture;
363 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
364 spec->num_adc_nids;
365 }
366 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100367 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
368
369 if (spec->multiout.dig_out_nid) {
370 info++;
371 codec->num_pcms++;
372 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100373 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100374 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
375 conexant_pcm_digital_playback;
376 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
377 spec->multiout.dig_out_nid;
378 if (spec->dig_in_nid) {
379 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
380 conexant_pcm_digital_capture;
381 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
382 spec->dig_in_nid;
383 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500384 if (spec->slave_dig_outs[0])
385 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100386 }
387
388 return 0;
389}
390
391static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
392 struct snd_ctl_elem_info *uinfo)
393{
394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
395 struct conexant_spec *spec = codec->spec;
396
397 return snd_hda_input_mux_info(spec->input_mux, uinfo);
398}
399
400static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_value *ucontrol)
402{
403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
404 struct conexant_spec *spec = codec->spec;
405 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
406
407 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
408 return 0;
409}
410
411static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
412 struct snd_ctl_elem_value *ucontrol)
413{
414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415 struct conexant_spec *spec = codec->spec;
416 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
417
418 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
419 spec->capsrc_nids[adc_idx],
420 &spec->cur_mux[adc_idx]);
421}
422
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200423static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
424 unsigned int power_state)
425{
426 if (power_state == AC_PWRST_D3)
427 msleep(100);
428 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
429 power_state);
430 /* partial workaround for "azx_get_response timeout" */
431 if (power_state == AC_PWRST_D0)
432 msleep(10);
433 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
434}
435
Tobin Davisc9b443d2006-11-14 12:13:39 +0100436static int conexant_init(struct hda_codec *codec)
437{
438 struct conexant_spec *spec = codec->spec;
439 int i;
440
441 for (i = 0; i < spec->num_init_verbs; i++)
442 snd_hda_sequence_write(codec, spec->init_verbs[i]);
443 return 0;
444}
445
446static void conexant_free(struct hda_codec *codec)
447{
Takashi Iwaiee48df52012-06-26 14:54:32 +0200448 struct conexant_spec *spec = codec->spec;
449 snd_hda_gen_free(&spec->gen);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200450 snd_hda_detach_beep_device(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +0200451 kfree(spec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100452}
453
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200454static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100455 {
456 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
457 .name = "Capture Source",
458 .info = conexant_mux_enum_info,
459 .get = conexant_mux_enum_get,
460 .put = conexant_mux_enum_put
461 },
462 {}
463};
464
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200465#ifdef CONFIG_SND_HDA_INPUT_BEEP
466/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200467static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200468 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
469 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
470 { } /* end */
471};
472#endif
473
Takashi Iwai9322ca52012-02-03 14:28:01 +0100474static const char * const slave_pfxs[] = {
Takashi Iwaif37bc7a2012-11-08 15:59:23 +0100475 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100476 NULL
477};
478
Tobin Davisc9b443d2006-11-14 12:13:39 +0100479static int conexant_build_controls(struct hda_codec *codec)
480{
481 struct conexant_spec *spec = codec->spec;
482 unsigned int i;
483 int err;
484
485 for (i = 0; i < spec->num_mixers; i++) {
486 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
487 if (err < 0)
488 return err;
489 }
490 if (spec->multiout.dig_out_nid) {
491 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600492 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100493 spec->multiout.dig_out_nid);
494 if (err < 0)
495 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100496 err = snd_hda_create_spdif_share_sw(codec,
497 &spec->multiout);
498 if (err < 0)
499 return err;
500 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100501 }
502 if (spec->dig_in_nid) {
503 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
504 if (err < 0)
505 return err;
506 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100507
508 /* if we have no master control, let's create it */
509 if (spec->vmaster_nid &&
510 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
511 unsigned int vmaster_tlv[4];
512 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
513 HDA_OUTPUT, vmaster_tlv);
514 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100515 vmaster_tlv, slave_pfxs,
516 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100517 if (err < 0)
518 return err;
519 }
520 if (spec->vmaster_nid &&
521 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai527c73b2012-03-12 12:38:51 +0100522 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
523 NULL, slave_pfxs,
524 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100525 &spec->vmaster_mute.sw_kctl);
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100526 if (err < 0)
527 return err;
528 }
529
Takashi Iwaib880c742009-03-10 14:41:05 +0100530 if (spec->input_mux) {
531 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
532 if (err < 0)
533 return err;
534 }
535
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200536#ifdef CONFIG_SND_HDA_INPUT_BEEP
537 /* create beep controls if needed */
538 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200539 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200540 for (knew = cxt_beep_mixer; knew->name; knew++) {
541 struct snd_kcontrol *kctl;
542 kctl = snd_ctl_new1(knew, codec);
543 if (!kctl)
544 return -ENOMEM;
545 kctl->private_value = spec->beep_amp;
546 err = snd_hda_ctl_add(codec, 0, kctl);
547 if (err < 0)
548 return err;
549 }
550 }
551#endif
552
Tobin Davisc9b443d2006-11-14 12:13:39 +0100553 return 0;
554}
555
Takashi Iwai83012a72012-08-24 18:38:08 +0200556#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200557static int conexant_suspend(struct hda_codec *codec)
Takashi Iwai697c3732010-07-30 11:28:02 +0200558{
559 snd_hda_shutup_pins(codec);
560 return 0;
561}
562#endif
563
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200564static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100565 .build_controls = conexant_build_controls,
566 .build_pcms = conexant_build_pcms,
567 .init = conexant_init,
568 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200569 .set_power_state = conexant_set_power,
Takashi Iwai83012a72012-08-24 18:38:08 +0200570#ifdef CONFIG_PM
Takashi Iwai697c3732010-07-30 11:28:02 +0200571 .suspend = conexant_suspend,
572#endif
573 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100574};
575
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200576#ifdef CONFIG_SND_HDA_INPUT_BEEP
577#define set_beep_amp(spec, nid, idx, dir) \
578 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
579#else
580#define set_beep_amp(spec, nid, idx, dir) /* NOP */
581#endif
582
Takashi Iwai6764bce2011-05-13 16:52:25 +0200583static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100584/*
585 * EAPD control
586 * the private value = nid | (invert << 8)
587 */
588
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200589#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100590
Tobin Davis82f30042007-02-13 12:45:44 +0100591static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100592 struct snd_ctl_elem_value *ucontrol)
593{
594 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
595 struct conexant_spec *spec = codec->spec;
596 int invert = (kcontrol->private_value >> 8) & 1;
597 if (invert)
598 ucontrol->value.integer.value[0] = !spec->cur_eapd;
599 else
600 ucontrol->value.integer.value[0] = spec->cur_eapd;
601 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100602
Tobin Davisc9b443d2006-11-14 12:13:39 +0100603}
604
Tobin Davis82f30042007-02-13 12:45:44 +0100605static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100606 struct snd_ctl_elem_value *ucontrol)
607{
608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
609 struct conexant_spec *spec = codec->spec;
610 int invert = (kcontrol->private_value >> 8) & 1;
611 hda_nid_t nid = kcontrol->private_value & 0xff;
612 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100613
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100614 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100615 if (invert)
616 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200617 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100618 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100619
Tobin Davisc9b443d2006-11-14 12:13:39 +0100620 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200621 snd_hda_codec_write_cache(codec, nid,
622 0, AC_VERB_SET_EAPD_BTLENABLE,
623 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100624 return 1;
625}
626
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100627/* controls for test mode */
628#ifdef CONFIG_SND_DEBUG
629
Tobin Davis82f30042007-02-13 12:45:44 +0100630#define CXT_EAPD_SWITCH(xname, nid, mask) \
631 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
632 .info = cxt_eapd_info, \
633 .get = cxt_eapd_get, \
634 .put = cxt_eapd_put, \
635 .private_value = nid | (mask<<16) }
636
637
638
Tobin Davisc9b443d2006-11-14 12:13:39 +0100639static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_info *uinfo)
641{
642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct conexant_spec *spec = codec->spec;
644 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
645 spec->num_channel_mode);
646}
647
648static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
654 spec->num_channel_mode,
655 spec->multiout.max_channels);
656}
657
658static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_value *ucontrol)
660{
661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct conexant_spec *spec = codec->spec;
663 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
664 spec->num_channel_mode,
665 &spec->multiout.max_channels);
666 if (err >= 0 && spec->need_dac_fix)
667 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
668 return err;
669}
670
671#define CXT_PIN_MODE(xname, nid, dir) \
672 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
673 .info = conexant_ch_mode_info, \
674 .get = conexant_ch_mode_get, \
675 .put = conexant_ch_mode_put, \
676 .private_value = nid | (dir<<16) }
677
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100678#endif /* CONFIG_SND_DEBUG */
679
Tobin Davisc9b443d2006-11-14 12:13:39 +0100680/* Conexant 5045 specific */
681
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200682static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
683static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
684static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100685#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100686
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200687static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100688 { 2, NULL },
689};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100690
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200691static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100692 .num_items = 2,
693 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200694 { "Internal Mic", 0x1 },
695 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100696 }
697};
698
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200699static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200700 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100701 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200702 { "Internal Mic", 0x1 },
703 { "Mic", 0x2 },
704 { "Line", 0x3 },
705 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100706 }
707};
708
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200709static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100710 .num_items = 2,
711 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200712 { "Mic", 0x1 },
713 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100714 }
715};
716
Tobin Davisc9b443d2006-11-14 12:13:39 +0100717/* turn on/off EAPD (+ mute HP) as a master switch */
718static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
719 struct snd_ctl_elem_value *ucontrol)
720{
721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100723 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100724
Tobin Davis82f30042007-02-13 12:45:44 +0100725 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100726 return 0;
727
Tobin Davis82f30042007-02-13 12:45:44 +0100728 /* toggle internal speakers mute depending of presence of
729 * the headphone jack
730 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200731 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
732 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
733 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100734
Takashi Iwai47fd8302007-08-10 17:11:07 +0200735 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
736 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
737 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100738 return 1;
739}
740
741/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200742static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200743 .ops = &snd_hda_bind_vol,
744 .values = {
745 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
746 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
747 0
748 },
749};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100750
Tobin Davis7f296732007-03-12 11:39:01 +0100751/* toggle input of built-in and mic jack appropriately */
752static void cxt5045_hp_automic(struct hda_codec *codec)
753{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200754 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
756 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
757 {}
758 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200759 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100760 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
762 {}
763 };
764 unsigned int present;
765
Takashi Iwaid56757a2009-11-18 08:00:14 +0100766 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100767 if (present)
768 snd_hda_sequence_write(codec, mic_jack_on);
769 else
770 snd_hda_sequence_write(codec, mic_jack_off);
771}
772
Tobin Davisc9b443d2006-11-14 12:13:39 +0100773
774/* mute internal speaker if HP is plugged */
775static void cxt5045_hp_automute(struct hda_codec *codec)
776{
Tobin Davis82f30042007-02-13 12:45:44 +0100777 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100778 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100779
Takashi Iwaid56757a2009-11-18 08:00:14 +0100780 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100781
Takashi Iwai47fd8302007-08-10 17:11:07 +0200782 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
783 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
784 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100785}
786
787/* unsolicited event for HP jack sensing */
788static void cxt5045_hp_unsol_event(struct hda_codec *codec,
789 unsigned int res)
790{
791 res >>= 26;
792 switch (res) {
793 case CONEXANT_HP_EVENT:
794 cxt5045_hp_automute(codec);
795 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100796 case CONEXANT_MIC_EVENT:
797 cxt5045_hp_automic(codec);
798 break;
799
Tobin Davisc9b443d2006-11-14 12:13:39 +0100800 }
801}
802
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200803static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200804 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
805 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200806 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
807 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100808 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
809 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100810 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
811 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200812 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100813 {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100816 .info = cxt_eapd_info,
817 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100819 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100820 },
821
822 {}
823};
824
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200825static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200826 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
827 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200828
Jiang Zhe5218c892008-01-17 11:18:41 +0100829 {}
830};
831
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200832static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200833 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
834 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100835 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
836 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100837 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
838 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100839 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
840 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100841 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
842 {
843 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
844 .name = "Master Playback Switch",
845 .info = cxt_eapd_info,
846 .get = cxt_eapd_get,
847 .put = cxt5045_hp_master_sw_put,
848 .private_value = 0x10,
849 },
850
851 {}
852};
853
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200854static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100855 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200856 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100857 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100858 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200859 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
860 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
861 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
862 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
863 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
864 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
865 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
867 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100868 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100869 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100870 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100871 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
872 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100873 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100874 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100875 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100876 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100877 { } /* end */
878};
879
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200880static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100881 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100882 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
883 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
884 /* Line In,HP, Amp */
885 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
886 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
887 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
888 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
892 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
893 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100894 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100895 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
896 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
897 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
898 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100899 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100900 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
901 /* EAPD */
902 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
903 { } /* end */
904};
Tobin Davis7f296732007-03-12 11:39:01 +0100905
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200906static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100907 /* pin sensing on HP jack */
908 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200909 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100910};
911
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200912static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100913 /* pin sensing on HP jack */
914 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200915 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100916};
917
Tobin Davisc9b443d2006-11-14 12:13:39 +0100918#ifdef CONFIG_SND_DEBUG
919/* Test configuration for debugging, modelled after the ALC260 test
920 * configuration.
921 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200922static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100923 .num_items = 5,
924 .items = {
925 { "MIXER", 0x0 },
926 { "MIC1 pin", 0x1 },
927 { "LINE1 pin", 0x2 },
928 { "HP-OUT pin", 0x3 },
929 { "CD pin", 0x4 },
930 },
931};
932
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200933static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100934
935 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100936 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
937 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200938 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
939 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
940 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
941 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100942
943 /* Modes for retasking pin widgets */
944 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
945 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
946
Tobin Davis82f30042007-02-13 12:45:44 +0100947 /* EAPD Switch Control */
948 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
949
Tobin Davisc9b443d2006-11-14 12:13:39 +0100950 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100951
Michael Karcher250f3272012-04-06 15:34:20 +0200952 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
953 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
954 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
955 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
956 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
957 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
958 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
959 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
960 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
961 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100962 {
963 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
964 .name = "Input Source",
965 .info = conexant_mux_enum_info,
966 .get = conexant_mux_enum_get,
967 .put = conexant_mux_enum_put,
968 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200969 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200970 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
971 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972 { } /* end */
973};
974
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200975static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100976 /* Set connections */
977 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
978 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
979 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100980 /* Enable retasking pins as output, initially without power amp */
981 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100982 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100983
984 /* Disable digital (SPDIF) pins initially, but users can enable
985 * them via a mixer switch. In the case of SPDIF-out, this initverb
986 * payload also sets the generation to 0, output to be in "consumer"
987 * PCM format, copyright asserted, no pre-emphasis and no validity
988 * control.
989 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100990 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
991 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100992
Tobin Davisc9b443d2006-11-14 12:13:39 +0100993 /* Unmute retasking pin widget output buffers since the default
994 * state appears to be output. As the pin mode is changed by the
995 * user the pin mode control will take care of enabling the pin's
996 * input/output buffers as needed.
997 */
998 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
999 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1000
1001 /* Mute capture amp left and right */
1002 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1003
1004 /* Set ADC connection select to match default mixer setting (mic1
1005 * pin)
1006 */
Michael Karcher250f3272012-04-06 15:34:20 +02001007 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1008 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001009
1010 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +02001011 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001012 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1013 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1014 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1015 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1016
1017 { }
1018};
1019#endif
1020
1021
1022/* initialize jack-sensing, too */
1023static int cxt5045_init(struct hda_codec *codec)
1024{
1025 conexant_init(codec);
1026 cxt5045_hp_automute(codec);
1027 return 0;
1028}
1029
1030
1031enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001032 CXT5045_LAPTOP_HPSENSE,
1033 CXT5045_LAPTOP_MICSENSE,
1034 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001035 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001036 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001037#ifdef CONFIG_SND_DEBUG
1038 CXT5045_TEST,
1039#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001040 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001041 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001042};
1043
Takashi Iwaiea734962011-01-17 11:29:34 +01001044static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001045 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1046 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1047 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1048 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001049 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001050#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001051 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001052#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001053 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001054};
1055
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001056static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001057 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001058 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001059 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001060 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1061 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001062 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1063 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001064 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1065 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1066 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001067 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1068 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001069 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001070 {}
1071};
1072
1073static int patch_cxt5045(struct hda_codec *codec)
1074{
1075 struct conexant_spec *spec;
1076 int board_config;
1077
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001078 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1079 cxt5045_models,
1080 cxt5045_cfg_tbl);
1081 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001082 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001083 if (board_config == CXT5045_AUTO)
1084 return patch_conexant_auto(codec);
1085
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1087 if (!spec)
1088 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001089 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001090 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001091
1092 spec->multiout.max_channels = 2;
1093 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1094 spec->multiout.dac_nids = cxt5045_dac_nids;
1095 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1096 spec->num_adc_nids = 1;
1097 spec->adc_nids = cxt5045_adc_nids;
1098 spec->capsrc_nids = cxt5045_capsrc_nids;
1099 spec->input_mux = &cxt5045_capture_source;
1100 spec->num_mixers = 1;
1101 spec->mixers[0] = cxt5045_mixers;
1102 spec->num_init_verbs = 1;
1103 spec->init_verbs[0] = cxt5045_init_verbs;
1104 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001105 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1106 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001107
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001108 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001109
1110 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111
Tobin Davisc9b443d2006-11-14 12:13:39 +01001112 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001113 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001114 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001115 spec->input_mux = &cxt5045_capture_source;
1116 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001117 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1118 spec->mixers[0] = cxt5045_mixers;
1119 codec->patch_ops.init = cxt5045_init;
1120 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001121 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001122 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001123 spec->input_mux = &cxt5045_capture_source;
1124 spec->num_init_verbs = 2;
1125 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001126 spec->mixers[0] = cxt5045_mixers;
1127 codec->patch_ops.init = cxt5045_init;
1128 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001129 default:
1130 case CXT5045_LAPTOP_HPMICSENSE:
1131 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1132 spec->input_mux = &cxt5045_capture_source;
1133 spec->num_init_verbs = 3;
1134 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1135 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1136 spec->mixers[0] = cxt5045_mixers;
1137 codec->patch_ops.init = cxt5045_init;
1138 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001139 case CXT5045_BENQ:
1140 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1141 spec->input_mux = &cxt5045_capture_source_benq;
1142 spec->num_init_verbs = 1;
1143 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1144 spec->mixers[0] = cxt5045_mixers;
1145 spec->mixers[1] = cxt5045_benq_mixers;
1146 spec->num_mixers = 2;
1147 codec->patch_ops.init = cxt5045_init;
1148 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001149 case CXT5045_LAPTOP_HP530:
1150 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1151 spec->input_mux = &cxt5045_capture_source_hp530;
1152 spec->num_init_verbs = 2;
1153 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1154 spec->mixers[0] = cxt5045_mixers_hp530;
1155 codec->patch_ops.init = cxt5045_init;
1156 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157#ifdef CONFIG_SND_DEBUG
1158 case CXT5045_TEST:
1159 spec->input_mux = &cxt5045_test_capture_source;
1160 spec->mixers[0] = cxt5045_test_mixer;
1161 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001162 break;
1163
Tobin Davisc9b443d2006-11-14 12:13:39 +01001164#endif
1165 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001166
Takashi Iwai031005f2008-06-26 14:49:58 +02001167 switch (codec->subsystem_id >> 16) {
1168 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001169 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001170 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001171 case 0x17aa:
1172 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1173 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1174 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001175 */
1176 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1177 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1178 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1179 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1180 (1 << AC_AMPCAP_MUTE_SHIFT));
1181 break;
1182 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001183
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001184 if (spec->beep_amp)
1185 snd_hda_attach_beep_device(codec, spec->beep_amp);
1186
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187 return 0;
1188}
1189
1190
1191/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001192#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001194static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1195static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1196static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001198static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001199 { 2, NULL },
1200};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001202static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001203 .num_items = 2,
1204 .items = {
1205 { "ExtMic", 0x2 },
1206 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207 }
1208};
1209
1210/* turn on/off EAPD (+ mute HP) as a master switch */
1211static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1212 struct snd_ctl_elem_value *ucontrol)
1213{
1214 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1215 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001216 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217
Tobin Davis82f30042007-02-13 12:45:44 +01001218 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001219 return 0;
1220
Tobin Davis82f30042007-02-13 12:45:44 +01001221 /* toggle internal speakers mute depending of presence of
1222 * the headphone jack
1223 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001224 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001225 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1226 * pin widgets unlike other codecs. In this case, we need to
1227 * set index 0x01 for the volume from the mixer amp 0x19.
1228 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001229 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001230 HDA_AMP_MUTE, bits);
1231 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1232 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1233 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 return 1;
1235}
1236
Tobin Davisc9b443d2006-11-14 12:13:39 +01001237/* mute internal speaker if HP is plugged */
1238static void cxt5047_hp_automute(struct hda_codec *codec)
1239{
Tobin Davis82f30042007-02-13 12:45:44 +01001240 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001241 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242
Takashi Iwaid56757a2009-11-18 08:00:14 +01001243 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001244
Takashi Iwai47fd8302007-08-10 17:11:07 +02001245 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001246 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001247 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001248 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001249}
1250
1251/* toggle input of built-in and mic jack appropriately */
1252static void cxt5047_hp_automic(struct hda_codec *codec)
1253{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001254 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001255 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1256 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257 {}
1258 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001259 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001260 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1261 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 {}
1263 };
1264 unsigned int present;
1265
Takashi Iwaid56757a2009-11-18 08:00:14 +01001266 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267 if (present)
1268 snd_hda_sequence_write(codec, mic_jack_on);
1269 else
1270 snd_hda_sequence_write(codec, mic_jack_off);
1271}
1272
1273/* unsolicited event for HP jack sensing */
1274static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1275 unsigned int res)
1276{
Marc Boucher9f113e02008-01-22 15:18:08 +01001277 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001278 case CONEXANT_HP_EVENT:
1279 cxt5047_hp_automute(codec);
1280 break;
1281 case CONEXANT_MIC_EVENT:
1282 cxt5047_hp_automic(codec);
1283 break;
1284 }
1285}
1286
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001287static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001288 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1289 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001290 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1292 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1293 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001295 {
1296 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1297 .name = "Master Playback Switch",
1298 .info = cxt_eapd_info,
1299 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 .put = cxt5047_hp_master_sw_put,
1301 .private_value = 0x13,
1302 },
1303
1304 {}
1305};
1306
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001307static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001308 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001309 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001310 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1311 {}
1312};
1313
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001314static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316 { } /* end */
1317};
1318
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001319static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001320 /* Line in, Mic, Built-in Mic */
1321 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1322 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1323 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001324 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001325 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001326 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1327 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001328 /* Record selector: Mic */
1329 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1330 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1331 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1332 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001333 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1334 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1335 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1336 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001337 /* SPDIF route: PCM */
1338 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001339 /* Enable unsolicited events */
1340 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1341 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 { } /* end */
1343};
1344
1345/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001346static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001347 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001348 {}
1349};
1350
1351/* Test configuration for debugging, modelled after the ALC260 test
1352 * configuration.
1353 */
1354#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001355static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001356 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001358 { "LINE1 pin", 0x0 },
1359 { "MIC1 pin", 0x1 },
1360 { "MIC2 pin", 0x2 },
1361 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 },
1363};
1364
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001365static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366
1367 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001368 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1375 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001376 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1377 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1378 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001380
1381 /* Modes for retasking pin widgets */
1382 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1383 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1384
Tobin Davis82f30042007-02-13 12:45:44 +01001385 /* EAPD Switch Control */
1386 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1387
Tobin Davisc9b443d2006-11-14 12:13:39 +01001388 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001389 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1390 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1391 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1392 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1393 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1394 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1395 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1396 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001397
Tobin Davis82f30042007-02-13 12:45:44 +01001398 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1399 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1400 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1401 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1402 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1403 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1404 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1405 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001406 {
1407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1408 .name = "Input Source",
1409 .info = conexant_mux_enum_info,
1410 .get = conexant_mux_enum_get,
1411 .put = conexant_mux_enum_put,
1412 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001413 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001414
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 { } /* end */
1416};
1417
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001418static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419 /* Enable retasking pins as output, initially without power amp */
1420 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1421 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1422 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1423
1424 /* Disable digital (SPDIF) pins initially, but users can enable
1425 * them via a mixer switch. In the case of SPDIF-out, this initverb
1426 * payload also sets the generation to 0, output to be in "consumer"
1427 * PCM format, copyright asserted, no pre-emphasis and no validity
1428 * control.
1429 */
1430 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1431
1432 /* Ensure mic1, mic2, line1 pin widgets take input from the
1433 * OUT1 sum bus when acting as an output.
1434 */
1435 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1436 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1437
1438 /* Start with output sum widgets muted and their output gains at min */
1439 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1440 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1441
1442 /* Unmute retasking pin widget output buffers since the default
1443 * state appears to be output. As the pin mode is changed by the
1444 * user the pin mode control will take care of enabling the pin's
1445 * input/output buffers as needed.
1446 */
1447 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1448 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1449 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1450
1451 /* Mute capture amp left and right */
1452 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1453
1454 /* Set ADC connection select to match default mixer setting (mic1
1455 * pin)
1456 */
1457 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1458
1459 /* Mute all inputs to mixer widget (even unconnected ones) */
1460 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1461 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1462 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1468
1469 { }
1470};
1471#endif
1472
1473
1474/* initialize jack-sensing, too */
1475static int cxt5047_hp_init(struct hda_codec *codec)
1476{
1477 conexant_init(codec);
1478 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001479 return 0;
1480}
1481
1482
1483enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001484 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1485 CXT5047_LAPTOP_HP, /* Some HP laptops */
1486 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001487#ifdef CONFIG_SND_DEBUG
1488 CXT5047_TEST,
1489#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001490 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001491 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001492};
1493
Takashi Iwaiea734962011-01-17 11:29:34 +01001494static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001495 [CXT5047_LAPTOP] = "laptop",
1496 [CXT5047_LAPTOP_HP] = "laptop-hp",
1497 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001498#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001499 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001500#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001501 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001502};
1503
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001504static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001505 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001506 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1507 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001508 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509 {}
1510};
1511
1512static int patch_cxt5047(struct hda_codec *codec)
1513{
1514 struct conexant_spec *spec;
1515 int board_config;
1516
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001517 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1518 cxt5047_models,
1519 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001520 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001521 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001522 if (board_config == CXT5047_AUTO)
1523 return patch_conexant_auto(codec);
1524
Tobin Davisc9b443d2006-11-14 12:13:39 +01001525 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1526 if (!spec)
1527 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001528 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001529 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001530
1531 spec->multiout.max_channels = 2;
1532 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1533 spec->multiout.dac_nids = cxt5047_dac_nids;
1534 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1535 spec->num_adc_nids = 1;
1536 spec->adc_nids = cxt5047_adc_nids;
1537 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001539 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001540 spec->num_init_verbs = 1;
1541 spec->init_verbs[0] = cxt5047_init_verbs;
1542 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001543 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1544 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545
1546 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001547
Tobin Davisc9b443d2006-11-14 12:13:39 +01001548 switch (board_config) {
1549 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001550 spec->num_mixers = 2;
1551 spec->mixers[1] = cxt5047_hp_spk_mixers;
1552 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553 break;
1554 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001555 spec->num_mixers = 2;
1556 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001557 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558 codec->patch_ops.init = cxt5047_hp_init;
1559 break;
1560 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001561 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001562 spec->num_mixers = 2;
1563 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001564 spec->num_init_verbs = 2;
1565 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001566 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001567 break;
1568#ifdef CONFIG_SND_DEBUG
1569 case CXT5047_TEST:
1570 spec->input_mux = &cxt5047_test_capture_source;
1571 spec->mixers[0] = cxt5047_test_mixer;
1572 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001573 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001574#endif
1575 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001576 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001577
1578 switch (codec->subsystem_id >> 16) {
1579 case 0x103c:
1580 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1581 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1582 * with 0 dB offset 0x17)
1583 */
1584 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1585 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1586 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1587 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1588 (1 << AC_AMPCAP_MUTE_SHIFT));
1589 break;
1590 }
1591
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592 return 0;
1593}
1594
Takashi Iwai461e2c72008-01-25 11:35:17 +01001595/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001596static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1597static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001598
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001599static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001600 { 2, NULL },
1601};
1602
1603static void cxt5051_update_speaker(struct hda_codec *codec)
1604{
1605 struct conexant_spec *spec = codec->spec;
1606 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001607 /* headphone pin */
1608 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001609 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
Takashi Iwai23d2df52010-01-24 11:19:27 +01001610 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001611 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001612 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001613 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001614 if (spec->ideapad)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001615 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001616}
1617
1618/* turn on/off EAPD (+ mute HP) as a master switch */
1619static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1621{
1622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1623
1624 if (!cxt_eapd_put(kcontrol, ucontrol))
1625 return 0;
1626 cxt5051_update_speaker(codec);
1627 return 1;
1628}
1629
1630/* toggle input of built-in and mic jack appropriately */
1631static void cxt5051_portb_automic(struct hda_codec *codec)
1632{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001633 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001634 unsigned int present;
1635
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001636 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001637 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001638 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001639 snd_hda_codec_write(codec, 0x14, 0,
1640 AC_VERB_SET_CONNECT_SEL,
1641 present ? 0x01 : 0x00);
1642}
1643
1644/* switch the current ADC according to the jack state */
1645static void cxt5051_portc_automic(struct hda_codec *codec)
1646{
1647 struct conexant_spec *spec = codec->spec;
1648 unsigned int present;
1649 hda_nid_t new_adc;
1650
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001651 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001652 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001653 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001654 if (present)
1655 spec->cur_adc_idx = 1;
1656 else
1657 spec->cur_adc_idx = 0;
1658 new_adc = spec->adc_nids[spec->cur_adc_idx];
1659 if (spec->cur_adc && spec->cur_adc != new_adc) {
1660 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001661 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001662 spec->cur_adc = new_adc;
1663 snd_hda_codec_setup_stream(codec, new_adc,
1664 spec->cur_adc_stream_tag, 0,
1665 spec->cur_adc_format);
1666 }
1667}
1668
1669/* mute internal speaker if HP is plugged */
1670static void cxt5051_hp_automute(struct hda_codec *codec)
1671{
1672 struct conexant_spec *spec = codec->spec;
1673
Takashi Iwaid56757a2009-11-18 08:00:14 +01001674 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001675 cxt5051_update_speaker(codec);
1676}
1677
1678/* unsolicited event for HP jack sensing */
1679static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1680 unsigned int res)
1681{
1682 switch (res >> 26) {
1683 case CONEXANT_HP_EVENT:
1684 cxt5051_hp_automute(codec);
1685 break;
1686 case CXT5051_PORTB_EVENT:
1687 cxt5051_portb_automic(codec);
1688 break;
1689 case CXT5051_PORTC_EVENT:
1690 cxt5051_portc_automic(codec);
1691 break;
1692 }
1693}
1694
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001695static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001696 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1697 {
1698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1699 .name = "Master Playback Switch",
1700 .info = cxt_eapd_info,
1701 .get = cxt_eapd_get,
1702 .put = cxt5051_hp_master_sw_put,
1703 .private_value = 0x1a,
1704 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001705 {}
1706};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001707
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001708static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001709 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1710 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001711 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1712 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
David Henningssonc40bd912012-09-19 12:19:47 +02001713 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1714 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715 {}
1716};
1717
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001718static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1720 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001721 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1722 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723 {}
1724};
1725
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001726static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001727 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1728 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001729 {}
1730};
1731
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001732static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001733 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1734 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001735 {}
1736};
1737
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001738static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001739 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1740 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001741 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1742 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001743 {}
1744};
1745
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001746static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001747 /* Line in, Mic */
1748 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1749 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1750 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1751 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1752 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1753 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1754 /* SPK */
1755 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1756 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1757 /* HP, Amp */
1758 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1759 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1760 /* DAC1 */
1761 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001762 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001763 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1764 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1765 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1766 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001767 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001768 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1769 /* EAPD */
1770 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1771 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001772 { } /* end */
1773};
1774
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001775static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001776 /* Line in, Mic */
1777 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1778 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1779 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1780 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1781 /* SPK */
1782 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1783 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1784 /* HP, Amp */
1785 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1786 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1787 /* DAC1 */
1788 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001789 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001790 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1791 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1792 /* SPDIF route: PCM */
1793 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1794 /* EAPD */
1795 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1796 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001797 { } /* end */
1798};
1799
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001800static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001801 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001802 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001803 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1804 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1805 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1806 /* SPK */
1807 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1808 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1809 /* HP, Amp */
1810 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1811 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1812 /* DAC1 */
1813 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001814 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1816 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1817 /* SPDIF route: PCM */
1818 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1819 /* EAPD */
1820 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1821 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001822 { } /* end */
1823};
1824
Takashi Iwai6953e552010-01-24 11:00:27 +01001825static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1826 unsigned int event)
1827{
1828 snd_hda_codec_write(codec, nid, 0,
1829 AC_VERB_SET_UNSOLICITED_ENABLE,
1830 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001831}
1832
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001833static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001834 /* Subwoofer */
1835 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1836 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1837 { } /* end */
1838};
1839
Takashi Iwai461e2c72008-01-25 11:35:17 +01001840/* initialize jack-sensing, too */
1841static int cxt5051_init(struct hda_codec *codec)
1842{
Takashi Iwai6953e552010-01-24 11:00:27 +01001843 struct conexant_spec *spec = codec->spec;
1844
Takashi Iwai461e2c72008-01-25 11:35:17 +01001845 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001846
1847 if (spec->auto_mic & AUTO_MIC_PORTB)
1848 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1849 if (spec->auto_mic & AUTO_MIC_PORTC)
1850 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1851
Takashi Iwai461e2c72008-01-25 11:35:17 +01001852 if (codec->patch_ops.unsol_event) {
1853 cxt5051_hp_automute(codec);
1854 cxt5051_portb_automic(codec);
1855 cxt5051_portc_automic(codec);
1856 }
1857 return 0;
1858}
1859
1860
1861enum {
1862 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1863 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001864 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001865 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001866 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001867 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001868 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001869 CXT5051_MODELS
1870};
1871
Takashi Iwaiea734962011-01-17 11:29:34 +01001872static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001873 [CXT5051_LAPTOP] = "laptop",
1874 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001875 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001876 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001877 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001878 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001879 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001880};
1881
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001882static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001883 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001884 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001885 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001886 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001887 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1888 CXT5051_LAPTOP),
1889 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001890 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001891 {}
1892};
1893
1894static int patch_cxt5051(struct hda_codec *codec)
1895{
1896 struct conexant_spec *spec;
1897 int board_config;
1898
Takashi Iwai6764bce2011-05-13 16:52:25 +02001899 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1900 cxt5051_models,
1901 cxt5051_cfg_tbl);
1902 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001903 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001904 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001905 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001906
Takashi Iwai461e2c72008-01-25 11:35:17 +01001907 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1908 if (!spec)
1909 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001910 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001911 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001912
1913 codec->patch_ops = conexant_patch_ops;
1914 codec->patch_ops.init = cxt5051_init;
1915
1916 spec->multiout.max_channels = 2;
1917 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1918 spec->multiout.dac_nids = cxt5051_dac_nids;
1919 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1920 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1921 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001922 spec->num_mixers = 2;
1923 spec->mixers[0] = cxt5051_capture_mixers;
1924 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001925 spec->num_init_verbs = 1;
1926 spec->init_verbs[0] = cxt5051_init_verbs;
1927 spec->spdif_route = 0;
1928 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1929 spec->channel_mode = cxt5051_modes;
1930 spec->cur_adc = 0;
1931 spec->cur_adc_idx = 0;
1932
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001933 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1934
Takashi Iwai79d7d532009-03-04 09:03:50 +01001935 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1936
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001937 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001938 switch (board_config) {
1939 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001940 spec->mixers[0] = cxt5051_hp_mixers;
1941 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001942 case CXT5051_HP_DV6736:
1943 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1944 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001945 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001946 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001947 case CXT5051_F700:
1948 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1949 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001950 spec->auto_mic = 0;
1951 break;
1952 case CXT5051_TOSHIBA:
1953 spec->mixers[0] = cxt5051_toshiba_mixers;
1954 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001955 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001956 case CXT5051_IDEAPAD:
1957 spec->init_verbs[spec->num_init_verbs++] =
1958 cxt5051_ideapad_init_verbs;
1959 spec->ideapad = 1;
1960 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001961 }
1962
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001963 if (spec->beep_amp)
1964 snd_hda_attach_beep_device(codec, spec->beep_amp);
1965
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 return 0;
1967}
1968
Daniel Drake0fb67e92009-07-16 14:46:57 +01001969/* Conexant 5066 specific */
1970
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001971static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1972static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1973static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1974static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001975
Daniel Drakedbaccc02009-11-09 15:17:24 +00001976/* OLPC's microphone port is DC coupled for use with external sensors,
1977 * therefore we use a 50% mic bias in order to center the input signal with
1978 * the DC input range of the codec. */
1979#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1980
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001981static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001982 { 2, NULL },
1983};
1984
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001985#define HP_PRESENT_PORT_A (1 << 0)
1986#define HP_PRESENT_PORT_D (1 << 1)
1987#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1988#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1989
Daniel Drake0fb67e92009-07-16 14:46:57 +01001990static void cxt5066_update_speaker(struct hda_codec *codec)
1991{
1992 struct conexant_spec *spec = codec->spec;
1993 unsigned int pinctl;
1994
John Baboval3a253442010-12-02 11:21:31 -05001995 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1996 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001997
1998 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001999 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002000 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002001
2002 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002003 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2004 if (spec->dell_automute || spec->thinkpad) {
2005 /* Mute if Port A is connected */
2006 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002007 pinctl = 0;
2008 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002009 /* Thinkpad/Dell doesn't give pin-D status */
2010 if (!hp_port_d_present(spec))
2011 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002012 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002013 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002014
2015 /* CLASS_D AMP */
2016 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002017 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002018}
2019
2020/* turn on/off EAPD (+ mute HP) as a master switch */
2021static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2022 struct snd_ctl_elem_value *ucontrol)
2023{
2024 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2025
2026 if (!cxt_eapd_put(kcontrol, ucontrol))
2027 return 0;
2028
2029 cxt5066_update_speaker(codec);
2030 return 1;
2031}
2032
Daniel Drakec4cfe662010-01-07 13:47:04 +01002033static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2034 .num_items = 3,
2035 .items = {
2036 { "Off", PIN_IN },
2037 { "50%", PIN_VREF50 },
2038 { "80%", PIN_VREF80 },
2039 },
2040};
2041
2042static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2043{
2044 struct conexant_spec *spec = codec->spec;
2045 /* Even though port F is the DC input, the bias is controlled on port B.
2046 * we also leave that port as an active input (but unselected) in DC mode
2047 * just in case that is necessary to make the bias setting take effect. */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002048 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002049 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2050}
2051
Daniel Drake75f89912010-01-07 13:46:25 +01002052/* OLPC defers mic widget control until when capture is started because the
2053 * microphone LED comes on as soon as these settings are put in place. if we
2054 * did this before recording, it would give the false indication that recording
2055 * is happening when it is not. */
2056static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002057{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002058 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002059 if (!spec->recording)
2060 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002061
Daniel Drakec4cfe662010-01-07 13:47:04 +01002062 if (spec->dc_enable) {
2063 /* in DC mode we ignore presence detection and just use the jack
2064 * through our special DC port */
2065 const struct hda_verb enable_dc_mode[] = {
2066 /* disble internal mic, port C */
2067 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2068
2069 /* enable DC capture, port F */
2070 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2071 {},
2072 };
2073
2074 snd_hda_sequence_write(codec, enable_dc_mode);
2075 /* port B input disabled (and bias set) through the following call */
2076 cxt5066_set_olpc_dc_bias(codec);
2077 return;
2078 }
2079
2080 /* disable DC (port F) */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002081 snd_hda_set_pin_ctl(codec, 0x1e, 0);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002082
Daniel Drake75f89912010-01-07 13:46:25 +01002083 /* external mic, port B */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002084 snd_hda_set_pin_ctl(codec, 0x1a,
Daniel Drake75f89912010-01-07 13:46:25 +01002085 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002086
Daniel Drake75f89912010-01-07 13:46:25 +01002087 /* internal mic, port C */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002088 snd_hda_set_pin_ctl(codec, 0x1b,
Daniel Drake75f89912010-01-07 13:46:25 +01002089 spec->ext_mic_present ? 0 : PIN_VREF80);
2090}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002091
Daniel Drake75f89912010-01-07 13:46:25 +01002092/* toggle input of built-in and mic jack appropriately */
2093static void cxt5066_olpc_automic(struct hda_codec *codec)
2094{
2095 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002096 unsigned int present;
2097
Daniel Drakec4cfe662010-01-07 13:47:04 +01002098 if (spec->dc_enable) /* don't do presence detection in DC mode */
2099 return;
2100
Daniel Drake75f89912010-01-07 13:46:25 +01002101 present = snd_hda_codec_read(codec, 0x1a, 0,
2102 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2103 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002104 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002105 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002106 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002107
2108 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2109 present ? 0 : 1);
2110 spec->ext_mic_present = !!present;
2111
2112 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002113}
2114
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002115/* toggle input of built-in digital mic and mic jack appropriately */
2116static void cxt5066_vostro_automic(struct hda_codec *codec)
2117{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002118 unsigned int present;
2119
2120 struct hda_verb ext_mic_present[] = {
2121 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002122 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002123
2124 /* switch to external mic input */
2125 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2126 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2127
2128 /* disable internal digital mic */
2129 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2130 {}
2131 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002132 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002133 /* enable internal mic, port C */
2134 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2135
2136 /* switch to internal mic input */
2137 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2138
2139 /* disable external mic, port B */
2140 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2141 {}
2142 };
2143
2144 present = snd_hda_jack_detect(codec, 0x1a);
2145 if (present) {
2146 snd_printdd("CXT5066: external microphone detected\n");
2147 snd_hda_sequence_write(codec, ext_mic_present);
2148 } else {
2149 snd_printdd("CXT5066: external microphone absent\n");
2150 snd_hda_sequence_write(codec, ext_mic_absent);
2151 }
2152}
2153
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002154/* toggle input of built-in digital mic and mic jack appropriately */
2155static void cxt5066_ideapad_automic(struct hda_codec *codec)
2156{
2157 unsigned int present;
2158
2159 struct hda_verb ext_mic_present[] = {
2160 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2161 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2162 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2163 {}
2164 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002165 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002166 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2167 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2168 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2169 {}
2170 };
2171
2172 present = snd_hda_jack_detect(codec, 0x1b);
2173 if (present) {
2174 snd_printdd("CXT5066: external microphone detected\n");
2175 snd_hda_sequence_write(codec, ext_mic_present);
2176 } else {
2177 snd_printdd("CXT5066: external microphone absent\n");
2178 snd_hda_sequence_write(codec, ext_mic_absent);
2179 }
2180}
2181
David Henningssona1d69062011-01-21 13:33:28 +01002182
2183/* toggle input of built-in digital mic and mic jack appropriately */
2184static void cxt5066_asus_automic(struct hda_codec *codec)
2185{
2186 unsigned int present;
2187
2188 present = snd_hda_jack_detect(codec, 0x1b);
2189 snd_printdd("CXT5066: external microphone present=%d\n", present);
2190 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2191 present ? 1 : 0);
2192}
2193
2194
David Henningsson048e78a2010-09-02 08:35:47 +02002195/* toggle input of built-in digital mic and mic jack appropriately */
2196static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2197{
2198 unsigned int present;
2199
2200 present = snd_hda_jack_detect(codec, 0x1b);
2201 snd_printdd("CXT5066: external microphone present=%d\n", present);
2202 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2203 present ? 1 : 3);
2204}
2205
2206
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002207/* toggle input of built-in digital mic and mic jack appropriately
2208 order is: external mic -> dock mic -> interal mic */
2209static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2210{
2211 unsigned int ext_present, dock_present;
2212
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002213 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002214 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2215 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2216 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2217 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2218 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2219 {}
2220 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002221 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002222 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2223 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2224 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2225 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2226 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2227 {}
2228 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002229 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002230 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2231 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2232 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2233 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2234 {}
2235 };
2236
2237 ext_present = snd_hda_jack_detect(codec, 0x1b);
2238 dock_present = snd_hda_jack_detect(codec, 0x1a);
2239 if (ext_present) {
2240 snd_printdd("CXT5066: external microphone detected\n");
2241 snd_hda_sequence_write(codec, ext_mic_present);
2242 } else if (dock_present) {
2243 snd_printdd("CXT5066: dock microphone detected\n");
2244 snd_hda_sequence_write(codec, dock_mic_present);
2245 } else {
2246 snd_printdd("CXT5066: external microphone absent\n");
2247 snd_hda_sequence_write(codec, ext_mic_absent);
2248 }
2249}
2250
Daniel Drake0fb67e92009-07-16 14:46:57 +01002251/* mute internal speaker if HP is plugged */
2252static void cxt5066_hp_automute(struct hda_codec *codec)
2253{
2254 struct conexant_spec *spec = codec->spec;
2255 unsigned int portA, portD;
2256
2257 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002258 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002259
2260 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002261 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002262
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002263 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2264 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002265 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2266 portA, portD, spec->hp_present);
2267 cxt5066_update_speaker(codec);
2268}
2269
David Henningsson02b6b5b2011-01-21 13:27:39 +01002270/* Dispatch the right mic autoswitch function */
2271static void cxt5066_automic(struct hda_codec *codec)
2272{
2273 struct conexant_spec *spec = codec->spec;
2274
2275 if (spec->dell_vostro)
2276 cxt5066_vostro_automic(codec);
2277 else if (spec->ideapad)
2278 cxt5066_ideapad_automic(codec);
2279 else if (spec->thinkpad)
2280 cxt5066_thinkpad_automic(codec);
2281 else if (spec->hp_laptop)
2282 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002283 else if (spec->asus)
2284 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002285}
2286
Daniel Drake0fb67e92009-07-16 14:46:57 +01002287/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002288static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002289{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002290 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002291 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2292 switch (res >> 26) {
2293 case CONEXANT_HP_EVENT:
2294 cxt5066_hp_automute(codec);
2295 break;
2296 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002297 /* ignore mic events in DC mode; we're always using the jack */
2298 if (!spec->dc_enable)
2299 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002300 break;
2301 }
2302}
2303
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002304/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002305static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002306{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002307 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002308 switch (res >> 26) {
2309 case CONEXANT_HP_EVENT:
2310 cxt5066_hp_automute(codec);
2311 break;
2312 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002313 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002314 break;
2315 }
2316}
2317
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002318
Daniel Drake0fb67e92009-07-16 14:46:57 +01002319static const struct hda_input_mux cxt5066_analog_mic_boost = {
2320 .num_items = 5,
2321 .items = {
2322 { "0dB", 0 },
2323 { "10dB", 1 },
2324 { "20dB", 2 },
2325 { "30dB", 3 },
2326 { "40dB", 4 },
2327 },
2328};
2329
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002330static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002331{
2332 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002333 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002334 AC_VERB_SET_AMP_GAIN_MUTE,
2335 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2336 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002337 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002338 /* adjust the internal mic as well...it is not through 0x17 */
2339 snd_hda_codec_write_cache(codec, 0x23, 0,
2340 AC_VERB_SET_AMP_GAIN_MUTE,
2341 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2342 cxt5066_analog_mic_boost.
2343 items[spec->mic_boost].index);
2344 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002345}
2346
Daniel Drake0fb67e92009-07-16 14:46:57 +01002347static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2348 struct snd_ctl_elem_info *uinfo)
2349{
2350 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2351}
2352
2353static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2354 struct snd_ctl_elem_value *ucontrol)
2355{
2356 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002357 struct conexant_spec *spec = codec->spec;
2358 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359 return 0;
2360}
2361
2362static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2363 struct snd_ctl_elem_value *ucontrol)
2364{
2365 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002366 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2368 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002369 idx = ucontrol->value.enumerated.item[0];
2370 if (idx >= imux->num_items)
2371 idx = imux->num_items - 1;
2372
Daniel Drakec4cfe662010-01-07 13:47:04 +01002373 spec->mic_boost = idx;
2374 if (!spec->dc_enable)
2375 cxt5066_set_mic_boost(codec);
2376 return 1;
2377}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002378
Daniel Drakec4cfe662010-01-07 13:47:04 +01002379static void cxt5066_enable_dc(struct hda_codec *codec)
2380{
2381 const struct hda_verb enable_dc_mode[] = {
2382 /* disable gain */
2383 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2384
2385 /* switch to DC input */
2386 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2387 {}
2388 };
2389
2390 /* configure as input source */
2391 snd_hda_sequence_write(codec, enable_dc_mode);
2392 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2393}
2394
2395static void cxt5066_disable_dc(struct hda_codec *codec)
2396{
2397 /* reconfigure input source */
2398 cxt5066_set_mic_boost(codec);
2399 /* automic also selects the right mic if we're recording */
2400 cxt5066_olpc_automic(codec);
2401}
2402
2403static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2404 struct snd_ctl_elem_value *ucontrol)
2405{
2406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2407 struct conexant_spec *spec = codec->spec;
2408 ucontrol->value.integer.value[0] = spec->dc_enable;
2409 return 0;
2410}
2411
2412static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2413 struct snd_ctl_elem_value *ucontrol)
2414{
2415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2416 struct conexant_spec *spec = codec->spec;
2417 int dc_enable = !!ucontrol->value.integer.value[0];
2418
2419 if (dc_enable == spec->dc_enable)
2420 return 0;
2421
2422 spec->dc_enable = dc_enable;
2423 if (dc_enable)
2424 cxt5066_enable_dc(codec);
2425 else
2426 cxt5066_disable_dc(codec);
2427
2428 return 1;
2429}
2430
2431static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2432 struct snd_ctl_elem_info *uinfo)
2433{
2434 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2435}
2436
2437static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2438 struct snd_ctl_elem_value *ucontrol)
2439{
2440 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2441 struct conexant_spec *spec = codec->spec;
2442 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2443 return 0;
2444}
2445
2446static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2447 struct snd_ctl_elem_value *ucontrol)
2448{
2449 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2450 struct conexant_spec *spec = codec->spec;
2451 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2452 unsigned int idx;
2453
2454 idx = ucontrol->value.enumerated.item[0];
2455 if (idx >= imux->num_items)
2456 idx = imux->num_items - 1;
2457
2458 spec->dc_input_bias = idx;
2459 if (spec->dc_enable)
2460 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002461 return 1;
2462}
2463
Daniel Drake75f89912010-01-07 13:46:25 +01002464static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2465{
2466 struct conexant_spec *spec = codec->spec;
2467 /* mark as recording and configure the microphone widget so that the
2468 * recording LED comes on. */
2469 spec->recording = 1;
2470 cxt5066_olpc_select_mic(codec);
2471}
2472
2473static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2474{
2475 struct conexant_spec *spec = codec->spec;
2476 const struct hda_verb disable_mics[] = {
2477 /* disable external mic, port B */
2478 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2479
2480 /* disble internal mic, port C */
2481 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002482
2483 /* disable DC capture, port F */
2484 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002485 {},
2486 };
2487
2488 snd_hda_sequence_write(codec, disable_mics);
2489 spec->recording = 0;
2490}
2491
Andy Robinsonf6a24912011-01-24 10:12:37 -05002492static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002493 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002494 int num_pins)
2495{
2496 struct conexant_spec *spec = codec->spec;
2497 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2498 int i;
2499
2500 for (i = 0; i < num_pins; i++, dig_pins++) {
2501 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2502 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2503 continue;
2504 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2505 continue;
2506 if (spec->slave_dig_outs[0])
2507 nid_loc++;
2508 else
2509 nid_loc = spec->slave_dig_outs;
2510 }
2511}
2512
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002513static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002514 .num_items = 4,
2515 .items = {
2516 { "Mic B", 0 },
2517 { "Mic C", 1 },
2518 { "Mic E", 2 },
2519 { "Mic F", 3 },
2520 },
2521};
2522
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002523static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002524 .ops = &snd_hda_bind_vol,
2525 .values = {
2526 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2527 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2528 0
2529 },
2530};
2531
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002532static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002533 .ops = &snd_hda_bind_sw,
2534 .values = {
2535 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2536 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2537 0
2538 },
2539};
2540
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002541static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002542 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2543 {}
2544};
2545
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002546static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002547 {
2548 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2549 .name = "Master Playback Volume",
2550 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2551 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2552 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002553 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002554 .info = snd_hda_mixer_amp_volume_info,
2555 .get = snd_hda_mixer_amp_volume_get,
2556 .put = snd_hda_mixer_amp_volume_put,
2557 .tlv = { .c = snd_hda_mixer_amp_tlv },
2558 /* offset by 28 volume steps to limit minimum gain to -46dB */
2559 .private_value =
2560 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2561 },
2562 {}
2563};
2564
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002565static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002566 {
2567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2568 .name = "DC Mode Enable Switch",
2569 .info = snd_ctl_boolean_mono_info,
2570 .get = cxt5066_olpc_dc_get,
2571 .put = cxt5066_olpc_dc_put,
2572 },
2573 {
2574 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2575 .name = "DC Input Bias Enum",
2576 .info = cxt5066_olpc_dc_bias_enum_info,
2577 .get = cxt5066_olpc_dc_bias_enum_get,
2578 .put = cxt5066_olpc_dc_bias_enum_put,
2579 },
2580 {}
2581};
2582
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002583static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002584 {
2585 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2586 .name = "Master Playback Switch",
2587 .info = cxt_eapd_info,
2588 .get = cxt_eapd_get,
2589 .put = cxt5066_hp_master_sw_put,
2590 .private_value = 0x1d,
2591 },
2592
2593 {
2594 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002595 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002596 .info = cxt5066_mic_boost_mux_enum_info,
2597 .get = cxt5066_mic_boost_mux_enum_get,
2598 .put = cxt5066_mic_boost_mux_enum_put,
2599 },
2600
2601 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2602 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2603 {}
2604};
2605
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002606static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002607 {
2608 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002609 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002610 .info = cxt5066_mic_boost_mux_enum_info,
2611 .get = cxt5066_mic_boost_mux_enum_get,
2612 .put = cxt5066_mic_boost_mux_enum_put,
2613 .private_value = 0x23 | 0x100,
2614 },
2615 {}
2616};
2617
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002618static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002619 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2620 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2621 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2622 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2623
2624 /* Speakers */
2625 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2626 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2627
2628 /* HP, Amp */
2629 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2630 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2631
2632 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2633 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2634
2635 /* DAC1 */
2636 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2637
2638 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2639 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2640 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2641 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2642 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2643 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2644
2645 /* no digital microphone support yet */
2646 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2647
2648 /* Audio input selector */
2649 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2650
2651 /* SPDIF route: PCM */
2652 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2653 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2654
2655 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2656 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2657
2658 /* EAPD */
2659 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2660
2661 /* not handling these yet */
2662 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2663 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2664 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2665 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2666 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2667 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2668 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2669 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2670 { } /* end */
2671};
2672
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002673static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002674 /* Port A: headphones */
2675 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2676 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2677
2678 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002679 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002680
2681 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002682 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002683
2684 /* Port D: unused */
2685 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2686
2687 /* Port E: unused, but has primary EAPD */
2688 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2689 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2690
Daniel Drakec4cfe662010-01-07 13:47:04 +01002691 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002692 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2693
2694 /* Port G: internal speakers */
2695 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2696 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2697
2698 /* DAC1 */
2699 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2700
2701 /* DAC2: unused */
2702 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2703
2704 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2705 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2706 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2707 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2708 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2709 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2710 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2711 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2712 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2713 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2714 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2715 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2716
2717 /* Disable digital microphone port */
2718 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2719
2720 /* Audio input selectors */
2721 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2722 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2723
2724 /* Disable SPDIF */
2725 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2726 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727
2728 /* enable unsolicited events for Port A and B */
2729 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2730 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2731 { } /* end */
2732};
2733
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002734static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002735 /* Port A: headphones */
2736 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2737 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2738
2739 /* Port B: external microphone */
2740 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2741
2742 /* Port C: unused */
2743 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2744
2745 /* Port D: unused */
2746 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2747
2748 /* Port E: unused, but has primary EAPD */
2749 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2750 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2751
2752 /* Port F: unused */
2753 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2754
2755 /* Port G: internal speakers */
2756 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2757 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2758
2759 /* DAC1 */
2760 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2761
2762 /* DAC2: unused */
2763 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2764
2765 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2766 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2767 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2769 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2770 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2771 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2772 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2773 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2774 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2775 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2776 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2777
2778 /* Digital microphone port */
2779 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2780
2781 /* Audio input selectors */
2782 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2783 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2784
2785 /* Disable SPDIF */
2786 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2787 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2788
2789 /* enable unsolicited events for Port A and B */
2790 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2791 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2792 { } /* end */
2793};
2794
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002795static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002796 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2797 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2798 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2799 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2800
2801 /* Speakers */
2802 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2803 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2804
2805 /* HP, Amp */
2806 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2807 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2808
2809 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2810 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2811
2812 /* DAC1 */
2813 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2814
2815 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2817 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2818 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2821 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2822
2823 /* Audio input selector */
2824 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2825 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2826
2827 /* SPDIF route: PCM */
2828 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2829 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2830
2831 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2832 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2833
2834 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002835 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002836
2837 /* EAPD */
2838 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2839
2840 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2841 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2842 { } /* end */
2843};
2844
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002845static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002846 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2847 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2848
2849 /* Port G: internal speakers */
2850 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2851 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2852
2853 /* Port A: HP, Amp */
2854 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2856
2857 /* Port B: Mic Dock */
2858 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2859
2860 /* Port C: Mic */
2861 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2862
2863 /* Port D: HP Dock, Amp */
2864 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2865 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2866
2867 /* DAC1 */
2868 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2869
2870 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2871 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2872 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2873 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2874 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2876 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2877
2878 /* Audio input selector */
2879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2880 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2881
2882 /* SPDIF route: PCM */
2883 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2884 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2885
2886 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2887 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2888
2889 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002890 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002891
2892 /* EAPD */
2893 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2894
2895 /* enable unsolicited events for Port A, B, C and D */
2896 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2897 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2898 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2899 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2900 { } /* end */
2901};
2902
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002903static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002904 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2905 { } /* end */
2906};
2907
David Henningsson048e78a2010-09-02 08:35:47 +02002908
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002909static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002910 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2911 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2912 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2913 { } /* end */
2914};
2915
Daniel Drake0fb67e92009-07-16 14:46:57 +01002916/* initialize jack-sensing, too */
2917static int cxt5066_init(struct hda_codec *codec)
2918{
2919 snd_printdd("CXT5066: init\n");
2920 conexant_init(codec);
2921 if (codec->patch_ops.unsol_event) {
2922 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002923 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002924 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002925 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002926 return 0;
2927}
2928
Daniel Drake75f89912010-01-07 13:46:25 +01002929static int cxt5066_olpc_init(struct hda_codec *codec)
2930{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002931 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002932 snd_printdd("CXT5066: init\n");
2933 conexant_init(codec);
2934 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002935 if (!spec->dc_enable) {
2936 cxt5066_set_mic_boost(codec);
2937 cxt5066_olpc_automic(codec);
2938 } else {
2939 cxt5066_enable_dc(codec);
2940 }
Daniel Drake75f89912010-01-07 13:46:25 +01002941 return 0;
2942}
2943
Daniel Drake0fb67e92009-07-16 14:46:57 +01002944enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002945 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002946 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2947 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002948 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002949 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002950 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002951 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002952 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002953 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002954 CXT5066_MODELS
2955};
2956
Takashi Iwaiea734962011-01-17 11:29:34 +01002957static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002958 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002959 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2960 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002961 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002962 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002963 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002964 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002965 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002966 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002967};
2968
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002969static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002970 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002971 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002972 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002973 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002974 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002975 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2976 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002977 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002978 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002979 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002980 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002981 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002982 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002983 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2984 CXT5066_LAPTOP),
2985 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002986 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002987 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002988 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson84012652011-03-31 09:36:19 +02002989 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002990 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002991 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002992 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002993 {}
2994};
2995
2996static int patch_cxt5066(struct hda_codec *codec)
2997{
2998 struct conexant_spec *spec;
2999 int board_config;
3000
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003001 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3002 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003003 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003004 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003005 if (board_config == CXT5066_AUTO)
3006 return patch_conexant_auto(codec);
3007
Daniel Drake0fb67e92009-07-16 14:46:57 +01003008 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3009 if (!spec)
3010 return -ENOMEM;
3011 codec->spec = spec;
3012
3013 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003014 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003015
3016 spec->dell_automute = 0;
3017 spec->multiout.max_channels = 2;
3018 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3019 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003020 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3021 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003022 spec->num_adc_nids = 1;
3023 spec->adc_nids = cxt5066_adc_nids;
3024 spec->capsrc_nids = cxt5066_capsrc_nids;
3025 spec->input_mux = &cxt5066_capture_source;
3026
3027 spec->port_d_mode = PIN_HP;
3028
3029 spec->num_init_verbs = 1;
3030 spec->init_verbs[0] = cxt5066_init_verbs;
3031 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3032 spec->channel_mode = cxt5066_modes;
3033 spec->cur_adc = 0;
3034 spec->cur_adc_idx = 0;
3035
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003036 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3037
Daniel Drake0fb67e92009-07-16 14:46:57 +01003038 switch (board_config) {
3039 default:
3040 case CXT5066_LAPTOP:
3041 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3042 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3043 break;
3044 case CXT5066_DELL_LAPTOP:
3045 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3046 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3047
3048 spec->port_d_mode = PIN_OUT;
3049 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3050 spec->num_init_verbs++;
3051 spec->dell_automute = 1;
3052 break;
David Henningssona1d69062011-01-21 13:33:28 +01003053 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003054 case CXT5066_HP_LAPTOP:
3055 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003056 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003057 spec->init_verbs[spec->num_init_verbs] =
3058 cxt5066_init_verbs_hp_laptop;
3059 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003060 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3061 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003062 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3063 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3064 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003065 if (board_config == CXT5066_HP_LAPTOP)
3066 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003067 /* input source automatically selected */
3068 spec->input_mux = NULL;
3069 spec->port_d_mode = 0;
3070 spec->mic_boost = 3; /* default 30dB gain */
3071 break;
3072
Daniel Drake0fb67e92009-07-16 14:46:57 +01003073 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003074 codec->patch_ops.init = cxt5066_olpc_init;
3075 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003076 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3077 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003078 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003079 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3080 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003081 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003082
3083 /* no S/PDIF out */
3084 spec->multiout.dig_out_nid = 0;
3085
3086 /* input source automatically selected */
3087 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003088
3089 /* our capture hooks which allow us to turn on the microphone LED
3090 * at the right time */
3091 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3092 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003093 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003094 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003095 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003096 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003097 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3098 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3099 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003100 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003101 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003102 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003103 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003104
3105 /* no S/PDIF out */
3106 spec->multiout.dig_out_nid = 0;
3107
3108 /* input source automatically selected */
3109 spec->input_mux = NULL;
3110 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003111 case CXT5066_IDEAPAD:
3112 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003113 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003114 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3115 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3116 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3117 spec->port_d_mode = 0;
3118 spec->ideapad = 1;
3119 spec->mic_boost = 2; /* default 20dB gain */
3120
3121 /* no S/PDIF out */
3122 spec->multiout.dig_out_nid = 0;
3123
3124 /* input source automatically selected */
3125 spec->input_mux = NULL;
3126 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003127 case CXT5066_THINKPAD:
3128 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003129 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003130 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3131 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3132 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3133 spec->thinkpad = 1;
3134 spec->port_d_mode = PIN_OUT;
3135 spec->mic_boost = 2; /* default 20dB gain */
3136
3137 /* no S/PDIF out */
3138 spec->multiout.dig_out_nid = 0;
3139
3140 /* input source automatically selected */
3141 spec->input_mux = NULL;
3142 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003143 }
3144
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003145 if (spec->beep_amp)
3146 snd_hda_attach_beep_device(codec, spec->beep_amp);
3147
Daniel Drake0fb67e92009-07-16 14:46:57 +01003148 return 0;
3149}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003150
3151/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003152 * Automatic parser for CX20641 & co
3153 */
3154
Takashi Iwai6764bce2011-05-13 16:52:25 +02003155static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3156 struct hda_codec *codec,
3157 unsigned int stream_tag,
3158 unsigned int format,
3159 struct snd_pcm_substream *substream)
3160{
3161 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003162 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003163 if (spec->adc_switching) {
3164 spec->cur_adc = adc;
3165 spec->cur_adc_stream_tag = stream_tag;
3166 spec->cur_adc_format = format;
3167 }
3168 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3169 return 0;
3170}
3171
3172static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3173 struct hda_codec *codec,
3174 struct snd_pcm_substream *substream)
3175{
3176 struct conexant_spec *spec = codec->spec;
3177 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3178 spec->cur_adc = 0;
3179 return 0;
3180}
3181
3182static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3183 .substreams = 1,
3184 .channels_min = 2,
3185 .channels_max = 2,
3186 .nid = 0, /* fill later */
3187 .ops = {
3188 .prepare = cx_auto_capture_pcm_prepare,
3189 .cleanup = cx_auto_capture_pcm_cleanup
3190 },
3191};
3192
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003193static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003194
Takashi Iwai8d087c72011-06-28 12:45:47 +02003195#define get_connection_index(codec, mux, nid)\
3196 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003197
3198/* get an unassigned DAC from the given list.
3199 * Return the nid if found and reduce the DAC list, or return zero if
3200 * not found
3201 */
3202static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3203 hda_nid_t *dacs, int *num_dacs)
3204{
3205 int i, nums = *num_dacs;
3206 hda_nid_t ret = 0;
3207
3208 for (i = 0; i < nums; i++) {
3209 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3210 ret = dacs[i];
3211 break;
3212 }
3213 }
3214 if (!ret)
3215 return 0;
3216 if (--nums > 0)
3217 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3218 *num_dacs = nums;
3219 return ret;
3220}
3221
3222#define MAX_AUTO_DACS 5
3223
Takashi Iwai1f015f52011-08-23 14:57:08 +02003224#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3225
Takashi Iwaif2e57312010-09-15 10:07:08 +02003226/* fill analog DAC list from the widget tree */
3227static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3228{
3229 hda_nid_t nid, end_nid;
3230 int nums = 0;
3231
3232 end_nid = codec->start_nid + codec->num_nodes;
3233 for (nid = codec->start_nid; nid < end_nid; nid++) {
3234 unsigned int wcaps = get_wcaps(codec, nid);
3235 unsigned int type = get_wcaps_type(wcaps);
3236 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3237 dacs[nums++] = nid;
3238 if (nums >= MAX_AUTO_DACS)
3239 break;
3240 }
3241 }
3242 return nums;
3243}
3244
3245/* fill pin_dac_pair list from the pin and dac list */
3246static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3247 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003248 struct pin_dac_pair *filled, int nums,
3249 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003250{
David Henningsson468c5452011-08-25 13:16:02 +02003251 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003252
David Henningsson468c5452011-08-25 13:16:02 +02003253 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003254 filled[nums].pin = pins[i];
3255 filled[nums].type = type;
3256 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003257 if (filled[nums].dac)
3258 continue;
3259 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3260 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3261 continue;
3262 }
3263 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003264 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003265 continue;
3266 }
3267 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003268 }
3269 return nums;
3270}
3271
3272/* parse analog output paths */
3273static void cx_auto_parse_output(struct hda_codec *codec)
3274{
3275 struct conexant_spec *spec = codec->spec;
3276 struct auto_pin_cfg *cfg = &spec->autocfg;
3277 hda_nid_t dacs[MAX_AUTO_DACS];
3278 int i, j, nums, rest;
3279
3280 rest = fill_cx_auto_dacs(codec, dacs);
3281 /* parse all analog output pins */
3282 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003283 dacs, &rest, spec->dac_info, 0,
3284 AUTO_PIN_LINE_OUT);
3285 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3286 dacs, &rest, spec->dac_info, nums,
3287 AUTO_PIN_HP_OUT);
3288 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3289 dacs, &rest, spec->dac_info, nums,
3290 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003291 spec->dac_info_filled = nums;
3292 /* fill multiout struct */
3293 for (i = 0; i < nums; i++) {
3294 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003295 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003296 continue;
3297 switch (spec->dac_info[i].type) {
3298 case AUTO_PIN_LINE_OUT:
3299 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3300 spec->multiout.num_dacs++;
3301 break;
3302 case AUTO_PIN_HP_OUT:
3303 case AUTO_PIN_SPEAKER_OUT:
3304 if (!spec->multiout.hp_nid) {
3305 spec->multiout.hp_nid = dac;
3306 break;
3307 }
3308 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3309 if (!spec->multiout.extra_out_nid[j]) {
3310 spec->multiout.extra_out_nid[j] = dac;
3311 break;
3312 }
3313 break;
3314 }
3315 }
3316 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003317 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003318
Takashi Iwai03697e22011-05-17 09:53:31 +02003319 for (i = 0; i < cfg->hp_outs; i++) {
3320 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3321 spec->auto_mute = 1;
3322 break;
3323 }
3324 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003325 if (spec->auto_mute &&
3326 cfg->line_out_pins[0] &&
3327 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003328 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3329 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3330 for (i = 0; i < cfg->line_outs; i++) {
3331 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3332 spec->detect_line = 1;
3333 break;
3334 }
3335 }
3336 spec->automute_lines = spec->detect_line;
3337 }
3338
Takashi Iwaif2e57312010-09-15 10:07:08 +02003339 spec->vmaster_nid = spec->private_dac_nids[0];
3340}
3341
Takashi Iwaida339862011-05-13 16:24:15 +02003342static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3343 hda_nid_t *pins, bool on);
3344
Takashi Iwai03697e22011-05-17 09:53:31 +02003345static void do_automute(struct hda_codec *codec, int num_pins,
3346 hda_nid_t *pins, bool on)
3347{
Takashi Iwai254f2962011-10-14 15:22:34 +02003348 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003349 int i;
3350 for (i = 0; i < num_pins; i++)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003351 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003352 if (spec->pin_eapd_ctrls)
3353 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003354}
3355
3356static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3357{
3358 int i, present = 0;
3359
3360 for (i = 0; i < num_pins; i++) {
3361 hda_nid_t nid = pins[i];
3362 if (!nid || !is_jack_detectable(codec, nid))
3363 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003364 present |= snd_hda_jack_detect(codec, nid);
3365 }
3366 return present;
3367}
3368
Takashi Iwaif2e57312010-09-15 10:07:08 +02003369/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003370static void cx_auto_update_speakers(struct hda_codec *codec)
3371{
3372 struct conexant_spec *spec = codec->spec;
3373 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003374 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003375
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003376 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003377 if (spec->pin_eapd_ctrls) {
3378 if (spec->auto_mute)
3379 on = spec->hp_present;
3380 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3381 }
3382
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003383 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3384 if (spec->auto_mute)
3385 on = !(spec->hp_present ||
3386 (spec->detect_line && spec->line_present));
3387 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003388
3389 /* toggle line-out mutes if needed, too */
3390 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3391 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3392 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3393 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003394 if (spec->auto_mute) {
3395 /* mute LO in auto-mode when HP jack is present */
3396 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3397 spec->automute_lines)
3398 on = !spec->hp_present;
3399 else
3400 on = 1;
3401 }
3402 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003403}
3404
David Henningsson29adc4b2012-09-25 11:31:00 +02003405static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003406{
3407 struct conexant_spec *spec = codec->spec;
3408 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003409
3410 if (!spec->auto_mute)
3411 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003412 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3413 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003414}
3415
David Henningsson29adc4b2012-09-25 11:31:00 +02003416static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwai03697e22011-05-17 09:53:31 +02003417{
3418 struct conexant_spec *spec = codec->spec;
3419 struct auto_pin_cfg *cfg = &spec->autocfg;
3420
3421 if (!spec->auto_mute || !spec->detect_line)
3422 return;
3423 spec->line_present = detect_jacks(codec, cfg->line_outs,
3424 cfg->line_out_pins);
3425 cx_auto_update_speakers(codec);
3426}
3427
3428static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3429 struct snd_ctl_elem_info *uinfo)
3430{
3431 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3432 struct conexant_spec *spec = codec->spec;
3433 static const char * const texts2[] = {
3434 "Disabled", "Enabled"
3435 };
3436 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003437 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003438 };
3439 const char * const *texts;
3440
3441 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3442 uinfo->count = 1;
3443 if (spec->automute_hp_lo) {
3444 uinfo->value.enumerated.items = 3;
3445 texts = texts3;
3446 } else {
3447 uinfo->value.enumerated.items = 2;
3448 texts = texts2;
3449 }
3450 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3451 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3452 strcpy(uinfo->value.enumerated.name,
3453 texts[uinfo->value.enumerated.item]);
3454 return 0;
3455}
3456
3457static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3458 struct snd_ctl_elem_value *ucontrol)
3459{
3460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3461 struct conexant_spec *spec = codec->spec;
3462 unsigned int val;
3463 if (!spec->auto_mute)
3464 val = 0;
3465 else if (!spec->automute_lines)
3466 val = 1;
3467 else
3468 val = 2;
3469 ucontrol->value.enumerated.item[0] = val;
3470 return 0;
3471}
3472
3473static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3474 struct snd_ctl_elem_value *ucontrol)
3475{
3476 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3477 struct conexant_spec *spec = codec->spec;
3478
3479 switch (ucontrol->value.enumerated.item[0]) {
3480 case 0:
3481 if (!spec->auto_mute)
3482 return 0;
3483 spec->auto_mute = 0;
3484 break;
3485 case 1:
3486 if (spec->auto_mute && !spec->automute_lines)
3487 return 0;
3488 spec->auto_mute = 1;
3489 spec->automute_lines = 0;
3490 break;
3491 case 2:
3492 if (!spec->automute_hp_lo)
3493 return -EINVAL;
3494 if (spec->auto_mute && spec->automute_lines)
3495 return 0;
3496 spec->auto_mute = 1;
3497 spec->automute_lines = 1;
3498 break;
3499 default:
3500 return -EINVAL;
3501 }
3502 cx_auto_update_speakers(codec);
3503 return 1;
3504}
3505
3506static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3507 {
3508 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3509 .name = "Auto-Mute Mode",
3510 .info = cx_automute_mode_info,
3511 .get = cx_automute_mode_get,
3512 .put = cx_automute_mode_put,
3513 },
3514 { }
3515};
3516
Takashi Iwai6764bce2011-05-13 16:52:25 +02003517static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3518 struct snd_ctl_elem_info *uinfo)
3519{
3520 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3521 struct conexant_spec *spec = codec->spec;
3522
3523 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3524}
3525
3526static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3527 struct snd_ctl_elem_value *ucontrol)
3528{
3529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3530 struct conexant_spec *spec = codec->spec;
3531
3532 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3533 return 0;
3534}
3535
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003536/* look for the route the given pin from mux and return the index;
3537 * if do_select is set, actually select the route.
3538 */
3539static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003540 hda_nid_t pin, hda_nid_t *srcp,
3541 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003542{
David Henningsson739572a2012-09-20 15:41:21 +02003543 struct conexant_spec *spec = codec->spec;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003544 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
David Henningsson739572a2012-09-20 15:41:21 +02003545 int startidx, i, nums;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003546
Takashi Iwaicf27f292011-05-16 11:33:02 +02003547 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3548 case AC_WID_AUD_IN:
3549 case AC_WID_AUD_SEL:
3550 case AC_WID_AUD_MIX:
3551 break;
3552 default:
3553 return -1;
3554 }
3555
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003556 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3557 for (i = 0; i < nums; i++)
3558 if (conn[i] == pin) {
3559 if (do_select)
3560 snd_hda_codec_write(codec, mux, 0,
3561 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003562 if (srcp)
3563 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003564 return i;
3565 }
3566 depth++;
3567 if (depth == 2)
3568 return -1;
David Henningsson739572a2012-09-20 15:41:21 +02003569
3570 /* Try to rotate around connections to avoid one boost controlling
3571 another input path as well */
3572 startidx = 0;
3573 for (i = 0; i < spec->private_imux.num_items; i++)
3574 if (spec->imux_info[i].pin == pin) {
3575 startidx = i;
3576 break;
3577 }
3578
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003579 for (i = 0; i < nums; i++) {
David Henningsson739572a2012-09-20 15:41:21 +02003580 int j = (i + startidx) % nums;
3581 int ret = __select_input_connection(codec, conn[j], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003582 do_select, depth);
3583 if (ret >= 0) {
3584 if (do_select)
3585 snd_hda_codec_write(codec, mux, 0,
David Henningsson739572a2012-09-20 15:41:21 +02003586 AC_VERB_SET_CONNECT_SEL, j);
3587 return j;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003588 }
3589 }
3590 return -1;
3591}
3592
3593static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3594 hda_nid_t pin)
3595{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003596 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003597}
3598
3599static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3600 hda_nid_t pin)
3601{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003602 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003603}
3604
Takashi Iwai6764bce2011-05-13 16:52:25 +02003605static int cx_auto_mux_enum_update(struct hda_codec *codec,
3606 const struct hda_input_mux *imux,
3607 unsigned int idx)
3608{
3609 struct conexant_spec *spec = codec->spec;
3610 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003611 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003612
3613 if (!imux->num_items)
3614 return 0;
3615 if (idx >= imux->num_items)
3616 idx = imux->num_items - 1;
3617 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003618 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003619 adc = spec->imux_info[idx].adc;
3620 select_input_connection(codec, spec->imux_info[idx].adc,
3621 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003622 if (spec->cur_adc && spec->cur_adc != adc) {
3623 /* stream is running, let's swap the current ADC */
3624 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3625 spec->cur_adc = adc;
3626 snd_hda_codec_setup_stream(codec, adc,
3627 spec->cur_adc_stream_tag, 0,
3628 spec->cur_adc_format);
3629 }
3630 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003631 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003632}
3633
3634static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3635 struct snd_ctl_elem_value *ucontrol)
3636{
3637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3638 struct conexant_spec *spec = codec->spec;
3639
3640 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3641 ucontrol->value.enumerated.item[0]);
3642}
3643
3644static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3645 {
3646 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3647 .name = "Capture Source",
3648 .info = cx_auto_mux_enum_info,
3649 .get = cx_auto_mux_enum_get,
3650 .put = cx_auto_mux_enum_put
3651 },
3652 {}
3653};
3654
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003655static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3656{
3657 struct conexant_spec *spec = codec->spec;
3658 if (idx < 0)
3659 return false;
3660 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3661 return false;
3662 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3663 return true;
3664}
3665
Takashi Iwaif2e57312010-09-15 10:07:08 +02003666/* automatic switch internal and external mic */
David Henningsson29adc4b2012-09-25 11:31:00 +02003667static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003668{
3669 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003670
3671 if (!spec->auto_mic)
3672 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003673 if (!select_automic(codec, spec->auto_mic_ext, true))
3674 if (!select_automic(codec, spec->auto_mic_dock, true))
3675 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003676}
3677
Takashi Iwaif2e57312010-09-15 10:07:08 +02003678/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003679 * auto-mic is enabled only when one int-mic and one ext- and/or
3680 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003681 */
3682static void cx_auto_check_auto_mic(struct hda_codec *codec)
3683{
3684 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003685 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3686 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003687
Takashi Iwai506a4192011-05-23 20:07:15 +02003688 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003689 pset[i] = -1;
3690 for (i = 0; i < spec->private_imux.num_items; i++) {
3691 hda_nid_t pin = spec->imux_info[i].pin;
3692 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003693 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003694 attr = snd_hda_get_input_pin_attr(def_conf);
3695 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003696 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003697 if (attr > INPUT_PIN_ATTR_NORMAL)
3698 attr = INPUT_PIN_ATTR_NORMAL;
3699 if (attr != INPUT_PIN_ATTR_INT &&
3700 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003701 return; /* non-detectable pin */
3702 type = get_defcfg_device(def_conf);
3703 if (type != AC_JACK_MIC_IN &&
3704 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3705 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003706 if (pset[attr] >= 0)
3707 return; /* already occupied */
3708 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003709 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003710 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3711 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3712 return; /* no input to switch*/
3713 spec->auto_mic = 1;
3714 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3715 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3716 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003717}
3718
3719static void cx_auto_parse_input(struct hda_codec *codec)
3720{
3721 struct conexant_spec *spec = codec->spec;
3722 struct auto_pin_cfg *cfg = &spec->autocfg;
3723 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003724 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003725
3726 imux = &spec->private_imux;
3727 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003728 for (j = 0; j < spec->num_adc_nids; j++) {
3729 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003730 int idx = get_input_connection(codec, adc,
3731 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003732 if (idx >= 0) {
3733 const char *label;
3734 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003735 spec->imux_info[imux->num_items].index = i;
3736 spec->imux_info[imux->num_items].boost = 0;
3737 spec->imux_info[imux->num_items].adc = adc;
3738 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003739 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003740 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003741 break;
3742 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003743 }
3744 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003745 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003746 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003747 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003748 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003749 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003750 spec->adc_switching = 1;
3751 break;
3752 }
3753 }
3754 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003755}
3756
3757/* get digital-input audio widget corresponding to the given pin */
3758static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3759{
3760 hda_nid_t nid, end_nid;
3761
3762 end_nid = codec->start_nid + codec->num_nodes;
3763 for (nid = codec->start_nid; nid < end_nid; nid++) {
3764 unsigned int wcaps = get_wcaps(codec, nid);
3765 unsigned int type = get_wcaps_type(wcaps);
3766 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3767 if (get_connection_index(codec, nid, pin) >= 0)
3768 return nid;
3769 }
3770 }
3771 return 0;
3772}
3773
3774static void cx_auto_parse_digital(struct hda_codec *codec)
3775{
3776 struct conexant_spec *spec = codec->spec;
3777 struct auto_pin_cfg *cfg = &spec->autocfg;
3778 hda_nid_t nid;
3779
3780 if (cfg->dig_outs &&
3781 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3782 spec->multiout.dig_out_nid = nid;
3783 if (cfg->dig_in_pin)
3784 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3785}
3786
3787#ifdef CONFIG_SND_HDA_INPUT_BEEP
3788static void cx_auto_parse_beep(struct hda_codec *codec)
3789{
3790 struct conexant_spec *spec = codec->spec;
3791 hda_nid_t nid, end_nid;
3792
3793 end_nid = codec->start_nid + codec->num_nodes;
3794 for (nid = codec->start_nid; nid < end_nid; nid++)
3795 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3796 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3797 break;
3798 }
3799}
3800#else
3801#define cx_auto_parse_beep(codec)
3802#endif
3803
Takashi Iwai254f2962011-10-14 15:22:34 +02003804/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003805static void cx_auto_parse_eapd(struct hda_codec *codec)
3806{
3807 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003808 hda_nid_t nid, end_nid;
3809
3810 end_nid = codec->start_nid + codec->num_nodes;
3811 for (nid = codec->start_nid; nid < end_nid; nid++) {
3812 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3813 continue;
3814 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3815 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003816 spec->eapds[spec->num_eapds++] = nid;
3817 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3818 break;
3819 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003820
3821 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3822 * it's a new chip, where EAPDs are supposed to be associated to
3823 * pins, and we can control EAPD per pin.
3824 * OTOH, if only one or two EAPDs are found, it's an old chip,
3825 * thus it might control over all pins.
3826 */
3827 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003828}
3829
Takashi Iwaif2e57312010-09-15 10:07:08 +02003830static int cx_auto_parse_auto_config(struct hda_codec *codec)
3831{
3832 struct conexant_spec *spec = codec->spec;
3833 int err;
3834
3835 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3836 if (err < 0)
3837 return err;
3838
3839 cx_auto_parse_output(codec);
3840 cx_auto_parse_input(codec);
3841 cx_auto_parse_digital(codec);
3842 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003843 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003844 return 0;
3845}
3846
Takashi Iwaida339862011-05-13 16:24:15 +02003847static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3848 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003849{
3850 int i;
3851 for (i = 0; i < num_pins; i++) {
3852 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3853 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003854 AC_VERB_SET_EAPD_BTLENABLE,
3855 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003856 }
3857}
3858
3859static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3860 hda_nid_t src)
3861{
3862 int idx = get_connection_index(codec, pin, src);
3863 if (idx >= 0)
3864 snd_hda_codec_write(codec, pin, 0,
3865 AC_VERB_SET_CONNECT_SEL, idx);
3866}
3867
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003868static void mute_outputs(struct hda_codec *codec, int num_nids,
3869 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003870{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003871 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003872
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003873 for (i = 0; i < num_nids; i++) {
3874 hda_nid_t nid = nids[i];
3875 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3876 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003877 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3878 val = AMP_OUT_MUTE;
3879 else
3880 val = AMP_OUT_ZERO;
3881 snd_hda_codec_write(codec, nid, 0,
3882 AC_VERB_SET_AMP_GAIN_MUTE, val);
3883 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003884}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003885
Takashi Iwai03697e22011-05-17 09:53:31 +02003886static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003887 hda_nid_t *pins, unsigned int action,
3888 hda_jack_callback cb)
Takashi Iwai03697e22011-05-17 09:53:31 +02003889{
3890 int i;
3891 for (i = 0; i < num_pins; i++)
David Henningsson29adc4b2012-09-25 11:31:00 +02003892 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb);
Takashi Iwai03697e22011-05-17 09:53:31 +02003893}
3894
Takashi Iwai07cafff2012-02-20 12:30:59 +01003895static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3896{
3897 int i;
3898 for (i = 0; i < nums; i++)
3899 if (list[i] == nid)
3900 return true;
3901 return false;
3902}
3903
3904/* is the given NID found in any of autocfg items? */
3905static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3906{
3907 int i;
3908
3909 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3910 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3911 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3912 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3913 return true;
3914 for (i = 0; i < cfg->num_inputs; i++)
3915 if (cfg->inputs[i].pin == nid)
3916 return true;
3917 if (cfg->dig_in_pin == nid)
3918 return true;
3919 return false;
3920}
3921
3922/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3923 * invalid unsol tags by some reason
3924 */
3925static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3926{
3927 struct conexant_spec *spec = codec->spec;
3928 struct auto_pin_cfg *cfg = &spec->autocfg;
3929 int i;
3930
3931 for (i = 0; i < codec->init_pins.used; i++) {
3932 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3933 if (!found_in_autocfg(cfg, pin->nid))
3934 snd_hda_codec_write(codec, pin->nid, 0,
3935 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3936 }
3937}
3938
Takashi Iwai527c73b2012-03-12 12:38:51 +01003939/* turn on/off EAPD according to Master switch */
3940static void cx_auto_vmaster_hook(void *private_data, int enabled)
3941{
3942 struct hda_codec *codec = private_data;
3943 struct conexant_spec *spec = codec->spec;
3944
3945 if (enabled && spec->pin_eapd_ctrls) {
3946 cx_auto_update_speakers(codec);
3947 return;
3948 }
3949 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3950}
3951
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003952static void cx_auto_init_output(struct hda_codec *codec)
3953{
3954 struct conexant_spec *spec = codec->spec;
3955 struct auto_pin_cfg *cfg = &spec->autocfg;
3956 hda_nid_t nid;
3957 int i;
3958
3959 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003960 for (i = 0; i < cfg->hp_outs; i++) {
3961 unsigned int val = PIN_OUT;
3962 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3963 AC_PINCAP_HP_DRV)
3964 val |= AC_PINCTL_HP_EN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003965 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003966 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003967 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3968 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3969 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003970 for (i = 0; i < spec->dac_info_filled; i++) {
3971 nid = spec->dac_info[i].dac;
3972 if (!nid)
3973 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003974 else if (nid & DAC_SLAVE_FLAG)
3975 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003976 select_connection(codec, spec->dac_info[i].pin, nid);
3977 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003978 if (spec->auto_mute) {
3979 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003980 CONEXANT_HP_EVENT, cx_auto_hp_automute);
Takashi Iwai03697e22011-05-17 09:53:31 +02003981 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3982 cfg->hp_pins);
3983 if (spec->detect_line) {
3984 enable_unsol_pins(codec, cfg->line_outs,
3985 cfg->line_out_pins,
David Henningsson29adc4b2012-09-25 11:31:00 +02003986 CONEXANT_LINE_EVENT,
3987 cx_auto_line_automute);
Takashi Iwai03697e22011-05-17 09:53:31 +02003988 spec->line_present =
3989 detect_jacks(codec, cfg->line_outs,
3990 cfg->line_out_pins);
3991 }
3992 }
3993 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02003994 /* turn on all EAPDs if no individual EAPD control is available */
3995 if (!spec->pin_eapd_ctrls)
3996 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01003997 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003998}
3999
4000static void cx_auto_init_input(struct hda_codec *codec)
4001{
4002 struct conexant_spec *spec = codec->spec;
4003 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004004 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004005
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004006 for (i = 0; i < spec->num_adc_nids; i++) {
4007 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004008 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4009 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004010 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4011 val = AMP_IN_MUTE(0);
4012 else
4013 val = AMP_IN_UNMUTE(0);
4014 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4015 val);
4016 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004017
4018 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai47408602012-04-20 13:06:53 +02004019 hda_nid_t pin = cfg->inputs[i].pin;
4020 unsigned int type = PIN_IN;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004021 if (cfg->inputs[i].type == AUTO_PIN_MIC)
Takashi Iwai47408602012-04-20 13:06:53 +02004022 type |= snd_hda_get_default_vref(codec, pin);
4023 snd_hda_set_pin_ctl(codec, pin, type);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004024 }
4025
4026 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004027 if (spec->auto_mic_ext >= 0) {
David Henningsson29adc4b2012-09-25 11:31:00 +02004028 snd_hda_jack_detect_enable_callback(codec,
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004029 cfg->inputs[spec->auto_mic_ext].pin,
David Henningsson29adc4b2012-09-25 11:31:00 +02004030 CONEXANT_MIC_EVENT, cx_auto_automic);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004031 }
4032 if (spec->auto_mic_dock >= 0) {
David Henningsson29adc4b2012-09-25 11:31:00 +02004033 snd_hda_jack_detect_enable_callback(codec,
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004034 cfg->inputs[spec->auto_mic_dock].pin,
David Henningsson29adc4b2012-09-25 11:31:00 +02004035 CONEXANT_MIC_EVENT, cx_auto_automic);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004036 }
David Henningsson29adc4b2012-09-25 11:31:00 +02004037 cx_auto_automic(codec, NULL);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004038 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004039 select_input_connection(codec, spec->imux_info[0].adc,
4040 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004041 }
4042}
4043
4044static void cx_auto_init_digital(struct hda_codec *codec)
4045{
4046 struct conexant_spec *spec = codec->spec;
4047 struct auto_pin_cfg *cfg = &spec->autocfg;
4048
4049 if (spec->multiout.dig_out_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004050 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004051 if (spec->dig_in_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004052 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004053}
4054
4055static int cx_auto_init(struct hda_codec *codec)
4056{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004057 struct conexant_spec *spec = codec->spec;
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02004058 snd_hda_gen_apply_verbs(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004059 cx_auto_init_output(codec);
4060 cx_auto_init_input(codec);
4061 cx_auto_init_digital(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004062 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004063 return 0;
4064}
4065
David Henningsson983345e2011-02-15 19:57:09 +01004066static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004067 const char *dir, int cidx,
David Henningsson18dcd302012-04-02 15:40:27 +02004068 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004069{
David Henningsson18dcd302012-04-02 15:40:27 +02004070 static char name[44];
Takashi Iwaif2e57312010-09-15 10:07:08 +02004071 static struct snd_kcontrol_new knew[] = {
4072 HDA_CODEC_VOLUME(name, 0, 0, 0),
4073 HDA_CODEC_MUTE(name, 0, 0, 0),
4074 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004075 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004076 int i, err;
4077
4078 for (i = 0; i < 2; i++) {
4079 struct snd_kcontrol *kctl;
David Henningsson18dcd302012-04-02 15:40:27 +02004080 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
David Henningsson983345e2011-02-15 19:57:09 +01004081 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004082 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4083 knew[i].index = cidx;
4084 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4085 kctl = snd_ctl_new1(&knew[i], codec);
4086 if (!kctl)
4087 return -ENOMEM;
4088 err = snd_hda_ctl_add(codec, nid, kctl);
4089 if (err < 0)
4090 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004091 if (!(query_amp_caps(codec, nid, hda_dir) &
4092 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004093 break;
4094 }
4095 return 0;
4096}
4097
David Henningsson983345e2011-02-15 19:57:09 +01004098#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
David Henningsson18dcd302012-04-02 15:40:27 +02004099 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
David Henningsson983345e2011-02-15 19:57:09 +01004100
Takashi Iwaif2e57312010-09-15 10:07:08 +02004101#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4102 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4103
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004104static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4105 hda_nid_t pin, const char *name, int idx)
4106{
4107 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004108 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4109 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4110 if (caps & AC_AMPCAP_NUM_STEPS)
4111 return cx_auto_add_pb_volume(codec, dac, name, idx);
4112 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004113 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4114 if (caps & AC_AMPCAP_NUM_STEPS)
4115 return cx_auto_add_pb_volume(codec, pin, name, idx);
4116 return 0;
4117}
4118
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004119static bool is_2_1_speaker(struct conexant_spec *spec)
4120{
4121 int i, type, num_spk = 0;
4122
4123 for (i = 0; i < spec->dac_info_filled; i++) {
4124 type = spec->dac_info[i].type;
4125 if (type == AUTO_PIN_LINE_OUT)
4126 type = spec->autocfg.line_out_type;
4127 if (type == AUTO_PIN_SPEAKER_OUT)
4128 num_spk++;
4129 }
4130 return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT);
4131}
4132
Takashi Iwaif2e57312010-09-15 10:07:08 +02004133static int cx_auto_build_output_controls(struct hda_codec *codec)
4134{
4135 struct conexant_spec *spec = codec->spec;
4136 int i, err;
4137 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004138 bool speaker_2_1;
Takashi Iwaiea734962011-01-17 11:29:34 +01004139 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004140
4141 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004142 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4143 spec->dac_info[0].pin,
4144 "Master", 0);
4145
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004146 speaker_2_1 = is_2_1_speaker(spec);
4147
Takashi Iwaif2e57312010-09-15 10:07:08 +02004148 for (i = 0; i < spec->dac_info_filled; i++) {
4149 const char *label;
4150 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004151 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004152 type = spec->dac_info[i].type;
4153 if (type == AUTO_PIN_LINE_OUT)
4154 type = spec->autocfg.line_out_type;
4155 switch (type) {
4156 case AUTO_PIN_LINE_OUT:
4157 default:
4158 label = texts[num_line++];
4159 idx = 0;
4160 break;
4161 case AUTO_PIN_HP_OUT:
4162 label = "Headphone";
4163 idx = num_hp++;
4164 break;
4165 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01004166 if (speaker_2_1) {
4167 label = num_spk++ ? "Bass Speaker" : "Speaker";
4168 idx = 0;
4169 } else {
4170 label = "Speaker";
4171 idx = num_spk++;
4172 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004173 break;
4174 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004175 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004176 spec->dac_info[i].pin,
4177 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004178 if (err < 0)
4179 return err;
4180 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004181
4182 if (spec->auto_mute) {
4183 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4184 if (err < 0)
4185 return err;
4186 }
4187
Takashi Iwaif2e57312010-09-15 10:07:08 +02004188 return 0;
4189}
4190
David Henningsson18dcd302012-04-02 15:40:27 +02004191/* Returns zero if this is a normal stereo channel, and non-zero if it should
4192 be split in two independent channels.
4193 dest_label must be at least 44 characters. */
4194static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4195 char *dest_label, int nid)
4196{
4197 struct conexant_spec *spec = codec->spec;
4198 int i;
4199
4200 if (!spec->fixup_stereo_dmic)
4201 return 0;
4202
4203 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4204 int def_conf;
4205 if (spec->autocfg.inputs[i].pin != nid)
4206 continue;
4207
4208 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4209 return 0;
4210 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4211 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4212 return 0;
4213
4214 /* Finally found the inverted internal mic! */
4215 snprintf(dest_label, 44, "Inverted %s", label);
4216 return 1;
4217 }
4218 return 0;
4219}
4220
Takashi Iwai6764bce2011-05-13 16:52:25 +02004221static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4222 const char *label, const char *pfx,
4223 int cidx)
4224{
4225 struct conexant_spec *spec = codec->spec;
4226 int i;
4227
4228 for (i = 0; i < spec->num_adc_nids; i++) {
David Henningsson18dcd302012-04-02 15:40:27 +02004229 char rightch_label[44];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004230 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004231 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004232 if (idx < 0)
4233 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004234 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004235 idx = 0;
David Henningsson18dcd302012-04-02 15:40:27 +02004236
4237 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4238 /* Make two independent kcontrols for left and right */
4239 int err = cx_auto_add_volume_idx(codec, label, pfx,
4240 cidx, adc_nid, HDA_INPUT, idx, 1);
4241 if (err < 0)
4242 return err;
4243 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4244 cidx, adc_nid, HDA_INPUT, idx, 2);
4245 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004246 return cx_auto_add_volume_idx(codec, label, pfx,
David Henningsson18dcd302012-04-02 15:40:27 +02004247 cidx, adc_nid, HDA_INPUT, idx, 3);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004248 }
4249 return 0;
4250}
4251
Takashi Iwaicf27f292011-05-16 11:33:02 +02004252static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4253 const char *label, int cidx)
4254{
4255 struct conexant_spec *spec = codec->spec;
4256 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004257 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004258
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004259 nid = spec->imux_info[idx].pin;
David Henningsson18dcd302012-04-02 15:40:27 +02004260 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4261 char rightch_label[44];
4262 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4263 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4264 cidx, nid, HDA_INPUT, 0, 1);
4265 if (err < 0)
4266 return err;
4267 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4268 cidx, nid, HDA_INPUT, 0, 2);
4269 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004270 return cx_auto_add_volume(codec, label, " Boost", cidx,
4271 nid, HDA_INPUT);
David Henningsson18dcd302012-04-02 15:40:27 +02004272 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004273 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4274 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004275 if (con < 0)
4276 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004277 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004278 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004279 return 0; /* already present */
4280 }
4281
4282 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004283 spec->imux_info[idx].boost = mux;
David Henningsson74d3e6972012-10-02 10:14:23 +02004284 return cx_auto_add_volume(codec, label, " Boost", cidx,
Takashi Iwaicf27f292011-05-16 11:33:02 +02004285 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004286 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004287 return 0;
4288}
4289
Takashi Iwaif2e57312010-09-15 10:07:08 +02004290static int cx_auto_build_input_controls(struct hda_codec *codec)
4291{
4292 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004293 struct hda_input_mux *imux = &spec->private_imux;
4294 const char *prev_label;
4295 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004296 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004297 int multi_connection;
4298
Takashi Iwai6b452142011-10-14 15:26:20 +02004299 if (!imux->num_items)
4300 return 0;
4301
Takashi Iwaicf27f292011-05-16 11:33:02 +02004302 multi_connection = 0;
4303 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004304 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4305 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004306 if (cidx < 0)
4307 continue;
4308 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004309 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004310 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004311 if (i > 0 && input_conn[i] != input_conn[0])
4312 multi_connection = 1;
4313 }
David Henningsson983345e2011-02-15 19:57:09 +01004314
Takashi Iwaif2e57312010-09-15 10:07:08 +02004315 prev_label = NULL;
4316 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004317 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004318 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004319 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004320
Takashi Iwaicf27f292011-05-16 11:33:02 +02004321 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004322 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004323 if (label == prev_label)
4324 cidx++;
4325 else
4326 cidx = 0;
4327 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004328
Takashi Iwaicf27f292011-05-16 11:33:02 +02004329 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4330 if (err < 0)
4331 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004332
Takashi Iwaicf27f292011-05-16 11:33:02 +02004333 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004334 if (i > 0)
4335 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004336 err = cx_auto_add_capture_volume(codec, nid,
4337 "Capture", "", cidx);
4338 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004339 bool dup_found = false;
4340 for (j = 0; j < i; j++) {
4341 if (input_conn[j] == input_conn[i]) {
4342 dup_found = true;
4343 break;
4344 }
4345 }
4346 if (dup_found)
4347 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004348 err = cx_auto_add_capture_volume(codec, nid,
4349 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004350 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004351 if (err < 0)
4352 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004353 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004354
4355 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4356 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4357 if (err < 0)
4358 return err;
4359 }
4360
Takashi Iwaif2e57312010-09-15 10:07:08 +02004361 return 0;
4362}
4363
4364static int cx_auto_build_controls(struct hda_codec *codec)
4365{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004366 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004367 int err;
4368
4369 err = cx_auto_build_output_controls(codec);
4370 if (err < 0)
4371 return err;
4372 err = cx_auto_build_input_controls(codec);
4373 if (err < 0)
4374 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004375 err = conexant_build_controls(codec);
4376 if (err < 0)
4377 return err;
4378 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4379 if (err < 0)
4380 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004381 if (spec->vmaster_mute.sw_kctl) {
4382 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4383 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4384 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004385 if (err < 0)
4386 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004387 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004388 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004389}
4390
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004391static int cx_auto_search_adcs(struct hda_codec *codec)
4392{
4393 struct conexant_spec *spec = codec->spec;
4394 hda_nid_t nid, end_nid;
4395
4396 end_nid = codec->start_nid + codec->num_nodes;
4397 for (nid = codec->start_nid; nid < end_nid; nid++) {
4398 unsigned int caps = get_wcaps(codec, nid);
4399 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4400 continue;
4401 if (caps & AC_WCAP_DIGITAL)
4402 continue;
4403 if (snd_BUG_ON(spec->num_adc_nids >=
4404 ARRAY_SIZE(spec->private_adc_nids)))
4405 break;
4406 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4407 }
4408 spec->adc_nids = spec->private_adc_nids;
4409 return 0;
4410}
4411
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004412static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004413 .build_controls = cx_auto_build_controls,
4414 .build_pcms = conexant_build_pcms,
4415 .init = cx_auto_init,
4416 .free = conexant_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02004417 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai83012a72012-08-24 18:38:08 +02004418#ifdef CONFIG_PM
Takashi Iwaif2e57312010-09-15 10:07:08 +02004419 .suspend = conexant_suspend,
4420#endif
4421 .reboot_notify = snd_hda_shutup_pins,
4422};
4423
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004424/*
4425 * pin fix-up
4426 */
David Henningsson18dcd302012-04-02 15:40:27 +02004427enum {
4428 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02004429 CXT_PINCFG_LENOVO_TP410,
Huacai Chen239fb862012-10-05 21:25:09 +08004430 CXT_PINCFG_LEMOTE_A1004,
4431 CXT_PINCFG_LEMOTE_A1205,
David Henningsson18dcd302012-04-02 15:40:27 +02004432 CXT_FIXUP_STEREO_DMIC,
Huacai Chen239fb862012-10-05 21:25:09 +08004433 CXT_FIXUP_INC_MIC_BOOST,
David Henningsson18dcd302012-04-02 15:40:27 +02004434};
4435
Takashi Iwai23d30f22012-05-07 17:17:32 +02004436static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4437 const struct hda_fixup *fix, int action)
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004438{
David Henningsson18dcd302012-04-02 15:40:27 +02004439 struct conexant_spec *spec = codec->spec;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004440 spec->fixup_stereo_dmic = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004441}
4442
Huacai Chen239fb862012-10-05 21:25:09 +08004443static void cxt5066_increase_mic_boost(struct hda_codec *codec,
4444 const struct hda_fixup *fix, int action)
4445{
4446 if (action != HDA_FIXUP_ACT_PRE_PROBE)
4447 return;
4448
4449 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
4450 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
4451 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4452 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4453 (0 << AC_AMPCAP_MUTE_SHIFT));
4454}
4455
Takashi Iwaid70f3632012-04-19 15:18:08 +02004456/* ThinkPad X200 & co with cxt5051 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02004457static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004458 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4459 { 0x17, 0x21a11000 }, /* dock-mic */
4460 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004461 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004462 {}
4463};
4464
Takashi Iwaid70f3632012-04-19 15:18:08 +02004465/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02004466static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
Takashi Iwaid70f3632012-04-19 15:18:08 +02004467 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4468 { 0x1a, 0x21a190f0 }, /* dock-mic */
4469 { 0x1c, 0x212140ff }, /* dock-HP */
4470 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004471};
4472
Huacai Chen239fb862012-10-05 21:25:09 +08004473/* Lemote A1004/A1205 with cxt5066 */
4474static const struct hda_pintbl cxt_pincfg_lemote[] = {
4475 { 0x1a, 0x90a10020 }, /* Internal mic */
4476 { 0x1b, 0x03a11020 }, /* External mic */
4477 { 0x1d, 0x400101f0 }, /* Not used */
4478 { 0x1e, 0x40a701f0 }, /* Not used */
4479 { 0x20, 0x404501f0 }, /* Not used */
4480 { 0x22, 0x404401f0 }, /* Not used */
4481 { 0x23, 0x40a701f0 }, /* Not used */
4482 {}
4483};
4484
Takashi Iwai23d30f22012-05-07 17:17:32 +02004485static const struct hda_fixup cxt_fixups[] = {
4486 [CXT_PINCFG_LENOVO_X200] = {
4487 .type = HDA_FIXUP_PINS,
4488 .v.pins = cxt_pincfg_lenovo_x200,
4489 },
4490 [CXT_PINCFG_LENOVO_TP410] = {
4491 .type = HDA_FIXUP_PINS,
4492 .v.pins = cxt_pincfg_lenovo_tp410,
4493 },
Huacai Chen239fb862012-10-05 21:25:09 +08004494 [CXT_PINCFG_LEMOTE_A1004] = {
4495 .type = HDA_FIXUP_PINS,
4496 .chained = true,
4497 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
4498 .v.pins = cxt_pincfg_lemote,
4499 },
4500 [CXT_PINCFG_LEMOTE_A1205] = {
4501 .type = HDA_FIXUP_PINS,
4502 .v.pins = cxt_pincfg_lemote,
4503 },
Takashi Iwai23d30f22012-05-07 17:17:32 +02004504 [CXT_FIXUP_STEREO_DMIC] = {
4505 .type = HDA_FIXUP_FUNC,
4506 .v.func = cxt_fixup_stereo_dmic,
4507 },
Huacai Chen239fb862012-10-05 21:25:09 +08004508 [CXT_FIXUP_INC_MIC_BOOST] = {
4509 .type = HDA_FIXUP_FUNC,
4510 .v.func = cxt5066_increase_mic_boost,
4511 },
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004512};
4513
Takashi Iwaid70f3632012-04-19 15:18:08 +02004514static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004515 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4516 {}
4517};
4518
Takashi Iwaid70f3632012-04-19 15:18:08 +02004519static const struct snd_pci_quirk cxt5066_fixups[] = {
4520 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4521 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4522 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4523 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4524 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02004525 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Felix Kaechelee4db0952012-09-26 01:20:44 +02004526 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
David Henningssonb3c5dce2012-06-21 16:03:01 +02004527 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
Huacai Chen239fb862012-10-05 21:25:09 +08004528 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
4529 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
Takashi Iwaif2e57312010-09-15 10:07:08 +02004530 {}
4531};
4532
Takashi Iwai38681372012-02-27 15:00:58 +01004533/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4534 * can be created (bko#42825)
4535 */
4536static void add_cx5051_fake_mutes(struct hda_codec *codec)
4537{
4538 static hda_nid_t out_nids[] = {
4539 0x10, 0x11, 0
4540 };
4541 hda_nid_t *p;
4542
4543 for (p = out_nids; *p; p++)
4544 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4545 AC_AMPCAP_MIN_MUTE |
4546 query_amp_caps(codec, *p, HDA_OUTPUT));
4547}
4548
Takashi Iwaif2e57312010-09-15 10:07:08 +02004549static int patch_conexant_auto(struct hda_codec *codec)
4550{
4551 struct conexant_spec *spec;
4552 int err;
4553
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004554 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4555 codec->chip_name);
4556
Takashi Iwaif2e57312010-09-15 10:07:08 +02004557 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4558 if (!spec)
4559 return -ENOMEM;
4560 codec->spec = spec;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004561 snd_hda_gen_init(&spec->gen);
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004562
Takashi Iwai6b452142011-10-14 15:26:20 +02004563 switch (codec->vendor_id) {
4564 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004565 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004566 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004567 case 0x14f15051:
4568 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02004569 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004570 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
Takashi Iwai38681372012-02-27 15:00:58 +01004571 break;
Michael Karcher51969d62012-04-06 15:34:19 +02004572 default:
4573 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004574 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
4575 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02004576 }
4577
Takashi Iwai23d30f22012-05-07 17:17:32 +02004578 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4579
Takashi Iwaif29735c2012-03-13 07:55:10 +01004580 /* Show mute-led control only on HP laptops
4581 * This is a sort of white-list: on HP laptops, EAPD corresponds
4582 * only to the mute-LED without actualy amp function. Meanwhile,
4583 * others may use EAPD really as an amp switch, so it might be
4584 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004585 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004586 switch (codec->subsystem_id >> 16) {
4587 case 0x103c:
4588 spec->vmaster_mute_led = 1;
4589 break;
4590 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004591
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004592 err = cx_auto_search_adcs(codec);
4593 if (err < 0)
4594 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004595 err = cx_auto_parse_auto_config(codec);
4596 if (err < 0) {
4597 kfree(codec->spec);
4598 codec->spec = NULL;
4599 return err;
4600 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004601 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004602 codec->patch_ops = cx_auto_patch_ops;
4603 if (spec->beep_amp)
4604 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004605
4606 /* Some laptops with Conexant chips show stalls in S3 resume,
4607 * which falls into the single-cmd mode.
4608 * Better to make reset, then.
4609 */
4610 if (!codec->bus->sync_write) {
4611 snd_printd("hda_codec: "
4612 "Enable sync_write for stable communication\n");
4613 codec->bus->sync_write = 1;
4614 codec->bus->allow_bus_reset = 1;
4615 }
4616
Takashi Iwaif2e57312010-09-15 10:07:08 +02004617 return 0;
4618}
4619
4620/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004621 */
4622
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004623static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004624 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4625 .patch = patch_cxt5045 },
4626 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4627 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004628 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4629 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004630 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4631 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004632 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4633 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004634 { .id = 0x14f15068, .name = "CX20584",
4635 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004636 { .id = 0x14f15069, .name = "CX20585",
4637 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004638 { .id = 0x14f1506c, .name = "CX20588",
4639 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004640 { .id = 0x14f1506e, .name = "CX20590",
4641 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004642 { .id = 0x14f15097, .name = "CX20631",
4643 .patch = patch_conexant_auto },
4644 { .id = 0x14f15098, .name = "CX20632",
4645 .patch = patch_conexant_auto },
4646 { .id = 0x14f150a1, .name = "CX20641",
4647 .patch = patch_conexant_auto },
4648 { .id = 0x14f150a2, .name = "CX20642",
4649 .patch = patch_conexant_auto },
4650 { .id = 0x14f150ab, .name = "CX20651",
4651 .patch = patch_conexant_auto },
4652 { .id = 0x14f150ac, .name = "CX20652",
4653 .patch = patch_conexant_auto },
4654 { .id = 0x14f150b8, .name = "CX20664",
4655 .patch = patch_conexant_auto },
4656 { .id = 0x14f150b9, .name = "CX20665",
4657 .patch = patch_conexant_auto },
Takashi Iwai2d825fd2012-05-11 08:39:24 +02004658 { .id = 0x14f1510f, .name = "CX20751/2",
4659 .patch = patch_conexant_auto },
4660 { .id = 0x14f15110, .name = "CX20751/2",
4661 .patch = patch_conexant_auto },
4662 { .id = 0x14f15111, .name = "CX20753/4",
4663 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004664 {} /* terminator */
4665};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004666
4667MODULE_ALIAS("snd-hda-codec-id:14f15045");
4668MODULE_ALIAS("snd-hda-codec-id:14f15047");
4669MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004670MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004671MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004672MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004673MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004674MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004675MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004676MODULE_ALIAS("snd-hda-codec-id:14f15097");
4677MODULE_ALIAS("snd-hda-codec-id:14f15098");
4678MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4679MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4680MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4681MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4682MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4683MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai2d825fd2012-05-11 08:39:24 +02004684MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4685MODULE_ALIAS("snd-hda-codec-id:14f15110");
4686MODULE_ALIAS("snd-hda-codec-id:14f15111");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004687
4688MODULE_LICENSE("GPL");
4689MODULE_DESCRIPTION("Conexant HD-audio codec");
4690
4691static struct hda_codec_preset_list conexant_list = {
4692 .preset = snd_hda_preset_conexant,
4693 .owner = THIS_MODULE,
4694};
4695
4696static int __init patch_conexant_init(void)
4697{
4698 return snd_hda_add_codec_preset(&conexant_list);
4699}
4700
4701static void __exit patch_conexant_exit(void)
4702{
4703 snd_hda_delete_codec_preset(&conexant_list);
4704}
4705
4706module_init(patch_conexant_init)
4707module_exit(patch_conexant_exit)