blob: 623cd9be5477c1bf098fe315e621d49c8c1a199e [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>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020032#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010033
34#define CXT_PIN_DIR_IN 0x00
35#define CXT_PIN_DIR_OUT 0x01
36#define CXT_PIN_DIR_INOUT 0x02
37#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39
40#define CONEXANT_HP_EVENT 0x37
41#define CONEXANT_MIC_EVENT 0x38
42
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010043/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010044
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010045#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046#define CXT5051_PORTB_EVENT 0x38
47#define CXT5051_PORTC_EVENT 0x39
48
Takashi Iwaifaddaa52010-01-23 22:31:36 +010049#define AUTO_MIC_PORTB (1 << 1)
50#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010051
Takashi Iwaif2e57312010-09-15 10:07:08 +020052struct pin_dac_pair {
53 hda_nid_t pin;
54 hda_nid_t dac;
55 int type;
56};
57
Tobin Davisc9b443d2006-11-14 12:13:39 +010058struct conexant_spec {
59
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020060 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010061 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010062 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010063
64 const struct hda_verb *init_verbs[5]; /* initialization verbs
65 * don't forget NULL
66 * termination!
67 */
68 unsigned int num_init_verbs;
69
70 /* playback */
71 struct hda_multi_out multiout; /* playback set-up
72 * max_channels, dacs must be set
73 * dig_out_nid and hp_nid are optional
74 */
75 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010076 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010077 unsigned int auto_mic;
Takashi Iwaif2e57312010-09-15 10:07:08 +020078 int auto_mic_ext; /* autocfg.inputs[] index for ext mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010079 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050080 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010081
82 /* capture */
83 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020084 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010085 hda_nid_t dig_in_nid; /* digital-in NID; optional */
86
Takashi Iwai461e2c72008-01-25 11:35:17 +010087 unsigned int cur_adc_idx;
88 hda_nid_t cur_adc;
89 unsigned int cur_adc_stream_tag;
90 unsigned int cur_adc_format;
91
Takashi Iwai6764bce2011-05-13 16:52:25 +020092 const struct hda_pcm_stream *capture_stream;
93
Tobin Davisc9b443d2006-11-14 12:13:39 +010094 /* capture source */
95 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020096 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010097 unsigned int cur_mux[3];
98
99 /* channel model */
100 const struct hda_channel_mode *channel_mode;
101 int num_channel_mode;
102
103 /* PCM information */
104 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
105
Tobin Davisc9b443d2006-11-14 12:13:39 +0100106 unsigned int spdif_route;
107
108 /* dynamic controls, init_verbs and input_mux */
109 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100110 struct hda_input_mux private_imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +0200111 hda_nid_t imux_adcs[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200112 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200113 struct pin_dac_pair dac_info[8];
114 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100115
Daniel Drake0fb67e92009-07-16 14:46:57 +0100116 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200117 unsigned int auto_mute:1; /* used in auto-parser */
118 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500119 unsigned int dell_vostro:1;
120 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200121 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200122 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100123 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100124
Takashi Iwai6764bce2011-05-13 16:52:25 +0200125 unsigned int adc_switching:1;
126
Daniel Drake75f89912010-01-07 13:46:25 +0100127 unsigned int ext_mic_present;
128 unsigned int recording;
129 void (*capture_prepare)(struct hda_codec *codec);
130 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100131
132 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
133 * through the microphone jack.
134 * When the user enables this through a mixer switch, both internal and
135 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
136 * we also allow the bias to be configured through a separate mixer
137 * control. */
138 unsigned int dc_enable;
139 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
140 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200141
142 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100143};
144
145static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
146 struct hda_codec *codec,
147 struct snd_pcm_substream *substream)
148{
149 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100150 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
151 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100152}
153
154static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
155 struct hda_codec *codec,
156 unsigned int stream_tag,
157 unsigned int format,
158 struct snd_pcm_substream *substream)
159{
160 struct conexant_spec *spec = codec->spec;
161 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
162 stream_tag,
163 format, substream);
164}
165
166static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
167 struct hda_codec *codec,
168 struct snd_pcm_substream *substream)
169{
170 struct conexant_spec *spec = codec->spec;
171 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
172}
173
174/*
175 * Digital out
176 */
177static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
178 struct hda_codec *codec,
179 struct snd_pcm_substream *substream)
180{
181 struct conexant_spec *spec = codec->spec;
182 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
183}
184
185static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
186 struct hda_codec *codec,
187 struct snd_pcm_substream *substream)
188{
189 struct conexant_spec *spec = codec->spec;
190 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
191}
192
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200193static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
194 struct hda_codec *codec,
195 unsigned int stream_tag,
196 unsigned int format,
197 struct snd_pcm_substream *substream)
198{
199 struct conexant_spec *spec = codec->spec;
200 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
201 stream_tag,
202 format, substream);
203}
204
Tobin Davisc9b443d2006-11-14 12:13:39 +0100205/*
206 * Analog capture
207 */
208static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
209 struct hda_codec *codec,
210 unsigned int stream_tag,
211 unsigned int format,
212 struct snd_pcm_substream *substream)
213{
214 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100215 if (spec->capture_prepare)
216 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100217 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
218 stream_tag, 0, format);
219 return 0;
220}
221
222static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
223 struct hda_codec *codec,
224 struct snd_pcm_substream *substream)
225{
226 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100227 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100228 if (spec->capture_cleanup)
229 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100230 return 0;
231}
232
233
234
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200235static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100236 .substreams = 1,
237 .channels_min = 2,
238 .channels_max = 2,
239 .nid = 0, /* fill later */
240 .ops = {
241 .open = conexant_playback_pcm_open,
242 .prepare = conexant_playback_pcm_prepare,
243 .cleanup = conexant_playback_pcm_cleanup
244 },
245};
246
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200247static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100248 .substreams = 1,
249 .channels_min = 2,
250 .channels_max = 2,
251 .nid = 0, /* fill later */
252 .ops = {
253 .prepare = conexant_capture_pcm_prepare,
254 .cleanup = conexant_capture_pcm_cleanup
255 },
256};
257
258
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200259static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100260 .substreams = 1,
261 .channels_min = 2,
262 .channels_max = 2,
263 .nid = 0, /* fill later */
264 .ops = {
265 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200266 .close = conexant_dig_playback_pcm_close,
267 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100268 },
269};
270
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200271static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100272 .substreams = 1,
273 .channels_min = 2,
274 .channels_max = 2,
275 /* NID is set in alc_build_pcms */
276};
277
Takashi Iwai461e2c72008-01-25 11:35:17 +0100278static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
279 struct hda_codec *codec,
280 unsigned int stream_tag,
281 unsigned int format,
282 struct snd_pcm_substream *substream)
283{
284 struct conexant_spec *spec = codec->spec;
285 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
286 spec->cur_adc_stream_tag = stream_tag;
287 spec->cur_adc_format = format;
288 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
289 return 0;
290}
291
292static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
293 struct hda_codec *codec,
294 struct snd_pcm_substream *substream)
295{
296 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100297 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100298 spec->cur_adc = 0;
299 return 0;
300}
301
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200302static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100303 .substreams = 1,
304 .channels_min = 2,
305 .channels_max = 2,
306 .nid = 0, /* fill later */
307 .ops = {
308 .prepare = cx5051_capture_pcm_prepare,
309 .cleanup = cx5051_capture_pcm_cleanup
310 },
311};
312
Tobin Davisc9b443d2006-11-14 12:13:39 +0100313static int conexant_build_pcms(struct hda_codec *codec)
314{
315 struct conexant_spec *spec = codec->spec;
316 struct hda_pcm *info = spec->pcm_rec;
317
318 codec->num_pcms = 1;
319 codec->pcm_info = info;
320
321 info->name = "CONEXANT Analog";
322 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
323 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
324 spec->multiout.max_channels;
325 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
326 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200327 if (spec->capture_stream)
328 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
329 else {
330 if (codec->vendor_id == 0x14f15051)
331 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
332 cx5051_pcm_analog_capture;
333 else {
334 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
335 conexant_pcm_analog_capture;
336 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
337 spec->num_adc_nids;
338 }
339 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100340 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
341
342 if (spec->multiout.dig_out_nid) {
343 info++;
344 codec->num_pcms++;
345 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100346 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
348 conexant_pcm_digital_playback;
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
350 spec->multiout.dig_out_nid;
351 if (spec->dig_in_nid) {
352 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
353 conexant_pcm_digital_capture;
354 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
355 spec->dig_in_nid;
356 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500357 if (spec->slave_dig_outs[0])
358 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100359 }
360
361 return 0;
362}
363
364static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
365 struct snd_ctl_elem_info *uinfo)
366{
367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368 struct conexant_spec *spec = codec->spec;
369
370 return snd_hda_input_mux_info(spec->input_mux, uinfo);
371}
372
373static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
375{
376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377 struct conexant_spec *spec = codec->spec;
378 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379
380 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
381 return 0;
382}
383
384static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_value *ucontrol)
386{
387 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388 struct conexant_spec *spec = codec->spec;
389 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
390
391 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
392 spec->capsrc_nids[adc_idx],
393 &spec->cur_mux[adc_idx]);
394}
395
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100396static int conexant_init_jacks(struct hda_codec *codec)
397{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100398#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100399 struct conexant_spec *spec = codec->spec;
400 int i;
401
402 for (i = 0; i < spec->num_init_verbs; i++) {
403 const struct hda_verb *hv;
404
405 hv = spec->init_verbs[i];
406 while (hv->nid) {
407 int err = 0;
408 switch (hv->param ^ AC_USRSP_EN) {
409 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100410 err = snd_hda_input_jack_add(codec, hv->nid,
411 SND_JACK_HEADPHONE, NULL);
412 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100413 break;
414 case CXT5051_PORTC_EVENT:
415 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100416 err = snd_hda_input_jack_add(codec, hv->nid,
417 SND_JACK_MICROPHONE, NULL);
418 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100419 break;
420 }
421 if (err < 0)
422 return err;
423 ++hv;
424 }
425 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100426#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100427 return 0;
428}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100429
Tobin Davisc9b443d2006-11-14 12:13:39 +0100430static int conexant_init(struct hda_codec *codec)
431{
432 struct conexant_spec *spec = codec->spec;
433 int i;
434
435 for (i = 0; i < spec->num_init_verbs; i++)
436 snd_hda_sequence_write(codec, spec->init_verbs[i]);
437 return 0;
438}
439
440static void conexant_free(struct hda_codec *codec)
441{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100442 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200443 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100444 kfree(codec->spec);
445}
446
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200447static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100448 {
449 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
450 .name = "Capture Source",
451 .info = conexant_mux_enum_info,
452 .get = conexant_mux_enum_get,
453 .put = conexant_mux_enum_put
454 },
455 {}
456};
457
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200458#ifdef CONFIG_SND_HDA_INPUT_BEEP
459/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200460static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200461 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
462 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
463 { } /* end */
464};
465#endif
466
Takashi Iwaiea734962011-01-17 11:29:34 +0100467static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100468 "Headphone Playback Volume",
469 "Speaker Playback Volume",
470 NULL
471};
472
Takashi Iwaiea734962011-01-17 11:29:34 +0100473static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100474 "Headphone Playback Switch",
475 "Speaker Playback Switch",
476 NULL
477};
478
Tobin Davisc9b443d2006-11-14 12:13:39 +0100479static int conexant_build_controls(struct hda_codec *codec)
480{
481 struct conexant_spec *spec = codec->spec;
482 unsigned int i;
483 int err;
484
485 for (i = 0; i < spec->num_mixers; i++) {
486 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
487 if (err < 0)
488 return err;
489 }
490 if (spec->multiout.dig_out_nid) {
491 err = snd_hda_create_spdif_out_ctls(codec,
492 spec->multiout.dig_out_nid);
493 if (err < 0)
494 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100495 err = snd_hda_create_spdif_share_sw(codec,
496 &spec->multiout);
497 if (err < 0)
498 return err;
499 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100500 }
501 if (spec->dig_in_nid) {
502 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
503 if (err < 0)
504 return err;
505 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100506
507 /* if we have no master control, let's create it */
508 if (spec->vmaster_nid &&
509 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
510 unsigned int vmaster_tlv[4];
511 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
512 HDA_OUTPUT, vmaster_tlv);
513 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
514 vmaster_tlv, slave_vols);
515 if (err < 0)
516 return err;
517 }
518 if (spec->vmaster_nid &&
519 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
520 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
521 NULL, slave_sws);
522 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 Iwai697c3732010-07-30 11:28:02 +0200552#ifdef CONFIG_SND_HDA_POWER_SAVE
553static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
554{
555 snd_hda_shutup_pins(codec);
556 return 0;
557}
558#endif
559
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200560static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100561 .build_controls = conexant_build_controls,
562 .build_pcms = conexant_build_pcms,
563 .init = conexant_init,
564 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200565#ifdef CONFIG_SND_HDA_POWER_SAVE
566 .suspend = conexant_suspend,
567#endif
568 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100569};
570
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200571#ifdef CONFIG_SND_HDA_INPUT_BEEP
572#define set_beep_amp(spec, nid, idx, dir) \
573 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
574#else
575#define set_beep_amp(spec, nid, idx, dir) /* NOP */
576#endif
577
Takashi Iwai6764bce2011-05-13 16:52:25 +0200578static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100579/*
580 * EAPD control
581 * the private value = nid | (invert << 8)
582 */
583
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200584#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100585
Tobin Davis82f30042007-02-13 12:45:44 +0100586static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100587 struct snd_ctl_elem_value *ucontrol)
588{
589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590 struct conexant_spec *spec = codec->spec;
591 int invert = (kcontrol->private_value >> 8) & 1;
592 if (invert)
593 ucontrol->value.integer.value[0] = !spec->cur_eapd;
594 else
595 ucontrol->value.integer.value[0] = spec->cur_eapd;
596 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100597
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598}
599
Tobin Davis82f30042007-02-13 12:45:44 +0100600static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct conexant_spec *spec = codec->spec;
605 int invert = (kcontrol->private_value >> 8) & 1;
606 hda_nid_t nid = kcontrol->private_value & 0xff;
607 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100608
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100609 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100610 if (invert)
611 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200612 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100613 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100614
Tobin Davisc9b443d2006-11-14 12:13:39 +0100615 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200616 snd_hda_codec_write_cache(codec, nid,
617 0, AC_VERB_SET_EAPD_BTLENABLE,
618 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100619 return 1;
620}
621
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100622/* controls for test mode */
623#ifdef CONFIG_SND_DEBUG
624
Tobin Davis82f30042007-02-13 12:45:44 +0100625#define CXT_EAPD_SWITCH(xname, nid, mask) \
626 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
627 .info = cxt_eapd_info, \
628 .get = cxt_eapd_get, \
629 .put = cxt_eapd_put, \
630 .private_value = nid | (mask<<16) }
631
632
633
Tobin Davisc9b443d2006-11-14 12:13:39 +0100634static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_info *uinfo)
636{
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct conexant_spec *spec = codec->spec;
639 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
640 spec->num_channel_mode);
641}
642
643static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct conexant_spec *spec = codec->spec;
648 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
649 spec->num_channel_mode,
650 spec->multiout.max_channels);
651}
652
653static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol)
655{
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct conexant_spec *spec = codec->spec;
658 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
659 spec->num_channel_mode,
660 &spec->multiout.max_channels);
661 if (err >= 0 && spec->need_dac_fix)
662 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
663 return err;
664}
665
666#define CXT_PIN_MODE(xname, nid, dir) \
667 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
668 .info = conexant_ch_mode_info, \
669 .get = conexant_ch_mode_get, \
670 .put = conexant_ch_mode_put, \
671 .private_value = nid | (dir<<16) }
672
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100673#endif /* CONFIG_SND_DEBUG */
674
Tobin Davisc9b443d2006-11-14 12:13:39 +0100675/* Conexant 5045 specific */
676
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200677static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
678static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
679static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100680#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200682static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100683 { 2, NULL },
684};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100685
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200686static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100687 .num_items = 2,
688 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100689 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100690 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691 }
692};
693
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200694static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200695 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100696 .items = {
697 { "IntMic", 0x1 },
698 { "ExtMic", 0x2 },
699 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200700 { "CD", 0x4 },
701 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100702 }
703};
704
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200705static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100706 .num_items = 2,
707 .items = {
708 { "ExtMic", 0x1 },
709 { "IntMic", 0x2 },
710 }
711};
712
Tobin Davisc9b443d2006-11-14 12:13:39 +0100713/* turn on/off EAPD (+ mute HP) as a master switch */
714static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
716{
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100719 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100720
Tobin Davis82f30042007-02-13 12:45:44 +0100721 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722 return 0;
723
Tobin Davis82f30042007-02-13 12:45:44 +0100724 /* toggle internal speakers mute depending of presence of
725 * the headphone jack
726 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200727 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
728 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
729 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100730
Takashi Iwai47fd8302007-08-10 17:11:07 +0200731 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
732 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
733 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734 return 1;
735}
736
737/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200738static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200739 .ops = &snd_hda_bind_vol,
740 .values = {
741 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
742 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
743 0
744 },
745};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746
Tobin Davis7f296732007-03-12 11:39:01 +0100747/* toggle input of built-in and mic jack appropriately */
748static void cxt5045_hp_automic(struct hda_codec *codec)
749{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200750 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
752 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
753 {}
754 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200755 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100756 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
758 {}
759 };
760 unsigned int present;
761
Takashi Iwaid56757a2009-11-18 08:00:14 +0100762 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100763 if (present)
764 snd_hda_sequence_write(codec, mic_jack_on);
765 else
766 snd_hda_sequence_write(codec, mic_jack_off);
767}
768
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769
770/* mute internal speaker if HP is plugged */
771static void cxt5045_hp_automute(struct hda_codec *codec)
772{
Tobin Davis82f30042007-02-13 12:45:44 +0100773 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100774 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775
Takashi Iwaid56757a2009-11-18 08:00:14 +0100776 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100777
Takashi Iwai47fd8302007-08-10 17:11:07 +0200778 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
779 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
780 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100781}
782
783/* unsolicited event for HP jack sensing */
784static void cxt5045_hp_unsol_event(struct hda_codec *codec,
785 unsigned int res)
786{
787 res >>= 26;
788 switch (res) {
789 case CONEXANT_HP_EVENT:
790 cxt5045_hp_automute(codec);
791 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100792 case CONEXANT_MIC_EVENT:
793 cxt5045_hp_automic(codec);
794 break;
795
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796 }
797}
798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200799static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100800 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
801 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100802 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
803 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200804 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
805 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100806 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
807 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100808 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
809 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200810 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100811 {
812 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
813 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100814 .info = cxt_eapd_info,
815 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100816 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100817 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 },
819
820 {}
821};
822
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200823static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200824 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
825 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
826 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
827 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
828
Jiang Zhe5218c892008-01-17 11:18:41 +0100829 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
830 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
831 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
832 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
833
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200834 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
835 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
836
Jiang Zhe5218c892008-01-17 11:18:41 +0100837 {}
838};
839
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200840static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100841 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
842 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100843 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
844 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100845 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
846 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100847 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
848 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100849 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
850 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100851 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
852 {
853 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
854 .name = "Master Playback Switch",
855 .info = cxt_eapd_info,
856 .get = cxt_eapd_get,
857 .put = cxt5045_hp_master_sw_put,
858 .private_value = 0x10,
859 },
860
861 {}
862};
863
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200864static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100865 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200866 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100867 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100868 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200869 {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_HP},
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 */
Tobin Davis7f296732007-03-12 11:39:01 +0100879 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100880 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100881 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},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100884 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100885 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100886 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100887 { } /* end */
888};
889
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200890static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100891 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100892 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
893 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
894 /* Line In,HP, Amp */
895 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
896 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
897 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
898 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
899 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
901 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
902 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
903 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100904 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100905 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
906 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
907 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
908 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100909 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100910 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
911 /* EAPD */
912 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
913 { } /* end */
914};
Tobin Davis7f296732007-03-12 11:39:01 +0100915
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200916static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100917 /* pin sensing on HP jack */
918 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200919 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100920};
921
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200922static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100923 /* pin sensing on HP jack */
924 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200925 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100926};
927
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928#ifdef CONFIG_SND_DEBUG
929/* Test configuration for debugging, modelled after the ALC260 test
930 * configuration.
931 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200932static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100933 .num_items = 5,
934 .items = {
935 { "MIXER", 0x0 },
936 { "MIC1 pin", 0x1 },
937 { "LINE1 pin", 0x2 },
938 { "HP-OUT pin", 0x3 },
939 { "CD pin", 0x4 },
940 },
941};
942
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200943static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100944
945 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
947 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100948 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
949 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
950 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
951 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952
953 /* Modes for retasking pin widgets */
954 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
955 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
956
Tobin Davis82f30042007-02-13 12:45:44 +0100957 /* EAPD Switch Control */
958 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
959
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100961
Tobin Davis7f296732007-03-12 11:39:01 +0100962 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
963 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
964 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
965 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
966 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
967 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
968 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
969 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
970 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
971 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972 {
973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
974 .name = "Input Source",
975 .info = conexant_mux_enum_info,
976 .get = conexant_mux_enum_get,
977 .put = conexant_mux_enum_put,
978 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200979 /* Audio input controls */
980 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
981 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
982 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
983 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
984 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
985 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
986 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
987 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
988 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
989 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990 { } /* end */
991};
992
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200993static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100994 /* Set connections */
995 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
996 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
997 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100998 /* Enable retasking pins as output, initially without power amp */
999 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001000 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001
1002 /* Disable digital (SPDIF) pins initially, but users can enable
1003 * them via a mixer switch. In the case of SPDIF-out, this initverb
1004 * payload also sets the generation to 0, output to be in "consumer"
1005 * PCM format, copyright asserted, no pre-emphasis and no validity
1006 * control.
1007 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001008 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1009 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001010
1011 /* Start with output sum widgets muted and their output gains at min */
1012 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1013 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1014
1015 /* Unmute retasking pin widget output buffers since the default
1016 * state appears to be output. As the pin mode is changed by the
1017 * user the pin mode control will take care of enabling the pin's
1018 * input/output buffers as needed.
1019 */
1020 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1021 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1022
1023 /* Mute capture amp left and right */
1024 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1025
1026 /* Set ADC connection select to match default mixer setting (mic1
1027 * pin)
1028 */
1029 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001030 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001031
1032 /* Mute all inputs to mixer widget (even unconnected ones) */
1033 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1034 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1035 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1036 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1037 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1038
1039 { }
1040};
1041#endif
1042
1043
1044/* initialize jack-sensing, too */
1045static int cxt5045_init(struct hda_codec *codec)
1046{
1047 conexant_init(codec);
1048 cxt5045_hp_automute(codec);
1049 return 0;
1050}
1051
1052
1053enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001054 CXT5045_LAPTOP_HPSENSE,
1055 CXT5045_LAPTOP_MICSENSE,
1056 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001057 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001058 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001059#ifdef CONFIG_SND_DEBUG
1060 CXT5045_TEST,
1061#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001062 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001063 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001064};
1065
Takashi Iwaiea734962011-01-17 11:29:34 +01001066static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001067 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1068 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1069 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1070 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001071 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001073 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001074#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001075 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001076};
1077
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001078static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001079 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001080 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1081 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001082 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001083 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001084 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1085 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001086 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1087 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001088 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1089 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1090 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001091 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1092 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001093 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001094 {}
1095};
1096
1097static int patch_cxt5045(struct hda_codec *codec)
1098{
1099 struct conexant_spec *spec;
1100 int board_config;
1101
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001102 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1103 cxt5045_models,
1104 cxt5045_cfg_tbl);
1105 if (board_config < 0)
1106 board_config = CXT5045_AUTO;
1107 if (board_config == CXT5045_AUTO)
1108 return patch_conexant_auto(codec);
1109
Tobin Davisc9b443d2006-11-14 12:13:39 +01001110 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1111 if (!spec)
1112 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001114 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001115
1116 spec->multiout.max_channels = 2;
1117 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1118 spec->multiout.dac_nids = cxt5045_dac_nids;
1119 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1120 spec->num_adc_nids = 1;
1121 spec->adc_nids = cxt5045_adc_nids;
1122 spec->capsrc_nids = cxt5045_capsrc_nids;
1123 spec->input_mux = &cxt5045_capture_source;
1124 spec->num_mixers = 1;
1125 spec->mixers[0] = cxt5045_mixers;
1126 spec->num_init_verbs = 1;
1127 spec->init_verbs[0] = cxt5045_init_verbs;
1128 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001129 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1130 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001131
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001132 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001133
1134 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001137 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001138 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001139 spec->input_mux = &cxt5045_capture_source;
1140 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001141 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1142 spec->mixers[0] = cxt5045_mixers;
1143 codec->patch_ops.init = cxt5045_init;
1144 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001145 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001146 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001147 spec->input_mux = &cxt5045_capture_source;
1148 spec->num_init_verbs = 2;
1149 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001150 spec->mixers[0] = cxt5045_mixers;
1151 codec->patch_ops.init = cxt5045_init;
1152 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001153 default:
1154 case CXT5045_LAPTOP_HPMICSENSE:
1155 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1156 spec->input_mux = &cxt5045_capture_source;
1157 spec->num_init_verbs = 3;
1158 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1159 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1160 spec->mixers[0] = cxt5045_mixers;
1161 codec->patch_ops.init = cxt5045_init;
1162 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001163 case CXT5045_BENQ:
1164 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1165 spec->input_mux = &cxt5045_capture_source_benq;
1166 spec->num_init_verbs = 1;
1167 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1168 spec->mixers[0] = cxt5045_mixers;
1169 spec->mixers[1] = cxt5045_benq_mixers;
1170 spec->num_mixers = 2;
1171 codec->patch_ops.init = cxt5045_init;
1172 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001173 case CXT5045_LAPTOP_HP530:
1174 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1175 spec->input_mux = &cxt5045_capture_source_hp530;
1176 spec->num_init_verbs = 2;
1177 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1178 spec->mixers[0] = cxt5045_mixers_hp530;
1179 codec->patch_ops.init = cxt5045_init;
1180 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181#ifdef CONFIG_SND_DEBUG
1182 case CXT5045_TEST:
1183 spec->input_mux = &cxt5045_test_capture_source;
1184 spec->mixers[0] = cxt5045_test_mixer;
1185 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001186 break;
1187
Tobin Davisc9b443d2006-11-14 12:13:39 +01001188#endif
1189 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001190
Takashi Iwai031005f2008-06-26 14:49:58 +02001191 switch (codec->subsystem_id >> 16) {
1192 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001193 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001194 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001195 case 0x17aa:
1196 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1197 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1198 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001199 */
1200 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1201 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1202 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1203 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1204 (1 << AC_AMPCAP_MUTE_SHIFT));
1205 break;
1206 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001207
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001208 if (spec->beep_amp)
1209 snd_hda_attach_beep_device(codec, spec->beep_amp);
1210
Tobin Davisc9b443d2006-11-14 12:13:39 +01001211 return 0;
1212}
1213
1214
1215/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001216#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001218static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1219static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1220static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001221
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001222static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001223 { 2, NULL },
1224};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001225
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001226static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001227 .num_items = 2,
1228 .items = {
1229 { "ExtMic", 0x2 },
1230 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231 }
1232};
1233
1234/* turn on/off EAPD (+ mute HP) as a master switch */
1235static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1236 struct snd_ctl_elem_value *ucontrol)
1237{
1238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1239 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001240 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241
Tobin Davis82f30042007-02-13 12:45:44 +01001242 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001243 return 0;
1244
Tobin Davis82f30042007-02-13 12:45:44 +01001245 /* toggle internal speakers mute depending of presence of
1246 * the headphone jack
1247 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001248 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001249 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1250 * pin widgets unlike other codecs. In this case, we need to
1251 * set index 0x01 for the volume from the mixer amp 0x19.
1252 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001253 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001254 HDA_AMP_MUTE, bits);
1255 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1256 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1257 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001258 return 1;
1259}
1260
Tobin Davisc9b443d2006-11-14 12:13:39 +01001261/* mute internal speaker if HP is plugged */
1262static void cxt5047_hp_automute(struct hda_codec *codec)
1263{
Tobin Davis82f30042007-02-13 12:45:44 +01001264 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001265 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001266
Takashi Iwaid56757a2009-11-18 08:00:14 +01001267 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001268
Takashi Iwai47fd8302007-08-10 17:11:07 +02001269 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001270 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001271 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001272 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001273}
1274
1275/* toggle input of built-in and mic jack appropriately */
1276static void cxt5047_hp_automic(struct hda_codec *codec)
1277{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001278 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001279 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1280 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001281 {}
1282 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001283 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001284 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1285 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286 {}
1287 };
1288 unsigned int present;
1289
Takashi Iwaid56757a2009-11-18 08:00:14 +01001290 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 if (present)
1292 snd_hda_sequence_write(codec, mic_jack_on);
1293 else
1294 snd_hda_sequence_write(codec, mic_jack_off);
1295}
1296
1297/* unsolicited event for HP jack sensing */
1298static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1299 unsigned int res)
1300{
Marc Boucher9f113e02008-01-22 15:18:08 +01001301 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001302 case CONEXANT_HP_EVENT:
1303 cxt5047_hp_automute(codec);
1304 break;
1305 case CONEXANT_MIC_EVENT:
1306 cxt5047_hp_automic(codec);
1307 break;
1308 }
1309}
1310
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001311static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001312 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1313 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001314 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1316 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1317 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1318 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001319 {
1320 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1321 .name = "Master Playback Switch",
1322 .info = cxt_eapd_info,
1323 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001324 .put = cxt5047_hp_master_sw_put,
1325 .private_value = 0x13,
1326 },
1327
1328 {}
1329};
1330
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001331static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001332 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001333 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001334 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1335 {}
1336};
1337
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001338static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001339 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340 { } /* end */
1341};
1342
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001343static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 /* Line in, Mic, Built-in Mic */
1345 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1346 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1347 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001348 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001349 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001350 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1351 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001352 /* Record selector: Mic */
1353 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1354 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1355 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1356 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1358 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1359 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1360 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001361 /* SPDIF route: PCM */
1362 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001363 /* Enable unsolicited events */
1364 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1365 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 { } /* end */
1367};
1368
1369/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001370static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001371 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 {}
1373};
1374
1375/* Test configuration for debugging, modelled after the ALC260 test
1376 * configuration.
1377 */
1378#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001379static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001380 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001382 { "LINE1 pin", 0x0 },
1383 { "MIC1 pin", 0x1 },
1384 { "MIC2 pin", 0x2 },
1385 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001386 },
1387};
1388
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001389static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001390
1391 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001392 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1393 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1394 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1395 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001396 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001400 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001404
1405 /* Modes for retasking pin widgets */
1406 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1407 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1408
Tobin Davis82f30042007-02-13 12:45:44 +01001409 /* EAPD Switch Control */
1410 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1411
Tobin Davisc9b443d2006-11-14 12:13:39 +01001412 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001413 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1414 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1415 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1416 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1417 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1418 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1419 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1420 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001421
Tobin Davis82f30042007-02-13 12:45:44 +01001422 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1423 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1425 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1427 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1428 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1429 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001430 {
1431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1432 .name = "Input Source",
1433 .info = conexant_mux_enum_info,
1434 .get = conexant_mux_enum_get,
1435 .put = conexant_mux_enum_put,
1436 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001437 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001438
Tobin Davisc9b443d2006-11-14 12:13:39 +01001439 { } /* end */
1440};
1441
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001442static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001443 /* Enable retasking pins as output, initially without power amp */
1444 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1445 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1446 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1447
1448 /* Disable digital (SPDIF) pins initially, but users can enable
1449 * them via a mixer switch. In the case of SPDIF-out, this initverb
1450 * payload also sets the generation to 0, output to be in "consumer"
1451 * PCM format, copyright asserted, no pre-emphasis and no validity
1452 * control.
1453 */
1454 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1455
1456 /* Ensure mic1, mic2, line1 pin widgets take input from the
1457 * OUT1 sum bus when acting as an output.
1458 */
1459 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1460 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1461
1462 /* Start with output sum widgets muted and their output gains at min */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1465
1466 /* Unmute retasking pin widget output buffers since the default
1467 * state appears to be output. As the pin mode is changed by the
1468 * user the pin mode control will take care of enabling the pin's
1469 * input/output buffers as needed.
1470 */
1471 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1472 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1474
1475 /* Mute capture amp left and right */
1476 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1477
1478 /* Set ADC connection select to match default mixer setting (mic1
1479 * pin)
1480 */
1481 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1482
1483 /* Mute all inputs to mixer widget (even unconnected ones) */
1484 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1492
1493 { }
1494};
1495#endif
1496
1497
1498/* initialize jack-sensing, too */
1499static int cxt5047_hp_init(struct hda_codec *codec)
1500{
1501 conexant_init(codec);
1502 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001503 return 0;
1504}
1505
1506
1507enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001508 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1509 CXT5047_LAPTOP_HP, /* Some HP laptops */
1510 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001511#ifdef CONFIG_SND_DEBUG
1512 CXT5047_TEST,
1513#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001514 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001515};
1516
Takashi Iwaiea734962011-01-17 11:29:34 +01001517static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001518 [CXT5047_LAPTOP] = "laptop",
1519 [CXT5047_LAPTOP_HP] = "laptop-hp",
1520 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001521#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001522 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001523#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001524};
1525
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001526static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001527 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001528 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1529 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001531 {}
1532};
1533
1534static int patch_cxt5047(struct hda_codec *codec)
1535{
1536 struct conexant_spec *spec;
1537 int board_config;
1538
1539 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1540 if (!spec)
1541 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001542 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001543 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544
1545 spec->multiout.max_channels = 2;
1546 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1547 spec->multiout.dac_nids = cxt5047_dac_nids;
1548 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1549 spec->num_adc_nids = 1;
1550 spec->adc_nids = cxt5047_adc_nids;
1551 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001553 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001554 spec->num_init_verbs = 1;
1555 spec->init_verbs[0] = cxt5047_init_verbs;
1556 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001557 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1558 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001559
1560 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001561
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001562 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1563 cxt5047_models,
1564 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001565 switch (board_config) {
1566 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001567 spec->num_mixers = 2;
1568 spec->mixers[1] = cxt5047_hp_spk_mixers;
1569 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 break;
1571 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001572 spec->num_mixers = 2;
1573 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001574 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575 codec->patch_ops.init = cxt5047_hp_init;
1576 break;
1577 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001578 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001579 spec->num_mixers = 2;
1580 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001581 spec->num_init_verbs = 2;
1582 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001583 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001584 break;
1585#ifdef CONFIG_SND_DEBUG
1586 case CXT5047_TEST:
1587 spec->input_mux = &cxt5047_test_capture_source;
1588 spec->mixers[0] = cxt5047_test_mixer;
1589 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001590 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001591#endif
1592 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001593 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001594
1595 switch (codec->subsystem_id >> 16) {
1596 case 0x103c:
1597 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1598 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1599 * with 0 dB offset 0x17)
1600 */
1601 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1602 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1603 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1604 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1605 (1 << AC_AMPCAP_MUTE_SHIFT));
1606 break;
1607 }
1608
Tobin Davisc9b443d2006-11-14 12:13:39 +01001609 return 0;
1610}
1611
Takashi Iwai461e2c72008-01-25 11:35:17 +01001612/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001613static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1614static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001615
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001616static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001617 { 2, NULL },
1618};
1619
1620static void cxt5051_update_speaker(struct hda_codec *codec)
1621{
1622 struct conexant_spec *spec = codec->spec;
1623 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001624 /* headphone pin */
1625 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1626 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1627 pinctl);
1628 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001629 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1630 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1631 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001632 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1633 if (spec->ideapad)
1634 snd_hda_codec_write(codec, 0x1b, 0,
1635 AC_VERB_SET_PIN_WIDGET_CONTROL,
1636 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001637}
1638
1639/* turn on/off EAPD (+ mute HP) as a master switch */
1640static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1641 struct snd_ctl_elem_value *ucontrol)
1642{
1643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1644
1645 if (!cxt_eapd_put(kcontrol, ucontrol))
1646 return 0;
1647 cxt5051_update_speaker(codec);
1648 return 1;
1649}
1650
1651/* toggle input of built-in and mic jack appropriately */
1652static void cxt5051_portb_automic(struct hda_codec *codec)
1653{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001654 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001655 unsigned int present;
1656
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001657 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001658 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001659 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001660 snd_hda_codec_write(codec, 0x14, 0,
1661 AC_VERB_SET_CONNECT_SEL,
1662 present ? 0x01 : 0x00);
1663}
1664
1665/* switch the current ADC according to the jack state */
1666static void cxt5051_portc_automic(struct hda_codec *codec)
1667{
1668 struct conexant_spec *spec = codec->spec;
1669 unsigned int present;
1670 hda_nid_t new_adc;
1671
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001672 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001673 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001674 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001675 if (present)
1676 spec->cur_adc_idx = 1;
1677 else
1678 spec->cur_adc_idx = 0;
1679 new_adc = spec->adc_nids[spec->cur_adc_idx];
1680 if (spec->cur_adc && spec->cur_adc != new_adc) {
1681 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001682 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001683 spec->cur_adc = new_adc;
1684 snd_hda_codec_setup_stream(codec, new_adc,
1685 spec->cur_adc_stream_tag, 0,
1686 spec->cur_adc_format);
1687 }
1688}
1689
1690/* mute internal speaker if HP is plugged */
1691static void cxt5051_hp_automute(struct hda_codec *codec)
1692{
1693 struct conexant_spec *spec = codec->spec;
1694
Takashi Iwaid56757a2009-11-18 08:00:14 +01001695 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001696 cxt5051_update_speaker(codec);
1697}
1698
1699/* unsolicited event for HP jack sensing */
1700static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1701 unsigned int res)
1702{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001703 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001704 switch (res >> 26) {
1705 case CONEXANT_HP_EVENT:
1706 cxt5051_hp_automute(codec);
1707 break;
1708 case CXT5051_PORTB_EVENT:
1709 cxt5051_portb_automic(codec);
1710 break;
1711 case CXT5051_PORTC_EVENT:
1712 cxt5051_portc_automic(codec);
1713 break;
1714 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001715 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001716}
1717
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001718static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1720 {
1721 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1722 .name = "Master Playback Switch",
1723 .info = cxt_eapd_info,
1724 .get = cxt_eapd_get,
1725 .put = cxt5051_hp_master_sw_put,
1726 .private_value = 0x1a,
1727 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001728 {}
1729};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001730
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001731static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001732 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1733 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001734 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1735 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001736 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1737 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001738 {}
1739};
1740
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001741static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001742 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1743 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001744 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1745 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001746 {}
1747};
1748
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001749static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001750 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1751 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001752 {}
1753};
1754
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001755static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001756 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1757 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001758 {}
1759};
1760
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001761static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001762 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1763 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001764 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1765 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001766 {}
1767};
1768
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001769static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001770 /* Line in, Mic */
1771 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1772 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1773 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1776 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1777 /* SPK */
1778 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1779 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1780 /* HP, Amp */
1781 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1782 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1783 /* DAC1 */
1784 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001785 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1787 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1788 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1789 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001790 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001791 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1792 /* EAPD */
1793 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1794 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001795 { } /* end */
1796};
1797
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001798static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001799 /* Line in, Mic */
1800 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1801 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1802 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1803 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1804 /* SPK */
1805 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1806 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1807 /* HP, Amp */
1808 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1809 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1810 /* DAC1 */
1811 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001812 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001813 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1814 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1815 /* SPDIF route: PCM */
1816 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1817 /* EAPD */
1818 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1819 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001820 { } /* end */
1821};
1822
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001823static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001824 /* Line in, Mic */
1825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1828 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1830 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1831 /* SPK */
1832 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1833 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1834 /* HP, Amp */
1835 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1836 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1837 /* Docking HP */
1838 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1839 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1840 /* DAC1 */
1841 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001842 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1846 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001847 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001848 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1849 /* EAPD */
1850 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1851 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001852 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1853 { } /* end */
1854};
1855
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001856static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001857 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001859 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1860 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1861 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1862 /* SPK */
1863 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1864 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1865 /* HP, Amp */
1866 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1867 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1868 /* DAC1 */
1869 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001870 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001871 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1872 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1873 /* SPDIF route: PCM */
1874 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1875 /* EAPD */
1876 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1877 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001878 { } /* end */
1879};
1880
Takashi Iwai6953e552010-01-24 11:00:27 +01001881static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1882 unsigned int event)
1883{
1884 snd_hda_codec_write(codec, nid, 0,
1885 AC_VERB_SET_UNSOLICITED_ENABLE,
1886 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001887 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1888 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001889}
1890
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001891static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001892 /* Subwoofer */
1893 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1894 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1895 { } /* end */
1896};
1897
Takashi Iwai461e2c72008-01-25 11:35:17 +01001898/* initialize jack-sensing, too */
1899static int cxt5051_init(struct hda_codec *codec)
1900{
Takashi Iwai6953e552010-01-24 11:00:27 +01001901 struct conexant_spec *spec = codec->spec;
1902
Takashi Iwai461e2c72008-01-25 11:35:17 +01001903 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001904 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001905
1906 if (spec->auto_mic & AUTO_MIC_PORTB)
1907 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1908 if (spec->auto_mic & AUTO_MIC_PORTC)
1909 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1910
Takashi Iwai461e2c72008-01-25 11:35:17 +01001911 if (codec->patch_ops.unsol_event) {
1912 cxt5051_hp_automute(codec);
1913 cxt5051_portb_automic(codec);
1914 cxt5051_portc_automic(codec);
1915 }
1916 return 0;
1917}
1918
1919
1920enum {
1921 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1922 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001923 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001924 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001925 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001926 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001927 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001928 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001929 CXT5051_MODELS
1930};
1931
Takashi Iwaiea734962011-01-17 11:29:34 +01001932static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001933 [CXT5051_LAPTOP] = "laptop",
1934 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001935 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001936 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001937 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001938 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001939 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001940 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001941};
1942
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001943static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001944 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001945 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001946 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001947 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001948 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1949 CXT5051_LAPTOP),
1950 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001951 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001952 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001953 {}
1954};
1955
1956static int patch_cxt5051(struct hda_codec *codec)
1957{
1958 struct conexant_spec *spec;
1959 int board_config;
1960
Takashi Iwai6764bce2011-05-13 16:52:25 +02001961 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1962 cxt5051_models,
1963 cxt5051_cfg_tbl);
1964 if (board_config < 0)
1965 board_config = CXT5051_AUTO;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001966 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001967 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001968
Takashi Iwai461e2c72008-01-25 11:35:17 +01001969 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1970 if (!spec)
1971 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001972 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001973 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001974
1975 codec->patch_ops = conexant_patch_ops;
1976 codec->patch_ops.init = cxt5051_init;
1977
1978 spec->multiout.max_channels = 2;
1979 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1980 spec->multiout.dac_nids = cxt5051_dac_nids;
1981 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1982 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1983 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001984 spec->num_mixers = 2;
1985 spec->mixers[0] = cxt5051_capture_mixers;
1986 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001987 spec->num_init_verbs = 1;
1988 spec->init_verbs[0] = cxt5051_init_verbs;
1989 spec->spdif_route = 0;
1990 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1991 spec->channel_mode = cxt5051_modes;
1992 spec->cur_adc = 0;
1993 spec->cur_adc_idx = 0;
1994
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001995 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1996
Takashi Iwai79d7d532009-03-04 09:03:50 +01001997 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1998
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001999 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002000 switch (board_config) {
2001 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002002 spec->mixers[0] = cxt5051_hp_mixers;
2003 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002004 case CXT5051_HP_DV6736:
2005 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2006 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002007 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002008 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002009 case CXT5051_LENOVO_X200:
2010 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002011 /* Thinkpad X301 does not have S/PDIF wired and no ability
2012 to use a docking station. */
2013 if (codec->subsystem_id == 0x17aa211f)
2014 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002015 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002016 case CXT5051_F700:
2017 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2018 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002019 spec->auto_mic = 0;
2020 break;
2021 case CXT5051_TOSHIBA:
2022 spec->mixers[0] = cxt5051_toshiba_mixers;
2023 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002024 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002025 case CXT5051_IDEAPAD:
2026 spec->init_verbs[spec->num_init_verbs++] =
2027 cxt5051_ideapad_init_verbs;
2028 spec->ideapad = 1;
2029 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002030 }
2031
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002032 if (spec->beep_amp)
2033 snd_hda_attach_beep_device(codec, spec->beep_amp);
2034
Takashi Iwai461e2c72008-01-25 11:35:17 +01002035 return 0;
2036}
2037
Daniel Drake0fb67e92009-07-16 14:46:57 +01002038/* Conexant 5066 specific */
2039
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002040static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2041static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2042static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2043static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002044
Daniel Drakedbaccc02009-11-09 15:17:24 +00002045/* OLPC's microphone port is DC coupled for use with external sensors,
2046 * therefore we use a 50% mic bias in order to center the input signal with
2047 * the DC input range of the codec. */
2048#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2049
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002050static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002051 { 2, NULL },
2052};
2053
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002054#define HP_PRESENT_PORT_A (1 << 0)
2055#define HP_PRESENT_PORT_D (1 << 1)
2056#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2057#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2058
Daniel Drake0fb67e92009-07-16 14:46:57 +01002059static void cxt5066_update_speaker(struct hda_codec *codec)
2060{
2061 struct conexant_spec *spec = codec->spec;
2062 unsigned int pinctl;
2063
John Baboval3a253442010-12-02 11:21:31 -05002064 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2065 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002066
2067 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002068 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002069 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2070 pinctl);
2071
2072 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002073 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2074 if (spec->dell_automute || spec->thinkpad) {
2075 /* Mute if Port A is connected */
2076 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002077 pinctl = 0;
2078 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002079 /* Thinkpad/Dell doesn't give pin-D status */
2080 if (!hp_port_d_present(spec))
2081 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002082 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002083 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2084 pinctl);
2085
2086 /* CLASS_D AMP */
2087 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2088 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2089 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002090}
2091
2092/* turn on/off EAPD (+ mute HP) as a master switch */
2093static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2094 struct snd_ctl_elem_value *ucontrol)
2095{
2096 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2097
2098 if (!cxt_eapd_put(kcontrol, ucontrol))
2099 return 0;
2100
2101 cxt5066_update_speaker(codec);
2102 return 1;
2103}
2104
Daniel Drakec4cfe662010-01-07 13:47:04 +01002105static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2106 .num_items = 3,
2107 .items = {
2108 { "Off", PIN_IN },
2109 { "50%", PIN_VREF50 },
2110 { "80%", PIN_VREF80 },
2111 },
2112};
2113
2114static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2115{
2116 struct conexant_spec *spec = codec->spec;
2117 /* Even though port F is the DC input, the bias is controlled on port B.
2118 * we also leave that port as an active input (but unselected) in DC mode
2119 * just in case that is necessary to make the bias setting take effect. */
2120 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2121 AC_VERB_SET_PIN_WIDGET_CONTROL,
2122 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2123}
2124
Daniel Drake75f89912010-01-07 13:46:25 +01002125/* OLPC defers mic widget control until when capture is started because the
2126 * microphone LED comes on as soon as these settings are put in place. if we
2127 * did this before recording, it would give the false indication that recording
2128 * is happening when it is not. */
2129static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002130{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002131 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002132 if (!spec->recording)
2133 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002134
Daniel Drakec4cfe662010-01-07 13:47:04 +01002135 if (spec->dc_enable) {
2136 /* in DC mode we ignore presence detection and just use the jack
2137 * through our special DC port */
2138 const struct hda_verb enable_dc_mode[] = {
2139 /* disble internal mic, port C */
2140 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2141
2142 /* enable DC capture, port F */
2143 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2144 {},
2145 };
2146
2147 snd_hda_sequence_write(codec, enable_dc_mode);
2148 /* port B input disabled (and bias set) through the following call */
2149 cxt5066_set_olpc_dc_bias(codec);
2150 return;
2151 }
2152
2153 /* disable DC (port F) */
2154 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2155
Daniel Drake75f89912010-01-07 13:46:25 +01002156 /* external mic, port B */
2157 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2158 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002159
Daniel Drake75f89912010-01-07 13:46:25 +01002160 /* internal mic, port C */
2161 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2162 spec->ext_mic_present ? 0 : PIN_VREF80);
2163}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002164
Daniel Drake75f89912010-01-07 13:46:25 +01002165/* toggle input of built-in and mic jack appropriately */
2166static void cxt5066_olpc_automic(struct hda_codec *codec)
2167{
2168 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002169 unsigned int present;
2170
Daniel Drakec4cfe662010-01-07 13:47:04 +01002171 if (spec->dc_enable) /* don't do presence detection in DC mode */
2172 return;
2173
Daniel Drake75f89912010-01-07 13:46:25 +01002174 present = snd_hda_codec_read(codec, 0x1a, 0,
2175 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2176 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002177 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002178 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002179 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002180
2181 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2182 present ? 0 : 1);
2183 spec->ext_mic_present = !!present;
2184
2185 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002186}
2187
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002188/* toggle input of built-in digital mic and mic jack appropriately */
2189static void cxt5066_vostro_automic(struct hda_codec *codec)
2190{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002191 unsigned int present;
2192
2193 struct hda_verb ext_mic_present[] = {
2194 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002195 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002196
2197 /* switch to external mic input */
2198 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2199 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2200
2201 /* disable internal digital mic */
2202 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2203 {}
2204 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002205 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002206 /* enable internal mic, port C */
2207 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2208
2209 /* switch to internal mic input */
2210 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2211
2212 /* disable external mic, port B */
2213 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2214 {}
2215 };
2216
2217 present = snd_hda_jack_detect(codec, 0x1a);
2218 if (present) {
2219 snd_printdd("CXT5066: external microphone detected\n");
2220 snd_hda_sequence_write(codec, ext_mic_present);
2221 } else {
2222 snd_printdd("CXT5066: external microphone absent\n");
2223 snd_hda_sequence_write(codec, ext_mic_absent);
2224 }
2225}
2226
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002227/* toggle input of built-in digital mic and mic jack appropriately */
2228static void cxt5066_ideapad_automic(struct hda_codec *codec)
2229{
2230 unsigned int present;
2231
2232 struct hda_verb ext_mic_present[] = {
2233 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2234 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2235 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2236 {}
2237 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002238 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002239 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2240 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2241 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2242 {}
2243 };
2244
2245 present = snd_hda_jack_detect(codec, 0x1b);
2246 if (present) {
2247 snd_printdd("CXT5066: external microphone detected\n");
2248 snd_hda_sequence_write(codec, ext_mic_present);
2249 } else {
2250 snd_printdd("CXT5066: external microphone absent\n");
2251 snd_hda_sequence_write(codec, ext_mic_absent);
2252 }
2253}
2254
David Henningssona1d69062011-01-21 13:33:28 +01002255
2256/* toggle input of built-in digital mic and mic jack appropriately */
2257static void cxt5066_asus_automic(struct hda_codec *codec)
2258{
2259 unsigned int present;
2260
2261 present = snd_hda_jack_detect(codec, 0x1b);
2262 snd_printdd("CXT5066: external microphone present=%d\n", present);
2263 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2264 present ? 1 : 0);
2265}
2266
2267
David Henningsson048e78a2010-09-02 08:35:47 +02002268/* toggle input of built-in digital mic and mic jack appropriately */
2269static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2270{
2271 unsigned int present;
2272
2273 present = snd_hda_jack_detect(codec, 0x1b);
2274 snd_printdd("CXT5066: external microphone present=%d\n", present);
2275 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2276 present ? 1 : 3);
2277}
2278
2279
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002280/* toggle input of built-in digital mic and mic jack appropriately
2281 order is: external mic -> dock mic -> interal mic */
2282static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2283{
2284 unsigned int ext_present, dock_present;
2285
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002286 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002287 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2288 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2289 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2290 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2291 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2292 {}
2293 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002294 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002295 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2296 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2297 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2298 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2299 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2300 {}
2301 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002302 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002303 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2304 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2305 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2307 {}
2308 };
2309
2310 ext_present = snd_hda_jack_detect(codec, 0x1b);
2311 dock_present = snd_hda_jack_detect(codec, 0x1a);
2312 if (ext_present) {
2313 snd_printdd("CXT5066: external microphone detected\n");
2314 snd_hda_sequence_write(codec, ext_mic_present);
2315 } else if (dock_present) {
2316 snd_printdd("CXT5066: dock microphone detected\n");
2317 snd_hda_sequence_write(codec, dock_mic_present);
2318 } else {
2319 snd_printdd("CXT5066: external microphone absent\n");
2320 snd_hda_sequence_write(codec, ext_mic_absent);
2321 }
2322}
2323
Daniel Drake0fb67e92009-07-16 14:46:57 +01002324/* mute internal speaker if HP is plugged */
2325static void cxt5066_hp_automute(struct hda_codec *codec)
2326{
2327 struct conexant_spec *spec = codec->spec;
2328 unsigned int portA, portD;
2329
2330 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002331 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002332
2333 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002334 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002335
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002336 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2337 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002338 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2339 portA, portD, spec->hp_present);
2340 cxt5066_update_speaker(codec);
2341}
2342
David Henningsson02b6b5b2011-01-21 13:27:39 +01002343/* Dispatch the right mic autoswitch function */
2344static void cxt5066_automic(struct hda_codec *codec)
2345{
2346 struct conexant_spec *spec = codec->spec;
2347
2348 if (spec->dell_vostro)
2349 cxt5066_vostro_automic(codec);
2350 else if (spec->ideapad)
2351 cxt5066_ideapad_automic(codec);
2352 else if (spec->thinkpad)
2353 cxt5066_thinkpad_automic(codec);
2354 else if (spec->hp_laptop)
2355 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002356 else if (spec->asus)
2357 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002358}
2359
Daniel Drake0fb67e92009-07-16 14:46:57 +01002360/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002361static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002362{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002363 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002364 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2365 switch (res >> 26) {
2366 case CONEXANT_HP_EVENT:
2367 cxt5066_hp_automute(codec);
2368 break;
2369 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002370 /* ignore mic events in DC mode; we're always using the jack */
2371 if (!spec->dc_enable)
2372 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002373 break;
2374 }
2375}
2376
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002377/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002378static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002379{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002380 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002381 switch (res >> 26) {
2382 case CONEXANT_HP_EVENT:
2383 cxt5066_hp_automute(codec);
2384 break;
2385 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002386 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002387 break;
2388 }
2389}
2390
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002391
Daniel Drake0fb67e92009-07-16 14:46:57 +01002392static const struct hda_input_mux cxt5066_analog_mic_boost = {
2393 .num_items = 5,
2394 .items = {
2395 { "0dB", 0 },
2396 { "10dB", 1 },
2397 { "20dB", 2 },
2398 { "30dB", 3 },
2399 { "40dB", 4 },
2400 },
2401};
2402
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002403static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002404{
2405 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002406 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002407 AC_VERB_SET_AMP_GAIN_MUTE,
2408 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2409 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002410 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002411 /* adjust the internal mic as well...it is not through 0x17 */
2412 snd_hda_codec_write_cache(codec, 0x23, 0,
2413 AC_VERB_SET_AMP_GAIN_MUTE,
2414 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2415 cxt5066_analog_mic_boost.
2416 items[spec->mic_boost].index);
2417 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002418}
2419
Daniel Drake0fb67e92009-07-16 14:46:57 +01002420static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2421 struct snd_ctl_elem_info *uinfo)
2422{
2423 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2424}
2425
2426static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2427 struct snd_ctl_elem_value *ucontrol)
2428{
2429 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002430 struct conexant_spec *spec = codec->spec;
2431 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002432 return 0;
2433}
2434
2435static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2436 struct snd_ctl_elem_value *ucontrol)
2437{
2438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002439 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002440 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2441 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002442 idx = ucontrol->value.enumerated.item[0];
2443 if (idx >= imux->num_items)
2444 idx = imux->num_items - 1;
2445
Daniel Drakec4cfe662010-01-07 13:47:04 +01002446 spec->mic_boost = idx;
2447 if (!spec->dc_enable)
2448 cxt5066_set_mic_boost(codec);
2449 return 1;
2450}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002451
Daniel Drakec4cfe662010-01-07 13:47:04 +01002452static void cxt5066_enable_dc(struct hda_codec *codec)
2453{
2454 const struct hda_verb enable_dc_mode[] = {
2455 /* disable gain */
2456 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2457
2458 /* switch to DC input */
2459 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2460 {}
2461 };
2462
2463 /* configure as input source */
2464 snd_hda_sequence_write(codec, enable_dc_mode);
2465 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2466}
2467
2468static void cxt5066_disable_dc(struct hda_codec *codec)
2469{
2470 /* reconfigure input source */
2471 cxt5066_set_mic_boost(codec);
2472 /* automic also selects the right mic if we're recording */
2473 cxt5066_olpc_automic(codec);
2474}
2475
2476static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2477 struct snd_ctl_elem_value *ucontrol)
2478{
2479 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2480 struct conexant_spec *spec = codec->spec;
2481 ucontrol->value.integer.value[0] = spec->dc_enable;
2482 return 0;
2483}
2484
2485static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_value *ucontrol)
2487{
2488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2489 struct conexant_spec *spec = codec->spec;
2490 int dc_enable = !!ucontrol->value.integer.value[0];
2491
2492 if (dc_enable == spec->dc_enable)
2493 return 0;
2494
2495 spec->dc_enable = dc_enable;
2496 if (dc_enable)
2497 cxt5066_enable_dc(codec);
2498 else
2499 cxt5066_disable_dc(codec);
2500
2501 return 1;
2502}
2503
2504static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2505 struct snd_ctl_elem_info *uinfo)
2506{
2507 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2508}
2509
2510static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2511 struct snd_ctl_elem_value *ucontrol)
2512{
2513 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2514 struct conexant_spec *spec = codec->spec;
2515 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2516 return 0;
2517}
2518
2519static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2520 struct snd_ctl_elem_value *ucontrol)
2521{
2522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2523 struct conexant_spec *spec = codec->spec;
2524 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2525 unsigned int idx;
2526
2527 idx = ucontrol->value.enumerated.item[0];
2528 if (idx >= imux->num_items)
2529 idx = imux->num_items - 1;
2530
2531 spec->dc_input_bias = idx;
2532 if (spec->dc_enable)
2533 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002534 return 1;
2535}
2536
Daniel Drake75f89912010-01-07 13:46:25 +01002537static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2538{
2539 struct conexant_spec *spec = codec->spec;
2540 /* mark as recording and configure the microphone widget so that the
2541 * recording LED comes on. */
2542 spec->recording = 1;
2543 cxt5066_olpc_select_mic(codec);
2544}
2545
2546static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2547{
2548 struct conexant_spec *spec = codec->spec;
2549 const struct hda_verb disable_mics[] = {
2550 /* disable external mic, port B */
2551 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2552
2553 /* disble internal mic, port C */
2554 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002555
2556 /* disable DC capture, port F */
2557 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002558 {},
2559 };
2560
2561 snd_hda_sequence_write(codec, disable_mics);
2562 spec->recording = 0;
2563}
2564
Andy Robinsonf6a24912011-01-24 10:12:37 -05002565static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002566 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002567 int num_pins)
2568{
2569 struct conexant_spec *spec = codec->spec;
2570 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2571 int i;
2572
2573 for (i = 0; i < num_pins; i++, dig_pins++) {
2574 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2575 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2576 continue;
2577 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2578 continue;
2579 if (spec->slave_dig_outs[0])
2580 nid_loc++;
2581 else
2582 nid_loc = spec->slave_dig_outs;
2583 }
2584}
2585
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002586static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002587 .num_items = 4,
2588 .items = {
2589 { "Mic B", 0 },
2590 { "Mic C", 1 },
2591 { "Mic E", 2 },
2592 { "Mic F", 3 },
2593 },
2594};
2595
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002596static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002597 .ops = &snd_hda_bind_vol,
2598 .values = {
2599 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2600 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2601 0
2602 },
2603};
2604
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002605static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002606 .ops = &snd_hda_bind_sw,
2607 .values = {
2608 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2609 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2610 0
2611 },
2612};
2613
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002614static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002615 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2616 {}
2617};
2618
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002619static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002620 {
2621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2622 .name = "Master Playback Volume",
2623 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2624 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2625 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002626 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002627 .info = snd_hda_mixer_amp_volume_info,
2628 .get = snd_hda_mixer_amp_volume_get,
2629 .put = snd_hda_mixer_amp_volume_put,
2630 .tlv = { .c = snd_hda_mixer_amp_tlv },
2631 /* offset by 28 volume steps to limit minimum gain to -46dB */
2632 .private_value =
2633 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2634 },
2635 {}
2636};
2637
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002638static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002639 {
2640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2641 .name = "DC Mode Enable Switch",
2642 .info = snd_ctl_boolean_mono_info,
2643 .get = cxt5066_olpc_dc_get,
2644 .put = cxt5066_olpc_dc_put,
2645 },
2646 {
2647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2648 .name = "DC Input Bias Enum",
2649 .info = cxt5066_olpc_dc_bias_enum_info,
2650 .get = cxt5066_olpc_dc_bias_enum_get,
2651 .put = cxt5066_olpc_dc_bias_enum_put,
2652 },
2653 {}
2654};
2655
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002656static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002657 {
2658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2659 .name = "Master Playback Switch",
2660 .info = cxt_eapd_info,
2661 .get = cxt_eapd_get,
2662 .put = cxt5066_hp_master_sw_put,
2663 .private_value = 0x1d,
2664 },
2665
2666 {
2667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002668 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002669 .info = cxt5066_mic_boost_mux_enum_info,
2670 .get = cxt5066_mic_boost_mux_enum_get,
2671 .put = cxt5066_mic_boost_mux_enum_put,
2672 },
2673
2674 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2675 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2676 {}
2677};
2678
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002679static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002680 {
2681 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002682 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002683 .info = cxt5066_mic_boost_mux_enum_info,
2684 .get = cxt5066_mic_boost_mux_enum_get,
2685 .put = cxt5066_mic_boost_mux_enum_put,
2686 .private_value = 0x23 | 0x100,
2687 },
2688 {}
2689};
2690
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002691static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002692 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2693 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2694 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2695 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2696
2697 /* Speakers */
2698 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2699 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2700
2701 /* HP, Amp */
2702 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2703 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2704
2705 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2706 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2707
2708 /* DAC1 */
2709 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2710
2711 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2712 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2713 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2714 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2715 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2716 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2717
2718 /* no digital microphone support yet */
2719 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2720
2721 /* Audio input selector */
2722 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2723
2724 /* SPDIF route: PCM */
2725 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2726 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2727
2728 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2729 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2730
2731 /* EAPD */
2732 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2733
2734 /* not handling these yet */
2735 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2736 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2737 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2738 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2739 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2740 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2741 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2742 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 { } /* end */
2744};
2745
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002746static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002747 /* Port A: headphones */
2748 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2749 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2750
2751 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002752 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002753
2754 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002755 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002756
2757 /* Port D: unused */
2758 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2759
2760 /* Port E: unused, but has primary EAPD */
2761 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2762 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2763
Daniel Drakec4cfe662010-01-07 13:47:04 +01002764 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002765 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2766
2767 /* Port G: internal speakers */
2768 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2769 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2770
2771 /* DAC1 */
2772 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2773
2774 /* DAC2: unused */
2775 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2776
2777 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2781 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2782 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2784 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2785 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2786 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2787 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2788 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2789
2790 /* Disable digital microphone port */
2791 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2792
2793 /* Audio input selectors */
2794 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2795 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2796
2797 /* Disable SPDIF */
2798 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2799 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2800
2801 /* enable unsolicited events for Port A and B */
2802 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2803 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2804 { } /* end */
2805};
2806
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002807static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002808 /* Port A: headphones */
2809 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2810 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2811
2812 /* Port B: external microphone */
2813 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2814
2815 /* Port C: unused */
2816 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2817
2818 /* Port D: unused */
2819 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2820
2821 /* Port E: unused, but has primary EAPD */
2822 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2823 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2824
2825 /* Port F: unused */
2826 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2827
2828 /* Port G: internal speakers */
2829 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2830 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2831
2832 /* DAC1 */
2833 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2834
2835 /* DAC2: unused */
2836 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2837
2838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2839 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2840 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2842 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2843 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2844 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2846 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2847 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2848 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2850
2851 /* Digital microphone port */
2852 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2853
2854 /* Audio input selectors */
2855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2856 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2857
2858 /* Disable SPDIF */
2859 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2860 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2861
2862 /* enable unsolicited events for Port A and B */
2863 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2864 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2865 { } /* end */
2866};
2867
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002868static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002869 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2870 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2871 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2872 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2873
2874 /* Speakers */
2875 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2876 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2877
2878 /* HP, Amp */
2879 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2880 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2881
2882 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2883 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2884
2885 /* DAC1 */
2886 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2887
2888 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2889 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2890 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2891 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2892 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2893 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2894 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2895
2896 /* Audio input selector */
2897 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2898 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2899
2900 /* SPDIF route: PCM */
2901 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2902 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2903
2904 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2905 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2906
2907 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002908 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002909
2910 /* EAPD */
2911 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2912
2913 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2914 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2915 { } /* end */
2916};
2917
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002918static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002919 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2920 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2921
2922 /* Port G: internal speakers */
2923 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2924 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2925
2926 /* Port A: HP, Amp */
2927 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2928 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2929
2930 /* Port B: Mic Dock */
2931 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2932
2933 /* Port C: Mic */
2934 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2935
2936 /* Port D: HP Dock, Amp */
2937 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2938 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2939
2940 /* DAC1 */
2941 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2942
2943 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2944 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2945 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2946 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2947 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2948 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2949 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2950
2951 /* Audio input selector */
2952 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2953 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2954
2955 /* SPDIF route: PCM */
2956 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2957 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2958
2959 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2960 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2961
2962 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002963 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002964
2965 /* EAPD */
2966 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2967
2968 /* enable unsolicited events for Port A, B, C and D */
2969 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2970 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2971 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2972 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2973 { } /* end */
2974};
2975
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002976static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002977 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2978 { } /* end */
2979};
2980
David Henningsson048e78a2010-09-02 08:35:47 +02002981
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002982static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002983 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2984 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2985 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2986 { } /* end */
2987};
2988
Daniel Drake0fb67e92009-07-16 14:46:57 +01002989/* initialize jack-sensing, too */
2990static int cxt5066_init(struct hda_codec *codec)
2991{
2992 snd_printdd("CXT5066: init\n");
2993 conexant_init(codec);
2994 if (codec->patch_ops.unsol_event) {
2995 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002996 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002997 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002998 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002999 return 0;
3000}
3001
Daniel Drake75f89912010-01-07 13:46:25 +01003002static int cxt5066_olpc_init(struct hda_codec *codec)
3003{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003004 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003005 snd_printdd("CXT5066: init\n");
3006 conexant_init(codec);
3007 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003008 if (!spec->dc_enable) {
3009 cxt5066_set_mic_boost(codec);
3010 cxt5066_olpc_automic(codec);
3011 } else {
3012 cxt5066_enable_dc(codec);
3013 }
Daniel Drake75f89912010-01-07 13:46:25 +01003014 return 0;
3015}
3016
Daniel Drake0fb67e92009-07-16 14:46:57 +01003017enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003018 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003019 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3020 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003021 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003022 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003023 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003024 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003025 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003026 CXT5066_MODELS
3027};
3028
Takashi Iwaiea734962011-01-17 11:29:34 +01003029static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003030 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003031 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3032 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003033 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003034 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003035 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003036 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003037 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003038};
3039
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003040static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003041 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003042 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003043 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003044 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003045 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003046 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003047 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3048 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003049 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003050 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003051 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003052 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003053 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003054 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003055 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003056 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3057 CXT5066_LAPTOP),
3058 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003059 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003060 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003061 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003062 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003063 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003064 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003065 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003066 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003067 {}
3068};
3069
3070static int patch_cxt5066(struct hda_codec *codec)
3071{
3072 struct conexant_spec *spec;
3073 int board_config;
3074
3075 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3076 if (!spec)
3077 return -ENOMEM;
3078 codec->spec = spec;
3079
3080 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003081 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003082
3083 spec->dell_automute = 0;
3084 spec->multiout.max_channels = 2;
3085 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3086 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003087 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3088 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003089 spec->num_adc_nids = 1;
3090 spec->adc_nids = cxt5066_adc_nids;
3091 spec->capsrc_nids = cxt5066_capsrc_nids;
3092 spec->input_mux = &cxt5066_capture_source;
3093
3094 spec->port_d_mode = PIN_HP;
3095
3096 spec->num_init_verbs = 1;
3097 spec->init_verbs[0] = cxt5066_init_verbs;
3098 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3099 spec->channel_mode = cxt5066_modes;
3100 spec->cur_adc = 0;
3101 spec->cur_adc_idx = 0;
3102
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003103 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3104
Daniel Drake0fb67e92009-07-16 14:46:57 +01003105 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3106 cxt5066_models, cxt5066_cfg_tbl);
3107 switch (board_config) {
3108 default:
3109 case CXT5066_LAPTOP:
3110 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3111 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3112 break;
3113 case CXT5066_DELL_LAPTOP:
3114 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3115 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3116
3117 spec->port_d_mode = PIN_OUT;
3118 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3119 spec->num_init_verbs++;
3120 spec->dell_automute = 1;
3121 break;
David Henningssona1d69062011-01-21 13:33:28 +01003122 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003123 case CXT5066_HP_LAPTOP:
3124 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003125 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003126 spec->init_verbs[spec->num_init_verbs] =
3127 cxt5066_init_verbs_hp_laptop;
3128 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003129 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3130 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003131 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3132 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3133 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003134 if (board_config == CXT5066_HP_LAPTOP)
3135 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003136 /* input source automatically selected */
3137 spec->input_mux = NULL;
3138 spec->port_d_mode = 0;
3139 spec->mic_boost = 3; /* default 30dB gain */
3140 break;
3141
Daniel Drake0fb67e92009-07-16 14:46:57 +01003142 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003143 codec->patch_ops.init = cxt5066_olpc_init;
3144 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003145 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3146 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003147 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003148 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3149 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003150 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003151
3152 /* no S/PDIF out */
3153 spec->multiout.dig_out_nid = 0;
3154
3155 /* input source automatically selected */
3156 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003157
3158 /* our capture hooks which allow us to turn on the microphone LED
3159 * at the right time */
3160 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3161 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003162 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003163 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003164 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003165 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003166 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3167 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3168 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003169 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003170 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003171 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003172 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003173
3174 /* no S/PDIF out */
3175 spec->multiout.dig_out_nid = 0;
3176
3177 /* input source automatically selected */
3178 spec->input_mux = NULL;
3179 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003180 case CXT5066_IDEAPAD:
3181 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003182 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003183 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3184 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3185 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3186 spec->port_d_mode = 0;
3187 spec->ideapad = 1;
3188 spec->mic_boost = 2; /* default 20dB gain */
3189
3190 /* no S/PDIF out */
3191 spec->multiout.dig_out_nid = 0;
3192
3193 /* input source automatically selected */
3194 spec->input_mux = NULL;
3195 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003196 case CXT5066_THINKPAD:
3197 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003198 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003199 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3200 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3201 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3202 spec->thinkpad = 1;
3203 spec->port_d_mode = PIN_OUT;
3204 spec->mic_boost = 2; /* default 20dB gain */
3205
3206 /* no S/PDIF out */
3207 spec->multiout.dig_out_nid = 0;
3208
3209 /* input source automatically selected */
3210 spec->input_mux = NULL;
3211 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003212 }
3213
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003214 if (spec->beep_amp)
3215 snd_hda_attach_beep_device(codec, spec->beep_amp);
3216
Daniel Drake0fb67e92009-07-16 14:46:57 +01003217 return 0;
3218}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003219
3220/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003221 * Automatic parser for CX20641 & co
3222 */
3223
Takashi Iwai6764bce2011-05-13 16:52:25 +02003224static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3225 struct hda_codec *codec,
3226 unsigned int stream_tag,
3227 unsigned int format,
3228 struct snd_pcm_substream *substream)
3229{
3230 struct conexant_spec *spec = codec->spec;
3231 hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]];
3232 if (spec->adc_switching) {
3233 spec->cur_adc = adc;
3234 spec->cur_adc_stream_tag = stream_tag;
3235 spec->cur_adc_format = format;
3236 }
3237 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3238 return 0;
3239}
3240
3241static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3242 struct hda_codec *codec,
3243 struct snd_pcm_substream *substream)
3244{
3245 struct conexant_spec *spec = codec->spec;
3246 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3247 spec->cur_adc = 0;
3248 return 0;
3249}
3250
3251static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3252 .substreams = 1,
3253 .channels_min = 2,
3254 .channels_max = 2,
3255 .nid = 0, /* fill later */
3256 .ops = {
3257 .prepare = cx_auto_capture_pcm_prepare,
3258 .cleanup = cx_auto_capture_pcm_cleanup
3259 },
3260};
3261
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003262static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003263
3264/* get the connection index of @nid in the widget @mux */
3265static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3266 hda_nid_t nid)
3267{
3268 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3269 int i, nums;
3270
3271 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3272 for (i = 0; i < nums; i++)
3273 if (conn[i] == nid)
3274 return i;
3275 return -1;
3276}
3277
Takashi Iwai6764bce2011-05-13 16:52:25 +02003278static int has_multi_connection(struct hda_codec *codec, hda_nid_t mux)
3279{
3280 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3281 int nums;
3282
3283 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3284 return nums > 1;
3285}
3286
Takashi Iwaif2e57312010-09-15 10:07:08 +02003287/* get an unassigned DAC from the given list.
3288 * Return the nid if found and reduce the DAC list, or return zero if
3289 * not found
3290 */
3291static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3292 hda_nid_t *dacs, int *num_dacs)
3293{
3294 int i, nums = *num_dacs;
3295 hda_nid_t ret = 0;
3296
3297 for (i = 0; i < nums; i++) {
3298 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3299 ret = dacs[i];
3300 break;
3301 }
3302 }
3303 if (!ret)
3304 return 0;
3305 if (--nums > 0)
3306 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3307 *num_dacs = nums;
3308 return ret;
3309}
3310
3311#define MAX_AUTO_DACS 5
3312
3313/* fill analog DAC list from the widget tree */
3314static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3315{
3316 hda_nid_t nid, end_nid;
3317 int nums = 0;
3318
3319 end_nid = codec->start_nid + codec->num_nodes;
3320 for (nid = codec->start_nid; nid < end_nid; nid++) {
3321 unsigned int wcaps = get_wcaps(codec, nid);
3322 unsigned int type = get_wcaps_type(wcaps);
3323 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3324 dacs[nums++] = nid;
3325 if (nums >= MAX_AUTO_DACS)
3326 break;
3327 }
3328 }
3329 return nums;
3330}
3331
3332/* fill pin_dac_pair list from the pin and dac list */
3333static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3334 int num_pins, hda_nid_t *dacs, int *rest,
3335 struct pin_dac_pair *filled, int type)
3336{
3337 int i, nums;
3338
3339 nums = 0;
3340 for (i = 0; i < num_pins; i++) {
3341 filled[nums].pin = pins[i];
3342 filled[nums].type = type;
3343 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3344 nums++;
3345 }
3346 return nums;
3347}
3348
3349/* parse analog output paths */
3350static void cx_auto_parse_output(struct hda_codec *codec)
3351{
3352 struct conexant_spec *spec = codec->spec;
3353 struct auto_pin_cfg *cfg = &spec->autocfg;
3354 hda_nid_t dacs[MAX_AUTO_DACS];
3355 int i, j, nums, rest;
3356
3357 rest = fill_cx_auto_dacs(codec, dacs);
3358 /* parse all analog output pins */
3359 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3360 dacs, &rest, spec->dac_info,
3361 AUTO_PIN_LINE_OUT);
3362 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3363 dacs, &rest, spec->dac_info + nums,
3364 AUTO_PIN_HP_OUT);
3365 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3366 dacs, &rest, spec->dac_info + nums,
3367 AUTO_PIN_SPEAKER_OUT);
3368 spec->dac_info_filled = nums;
3369 /* fill multiout struct */
3370 for (i = 0; i < nums; i++) {
3371 hda_nid_t dac = spec->dac_info[i].dac;
3372 if (!dac)
3373 continue;
3374 switch (spec->dac_info[i].type) {
3375 case AUTO_PIN_LINE_OUT:
3376 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3377 spec->multiout.num_dacs++;
3378 break;
3379 case AUTO_PIN_HP_OUT:
3380 case AUTO_PIN_SPEAKER_OUT:
3381 if (!spec->multiout.hp_nid) {
3382 spec->multiout.hp_nid = dac;
3383 break;
3384 }
3385 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3386 if (!spec->multiout.extra_out_nid[j]) {
3387 spec->multiout.extra_out_nid[j] = dac;
3388 break;
3389 }
3390 break;
3391 }
3392 }
3393 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003394 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003395
3396 if (cfg->hp_outs > 0)
3397 spec->auto_mute = 1;
3398 spec->vmaster_nid = spec->private_dac_nids[0];
3399}
3400
Takashi Iwaida339862011-05-13 16:24:15 +02003401static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3402 hda_nid_t *pins, bool on);
3403
Takashi Iwaif2e57312010-09-15 10:07:08 +02003404/* auto-mute/unmute speaker and line outs according to headphone jack */
3405static void cx_auto_hp_automute(struct hda_codec *codec)
3406{
3407 struct conexant_spec *spec = codec->spec;
3408 struct auto_pin_cfg *cfg = &spec->autocfg;
3409 int i, present;
3410
3411 if (!spec->auto_mute)
3412 return;
3413 present = 0;
3414 for (i = 0; i < cfg->hp_outs; i++) {
3415 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3416 present = 1;
3417 break;
3418 }
3419 }
Takashi Iwaida339862011-05-13 16:24:15 +02003420 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003421 for (i = 0; i < cfg->line_outs; i++) {
3422 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3423 AC_VERB_SET_PIN_WIDGET_CONTROL,
3424 present ? 0 : PIN_OUT);
3425 }
Takashi Iwaida339862011-05-13 16:24:15 +02003426 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003427 for (i = 0; !present && i < cfg->line_outs; i++)
3428 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3429 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003430 for (i = 0; i < cfg->speaker_outs; i++) {
3431 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3432 AC_VERB_SET_PIN_WIDGET_CONTROL,
3433 present ? 0 : PIN_OUT);
3434 }
Takashi Iwaida339862011-05-13 16:24:15 +02003435 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003436}
3437
Takashi Iwai6764bce2011-05-13 16:52:25 +02003438static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3439 struct snd_ctl_elem_info *uinfo)
3440{
3441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3442 struct conexant_spec *spec = codec->spec;
3443
3444 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3445}
3446
3447static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3448 struct snd_ctl_elem_value *ucontrol)
3449{
3450 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3451 struct conexant_spec *spec = codec->spec;
3452
3453 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3454 return 0;
3455}
3456
3457static int cx_auto_mux_enum_update(struct hda_codec *codec,
3458 const struct hda_input_mux *imux,
3459 unsigned int idx)
3460{
3461 struct conexant_spec *spec = codec->spec;
3462 hda_nid_t adc;
3463
3464 if (!imux->num_items)
3465 return 0;
3466 if (idx >= imux->num_items)
3467 idx = imux->num_items - 1;
3468 if (spec->cur_mux[0] == idx)
3469 return 0;
3470 adc = spec->imux_adcs[idx];
3471 if (has_multi_connection(codec, adc))
3472 snd_hda_codec_write(codec, adc, 0,
3473 AC_VERB_SET_CONNECT_SEL,
3474 imux->items[idx].index);
3475 if (spec->cur_adc && spec->cur_adc != adc) {
3476 /* stream is running, let's swap the current ADC */
3477 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3478 spec->cur_adc = adc;
3479 snd_hda_codec_setup_stream(codec, adc,
3480 spec->cur_adc_stream_tag, 0,
3481 spec->cur_adc_format);
3482 }
3483 spec->cur_mux[0] = idx;
3484 return 1;
3485}
3486
3487static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3488 struct snd_ctl_elem_value *ucontrol)
3489{
3490 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3491 struct conexant_spec *spec = codec->spec;
3492
3493 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3494 ucontrol->value.enumerated.item[0]);
3495}
3496
3497static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3498 {
3499 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3500 .name = "Capture Source",
3501 .info = cx_auto_mux_enum_info,
3502 .get = cx_auto_mux_enum_get,
3503 .put = cx_auto_mux_enum_put
3504 },
3505 {}
3506};
3507
Takashi Iwaif2e57312010-09-15 10:07:08 +02003508/* automatic switch internal and external mic */
3509static void cx_auto_automic(struct hda_codec *codec)
3510{
3511 struct conexant_spec *spec = codec->spec;
3512 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003513 int ext_idx = spec->auto_mic_ext;
3514
3515 if (!spec->auto_mic)
3516 return;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003517 if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin))
3518 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3519 else
3520 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003521}
3522
3523static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3524{
3525 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3526 switch (res >> 26) {
3527 case CONEXANT_HP_EVENT:
3528 cx_auto_hp_automute(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003529 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003530 break;
3531 case CONEXANT_MIC_EVENT:
3532 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003533 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003534 break;
3535 }
3536}
3537
Takashi Iwaif2e57312010-09-15 10:07:08 +02003538/* return true if it's an internal-mic pin */
3539static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3540{
3541 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3542 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003543 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003544}
3545
3546/* return true if it's an external-mic pin */
3547static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3548{
3549 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3550 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003551 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3552 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003553}
3554
3555/* check whether the pin config is suitable for auto-mic switching;
3556 * auto-mic is enabled only when one int-mic and one-ext mic exist
3557 */
3558static void cx_auto_check_auto_mic(struct hda_codec *codec)
3559{
3560 struct conexant_spec *spec = codec->spec;
3561 struct auto_pin_cfg *cfg = &spec->autocfg;
3562
3563 if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3564 is_int_mic(codec, cfg->inputs[1].pin)) {
3565 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003566 spec->auto_mic_ext = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003567 return;
3568 }
Takashi Iwai2557f742011-05-13 16:18:37 +02003569 if (is_int_mic(codec, cfg->inputs[0].pin) &&
3570 is_ext_mic(codec, cfg->inputs[1].pin)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003571 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003572 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003573 return;
3574 }
3575}
3576
3577static void cx_auto_parse_input(struct hda_codec *codec)
3578{
3579 struct conexant_spec *spec = codec->spec;
3580 struct auto_pin_cfg *cfg = &spec->autocfg;
3581 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003582 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003583
3584 imux = &spec->private_imux;
3585 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003586 for (j = 0; j < spec->num_adc_nids; j++) {
3587 hda_nid_t adc = spec->adc_nids[j];
3588 int idx = get_connection_index(codec, adc,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003589 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003590 if (idx >= 0) {
3591 const char *label;
3592 label = hda_get_autocfg_input_label(codec, cfg, i);
3593 snd_hda_add_imux_item(imux, label, idx, NULL);
3594 spec->imux_adcs[i] = adc;
3595 break;
3596 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003597 }
3598 }
3599 if (imux->num_items == 2 && cfg->num_inputs == 2)
3600 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003601 if (imux->num_items > 1 && !spec->auto_mic) {
3602 for (i = 1; i < imux->num_items; i++) {
3603 if (spec->imux_adcs[i] != spec->imux_adcs[0]) {
3604 spec->adc_switching = 1;
3605 break;
3606 }
3607 }
3608 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003609}
3610
3611/* get digital-input audio widget corresponding to the given pin */
3612static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3613{
3614 hda_nid_t nid, end_nid;
3615
3616 end_nid = codec->start_nid + codec->num_nodes;
3617 for (nid = codec->start_nid; nid < end_nid; nid++) {
3618 unsigned int wcaps = get_wcaps(codec, nid);
3619 unsigned int type = get_wcaps_type(wcaps);
3620 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3621 if (get_connection_index(codec, nid, pin) >= 0)
3622 return nid;
3623 }
3624 }
3625 return 0;
3626}
3627
3628static void cx_auto_parse_digital(struct hda_codec *codec)
3629{
3630 struct conexant_spec *spec = codec->spec;
3631 struct auto_pin_cfg *cfg = &spec->autocfg;
3632 hda_nid_t nid;
3633
3634 if (cfg->dig_outs &&
3635 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3636 spec->multiout.dig_out_nid = nid;
3637 if (cfg->dig_in_pin)
3638 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3639}
3640
3641#ifdef CONFIG_SND_HDA_INPUT_BEEP
3642static void cx_auto_parse_beep(struct hda_codec *codec)
3643{
3644 struct conexant_spec *spec = codec->spec;
3645 hda_nid_t nid, end_nid;
3646
3647 end_nid = codec->start_nid + codec->num_nodes;
3648 for (nid = codec->start_nid; nid < end_nid; nid++)
3649 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3650 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3651 break;
3652 }
3653}
3654#else
3655#define cx_auto_parse_beep(codec)
3656#endif
3657
3658static int cx_auto_parse_auto_config(struct hda_codec *codec)
3659{
3660 struct conexant_spec *spec = codec->spec;
3661 int err;
3662
3663 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3664 if (err < 0)
3665 return err;
3666
3667 cx_auto_parse_output(codec);
3668 cx_auto_parse_input(codec);
3669 cx_auto_parse_digital(codec);
3670 cx_auto_parse_beep(codec);
3671 return 0;
3672}
3673
Takashi Iwaida339862011-05-13 16:24:15 +02003674static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3675 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003676{
3677 int i;
3678 for (i = 0; i < num_pins; i++) {
3679 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3680 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003681 AC_VERB_SET_EAPD_BTLENABLE,
3682 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003683 }
3684}
3685
3686static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3687 hda_nid_t src)
3688{
3689 int idx = get_connection_index(codec, pin, src);
3690 if (idx >= 0)
3691 snd_hda_codec_write(codec, pin, 0,
3692 AC_VERB_SET_CONNECT_SEL, idx);
3693}
3694
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003695static void mute_outputs(struct hda_codec *codec, int num_nids,
3696 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003697{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003698 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003699
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003700 for (i = 0; i < num_nids; i++) {
3701 hda_nid_t nid = nids[i];
3702 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3703 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003704 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3705 val = AMP_OUT_MUTE;
3706 else
3707 val = AMP_OUT_ZERO;
3708 snd_hda_codec_write(codec, nid, 0,
3709 AC_VERB_SET_AMP_GAIN_MUTE, val);
3710 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003711}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003712
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003713static void cx_auto_init_output(struct hda_codec *codec)
3714{
3715 struct conexant_spec *spec = codec->spec;
3716 struct auto_pin_cfg *cfg = &spec->autocfg;
3717 hda_nid_t nid;
3718 int i;
3719
3720 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003721 for (i = 0; i < cfg->hp_outs; i++)
3722 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3723 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003724 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3725 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3726 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003727 if (spec->auto_mute) {
3728 for (i = 0; i < cfg->hp_outs; i++) {
3729 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3730 AC_VERB_SET_UNSOLICITED_ENABLE,
3731 AC_USRSP_EN | CONEXANT_HP_EVENT);
3732 }
3733 cx_auto_hp_automute(codec);
3734 } else {
3735 for (i = 0; i < cfg->line_outs; i++)
3736 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3737 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3738 for (i = 0; i < cfg->speaker_outs; i++)
3739 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3740 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Takashi Iwaida339862011-05-13 16:24:15 +02003741 /* turn on EAPD */
3742 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3743 true);
3744 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3745 true);
3746 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3747 true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003748 }
3749
3750 for (i = 0; i < spec->dac_info_filled; i++) {
3751 nid = spec->dac_info[i].dac;
3752 if (!nid)
3753 nid = spec->multiout.dac_nids[0];
3754 select_connection(codec, spec->dac_info[i].pin, nid);
3755 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003756}
3757
3758static void cx_auto_init_input(struct hda_codec *codec)
3759{
3760 struct conexant_spec *spec = codec->spec;
3761 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003762 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003763
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003764 for (i = 0; i < spec->num_adc_nids; i++) {
3765 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003766 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3767 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003768 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3769 val = AMP_IN_MUTE(0);
3770 else
3771 val = AMP_IN_UNMUTE(0);
3772 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3773 val);
3774 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003775
3776 for (i = 0; i < cfg->num_inputs; i++) {
3777 unsigned int type;
3778 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3779 type = PIN_VREF80;
3780 else
3781 type = PIN_IN;
3782 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3783 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3784 }
3785
3786 if (spec->auto_mic) {
3787 int ext_idx = spec->auto_mic_ext;
3788 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3789 AC_VERB_SET_UNSOLICITED_ENABLE,
3790 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3791 cx_auto_automic(codec);
3792 } else {
3793 for (i = 0; i < spec->num_adc_nids; i++) {
3794 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3795 AC_VERB_SET_CONNECT_SEL,
3796 spec->private_imux.items[0].index);
3797 }
3798 }
3799}
3800
3801static void cx_auto_init_digital(struct hda_codec *codec)
3802{
3803 struct conexant_spec *spec = codec->spec;
3804 struct auto_pin_cfg *cfg = &spec->autocfg;
3805
3806 if (spec->multiout.dig_out_nid)
3807 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3808 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3809 if (spec->dig_in_nid)
3810 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3811 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3812}
3813
3814static int cx_auto_init(struct hda_codec *codec)
3815{
3816 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3817 cx_auto_init_output(codec);
3818 cx_auto_init_input(codec);
3819 cx_auto_init_digital(codec);
3820 return 0;
3821}
3822
David Henningsson983345e2011-02-15 19:57:09 +01003823static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003824 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01003825 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003826{
3827 static char name[32];
3828 static struct snd_kcontrol_new knew[] = {
3829 HDA_CODEC_VOLUME(name, 0, 0, 0),
3830 HDA_CODEC_MUTE(name, 0, 0, 0),
3831 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003832 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003833 int i, err;
3834
3835 for (i = 0; i < 2; i++) {
3836 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01003837 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3838 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003839 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3840 knew[i].index = cidx;
3841 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3842 kctl = snd_ctl_new1(&knew[i], codec);
3843 if (!kctl)
3844 return -ENOMEM;
3845 err = snd_hda_ctl_add(codec, nid, kctl);
3846 if (err < 0)
3847 return err;
3848 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3849 break;
3850 }
3851 return 0;
3852}
3853
David Henningsson983345e2011-02-15 19:57:09 +01003854#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3855 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3856
Takashi Iwaif2e57312010-09-15 10:07:08 +02003857#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3858 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3859
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003860static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3861 hda_nid_t pin, const char *name, int idx)
3862{
3863 unsigned int caps;
3864 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3865 if (caps & AC_AMPCAP_NUM_STEPS)
3866 return cx_auto_add_pb_volume(codec, dac, name, idx);
3867 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3868 if (caps & AC_AMPCAP_NUM_STEPS)
3869 return cx_auto_add_pb_volume(codec, pin, name, idx);
3870 return 0;
3871}
3872
Takashi Iwaif2e57312010-09-15 10:07:08 +02003873static int cx_auto_build_output_controls(struct hda_codec *codec)
3874{
3875 struct conexant_spec *spec = codec->spec;
3876 int i, err;
3877 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003878 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003879
3880 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003881 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3882 spec->dac_info[0].pin,
3883 "Master", 0);
3884
Takashi Iwaif2e57312010-09-15 10:07:08 +02003885 for (i = 0; i < spec->dac_info_filled; i++) {
3886 const char *label;
3887 int idx, type;
3888 if (!spec->dac_info[i].dac)
3889 continue;
3890 type = spec->dac_info[i].type;
3891 if (type == AUTO_PIN_LINE_OUT)
3892 type = spec->autocfg.line_out_type;
3893 switch (type) {
3894 case AUTO_PIN_LINE_OUT:
3895 default:
3896 label = texts[num_line++];
3897 idx = 0;
3898 break;
3899 case AUTO_PIN_HP_OUT:
3900 label = "Headphone";
3901 idx = num_hp++;
3902 break;
3903 case AUTO_PIN_SPEAKER_OUT:
3904 label = "Speaker";
3905 idx = num_spk++;
3906 break;
3907 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003908 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3909 spec->dac_info[i].pin,
3910 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003911 if (err < 0)
3912 return err;
3913 }
3914 return 0;
3915}
3916
Takashi Iwai6764bce2011-05-13 16:52:25 +02003917static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3918 const char *label, const char *pfx,
3919 int cidx)
3920{
3921 struct conexant_spec *spec = codec->spec;
3922 int i;
3923
3924 for (i = 0; i < spec->num_adc_nids; i++) {
3925 hda_nid_t adc_nid = spec->adc_nids[i];
3926 int idx = get_connection_index(codec, adc_nid, nid);
3927 if (idx < 0)
3928 continue;
3929 return cx_auto_add_volume_idx(codec, label, pfx,
3930 cidx, adc_nid, HDA_INPUT, idx);
3931 }
3932 return 0;
3933}
3934
Takashi Iwaif2e57312010-09-15 10:07:08 +02003935static int cx_auto_build_input_controls(struct hda_codec *codec)
3936{
3937 struct conexant_spec *spec = codec->spec;
3938 struct auto_pin_cfg *cfg = &spec->autocfg;
3939 static const char *prev_label;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003940 int i, err, cidx;
David Henningsson983345e2011-02-15 19:57:09 +01003941
Takashi Iwaif2e57312010-09-15 10:07:08 +02003942 prev_label = NULL;
3943 cidx = 0;
3944 for (i = 0; i < cfg->num_inputs; i++) {
3945 hda_nid_t nid = cfg->inputs[i].pin;
3946 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01003947 int pin_amp = get_wcaps(codec, nid) & AC_WCAP_IN_AMP;
David Henningsson983345e2011-02-15 19:57:09 +01003948
Takashi Iwaif2e57312010-09-15 10:07:08 +02003949 label = hda_get_autocfg_input_label(codec, cfg, i);
3950 if (label == prev_label)
3951 cidx++;
3952 else
3953 cidx = 0;
3954 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01003955
3956 if (pin_amp) {
3957 err = cx_auto_add_volume(codec, label, " Boost", cidx,
3958 nid, HDA_INPUT);
3959 if (err < 0)
3960 return err;
3961 }
3962
Takashi Iwai6764bce2011-05-13 16:52:25 +02003963 if (cfg->num_inputs == 1) {
3964 err = cx_auto_add_capture_volume(codec, nid,
3965 "Capture", "", cidx);
3966 } else {
3967 err = cx_auto_add_capture_volume(codec, nid,
3968 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01003969 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02003970 if (err < 0)
3971 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003972 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02003973
3974 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
3975 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
3976 if (err < 0)
3977 return err;
3978 }
3979
Takashi Iwaif2e57312010-09-15 10:07:08 +02003980 return 0;
3981}
3982
3983static int cx_auto_build_controls(struct hda_codec *codec)
3984{
3985 int err;
3986
3987 err = cx_auto_build_output_controls(codec);
3988 if (err < 0)
3989 return err;
3990 err = cx_auto_build_input_controls(codec);
3991 if (err < 0)
3992 return err;
3993 return conexant_build_controls(codec);
3994}
3995
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003996static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003997 .build_controls = cx_auto_build_controls,
3998 .build_pcms = conexant_build_pcms,
3999 .init = cx_auto_init,
4000 .free = conexant_free,
4001 .unsol_event = cx_auto_unsol_event,
4002#ifdef CONFIG_SND_HDA_POWER_SAVE
4003 .suspend = conexant_suspend,
4004#endif
4005 .reboot_notify = snd_hda_shutup_pins,
4006};
4007
4008static int patch_conexant_auto(struct hda_codec *codec)
4009{
4010 struct conexant_spec *spec;
4011 int err;
4012
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004013 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4014 codec->chip_name);
4015
Takashi Iwaif2e57312010-09-15 10:07:08 +02004016 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4017 if (!spec)
4018 return -ENOMEM;
4019 codec->spec = spec;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004020 switch (codec->vendor_id) {
4021 case 0x14f15051:
Takashi Iwai6764bce2011-05-13 16:52:25 +02004022 codec->pin_amp_workaround = 1;
4023 spec->adc_nids = cxt5051_adc_nids;
4024 spec->num_adc_nids = ARRAY_SIZE(cxt5051_adc_nids);
4025 spec->capsrc_nids = spec->adc_nids;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004026 break;
4027 case 0x14f15045:
4028 codec->pin_amp_workaround = 1;
4029 spec->adc_nids = cxt5045_adc_nids;
4030 spec->num_adc_nids = ARRAY_SIZE(cxt5045_adc_nids);
4031 spec->capsrc_nids = spec->adc_nids;
4032 break;
4033 default:
Takashi Iwai6764bce2011-05-13 16:52:25 +02004034 spec->adc_nids = cx_auto_adc_nids;
4035 spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
4036 spec->capsrc_nids = spec->adc_nids;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004037 break;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004038 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004039 err = cx_auto_parse_auto_config(codec);
4040 if (err < 0) {
4041 kfree(codec->spec);
4042 codec->spec = NULL;
4043 return err;
4044 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004045 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004046 codec->patch_ops = cx_auto_patch_ops;
4047 if (spec->beep_amp)
4048 snd_hda_attach_beep_device(codec, spec->beep_amp);
4049 return 0;
4050}
4051
4052/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004053 */
4054
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004055static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004056 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4057 .patch = patch_cxt5045 },
4058 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4059 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004060 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4061 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004062 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4063 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004064 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4065 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004066 { .id = 0x14f15068, .name = "CX20584",
4067 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004068 { .id = 0x14f15069, .name = "CX20585",
4069 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004070 { .id = 0x14f1506e, .name = "CX20590",
4071 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004072 { .id = 0x14f15097, .name = "CX20631",
4073 .patch = patch_conexant_auto },
4074 { .id = 0x14f15098, .name = "CX20632",
4075 .patch = patch_conexant_auto },
4076 { .id = 0x14f150a1, .name = "CX20641",
4077 .patch = patch_conexant_auto },
4078 { .id = 0x14f150a2, .name = "CX20642",
4079 .patch = patch_conexant_auto },
4080 { .id = 0x14f150ab, .name = "CX20651",
4081 .patch = patch_conexant_auto },
4082 { .id = 0x14f150ac, .name = "CX20652",
4083 .patch = patch_conexant_auto },
4084 { .id = 0x14f150b8, .name = "CX20664",
4085 .patch = patch_conexant_auto },
4086 { .id = 0x14f150b9, .name = "CX20665",
4087 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004088 {} /* terminator */
4089};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004090
4091MODULE_ALIAS("snd-hda-codec-id:14f15045");
4092MODULE_ALIAS("snd-hda-codec-id:14f15047");
4093MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004094MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004095MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004096MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004097MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004098MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004099MODULE_ALIAS("snd-hda-codec-id:14f15097");
4100MODULE_ALIAS("snd-hda-codec-id:14f15098");
4101MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4102MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4103MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4104MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4105MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4106MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004107
4108MODULE_LICENSE("GPL");
4109MODULE_DESCRIPTION("Conexant HD-audio codec");
4110
4111static struct hda_codec_preset_list conexant_list = {
4112 .preset = snd_hda_preset_conexant,
4113 .owner = THIS_MODULE,
4114};
4115
4116static int __init patch_conexant_init(void)
4117{
4118 return snd_hda_add_codec_preset(&conexant_list);
4119}
4120
4121static void __exit patch_conexant_exit(void)
4122{
4123 snd_hda_delete_codec_preset(&conexant_list);
4124}
4125
4126module_init(patch_conexant_init)
4127module_exit(patch_conexant_exit)