blob: e652b34b1bd924d91c6b33684efd013dd3279784 [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
52struct conexant_jack {
53
54 hda_nid_t nid;
55 int type;
56 struct snd_jack *jack;
57
58};
Tobin Davisc9b443d2006-11-14 12:13:39 +010059
Takashi Iwaif2e57312010-09-15 10:07:08 +020060struct pin_dac_pair {
61 hda_nid_t pin;
62 hda_nid_t dac;
63 int type;
64};
65
Tobin Davisc9b443d2006-11-14 12:13:39 +010066struct conexant_spec {
67
68 struct snd_kcontrol_new *mixers[5];
69 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010070 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010071
72 const struct hda_verb *init_verbs[5]; /* initialization verbs
73 * don't forget NULL
74 * termination!
75 */
76 unsigned int num_init_verbs;
77
78 /* playback */
79 struct hda_multi_out multiout; /* playback set-up
80 * max_channels, dacs must be set
81 * dig_out_nid and hp_nid are optional
82 */
83 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010084 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010085 unsigned int auto_mic;
Takashi Iwaif2e57312010-09-15 10:07:08 +020086 int auto_mic_ext; /* autocfg.inputs[] index for ext mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010087 unsigned int need_dac_fix;
88
89 /* capture */
90 unsigned int num_adc_nids;
91 hda_nid_t *adc_nids;
92 hda_nid_t dig_in_nid; /* digital-in NID; optional */
93
Takashi Iwai461e2c72008-01-25 11:35:17 +010094 unsigned int cur_adc_idx;
95 hda_nid_t cur_adc;
96 unsigned int cur_adc_stream_tag;
97 unsigned int cur_adc_format;
98
Tobin Davisc9b443d2006-11-14 12:13:39 +010099 /* capture source */
100 const struct hda_input_mux *input_mux;
101 hda_nid_t *capsrc_nids;
102 unsigned int cur_mux[3];
103
104 /* channel model */
105 const struct hda_channel_mode *channel_mode;
106 int num_channel_mode;
107
108 /* PCM information */
109 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
110
Tobin Davisc9b443d2006-11-14 12:13:39 +0100111 unsigned int spdif_route;
112
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100113 /* jack detection */
114 struct snd_array jacks;
115
Tobin Davisc9b443d2006-11-14 12:13:39 +0100116 /* dynamic controls, init_verbs and input_mux */
117 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100118 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200119 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200120 struct pin_dac_pair dac_info[8];
121 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100122
Daniel Drake0fb67e92009-07-16 14:46:57 +0100123 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200124 unsigned int auto_mute:1; /* used in auto-parser */
125 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500126 unsigned int dell_vostro:1;
127 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200128 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200129 unsigned int hp_laptop:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100130
131 unsigned int ext_mic_present;
132 unsigned int recording;
133 void (*capture_prepare)(struct hda_codec *codec);
134 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100135
136 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
137 * through the microphone jack.
138 * When the user enables this through a mixer switch, both internal and
139 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
140 * we also allow the bias to be configured through a separate mixer
141 * control. */
142 unsigned int dc_enable;
143 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
144 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200145
146 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100147};
148
149static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
150 struct hda_codec *codec,
151 struct snd_pcm_substream *substream)
152{
153 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100154 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
155 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100156}
157
158static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 unsigned int stream_tag,
161 unsigned int format,
162 struct snd_pcm_substream *substream)
163{
164 struct conexant_spec *spec = codec->spec;
165 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
166 stream_tag,
167 format, substream);
168}
169
170static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
173{
174 struct conexant_spec *spec = codec->spec;
175 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
176}
177
178/*
179 * Digital out
180 */
181static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
182 struct hda_codec *codec,
183 struct snd_pcm_substream *substream)
184{
185 struct conexant_spec *spec = codec->spec;
186 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
187}
188
189static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
190 struct hda_codec *codec,
191 struct snd_pcm_substream *substream)
192{
193 struct conexant_spec *spec = codec->spec;
194 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
195}
196
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200197static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
198 struct hda_codec *codec,
199 unsigned int stream_tag,
200 unsigned int format,
201 struct snd_pcm_substream *substream)
202{
203 struct conexant_spec *spec = codec->spec;
204 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
205 stream_tag,
206 format, substream);
207}
208
Tobin Davisc9b443d2006-11-14 12:13:39 +0100209/*
210 * Analog capture
211 */
212static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
213 struct hda_codec *codec,
214 unsigned int stream_tag,
215 unsigned int format,
216 struct snd_pcm_substream *substream)
217{
218 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100219 if (spec->capture_prepare)
220 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100221 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
222 stream_tag, 0, format);
223 return 0;
224}
225
226static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
227 struct hda_codec *codec,
228 struct snd_pcm_substream *substream)
229{
230 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100231 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100232 if (spec->capture_cleanup)
233 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100234 return 0;
235}
236
237
238
239static struct hda_pcm_stream conexant_pcm_analog_playback = {
240 .substreams = 1,
241 .channels_min = 2,
242 .channels_max = 2,
243 .nid = 0, /* fill later */
244 .ops = {
245 .open = conexant_playback_pcm_open,
246 .prepare = conexant_playback_pcm_prepare,
247 .cleanup = conexant_playback_pcm_cleanup
248 },
249};
250
251static struct hda_pcm_stream conexant_pcm_analog_capture = {
252 .substreams = 1,
253 .channels_min = 2,
254 .channels_max = 2,
255 .nid = 0, /* fill later */
256 .ops = {
257 .prepare = conexant_capture_pcm_prepare,
258 .cleanup = conexant_capture_pcm_cleanup
259 },
260};
261
262
263static struct hda_pcm_stream conexant_pcm_digital_playback = {
264 .substreams = 1,
265 .channels_min = 2,
266 .channels_max = 2,
267 .nid = 0, /* fill later */
268 .ops = {
269 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200270 .close = conexant_dig_playback_pcm_close,
271 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100272 },
273};
274
275static struct hda_pcm_stream conexant_pcm_digital_capture = {
276 .substreams = 1,
277 .channels_min = 2,
278 .channels_max = 2,
279 /* NID is set in alc_build_pcms */
280};
281
Takashi Iwai461e2c72008-01-25 11:35:17 +0100282static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
283 struct hda_codec *codec,
284 unsigned int stream_tag,
285 unsigned int format,
286 struct snd_pcm_substream *substream)
287{
288 struct conexant_spec *spec = codec->spec;
289 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
290 spec->cur_adc_stream_tag = stream_tag;
291 spec->cur_adc_format = format;
292 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
293 return 0;
294}
295
296static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
297 struct hda_codec *codec,
298 struct snd_pcm_substream *substream)
299{
300 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100301 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100302 spec->cur_adc = 0;
303 return 0;
304}
305
306static struct hda_pcm_stream cx5051_pcm_analog_capture = {
307 .substreams = 1,
308 .channels_min = 2,
309 .channels_max = 2,
310 .nid = 0, /* fill later */
311 .ops = {
312 .prepare = cx5051_capture_pcm_prepare,
313 .cleanup = cx5051_capture_pcm_cleanup
314 },
315};
316
Tobin Davisc9b443d2006-11-14 12:13:39 +0100317static int conexant_build_pcms(struct hda_codec *codec)
318{
319 struct conexant_spec *spec = codec->spec;
320 struct hda_pcm *info = spec->pcm_rec;
321
322 codec->num_pcms = 1;
323 codec->pcm_info = info;
324
325 info->name = "CONEXANT Analog";
326 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
327 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
328 spec->multiout.max_channels;
329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
330 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100331 if (codec->vendor_id == 0x14f15051)
332 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
333 cx5051_pcm_analog_capture;
334 else
335 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
336 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100337 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
338 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
339
340 if (spec->multiout.dig_out_nid) {
341 info++;
342 codec->num_pcms++;
343 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100344 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100345 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
346 conexant_pcm_digital_playback;
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
348 spec->multiout.dig_out_nid;
349 if (spec->dig_in_nid) {
350 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
351 conexant_pcm_digital_capture;
352 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
353 spec->dig_in_nid;
354 }
355 }
356
357 return 0;
358}
359
360static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
361 struct snd_ctl_elem_info *uinfo)
362{
363 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
364 struct conexant_spec *spec = codec->spec;
365
366 return snd_hda_input_mux_info(spec->input_mux, uinfo);
367}
368
369static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
370 struct snd_ctl_elem_value *ucontrol)
371{
372 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
373 struct conexant_spec *spec = codec->spec;
374 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
375
376 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
377 return 0;
378}
379
380static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
381 struct snd_ctl_elem_value *ucontrol)
382{
383 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
384 struct conexant_spec *spec = codec->spec;
385 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
386
387 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
388 spec->capsrc_nids[adc_idx],
389 &spec->cur_mux[adc_idx]);
390}
391
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200392#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200393static void conexant_free_jack_priv(struct snd_jack *jack)
394{
395 struct conexant_jack *jacks = jack->private_data;
396 jacks->nid = 0;
397 jacks->jack = NULL;
398}
399
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100400static int conexant_add_jack(struct hda_codec *codec,
401 hda_nid_t nid, int type)
402{
403 struct conexant_spec *spec;
404 struct conexant_jack *jack;
405 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200406 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100407
408 spec = codec->spec;
409 snd_array_init(&spec->jacks, sizeof(*jack), 32);
410 jack = snd_array_new(&spec->jacks);
411 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
412
413 if (!jack)
414 return -ENOMEM;
415
416 jack->nid = nid;
417 jack->type = type;
418
Takashi Iwai95c09092009-04-14 16:15:29 +0200419 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
420 if (err < 0)
421 return err;
422 jack->jack->private_data = jack;
423 jack->jack->private_free = conexant_free_jack_priv;
424 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100425}
426
427static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
428{
429 struct conexant_spec *spec = codec->spec;
430 struct conexant_jack *jacks = spec->jacks.list;
431
432 if (jacks) {
433 int i;
434 for (i = 0; i < spec->jacks.used; i++) {
435 if (jacks->nid == nid) {
436 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100437 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100438
439 present = (present) ? jacks->type : 0 ;
440
441 snd_jack_report(jacks->jack,
442 present);
443 }
444 jacks++;
445 }
446 }
447}
448
449static int conexant_init_jacks(struct hda_codec *codec)
450{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100451 struct conexant_spec *spec = codec->spec;
452 int i;
453
454 for (i = 0; i < spec->num_init_verbs; i++) {
455 const struct hda_verb *hv;
456
457 hv = spec->init_verbs[i];
458 while (hv->nid) {
459 int err = 0;
460 switch (hv->param ^ AC_USRSP_EN) {
461 case CONEXANT_HP_EVENT:
462 err = conexant_add_jack(codec, hv->nid,
463 SND_JACK_HEADPHONE);
464 conexant_report_jack(codec, hv->nid);
465 break;
466 case CXT5051_PORTC_EVENT:
467 case CONEXANT_MIC_EVENT:
468 err = conexant_add_jack(codec, hv->nid,
469 SND_JACK_MICROPHONE);
470 conexant_report_jack(codec, hv->nid);
471 break;
472 }
473 if (err < 0)
474 return err;
475 ++hv;
476 }
477 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100478 return 0;
479
480}
Takashi Iwai5801f992009-01-27 12:53:22 +0100481#else
482static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
483{
484}
485
486static inline int conexant_init_jacks(struct hda_codec *codec)
487{
488 return 0;
489}
490#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100491
Tobin Davisc9b443d2006-11-14 12:13:39 +0100492static int conexant_init(struct hda_codec *codec)
493{
494 struct conexant_spec *spec = codec->spec;
495 int i;
496
497 for (i = 0; i < spec->num_init_verbs; i++)
498 snd_hda_sequence_write(codec, spec->init_verbs[i]);
499 return 0;
500}
501
502static void conexant_free(struct hda_codec *codec)
503{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200504#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100505 struct conexant_spec *spec = codec->spec;
506 if (spec->jacks.list) {
507 struct conexant_jack *jacks = spec->jacks.list;
508 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200509 for (i = 0; i < spec->jacks.used; i++, jacks++) {
510 if (jacks->jack)
511 snd_device_free(codec->bus->card, jacks->jack);
512 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100513 snd_array_free(&spec->jacks);
514 }
515#endif
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200516 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100517 kfree(codec->spec);
518}
519
Takashi Iwaib880c742009-03-10 14:41:05 +0100520static struct snd_kcontrol_new cxt_capture_mixers[] = {
521 {
522 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
523 .name = "Capture Source",
524 .info = conexant_mux_enum_info,
525 .get = conexant_mux_enum_get,
526 .put = conexant_mux_enum_put
527 },
528 {}
529};
530
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200531#ifdef CONFIG_SND_HDA_INPUT_BEEP
532/* additional beep mixers; the actual parameters are overwritten at build */
533static struct snd_kcontrol_new cxt_beep_mixer[] = {
534 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
535 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
536 { } /* end */
537};
538#endif
539
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100540static const char *slave_vols[] = {
541 "Headphone Playback Volume",
542 "Speaker Playback Volume",
543 NULL
544};
545
546static const char *slave_sws[] = {
547 "Headphone Playback Switch",
548 "Speaker Playback Switch",
549 NULL
550};
551
Tobin Davisc9b443d2006-11-14 12:13:39 +0100552static int conexant_build_controls(struct hda_codec *codec)
553{
554 struct conexant_spec *spec = codec->spec;
555 unsigned int i;
556 int err;
557
558 for (i = 0; i < spec->num_mixers; i++) {
559 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
560 if (err < 0)
561 return err;
562 }
563 if (spec->multiout.dig_out_nid) {
564 err = snd_hda_create_spdif_out_ctls(codec,
565 spec->multiout.dig_out_nid);
566 if (err < 0)
567 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100568 err = snd_hda_create_spdif_share_sw(codec,
569 &spec->multiout);
570 if (err < 0)
571 return err;
572 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100573 }
574 if (spec->dig_in_nid) {
575 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
576 if (err < 0)
577 return err;
578 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100579
580 /* if we have no master control, let's create it */
581 if (spec->vmaster_nid &&
582 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
583 unsigned int vmaster_tlv[4];
584 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
585 HDA_OUTPUT, vmaster_tlv);
586 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
587 vmaster_tlv, slave_vols);
588 if (err < 0)
589 return err;
590 }
591 if (spec->vmaster_nid &&
592 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
593 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
594 NULL, slave_sws);
595 if (err < 0)
596 return err;
597 }
598
Takashi Iwaib880c742009-03-10 14:41:05 +0100599 if (spec->input_mux) {
600 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
601 if (err < 0)
602 return err;
603 }
604
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200605#ifdef CONFIG_SND_HDA_INPUT_BEEP
606 /* create beep controls if needed */
607 if (spec->beep_amp) {
608 struct snd_kcontrol_new *knew;
609 for (knew = cxt_beep_mixer; knew->name; knew++) {
610 struct snd_kcontrol *kctl;
611 kctl = snd_ctl_new1(knew, codec);
612 if (!kctl)
613 return -ENOMEM;
614 kctl->private_value = spec->beep_amp;
615 err = snd_hda_ctl_add(codec, 0, kctl);
616 if (err < 0)
617 return err;
618 }
619 }
620#endif
621
Tobin Davisc9b443d2006-11-14 12:13:39 +0100622 return 0;
623}
624
Takashi Iwai697c3732010-07-30 11:28:02 +0200625#ifdef CONFIG_SND_HDA_POWER_SAVE
626static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
627{
628 snd_hda_shutup_pins(codec);
629 return 0;
630}
631#endif
632
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633static struct hda_codec_ops conexant_patch_ops = {
634 .build_controls = conexant_build_controls,
635 .build_pcms = conexant_build_pcms,
636 .init = conexant_init,
637 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200638#ifdef CONFIG_SND_HDA_POWER_SAVE
639 .suspend = conexant_suspend,
640#endif
641 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100642};
643
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200644#ifdef CONFIG_SND_HDA_INPUT_BEEP
645#define set_beep_amp(spec, nid, idx, dir) \
646 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
647#else
648#define set_beep_amp(spec, nid, idx, dir) /* NOP */
649#endif
650
Tobin Davisc9b443d2006-11-14 12:13:39 +0100651/*
652 * EAPD control
653 * the private value = nid | (invert << 8)
654 */
655
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200656#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100657
Tobin Davis82f30042007-02-13 12:45:44 +0100658static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100659 struct snd_ctl_elem_value *ucontrol)
660{
661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct conexant_spec *spec = codec->spec;
663 int invert = (kcontrol->private_value >> 8) & 1;
664 if (invert)
665 ucontrol->value.integer.value[0] = !spec->cur_eapd;
666 else
667 ucontrol->value.integer.value[0] = spec->cur_eapd;
668 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100669
Tobin Davisc9b443d2006-11-14 12:13:39 +0100670}
671
Tobin Davis82f30042007-02-13 12:45:44 +0100672static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100673 struct snd_ctl_elem_value *ucontrol)
674{
675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
676 struct conexant_spec *spec = codec->spec;
677 int invert = (kcontrol->private_value >> 8) & 1;
678 hda_nid_t nid = kcontrol->private_value & 0xff;
679 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100680
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100681 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100682 if (invert)
683 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200684 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100685 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100686
Tobin Davisc9b443d2006-11-14 12:13:39 +0100687 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200688 snd_hda_codec_write_cache(codec, nid,
689 0, AC_VERB_SET_EAPD_BTLENABLE,
690 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691 return 1;
692}
693
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100694/* controls for test mode */
695#ifdef CONFIG_SND_DEBUG
696
Tobin Davis82f30042007-02-13 12:45:44 +0100697#define CXT_EAPD_SWITCH(xname, nid, mask) \
698 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
699 .info = cxt_eapd_info, \
700 .get = cxt_eapd_get, \
701 .put = cxt_eapd_put, \
702 .private_value = nid | (mask<<16) }
703
704
705
Tobin Davisc9b443d2006-11-14 12:13:39 +0100706static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
707 struct snd_ctl_elem_info *uinfo)
708{
709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710 struct conexant_spec *spec = codec->spec;
711 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
712 spec->num_channel_mode);
713}
714
715static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
716 struct snd_ctl_elem_value *ucontrol)
717{
718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
719 struct conexant_spec *spec = codec->spec;
720 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
721 spec->num_channel_mode,
722 spec->multiout.max_channels);
723}
724
725static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
726 struct snd_ctl_elem_value *ucontrol)
727{
728 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
729 struct conexant_spec *spec = codec->spec;
730 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
731 spec->num_channel_mode,
732 &spec->multiout.max_channels);
733 if (err >= 0 && spec->need_dac_fix)
734 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
735 return err;
736}
737
738#define CXT_PIN_MODE(xname, nid, dir) \
739 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
740 .info = conexant_ch_mode_info, \
741 .get = conexant_ch_mode_get, \
742 .put = conexant_ch_mode_put, \
743 .private_value = nid | (dir<<16) }
744
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100745#endif /* CONFIG_SND_DEBUG */
746
Tobin Davisc9b443d2006-11-14 12:13:39 +0100747/* Conexant 5045 specific */
748
749static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
750static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
751static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100752#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100753
Tobin Davis5cd57522006-11-20 17:42:09 +0100754static struct hda_channel_mode cxt5045_modes[1] = {
755 { 2, NULL },
756};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100757
758static struct hda_input_mux cxt5045_capture_source = {
759 .num_items = 2,
760 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100761 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100762 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100763 }
764};
765
Jiang Zhe5218c892008-01-17 11:18:41 +0100766static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200767 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100768 .items = {
769 { "IntMic", 0x1 },
770 { "ExtMic", 0x2 },
771 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200772 { "CD", 0x4 },
773 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100774 }
775};
776
Jiang zhe2de3c232008-03-06 11:09:09 +0100777static struct hda_input_mux cxt5045_capture_source_hp530 = {
778 .num_items = 2,
779 .items = {
780 { "ExtMic", 0x1 },
781 { "IntMic", 0x2 },
782 }
783};
784
Tobin Davisc9b443d2006-11-14 12:13:39 +0100785/* turn on/off EAPD (+ mute HP) as a master switch */
786static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *ucontrol)
788{
789 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
790 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100791 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100792
Tobin Davis82f30042007-02-13 12:45:44 +0100793 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100794 return 0;
795
Tobin Davis82f30042007-02-13 12:45:44 +0100796 /* toggle internal speakers mute depending of presence of
797 * the headphone jack
798 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200799 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
800 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
801 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100802
Takashi Iwai47fd8302007-08-10 17:11:07 +0200803 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
804 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
805 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100806 return 1;
807}
808
809/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200810static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
811 .ops = &snd_hda_bind_vol,
812 .values = {
813 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
814 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
815 0
816 },
817};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818
Tobin Davis7f296732007-03-12 11:39:01 +0100819/* toggle input of built-in and mic jack appropriately */
820static void cxt5045_hp_automic(struct hda_codec *codec)
821{
822 static struct hda_verb mic_jack_on[] = {
823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
824 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
825 {}
826 };
827 static struct hda_verb mic_jack_off[] = {
828 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
829 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
830 {}
831 };
832 unsigned int present;
833
Takashi Iwaid56757a2009-11-18 08:00:14 +0100834 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100835 if (present)
836 snd_hda_sequence_write(codec, mic_jack_on);
837 else
838 snd_hda_sequence_write(codec, mic_jack_off);
839}
840
Tobin Davisc9b443d2006-11-14 12:13:39 +0100841
842/* mute internal speaker if HP is plugged */
843static void cxt5045_hp_automute(struct hda_codec *codec)
844{
Tobin Davis82f30042007-02-13 12:45:44 +0100845 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100846 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100847
Takashi Iwaid56757a2009-11-18 08:00:14 +0100848 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100849
Takashi Iwai47fd8302007-08-10 17:11:07 +0200850 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
851 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
852 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100853}
854
855/* unsolicited event for HP jack sensing */
856static void cxt5045_hp_unsol_event(struct hda_codec *codec,
857 unsigned int res)
858{
859 res >>= 26;
860 switch (res) {
861 case CONEXANT_HP_EVENT:
862 cxt5045_hp_automute(codec);
863 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100864 case CONEXANT_MIC_EVENT:
865 cxt5045_hp_automic(codec);
866 break;
867
Tobin Davisc9b443d2006-11-14 12:13:39 +0100868 }
869}
870
871static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200872 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
873 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
874 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
875 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
876 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
877 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
878 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
879 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
880 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
881 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200882 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100883 {
884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
885 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100886 .info = cxt_eapd_info,
887 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100888 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100889 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100890 },
891
892 {}
893};
894
Jiang Zhe5218c892008-01-17 11:18:41 +0100895static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200896 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
897 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
898 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
899 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
900
Jiang Zhe5218c892008-01-17 11:18:41 +0100901 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
902 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
903 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
904 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
905
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200906 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
907 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
908
Jiang Zhe5218c892008-01-17 11:18:41 +0100909 {}
910};
911
Jiang zhe2de3c232008-03-06 11:09:09 +0100912static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100913 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
914 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
915 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
916 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
917 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
918 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
919 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
920 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
921 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
922 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
923 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
924 {
925 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
926 .name = "Master Playback Switch",
927 .info = cxt_eapd_info,
928 .get = cxt_eapd_get,
929 .put = cxt5045_hp_master_sw_put,
930 .private_value = 0x10,
931 },
932
933 {}
934};
935
Tobin Davisc9b443d2006-11-14 12:13:39 +0100936static struct hda_verb cxt5045_init_verbs[] = {
937 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200938 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100939 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100940 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200941 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
942 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
943 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
944 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
945 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
946 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
947 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
948 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100950 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100951 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100952 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100953 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
954 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100955 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100956 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100957 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100958 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100959 { } /* end */
960};
961
Jiang Zhe5218c892008-01-17 11:18:41 +0100962static struct hda_verb cxt5045_benq_init_verbs[] = {
963 /* Int Mic, Mic */
964 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
965 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
966 /* Line In,HP, Amp */
967 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
968 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
969 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
970 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
971 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
972 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
973 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
974 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
976 /* Record selector: Int mic */
977 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
978 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
979 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
980 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100981 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100982 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
983 /* EAPD */
984 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
985 { } /* end */
986};
Tobin Davis7f296732007-03-12 11:39:01 +0100987
988static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
989 /* pin sensing on HP jack */
990 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200991 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100992};
993
994static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
995 /* pin sensing on HP jack */
996 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200997 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100998};
999
Tobin Davisc9b443d2006-11-14 12:13:39 +01001000#ifdef CONFIG_SND_DEBUG
1001/* Test configuration for debugging, modelled after the ALC260 test
1002 * configuration.
1003 */
1004static struct hda_input_mux cxt5045_test_capture_source = {
1005 .num_items = 5,
1006 .items = {
1007 { "MIXER", 0x0 },
1008 { "MIC1 pin", 0x1 },
1009 { "LINE1 pin", 0x2 },
1010 { "HP-OUT pin", 0x3 },
1011 { "CD pin", 0x4 },
1012 },
1013};
1014
1015static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1016
1017 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001018 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1019 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001020 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1021 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1022 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1023 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001024
1025 /* Modes for retasking pin widgets */
1026 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1027 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1028
Tobin Davis82f30042007-02-13 12:45:44 +01001029 /* EAPD Switch Control */
1030 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1031
Tobin Davisc9b443d2006-11-14 12:13:39 +01001032 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001033
Tobin Davis7f296732007-03-12 11:39:01 +01001034 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1035 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1036 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1037 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1038 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1039 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1040 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1041 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1042 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1043 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001044 {
1045 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1046 .name = "Input Source",
1047 .info = conexant_mux_enum_info,
1048 .get = conexant_mux_enum_get,
1049 .put = conexant_mux_enum_put,
1050 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001051 /* Audio input controls */
1052 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1053 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1054 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1055 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1056 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1057 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1058 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1059 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1060 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1061 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001062 { } /* end */
1063};
1064
1065static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001066 /* Set connections */
1067 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1068 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1069 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001070 /* Enable retasking pins as output, initially without power amp */
1071 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001072 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073
1074 /* Disable digital (SPDIF) pins initially, but users can enable
1075 * them via a mixer switch. In the case of SPDIF-out, this initverb
1076 * payload also sets the generation to 0, output to be in "consumer"
1077 * PCM format, copyright asserted, no pre-emphasis and no validity
1078 * control.
1079 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001080 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1081 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001082
1083 /* Start with output sum widgets muted and their output gains at min */
1084 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1085 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1086
1087 /* Unmute retasking pin widget output buffers since the default
1088 * state appears to be output. As the pin mode is changed by the
1089 * user the pin mode control will take care of enabling the pin's
1090 * input/output buffers as needed.
1091 */
1092 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1093 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1094
1095 /* Mute capture amp left and right */
1096 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1097
1098 /* Set ADC connection select to match default mixer setting (mic1
1099 * pin)
1100 */
1101 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001102 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001103
1104 /* Mute all inputs to mixer widget (even unconnected ones) */
1105 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1106 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1107 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1108 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1109 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1110
1111 { }
1112};
1113#endif
1114
1115
1116/* initialize jack-sensing, too */
1117static int cxt5045_init(struct hda_codec *codec)
1118{
1119 conexant_init(codec);
1120 cxt5045_hp_automute(codec);
1121 return 0;
1122}
1123
1124
1125enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001126 CXT5045_LAPTOP_HPSENSE,
1127 CXT5045_LAPTOP_MICSENSE,
1128 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001129 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001130 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131#ifdef CONFIG_SND_DEBUG
1132 CXT5045_TEST,
1133#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001134 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135};
1136
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001137static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001138 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1139 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1140 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1141 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001142 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001143#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001144 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001145#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001146};
1147
1148static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001149 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001150 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1151 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001152 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001153 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001154 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1155 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001156 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1157 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001158 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1159 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1160 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001161 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1162 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001163 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001164 {}
1165};
1166
1167static int patch_cxt5045(struct hda_codec *codec)
1168{
1169 struct conexant_spec *spec;
1170 int board_config;
1171
1172 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1173 if (!spec)
1174 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001175 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001176 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001177
1178 spec->multiout.max_channels = 2;
1179 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1180 spec->multiout.dac_nids = cxt5045_dac_nids;
1181 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1182 spec->num_adc_nids = 1;
1183 spec->adc_nids = cxt5045_adc_nids;
1184 spec->capsrc_nids = cxt5045_capsrc_nids;
1185 spec->input_mux = &cxt5045_capture_source;
1186 spec->num_mixers = 1;
1187 spec->mixers[0] = cxt5045_mixers;
1188 spec->num_init_verbs = 1;
1189 spec->init_verbs[0] = cxt5045_init_verbs;
1190 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001191 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1192 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001193
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001194 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001195
1196 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001198 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1199 cxt5045_models,
1200 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001202 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001203 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001204 spec->input_mux = &cxt5045_capture_source;
1205 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001206 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1207 spec->mixers[0] = cxt5045_mixers;
1208 codec->patch_ops.init = cxt5045_init;
1209 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001210 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001211 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001212 spec->input_mux = &cxt5045_capture_source;
1213 spec->num_init_verbs = 2;
1214 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001215 spec->mixers[0] = cxt5045_mixers;
1216 codec->patch_ops.init = cxt5045_init;
1217 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001218 default:
1219 case CXT5045_LAPTOP_HPMICSENSE:
1220 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1221 spec->input_mux = &cxt5045_capture_source;
1222 spec->num_init_verbs = 3;
1223 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1224 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1225 spec->mixers[0] = cxt5045_mixers;
1226 codec->patch_ops.init = cxt5045_init;
1227 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001228 case CXT5045_BENQ:
1229 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1230 spec->input_mux = &cxt5045_capture_source_benq;
1231 spec->num_init_verbs = 1;
1232 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1233 spec->mixers[0] = cxt5045_mixers;
1234 spec->mixers[1] = cxt5045_benq_mixers;
1235 spec->num_mixers = 2;
1236 codec->patch_ops.init = cxt5045_init;
1237 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001238 case CXT5045_LAPTOP_HP530:
1239 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1240 spec->input_mux = &cxt5045_capture_source_hp530;
1241 spec->num_init_verbs = 2;
1242 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1243 spec->mixers[0] = cxt5045_mixers_hp530;
1244 codec->patch_ops.init = cxt5045_init;
1245 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001246#ifdef CONFIG_SND_DEBUG
1247 case CXT5045_TEST:
1248 spec->input_mux = &cxt5045_test_capture_source;
1249 spec->mixers[0] = cxt5045_test_mixer;
1250 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001251 break;
1252
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253#endif
1254 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001255
Takashi Iwai031005f2008-06-26 14:49:58 +02001256 switch (codec->subsystem_id >> 16) {
1257 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001258 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001259 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001260 case 0x17aa:
1261 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1262 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1263 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001264 */
1265 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1266 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1267 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1268 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1269 (1 << AC_AMPCAP_MUTE_SHIFT));
1270 break;
1271 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001272
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001273 if (spec->beep_amp)
1274 snd_hda_attach_beep_device(codec, spec->beep_amp);
1275
Tobin Davisc9b443d2006-11-14 12:13:39 +01001276 return 0;
1277}
1278
1279
1280/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001281#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001283static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001284static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1285static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286
Tobin Davis5cd57522006-11-20 17:42:09 +01001287static struct hda_channel_mode cxt5047_modes[1] = {
1288 { 2, NULL },
1289};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001290
Tobin Davis82f30042007-02-13 12:45:44 +01001291static struct hda_input_mux cxt5047_toshiba_capture_source = {
1292 .num_items = 2,
1293 .items = {
1294 { "ExtMic", 0x2 },
1295 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001296 }
1297};
1298
1299/* turn on/off EAPD (+ mute HP) as a master switch */
1300static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1301 struct snd_ctl_elem_value *ucontrol)
1302{
1303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1304 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001305 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001306
Tobin Davis82f30042007-02-13 12:45:44 +01001307 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001308 return 0;
1309
Tobin Davis82f30042007-02-13 12:45:44 +01001310 /* toggle internal speakers mute depending of presence of
1311 * the headphone jack
1312 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001313 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001314 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1315 * pin widgets unlike other codecs. In this case, we need to
1316 * set index 0x01 for the volume from the mixer amp 0x19.
1317 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001318 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001319 HDA_AMP_MUTE, bits);
1320 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1321 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1322 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001323 return 1;
1324}
1325
Tobin Davisc9b443d2006-11-14 12:13:39 +01001326/* mute internal speaker if HP is plugged */
1327static void cxt5047_hp_automute(struct hda_codec *codec)
1328{
Tobin Davis82f30042007-02-13 12:45:44 +01001329 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001330 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001331
Takashi Iwaid56757a2009-11-18 08:00:14 +01001332 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001333
Takashi Iwai47fd8302007-08-10 17:11:07 +02001334 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001335 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001336 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001337 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001338}
1339
1340/* toggle input of built-in and mic jack appropriately */
1341static void cxt5047_hp_automic(struct hda_codec *codec)
1342{
1343 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001344 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1345 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 {}
1347 };
1348 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001349 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1350 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001351 {}
1352 };
1353 unsigned int present;
1354
Takashi Iwaid56757a2009-11-18 08:00:14 +01001355 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001356 if (present)
1357 snd_hda_sequence_write(codec, mic_jack_on);
1358 else
1359 snd_hda_sequence_write(codec, mic_jack_off);
1360}
1361
1362/* unsolicited event for HP jack sensing */
1363static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1364 unsigned int res)
1365{
Marc Boucher9f113e02008-01-22 15:18:08 +01001366 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 case CONEXANT_HP_EVENT:
1368 cxt5047_hp_automute(codec);
1369 break;
1370 case CONEXANT_MIC_EVENT:
1371 cxt5047_hp_automic(codec);
1372 break;
1373 }
1374}
1375
Takashi Iwaidf481e42009-03-10 15:35:35 +01001376static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1377 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1378 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1379 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001380 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1381 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1382 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1383 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001384 {
1385 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1386 .name = "Master Playback Switch",
1387 .info = cxt_eapd_info,
1388 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001389 .put = cxt5047_hp_master_sw_put,
1390 .private_value = 0x13,
1391 },
1392
1393 {}
1394};
1395
Takashi Iwaidf481e42009-03-10 15:35:35 +01001396static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001397 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001398 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001399 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1400 {}
1401};
1402
1403static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001404 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405 { } /* end */
1406};
1407
1408static struct hda_verb cxt5047_init_verbs[] = {
1409 /* Line in, Mic, Built-in Mic */
1410 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1411 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1412 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001413 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001414 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001415 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1416 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001417 /* Record selector: Mic */
1418 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1419 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1420 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1421 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001422 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1423 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1424 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1425 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001426 /* SPDIF route: PCM */
1427 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001428 /* Enable unsolicited events */
1429 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1430 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001431 { } /* end */
1432};
1433
1434/* configuration for Toshiba Laptops */
1435static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001436 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001437 {}
1438};
1439
1440/* Test configuration for debugging, modelled after the ALC260 test
1441 * configuration.
1442 */
1443#ifdef CONFIG_SND_DEBUG
1444static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001445 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001446 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001447 { "LINE1 pin", 0x0 },
1448 { "MIC1 pin", 0x1 },
1449 { "MIC2 pin", 0x2 },
1450 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001451 },
1452};
1453
1454static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1455
1456 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001457 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1458 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1459 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1460 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001461 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1462 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1463 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1464 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001465 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1466 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1467 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1468 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001469
1470 /* Modes for retasking pin widgets */
1471 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1472 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1473
Tobin Davis82f30042007-02-13 12:45:44 +01001474 /* EAPD Switch Control */
1475 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1476
Tobin Davisc9b443d2006-11-14 12:13:39 +01001477 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001478 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1479 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1480 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1481 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1482 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1483 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1484 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1485 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001486
Tobin Davis82f30042007-02-13 12:45:44 +01001487 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1488 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1489 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1490 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1491 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1492 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1493 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1494 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001495 {
1496 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1497 .name = "Input Source",
1498 .info = conexant_mux_enum_info,
1499 .get = conexant_mux_enum_get,
1500 .put = conexant_mux_enum_put,
1501 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001502 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001503
Tobin Davisc9b443d2006-11-14 12:13:39 +01001504 { } /* end */
1505};
1506
1507static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001508 /* Enable retasking pins as output, initially without power amp */
1509 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1510 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1511 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1512
1513 /* Disable digital (SPDIF) pins initially, but users can enable
1514 * them via a mixer switch. In the case of SPDIF-out, this initverb
1515 * payload also sets the generation to 0, output to be in "consumer"
1516 * PCM format, copyright asserted, no pre-emphasis and no validity
1517 * control.
1518 */
1519 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1520
1521 /* Ensure mic1, mic2, line1 pin widgets take input from the
1522 * OUT1 sum bus when acting as an output.
1523 */
1524 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1525 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1526
1527 /* Start with output sum widgets muted and their output gains at min */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1530
1531 /* Unmute retasking pin widget output buffers since the default
1532 * state appears to be output. As the pin mode is changed by the
1533 * user the pin mode control will take care of enabling the pin's
1534 * input/output buffers as needed.
1535 */
1536 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1537 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1538 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1539
1540 /* Mute capture amp left and right */
1541 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1542
1543 /* Set ADC connection select to match default mixer setting (mic1
1544 * pin)
1545 */
1546 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1547
1548 /* Mute all inputs to mixer widget (even unconnected ones) */
1549 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1550 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1551 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1552 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1553 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1554 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1555 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1556 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1557
1558 { }
1559};
1560#endif
1561
1562
1563/* initialize jack-sensing, too */
1564static int cxt5047_hp_init(struct hda_codec *codec)
1565{
1566 conexant_init(codec);
1567 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001568 return 0;
1569}
1570
1571
1572enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001573 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1574 CXT5047_LAPTOP_HP, /* Some HP laptops */
1575 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576#ifdef CONFIG_SND_DEBUG
1577 CXT5047_TEST,
1578#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001579 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580};
1581
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001582static const char *cxt5047_models[CXT5047_MODELS] = {
1583 [CXT5047_LAPTOP] = "laptop",
1584 [CXT5047_LAPTOP_HP] = "laptop-hp",
1585 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001586#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001587 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001588#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001589};
1590
1591static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001592 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001593 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1594 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001595 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596 {}
1597};
1598
1599static int patch_cxt5047(struct hda_codec *codec)
1600{
1601 struct conexant_spec *spec;
1602 int board_config;
1603
1604 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1605 if (!spec)
1606 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001607 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001608 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001609
1610 spec->multiout.max_channels = 2;
1611 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1612 spec->multiout.dac_nids = cxt5047_dac_nids;
1613 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1614 spec->num_adc_nids = 1;
1615 spec->adc_nids = cxt5047_adc_nids;
1616 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001617 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001618 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001619 spec->num_init_verbs = 1;
1620 spec->init_verbs[0] = cxt5047_init_verbs;
1621 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001622 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1623 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001624
1625 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001626
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001627 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1628 cxt5047_models,
1629 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001630 switch (board_config) {
1631 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001632 spec->num_mixers = 2;
1633 spec->mixers[1] = cxt5047_hp_spk_mixers;
1634 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001635 break;
1636 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001637 spec->num_mixers = 2;
1638 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001639 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001640 codec->patch_ops.init = cxt5047_hp_init;
1641 break;
1642 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001643 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001644 spec->num_mixers = 2;
1645 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001646 spec->num_init_verbs = 2;
1647 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001648 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001649 break;
1650#ifdef CONFIG_SND_DEBUG
1651 case CXT5047_TEST:
1652 spec->input_mux = &cxt5047_test_capture_source;
1653 spec->mixers[0] = cxt5047_test_mixer;
1654 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001655 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001656#endif
1657 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001658 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001659
1660 switch (codec->subsystem_id >> 16) {
1661 case 0x103c:
1662 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1663 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1664 * with 0 dB offset 0x17)
1665 */
1666 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1667 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1668 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1669 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1670 (1 << AC_AMPCAP_MUTE_SHIFT));
1671 break;
1672 }
1673
Tobin Davisc9b443d2006-11-14 12:13:39 +01001674 return 0;
1675}
1676
Takashi Iwai461e2c72008-01-25 11:35:17 +01001677/* Conexant 5051 specific */
1678static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1679static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001680
1681static struct hda_channel_mode cxt5051_modes[1] = {
1682 { 2, NULL },
1683};
1684
1685static void cxt5051_update_speaker(struct hda_codec *codec)
1686{
1687 struct conexant_spec *spec = codec->spec;
1688 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001689 /* headphone pin */
1690 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1691 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1692 pinctl);
1693 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001694 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1695 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1696 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001697 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1698 if (spec->ideapad)
1699 snd_hda_codec_write(codec, 0x1b, 0,
1700 AC_VERB_SET_PIN_WIDGET_CONTROL,
1701 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001702}
1703
1704/* turn on/off EAPD (+ mute HP) as a master switch */
1705static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol)
1707{
1708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1709
1710 if (!cxt_eapd_put(kcontrol, ucontrol))
1711 return 0;
1712 cxt5051_update_speaker(codec);
1713 return 1;
1714}
1715
1716/* toggle input of built-in and mic jack appropriately */
1717static void cxt5051_portb_automic(struct hda_codec *codec)
1718{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001719 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001720 unsigned int present;
1721
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001722 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001723 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001724 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001725 snd_hda_codec_write(codec, 0x14, 0,
1726 AC_VERB_SET_CONNECT_SEL,
1727 present ? 0x01 : 0x00);
1728}
1729
1730/* switch the current ADC according to the jack state */
1731static void cxt5051_portc_automic(struct hda_codec *codec)
1732{
1733 struct conexant_spec *spec = codec->spec;
1734 unsigned int present;
1735 hda_nid_t new_adc;
1736
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001737 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001738 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001739 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001740 if (present)
1741 spec->cur_adc_idx = 1;
1742 else
1743 spec->cur_adc_idx = 0;
1744 new_adc = spec->adc_nids[spec->cur_adc_idx];
1745 if (spec->cur_adc && spec->cur_adc != new_adc) {
1746 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001747 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001748 spec->cur_adc = new_adc;
1749 snd_hda_codec_setup_stream(codec, new_adc,
1750 spec->cur_adc_stream_tag, 0,
1751 spec->cur_adc_format);
1752 }
1753}
1754
1755/* mute internal speaker if HP is plugged */
1756static void cxt5051_hp_automute(struct hda_codec *codec)
1757{
1758 struct conexant_spec *spec = codec->spec;
1759
Takashi Iwaid56757a2009-11-18 08:00:14 +01001760 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001761 cxt5051_update_speaker(codec);
1762}
1763
1764/* unsolicited event for HP jack sensing */
1765static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1766 unsigned int res)
1767{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001768 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001769 switch (res >> 26) {
1770 case CONEXANT_HP_EVENT:
1771 cxt5051_hp_automute(codec);
1772 break;
1773 case CXT5051_PORTB_EVENT:
1774 cxt5051_portb_automic(codec);
1775 break;
1776 case CXT5051_PORTC_EVENT:
1777 cxt5051_portc_automic(codec);
1778 break;
1779 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001780 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001781}
1782
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001783static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001784 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1785 {
1786 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1787 .name = "Master Playback Switch",
1788 .info = cxt_eapd_info,
1789 .get = cxt_eapd_get,
1790 .put = cxt5051_hp_master_sw_put,
1791 .private_value = 0x1a,
1792 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001793 {}
1794};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001795
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001796static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1797 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1798 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1799 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1800 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1801 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1802 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001803 {}
1804};
1805
1806static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1807 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1808 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1809 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1810 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001811 {}
1812};
1813
Takashi Iwai79d7d532009-03-04 09:03:50 +01001814static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001815 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1816 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001817 {}
1818};
1819
Ken Proxcd9d95a2010-01-08 09:01:47 +01001820static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001821 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1822 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001823 {}
1824};
1825
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001826static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1827 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1828 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1829 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1830 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001831 {}
1832};
1833
Takashi Iwai461e2c72008-01-25 11:35:17 +01001834static struct hda_verb cxt5051_init_verbs[] = {
1835 /* Line in, Mic */
1836 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1837 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1838 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1839 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1840 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1841 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1842 /* SPK */
1843 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1844 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1845 /* HP, Amp */
1846 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1847 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1848 /* DAC1 */
1849 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1850 /* Record selector: Int mic */
1851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1853 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1854 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001855 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001856 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1857 /* EAPD */
1858 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1859 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001860 { } /* end */
1861};
1862
Takashi Iwai79d7d532009-03-04 09:03:50 +01001863static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1864 /* Line in, Mic */
1865 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1866 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1867 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1868 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1869 /* SPK */
1870 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1871 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1872 /* HP, Amp */
1873 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1874 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1875 /* DAC1 */
1876 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1877 /* Record selector: Int mic */
1878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1879 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1880 /* SPDIF route: PCM */
1881 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1882 /* EAPD */
1883 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1884 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001885 { } /* end */
1886};
1887
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001888static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1889 /* Line in, Mic */
1890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1891 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1892 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1893 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1894 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1895 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1896 /* SPK */
1897 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1898 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1899 /* HP, Amp */
1900 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1901 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1902 /* Docking HP */
1903 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1904 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1905 /* DAC1 */
1906 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1907 /* Record selector: Int mic */
1908 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1910 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1911 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001912 {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 -05001913 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1914 /* EAPD */
1915 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1916 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001917 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1918 { } /* end */
1919};
1920
Ken Proxcd9d95a2010-01-08 09:01:47 +01001921static struct hda_verb cxt5051_f700_init_verbs[] = {
1922 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001923 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001924 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1925 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1926 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1927 /* SPK */
1928 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1929 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1930 /* HP, Amp */
1931 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1932 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1933 /* DAC1 */
1934 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1935 /* Record selector: Int mic */
1936 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1937 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1938 /* SPDIF route: PCM */
1939 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1940 /* EAPD */
1941 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1942 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001943 { } /* end */
1944};
1945
Takashi Iwai6953e552010-01-24 11:00:27 +01001946static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1947 unsigned int event)
1948{
1949 snd_hda_codec_write(codec, nid, 0,
1950 AC_VERB_SET_UNSOLICITED_ENABLE,
1951 AC_USRSP_EN | event);
1952#ifdef CONFIG_SND_HDA_INPUT_JACK
1953 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1954 conexant_report_jack(codec, nid);
1955#endif
1956}
1957
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001958static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1959 /* Subwoofer */
1960 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1961 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1962 { } /* end */
1963};
1964
Takashi Iwai461e2c72008-01-25 11:35:17 +01001965/* initialize jack-sensing, too */
1966static int cxt5051_init(struct hda_codec *codec)
1967{
Takashi Iwai6953e552010-01-24 11:00:27 +01001968 struct conexant_spec *spec = codec->spec;
1969
Takashi Iwai461e2c72008-01-25 11:35:17 +01001970 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001971 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001972
1973 if (spec->auto_mic & AUTO_MIC_PORTB)
1974 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1975 if (spec->auto_mic & AUTO_MIC_PORTC)
1976 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1977
Takashi Iwai461e2c72008-01-25 11:35:17 +01001978 if (codec->patch_ops.unsol_event) {
1979 cxt5051_hp_automute(codec);
1980 cxt5051_portb_automic(codec);
1981 cxt5051_portc_automic(codec);
1982 }
1983 return 0;
1984}
1985
1986
1987enum {
1988 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1989 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001990 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001991 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001992 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001993 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001994 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001995 CXT5051_MODELS
1996};
1997
1998static const char *cxt5051_models[CXT5051_MODELS] = {
1999 [CXT5051_LAPTOP] = "laptop",
2000 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01002001 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002002 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002003 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002004 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002005 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai461e2c72008-01-25 11:35:17 +01002006};
2007
2008static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01002009 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01002010 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002011 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002012 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002013 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2014 CXT5051_LAPTOP),
2015 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002016 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002017 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002018 {}
2019};
2020
2021static int patch_cxt5051(struct hda_codec *codec)
2022{
2023 struct conexant_spec *spec;
2024 int board_config;
2025
2026 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2027 if (!spec)
2028 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002029 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002030 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002031
2032 codec->patch_ops = conexant_patch_ops;
2033 codec->patch_ops.init = cxt5051_init;
2034
2035 spec->multiout.max_channels = 2;
2036 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2037 spec->multiout.dac_nids = cxt5051_dac_nids;
2038 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2039 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2040 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002041 spec->num_mixers = 2;
2042 spec->mixers[0] = cxt5051_capture_mixers;
2043 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002044 spec->num_init_verbs = 1;
2045 spec->init_verbs[0] = cxt5051_init_verbs;
2046 spec->spdif_route = 0;
2047 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2048 spec->channel_mode = cxt5051_modes;
2049 spec->cur_adc = 0;
2050 spec->cur_adc_idx = 0;
2051
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002052 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2053
Takashi Iwai79d7d532009-03-04 09:03:50 +01002054 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2055
Takashi Iwai461e2c72008-01-25 11:35:17 +01002056 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2057 cxt5051_models,
2058 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002059 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002060 switch (board_config) {
2061 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002062 spec->mixers[0] = cxt5051_hp_mixers;
2063 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002064 case CXT5051_HP_DV6736:
2065 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2066 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002067 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002068 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002069 case CXT5051_LENOVO_X200:
2070 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002071 /* Thinkpad X301 does not have S/PDIF wired and no ability
2072 to use a docking station. */
2073 if (codec->subsystem_id == 0x17aa211f)
2074 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002075 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002076 case CXT5051_F700:
2077 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2078 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002079 spec->auto_mic = 0;
2080 break;
2081 case CXT5051_TOSHIBA:
2082 spec->mixers[0] = cxt5051_toshiba_mixers;
2083 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002084 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002085 case CXT5051_IDEAPAD:
2086 spec->init_verbs[spec->num_init_verbs++] =
2087 cxt5051_ideapad_init_verbs;
2088 spec->ideapad = 1;
2089 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002090 }
2091
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002092 if (spec->beep_amp)
2093 snd_hda_attach_beep_device(codec, spec->beep_amp);
2094
Takashi Iwai461e2c72008-01-25 11:35:17 +01002095 return 0;
2096}
2097
Daniel Drake0fb67e92009-07-16 14:46:57 +01002098/* Conexant 5066 specific */
2099
2100static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2101static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2102static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2103#define CXT5066_SPDIF_OUT 0x21
2104
Daniel Drakedbaccc02009-11-09 15:17:24 +00002105/* OLPC's microphone port is DC coupled for use with external sensors,
2106 * therefore we use a 50% mic bias in order to center the input signal with
2107 * the DC input range of the codec. */
2108#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2109
Daniel Drake0fb67e92009-07-16 14:46:57 +01002110static struct hda_channel_mode cxt5066_modes[1] = {
2111 { 2, NULL },
2112};
2113
2114static void cxt5066_update_speaker(struct hda_codec *codec)
2115{
2116 struct conexant_spec *spec = codec->spec;
2117 unsigned int pinctl;
2118
John Baboval3a253442010-12-02 11:21:31 -05002119 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2120 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002121
2122 /* Port A (HP) */
2123 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2124 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2125 pinctl);
2126
2127 /* Port D (HP/LO) */
John Baboval3a253442010-12-02 11:21:31 -05002128 if (spec->dell_automute) {
2129 /* DELL AIO Port Rule: PortA> PortD> IntSpk */
2130 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2131 ? PIN_OUT : 0;
2132 } else if (spec->thinkpad) {
2133 if (spec->cur_eapd)
2134 pinctl = spec->port_d_mode;
2135 /* Mute dock line-out if Port A (laptop HP) is present */
2136 if (spec->hp_present& 1)
2137 pinctl = 0;
2138 } else {
2139 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2140 ? spec->port_d_mode : 0;
2141 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002142 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2143 pinctl);
2144
2145 /* CLASS_D AMP */
2146 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2147 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2148 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002149}
2150
2151/* turn on/off EAPD (+ mute HP) as a master switch */
2152static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2153 struct snd_ctl_elem_value *ucontrol)
2154{
2155 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2156
2157 if (!cxt_eapd_put(kcontrol, ucontrol))
2158 return 0;
2159
2160 cxt5066_update_speaker(codec);
2161 return 1;
2162}
2163
Daniel Drakec4cfe662010-01-07 13:47:04 +01002164static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2165 .num_items = 3,
2166 .items = {
2167 { "Off", PIN_IN },
2168 { "50%", PIN_VREF50 },
2169 { "80%", PIN_VREF80 },
2170 },
2171};
2172
2173static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2174{
2175 struct conexant_spec *spec = codec->spec;
2176 /* Even though port F is the DC input, the bias is controlled on port B.
2177 * we also leave that port as an active input (but unselected) in DC mode
2178 * just in case that is necessary to make the bias setting take effect. */
2179 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2180 AC_VERB_SET_PIN_WIDGET_CONTROL,
2181 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2182}
2183
Daniel Drake75f89912010-01-07 13:46:25 +01002184/* OLPC defers mic widget control until when capture is started because the
2185 * microphone LED comes on as soon as these settings are put in place. if we
2186 * did this before recording, it would give the false indication that recording
2187 * is happening when it is not. */
2188static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002189{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002190 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002191 if (!spec->recording)
2192 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002193
Daniel Drakec4cfe662010-01-07 13:47:04 +01002194 if (spec->dc_enable) {
2195 /* in DC mode we ignore presence detection and just use the jack
2196 * through our special DC port */
2197 const struct hda_verb enable_dc_mode[] = {
2198 /* disble internal mic, port C */
2199 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2200
2201 /* enable DC capture, port F */
2202 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2203 {},
2204 };
2205
2206 snd_hda_sequence_write(codec, enable_dc_mode);
2207 /* port B input disabled (and bias set) through the following call */
2208 cxt5066_set_olpc_dc_bias(codec);
2209 return;
2210 }
2211
2212 /* disable DC (port F) */
2213 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2214
Daniel Drake75f89912010-01-07 13:46:25 +01002215 /* external mic, port B */
2216 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2217 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002218
Daniel Drake75f89912010-01-07 13:46:25 +01002219 /* internal mic, port C */
2220 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2221 spec->ext_mic_present ? 0 : PIN_VREF80);
2222}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002223
Daniel Drake75f89912010-01-07 13:46:25 +01002224/* toggle input of built-in and mic jack appropriately */
2225static void cxt5066_olpc_automic(struct hda_codec *codec)
2226{
2227 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002228 unsigned int present;
2229
Daniel Drakec4cfe662010-01-07 13:47:04 +01002230 if (spec->dc_enable) /* don't do presence detection in DC mode */
2231 return;
2232
Daniel Drake75f89912010-01-07 13:46:25 +01002233 present = snd_hda_codec_read(codec, 0x1a, 0,
2234 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2235 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002236 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002237 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002238 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002239
2240 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2241 present ? 0 : 1);
2242 spec->ext_mic_present = !!present;
2243
2244 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002245}
2246
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002247/* toggle input of built-in digital mic and mic jack appropriately */
2248static void cxt5066_vostro_automic(struct hda_codec *codec)
2249{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002250 unsigned int present;
2251
2252 struct hda_verb ext_mic_present[] = {
2253 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002254 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002255
2256 /* switch to external mic input */
2257 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2258 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2259
2260 /* disable internal digital mic */
2261 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2262 {}
2263 };
2264 static struct hda_verb ext_mic_absent[] = {
2265 /* enable internal mic, port C */
2266 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2267
2268 /* switch to internal mic input */
2269 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2270
2271 /* disable external mic, port B */
2272 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2273 {}
2274 };
2275
2276 present = snd_hda_jack_detect(codec, 0x1a);
2277 if (present) {
2278 snd_printdd("CXT5066: external microphone detected\n");
2279 snd_hda_sequence_write(codec, ext_mic_present);
2280 } else {
2281 snd_printdd("CXT5066: external microphone absent\n");
2282 snd_hda_sequence_write(codec, ext_mic_absent);
2283 }
2284}
2285
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002286/* toggle input of built-in digital mic and mic jack appropriately */
2287static void cxt5066_ideapad_automic(struct hda_codec *codec)
2288{
2289 unsigned int present;
2290
2291 struct hda_verb ext_mic_present[] = {
2292 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2293 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2294 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2295 {}
2296 };
2297 static struct hda_verb ext_mic_absent[] = {
2298 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2299 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2300 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2301 {}
2302 };
2303
2304 present = snd_hda_jack_detect(codec, 0x1b);
2305 if (present) {
2306 snd_printdd("CXT5066: external microphone detected\n");
2307 snd_hda_sequence_write(codec, ext_mic_present);
2308 } else {
2309 snd_printdd("CXT5066: external microphone absent\n");
2310 snd_hda_sequence_write(codec, ext_mic_absent);
2311 }
2312}
2313
David Henningsson048e78a2010-09-02 08:35:47 +02002314/* toggle input of built-in digital mic and mic jack appropriately */
2315static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2316{
2317 unsigned int present;
2318
2319 present = snd_hda_jack_detect(codec, 0x1b);
2320 snd_printdd("CXT5066: external microphone present=%d\n", present);
2321 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2322 present ? 1 : 3);
2323}
2324
2325
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002326/* toggle input of built-in digital mic and mic jack appropriately
2327 order is: external mic -> dock mic -> interal mic */
2328static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2329{
2330 unsigned int ext_present, dock_present;
2331
2332 static struct hda_verb ext_mic_present[] = {
2333 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2334 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2335 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2336 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2337 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2338 {}
2339 };
2340 static struct hda_verb dock_mic_present[] = {
2341 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2342 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2343 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2344 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2345 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2346 {}
2347 };
2348 static struct hda_verb ext_mic_absent[] = {
2349 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2350 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2351 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2352 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2353 {}
2354 };
2355
2356 ext_present = snd_hda_jack_detect(codec, 0x1b);
2357 dock_present = snd_hda_jack_detect(codec, 0x1a);
2358 if (ext_present) {
2359 snd_printdd("CXT5066: external microphone detected\n");
2360 snd_hda_sequence_write(codec, ext_mic_present);
2361 } else if (dock_present) {
2362 snd_printdd("CXT5066: dock microphone detected\n");
2363 snd_hda_sequence_write(codec, dock_mic_present);
2364 } else {
2365 snd_printdd("CXT5066: external microphone absent\n");
2366 snd_hda_sequence_write(codec, ext_mic_absent);
2367 }
2368}
2369
Daniel Drake0fb67e92009-07-16 14:46:57 +01002370/* mute internal speaker if HP is plugged */
2371static void cxt5066_hp_automute(struct hda_codec *codec)
2372{
2373 struct conexant_spec *spec = codec->spec;
2374 unsigned int portA, portD;
2375
2376 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002377 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002378
2379 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002380 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002381
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002382 spec->hp_present = !!(portA);
2383 spec->hp_present |= portD ? 2 : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002384 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2385 portA, portD, spec->hp_present);
2386 cxt5066_update_speaker(codec);
2387}
2388
2389/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002390static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002391{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002392 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002393 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2394 switch (res >> 26) {
2395 case CONEXANT_HP_EVENT:
2396 cxt5066_hp_automute(codec);
2397 break;
2398 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002399 /* ignore mic events in DC mode; we're always using the jack */
2400 if (!spec->dc_enable)
2401 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002402 break;
2403 }
2404}
2405
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002406/* unsolicited event for jack sensing */
2407static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2408{
2409 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2410 switch (res >> 26) {
2411 case CONEXANT_HP_EVENT:
2412 cxt5066_hp_automute(codec);
2413 break;
2414 case CONEXANT_MIC_EVENT:
2415 cxt5066_vostro_automic(codec);
2416 break;
2417 }
2418}
2419
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002420/* unsolicited event for jack sensing */
2421static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2422{
2423 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2424 switch (res >> 26) {
2425 case CONEXANT_HP_EVENT:
2426 cxt5066_hp_automute(codec);
2427 break;
2428 case CONEXANT_MIC_EVENT:
2429 cxt5066_ideapad_automic(codec);
2430 break;
2431 }
2432}
2433
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002434/* unsolicited event for jack sensing */
David Henningsson048e78a2010-09-02 08:35:47 +02002435static void cxt5066_hp_laptop_event(struct hda_codec *codec, unsigned int res)
2436{
2437 snd_printdd("CXT5066_hp_laptop: unsol event %x (%x)\n", res, res >> 26);
2438 switch (res >> 26) {
2439 case CONEXANT_HP_EVENT:
2440 cxt5066_hp_automute(codec);
2441 break;
2442 case CONEXANT_MIC_EVENT:
2443 cxt5066_hp_laptop_automic(codec);
2444 break;
2445 }
2446}
2447
2448/* unsolicited event for jack sensing */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002449static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
2450{
2451 snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
2452 switch (res >> 26) {
2453 case CONEXANT_HP_EVENT:
2454 cxt5066_hp_automute(codec);
2455 break;
2456 case CONEXANT_MIC_EVENT:
2457 cxt5066_thinkpad_automic(codec);
2458 break;
2459 }
2460}
2461
Daniel Drake0fb67e92009-07-16 14:46:57 +01002462static const struct hda_input_mux cxt5066_analog_mic_boost = {
2463 .num_items = 5,
2464 .items = {
2465 { "0dB", 0 },
2466 { "10dB", 1 },
2467 { "20dB", 2 },
2468 { "30dB", 3 },
2469 { "40dB", 4 },
2470 },
2471};
2472
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002473static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002474{
2475 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002476 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002477 AC_VERB_SET_AMP_GAIN_MUTE,
2478 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2479 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002480 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002481 /* adjust the internal mic as well...it is not through 0x17 */
2482 snd_hda_codec_write_cache(codec, 0x23, 0,
2483 AC_VERB_SET_AMP_GAIN_MUTE,
2484 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2485 cxt5066_analog_mic_boost.
2486 items[spec->mic_boost].index);
2487 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002488}
2489
Daniel Drake0fb67e92009-07-16 14:46:57 +01002490static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2491 struct snd_ctl_elem_info *uinfo)
2492{
2493 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2494}
2495
2496static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2497 struct snd_ctl_elem_value *ucontrol)
2498{
2499 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002500 struct conexant_spec *spec = codec->spec;
2501 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002502 return 0;
2503}
2504
2505static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2506 struct snd_ctl_elem_value *ucontrol)
2507{
2508 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002509 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002510 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2511 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002512 idx = ucontrol->value.enumerated.item[0];
2513 if (idx >= imux->num_items)
2514 idx = imux->num_items - 1;
2515
Daniel Drakec4cfe662010-01-07 13:47:04 +01002516 spec->mic_boost = idx;
2517 if (!spec->dc_enable)
2518 cxt5066_set_mic_boost(codec);
2519 return 1;
2520}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002521
Daniel Drakec4cfe662010-01-07 13:47:04 +01002522static void cxt5066_enable_dc(struct hda_codec *codec)
2523{
2524 const struct hda_verb enable_dc_mode[] = {
2525 /* disable gain */
2526 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2527
2528 /* switch to DC input */
2529 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2530 {}
2531 };
2532
2533 /* configure as input source */
2534 snd_hda_sequence_write(codec, enable_dc_mode);
2535 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2536}
2537
2538static void cxt5066_disable_dc(struct hda_codec *codec)
2539{
2540 /* reconfigure input source */
2541 cxt5066_set_mic_boost(codec);
2542 /* automic also selects the right mic if we're recording */
2543 cxt5066_olpc_automic(codec);
2544}
2545
2546static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2547 struct snd_ctl_elem_value *ucontrol)
2548{
2549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550 struct conexant_spec *spec = codec->spec;
2551 ucontrol->value.integer.value[0] = spec->dc_enable;
2552 return 0;
2553}
2554
2555static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2556 struct snd_ctl_elem_value *ucontrol)
2557{
2558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2559 struct conexant_spec *spec = codec->spec;
2560 int dc_enable = !!ucontrol->value.integer.value[0];
2561
2562 if (dc_enable == spec->dc_enable)
2563 return 0;
2564
2565 spec->dc_enable = dc_enable;
2566 if (dc_enable)
2567 cxt5066_enable_dc(codec);
2568 else
2569 cxt5066_disable_dc(codec);
2570
2571 return 1;
2572}
2573
2574static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2575 struct snd_ctl_elem_info *uinfo)
2576{
2577 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2578}
2579
2580static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2581 struct snd_ctl_elem_value *ucontrol)
2582{
2583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2584 struct conexant_spec *spec = codec->spec;
2585 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2586 return 0;
2587}
2588
2589static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2590 struct snd_ctl_elem_value *ucontrol)
2591{
2592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2593 struct conexant_spec *spec = codec->spec;
2594 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2595 unsigned int idx;
2596
2597 idx = ucontrol->value.enumerated.item[0];
2598 if (idx >= imux->num_items)
2599 idx = imux->num_items - 1;
2600
2601 spec->dc_input_bias = idx;
2602 if (spec->dc_enable)
2603 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002604 return 1;
2605}
2606
Daniel Drake75f89912010-01-07 13:46:25 +01002607static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2608{
2609 struct conexant_spec *spec = codec->spec;
2610 /* mark as recording and configure the microphone widget so that the
2611 * recording LED comes on. */
2612 spec->recording = 1;
2613 cxt5066_olpc_select_mic(codec);
2614}
2615
2616static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2617{
2618 struct conexant_spec *spec = codec->spec;
2619 const struct hda_verb disable_mics[] = {
2620 /* disable external mic, port B */
2621 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2622
2623 /* disble internal mic, port C */
2624 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002625
2626 /* disable DC capture, port F */
2627 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002628 {},
2629 };
2630
2631 snd_hda_sequence_write(codec, disable_mics);
2632 spec->recording = 0;
2633}
2634
Daniel Drake0fb67e92009-07-16 14:46:57 +01002635static struct hda_input_mux cxt5066_capture_source = {
2636 .num_items = 4,
2637 .items = {
2638 { "Mic B", 0 },
2639 { "Mic C", 1 },
2640 { "Mic E", 2 },
2641 { "Mic F", 3 },
2642 },
2643};
2644
2645static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2646 .ops = &snd_hda_bind_vol,
2647 .values = {
2648 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2649 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2650 0
2651 },
2652};
2653
2654static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2655 .ops = &snd_hda_bind_sw,
2656 .values = {
2657 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2658 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2659 0
2660 },
2661};
2662
2663static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2664 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2665 {}
2666};
2667
2668static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2669 {
2670 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2671 .name = "Master Playback Volume",
2672 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2673 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2674 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002675 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002676 .info = snd_hda_mixer_amp_volume_info,
2677 .get = snd_hda_mixer_amp_volume_get,
2678 .put = snd_hda_mixer_amp_volume_put,
2679 .tlv = { .c = snd_hda_mixer_amp_tlv },
2680 /* offset by 28 volume steps to limit minimum gain to -46dB */
2681 .private_value =
2682 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2683 },
2684 {}
2685};
2686
Daniel Drakec4cfe662010-01-07 13:47:04 +01002687static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2688 {
2689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2690 .name = "DC Mode Enable Switch",
2691 .info = snd_ctl_boolean_mono_info,
2692 .get = cxt5066_olpc_dc_get,
2693 .put = cxt5066_olpc_dc_put,
2694 },
2695 {
2696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2697 .name = "DC Input Bias Enum",
2698 .info = cxt5066_olpc_dc_bias_enum_info,
2699 .get = cxt5066_olpc_dc_bias_enum_get,
2700 .put = cxt5066_olpc_dc_bias_enum_put,
2701 },
2702 {}
2703};
2704
Daniel Drake0fb67e92009-07-16 14:46:57 +01002705static struct snd_kcontrol_new cxt5066_mixers[] = {
2706 {
2707 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2708 .name = "Master Playback Switch",
2709 .info = cxt_eapd_info,
2710 .get = cxt_eapd_get,
2711 .put = cxt5066_hp_master_sw_put,
2712 .private_value = 0x1d,
2713 },
2714
2715 {
2716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002717 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002718 .info = cxt5066_mic_boost_mux_enum_info,
2719 .get = cxt5066_mic_boost_mux_enum_get,
2720 .put = cxt5066_mic_boost_mux_enum_put,
2721 },
2722
2723 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2724 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2725 {}
2726};
2727
Einar Rünkaru254bba62009-12-16 22:16:13 +02002728static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2729 {
2730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2731 .name = "Int Mic Boost Capture Enum",
2732 .info = cxt5066_mic_boost_mux_enum_info,
2733 .get = cxt5066_mic_boost_mux_enum_get,
2734 .put = cxt5066_mic_boost_mux_enum_put,
2735 .private_value = 0x23 | 0x100,
2736 },
2737 {}
2738};
2739
Daniel Drake0fb67e92009-07-16 14:46:57 +01002740static struct hda_verb cxt5066_init_verbs[] = {
2741 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2742 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2743 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2744 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2745
2746 /* Speakers */
2747 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2748 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2749
2750 /* HP, Amp */
2751 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2752 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2753
2754 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2755 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2756
2757 /* DAC1 */
2758 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2759
2760 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2762 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2763 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2764 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2765 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2766
2767 /* no digital microphone support yet */
2768 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2769
2770 /* Audio input selector */
2771 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2772
2773 /* SPDIF route: PCM */
2774 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2775 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2776
2777 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2778 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2779
2780 /* EAPD */
2781 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2782
2783 /* not handling these yet */
2784 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2785 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2786 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2787 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2788 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2789 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2790 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2791 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2792 { } /* end */
2793};
2794
2795static struct hda_verb cxt5066_init_verbs_olpc[] = {
2796 /* Port A: headphones */
2797 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2798 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2799
2800 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002801 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002802
2803 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002804 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002805
2806 /* Port D: unused */
2807 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2808
2809 /* Port E: unused, but has primary EAPD */
2810 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2811 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2812
Daniel Drakec4cfe662010-01-07 13:47:04 +01002813 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002814 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815
2816 /* Port G: internal speakers */
2817 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2818 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2819
2820 /* DAC1 */
2821 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2822
2823 /* DAC2: unused */
2824 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2825
2826 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2827 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2828 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2829 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2830 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2831 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2832 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2833 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2834 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2835 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2836 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2837 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2838
2839 /* Disable digital microphone port */
2840 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2841
2842 /* Audio input selectors */
2843 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2844 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2845
2846 /* Disable SPDIF */
2847 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2848 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2849
2850 /* enable unsolicited events for Port A and B */
2851 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2852 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2853 { } /* end */
2854};
2855
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002856static struct hda_verb cxt5066_init_verbs_vostro[] = {
2857 /* Port A: headphones */
2858 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2859 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2860
2861 /* Port B: external microphone */
2862 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863
2864 /* Port C: unused */
2865 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2866
2867 /* Port D: unused */
2868 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2869
2870 /* Port E: unused, but has primary EAPD */
2871 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2872 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2873
2874 /* Port F: unused */
2875 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2876
2877 /* Port G: internal speakers */
2878 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2879 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2880
2881 /* DAC1 */
2882 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2883
2884 /* DAC2: unused */
2885 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2886
2887 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2888 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2889 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2890 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2891 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2892 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2893 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2894 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2895 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2896 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2897 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2898 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2899
2900 /* Digital microphone port */
2901 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2902
2903 /* Audio input selectors */
2904 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2905 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2906
2907 /* Disable SPDIF */
2908 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2909 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2910
2911 /* enable unsolicited events for Port A and B */
2912 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2913 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2914 { } /* end */
2915};
2916
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002917static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2918 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2919 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2920 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2921 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2922
2923 /* Speakers */
2924 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2925 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2926
2927 /* HP, Amp */
2928 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2929 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2930
2931 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2932 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2933
2934 /* DAC1 */
2935 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2936
2937 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2938 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2939 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2940 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2941 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2942 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2943 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2944
2945 /* Audio input selector */
2946 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2947 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2948
2949 /* SPDIF route: PCM */
2950 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2951 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2952
2953 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2954 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2955
2956 /* internal microphone */
2957 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2958
2959 /* EAPD */
2960 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2961
2962 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2963 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2964 { } /* end */
2965};
2966
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002967static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2968 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2969 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2970
2971 /* Port G: internal speakers */
2972 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2973 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2974
2975 /* Port A: HP, Amp */
2976 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2977 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2978
2979 /* Port B: Mic Dock */
2980 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2981
2982 /* Port C: Mic */
2983 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2984
2985 /* Port D: HP Dock, Amp */
2986 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2987 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2988
2989 /* DAC1 */
2990 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2991
2992 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2993 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2994 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2995 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2996 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2997 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2998 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2999
3000 /* Audio input selector */
3001 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
3002 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
3003
3004 /* SPDIF route: PCM */
3005 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
3006 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
3007
3008 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3009 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3010
3011 /* internal microphone */
3012 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
3013
3014 /* EAPD */
3015 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
3016
3017 /* enable unsolicited events for Port A, B, C and D */
3018 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3019 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3020 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3021 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3022 { } /* end */
3023};
3024
Daniel Drake0fb67e92009-07-16 14:46:57 +01003025static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
3026 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3027 { } /* end */
3028};
3029
David Henningsson048e78a2010-09-02 08:35:47 +02003030
3031static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3032 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3033 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3034 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3035 { } /* end */
3036};
3037
Daniel Drake0fb67e92009-07-16 14:46:57 +01003038/* initialize jack-sensing, too */
3039static int cxt5066_init(struct hda_codec *codec)
3040{
Einar Rünkaru254bba62009-12-16 22:16:13 +02003041 struct conexant_spec *spec = codec->spec;
3042
Daniel Drake0fb67e92009-07-16 14:46:57 +01003043 snd_printdd("CXT5066: init\n");
3044 conexant_init(codec);
3045 if (codec->patch_ops.unsol_event) {
3046 cxt5066_hp_automute(codec);
Einar Rünkaru254bba62009-12-16 22:16:13 +02003047 if (spec->dell_vostro)
3048 cxt5066_vostro_automic(codec);
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003049 else if (spec->ideapad)
3050 cxt5066_ideapad_automic(codec);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003051 else if (spec->thinkpad)
3052 cxt5066_thinkpad_automic(codec);
David Henningsson048e78a2010-09-02 08:35:47 +02003053 else if (spec->hp_laptop)
3054 cxt5066_hp_laptop_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003055 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003056 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003057 return 0;
3058}
3059
Daniel Drake75f89912010-01-07 13:46:25 +01003060static int cxt5066_olpc_init(struct hda_codec *codec)
3061{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003062 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003063 snd_printdd("CXT5066: init\n");
3064 conexant_init(codec);
3065 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003066 if (!spec->dc_enable) {
3067 cxt5066_set_mic_boost(codec);
3068 cxt5066_olpc_automic(codec);
3069 } else {
3070 cxt5066_enable_dc(codec);
3071 }
Daniel Drake75f89912010-01-07 13:46:25 +01003072 return 0;
3073}
3074
Daniel Drake0fb67e92009-07-16 14:46:57 +01003075enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003076 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003077 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3078 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003079 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003080 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003081 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningsson048e78a2010-09-02 08:35:47 +02003082 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003083 CXT5066_MODELS
3084};
3085
3086static const char *cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003087 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003088 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3089 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003090 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003091 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003092 [CXT5066_THINKPAD] = "thinkpad",
David Henningsson048e78a2010-09-02 08:35:47 +02003093 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003094};
3095
3096static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003097 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003098 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson5637edb2010-09-17 10:58:03 +02003099 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
3100 CXT5066_DELL_LAPTOP),
David Henningsson1feba3b2010-09-17 10:52:50 +02003101 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003102 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003103 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Daniel T Chen673f7a82010-11-21 14:01:14 -05003104 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_HP_LAPTOP),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003105 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003106 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003107 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003108 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3109 CXT5066_LAPTOP),
3110 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003111 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Andrej Gelenberg0217f142010-05-09 22:10:41 +02003112 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
Andreas Herrmannbadf18b2010-05-28 09:57:12 +02003113 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
Jerone Younga39e33e2010-05-26 10:06:01 -05003114 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
Manoj Iyer60272772010-11-23 07:43:44 +01003115 SND_PCI_QUIRK(0x17aa, 0x21c8, "Thinkpad Edge 11", CXT5066_IDEAPAD),
Jerone Youngab854572010-07-19 08:30:58 -05003116 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3117 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD),
Jerone Young6f0ef6e2010-08-23 08:34:36 +02003118 SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD),
Jerone Youngab854572010-07-19 08:30:58 -05003119 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD),
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003120 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003121 {}
3122};
3123
3124static int patch_cxt5066(struct hda_codec *codec)
3125{
3126 struct conexant_spec *spec;
3127 int board_config;
3128
3129 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3130 if (!spec)
3131 return -ENOMEM;
3132 codec->spec = spec;
3133
3134 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003135 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003136
3137 spec->dell_automute = 0;
3138 spec->multiout.max_channels = 2;
3139 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3140 spec->multiout.dac_nids = cxt5066_dac_nids;
3141 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
3142 spec->num_adc_nids = 1;
3143 spec->adc_nids = cxt5066_adc_nids;
3144 spec->capsrc_nids = cxt5066_capsrc_nids;
3145 spec->input_mux = &cxt5066_capture_source;
3146
3147 spec->port_d_mode = PIN_HP;
3148
3149 spec->num_init_verbs = 1;
3150 spec->init_verbs[0] = cxt5066_init_verbs;
3151 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3152 spec->channel_mode = cxt5066_modes;
3153 spec->cur_adc = 0;
3154 spec->cur_adc_idx = 0;
3155
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003156 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3157
Daniel Drake0fb67e92009-07-16 14:46:57 +01003158 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3159 cxt5066_models, cxt5066_cfg_tbl);
3160 switch (board_config) {
3161 default:
3162 case CXT5066_LAPTOP:
3163 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3164 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3165 break;
3166 case CXT5066_DELL_LAPTOP:
3167 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3168 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3169
3170 spec->port_d_mode = PIN_OUT;
3171 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3172 spec->num_init_verbs++;
3173 spec->dell_automute = 1;
3174 break;
David Henningsson048e78a2010-09-02 08:35:47 +02003175 case CXT5066_HP_LAPTOP:
3176 codec->patch_ops.init = cxt5066_init;
3177 codec->patch_ops.unsol_event = cxt5066_hp_laptop_event;
3178 spec->init_verbs[spec->num_init_verbs] =
3179 cxt5066_init_verbs_hp_laptop;
3180 spec->num_init_verbs++;
3181 spec->hp_laptop = 1;
3182 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3183 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3184 /* no S/PDIF out */
3185 spec->multiout.dig_out_nid = 0;
3186 /* input source automatically selected */
3187 spec->input_mux = NULL;
3188 spec->port_d_mode = 0;
3189 spec->mic_boost = 3; /* default 30dB gain */
3190 break;
3191
Daniel Drake0fb67e92009-07-16 14:46:57 +01003192 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003193 codec->patch_ops.init = cxt5066_olpc_init;
3194 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003195 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3196 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003197 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003198 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3199 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003200 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003201
3202 /* no S/PDIF out */
3203 spec->multiout.dig_out_nid = 0;
3204
3205 /* input source automatically selected */
3206 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003207
3208 /* our capture hooks which allow us to turn on the microphone LED
3209 * at the right time */
3210 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3211 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003212 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003213 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003214 codec->patch_ops.init = cxt5066_init;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003215 codec->patch_ops.unsol_event = cxt5066_vostro_event;
3216 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3217 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3218 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003219 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003220 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003221 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003222 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003223
3224 /* no S/PDIF out */
3225 spec->multiout.dig_out_nid = 0;
3226
3227 /* input source automatically selected */
3228 spec->input_mux = NULL;
3229 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003230 case CXT5066_IDEAPAD:
3231 codec->patch_ops.init = cxt5066_init;
3232 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3233 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3234 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3235 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3236 spec->port_d_mode = 0;
3237 spec->ideapad = 1;
3238 spec->mic_boost = 2; /* default 20dB gain */
3239
3240 /* no S/PDIF out */
3241 spec->multiout.dig_out_nid = 0;
3242
3243 /* input source automatically selected */
3244 spec->input_mux = NULL;
3245 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003246 case CXT5066_THINKPAD:
3247 codec->patch_ops.init = cxt5066_init;
3248 codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
3249 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3250 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3251 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3252 spec->thinkpad = 1;
3253 spec->port_d_mode = PIN_OUT;
3254 spec->mic_boost = 2; /* default 20dB gain */
3255
3256 /* no S/PDIF out */
3257 spec->multiout.dig_out_nid = 0;
3258
3259 /* input source automatically selected */
3260 spec->input_mux = NULL;
3261 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003262 }
3263
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003264 if (spec->beep_amp)
3265 snd_hda_attach_beep_device(codec, spec->beep_amp);
3266
Daniel Drake0fb67e92009-07-16 14:46:57 +01003267 return 0;
3268}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003269
3270/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003271 * Automatic parser for CX20641 & co
3272 */
3273
3274static hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3275
3276/* get the connection index of @nid in the widget @mux */
3277static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3278 hda_nid_t nid)
3279{
3280 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3281 int i, nums;
3282
3283 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3284 for (i = 0; i < nums; i++)
3285 if (conn[i] == nid)
3286 return i;
3287 return -1;
3288}
3289
3290/* get an unassigned DAC from the given list.
3291 * Return the nid if found and reduce the DAC list, or return zero if
3292 * not found
3293 */
3294static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3295 hda_nid_t *dacs, int *num_dacs)
3296{
3297 int i, nums = *num_dacs;
3298 hda_nid_t ret = 0;
3299
3300 for (i = 0; i < nums; i++) {
3301 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3302 ret = dacs[i];
3303 break;
3304 }
3305 }
3306 if (!ret)
3307 return 0;
3308 if (--nums > 0)
3309 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3310 *num_dacs = nums;
3311 return ret;
3312}
3313
3314#define MAX_AUTO_DACS 5
3315
3316/* fill analog DAC list from the widget tree */
3317static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3318{
3319 hda_nid_t nid, end_nid;
3320 int nums = 0;
3321
3322 end_nid = codec->start_nid + codec->num_nodes;
3323 for (nid = codec->start_nid; nid < end_nid; nid++) {
3324 unsigned int wcaps = get_wcaps(codec, nid);
3325 unsigned int type = get_wcaps_type(wcaps);
3326 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3327 dacs[nums++] = nid;
3328 if (nums >= MAX_AUTO_DACS)
3329 break;
3330 }
3331 }
3332 return nums;
3333}
3334
3335/* fill pin_dac_pair list from the pin and dac list */
3336static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3337 int num_pins, hda_nid_t *dacs, int *rest,
3338 struct pin_dac_pair *filled, int type)
3339{
3340 int i, nums;
3341
3342 nums = 0;
3343 for (i = 0; i < num_pins; i++) {
3344 filled[nums].pin = pins[i];
3345 filled[nums].type = type;
3346 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3347 nums++;
3348 }
3349 return nums;
3350}
3351
3352/* parse analog output paths */
3353static void cx_auto_parse_output(struct hda_codec *codec)
3354{
3355 struct conexant_spec *spec = codec->spec;
3356 struct auto_pin_cfg *cfg = &spec->autocfg;
3357 hda_nid_t dacs[MAX_AUTO_DACS];
3358 int i, j, nums, rest;
3359
3360 rest = fill_cx_auto_dacs(codec, dacs);
3361 /* parse all analog output pins */
3362 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3363 dacs, &rest, spec->dac_info,
3364 AUTO_PIN_LINE_OUT);
3365 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3366 dacs, &rest, spec->dac_info + nums,
3367 AUTO_PIN_HP_OUT);
3368 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3369 dacs, &rest, spec->dac_info + nums,
3370 AUTO_PIN_SPEAKER_OUT);
3371 spec->dac_info_filled = nums;
3372 /* fill multiout struct */
3373 for (i = 0; i < nums; i++) {
3374 hda_nid_t dac = spec->dac_info[i].dac;
3375 if (!dac)
3376 continue;
3377 switch (spec->dac_info[i].type) {
3378 case AUTO_PIN_LINE_OUT:
3379 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3380 spec->multiout.num_dacs++;
3381 break;
3382 case AUTO_PIN_HP_OUT:
3383 case AUTO_PIN_SPEAKER_OUT:
3384 if (!spec->multiout.hp_nid) {
3385 spec->multiout.hp_nid = dac;
3386 break;
3387 }
3388 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3389 if (!spec->multiout.extra_out_nid[j]) {
3390 spec->multiout.extra_out_nid[j] = dac;
3391 break;
3392 }
3393 break;
3394 }
3395 }
3396 spec->multiout.dac_nids = spec->private_dac_nids;
3397 spec->multiout.max_channels = nums * 2;
3398
3399 if (cfg->hp_outs > 0)
3400 spec->auto_mute = 1;
3401 spec->vmaster_nid = spec->private_dac_nids[0];
3402}
3403
3404/* 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 }
3420 for (i = 0; i < cfg->line_outs; i++) {
3421 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3422 AC_VERB_SET_PIN_WIDGET_CONTROL,
3423 present ? 0 : PIN_OUT);
3424 }
3425 for (i = 0; i < cfg->speaker_outs; i++) {
3426 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3427 AC_VERB_SET_PIN_WIDGET_CONTROL,
3428 present ? 0 : PIN_OUT);
3429 }
3430}
3431
3432/* automatic switch internal and external mic */
3433static void cx_auto_automic(struct hda_codec *codec)
3434{
3435 struct conexant_spec *spec = codec->spec;
3436 struct auto_pin_cfg *cfg = &spec->autocfg;
3437 struct hda_input_mux *imux = &spec->private_imux;
3438 int ext_idx = spec->auto_mic_ext;
3439
3440 if (!spec->auto_mic)
3441 return;
3442 if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) {
3443 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3444 AC_VERB_SET_CONNECT_SEL,
3445 imux->items[ext_idx].index);
3446 } else {
3447 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3448 AC_VERB_SET_CONNECT_SEL,
3449 imux->items[!ext_idx].index);
3450 }
3451}
3452
3453static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3454{
3455 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3456 switch (res >> 26) {
3457 case CONEXANT_HP_EVENT:
3458 cx_auto_hp_automute(codec);
3459 conexant_report_jack(codec, nid);
3460 break;
3461 case CONEXANT_MIC_EVENT:
3462 cx_auto_automic(codec);
3463 conexant_report_jack(codec, nid);
3464 break;
3465 }
3466}
3467
Takashi Iwaif2e57312010-09-15 10:07:08 +02003468/* return true if it's an internal-mic pin */
3469static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3470{
3471 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3472 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003473 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003474}
3475
3476/* return true if it's an external-mic pin */
3477static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3478{
3479 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3480 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003481 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3482 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003483}
3484
3485/* check whether the pin config is suitable for auto-mic switching;
3486 * auto-mic is enabled only when one int-mic and one-ext mic exist
3487 */
3488static void cx_auto_check_auto_mic(struct hda_codec *codec)
3489{
3490 struct conexant_spec *spec = codec->spec;
3491 struct auto_pin_cfg *cfg = &spec->autocfg;
3492
3493 if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3494 is_int_mic(codec, cfg->inputs[1].pin)) {
3495 spec->auto_mic = 1;
3496 spec->auto_mic_ext = 1;
3497 return;
3498 }
3499 if (is_int_mic(codec, cfg->inputs[1].pin) &&
3500 is_ext_mic(codec, cfg->inputs[0].pin)) {
3501 spec->auto_mic = 1;
3502 spec->auto_mic_ext = 0;
3503 return;
3504 }
3505}
3506
3507static void cx_auto_parse_input(struct hda_codec *codec)
3508{
3509 struct conexant_spec *spec = codec->spec;
3510 struct auto_pin_cfg *cfg = &spec->autocfg;
3511 struct hda_input_mux *imux;
3512 int i;
3513
3514 imux = &spec->private_imux;
3515 for (i = 0; i < cfg->num_inputs; i++) {
3516 int idx = get_connection_index(codec, spec->adc_nids[0],
3517 cfg->inputs[i].pin);
3518 if (idx >= 0) {
3519 const char *label;
3520 label = hda_get_autocfg_input_label(codec, cfg, i);
3521 snd_hda_add_imux_item(imux, label, idx, NULL);
3522 }
3523 }
3524 if (imux->num_items == 2 && cfg->num_inputs == 2)
3525 cx_auto_check_auto_mic(codec);
3526 if (imux->num_items > 1 && !spec->auto_mic)
3527 spec->input_mux = imux;
3528}
3529
3530/* get digital-input audio widget corresponding to the given pin */
3531static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3532{
3533 hda_nid_t nid, end_nid;
3534
3535 end_nid = codec->start_nid + codec->num_nodes;
3536 for (nid = codec->start_nid; nid < end_nid; nid++) {
3537 unsigned int wcaps = get_wcaps(codec, nid);
3538 unsigned int type = get_wcaps_type(wcaps);
3539 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3540 if (get_connection_index(codec, nid, pin) >= 0)
3541 return nid;
3542 }
3543 }
3544 return 0;
3545}
3546
3547static void cx_auto_parse_digital(struct hda_codec *codec)
3548{
3549 struct conexant_spec *spec = codec->spec;
3550 struct auto_pin_cfg *cfg = &spec->autocfg;
3551 hda_nid_t nid;
3552
3553 if (cfg->dig_outs &&
3554 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3555 spec->multiout.dig_out_nid = nid;
3556 if (cfg->dig_in_pin)
3557 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3558}
3559
3560#ifdef CONFIG_SND_HDA_INPUT_BEEP
3561static void cx_auto_parse_beep(struct hda_codec *codec)
3562{
3563 struct conexant_spec *spec = codec->spec;
3564 hda_nid_t nid, end_nid;
3565
3566 end_nid = codec->start_nid + codec->num_nodes;
3567 for (nid = codec->start_nid; nid < end_nid; nid++)
3568 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3569 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3570 break;
3571 }
3572}
3573#else
3574#define cx_auto_parse_beep(codec)
3575#endif
3576
3577static int cx_auto_parse_auto_config(struct hda_codec *codec)
3578{
3579 struct conexant_spec *spec = codec->spec;
3580 int err;
3581
3582 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3583 if (err < 0)
3584 return err;
3585
3586 cx_auto_parse_output(codec);
3587 cx_auto_parse_input(codec);
3588 cx_auto_parse_digital(codec);
3589 cx_auto_parse_beep(codec);
3590 return 0;
3591}
3592
3593static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins,
3594 hda_nid_t *pins)
3595{
3596 int i;
3597 for (i = 0; i < num_pins; i++) {
3598 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3599 snd_hda_codec_write(codec, pins[i], 0,
3600 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3601 }
3602}
3603
3604static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3605 hda_nid_t src)
3606{
3607 int idx = get_connection_index(codec, pin, src);
3608 if (idx >= 0)
3609 snd_hda_codec_write(codec, pin, 0,
3610 AC_VERB_SET_CONNECT_SEL, idx);
3611}
3612
3613static void cx_auto_init_output(struct hda_codec *codec)
3614{
3615 struct conexant_spec *spec = codec->spec;
3616 struct auto_pin_cfg *cfg = &spec->autocfg;
3617 hda_nid_t nid;
3618 int i;
3619
3620 for (i = 0; i < spec->multiout.num_dacs; i++)
3621 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
3622 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3623
3624 for (i = 0; i < cfg->hp_outs; i++)
3625 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3626 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3627 if (spec->auto_mute) {
3628 for (i = 0; i < cfg->hp_outs; i++) {
3629 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3630 AC_VERB_SET_UNSOLICITED_ENABLE,
3631 AC_USRSP_EN | CONEXANT_HP_EVENT);
3632 }
3633 cx_auto_hp_automute(codec);
3634 } else {
3635 for (i = 0; i < cfg->line_outs; i++)
3636 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3637 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3638 for (i = 0; i < cfg->speaker_outs; i++)
3639 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3640 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3641 }
3642
3643 for (i = 0; i < spec->dac_info_filled; i++) {
3644 nid = spec->dac_info[i].dac;
3645 if (!nid)
3646 nid = spec->multiout.dac_nids[0];
3647 select_connection(codec, spec->dac_info[i].pin, nid);
3648 }
3649
3650 /* turn on EAPD */
3651 cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins);
3652 cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins);
3653 cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins);
3654}
3655
3656static void cx_auto_init_input(struct hda_codec *codec)
3657{
3658 struct conexant_spec *spec = codec->spec;
3659 struct auto_pin_cfg *cfg = &spec->autocfg;
3660 int i;
3661
3662 for (i = 0; i < spec->num_adc_nids; i++)
3663 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3664 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0));
3665
3666 for (i = 0; i < cfg->num_inputs; i++) {
3667 unsigned int type;
3668 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3669 type = PIN_VREF80;
3670 else
3671 type = PIN_IN;
3672 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3673 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3674 }
3675
3676 if (spec->auto_mic) {
3677 int ext_idx = spec->auto_mic_ext;
3678 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3679 AC_VERB_SET_UNSOLICITED_ENABLE,
3680 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3681 cx_auto_automic(codec);
3682 } else {
3683 for (i = 0; i < spec->num_adc_nids; i++) {
3684 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3685 AC_VERB_SET_CONNECT_SEL,
3686 spec->private_imux.items[0].index);
3687 }
3688 }
3689}
3690
3691static void cx_auto_init_digital(struct hda_codec *codec)
3692{
3693 struct conexant_spec *spec = codec->spec;
3694 struct auto_pin_cfg *cfg = &spec->autocfg;
3695
3696 if (spec->multiout.dig_out_nid)
3697 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3698 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3699 if (spec->dig_in_nid)
3700 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3701 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3702}
3703
3704static int cx_auto_init(struct hda_codec *codec)
3705{
3706 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3707 cx_auto_init_output(codec);
3708 cx_auto_init_input(codec);
3709 cx_auto_init_digital(codec);
3710 return 0;
3711}
3712
3713static int cx_auto_add_volume(struct hda_codec *codec, const char *basename,
3714 const char *dir, int cidx,
3715 hda_nid_t nid, int hda_dir)
3716{
3717 static char name[32];
3718 static struct snd_kcontrol_new knew[] = {
3719 HDA_CODEC_VOLUME(name, 0, 0, 0),
3720 HDA_CODEC_MUTE(name, 0, 0, 0),
3721 };
3722 static char *sfx[2] = { "Volume", "Switch" };
3723 int i, err;
3724
3725 for (i = 0; i < 2; i++) {
3726 struct snd_kcontrol *kctl;
3727 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir);
3728 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3729 knew[i].index = cidx;
3730 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3731 kctl = snd_ctl_new1(&knew[i], codec);
3732 if (!kctl)
3733 return -ENOMEM;
3734 err = snd_hda_ctl_add(codec, nid, kctl);
3735 if (err < 0)
3736 return err;
3737 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3738 break;
3739 }
3740 return 0;
3741}
3742
3743#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3744 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3745
3746static int cx_auto_build_output_controls(struct hda_codec *codec)
3747{
3748 struct conexant_spec *spec = codec->spec;
3749 int i, err;
3750 int num_line = 0, num_hp = 0, num_spk = 0;
3751 static const char *texts[3] = { "Front", "Surround", "CLFE" };
3752
3753 if (spec->dac_info_filled == 1)
3754 return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3755 "Master", 0);
3756 for (i = 0; i < spec->dac_info_filled; i++) {
3757 const char *label;
3758 int idx, type;
3759 if (!spec->dac_info[i].dac)
3760 continue;
3761 type = spec->dac_info[i].type;
3762 if (type == AUTO_PIN_LINE_OUT)
3763 type = spec->autocfg.line_out_type;
3764 switch (type) {
3765 case AUTO_PIN_LINE_OUT:
3766 default:
3767 label = texts[num_line++];
3768 idx = 0;
3769 break;
3770 case AUTO_PIN_HP_OUT:
3771 label = "Headphone";
3772 idx = num_hp++;
3773 break;
3774 case AUTO_PIN_SPEAKER_OUT:
3775 label = "Speaker";
3776 idx = num_spk++;
3777 break;
3778 }
3779 err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3780 label, idx);
3781 if (err < 0)
3782 return err;
3783 }
3784 return 0;
3785}
3786
3787static int cx_auto_build_input_controls(struct hda_codec *codec)
3788{
3789 struct conexant_spec *spec = codec->spec;
3790 struct auto_pin_cfg *cfg = &spec->autocfg;
3791 static const char *prev_label;
3792 int i, err, cidx;
3793
3794 err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0],
3795 HDA_INPUT);
3796 if (err < 0)
3797 return err;
3798 prev_label = NULL;
3799 cidx = 0;
3800 for (i = 0; i < cfg->num_inputs; i++) {
3801 hda_nid_t nid = cfg->inputs[i].pin;
3802 const char *label;
3803 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3804 continue;
3805 label = hda_get_autocfg_input_label(codec, cfg, i);
3806 if (label == prev_label)
3807 cidx++;
3808 else
3809 cidx = 0;
3810 prev_label = label;
3811 err = cx_auto_add_volume(codec, label, " Capture", cidx,
3812 nid, HDA_INPUT);
3813 if (err < 0)
3814 return err;
3815 }
3816 return 0;
3817}
3818
3819static int cx_auto_build_controls(struct hda_codec *codec)
3820{
3821 int err;
3822
3823 err = cx_auto_build_output_controls(codec);
3824 if (err < 0)
3825 return err;
3826 err = cx_auto_build_input_controls(codec);
3827 if (err < 0)
3828 return err;
3829 return conexant_build_controls(codec);
3830}
3831
3832static struct hda_codec_ops cx_auto_patch_ops = {
3833 .build_controls = cx_auto_build_controls,
3834 .build_pcms = conexant_build_pcms,
3835 .init = cx_auto_init,
3836 .free = conexant_free,
3837 .unsol_event = cx_auto_unsol_event,
3838#ifdef CONFIG_SND_HDA_POWER_SAVE
3839 .suspend = conexant_suspend,
3840#endif
3841 .reboot_notify = snd_hda_shutup_pins,
3842};
3843
3844static int patch_conexant_auto(struct hda_codec *codec)
3845{
3846 struct conexant_spec *spec;
3847 int err;
3848
3849 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3850 if (!spec)
3851 return -ENOMEM;
3852 codec->spec = spec;
3853 spec->adc_nids = cx_auto_adc_nids;
3854 spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3855 spec->capsrc_nids = spec->adc_nids;
3856 err = cx_auto_parse_auto_config(codec);
3857 if (err < 0) {
3858 kfree(codec->spec);
3859 codec->spec = NULL;
3860 return err;
3861 }
3862 codec->patch_ops = cx_auto_patch_ops;
3863 if (spec->beep_amp)
3864 snd_hda_attach_beep_device(codec, spec->beep_amp);
3865 return 0;
3866}
3867
3868/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01003869 */
3870
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003871static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003872 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3873 .patch = patch_cxt5045 },
3874 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3875 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003876 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3877 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003878 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3879 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003880 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3881 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02003882 { .id = 0x14f15068, .name = "CX20584",
3883 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003884 { .id = 0x14f15069, .name = "CX20585",
3885 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02003886 { .id = 0x14f15097, .name = "CX20631",
3887 .patch = patch_conexant_auto },
3888 { .id = 0x14f15098, .name = "CX20632",
3889 .patch = patch_conexant_auto },
3890 { .id = 0x14f150a1, .name = "CX20641",
3891 .patch = patch_conexant_auto },
3892 { .id = 0x14f150a2, .name = "CX20642",
3893 .patch = patch_conexant_auto },
3894 { .id = 0x14f150ab, .name = "CX20651",
3895 .patch = patch_conexant_auto },
3896 { .id = 0x14f150ac, .name = "CX20652",
3897 .patch = patch_conexant_auto },
3898 { .id = 0x14f150b8, .name = "CX20664",
3899 .patch = patch_conexant_auto },
3900 { .id = 0x14f150b9, .name = "CX20665",
3901 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003902 {} /* terminator */
3903};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003904
3905MODULE_ALIAS("snd-hda-codec-id:14f15045");
3906MODULE_ALIAS("snd-hda-codec-id:14f15047");
3907MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003908MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003909MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02003910MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003911MODULE_ALIAS("snd-hda-codec-id:14f15069");
Takashi Iwaif2e57312010-09-15 10:07:08 +02003912MODULE_ALIAS("snd-hda-codec-id:14f15097");
3913MODULE_ALIAS("snd-hda-codec-id:14f15098");
3914MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3915MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3916MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3917MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3918MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3919MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003920
3921MODULE_LICENSE("GPL");
3922MODULE_DESCRIPTION("Conexant HD-audio codec");
3923
3924static struct hda_codec_preset_list conexant_list = {
3925 .preset = snd_hda_preset_conexant,
3926 .owner = THIS_MODULE,
3927};
3928
3929static int __init patch_conexant_init(void)
3930{
3931 return snd_hda_add_codec_preset(&conexant_list);
3932}
3933
3934static void __exit patch_conexant_exit(void)
3935{
3936 snd_hda_delete_codec_preset(&conexant_list);
3937}
3938
3939module_init(patch_conexant_init)
3940module_exit(patch_conexant_exit)