blob: a0c3ac32eb94fedafec7be4e5c29899dc13910d3 [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Tobin Davisc9b443d2006-11-14 12:13:39 +010028#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010029#include <sound/jack.h>
30
Tobin Davisc9b443d2006-11-14 12:13:39 +010031#include "hda_codec.h"
32#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020033#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020034#include "hda_jack.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010035
36#define CXT_PIN_DIR_IN 0x00
37#define CXT_PIN_DIR_OUT 0x01
38#define CXT_PIN_DIR_INOUT 0x02
39#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
40#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
41
42#define CONEXANT_HP_EVENT 0x37
43#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020044#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010045
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010047
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010048#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010049#define CXT5051_PORTB_EVENT 0x38
50#define CXT5051_PORTC_EVENT 0x39
51
Takashi Iwaifaddaa52010-01-23 22:31:36 +010052#define AUTO_MIC_PORTB (1 << 1)
53#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010054
Takashi Iwaif2e57312010-09-15 10:07:08 +020055struct pin_dac_pair {
56 hda_nid_t pin;
57 hda_nid_t dac;
58 int type;
59};
60
Takashi Iwai47ad1f42011-05-17 09:15:55 +020061struct imux_info {
62 hda_nid_t pin; /* input pin NID */
63 hda_nid_t adc; /* connected ADC NID */
64 hda_nid_t boost; /* optional boost volume NID */
65 int index; /* corresponding to autocfg.input */
66};
67
Tobin Davisc9b443d2006-11-14 12:13:39 +010068struct conexant_spec {
69
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020070 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010071 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010072 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +010073 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaif29735c2012-03-13 07:55:10 +010074 bool vmaster_mute_led;
Tobin Davisc9b443d2006-11-14 12:13:39 +010075
76 const struct hda_verb *init_verbs[5]; /* initialization verbs
77 * don't forget NULL
78 * termination!
79 */
80 unsigned int num_init_verbs;
81
82 /* playback */
83 struct hda_multi_out multiout; /* playback set-up
84 * max_channels, dacs must be set
85 * dig_out_nid and hp_nid are optional
86 */
87 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010088 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020089 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010090 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020091 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020092 int auto_mic_dock; /* imux_pins[] index for dock mic */
93 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010094 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050095 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010096
97 /* capture */
98 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020099 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100100 hda_nid_t dig_in_nid; /* digital-in NID; optional */
101
Takashi Iwai461e2c72008-01-25 11:35:17 +0100102 unsigned int cur_adc_idx;
103 hda_nid_t cur_adc;
104 unsigned int cur_adc_stream_tag;
105 unsigned int cur_adc_format;
106
Takashi Iwai6764bce2011-05-13 16:52:25 +0200107 const struct hda_pcm_stream *capture_stream;
108
Tobin Davisc9b443d2006-11-14 12:13:39 +0100109 /* capture source */
110 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200111 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100112 unsigned int cur_mux[3];
113
114 /* channel model */
115 const struct hda_channel_mode *channel_mode;
116 int num_channel_mode;
117
118 /* PCM information */
119 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
120
Tobin Davisc9b443d2006-11-14 12:13:39 +0100121 unsigned int spdif_route;
122
123 /* dynamic controls, init_verbs and input_mux */
124 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100125 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200126 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200127 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200128 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200129 struct pin_dac_pair dac_info[8];
130 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100131
Daniel Drake0fb67e92009-07-16 14:46:57 +0100132 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200133 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200134 unsigned int detect_line:1; /* Line-out detection enabled */
135 unsigned int automute_lines:1; /* automute line-out as well */
136 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200137 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500138 unsigned int dell_vostro:1;
139 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200140 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200141 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100142 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200143 unsigned int pin_eapd_ctrls:1;
David Henningssoncae4d9a2012-04-02 15:40:27 +0200144 unsigned int fixup_stereo_dmic:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100145
Takashi Iwai6764bce2011-05-13 16:52:25 +0200146 unsigned int adc_switching:1;
147
Daniel Drake75f89912010-01-07 13:46:25 +0100148 unsigned int ext_mic_present;
149 unsigned int recording;
150 void (*capture_prepare)(struct hda_codec *codec);
151 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100152
153 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
154 * through the microphone jack.
155 * When the user enables this through a mixer switch, both internal and
156 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
157 * we also allow the bias to be configured through a separate mixer
158 * control. */
159 unsigned int dc_enable;
160 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
161 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200162
163 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200164
165 /* extra EAPD pins */
166 unsigned int num_eapds;
167 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100168};
169
170static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
173{
174 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100175 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
176 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100177}
178
179static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 unsigned int stream_tag,
182 unsigned int format,
183 struct snd_pcm_substream *substream)
184{
185 struct conexant_spec *spec = codec->spec;
186 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
187 stream_tag,
188 format, substream);
189}
190
191static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
194{
195 struct conexant_spec *spec = codec->spec;
196 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
197}
198
199/*
200 * Digital out
201 */
202static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 struct snd_pcm_substream *substream)
205{
206 struct conexant_spec *spec = codec->spec;
207 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
208}
209
210static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 struct snd_pcm_substream *substream)
213{
214 struct conexant_spec *spec = codec->spec;
215 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
216}
217
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200218static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
219 struct hda_codec *codec,
220 unsigned int stream_tag,
221 unsigned int format,
222 struct snd_pcm_substream *substream)
223{
224 struct conexant_spec *spec = codec->spec;
225 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
226 stream_tag,
227 format, substream);
228}
229
Tobin Davisc9b443d2006-11-14 12:13:39 +0100230/*
231 * Analog capture
232 */
233static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
234 struct hda_codec *codec,
235 unsigned int stream_tag,
236 unsigned int format,
237 struct snd_pcm_substream *substream)
238{
239 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100240 if (spec->capture_prepare)
241 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100242 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
243 stream_tag, 0, format);
244 return 0;
245}
246
247static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
248 struct hda_codec *codec,
249 struct snd_pcm_substream *substream)
250{
251 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100252 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100253 if (spec->capture_cleanup)
254 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100255 return 0;
256}
257
258
259
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200260static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100261 .substreams = 1,
262 .channels_min = 2,
263 .channels_max = 2,
264 .nid = 0, /* fill later */
265 .ops = {
266 .open = conexant_playback_pcm_open,
267 .prepare = conexant_playback_pcm_prepare,
268 .cleanup = conexant_playback_pcm_cleanup
269 },
270};
271
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200272static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100273 .substreams = 1,
274 .channels_min = 2,
275 .channels_max = 2,
276 .nid = 0, /* fill later */
277 .ops = {
278 .prepare = conexant_capture_pcm_prepare,
279 .cleanup = conexant_capture_pcm_cleanup
280 },
281};
282
283
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200284static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100285 .substreams = 1,
286 .channels_min = 2,
287 .channels_max = 2,
288 .nid = 0, /* fill later */
289 .ops = {
290 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200291 .close = conexant_dig_playback_pcm_close,
292 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100293 },
294};
295
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200296static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100297 .substreams = 1,
298 .channels_min = 2,
299 .channels_max = 2,
300 /* NID is set in alc_build_pcms */
301};
302
Takashi Iwai461e2c72008-01-25 11:35:17 +0100303static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
304 struct hda_codec *codec,
305 unsigned int stream_tag,
306 unsigned int format,
307 struct snd_pcm_substream *substream)
308{
309 struct conexant_spec *spec = codec->spec;
310 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
311 spec->cur_adc_stream_tag = stream_tag;
312 spec->cur_adc_format = format;
313 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
314 return 0;
315}
316
317static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
318 struct hda_codec *codec,
319 struct snd_pcm_substream *substream)
320{
321 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100322 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100323 spec->cur_adc = 0;
324 return 0;
325}
326
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200327static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100328 .substreams = 1,
329 .channels_min = 2,
330 .channels_max = 2,
331 .nid = 0, /* fill later */
332 .ops = {
333 .prepare = cx5051_capture_pcm_prepare,
334 .cleanup = cx5051_capture_pcm_cleanup
335 },
336};
337
Tobin Davisc9b443d2006-11-14 12:13:39 +0100338static int conexant_build_pcms(struct hda_codec *codec)
339{
340 struct conexant_spec *spec = codec->spec;
341 struct hda_pcm *info = spec->pcm_rec;
342
343 codec->num_pcms = 1;
344 codec->pcm_info = info;
345
346 info->name = "CONEXANT Analog";
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
349 spec->multiout.max_channels;
350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
351 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200352 if (spec->capture_stream)
353 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
354 else {
355 if (codec->vendor_id == 0x14f15051)
356 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
357 cx5051_pcm_analog_capture;
358 else {
359 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
360 conexant_pcm_analog_capture;
361 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
362 spec->num_adc_nids;
363 }
364 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100365 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
366
367 if (spec->multiout.dig_out_nid) {
368 info++;
369 codec->num_pcms++;
370 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100371 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100372 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
373 conexant_pcm_digital_playback;
374 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
375 spec->multiout.dig_out_nid;
376 if (spec->dig_in_nid) {
377 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
378 conexant_pcm_digital_capture;
379 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
380 spec->dig_in_nid;
381 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500382 if (spec->slave_dig_outs[0])
383 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100384 }
385
386 return 0;
387}
388
389static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
390 struct snd_ctl_elem_info *uinfo)
391{
392 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
393 struct conexant_spec *spec = codec->spec;
394
395 return snd_hda_input_mux_info(spec->input_mux, uinfo);
396}
397
398static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 struct conexant_spec *spec = codec->spec;
403 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
404
405 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
406 return 0;
407}
408
409static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
410 struct snd_ctl_elem_value *ucontrol)
411{
412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413 struct conexant_spec *spec = codec->spec;
414 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
415
416 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
417 spec->capsrc_nids[adc_idx],
418 &spec->cur_mux[adc_idx]);
419}
420
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200421static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
422 unsigned int power_state)
423{
424 if (power_state == AC_PWRST_D3)
425 msleep(100);
426 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
427 power_state);
428 /* partial workaround for "azx_get_response timeout" */
429 if (power_state == AC_PWRST_D0)
430 msleep(10);
431 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
432}
433
Tobin Davisc9b443d2006-11-14 12:13:39 +0100434static int conexant_init(struct hda_codec *codec)
435{
436 struct conexant_spec *spec = codec->spec;
437 int i;
438
439 for (i = 0; i < spec->num_init_verbs; i++)
440 snd_hda_sequence_write(codec, spec->init_verbs[i]);
441 return 0;
442}
443
444static void conexant_free(struct hda_codec *codec)
445{
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200446 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100447 kfree(codec->spec);
448}
449
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200450static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100451 {
452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
453 .name = "Capture Source",
454 .info = conexant_mux_enum_info,
455 .get = conexant_mux_enum_get,
456 .put = conexant_mux_enum_put
457 },
458 {}
459};
460
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200461#ifdef CONFIG_SND_HDA_INPUT_BEEP
462/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200463static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200464 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
465 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
466 { } /* end */
467};
468#endif
469
Takashi Iwai9322ca52012-02-03 14:28:01 +0100470static const char * const slave_pfxs[] = {
471 "Headphone", "Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100472 NULL
473};
474
Tobin Davisc9b443d2006-11-14 12:13:39 +0100475static int conexant_build_controls(struct hda_codec *codec)
476{
477 struct conexant_spec *spec = codec->spec;
478 unsigned int i;
479 int err;
480
481 for (i = 0; i < spec->num_mixers; i++) {
482 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
483 if (err < 0)
484 return err;
485 }
486 if (spec->multiout.dig_out_nid) {
487 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600488 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100489 spec->multiout.dig_out_nid);
490 if (err < 0)
491 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100492 err = snd_hda_create_spdif_share_sw(codec,
493 &spec->multiout);
494 if (err < 0)
495 return err;
496 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100497 }
498 if (spec->dig_in_nid) {
499 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
500 if (err < 0)
501 return err;
502 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100503
504 /* if we have no master control, let's create it */
505 if (spec->vmaster_nid &&
506 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
507 unsigned int vmaster_tlv[4];
508 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
509 HDA_OUTPUT, vmaster_tlv);
510 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100511 vmaster_tlv, slave_pfxs,
512 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100513 if (err < 0)
514 return err;
515 }
516 if (spec->vmaster_nid &&
517 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai527c73b2012-03-12 12:38:51 +0100518 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
519 NULL, slave_pfxs,
520 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100521 &spec->vmaster_mute.sw_kctl);
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100522 if (err < 0)
523 return err;
524 }
525
Takashi Iwaib880c742009-03-10 14:41:05 +0100526 if (spec->input_mux) {
527 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
528 if (err < 0)
529 return err;
530 }
531
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200532#ifdef CONFIG_SND_HDA_INPUT_BEEP
533 /* create beep controls if needed */
534 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200535 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200536 for (knew = cxt_beep_mixer; knew->name; knew++) {
537 struct snd_kcontrol *kctl;
538 kctl = snd_ctl_new1(knew, codec);
539 if (!kctl)
540 return -ENOMEM;
541 kctl->private_value = spec->beep_amp;
542 err = snd_hda_ctl_add(codec, 0, kctl);
543 if (err < 0)
544 return err;
545 }
546 }
547#endif
548
Tobin Davisc9b443d2006-11-14 12:13:39 +0100549 return 0;
550}
551
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200552static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100553 .build_controls = conexant_build_controls,
554 .build_pcms = conexant_build_pcms,
555 .init = conexant_init,
556 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200557 .set_power_state = conexant_set_power,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100558};
559
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200560#ifdef CONFIG_SND_HDA_INPUT_BEEP
561#define set_beep_amp(spec, nid, idx, dir) \
562 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
563#else
564#define set_beep_amp(spec, nid, idx, dir) /* NOP */
565#endif
566
Takashi Iwai6764bce2011-05-13 16:52:25 +0200567static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100568/*
569 * EAPD control
570 * the private value = nid | (invert << 8)
571 */
572
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200573#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100574
Tobin Davis82f30042007-02-13 12:45:44 +0100575static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100576 struct snd_ctl_elem_value *ucontrol)
577{
578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579 struct conexant_spec *spec = codec->spec;
580 int invert = (kcontrol->private_value >> 8) & 1;
581 if (invert)
582 ucontrol->value.integer.value[0] = !spec->cur_eapd;
583 else
584 ucontrol->value.integer.value[0] = spec->cur_eapd;
585 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100586
Tobin Davisc9b443d2006-11-14 12:13:39 +0100587}
588
Tobin Davis82f30042007-02-13 12:45:44 +0100589static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100590 struct snd_ctl_elem_value *ucontrol)
591{
592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
593 struct conexant_spec *spec = codec->spec;
594 int invert = (kcontrol->private_value >> 8) & 1;
595 hda_nid_t nid = kcontrol->private_value & 0xff;
596 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100597
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100598 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100599 if (invert)
600 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200601 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100602 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100603
Tobin Davisc9b443d2006-11-14 12:13:39 +0100604 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200605 snd_hda_codec_write_cache(codec, nid,
606 0, AC_VERB_SET_EAPD_BTLENABLE,
607 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100608 return 1;
609}
610
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100611/* controls for test mode */
612#ifdef CONFIG_SND_DEBUG
613
Tobin Davis82f30042007-02-13 12:45:44 +0100614#define CXT_EAPD_SWITCH(xname, nid, mask) \
615 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
616 .info = cxt_eapd_info, \
617 .get = cxt_eapd_get, \
618 .put = cxt_eapd_put, \
619 .private_value = nid | (mask<<16) }
620
621
622
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_info *uinfo)
625{
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct conexant_spec *spec = codec->spec;
628 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
629 spec->num_channel_mode);
630}
631
632static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
634{
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct conexant_spec *spec = codec->spec;
637 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
638 spec->num_channel_mode,
639 spec->multiout.max_channels);
640}
641
642static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_value *ucontrol)
644{
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct conexant_spec *spec = codec->spec;
647 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
648 spec->num_channel_mode,
649 &spec->multiout.max_channels);
650 if (err >= 0 && spec->need_dac_fix)
651 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
652 return err;
653}
654
655#define CXT_PIN_MODE(xname, nid, dir) \
656 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
657 .info = conexant_ch_mode_info, \
658 .get = conexant_ch_mode_get, \
659 .put = conexant_ch_mode_put, \
660 .private_value = nid | (dir<<16) }
661
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100662#endif /* CONFIG_SND_DEBUG */
663
Tobin Davisc9b443d2006-11-14 12:13:39 +0100664/* Conexant 5045 specific */
665
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200666static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
667static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
668static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100669#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100670
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200671static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100672 { 2, NULL },
673};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100674
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200675static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100676 .num_items = 2,
677 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200678 { "Internal Mic", 0x1 },
679 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100680 }
681};
682
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200683static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200684 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100685 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200686 { "Internal Mic", 0x1 },
687 { "Mic", 0x2 },
688 { "Line", 0x3 },
689 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100690 }
691};
692
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200693static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100694 .num_items = 2,
695 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200696 { "Mic", 0x1 },
697 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100698 }
699};
700
Tobin Davisc9b443d2006-11-14 12:13:39 +0100701/* turn on/off EAPD (+ mute HP) as a master switch */
702static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
704{
705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
706 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100707 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100708
Tobin Davis82f30042007-02-13 12:45:44 +0100709 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100710 return 0;
711
Tobin Davis82f30042007-02-13 12:45:44 +0100712 /* toggle internal speakers mute depending of presence of
713 * the headphone jack
714 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200715 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
716 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
717 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100718
Takashi Iwai47fd8302007-08-10 17:11:07 +0200719 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
720 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
721 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722 return 1;
723}
724
725/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200726static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200727 .ops = &snd_hda_bind_vol,
728 .values = {
729 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
730 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
731 0
732 },
733};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734
Tobin Davis7f296732007-03-12 11:39:01 +0100735/* toggle input of built-in and mic jack appropriately */
736static void cxt5045_hp_automic(struct hda_codec *codec)
737{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200738 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100739 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
740 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
741 {}
742 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200743 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100744 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
745 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
746 {}
747 };
748 unsigned int present;
749
Takashi Iwaid56757a2009-11-18 08:00:14 +0100750 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100751 if (present)
752 snd_hda_sequence_write(codec, mic_jack_on);
753 else
754 snd_hda_sequence_write(codec, mic_jack_off);
755}
756
Tobin Davisc9b443d2006-11-14 12:13:39 +0100757
758/* mute internal speaker if HP is plugged */
759static void cxt5045_hp_automute(struct hda_codec *codec)
760{
Tobin Davis82f30042007-02-13 12:45:44 +0100761 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100762 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100763
Takashi Iwaid56757a2009-11-18 08:00:14 +0100764 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100765
Takashi Iwai47fd8302007-08-10 17:11:07 +0200766 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
767 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
768 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769}
770
771/* unsolicited event for HP jack sensing */
772static void cxt5045_hp_unsol_event(struct hda_codec *codec,
773 unsigned int res)
774{
775 res >>= 26;
776 switch (res) {
777 case CONEXANT_HP_EVENT:
778 cxt5045_hp_automute(codec);
779 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100780 case CONEXANT_MIC_EVENT:
781 cxt5045_hp_automic(codec);
782 break;
783
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784 }
785}
786
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200787static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200788 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
789 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200790 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
791 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100792 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
793 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100794 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
795 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200796 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100797 {
798 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
799 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100800 .info = cxt_eapd_info,
801 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100802 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100803 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100804 },
805
806 {}
807};
808
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200809static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200810 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
811 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Jiang Zhe5218c892008-01-17 11:18:41 +0100812
813 {}
814};
815
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200816static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200817 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
818 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100819 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
820 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100821 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
822 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100823 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
824 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100825 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
826 {
827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
828 .name = "Master Playback Switch",
829 .info = cxt_eapd_info,
830 .get = cxt_eapd_get,
831 .put = cxt5045_hp_master_sw_put,
832 .private_value = 0x10,
833 },
834
835 {}
836};
837
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200838static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100839 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200840 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100841 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100842 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200843 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
844 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
845 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
846 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
847 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
848 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
849 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
851 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100852 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100853 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100854 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100855 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
856 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100857 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100858 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100859 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100860 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100861 { } /* end */
862};
863
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200864static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100865 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100866 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
867 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
868 /* Line In,HP, Amp */
869 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
870 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
871 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
872 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
873 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
874 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
876 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
877 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100878 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100879 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
880 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
881 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
882 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100883 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100884 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
885 /* EAPD */
886 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
887 { } /* end */
888};
Tobin Davis7f296732007-03-12 11:39:01 +0100889
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200890static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100891 /* pin sensing on HP jack */
892 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200893 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100894};
895
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200896static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100897 /* pin sensing on HP jack */
898 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200899 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100900};
901
Tobin Davisc9b443d2006-11-14 12:13:39 +0100902#ifdef CONFIG_SND_DEBUG
903/* Test configuration for debugging, modelled after the ALC260 test
904 * configuration.
905 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200906static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100907 .num_items = 5,
908 .items = {
909 { "MIXER", 0x0 },
910 { "MIC1 pin", 0x1 },
911 { "LINE1 pin", 0x2 },
912 { "HP-OUT pin", 0x3 },
913 { "CD pin", 0x4 },
914 },
915};
916
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200917static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100918
919 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100920 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
921 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200922 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
923 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
924 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
925 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926
927 /* Modes for retasking pin widgets */
928 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
929 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
930
Tobin Davis82f30042007-02-13 12:45:44 +0100931 /* EAPD Switch Control */
932 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
933
Tobin Davisc9b443d2006-11-14 12:13:39 +0100934 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100935
Michael Karcher250f3272012-04-06 15:34:20 +0200936 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
937 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
938 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
939 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
940 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
941 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
942 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
943 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
944 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
945 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946 {
947 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
948 .name = "Input Source",
949 .info = conexant_mux_enum_info,
950 .get = conexant_mux_enum_get,
951 .put = conexant_mux_enum_put,
952 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200953 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200954 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
955 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100956 { } /* end */
957};
958
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200959static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100960 /* Set connections */
961 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
962 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
963 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100964 /* Enable retasking pins as output, initially without power amp */
965 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100966 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100967
968 /* Disable digital (SPDIF) pins initially, but users can enable
969 * them via a mixer switch. In the case of SPDIF-out, this initverb
970 * payload also sets the generation to 0, output to be in "consumer"
971 * PCM format, copyright asserted, no pre-emphasis and no validity
972 * control.
973 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100974 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
975 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100976
Tobin Davisc9b443d2006-11-14 12:13:39 +0100977 /* Unmute retasking pin widget output buffers since the default
978 * state appears to be output. As the pin mode is changed by the
979 * user the pin mode control will take care of enabling the pin's
980 * input/output buffers as needed.
981 */
982 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
983 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
984
985 /* Mute capture amp left and right */
986 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
987
988 /* Set ADC connection select to match default mixer setting (mic1
989 * pin)
990 */
Michael Karcher250f3272012-04-06 15:34:20 +0200991 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
992 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100993
994 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +0200995 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100996 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
997 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
998 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
999 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1000
1001 { }
1002};
1003#endif
1004
1005
1006/* initialize jack-sensing, too */
1007static int cxt5045_init(struct hda_codec *codec)
1008{
1009 conexant_init(codec);
1010 cxt5045_hp_automute(codec);
1011 return 0;
1012}
1013
1014
1015enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001016 CXT5045_LAPTOP_HPSENSE,
1017 CXT5045_LAPTOP_MICSENSE,
1018 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001019 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001020 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001021#ifdef CONFIG_SND_DEBUG
1022 CXT5045_TEST,
1023#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001024 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001025 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001026};
1027
Takashi Iwaiea734962011-01-17 11:29:34 +01001028static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001029 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1030 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1031 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1032 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001033 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001034#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001035 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001036#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001037 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001038};
1039
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001040static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001041 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001042 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001043 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001044 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1045 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001046 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1047 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001048 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1049 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1050 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001051 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1052 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001053 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001054 {}
1055};
1056
1057static int patch_cxt5045(struct hda_codec *codec)
1058{
1059 struct conexant_spec *spec;
1060 int board_config;
1061
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001062 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1063 cxt5045_models,
1064 cxt5045_cfg_tbl);
1065 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001066 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001067 if (board_config == CXT5045_AUTO)
1068 return patch_conexant_auto(codec);
1069
Tobin Davisc9b443d2006-11-14 12:13:39 +01001070 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1071 if (!spec)
1072 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001074 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075
1076 spec->multiout.max_channels = 2;
1077 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1078 spec->multiout.dac_nids = cxt5045_dac_nids;
1079 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1080 spec->num_adc_nids = 1;
1081 spec->adc_nids = cxt5045_adc_nids;
1082 spec->capsrc_nids = cxt5045_capsrc_nids;
1083 spec->input_mux = &cxt5045_capture_source;
1084 spec->num_mixers = 1;
1085 spec->mixers[0] = cxt5045_mixers;
1086 spec->num_init_verbs = 1;
1087 spec->init_verbs[0] = cxt5045_init_verbs;
1088 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001089 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1090 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001091
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001092 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001093
1094 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001095
Tobin Davisc9b443d2006-11-14 12:13:39 +01001096 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001097 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001098 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001099 spec->input_mux = &cxt5045_capture_source;
1100 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001101 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1102 spec->mixers[0] = cxt5045_mixers;
1103 codec->patch_ops.init = cxt5045_init;
1104 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001105 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001106 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001107 spec->input_mux = &cxt5045_capture_source;
1108 spec->num_init_verbs = 2;
1109 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001110 spec->mixers[0] = cxt5045_mixers;
1111 codec->patch_ops.init = cxt5045_init;
1112 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001113 default:
1114 case CXT5045_LAPTOP_HPMICSENSE:
1115 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1116 spec->input_mux = &cxt5045_capture_source;
1117 spec->num_init_verbs = 3;
1118 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1119 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1120 spec->mixers[0] = cxt5045_mixers;
1121 codec->patch_ops.init = cxt5045_init;
1122 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001123 case CXT5045_BENQ:
1124 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1125 spec->input_mux = &cxt5045_capture_source_benq;
1126 spec->num_init_verbs = 1;
1127 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1128 spec->mixers[0] = cxt5045_mixers;
1129 spec->mixers[1] = cxt5045_benq_mixers;
1130 spec->num_mixers = 2;
1131 codec->patch_ops.init = cxt5045_init;
1132 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001133 case CXT5045_LAPTOP_HP530:
1134 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1135 spec->input_mux = &cxt5045_capture_source_hp530;
1136 spec->num_init_verbs = 2;
1137 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1138 spec->mixers[0] = cxt5045_mixers_hp530;
1139 codec->patch_ops.init = cxt5045_init;
1140 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001141#ifdef CONFIG_SND_DEBUG
1142 case CXT5045_TEST:
1143 spec->input_mux = &cxt5045_test_capture_source;
1144 spec->mixers[0] = cxt5045_test_mixer;
1145 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001146 break;
1147
Tobin Davisc9b443d2006-11-14 12:13:39 +01001148#endif
1149 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001150
Takashi Iwai031005f2008-06-26 14:49:58 +02001151 switch (codec->subsystem_id >> 16) {
1152 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001153 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001154 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001155 case 0x17aa:
1156 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1157 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1158 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001159 */
1160 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1161 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1162 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1163 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1164 (1 << AC_AMPCAP_MUTE_SHIFT));
1165 break;
1166 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001167
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001168 if (spec->beep_amp)
Takashi Iwai184e91c2013-03-18 11:00:44 +01001169 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001170
Tobin Davisc9b443d2006-11-14 12:13:39 +01001171 return 0;
1172}
1173
1174
1175/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001176#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001177
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001178static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1179static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1180static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001182static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001183 { 2, NULL },
1184};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001185
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001186static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001187 .num_items = 2,
1188 .items = {
1189 { "ExtMic", 0x2 },
1190 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191 }
1192};
1193
1194/* turn on/off EAPD (+ mute HP) as a master switch */
1195static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1196 struct snd_ctl_elem_value *ucontrol)
1197{
1198 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1199 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001200 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201
Tobin Davis82f30042007-02-13 12:45:44 +01001202 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001203 return 0;
1204
Tobin Davis82f30042007-02-13 12:45:44 +01001205 /* toggle internal speakers mute depending of presence of
1206 * the headphone jack
1207 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001208 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001209 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1210 * pin widgets unlike other codecs. In this case, we need to
1211 * set index 0x01 for the volume from the mixer amp 0x19.
1212 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001213 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001214 HDA_AMP_MUTE, bits);
1215 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1216 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1217 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001218 return 1;
1219}
1220
Tobin Davisc9b443d2006-11-14 12:13:39 +01001221/* mute internal speaker if HP is plugged */
1222static void cxt5047_hp_automute(struct hda_codec *codec)
1223{
Tobin Davis82f30042007-02-13 12:45:44 +01001224 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001225 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001226
Takashi Iwaid56757a2009-11-18 08:00:14 +01001227 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001228
Takashi Iwai47fd8302007-08-10 17:11:07 +02001229 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001230 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001231 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001232 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233}
1234
1235/* toggle input of built-in and mic jack appropriately */
1236static void cxt5047_hp_automic(struct hda_codec *codec)
1237{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001238 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001239 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1240 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241 {}
1242 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001243 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001244 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1245 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001246 {}
1247 };
1248 unsigned int present;
1249
Takashi Iwaid56757a2009-11-18 08:00:14 +01001250 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001251 if (present)
1252 snd_hda_sequence_write(codec, mic_jack_on);
1253 else
1254 snd_hda_sequence_write(codec, mic_jack_off);
1255}
1256
1257/* unsolicited event for HP jack sensing */
1258static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1259 unsigned int res)
1260{
Marc Boucher9f113e02008-01-22 15:18:08 +01001261 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 case CONEXANT_HP_EVENT:
1263 cxt5047_hp_automute(codec);
1264 break;
1265 case CONEXANT_MIC_EVENT:
1266 cxt5047_hp_automic(codec);
1267 break;
1268 }
1269}
1270
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001271static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001272 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1273 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001274 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001275 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1276 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1277 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1278 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001279 {
1280 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1281 .name = "Master Playback Switch",
1282 .info = cxt_eapd_info,
1283 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001284 .put = cxt5047_hp_master_sw_put,
1285 .private_value = 0x13,
1286 },
1287
1288 {}
1289};
1290
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001291static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001292 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001293 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001294 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1295 {}
1296};
1297
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001298static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001299 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 { } /* end */
1301};
1302
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001303static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001304 /* Line in, Mic, Built-in Mic */
1305 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1306 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1307 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001308 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001309 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001310 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1311 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001312 /* Record selector: Mic */
1313 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1314 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1315 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1316 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001317 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1318 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1319 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1320 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001321 /* SPDIF route: PCM */
1322 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001323 /* Enable unsolicited events */
1324 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1325 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001326 { } /* end */
1327};
1328
1329/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001330static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001331 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332 {}
1333};
1334
1335/* Test configuration for debugging, modelled after the ALC260 test
1336 * configuration.
1337 */
1338#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001339static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001340 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001341 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001342 { "LINE1 pin", 0x0 },
1343 { "MIC1 pin", 0x1 },
1344 { "MIC2 pin", 0x2 },
1345 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 },
1347};
1348
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001349static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001350
1351 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001352 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1353 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1354 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1355 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001356 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1357 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1358 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001360 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001364
1365 /* Modes for retasking pin widgets */
1366 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1367 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1368
Tobin Davis82f30042007-02-13 12:45:44 +01001369 /* EAPD Switch Control */
1370 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1371
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001373 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1374 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1375 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1376 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1377 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1378 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1379 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1380 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381
Tobin Davis82f30042007-02-13 12:45:44 +01001382 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1383 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1384 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1385 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1386 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1387 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1388 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1389 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001390 {
1391 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1392 .name = "Input Source",
1393 .info = conexant_mux_enum_info,
1394 .get = conexant_mux_enum_get,
1395 .put = conexant_mux_enum_put,
1396 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001397 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001398
Tobin Davisc9b443d2006-11-14 12:13:39 +01001399 { } /* end */
1400};
1401
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001402static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001403 /* Enable retasking pins as output, initially without power amp */
1404 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1405 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1406 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1407
1408 /* Disable digital (SPDIF) pins initially, but users can enable
1409 * them via a mixer switch. In the case of SPDIF-out, this initverb
1410 * payload also sets the generation to 0, output to be in "consumer"
1411 * PCM format, copyright asserted, no pre-emphasis and no validity
1412 * control.
1413 */
1414 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1415
1416 /* Ensure mic1, mic2, line1 pin widgets take input from the
1417 * OUT1 sum bus when acting as an output.
1418 */
1419 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1420 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1421
1422 /* Start with output sum widgets muted and their output gains at min */
1423 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1424 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1425
1426 /* Unmute retasking pin widget output buffers since the default
1427 * state appears to be output. As the pin mode is changed by the
1428 * user the pin mode control will take care of enabling the pin's
1429 * input/output buffers as needed.
1430 */
1431 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1432 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1433 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1434
1435 /* Mute capture amp left and right */
1436 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1437
1438 /* Set ADC connection select to match default mixer setting (mic1
1439 * pin)
1440 */
1441 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1442
1443 /* Mute all inputs to mixer widget (even unconnected ones) */
1444 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1445 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1446 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1447 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1448 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1449 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1450 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1451 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1452
1453 { }
1454};
1455#endif
1456
1457
1458/* initialize jack-sensing, too */
1459static int cxt5047_hp_init(struct hda_codec *codec)
1460{
1461 conexant_init(codec);
1462 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001463 return 0;
1464}
1465
1466
1467enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001468 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1469 CXT5047_LAPTOP_HP, /* Some HP laptops */
1470 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001471#ifdef CONFIG_SND_DEBUG
1472 CXT5047_TEST,
1473#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001474 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001475 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001476};
1477
Takashi Iwaiea734962011-01-17 11:29:34 +01001478static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001479 [CXT5047_LAPTOP] = "laptop",
1480 [CXT5047_LAPTOP_HP] = "laptop-hp",
1481 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001482#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001483 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001484#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001485 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001486};
1487
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001488static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001489 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001490 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1491 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001492 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001493 {}
1494};
1495
1496static int patch_cxt5047(struct hda_codec *codec)
1497{
1498 struct conexant_spec *spec;
1499 int board_config;
1500
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001501 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1502 cxt5047_models,
1503 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001504 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001505 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001506 if (board_config == CXT5047_AUTO)
1507 return patch_conexant_auto(codec);
1508
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1510 if (!spec)
1511 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001512 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001513 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001514
1515 spec->multiout.max_channels = 2;
1516 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1517 spec->multiout.dac_nids = cxt5047_dac_nids;
1518 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1519 spec->num_adc_nids = 1;
1520 spec->adc_nids = cxt5047_adc_nids;
1521 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001522 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001523 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001524 spec->num_init_verbs = 1;
1525 spec->init_verbs[0] = cxt5047_init_verbs;
1526 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001527 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1528 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001529
1530 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001531
Tobin Davisc9b443d2006-11-14 12:13:39 +01001532 switch (board_config) {
1533 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001534 spec->num_mixers = 2;
1535 spec->mixers[1] = cxt5047_hp_spk_mixers;
1536 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001537 break;
1538 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001539 spec->num_mixers = 2;
1540 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001541 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001542 codec->patch_ops.init = cxt5047_hp_init;
1543 break;
1544 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001545 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001546 spec->num_mixers = 2;
1547 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001548 spec->num_init_verbs = 2;
1549 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001550 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001551 break;
1552#ifdef CONFIG_SND_DEBUG
1553 case CXT5047_TEST:
1554 spec->input_mux = &cxt5047_test_capture_source;
1555 spec->mixers[0] = cxt5047_test_mixer;
1556 spec->init_verbs[0] = cxt5047_test_init_verbs;
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#endif
1559 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001560 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001561
1562 switch (codec->subsystem_id >> 16) {
1563 case 0x103c:
1564 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1565 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1566 * with 0 dB offset 0x17)
1567 */
1568 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1569 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1570 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1571 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1572 (1 << AC_AMPCAP_MUTE_SHIFT));
1573 break;
1574 }
1575
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576 return 0;
1577}
1578
Takashi Iwai461e2c72008-01-25 11:35:17 +01001579/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001580static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1581static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001582
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001583static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001584 { 2, NULL },
1585};
1586
1587static void cxt5051_update_speaker(struct hda_codec *codec)
1588{
1589 struct conexant_spec *spec = codec->spec;
1590 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001591 /* headphone pin */
1592 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1593 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1594 pinctl);
1595 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001596 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1597 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1598 pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001599 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001600 if (spec->ideapad)
1601 snd_hda_codec_write(codec, 0x1b, 0,
1602 AC_VERB_SET_PIN_WIDGET_CONTROL,
1603 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001604}
1605
1606/* turn on/off EAPD (+ mute HP) as a master switch */
1607static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1608 struct snd_ctl_elem_value *ucontrol)
1609{
1610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1611
1612 if (!cxt_eapd_put(kcontrol, ucontrol))
1613 return 0;
1614 cxt5051_update_speaker(codec);
1615 return 1;
1616}
1617
1618/* toggle input of built-in and mic jack appropriately */
1619static void cxt5051_portb_automic(struct hda_codec *codec)
1620{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001621 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001622 unsigned int present;
1623
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001624 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001625 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001626 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001627 snd_hda_codec_write(codec, 0x14, 0,
1628 AC_VERB_SET_CONNECT_SEL,
1629 present ? 0x01 : 0x00);
1630}
1631
1632/* switch the current ADC according to the jack state */
1633static void cxt5051_portc_automic(struct hda_codec *codec)
1634{
1635 struct conexant_spec *spec = codec->spec;
1636 unsigned int present;
1637 hda_nid_t new_adc;
1638
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001639 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001640 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001641 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001642 if (present)
1643 spec->cur_adc_idx = 1;
1644 else
1645 spec->cur_adc_idx = 0;
1646 new_adc = spec->adc_nids[spec->cur_adc_idx];
1647 if (spec->cur_adc && spec->cur_adc != new_adc) {
1648 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001649 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001650 spec->cur_adc = new_adc;
1651 snd_hda_codec_setup_stream(codec, new_adc,
1652 spec->cur_adc_stream_tag, 0,
1653 spec->cur_adc_format);
1654 }
1655}
1656
1657/* mute internal speaker if HP is plugged */
1658static void cxt5051_hp_automute(struct hda_codec *codec)
1659{
1660 struct conexant_spec *spec = codec->spec;
1661
Takashi Iwaid56757a2009-11-18 08:00:14 +01001662 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001663 cxt5051_update_speaker(codec);
1664}
1665
1666/* unsolicited event for HP jack sensing */
1667static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1668 unsigned int res)
1669{
1670 switch (res >> 26) {
1671 case CONEXANT_HP_EVENT:
1672 cxt5051_hp_automute(codec);
1673 break;
1674 case CXT5051_PORTB_EVENT:
1675 cxt5051_portb_automic(codec);
1676 break;
1677 case CXT5051_PORTC_EVENT:
1678 cxt5051_portc_automic(codec);
1679 break;
1680 }
1681}
1682
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001683static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001684 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1685 {
1686 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1687 .name = "Master Playback Switch",
1688 .info = cxt_eapd_info,
1689 .get = cxt_eapd_get,
1690 .put = cxt5051_hp_master_sw_put,
1691 .private_value = 0x1a,
1692 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001693 {}
1694};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001696static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001697 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1698 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001699 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1700 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001701 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1702 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001703 {}
1704};
1705
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001706static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001707 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1708 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001709 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1710 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001711 {}
1712};
1713
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001714static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001715 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1716 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001717 {}
1718};
1719
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001720static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001721 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1722 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001723 {}
1724};
1725
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001726static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001727 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1728 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001729 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1730 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001731 {}
1732};
1733
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001734static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001735 /* Line in, Mic */
1736 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1737 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1738 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1739 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1740 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1741 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1742 /* SPK */
1743 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1744 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1745 /* HP, Amp */
1746 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1747 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1748 /* DAC1 */
1749 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001750 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1752 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1753 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1754 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001755 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001756 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1757 /* EAPD */
1758 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1759 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001760 { } /* end */
1761};
1762
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001763static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001764 /* Line in, Mic */
1765 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1766 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1767 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1768 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1769 /* SPK */
1770 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1771 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1772 /* HP, Amp */
1773 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1774 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1775 /* DAC1 */
1776 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001777 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1779 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1780 /* SPDIF route: PCM */
1781 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1782 /* EAPD */
1783 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1784 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001785 { } /* end */
1786};
1787
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001788static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001789 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001790 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001791 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1792 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1793 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1794 /* SPK */
1795 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1796 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1797 /* HP, Amp */
1798 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1799 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1800 /* DAC1 */
1801 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001802 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001803 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1804 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1805 /* SPDIF route: PCM */
1806 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1807 /* EAPD */
1808 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1809 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001810 { } /* end */
1811};
1812
Takashi Iwai6953e552010-01-24 11:00:27 +01001813static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1814 unsigned int event)
1815{
1816 snd_hda_codec_write(codec, nid, 0,
1817 AC_VERB_SET_UNSOLICITED_ENABLE,
1818 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001819}
1820
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001821static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001822 /* Subwoofer */
1823 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1824 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1825 { } /* end */
1826};
1827
Takashi Iwai461e2c72008-01-25 11:35:17 +01001828/* initialize jack-sensing, too */
1829static int cxt5051_init(struct hda_codec *codec)
1830{
Takashi Iwai6953e552010-01-24 11:00:27 +01001831 struct conexant_spec *spec = codec->spec;
1832
Takashi Iwai461e2c72008-01-25 11:35:17 +01001833 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001834
1835 if (spec->auto_mic & AUTO_MIC_PORTB)
1836 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1837 if (spec->auto_mic & AUTO_MIC_PORTC)
1838 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1839
Takashi Iwai461e2c72008-01-25 11:35:17 +01001840 if (codec->patch_ops.unsol_event) {
1841 cxt5051_hp_automute(codec);
1842 cxt5051_portb_automic(codec);
1843 cxt5051_portc_automic(codec);
1844 }
1845 return 0;
1846}
1847
1848
1849enum {
1850 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1851 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001852 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001853 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001854 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001855 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001856 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001857 CXT5051_MODELS
1858};
1859
Takashi Iwaiea734962011-01-17 11:29:34 +01001860static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001861 [CXT5051_LAPTOP] = "laptop",
1862 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001863 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001864 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001865 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001866 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001867 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001868};
1869
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001870static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001871 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001872 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001873 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001874 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001875 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1876 CXT5051_LAPTOP),
1877 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001878 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001879 {}
1880};
1881
1882static int patch_cxt5051(struct hda_codec *codec)
1883{
1884 struct conexant_spec *spec;
1885 int board_config;
1886
Takashi Iwai6764bce2011-05-13 16:52:25 +02001887 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1888 cxt5051_models,
1889 cxt5051_cfg_tbl);
1890 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001891 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001892 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001893 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001894
Takashi Iwai461e2c72008-01-25 11:35:17 +01001895 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1896 if (!spec)
1897 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001898 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001899 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001900
1901 codec->patch_ops = conexant_patch_ops;
1902 codec->patch_ops.init = cxt5051_init;
1903
1904 spec->multiout.max_channels = 2;
1905 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1906 spec->multiout.dac_nids = cxt5051_dac_nids;
1907 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1908 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1909 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001910 spec->num_mixers = 2;
1911 spec->mixers[0] = cxt5051_capture_mixers;
1912 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001913 spec->num_init_verbs = 1;
1914 spec->init_verbs[0] = cxt5051_init_verbs;
1915 spec->spdif_route = 0;
1916 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1917 spec->channel_mode = cxt5051_modes;
1918 spec->cur_adc = 0;
1919 spec->cur_adc_idx = 0;
1920
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001921 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1922
Takashi Iwai79d7d532009-03-04 09:03:50 +01001923 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1924
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001925 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001926 switch (board_config) {
1927 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001928 spec->mixers[0] = cxt5051_hp_mixers;
1929 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001930 case CXT5051_HP_DV6736:
1931 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1932 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001933 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001934 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001935 case CXT5051_F700:
1936 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1937 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001938 spec->auto_mic = 0;
1939 break;
1940 case CXT5051_TOSHIBA:
1941 spec->mixers[0] = cxt5051_toshiba_mixers;
1942 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001943 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001944 case CXT5051_IDEAPAD:
1945 spec->init_verbs[spec->num_init_verbs++] =
1946 cxt5051_ideapad_init_verbs;
1947 spec->ideapad = 1;
1948 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001949 }
1950
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001951 if (spec->beep_amp)
Takashi Iwai184e91c2013-03-18 11:00:44 +01001952 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001953
Takashi Iwai461e2c72008-01-25 11:35:17 +01001954 return 0;
1955}
1956
Daniel Drake0fb67e92009-07-16 14:46:57 +01001957/* Conexant 5066 specific */
1958
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001959static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1960static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1961static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1962static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001963
Daniel Drakedbaccc02009-11-09 15:17:24 +00001964/* OLPC's microphone port is DC coupled for use with external sensors,
1965 * therefore we use a 50% mic bias in order to center the input signal with
1966 * the DC input range of the codec. */
1967#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1968
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001969static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001970 { 2, NULL },
1971};
1972
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001973#define HP_PRESENT_PORT_A (1 << 0)
1974#define HP_PRESENT_PORT_D (1 << 1)
1975#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1976#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1977
Daniel Drake0fb67e92009-07-16 14:46:57 +01001978static void cxt5066_update_speaker(struct hda_codec *codec)
1979{
1980 struct conexant_spec *spec = codec->spec;
1981 unsigned int pinctl;
1982
John Baboval3a253442010-12-02 11:21:31 -05001983 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1984 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001985
1986 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001987 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01001988 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1989 pinctl);
1990
1991 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001992 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1993 if (spec->dell_automute || spec->thinkpad) {
1994 /* Mute if Port A is connected */
1995 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05001996 pinctl = 0;
1997 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001998 /* Thinkpad/Dell doesn't give pin-D status */
1999 if (!hp_port_d_present(spec))
2000 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002001 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002002 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2003 pinctl);
2004
2005 /* CLASS_D AMP */
2006 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2007 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2008 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002009}
2010
2011/* turn on/off EAPD (+ mute HP) as a master switch */
2012static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2013 struct snd_ctl_elem_value *ucontrol)
2014{
2015 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2016
2017 if (!cxt_eapd_put(kcontrol, ucontrol))
2018 return 0;
2019
2020 cxt5066_update_speaker(codec);
2021 return 1;
2022}
2023
Daniel Drakec4cfe662010-01-07 13:47:04 +01002024static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2025 .num_items = 3,
2026 .items = {
2027 { "Off", PIN_IN },
2028 { "50%", PIN_VREF50 },
2029 { "80%", PIN_VREF80 },
2030 },
2031};
2032
2033static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2034{
2035 struct conexant_spec *spec = codec->spec;
2036 /* Even though port F is the DC input, the bias is controlled on port B.
2037 * we also leave that port as an active input (but unselected) in DC mode
2038 * just in case that is necessary to make the bias setting take effect. */
2039 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2040 AC_VERB_SET_PIN_WIDGET_CONTROL,
2041 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2042}
2043
Daniel Drake75f89912010-01-07 13:46:25 +01002044/* OLPC defers mic widget control until when capture is started because the
2045 * microphone LED comes on as soon as these settings are put in place. if we
2046 * did this before recording, it would give the false indication that recording
2047 * is happening when it is not. */
2048static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002049{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002050 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002051 if (!spec->recording)
2052 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002053
Daniel Drakec4cfe662010-01-07 13:47:04 +01002054 if (spec->dc_enable) {
2055 /* in DC mode we ignore presence detection and just use the jack
2056 * through our special DC port */
2057 const struct hda_verb enable_dc_mode[] = {
2058 /* disble internal mic, port C */
2059 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2060
2061 /* enable DC capture, port F */
2062 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2063 {},
2064 };
2065
2066 snd_hda_sequence_write(codec, enable_dc_mode);
2067 /* port B input disabled (and bias set) through the following call */
2068 cxt5066_set_olpc_dc_bias(codec);
2069 return;
2070 }
2071
2072 /* disable DC (port F) */
2073 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2074
Daniel Drake75f89912010-01-07 13:46:25 +01002075 /* external mic, port B */
2076 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2077 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002078
Daniel Drake75f89912010-01-07 13:46:25 +01002079 /* internal mic, port C */
2080 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2081 spec->ext_mic_present ? 0 : PIN_VREF80);
2082}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002083
Daniel Drake75f89912010-01-07 13:46:25 +01002084/* toggle input of built-in and mic jack appropriately */
2085static void cxt5066_olpc_automic(struct hda_codec *codec)
2086{
2087 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002088 unsigned int present;
2089
Daniel Drakec4cfe662010-01-07 13:47:04 +01002090 if (spec->dc_enable) /* don't do presence detection in DC mode */
2091 return;
2092
Daniel Drake75f89912010-01-07 13:46:25 +01002093 present = snd_hda_codec_read(codec, 0x1a, 0,
2094 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2095 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002096 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002097 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002098 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002099
2100 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2101 present ? 0 : 1);
2102 spec->ext_mic_present = !!present;
2103
2104 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002105}
2106
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002107/* toggle input of built-in digital mic and mic jack appropriately */
2108static void cxt5066_vostro_automic(struct hda_codec *codec)
2109{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002110 unsigned int present;
2111
2112 struct hda_verb ext_mic_present[] = {
2113 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002114 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002115
2116 /* switch to external mic input */
2117 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2118 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2119
2120 /* disable internal digital mic */
2121 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2122 {}
2123 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002124 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002125 /* enable internal mic, port C */
2126 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2127
2128 /* switch to internal mic input */
2129 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2130
2131 /* disable external mic, port B */
2132 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2133 {}
2134 };
2135
2136 present = snd_hda_jack_detect(codec, 0x1a);
2137 if (present) {
2138 snd_printdd("CXT5066: external microphone detected\n");
2139 snd_hda_sequence_write(codec, ext_mic_present);
2140 } else {
2141 snd_printdd("CXT5066: external microphone absent\n");
2142 snd_hda_sequence_write(codec, ext_mic_absent);
2143 }
2144}
2145
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002146/* toggle input of built-in digital mic and mic jack appropriately */
2147static void cxt5066_ideapad_automic(struct hda_codec *codec)
2148{
2149 unsigned int present;
2150
2151 struct hda_verb ext_mic_present[] = {
2152 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2153 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2154 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2155 {}
2156 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002157 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002158 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2159 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2160 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2161 {}
2162 };
2163
2164 present = snd_hda_jack_detect(codec, 0x1b);
2165 if (present) {
2166 snd_printdd("CXT5066: external microphone detected\n");
2167 snd_hda_sequence_write(codec, ext_mic_present);
2168 } else {
2169 snd_printdd("CXT5066: external microphone absent\n");
2170 snd_hda_sequence_write(codec, ext_mic_absent);
2171 }
2172}
2173
David Henningssona1d69062011-01-21 13:33:28 +01002174
2175/* toggle input of built-in digital mic and mic jack appropriately */
2176static void cxt5066_asus_automic(struct hda_codec *codec)
2177{
2178 unsigned int present;
2179
2180 present = snd_hda_jack_detect(codec, 0x1b);
2181 snd_printdd("CXT5066: external microphone present=%d\n", present);
2182 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2183 present ? 1 : 0);
2184}
2185
2186
David Henningsson048e78a2010-09-02 08:35:47 +02002187/* toggle input of built-in digital mic and mic jack appropriately */
2188static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2189{
2190 unsigned int present;
2191
2192 present = snd_hda_jack_detect(codec, 0x1b);
2193 snd_printdd("CXT5066: external microphone present=%d\n", present);
2194 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2195 present ? 1 : 3);
2196}
2197
2198
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002199/* toggle input of built-in digital mic and mic jack appropriately
2200 order is: external mic -> dock mic -> interal mic */
2201static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2202{
2203 unsigned int ext_present, dock_present;
2204
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002205 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002206 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2207 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2208 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2209 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2210 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2211 {}
2212 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002213 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002214 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2215 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2216 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2217 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2218 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2219 {}
2220 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002221 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002222 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2223 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2224 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2225 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2226 {}
2227 };
2228
2229 ext_present = snd_hda_jack_detect(codec, 0x1b);
2230 dock_present = snd_hda_jack_detect(codec, 0x1a);
2231 if (ext_present) {
2232 snd_printdd("CXT5066: external microphone detected\n");
2233 snd_hda_sequence_write(codec, ext_mic_present);
2234 } else if (dock_present) {
2235 snd_printdd("CXT5066: dock microphone detected\n");
2236 snd_hda_sequence_write(codec, dock_mic_present);
2237 } else {
2238 snd_printdd("CXT5066: external microphone absent\n");
2239 snd_hda_sequence_write(codec, ext_mic_absent);
2240 }
2241}
2242
Daniel Drake0fb67e92009-07-16 14:46:57 +01002243/* mute internal speaker if HP is plugged */
2244static void cxt5066_hp_automute(struct hda_codec *codec)
2245{
2246 struct conexant_spec *spec = codec->spec;
2247 unsigned int portA, portD;
2248
2249 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002250 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002251
2252 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002253 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002254
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002255 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2256 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002257 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2258 portA, portD, spec->hp_present);
2259 cxt5066_update_speaker(codec);
2260}
2261
David Henningsson02b6b5b2011-01-21 13:27:39 +01002262/* Dispatch the right mic autoswitch function */
2263static void cxt5066_automic(struct hda_codec *codec)
2264{
2265 struct conexant_spec *spec = codec->spec;
2266
2267 if (spec->dell_vostro)
2268 cxt5066_vostro_automic(codec);
2269 else if (spec->ideapad)
2270 cxt5066_ideapad_automic(codec);
2271 else if (spec->thinkpad)
2272 cxt5066_thinkpad_automic(codec);
2273 else if (spec->hp_laptop)
2274 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002275 else if (spec->asus)
2276 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002277}
2278
Daniel Drake0fb67e92009-07-16 14:46:57 +01002279/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002280static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002281{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002282 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002283 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2284 switch (res >> 26) {
2285 case CONEXANT_HP_EVENT:
2286 cxt5066_hp_automute(codec);
2287 break;
2288 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002289 /* ignore mic events in DC mode; we're always using the jack */
2290 if (!spec->dc_enable)
2291 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002292 break;
2293 }
2294}
2295
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002296/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002297static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002298{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002299 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002300 switch (res >> 26) {
2301 case CONEXANT_HP_EVENT:
2302 cxt5066_hp_automute(codec);
2303 break;
2304 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002305 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002306 break;
2307 }
2308}
2309
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002310
Daniel Drake0fb67e92009-07-16 14:46:57 +01002311static const struct hda_input_mux cxt5066_analog_mic_boost = {
2312 .num_items = 5,
2313 .items = {
2314 { "0dB", 0 },
2315 { "10dB", 1 },
2316 { "20dB", 2 },
2317 { "30dB", 3 },
2318 { "40dB", 4 },
2319 },
2320};
2321
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002322static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002323{
2324 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002325 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002326 AC_VERB_SET_AMP_GAIN_MUTE,
2327 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2328 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002329 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002330 /* adjust the internal mic as well...it is not through 0x17 */
2331 snd_hda_codec_write_cache(codec, 0x23, 0,
2332 AC_VERB_SET_AMP_GAIN_MUTE,
2333 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2334 cxt5066_analog_mic_boost.
2335 items[spec->mic_boost].index);
2336 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002337}
2338
Daniel Drake0fb67e92009-07-16 14:46:57 +01002339static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2340 struct snd_ctl_elem_info *uinfo)
2341{
2342 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2343}
2344
2345static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2346 struct snd_ctl_elem_value *ucontrol)
2347{
2348 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002349 struct conexant_spec *spec = codec->spec;
2350 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002351 return 0;
2352}
2353
2354static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2355 struct snd_ctl_elem_value *ucontrol)
2356{
2357 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002358 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2360 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002361 idx = ucontrol->value.enumerated.item[0];
2362 if (idx >= imux->num_items)
2363 idx = imux->num_items - 1;
2364
Daniel Drakec4cfe662010-01-07 13:47:04 +01002365 spec->mic_boost = idx;
2366 if (!spec->dc_enable)
2367 cxt5066_set_mic_boost(codec);
2368 return 1;
2369}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002370
Daniel Drakec4cfe662010-01-07 13:47:04 +01002371static void cxt5066_enable_dc(struct hda_codec *codec)
2372{
2373 const struct hda_verb enable_dc_mode[] = {
2374 /* disable gain */
2375 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2376
2377 /* switch to DC input */
2378 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2379 {}
2380 };
2381
2382 /* configure as input source */
2383 snd_hda_sequence_write(codec, enable_dc_mode);
2384 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2385}
2386
2387static void cxt5066_disable_dc(struct hda_codec *codec)
2388{
2389 /* reconfigure input source */
2390 cxt5066_set_mic_boost(codec);
2391 /* automic also selects the right mic if we're recording */
2392 cxt5066_olpc_automic(codec);
2393}
2394
2395static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2396 struct snd_ctl_elem_value *ucontrol)
2397{
2398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2399 struct conexant_spec *spec = codec->spec;
2400 ucontrol->value.integer.value[0] = spec->dc_enable;
2401 return 0;
2402}
2403
2404static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2405 struct snd_ctl_elem_value *ucontrol)
2406{
2407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2408 struct conexant_spec *spec = codec->spec;
2409 int dc_enable = !!ucontrol->value.integer.value[0];
2410
2411 if (dc_enable == spec->dc_enable)
2412 return 0;
2413
2414 spec->dc_enable = dc_enable;
2415 if (dc_enable)
2416 cxt5066_enable_dc(codec);
2417 else
2418 cxt5066_disable_dc(codec);
2419
2420 return 1;
2421}
2422
2423static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2424 struct snd_ctl_elem_info *uinfo)
2425{
2426 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2427}
2428
2429static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2430 struct snd_ctl_elem_value *ucontrol)
2431{
2432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2433 struct conexant_spec *spec = codec->spec;
2434 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2435 return 0;
2436}
2437
2438static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2439 struct snd_ctl_elem_value *ucontrol)
2440{
2441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2442 struct conexant_spec *spec = codec->spec;
2443 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2444 unsigned int idx;
2445
2446 idx = ucontrol->value.enumerated.item[0];
2447 if (idx >= imux->num_items)
2448 idx = imux->num_items - 1;
2449
2450 spec->dc_input_bias = idx;
2451 if (spec->dc_enable)
2452 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002453 return 1;
2454}
2455
Daniel Drake75f89912010-01-07 13:46:25 +01002456static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2457{
2458 struct conexant_spec *spec = codec->spec;
2459 /* mark as recording and configure the microphone widget so that the
2460 * recording LED comes on. */
2461 spec->recording = 1;
2462 cxt5066_olpc_select_mic(codec);
2463}
2464
2465static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2466{
2467 struct conexant_spec *spec = codec->spec;
2468 const struct hda_verb disable_mics[] = {
2469 /* disable external mic, port B */
2470 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2471
2472 /* disble internal mic, port C */
2473 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002474
2475 /* disable DC capture, port F */
2476 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002477 {},
2478 };
2479
2480 snd_hda_sequence_write(codec, disable_mics);
2481 spec->recording = 0;
2482}
2483
Andy Robinsonf6a24912011-01-24 10:12:37 -05002484static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002485 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002486 int num_pins)
2487{
2488 struct conexant_spec *spec = codec->spec;
2489 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2490 int i;
2491
2492 for (i = 0; i < num_pins; i++, dig_pins++) {
2493 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2494 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2495 continue;
2496 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2497 continue;
2498 if (spec->slave_dig_outs[0])
2499 nid_loc++;
2500 else
2501 nid_loc = spec->slave_dig_outs;
2502 }
2503}
2504
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002505static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002506 .num_items = 4,
2507 .items = {
2508 { "Mic B", 0 },
2509 { "Mic C", 1 },
2510 { "Mic E", 2 },
2511 { "Mic F", 3 },
2512 },
2513};
2514
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002515static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002516 .ops = &snd_hda_bind_vol,
2517 .values = {
2518 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2519 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2520 0
2521 },
2522};
2523
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002524static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002525 .ops = &snd_hda_bind_sw,
2526 .values = {
2527 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2528 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2529 0
2530 },
2531};
2532
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002533static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002534 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2535 {}
2536};
2537
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002538static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002539 {
2540 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2541 .name = "Master Playback Volume",
2542 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2543 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2544 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002545 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002546 .info = snd_hda_mixer_amp_volume_info,
2547 .get = snd_hda_mixer_amp_volume_get,
2548 .put = snd_hda_mixer_amp_volume_put,
2549 .tlv = { .c = snd_hda_mixer_amp_tlv },
2550 /* offset by 28 volume steps to limit minimum gain to -46dB */
2551 .private_value =
2552 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2553 },
2554 {}
2555};
2556
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002557static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002558 {
2559 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2560 .name = "DC Mode Enable Switch",
2561 .info = snd_ctl_boolean_mono_info,
2562 .get = cxt5066_olpc_dc_get,
2563 .put = cxt5066_olpc_dc_put,
2564 },
2565 {
2566 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2567 .name = "DC Input Bias Enum",
2568 .info = cxt5066_olpc_dc_bias_enum_info,
2569 .get = cxt5066_olpc_dc_bias_enum_get,
2570 .put = cxt5066_olpc_dc_bias_enum_put,
2571 },
2572 {}
2573};
2574
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002575static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002576 {
2577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2578 .name = "Master Playback Switch",
2579 .info = cxt_eapd_info,
2580 .get = cxt_eapd_get,
2581 .put = cxt5066_hp_master_sw_put,
2582 .private_value = 0x1d,
2583 },
2584
2585 {
2586 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002587 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002588 .info = cxt5066_mic_boost_mux_enum_info,
2589 .get = cxt5066_mic_boost_mux_enum_get,
2590 .put = cxt5066_mic_boost_mux_enum_put,
2591 },
2592
2593 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2594 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2595 {}
2596};
2597
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002598static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002599 {
2600 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002601 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002602 .info = cxt5066_mic_boost_mux_enum_info,
2603 .get = cxt5066_mic_boost_mux_enum_get,
2604 .put = cxt5066_mic_boost_mux_enum_put,
2605 .private_value = 0x23 | 0x100,
2606 },
2607 {}
2608};
2609
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002610static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002611 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2612 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2613 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2614 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2615
2616 /* Speakers */
2617 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2618 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2619
2620 /* HP, Amp */
2621 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2622 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2623
2624 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2625 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2626
2627 /* DAC1 */
2628 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2629
2630 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2631 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2632 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2633 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2634 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2635 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2636
2637 /* no digital microphone support yet */
2638 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2639
2640 /* Audio input selector */
2641 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2642
2643 /* SPDIF route: PCM */
2644 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2645 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2646
2647 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2648 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2649
2650 /* EAPD */
2651 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2652
2653 /* not handling these yet */
2654 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2655 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2656 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2657 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2658 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2659 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2660 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2661 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2662 { } /* end */
2663};
2664
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002665static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002666 /* Port A: headphones */
2667 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2668 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2669
2670 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002671 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002672
2673 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002674 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002675
2676 /* Port D: unused */
2677 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2678
2679 /* Port E: unused, but has primary EAPD */
2680 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2681 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2682
Daniel Drakec4cfe662010-01-07 13:47:04 +01002683 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002684 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2685
2686 /* Port G: internal speakers */
2687 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2688 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2689
2690 /* DAC1 */
2691 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2692
2693 /* DAC2: unused */
2694 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2695
2696 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2697 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2698 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2699 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2700 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2701 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2702 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2703 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2704 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2705 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2706 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2707 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2708
2709 /* Disable digital microphone port */
2710 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2711
2712 /* Audio input selectors */
2713 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2714 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2715
2716 /* Disable SPDIF */
2717 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2718 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2719
2720 /* enable unsolicited events for Port A and B */
2721 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2722 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2723 { } /* end */
2724};
2725
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002726static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002727 /* Port A: headphones */
2728 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2729 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2730
2731 /* Port B: external microphone */
2732 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2733
2734 /* Port C: unused */
2735 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2736
2737 /* Port D: unused */
2738 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2739
2740 /* Port E: unused, but has primary EAPD */
2741 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2742 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2743
2744 /* Port F: unused */
2745 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2746
2747 /* Port G: internal speakers */
2748 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2749 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2750
2751 /* DAC1 */
2752 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2753
2754 /* DAC2: unused */
2755 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2756
2757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2759 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2761 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2762 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2763 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2764 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2765 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2766 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2767 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2768 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2769
2770 /* Digital microphone port */
2771 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2772
2773 /* Audio input selectors */
2774 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2775 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2776
2777 /* Disable SPDIF */
2778 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2779 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2780
2781 /* enable unsolicited events for Port A and B */
2782 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2783 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2784 { } /* end */
2785};
2786
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002787static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002788 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2789 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2790 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2791 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2792
2793 /* Speakers */
2794 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2795 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2796
2797 /* HP, Amp */
2798 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2799 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2800
2801 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2802 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2803
2804 /* DAC1 */
2805 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2806
2807 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2813 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2814
2815 /* Audio input selector */
2816 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2817 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2818
2819 /* SPDIF route: PCM */
2820 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2821 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2822
2823 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2824 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2825
2826 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002827 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002828
2829 /* EAPD */
2830 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2831
2832 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2833 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2834 { } /* end */
2835};
2836
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002837static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002838 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2839 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2840
2841 /* Port G: internal speakers */
2842 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2843 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2844
2845 /* Port A: HP, Amp */
2846 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2847 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2848
2849 /* Port B: Mic Dock */
2850 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2851
2852 /* Port C: Mic */
2853 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2854
2855 /* Port D: HP Dock, Amp */
2856 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2857 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2858
2859 /* DAC1 */
2860 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2861
2862 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2863 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2864 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2866 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2868 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2869
2870 /* Audio input selector */
2871 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2872 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2873
2874 /* SPDIF route: PCM */
2875 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2876 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2877
2878 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2879 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2880
2881 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002882 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002883
2884 /* EAPD */
2885 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2886
2887 /* enable unsolicited events for Port A, B, C and D */
2888 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2889 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2890 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2891 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2892 { } /* end */
2893};
2894
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002895static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002896 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2897 { } /* end */
2898};
2899
David Henningsson048e78a2010-09-02 08:35:47 +02002900
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002901static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002902 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2903 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2904 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2905 { } /* end */
2906};
2907
Daniel Drake0fb67e92009-07-16 14:46:57 +01002908/* initialize jack-sensing, too */
2909static int cxt5066_init(struct hda_codec *codec)
2910{
2911 snd_printdd("CXT5066: init\n");
2912 conexant_init(codec);
2913 if (codec->patch_ops.unsol_event) {
2914 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002915 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002916 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002917 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002918 return 0;
2919}
2920
Daniel Drake75f89912010-01-07 13:46:25 +01002921static int cxt5066_olpc_init(struct hda_codec *codec)
2922{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002923 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002924 snd_printdd("CXT5066: init\n");
2925 conexant_init(codec);
2926 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002927 if (!spec->dc_enable) {
2928 cxt5066_set_mic_boost(codec);
2929 cxt5066_olpc_automic(codec);
2930 } else {
2931 cxt5066_enable_dc(codec);
2932 }
Daniel Drake75f89912010-01-07 13:46:25 +01002933 return 0;
2934}
2935
Daniel Drake0fb67e92009-07-16 14:46:57 +01002936enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002937 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002938 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2939 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002940 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002941 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002942 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002943 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002944 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002945 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002946 CXT5066_MODELS
2947};
2948
Takashi Iwaiea734962011-01-17 11:29:34 +01002949static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002950 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002951 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2952 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002953 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002954 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002955 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002956 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002957 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002958 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002959};
2960
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002961static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02002962 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002963 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002964 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002965 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002966 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002967 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002968 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2969 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002970 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002971 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002972 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002973 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002974 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002975 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002976 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2977 CXT5066_LAPTOP),
2978 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002979 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002980 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002981 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson29c5fbb2012-01-23 16:39:55 +01002982 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO),
Daniel Suchyca201c02011-10-18 11:09:44 +02002983 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02002984 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002985 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002986 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002987 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02002988 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04002989 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002990 {}
2991};
2992
2993static int patch_cxt5066(struct hda_codec *codec)
2994{
2995 struct conexant_spec *spec;
2996 int board_config;
2997
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002998 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2999 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003000 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003001 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003002 if (board_config == CXT5066_AUTO)
3003 return patch_conexant_auto(codec);
3004
Daniel Drake0fb67e92009-07-16 14:46:57 +01003005 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3006 if (!spec)
3007 return -ENOMEM;
3008 codec->spec = spec;
3009
3010 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003011 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003012
3013 spec->dell_automute = 0;
3014 spec->multiout.max_channels = 2;
3015 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3016 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003017 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3018 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003019 spec->num_adc_nids = 1;
3020 spec->adc_nids = cxt5066_adc_nids;
3021 spec->capsrc_nids = cxt5066_capsrc_nids;
3022 spec->input_mux = &cxt5066_capture_source;
3023
3024 spec->port_d_mode = PIN_HP;
3025
3026 spec->num_init_verbs = 1;
3027 spec->init_verbs[0] = cxt5066_init_verbs;
3028 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3029 spec->channel_mode = cxt5066_modes;
3030 spec->cur_adc = 0;
3031 spec->cur_adc_idx = 0;
3032
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003033 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3034
Daniel Drake0fb67e92009-07-16 14:46:57 +01003035 switch (board_config) {
3036 default:
3037 case CXT5066_LAPTOP:
3038 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3039 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3040 break;
3041 case CXT5066_DELL_LAPTOP:
3042 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3043 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3044
3045 spec->port_d_mode = PIN_OUT;
3046 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3047 spec->num_init_verbs++;
3048 spec->dell_automute = 1;
3049 break;
David Henningssona1d69062011-01-21 13:33:28 +01003050 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003051 case CXT5066_HP_LAPTOP:
3052 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003053 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003054 spec->init_verbs[spec->num_init_verbs] =
3055 cxt5066_init_verbs_hp_laptop;
3056 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003057 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3058 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003059 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3060 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3061 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003062 if (board_config == CXT5066_HP_LAPTOP)
3063 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003064 /* input source automatically selected */
3065 spec->input_mux = NULL;
3066 spec->port_d_mode = 0;
3067 spec->mic_boost = 3; /* default 30dB gain */
3068 break;
3069
Daniel Drake0fb67e92009-07-16 14:46:57 +01003070 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003071 codec->patch_ops.init = cxt5066_olpc_init;
3072 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003073 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3074 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003075 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003076 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3077 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003078 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003079
3080 /* no S/PDIF out */
3081 spec->multiout.dig_out_nid = 0;
3082
3083 /* input source automatically selected */
3084 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003085
3086 /* our capture hooks which allow us to turn on the microphone LED
3087 * at the right time */
3088 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3089 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003090 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003091 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003092 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003093 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003094 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3095 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3096 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003097 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003098 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003099 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003100 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003101
3102 /* no S/PDIF out */
3103 spec->multiout.dig_out_nid = 0;
3104
3105 /* input source automatically selected */
3106 spec->input_mux = NULL;
3107 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003108 case CXT5066_IDEAPAD:
3109 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003110 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003111 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3112 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3113 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3114 spec->port_d_mode = 0;
3115 spec->ideapad = 1;
3116 spec->mic_boost = 2; /* default 20dB gain */
3117
3118 /* no S/PDIF out */
3119 spec->multiout.dig_out_nid = 0;
3120
3121 /* input source automatically selected */
3122 spec->input_mux = NULL;
3123 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003124 case CXT5066_THINKPAD:
3125 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003126 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003127 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3128 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3129 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3130 spec->thinkpad = 1;
3131 spec->port_d_mode = PIN_OUT;
3132 spec->mic_boost = 2; /* default 20dB gain */
3133
3134 /* no S/PDIF out */
3135 spec->multiout.dig_out_nid = 0;
3136
3137 /* input source automatically selected */
3138 spec->input_mux = NULL;
3139 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003140 }
3141
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003142 if (spec->beep_amp)
Takashi Iwai184e91c2013-03-18 11:00:44 +01003143 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003144
Daniel Drake0fb67e92009-07-16 14:46:57 +01003145 return 0;
3146}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003147
3148/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003149 * Automatic parser for CX20641 & co
3150 */
3151
Takashi Iwai6764bce2011-05-13 16:52:25 +02003152static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3153 struct hda_codec *codec,
3154 unsigned int stream_tag,
3155 unsigned int format,
3156 struct snd_pcm_substream *substream)
3157{
3158 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003159 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003160 if (spec->adc_switching) {
3161 spec->cur_adc = adc;
3162 spec->cur_adc_stream_tag = stream_tag;
3163 spec->cur_adc_format = format;
3164 }
3165 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3166 return 0;
3167}
3168
3169static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3170 struct hda_codec *codec,
3171 struct snd_pcm_substream *substream)
3172{
3173 struct conexant_spec *spec = codec->spec;
3174 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3175 spec->cur_adc = 0;
3176 return 0;
3177}
3178
3179static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3180 .substreams = 1,
3181 .channels_min = 2,
3182 .channels_max = 2,
3183 .nid = 0, /* fill later */
3184 .ops = {
3185 .prepare = cx_auto_capture_pcm_prepare,
3186 .cleanup = cx_auto_capture_pcm_cleanup
3187 },
3188};
3189
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003190static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003191
Takashi Iwai8d087c72011-06-28 12:45:47 +02003192#define get_connection_index(codec, mux, nid)\
3193 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003194
3195/* get an unassigned DAC from the given list.
3196 * Return the nid if found and reduce the DAC list, or return zero if
3197 * not found
3198 */
3199static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3200 hda_nid_t *dacs, int *num_dacs)
3201{
3202 int i, nums = *num_dacs;
3203 hda_nid_t ret = 0;
3204
3205 for (i = 0; i < nums; i++) {
3206 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3207 ret = dacs[i];
3208 break;
3209 }
3210 }
3211 if (!ret)
3212 return 0;
3213 if (--nums > 0)
3214 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3215 *num_dacs = nums;
3216 return ret;
3217}
3218
3219#define MAX_AUTO_DACS 5
3220
Takashi Iwai1f015f52011-08-23 14:57:08 +02003221#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3222
Takashi Iwaif2e57312010-09-15 10:07:08 +02003223/* fill analog DAC list from the widget tree */
3224static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3225{
3226 hda_nid_t nid, end_nid;
3227 int nums = 0;
3228
3229 end_nid = codec->start_nid + codec->num_nodes;
3230 for (nid = codec->start_nid; nid < end_nid; nid++) {
3231 unsigned int wcaps = get_wcaps(codec, nid);
3232 unsigned int type = get_wcaps_type(wcaps);
3233 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3234 dacs[nums++] = nid;
3235 if (nums >= MAX_AUTO_DACS)
3236 break;
3237 }
3238 }
3239 return nums;
3240}
3241
3242/* fill pin_dac_pair list from the pin and dac list */
3243static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3244 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003245 struct pin_dac_pair *filled, int nums,
3246 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003247{
David Henningsson468c5452011-08-25 13:16:02 +02003248 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003249
David Henningsson468c5452011-08-25 13:16:02 +02003250 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003251 filled[nums].pin = pins[i];
3252 filled[nums].type = type;
3253 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003254 if (filled[nums].dac)
3255 continue;
3256 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3257 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3258 continue;
3259 }
3260 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003261 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003262 continue;
3263 }
3264 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003265 }
3266 return nums;
3267}
3268
3269/* parse analog output paths */
3270static void cx_auto_parse_output(struct hda_codec *codec)
3271{
3272 struct conexant_spec *spec = codec->spec;
3273 struct auto_pin_cfg *cfg = &spec->autocfg;
3274 hda_nid_t dacs[MAX_AUTO_DACS];
3275 int i, j, nums, rest;
3276
3277 rest = fill_cx_auto_dacs(codec, dacs);
3278 /* parse all analog output pins */
3279 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003280 dacs, &rest, spec->dac_info, 0,
3281 AUTO_PIN_LINE_OUT);
3282 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3283 dacs, &rest, spec->dac_info, nums,
3284 AUTO_PIN_HP_OUT);
3285 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3286 dacs, &rest, spec->dac_info, nums,
3287 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003288 spec->dac_info_filled = nums;
3289 /* fill multiout struct */
3290 for (i = 0; i < nums; i++) {
3291 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003292 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003293 continue;
3294 switch (spec->dac_info[i].type) {
3295 case AUTO_PIN_LINE_OUT:
3296 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3297 spec->multiout.num_dacs++;
3298 break;
3299 case AUTO_PIN_HP_OUT:
3300 case AUTO_PIN_SPEAKER_OUT:
3301 if (!spec->multiout.hp_nid) {
3302 spec->multiout.hp_nid = dac;
3303 break;
3304 }
3305 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3306 if (!spec->multiout.extra_out_nid[j]) {
3307 spec->multiout.extra_out_nid[j] = dac;
3308 break;
3309 }
3310 break;
3311 }
3312 }
3313 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003314 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003315
Takashi Iwai03697e22011-05-17 09:53:31 +02003316 for (i = 0; i < cfg->hp_outs; i++) {
3317 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3318 spec->auto_mute = 1;
3319 break;
3320 }
3321 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003322 if (spec->auto_mute &&
3323 cfg->line_out_pins[0] &&
3324 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003325 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3326 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3327 for (i = 0; i < cfg->line_outs; i++) {
3328 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3329 spec->detect_line = 1;
3330 break;
3331 }
3332 }
3333 spec->automute_lines = spec->detect_line;
3334 }
3335
Takashi Iwaif2e57312010-09-15 10:07:08 +02003336 spec->vmaster_nid = spec->private_dac_nids[0];
3337}
3338
Takashi Iwaida339862011-05-13 16:24:15 +02003339static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3340 hda_nid_t *pins, bool on);
3341
Takashi Iwai03697e22011-05-17 09:53:31 +02003342static void do_automute(struct hda_codec *codec, int num_pins,
3343 hda_nid_t *pins, bool on)
3344{
Takashi Iwai254f2962011-10-14 15:22:34 +02003345 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003346 int i;
3347 for (i = 0; i < num_pins; i++)
3348 snd_hda_codec_write(codec, pins[i], 0,
3349 AC_VERB_SET_PIN_WIDGET_CONTROL,
3350 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003351 if (spec->pin_eapd_ctrls)
3352 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003353}
3354
3355static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3356{
3357 int i, present = 0;
3358
3359 for (i = 0; i < num_pins; i++) {
3360 hda_nid_t nid = pins[i];
3361 if (!nid || !is_jack_detectable(codec, nid))
3362 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003363 present |= snd_hda_jack_detect(codec, nid);
3364 }
3365 return present;
3366}
3367
Takashi Iwaif2e57312010-09-15 10:07:08 +02003368/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003369static void cx_auto_update_speakers(struct hda_codec *codec)
3370{
3371 struct conexant_spec *spec = codec->spec;
3372 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003373 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003374
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003375 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003376 if (spec->pin_eapd_ctrls) {
3377 if (spec->auto_mute)
3378 on = spec->hp_present;
3379 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3380 }
3381
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003382 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3383 if (spec->auto_mute)
3384 on = !(spec->hp_present ||
3385 (spec->detect_line && spec->line_present));
3386 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003387
3388 /* toggle line-out mutes if needed, too */
3389 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3390 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3391 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3392 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003393 if (spec->auto_mute) {
3394 /* mute LO in auto-mode when HP jack is present */
3395 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3396 spec->automute_lines)
3397 on = !spec->hp_present;
3398 else
3399 on = 1;
3400 }
3401 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003402}
3403
Takashi Iwaif2e57312010-09-15 10:07:08 +02003404static void cx_auto_hp_automute(struct hda_codec *codec)
3405{
3406 struct conexant_spec *spec = codec->spec;
3407 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003408
3409 if (!spec->auto_mute)
3410 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003411 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3412 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003413}
3414
Takashi Iwai03697e22011-05-17 09:53:31 +02003415static void cx_auto_line_automute(struct hda_codec *codec)
3416{
3417 struct conexant_spec *spec = codec->spec;
3418 struct auto_pin_cfg *cfg = &spec->autocfg;
3419
3420 if (!spec->auto_mute || !spec->detect_line)
3421 return;
3422 spec->line_present = detect_jacks(codec, cfg->line_outs,
3423 cfg->line_out_pins);
3424 cx_auto_update_speakers(codec);
3425}
3426
3427static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3428 struct snd_ctl_elem_info *uinfo)
3429{
3430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3431 struct conexant_spec *spec = codec->spec;
3432 static const char * const texts2[] = {
3433 "Disabled", "Enabled"
3434 };
3435 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003436 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003437 };
3438 const char * const *texts;
3439
3440 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3441 uinfo->count = 1;
3442 if (spec->automute_hp_lo) {
3443 uinfo->value.enumerated.items = 3;
3444 texts = texts3;
3445 } else {
3446 uinfo->value.enumerated.items = 2;
3447 texts = texts2;
3448 }
3449 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3450 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3451 strcpy(uinfo->value.enumerated.name,
3452 texts[uinfo->value.enumerated.item]);
3453 return 0;
3454}
3455
3456static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3457 struct snd_ctl_elem_value *ucontrol)
3458{
3459 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3460 struct conexant_spec *spec = codec->spec;
3461 unsigned int val;
3462 if (!spec->auto_mute)
3463 val = 0;
3464 else if (!spec->automute_lines)
3465 val = 1;
3466 else
3467 val = 2;
3468 ucontrol->value.enumerated.item[0] = val;
3469 return 0;
3470}
3471
3472static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3473 struct snd_ctl_elem_value *ucontrol)
3474{
3475 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3476 struct conexant_spec *spec = codec->spec;
3477
3478 switch (ucontrol->value.enumerated.item[0]) {
3479 case 0:
3480 if (!spec->auto_mute)
3481 return 0;
3482 spec->auto_mute = 0;
3483 break;
3484 case 1:
3485 if (spec->auto_mute && !spec->automute_lines)
3486 return 0;
3487 spec->auto_mute = 1;
3488 spec->automute_lines = 0;
3489 break;
3490 case 2:
3491 if (!spec->automute_hp_lo)
3492 return -EINVAL;
3493 if (spec->auto_mute && spec->automute_lines)
3494 return 0;
3495 spec->auto_mute = 1;
3496 spec->automute_lines = 1;
3497 break;
3498 default:
3499 return -EINVAL;
3500 }
3501 cx_auto_update_speakers(codec);
3502 return 1;
3503}
3504
3505static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3506 {
3507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3508 .name = "Auto-Mute Mode",
3509 .info = cx_automute_mode_info,
3510 .get = cx_automute_mode_get,
3511 .put = cx_automute_mode_put,
3512 },
3513 { }
3514};
3515
Takashi Iwai6764bce2011-05-13 16:52:25 +02003516static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3517 struct snd_ctl_elem_info *uinfo)
3518{
3519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3520 struct conexant_spec *spec = codec->spec;
3521
3522 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3523}
3524
3525static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3526 struct snd_ctl_elem_value *ucontrol)
3527{
3528 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3529 struct conexant_spec *spec = codec->spec;
3530
3531 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3532 return 0;
3533}
3534
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003535/* look for the route the given pin from mux and return the index;
3536 * if do_select is set, actually select the route.
3537 */
3538static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003539 hda_nid_t pin, hda_nid_t *srcp,
3540 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003541{
3542 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3543 int i, nums;
3544
Takashi Iwaicf27f292011-05-16 11:33:02 +02003545 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3546 case AC_WID_AUD_IN:
3547 case AC_WID_AUD_SEL:
3548 case AC_WID_AUD_MIX:
3549 break;
3550 default:
3551 return -1;
3552 }
3553
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003554 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3555 for (i = 0; i < nums; i++)
3556 if (conn[i] == pin) {
3557 if (do_select)
3558 snd_hda_codec_write(codec, mux, 0,
3559 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003560 if (srcp)
3561 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003562 return i;
3563 }
3564 depth++;
3565 if (depth == 2)
3566 return -1;
3567 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003568 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003569 do_select, depth);
3570 if (ret >= 0) {
3571 if (do_select)
3572 snd_hda_codec_write(codec, mux, 0,
3573 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003574 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003575 }
3576 }
3577 return -1;
3578}
3579
3580static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3581 hda_nid_t pin)
3582{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003583 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003584}
3585
3586static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3587 hda_nid_t pin)
3588{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003589 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003590}
3591
Takashi Iwai6764bce2011-05-13 16:52:25 +02003592static int cx_auto_mux_enum_update(struct hda_codec *codec,
3593 const struct hda_input_mux *imux,
3594 unsigned int idx)
3595{
3596 struct conexant_spec *spec = codec->spec;
3597 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003598 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003599
3600 if (!imux->num_items)
3601 return 0;
3602 if (idx >= imux->num_items)
3603 idx = imux->num_items - 1;
3604 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003605 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003606 adc = spec->imux_info[idx].adc;
3607 select_input_connection(codec, spec->imux_info[idx].adc,
3608 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003609 if (spec->cur_adc && spec->cur_adc != adc) {
3610 /* stream is running, let's swap the current ADC */
3611 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3612 spec->cur_adc = adc;
3613 snd_hda_codec_setup_stream(codec, adc,
3614 spec->cur_adc_stream_tag, 0,
3615 spec->cur_adc_format);
3616 }
3617 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003618 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003619}
3620
3621static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3622 struct snd_ctl_elem_value *ucontrol)
3623{
3624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3625 struct conexant_spec *spec = codec->spec;
3626
3627 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3628 ucontrol->value.enumerated.item[0]);
3629}
3630
3631static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3632 {
3633 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3634 .name = "Capture Source",
3635 .info = cx_auto_mux_enum_info,
3636 .get = cx_auto_mux_enum_get,
3637 .put = cx_auto_mux_enum_put
3638 },
3639 {}
3640};
3641
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003642static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3643{
3644 struct conexant_spec *spec = codec->spec;
3645 if (idx < 0)
3646 return false;
3647 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3648 return false;
3649 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3650 return true;
3651}
3652
Takashi Iwaif2e57312010-09-15 10:07:08 +02003653/* automatic switch internal and external mic */
3654static void cx_auto_automic(struct hda_codec *codec)
3655{
3656 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003657
3658 if (!spec->auto_mic)
3659 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003660 if (!select_automic(codec, spec->auto_mic_ext, true))
3661 if (!select_automic(codec, spec->auto_mic_dock, true))
3662 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003663}
3664
3665static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3666{
Takashi Iwai3a938972011-10-28 01:16:55 +02003667 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003668 case CONEXANT_HP_EVENT:
3669 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003670 break;
3671 case CONEXANT_LINE_EVENT:
3672 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003673 break;
3674 case CONEXANT_MIC_EVENT:
3675 cx_auto_automic(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003676 break;
3677 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02003678 snd_hda_jack_report_sync(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003679}
3680
Takashi Iwaif2e57312010-09-15 10:07:08 +02003681/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003682 * auto-mic is enabled only when one int-mic and one ext- and/or
3683 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003684 */
3685static void cx_auto_check_auto_mic(struct hda_codec *codec)
3686{
3687 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003688 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3689 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003690
Takashi Iwai506a4192011-05-23 20:07:15 +02003691 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003692 pset[i] = -1;
3693 for (i = 0; i < spec->private_imux.num_items; i++) {
3694 hda_nid_t pin = spec->imux_info[i].pin;
3695 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003696 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003697 attr = snd_hda_get_input_pin_attr(def_conf);
3698 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003699 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003700 if (attr > INPUT_PIN_ATTR_NORMAL)
3701 attr = INPUT_PIN_ATTR_NORMAL;
3702 if (attr != INPUT_PIN_ATTR_INT &&
3703 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003704 return; /* non-detectable pin */
3705 type = get_defcfg_device(def_conf);
3706 if (type != AC_JACK_MIC_IN &&
3707 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3708 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003709 if (pset[attr] >= 0)
3710 return; /* already occupied */
3711 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003712 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003713 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3714 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3715 return; /* no input to switch*/
3716 spec->auto_mic = 1;
3717 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3718 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3719 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003720}
3721
3722static void cx_auto_parse_input(struct hda_codec *codec)
3723{
3724 struct conexant_spec *spec = codec->spec;
3725 struct auto_pin_cfg *cfg = &spec->autocfg;
3726 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003727 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003728
3729 imux = &spec->private_imux;
3730 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003731 for (j = 0; j < spec->num_adc_nids; j++) {
3732 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003733 int idx = get_input_connection(codec, adc,
3734 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003735 if (idx >= 0) {
3736 const char *label;
3737 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003738 spec->imux_info[imux->num_items].index = i;
3739 spec->imux_info[imux->num_items].boost = 0;
3740 spec->imux_info[imux->num_items].adc = adc;
3741 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003742 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003743 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003744 break;
3745 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003746 }
3747 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003748 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003749 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003750 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003751 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003752 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003753 spec->adc_switching = 1;
3754 break;
3755 }
3756 }
3757 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003758}
3759
3760/* get digital-input audio widget corresponding to the given pin */
3761static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3762{
3763 hda_nid_t nid, end_nid;
3764
3765 end_nid = codec->start_nid + codec->num_nodes;
3766 for (nid = codec->start_nid; nid < end_nid; nid++) {
3767 unsigned int wcaps = get_wcaps(codec, nid);
3768 unsigned int type = get_wcaps_type(wcaps);
3769 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3770 if (get_connection_index(codec, nid, pin) >= 0)
3771 return nid;
3772 }
3773 }
3774 return 0;
3775}
3776
3777static void cx_auto_parse_digital(struct hda_codec *codec)
3778{
3779 struct conexant_spec *spec = codec->spec;
3780 struct auto_pin_cfg *cfg = &spec->autocfg;
3781 hda_nid_t nid;
3782
3783 if (cfg->dig_outs &&
3784 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3785 spec->multiout.dig_out_nid = nid;
3786 if (cfg->dig_in_pin)
3787 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3788}
3789
3790#ifdef CONFIG_SND_HDA_INPUT_BEEP
3791static void cx_auto_parse_beep(struct hda_codec *codec)
3792{
3793 struct conexant_spec *spec = codec->spec;
3794 hda_nid_t nid, end_nid;
3795
3796 end_nid = codec->start_nid + codec->num_nodes;
3797 for (nid = codec->start_nid; nid < end_nid; nid++)
3798 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3799 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3800 break;
3801 }
3802}
3803#else
3804#define cx_auto_parse_beep(codec)
3805#endif
3806
Takashi Iwai254f2962011-10-14 15:22:34 +02003807/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003808static void cx_auto_parse_eapd(struct hda_codec *codec)
3809{
3810 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003811 hda_nid_t nid, end_nid;
3812
3813 end_nid = codec->start_nid + codec->num_nodes;
3814 for (nid = codec->start_nid; nid < end_nid; nid++) {
3815 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3816 continue;
3817 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3818 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003819 spec->eapds[spec->num_eapds++] = nid;
3820 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3821 break;
3822 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003823
3824 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3825 * it's a new chip, where EAPDs are supposed to be associated to
3826 * pins, and we can control EAPD per pin.
3827 * OTOH, if only one or two EAPDs are found, it's an old chip,
3828 * thus it might control over all pins.
3829 */
3830 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003831}
3832
Takashi Iwaif2e57312010-09-15 10:07:08 +02003833static int cx_auto_parse_auto_config(struct hda_codec *codec)
3834{
3835 struct conexant_spec *spec = codec->spec;
3836 int err;
3837
3838 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3839 if (err < 0)
3840 return err;
3841
3842 cx_auto_parse_output(codec);
3843 cx_auto_parse_input(codec);
3844 cx_auto_parse_digital(codec);
3845 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003846 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003847 return 0;
3848}
3849
Takashi Iwaida339862011-05-13 16:24:15 +02003850static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3851 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003852{
3853 int i;
3854 for (i = 0; i < num_pins; i++) {
3855 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3856 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003857 AC_VERB_SET_EAPD_BTLENABLE,
3858 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003859 }
3860}
3861
3862static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3863 hda_nid_t src)
3864{
3865 int idx = get_connection_index(codec, pin, src);
3866 if (idx >= 0)
3867 snd_hda_codec_write(codec, pin, 0,
3868 AC_VERB_SET_CONNECT_SEL, idx);
3869}
3870
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003871static void mute_outputs(struct hda_codec *codec, int num_nids,
3872 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003873{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003874 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003875
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003876 for (i = 0; i < num_nids; i++) {
3877 hda_nid_t nid = nids[i];
3878 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3879 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003880 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3881 val = AMP_OUT_MUTE;
3882 else
3883 val = AMP_OUT_ZERO;
3884 snd_hda_codec_write(codec, nid, 0,
3885 AC_VERB_SET_AMP_GAIN_MUTE, val);
3886 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003887}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003888
Takashi Iwai03697e22011-05-17 09:53:31 +02003889static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
Takashi Iwai3a938972011-10-28 01:16:55 +02003890 hda_nid_t *pins, unsigned int action)
Takashi Iwai03697e22011-05-17 09:53:31 +02003891{
3892 int i;
3893 for (i = 0; i < num_pins; i++)
Takashi Iwai3a938972011-10-28 01:16:55 +02003894 snd_hda_jack_detect_enable(codec, pins[i], action);
Takashi Iwai03697e22011-05-17 09:53:31 +02003895}
3896
Takashi Iwai07cafff2012-02-20 12:30:59 +01003897static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3898{
3899 int i;
3900 for (i = 0; i < nums; i++)
3901 if (list[i] == nid)
3902 return true;
3903 return false;
3904}
3905
3906/* is the given NID found in any of autocfg items? */
3907static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3908{
3909 int i;
3910
3911 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3912 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3913 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3914 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3915 return true;
3916 for (i = 0; i < cfg->num_inputs; i++)
3917 if (cfg->inputs[i].pin == nid)
3918 return true;
3919 if (cfg->dig_in_pin == nid)
3920 return true;
3921 return false;
3922}
3923
3924/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3925 * invalid unsol tags by some reason
3926 */
3927static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3928{
3929 struct conexant_spec *spec = codec->spec;
3930 struct auto_pin_cfg *cfg = &spec->autocfg;
3931 int i;
3932
3933 for (i = 0; i < codec->init_pins.used; i++) {
3934 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3935 if (!found_in_autocfg(cfg, pin->nid))
3936 snd_hda_codec_write(codec, pin->nid, 0,
3937 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3938 }
3939}
3940
Takashi Iwai527c73b2012-03-12 12:38:51 +01003941/* turn on/off EAPD according to Master switch */
3942static void cx_auto_vmaster_hook(void *private_data, int enabled)
3943{
3944 struct hda_codec *codec = private_data;
3945 struct conexant_spec *spec = codec->spec;
3946
3947 if (enabled && spec->pin_eapd_ctrls) {
3948 cx_auto_update_speakers(codec);
3949 return;
3950 }
3951 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3952}
3953
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003954static void cx_auto_init_output(struct hda_codec *codec)
3955{
3956 struct conexant_spec *spec = codec->spec;
3957 struct auto_pin_cfg *cfg = &spec->autocfg;
3958 hda_nid_t nid;
3959 int i;
3960
3961 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003962 for (i = 0; i < cfg->hp_outs; i++) {
3963 unsigned int val = PIN_OUT;
3964 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3965 AC_PINCAP_HP_DRV)
3966 val |= AC_PINCTL_HP_EN;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003967 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
Takashi Iwaica3649d2012-04-19 15:15:25 +02003968 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
3969 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003970 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3971 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3972 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003973 for (i = 0; i < spec->dac_info_filled; i++) {
3974 nid = spec->dac_info[i].dac;
3975 if (!nid)
3976 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003977 else if (nid & DAC_SLAVE_FLAG)
3978 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003979 select_connection(codec, spec->dac_info[i].pin, nid);
3980 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003981 if (spec->auto_mute) {
3982 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3983 CONEXANT_HP_EVENT);
3984 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3985 cfg->hp_pins);
3986 if (spec->detect_line) {
3987 enable_unsol_pins(codec, cfg->line_outs,
3988 cfg->line_out_pins,
3989 CONEXANT_LINE_EVENT);
3990 spec->line_present =
3991 detect_jacks(codec, cfg->line_outs,
3992 cfg->line_out_pins);
3993 }
3994 }
3995 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02003996 /* turn on all EAPDs if no individual EAPD control is available */
3997 if (!spec->pin_eapd_ctrls)
3998 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01003999 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004000}
4001
4002static void cx_auto_init_input(struct hda_codec *codec)
4003{
4004 struct conexant_spec *spec = codec->spec;
4005 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004006 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004007
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004008 for (i = 0; i < spec->num_adc_nids; i++) {
4009 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004010 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4011 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004012 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4013 val = AMP_IN_MUTE(0);
4014 else
4015 val = AMP_IN_UNMUTE(0);
4016 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4017 val);
4018 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004019
4020 for (i = 0; i < cfg->num_inputs; i++) {
4021 unsigned int type;
4022 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4023 type = PIN_VREF80;
4024 else
4025 type = PIN_IN;
4026 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4027 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4028 }
4029
4030 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004031 if (spec->auto_mic_ext >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004032 snd_hda_jack_detect_enable(codec,
4033 cfg->inputs[spec->auto_mic_ext].pin,
4034 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004035 }
4036 if (spec->auto_mic_dock >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004037 snd_hda_jack_detect_enable(codec,
4038 cfg->inputs[spec->auto_mic_dock].pin,
4039 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004040 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004041 cx_auto_automic(codec);
4042 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004043 select_input_connection(codec, spec->imux_info[0].adc,
4044 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004045 }
4046}
4047
4048static void cx_auto_init_digital(struct hda_codec *codec)
4049{
4050 struct conexant_spec *spec = codec->spec;
4051 struct auto_pin_cfg *cfg = &spec->autocfg;
4052
4053 if (spec->multiout.dig_out_nid)
4054 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4055 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4056 if (spec->dig_in_nid)
4057 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4058 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4059}
4060
4061static int cx_auto_init(struct hda_codec *codec)
4062{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004063 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004064 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4065 cx_auto_init_output(codec);
4066 cx_auto_init_input(codec);
4067 cx_auto_init_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004068 snd_hda_jack_report_sync(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004069 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004070 return 0;
4071}
4072
David Henningsson983345e2011-02-15 19:57:09 +01004073static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004074 const char *dir, int cidx,
David Henningssoncae4d9a2012-04-02 15:40:27 +02004075 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004076{
David Henningssoncae4d9a2012-04-02 15:40:27 +02004077 static char name[44];
Takashi Iwaif2e57312010-09-15 10:07:08 +02004078 static struct snd_kcontrol_new knew[] = {
4079 HDA_CODEC_VOLUME(name, 0, 0, 0),
4080 HDA_CODEC_MUTE(name, 0, 0, 0),
4081 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004082 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004083 int i, err;
4084
4085 for (i = 0; i < 2; i++) {
4086 struct snd_kcontrol *kctl;
David Henningssoncae4d9a2012-04-02 15:40:27 +02004087 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
David Henningsson983345e2011-02-15 19:57:09 +01004088 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004089 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4090 knew[i].index = cidx;
4091 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4092 kctl = snd_ctl_new1(&knew[i], codec);
4093 if (!kctl)
4094 return -ENOMEM;
4095 err = snd_hda_ctl_add(codec, nid, kctl);
4096 if (err < 0)
4097 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004098 if (!(query_amp_caps(codec, nid, hda_dir) &
4099 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004100 break;
4101 }
4102 return 0;
4103}
4104
David Henningsson983345e2011-02-15 19:57:09 +01004105#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
David Henningssoncae4d9a2012-04-02 15:40:27 +02004106 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
David Henningsson983345e2011-02-15 19:57:09 +01004107
Takashi Iwaif2e57312010-09-15 10:07:08 +02004108#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4109 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4110
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004111static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4112 hda_nid_t pin, const char *name, int idx)
4113{
4114 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004115 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4116 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4117 if (caps & AC_AMPCAP_NUM_STEPS)
4118 return cx_auto_add_pb_volume(codec, dac, name, idx);
4119 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004120 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4121 if (caps & AC_AMPCAP_NUM_STEPS)
4122 return cx_auto_add_pb_volume(codec, pin, name, idx);
4123 return 0;
4124}
4125
Takashi Iwaif2e57312010-09-15 10:07:08 +02004126static int cx_auto_build_output_controls(struct hda_codec *codec)
4127{
4128 struct conexant_spec *spec = codec->spec;
4129 int i, err;
4130 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004131 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004132
4133 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004134 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4135 spec->dac_info[0].pin,
4136 "Master", 0);
4137
Takashi Iwaif2e57312010-09-15 10:07:08 +02004138 for (i = 0; i < spec->dac_info_filled; i++) {
4139 const char *label;
4140 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004141 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004142 type = spec->dac_info[i].type;
4143 if (type == AUTO_PIN_LINE_OUT)
4144 type = spec->autocfg.line_out_type;
4145 switch (type) {
4146 case AUTO_PIN_LINE_OUT:
4147 default:
4148 label = texts[num_line++];
4149 idx = 0;
4150 break;
4151 case AUTO_PIN_HP_OUT:
4152 label = "Headphone";
4153 idx = num_hp++;
4154 break;
4155 case AUTO_PIN_SPEAKER_OUT:
4156 label = "Speaker";
4157 idx = num_spk++;
4158 break;
4159 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004160 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004161 spec->dac_info[i].pin,
4162 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004163 if (err < 0)
4164 return err;
4165 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004166
4167 if (spec->auto_mute) {
4168 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4169 if (err < 0)
4170 return err;
4171 }
4172
Takashi Iwaif2e57312010-09-15 10:07:08 +02004173 return 0;
4174}
4175
David Henningssoncae4d9a2012-04-02 15:40:27 +02004176/* Returns zero if this is a normal stereo channel, and non-zero if it should
4177 be split in two independent channels.
4178 dest_label must be at least 44 characters. */
4179static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4180 char *dest_label, int nid)
4181{
4182 struct conexant_spec *spec = codec->spec;
4183 int i;
4184
4185 if (!spec->fixup_stereo_dmic)
4186 return 0;
4187
4188 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4189 int def_conf;
4190 if (spec->autocfg.inputs[i].pin != nid)
4191 continue;
4192
4193 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4194 return 0;
4195 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4196 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4197 return 0;
4198
4199 /* Finally found the inverted internal mic! */
4200 snprintf(dest_label, 44, "Inverted %s", label);
4201 return 1;
4202 }
4203 return 0;
4204}
4205
Takashi Iwai6764bce2011-05-13 16:52:25 +02004206static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4207 const char *label, const char *pfx,
4208 int cidx)
4209{
4210 struct conexant_spec *spec = codec->spec;
4211 int i;
4212
4213 for (i = 0; i < spec->num_adc_nids; i++) {
David Henningssoncae4d9a2012-04-02 15:40:27 +02004214 char rightch_label[44];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004215 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004216 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004217 if (idx < 0)
4218 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004219 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004220 idx = 0;
David Henningssoncae4d9a2012-04-02 15:40:27 +02004221
4222 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4223 /* Make two independent kcontrols for left and right */
4224 int err = cx_auto_add_volume_idx(codec, label, pfx,
4225 cidx, adc_nid, HDA_INPUT, idx, 1);
4226 if (err < 0)
4227 return err;
4228 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4229 cidx, adc_nid, HDA_INPUT, idx, 2);
4230 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004231 return cx_auto_add_volume_idx(codec, label, pfx,
David Henningssoncae4d9a2012-04-02 15:40:27 +02004232 cidx, adc_nid, HDA_INPUT, idx, 3);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004233 }
4234 return 0;
4235}
4236
Takashi Iwaicf27f292011-05-16 11:33:02 +02004237static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4238 const char *label, int cidx)
4239{
4240 struct conexant_spec *spec = codec->spec;
4241 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004242 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004243
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004244 nid = spec->imux_info[idx].pin;
David Henningssoncae4d9a2012-04-02 15:40:27 +02004245 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4246 char rightch_label[44];
4247 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4248 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4249 cidx, nid, HDA_INPUT, 0, 1);
4250 if (err < 0)
4251 return err;
4252 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4253 cidx, nid, HDA_INPUT, 0, 2);
4254 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004255 return cx_auto_add_volume(codec, label, " Boost", cidx,
4256 nid, HDA_INPUT);
David Henningssoncae4d9a2012-04-02 15:40:27 +02004257 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004258 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4259 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004260 if (con < 0)
4261 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004262 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004263 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004264 return 0; /* already present */
4265 }
4266
4267 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004268 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004269 return cx_auto_add_volume(codec, label, " Boost", 0,
4270 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004271 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004272 return 0;
4273}
4274
Takashi Iwaif2e57312010-09-15 10:07:08 +02004275static int cx_auto_build_input_controls(struct hda_codec *codec)
4276{
4277 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004278 struct hda_input_mux *imux = &spec->private_imux;
4279 const char *prev_label;
4280 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004281 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004282 int multi_connection;
4283
Takashi Iwai6b452142011-10-14 15:26:20 +02004284 if (!imux->num_items)
4285 return 0;
4286
Takashi Iwaicf27f292011-05-16 11:33:02 +02004287 multi_connection = 0;
4288 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004289 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4290 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004291 if (cidx < 0)
4292 continue;
4293 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004294 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004295 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004296 if (i > 0 && input_conn[i] != input_conn[0])
4297 multi_connection = 1;
4298 }
David Henningsson983345e2011-02-15 19:57:09 +01004299
Takashi Iwaif2e57312010-09-15 10:07:08 +02004300 prev_label = NULL;
4301 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004302 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004303 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004304 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004305
Takashi Iwaicf27f292011-05-16 11:33:02 +02004306 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004307 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004308 if (label == prev_label)
4309 cidx++;
4310 else
4311 cidx = 0;
4312 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004313
Takashi Iwaicf27f292011-05-16 11:33:02 +02004314 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4315 if (err < 0)
4316 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004317
Takashi Iwaicf27f292011-05-16 11:33:02 +02004318 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004319 if (i > 0)
4320 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004321 err = cx_auto_add_capture_volume(codec, nid,
4322 "Capture", "", cidx);
4323 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004324 bool dup_found = false;
4325 for (j = 0; j < i; j++) {
4326 if (input_conn[j] == input_conn[i]) {
4327 dup_found = true;
4328 break;
4329 }
4330 }
4331 if (dup_found)
4332 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004333 err = cx_auto_add_capture_volume(codec, nid,
4334 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004335 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004336 if (err < 0)
4337 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004338 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004339
4340 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4341 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4342 if (err < 0)
4343 return err;
4344 }
4345
Takashi Iwaif2e57312010-09-15 10:07:08 +02004346 return 0;
4347}
4348
4349static int cx_auto_build_controls(struct hda_codec *codec)
4350{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004351 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004352 int err;
4353
4354 err = cx_auto_build_output_controls(codec);
4355 if (err < 0)
4356 return err;
4357 err = cx_auto_build_input_controls(codec);
4358 if (err < 0)
4359 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004360 err = conexant_build_controls(codec);
4361 if (err < 0)
4362 return err;
4363 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4364 if (err < 0)
4365 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004366 if (spec->vmaster_mute.sw_kctl) {
4367 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4368 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4369 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004370 if (err < 0)
4371 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004372 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004373 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004374}
4375
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004376static int cx_auto_search_adcs(struct hda_codec *codec)
4377{
4378 struct conexant_spec *spec = codec->spec;
4379 hda_nid_t nid, end_nid;
4380
4381 end_nid = codec->start_nid + codec->num_nodes;
4382 for (nid = codec->start_nid; nid < end_nid; nid++) {
4383 unsigned int caps = get_wcaps(codec, nid);
4384 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4385 continue;
4386 if (caps & AC_WCAP_DIGITAL)
4387 continue;
4388 if (snd_BUG_ON(spec->num_adc_nids >=
4389 ARRAY_SIZE(spec->private_adc_nids)))
4390 break;
4391 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4392 }
4393 spec->adc_nids = spec->private_adc_nids;
4394 return 0;
4395}
4396
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004397static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004398 .build_controls = cx_auto_build_controls,
4399 .build_pcms = conexant_build_pcms,
4400 .init = cx_auto_init,
4401 .free = conexant_free,
4402 .unsol_event = cx_auto_unsol_event,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004403};
4404
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004405/*
4406 * pin fix-up
4407 */
4408struct cxt_pincfg {
4409 hda_nid_t nid;
4410 u32 val;
4411};
4412
4413static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4414{
4415 for (; cfg->nid; cfg++)
4416 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4417
4418}
4419
David Henningssoncae4d9a2012-04-02 15:40:27 +02004420enum {
4421 CXT_PINCFG_LENOVO_X200,
4422 CXT_PINCFG_LENOVO_TP410,
4423 CXT_FIXUP_STEREO_DMIC
4424};
4425
4426static void apply_fixup(struct hda_codec *codec,
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004427 const struct snd_pci_quirk *quirk,
4428 const struct cxt_pincfg **table)
4429{
David Henningssoncae4d9a2012-04-02 15:40:27 +02004430 struct conexant_spec *spec = codec->spec;
4431
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004432 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
David Henningssoncae4d9a2012-04-02 15:40:27 +02004433 if (quirk && table[quirk->value]) {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004434 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4435 quirk->name);
4436 apply_pincfg(codec, table[quirk->value]);
4437 }
David Henningssoncae4d9a2012-04-02 15:40:27 +02004438 if (quirk->value == CXT_FIXUP_STEREO_DMIC) {
4439 snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n",
4440 quirk->name);
4441 spec->fixup_stereo_dmic = 1;
4442 }
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004443}
4444
Takashi Iwaid70f3632012-04-19 15:18:08 +02004445/* ThinkPad X200 & co with cxt5051 */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004446static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4447 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4448 { 0x17, 0x21a11000 }, /* dock-mic */
4449 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004450 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004451 {}
4452};
4453
Takashi Iwaid70f3632012-04-19 15:18:08 +02004454/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4455static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = {
4456 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4457 { 0x1a, 0x21a190f0 }, /* dock-mic */
4458 { 0x1c, 0x212140ff }, /* dock-HP */
4459 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004460};
4461
Takashi Iwaid70f3632012-04-19 15:18:08 +02004462static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4463 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4464 [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410,
David Henningssoncae4d9a2012-04-02 15:40:27 +02004465 [CXT_FIXUP_STEREO_DMIC] = NULL,
Takashi Iwaid70f3632012-04-19 15:18:08 +02004466};
4467
4468static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004469 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4470 {}
4471};
4472
Takashi Iwaid70f3632012-04-19 15:18:08 +02004473static const struct snd_pci_quirk cxt5066_fixups[] = {
4474 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4475 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4476 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4477 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4478 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningssoncae4d9a2012-04-02 15:40:27 +02004479 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Felix Kaechele419f4df2012-09-26 01:20:44 +02004480 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
David Henningsson8194af42012-06-21 16:03:01 +02004481 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaid70f3632012-04-19 15:18:08 +02004482 {}
4483};
4484
Takashi Iwai38681372012-02-27 15:00:58 +01004485/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4486 * can be created (bko#42825)
4487 */
4488static void add_cx5051_fake_mutes(struct hda_codec *codec)
4489{
4490 static hda_nid_t out_nids[] = {
4491 0x10, 0x11, 0
4492 };
4493 hda_nid_t *p;
4494
4495 for (p = out_nids; *p; p++)
4496 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4497 AC_AMPCAP_MIN_MUTE |
4498 query_amp_caps(codec, *p, HDA_OUTPUT));
4499}
4500
Takashi Iwaif2e57312010-09-15 10:07:08 +02004501static int patch_conexant_auto(struct hda_codec *codec)
4502{
4503 struct conexant_spec *spec;
4504 int err;
4505
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004506 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4507 codec->chip_name);
4508
Takashi Iwaif2e57312010-09-15 10:07:08 +02004509 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4510 if (!spec)
4511 return -ENOMEM;
4512 codec->spec = spec;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004513
Takashi Iwai6b452142011-10-14 15:26:20 +02004514 switch (codec->vendor_id) {
4515 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004516 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004517 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004518 case 0x14f15051:
4519 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02004520 codec->pin_amp_workaround = 1;
David Henningssoncae4d9a2012-04-02 15:40:27 +02004521 apply_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl);
Takashi Iwai38681372012-02-27 15:00:58 +01004522 break;
Michael Karcher51969d62012-04-06 15:34:19 +02004523 default:
4524 codec->pin_amp_workaround = 1;
David Henningssoncae4d9a2012-04-02 15:40:27 +02004525 apply_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl);
Takashi Iwai6b452142011-10-14 15:26:20 +02004526 }
4527
Takashi Iwaif29735c2012-03-13 07:55:10 +01004528 /* Show mute-led control only on HP laptops
4529 * This is a sort of white-list: on HP laptops, EAPD corresponds
4530 * only to the mute-LED without actualy amp function. Meanwhile,
4531 * others may use EAPD really as an amp switch, so it might be
4532 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004533 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004534 switch (codec->subsystem_id >> 16) {
4535 case 0x103c:
4536 spec->vmaster_mute_led = 1;
4537 break;
4538 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004539
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004540 err = cx_auto_search_adcs(codec);
4541 if (err < 0)
4542 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004543 err = cx_auto_parse_auto_config(codec);
4544 if (err < 0) {
4545 kfree(codec->spec);
4546 codec->spec = NULL;
4547 return err;
4548 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004549 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004550 codec->patch_ops = cx_auto_patch_ops;
4551 if (spec->beep_amp)
Takashi Iwai184e91c2013-03-18 11:00:44 +01004552 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004553
4554 /* Some laptops with Conexant chips show stalls in S3 resume,
4555 * which falls into the single-cmd mode.
4556 * Better to make reset, then.
4557 */
4558 if (!codec->bus->sync_write) {
4559 snd_printd("hda_codec: "
4560 "Enable sync_write for stable communication\n");
4561 codec->bus->sync_write = 1;
4562 codec->bus->allow_bus_reset = 1;
4563 }
4564
Takashi Iwaif2e57312010-09-15 10:07:08 +02004565 return 0;
4566}
4567
4568/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004569 */
4570
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004571static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Takashi Iwai4aab66f2012-05-10 08:54:23 +02004572 { .id = 0x14f11510, .name = "CX20751/2",
4573 .patch = patch_conexant_auto },
4574 { .id = 0x14f11511, .name = "CX20753/4",
4575 .patch = patch_conexant_auto },
Tobin Davis82f30042007-02-13 12:45:44 +01004576 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4577 .patch = patch_cxt5045 },
4578 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4579 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004580 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4581 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004582 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4583 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004584 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4585 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004586 { .id = 0x14f15068, .name = "CX20584",
4587 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004588 { .id = 0x14f15069, .name = "CX20585",
4589 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004590 { .id = 0x14f1506c, .name = "CX20588",
4591 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004592 { .id = 0x14f1506e, .name = "CX20590",
4593 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004594 { .id = 0x14f15097, .name = "CX20631",
4595 .patch = patch_conexant_auto },
4596 { .id = 0x14f15098, .name = "CX20632",
4597 .patch = patch_conexant_auto },
4598 { .id = 0x14f150a1, .name = "CX20641",
4599 .patch = patch_conexant_auto },
4600 { .id = 0x14f150a2, .name = "CX20642",
4601 .patch = patch_conexant_auto },
4602 { .id = 0x14f150ab, .name = "CX20651",
4603 .patch = patch_conexant_auto },
4604 { .id = 0x14f150ac, .name = "CX20652",
4605 .patch = patch_conexant_auto },
4606 { .id = 0x14f150b8, .name = "CX20664",
4607 .patch = patch_conexant_auto },
4608 { .id = 0x14f150b9, .name = "CX20665",
4609 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004610 {} /* terminator */
4611};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004612
Takashi Iwai4aab66f2012-05-10 08:54:23 +02004613MODULE_ALIAS("snd-hda-codec-id:14f11510");
4614MODULE_ALIAS("snd-hda-codec-id:14f11511");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004615MODULE_ALIAS("snd-hda-codec-id:14f15045");
4616MODULE_ALIAS("snd-hda-codec-id:14f15047");
4617MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004618MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004619MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004620MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004621MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004622MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004623MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004624MODULE_ALIAS("snd-hda-codec-id:14f15097");
4625MODULE_ALIAS("snd-hda-codec-id:14f15098");
4626MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4627MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4628MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4629MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4630MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4631MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004632
4633MODULE_LICENSE("GPL");
4634MODULE_DESCRIPTION("Conexant HD-audio codec");
4635
4636static struct hda_codec_preset_list conexant_list = {
4637 .preset = snd_hda_preset_conexant,
4638 .owner = THIS_MODULE,
4639};
4640
4641static int __init patch_conexant_init(void)
4642{
4643 return snd_hda_add_codec_preset(&conexant_list);
4644}
4645
4646static void __exit patch_conexant_exit(void)
4647{
4648 snd_hda_delete_codec_preset(&conexant_list);
4649}
4650
4651module_init(patch_conexant_init)
4652module_exit(patch_conexant_exit)