blob: a09c03c3f62bdf5df0ebece70777d5a12705d239 [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"
32
33#define CXT_PIN_DIR_IN 0x00
34#define CXT_PIN_DIR_OUT 0x01
35#define CXT_PIN_DIR_INOUT 0x02
36#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
37#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
38
39#define CONEXANT_HP_EVENT 0x37
40#define CONEXANT_MIC_EVENT 0x38
41
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010042/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010043
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010044#define CXT5051_SPDIF_OUT 0x1C
45#define CXT5051_PORTB_EVENT 0x38
46#define CXT5051_PORTC_EVENT 0x39
47
48
49struct conexant_jack {
50
51 hda_nid_t nid;
52 int type;
53 struct snd_jack *jack;
54
55};
Tobin Davisc9b443d2006-11-14 12:13:39 +010056
57struct conexant_spec {
58
59 struct snd_kcontrol_new *mixers[5];
60 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010061 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010062
63 const struct hda_verb *init_verbs[5]; /* initialization verbs
64 * don't forget NULL
65 * termination!
66 */
67 unsigned int num_init_verbs;
68
69 /* playback */
70 struct hda_multi_out multiout; /* playback set-up
71 * max_channels, dacs must be set
72 * dig_out_nid and hp_nid are optional
73 */
74 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010075 unsigned int hp_present;
Takashi Iwai79d7d532009-03-04 09:03:50 +010076 unsigned int no_auto_mic;
Tobin Davisc9b443d2006-11-14 12:13:39 +010077 unsigned int need_dac_fix;
78
79 /* capture */
80 unsigned int num_adc_nids;
81 hda_nid_t *adc_nids;
82 hda_nid_t dig_in_nid; /* digital-in NID; optional */
83
Takashi Iwai461e2c72008-01-25 11:35:17 +010084 unsigned int cur_adc_idx;
85 hda_nid_t cur_adc;
86 unsigned int cur_adc_stream_tag;
87 unsigned int cur_adc_format;
88
Tobin Davisc9b443d2006-11-14 12:13:39 +010089 /* capture source */
90 const struct hda_input_mux *input_mux;
91 hda_nid_t *capsrc_nids;
92 unsigned int cur_mux[3];
93
94 /* channel model */
95 const struct hda_channel_mode *channel_mode;
96 int num_channel_mode;
97
98 /* PCM information */
99 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
100
Tobin Davisc9b443d2006-11-14 12:13:39 +0100101 unsigned int spdif_route;
102
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100103 /* jack detection */
104 struct snd_array jacks;
105
Tobin Davisc9b443d2006-11-14 12:13:39 +0100106 /* dynamic controls, init_verbs and input_mux */
107 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100108 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200109 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100110
Daniel Drake0fb67e92009-07-16 14:46:57 +0100111 unsigned int dell_automute;
112 unsigned int port_d_mode;
Daniel Drakedbaccc02009-11-09 15:17:24 +0000113 unsigned char ext_mic_bias;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100114};
115
116static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
117 struct hda_codec *codec,
118 struct snd_pcm_substream *substream)
119{
120 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100121 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
122 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100123}
124
125static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
126 struct hda_codec *codec,
127 unsigned int stream_tag,
128 unsigned int format,
129 struct snd_pcm_substream *substream)
130{
131 struct conexant_spec *spec = codec->spec;
132 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
133 stream_tag,
134 format, substream);
135}
136
137static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
138 struct hda_codec *codec,
139 struct snd_pcm_substream *substream)
140{
141 struct conexant_spec *spec = codec->spec;
142 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
143}
144
145/*
146 * Digital out
147 */
148static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
149 struct hda_codec *codec,
150 struct snd_pcm_substream *substream)
151{
152 struct conexant_spec *spec = codec->spec;
153 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
154}
155
156static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
157 struct hda_codec *codec,
158 struct snd_pcm_substream *substream)
159{
160 struct conexant_spec *spec = codec->spec;
161 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
162}
163
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200164static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
165 struct hda_codec *codec,
166 unsigned int stream_tag,
167 unsigned int format,
168 struct snd_pcm_substream *substream)
169{
170 struct conexant_spec *spec = codec->spec;
171 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
172 stream_tag,
173 format, substream);
174}
175
Tobin Davisc9b443d2006-11-14 12:13:39 +0100176/*
177 * Analog capture
178 */
179static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 unsigned int stream_tag,
182 unsigned int format,
183 struct snd_pcm_substream *substream)
184{
185 struct conexant_spec *spec = codec->spec;
186 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
187 stream_tag, 0, format);
188 return 0;
189}
190
191static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
194{
195 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100196 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100197 return 0;
198}
199
200
201
202static struct hda_pcm_stream conexant_pcm_analog_playback = {
203 .substreams = 1,
204 .channels_min = 2,
205 .channels_max = 2,
206 .nid = 0, /* fill later */
207 .ops = {
208 .open = conexant_playback_pcm_open,
209 .prepare = conexant_playback_pcm_prepare,
210 .cleanup = conexant_playback_pcm_cleanup
211 },
212};
213
214static struct hda_pcm_stream conexant_pcm_analog_capture = {
215 .substreams = 1,
216 .channels_min = 2,
217 .channels_max = 2,
218 .nid = 0, /* fill later */
219 .ops = {
220 .prepare = conexant_capture_pcm_prepare,
221 .cleanup = conexant_capture_pcm_cleanup
222 },
223};
224
225
226static struct hda_pcm_stream conexant_pcm_digital_playback = {
227 .substreams = 1,
228 .channels_min = 2,
229 .channels_max = 2,
230 .nid = 0, /* fill later */
231 .ops = {
232 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200233 .close = conexant_dig_playback_pcm_close,
234 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100235 },
236};
237
238static struct hda_pcm_stream conexant_pcm_digital_capture = {
239 .substreams = 1,
240 .channels_min = 2,
241 .channels_max = 2,
242 /* NID is set in alc_build_pcms */
243};
244
Takashi Iwai461e2c72008-01-25 11:35:17 +0100245static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
246 struct hda_codec *codec,
247 unsigned int stream_tag,
248 unsigned int format,
249 struct snd_pcm_substream *substream)
250{
251 struct conexant_spec *spec = codec->spec;
252 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
253 spec->cur_adc_stream_tag = stream_tag;
254 spec->cur_adc_format = format;
255 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
256 return 0;
257}
258
259static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
260 struct hda_codec *codec,
261 struct snd_pcm_substream *substream)
262{
263 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100264 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100265 spec->cur_adc = 0;
266 return 0;
267}
268
269static struct hda_pcm_stream cx5051_pcm_analog_capture = {
270 .substreams = 1,
271 .channels_min = 2,
272 .channels_max = 2,
273 .nid = 0, /* fill later */
274 .ops = {
275 .prepare = cx5051_capture_pcm_prepare,
276 .cleanup = cx5051_capture_pcm_cleanup
277 },
278};
279
Tobin Davisc9b443d2006-11-14 12:13:39 +0100280static int conexant_build_pcms(struct hda_codec *codec)
281{
282 struct conexant_spec *spec = codec->spec;
283 struct hda_pcm *info = spec->pcm_rec;
284
285 codec->num_pcms = 1;
286 codec->pcm_info = info;
287
288 info->name = "CONEXANT Analog";
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
291 spec->multiout.max_channels;
292 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
293 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100294 if (codec->vendor_id == 0x14f15051)
295 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
296 cx5051_pcm_analog_capture;
297 else
298 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
299 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100300 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
302
303 if (spec->multiout.dig_out_nid) {
304 info++;
305 codec->num_pcms++;
306 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100307 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100308 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
309 conexant_pcm_digital_playback;
310 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
311 spec->multiout.dig_out_nid;
312 if (spec->dig_in_nid) {
313 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
314 conexant_pcm_digital_capture;
315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
316 spec->dig_in_nid;
317 }
318 }
319
320 return 0;
321}
322
323static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_info *uinfo)
325{
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct conexant_spec *spec = codec->spec;
328
329 return snd_hda_input_mux_info(spec->input_mux, uinfo);
330}
331
332static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_value *ucontrol)
334{
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct conexant_spec *spec = codec->spec;
337 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
338
339 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
340 return 0;
341}
342
343static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
345{
346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
347 struct conexant_spec *spec = codec->spec;
348 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
349
350 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
351 spec->capsrc_nids[adc_idx],
352 &spec->cur_mux[adc_idx]);
353}
354
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200355#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200356static void conexant_free_jack_priv(struct snd_jack *jack)
357{
358 struct conexant_jack *jacks = jack->private_data;
359 jacks->nid = 0;
360 jacks->jack = NULL;
361}
362
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100363static int conexant_add_jack(struct hda_codec *codec,
364 hda_nid_t nid, int type)
365{
366 struct conexant_spec *spec;
367 struct conexant_jack *jack;
368 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200369 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100370
371 spec = codec->spec;
372 snd_array_init(&spec->jacks, sizeof(*jack), 32);
373 jack = snd_array_new(&spec->jacks);
374 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
375
376 if (!jack)
377 return -ENOMEM;
378
379 jack->nid = nid;
380 jack->type = type;
381
Takashi Iwai95c09092009-04-14 16:15:29 +0200382 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
383 if (err < 0)
384 return err;
385 jack->jack->private_data = jack;
386 jack->jack->private_free = conexant_free_jack_priv;
387 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100388}
389
390static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
391{
392 struct conexant_spec *spec = codec->spec;
393 struct conexant_jack *jacks = spec->jacks.list;
394
395 if (jacks) {
396 int i;
397 for (i = 0; i < spec->jacks.used; i++) {
398 if (jacks->nid == nid) {
399 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100400 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100401
402 present = (present) ? jacks->type : 0 ;
403
404 snd_jack_report(jacks->jack,
405 present);
406 }
407 jacks++;
408 }
409 }
410}
411
412static int conexant_init_jacks(struct hda_codec *codec)
413{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100414 struct conexant_spec *spec = codec->spec;
415 int i;
416
417 for (i = 0; i < spec->num_init_verbs; i++) {
418 const struct hda_verb *hv;
419
420 hv = spec->init_verbs[i];
421 while (hv->nid) {
422 int err = 0;
423 switch (hv->param ^ AC_USRSP_EN) {
424 case CONEXANT_HP_EVENT:
425 err = conexant_add_jack(codec, hv->nid,
426 SND_JACK_HEADPHONE);
427 conexant_report_jack(codec, hv->nid);
428 break;
429 case CXT5051_PORTC_EVENT:
430 case CONEXANT_MIC_EVENT:
431 err = conexant_add_jack(codec, hv->nid,
432 SND_JACK_MICROPHONE);
433 conexant_report_jack(codec, hv->nid);
434 break;
435 }
436 if (err < 0)
437 return err;
438 ++hv;
439 }
440 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100441 return 0;
442
443}
Takashi Iwai5801f992009-01-27 12:53:22 +0100444#else
445static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
446{
447}
448
449static inline int conexant_init_jacks(struct hda_codec *codec)
450{
451 return 0;
452}
453#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100454
Tobin Davisc9b443d2006-11-14 12:13:39 +0100455static int conexant_init(struct hda_codec *codec)
456{
457 struct conexant_spec *spec = codec->spec;
458 int i;
459
460 for (i = 0; i < spec->num_init_verbs; i++)
461 snd_hda_sequence_write(codec, spec->init_verbs[i]);
462 return 0;
463}
464
465static void conexant_free(struct hda_codec *codec)
466{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200467#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100468 struct conexant_spec *spec = codec->spec;
469 if (spec->jacks.list) {
470 struct conexant_jack *jacks = spec->jacks.list;
471 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200472 for (i = 0; i < spec->jacks.used; i++, jacks++) {
473 if (jacks->jack)
474 snd_device_free(codec->bus->card, jacks->jack);
475 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100476 snd_array_free(&spec->jacks);
477 }
478#endif
Tobin Davisc9b443d2006-11-14 12:13:39 +0100479 kfree(codec->spec);
480}
481
Takashi Iwaib880c742009-03-10 14:41:05 +0100482static struct snd_kcontrol_new cxt_capture_mixers[] = {
483 {
484 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
485 .name = "Capture Source",
486 .info = conexant_mux_enum_info,
487 .get = conexant_mux_enum_get,
488 .put = conexant_mux_enum_put
489 },
490 {}
491};
492
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100493static const char *slave_vols[] = {
494 "Headphone Playback Volume",
495 "Speaker Playback Volume",
496 NULL
497};
498
499static const char *slave_sws[] = {
500 "Headphone Playback Switch",
501 "Speaker Playback Switch",
502 NULL
503};
504
Tobin Davisc9b443d2006-11-14 12:13:39 +0100505static int conexant_build_controls(struct hda_codec *codec)
506{
507 struct conexant_spec *spec = codec->spec;
508 unsigned int i;
509 int err;
510
511 for (i = 0; i < spec->num_mixers; i++) {
512 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
513 if (err < 0)
514 return err;
515 }
516 if (spec->multiout.dig_out_nid) {
517 err = snd_hda_create_spdif_out_ctls(codec,
518 spec->multiout.dig_out_nid);
519 if (err < 0)
520 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100521 err = snd_hda_create_spdif_share_sw(codec,
522 &spec->multiout);
523 if (err < 0)
524 return err;
525 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100526 }
527 if (spec->dig_in_nid) {
528 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
529 if (err < 0)
530 return err;
531 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100532
533 /* if we have no master control, let's create it */
534 if (spec->vmaster_nid &&
535 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
536 unsigned int vmaster_tlv[4];
537 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
538 HDA_OUTPUT, vmaster_tlv);
539 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
540 vmaster_tlv, slave_vols);
541 if (err < 0)
542 return err;
543 }
544 if (spec->vmaster_nid &&
545 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
546 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
547 NULL, slave_sws);
548 if (err < 0)
549 return err;
550 }
551
Takashi Iwaib880c742009-03-10 14:41:05 +0100552 if (spec->input_mux) {
553 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
554 if (err < 0)
555 return err;
556 }
557
Tobin Davisc9b443d2006-11-14 12:13:39 +0100558 return 0;
559}
560
561static struct hda_codec_ops conexant_patch_ops = {
562 .build_controls = conexant_build_controls,
563 .build_pcms = conexant_build_pcms,
564 .init = conexant_init,
565 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100566};
567
568/*
569 * EAPD control
570 * the private value = nid | (invert << 8)
571 */
572
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200573#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100574
Tobin Davis82f30042007-02-13 12:45:44 +0100575static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100576 struct snd_ctl_elem_value *ucontrol)
577{
578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579 struct conexant_spec *spec = codec->spec;
580 int invert = (kcontrol->private_value >> 8) & 1;
581 if (invert)
582 ucontrol->value.integer.value[0] = !spec->cur_eapd;
583 else
584 ucontrol->value.integer.value[0] = spec->cur_eapd;
585 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100586
Tobin Davisc9b443d2006-11-14 12:13:39 +0100587}
588
Tobin Davis82f30042007-02-13 12:45:44 +0100589static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100590 struct snd_ctl_elem_value *ucontrol)
591{
592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
593 struct conexant_spec *spec = codec->spec;
594 int invert = (kcontrol->private_value >> 8) & 1;
595 hda_nid_t nid = kcontrol->private_value & 0xff;
596 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100597
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100598 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100599 if (invert)
600 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200601 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100602 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100603
Tobin Davisc9b443d2006-11-14 12:13:39 +0100604 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200605 snd_hda_codec_write_cache(codec, nid,
606 0, AC_VERB_SET_EAPD_BTLENABLE,
607 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100608 return 1;
609}
610
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100611/* controls for test mode */
612#ifdef CONFIG_SND_DEBUG
613
Tobin Davis82f30042007-02-13 12:45:44 +0100614#define CXT_EAPD_SWITCH(xname, nid, mask) \
615 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
616 .info = cxt_eapd_info, \
617 .get = cxt_eapd_get, \
618 .put = cxt_eapd_put, \
619 .private_value = nid | (mask<<16) }
620
621
622
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_info *uinfo)
625{
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct conexant_spec *spec = codec->spec;
628 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
629 spec->num_channel_mode);
630}
631
632static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
634{
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct conexant_spec *spec = codec->spec;
637 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
638 spec->num_channel_mode,
639 spec->multiout.max_channels);
640}
641
642static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_value *ucontrol)
644{
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct conexant_spec *spec = codec->spec;
647 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
648 spec->num_channel_mode,
649 &spec->multiout.max_channels);
650 if (err >= 0 && spec->need_dac_fix)
651 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
652 return err;
653}
654
655#define CXT_PIN_MODE(xname, nid, dir) \
656 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
657 .info = conexant_ch_mode_info, \
658 .get = conexant_ch_mode_get, \
659 .put = conexant_ch_mode_put, \
660 .private_value = nid | (dir<<16) }
661
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100662#endif /* CONFIG_SND_DEBUG */
663
Tobin Davisc9b443d2006-11-14 12:13:39 +0100664/* Conexant 5045 specific */
665
666static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
667static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
668static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100669#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100670
Tobin Davis5cd57522006-11-20 17:42:09 +0100671static struct hda_channel_mode cxt5045_modes[1] = {
672 { 2, NULL },
673};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100674
675static struct hda_input_mux cxt5045_capture_source = {
676 .num_items = 2,
677 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100678 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100679 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100680 }
681};
682
Jiang Zhe5218c892008-01-17 11:18:41 +0100683static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200684 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100685 .items = {
686 { "IntMic", 0x1 },
687 { "ExtMic", 0x2 },
688 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200689 { "CD", 0x4 },
690 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100691 }
692};
693
Jiang zhe2de3c232008-03-06 11:09:09 +0100694static struct hda_input_mux cxt5045_capture_source_hp530 = {
695 .num_items = 2,
696 .items = {
697 { "ExtMic", 0x1 },
698 { "IntMic", 0x2 },
699 }
700};
701
Tobin Davisc9b443d2006-11-14 12:13:39 +0100702/* turn on/off EAPD (+ mute HP) as a master switch */
703static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
704 struct snd_ctl_elem_value *ucontrol)
705{
706 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
707 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100708 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100709
Tobin Davis82f30042007-02-13 12:45:44 +0100710 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100711 return 0;
712
Tobin Davis82f30042007-02-13 12:45:44 +0100713 /* toggle internal speakers mute depending of presence of
714 * the headphone jack
715 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200716 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
717 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
718 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100719
Takashi Iwai47fd8302007-08-10 17:11:07 +0200720 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
721 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
722 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100723 return 1;
724}
725
726/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200727static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
728 .ops = &snd_hda_bind_vol,
729 .values = {
730 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
731 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
732 0
733 },
734};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100735
Tobin Davis7f296732007-03-12 11:39:01 +0100736/* toggle input of built-in and mic jack appropriately */
737static void cxt5045_hp_automic(struct hda_codec *codec)
738{
739 static struct hda_verb mic_jack_on[] = {
740 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
741 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
742 {}
743 };
744 static struct hda_verb mic_jack_off[] = {
745 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
746 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
747 {}
748 };
749 unsigned int present;
750
Takashi Iwaid56757a2009-11-18 08:00:14 +0100751 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100752 if (present)
753 snd_hda_sequence_write(codec, mic_jack_on);
754 else
755 snd_hda_sequence_write(codec, mic_jack_off);
756}
757
Tobin Davisc9b443d2006-11-14 12:13:39 +0100758
759/* mute internal speaker if HP is plugged */
760static void cxt5045_hp_automute(struct hda_codec *codec)
761{
Tobin Davis82f30042007-02-13 12:45:44 +0100762 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100763 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100764
Takashi Iwaid56757a2009-11-18 08:00:14 +0100765 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100766
Takashi Iwai47fd8302007-08-10 17:11:07 +0200767 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
768 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
769 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100770}
771
772/* unsolicited event for HP jack sensing */
773static void cxt5045_hp_unsol_event(struct hda_codec *codec,
774 unsigned int res)
775{
776 res >>= 26;
777 switch (res) {
778 case CONEXANT_HP_EVENT:
779 cxt5045_hp_automute(codec);
780 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100781 case CONEXANT_MIC_EVENT:
782 cxt5045_hp_automic(codec);
783 break;
784
Tobin Davisc9b443d2006-11-14 12:13:39 +0100785 }
786}
787
788static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200789 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
790 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
791 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
792 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
793 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
794 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
795 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
796 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
797 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
798 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200799 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100800 {
801 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
802 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100803 .info = cxt_eapd_info,
804 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100805 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100806 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100807 },
808
809 {}
810};
811
Jiang Zhe5218c892008-01-17 11:18:41 +0100812static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200813 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
814 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
815 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
816 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
817
Jiang Zhe5218c892008-01-17 11:18:41 +0100818 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
819 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
820 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
821 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
822
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200823 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
824 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
825
Jiang Zhe5218c892008-01-17 11:18:41 +0100826 {}
827};
828
Jiang zhe2de3c232008-03-06 11:09:09 +0100829static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100830 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
831 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
832 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
833 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
834 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
835 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
836 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
837 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
838 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
839 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
840 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
841 {
842 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
843 .name = "Master Playback Switch",
844 .info = cxt_eapd_info,
845 .get = cxt_eapd_get,
846 .put = cxt5045_hp_master_sw_put,
847 .private_value = 0x10,
848 },
849
850 {}
851};
852
Tobin Davisc9b443d2006-11-14 12:13:39 +0100853static struct hda_verb cxt5045_init_verbs[] = {
854 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200855 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100856 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200858 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
859 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
860 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
861 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
863 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
864 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
865 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100867 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100868 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100869 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100870 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
871 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100872 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100873 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100874 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100875 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100876 { } /* end */
877};
878
Jiang Zhe5218c892008-01-17 11:18:41 +0100879static struct hda_verb cxt5045_benq_init_verbs[] = {
880 /* Int Mic, Mic */
881 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
882 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
883 /* Line In,HP, Amp */
884 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
885 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
886 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
887 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
892 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
893 /* Record selector: Int mic */
894 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
895 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
896 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
897 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100898 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100899 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
900 /* EAPD */
901 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
902 { } /* end */
903};
Tobin Davis7f296732007-03-12 11:39:01 +0100904
905static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
906 /* pin sensing on HP jack */
907 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200908 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100909};
910
911static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
912 /* pin sensing on HP jack */
913 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200914 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100915};
916
Tobin Davisc9b443d2006-11-14 12:13:39 +0100917#ifdef CONFIG_SND_DEBUG
918/* Test configuration for debugging, modelled after the ALC260 test
919 * configuration.
920 */
921static struct hda_input_mux cxt5045_test_capture_source = {
922 .num_items = 5,
923 .items = {
924 { "MIXER", 0x0 },
925 { "MIC1 pin", 0x1 },
926 { "LINE1 pin", 0x2 },
927 { "HP-OUT pin", 0x3 },
928 { "CD pin", 0x4 },
929 },
930};
931
932static struct snd_kcontrol_new cxt5045_test_mixer[] = {
933
934 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100935 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
936 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100937 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
938 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
939 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
940 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941
942 /* Modes for retasking pin widgets */
943 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
944 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
945
Tobin Davis82f30042007-02-13 12:45:44 +0100946 /* EAPD Switch Control */
947 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
948
Tobin Davisc9b443d2006-11-14 12:13:39 +0100949 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100950
Tobin Davis7f296732007-03-12 11:39:01 +0100951 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
952 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
953 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
954 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
955 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
956 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
957 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
958 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
959 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
960 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100961 {
962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
963 .name = "Input Source",
964 .info = conexant_mux_enum_info,
965 .get = conexant_mux_enum_get,
966 .put = conexant_mux_enum_put,
967 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200968 /* Audio input controls */
969 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
970 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
971 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
972 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
973 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
974 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
975 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
976 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
977 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
978 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100979 { } /* end */
980};
981
982static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100983 /* Set connections */
984 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
985 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
986 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100987 /* Enable retasking pins as output, initially without power amp */
988 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100989 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990
991 /* Disable digital (SPDIF) pins initially, but users can enable
992 * them via a mixer switch. In the case of SPDIF-out, this initverb
993 * payload also sets the generation to 0, output to be in "consumer"
994 * PCM format, copyright asserted, no pre-emphasis and no validity
995 * control.
996 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100997 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
998 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100999
1000 /* Start with output sum widgets muted and their output gains at min */
1001 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1003
1004 /* Unmute retasking pin widget output buffers since the default
1005 * state appears to be output. As the pin mode is changed by the
1006 * user the pin mode control will take care of enabling the pin's
1007 * input/output buffers as needed.
1008 */
1009 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1010 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1011
1012 /* Mute capture amp left and right */
1013 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1014
1015 /* Set ADC connection select to match default mixer setting (mic1
1016 * pin)
1017 */
1018 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001019 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001020
1021 /* Mute all inputs to mixer widget (even unconnected ones) */
1022 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1023 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1024 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1025 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1026 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1027
1028 { }
1029};
1030#endif
1031
1032
1033/* initialize jack-sensing, too */
1034static int cxt5045_init(struct hda_codec *codec)
1035{
1036 conexant_init(codec);
1037 cxt5045_hp_automute(codec);
1038 return 0;
1039}
1040
1041
1042enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001043 CXT5045_LAPTOP_HPSENSE,
1044 CXT5045_LAPTOP_MICSENSE,
1045 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001046 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001047 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001048#ifdef CONFIG_SND_DEBUG
1049 CXT5045_TEST,
1050#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001051 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001052};
1053
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001054static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001055 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1056 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1057 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1058 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001059 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001060#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001061 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001062#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001063};
1064
1065static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001066 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001067 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1068 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001069 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001070 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001071 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1072 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001073 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1074 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001075 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1076 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1077 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001078 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1079 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001080 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001081 {}
1082};
1083
1084static int patch_cxt5045(struct hda_codec *codec)
1085{
1086 struct conexant_spec *spec;
1087 int board_config;
1088
1089 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1090 if (!spec)
1091 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001092 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001093 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001094
1095 spec->multiout.max_channels = 2;
1096 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1097 spec->multiout.dac_nids = cxt5045_dac_nids;
1098 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1099 spec->num_adc_nids = 1;
1100 spec->adc_nids = cxt5045_adc_nids;
1101 spec->capsrc_nids = cxt5045_capsrc_nids;
1102 spec->input_mux = &cxt5045_capture_source;
1103 spec->num_mixers = 1;
1104 spec->mixers[0] = cxt5045_mixers;
1105 spec->num_init_verbs = 1;
1106 spec->init_verbs[0] = cxt5045_init_verbs;
1107 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001108 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1109 spec->channel_mode = cxt5045_modes,
1110
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111
1112 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001114 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1115 cxt5045_models,
1116 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001117 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001118 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001119 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001120 spec->input_mux = &cxt5045_capture_source;
1121 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001122 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1123 spec->mixers[0] = cxt5045_mixers;
1124 codec->patch_ops.init = cxt5045_init;
1125 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001126 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001127 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001128 spec->input_mux = &cxt5045_capture_source;
1129 spec->num_init_verbs = 2;
1130 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131 spec->mixers[0] = cxt5045_mixers;
1132 codec->patch_ops.init = cxt5045_init;
1133 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001134 default:
1135 case CXT5045_LAPTOP_HPMICSENSE:
1136 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1137 spec->input_mux = &cxt5045_capture_source;
1138 spec->num_init_verbs = 3;
1139 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1140 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1141 spec->mixers[0] = cxt5045_mixers;
1142 codec->patch_ops.init = cxt5045_init;
1143 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001144 case CXT5045_BENQ:
1145 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1146 spec->input_mux = &cxt5045_capture_source_benq;
1147 spec->num_init_verbs = 1;
1148 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1149 spec->mixers[0] = cxt5045_mixers;
1150 spec->mixers[1] = cxt5045_benq_mixers;
1151 spec->num_mixers = 2;
1152 codec->patch_ops.init = cxt5045_init;
1153 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001154 case CXT5045_LAPTOP_HP530:
1155 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1156 spec->input_mux = &cxt5045_capture_source_hp530;
1157 spec->num_init_verbs = 2;
1158 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1159 spec->mixers[0] = cxt5045_mixers_hp530;
1160 codec->patch_ops.init = cxt5045_init;
1161 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001162#ifdef CONFIG_SND_DEBUG
1163 case CXT5045_TEST:
1164 spec->input_mux = &cxt5045_test_capture_source;
1165 spec->mixers[0] = cxt5045_test_mixer;
1166 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001167 break;
1168
Tobin Davisc9b443d2006-11-14 12:13:39 +01001169#endif
1170 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001171
Takashi Iwai031005f2008-06-26 14:49:58 +02001172 switch (codec->subsystem_id >> 16) {
1173 case 0x103c:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001174 case 0x1734:
1175 /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
1176 * on NID 0x17. Fix max PCM level to 0 dB
1177 * (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001178 */
1179 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1180 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1181 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1182 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1183 (1 << AC_AMPCAP_MUTE_SHIFT));
1184 break;
1185 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001186
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187 return 0;
1188}
1189
1190
1191/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001192#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001194static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001195static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1196static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197
Tobin Davis5cd57522006-11-20 17:42:09 +01001198static struct hda_channel_mode cxt5047_modes[1] = {
1199 { 2, NULL },
1200};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201
Tobin Davis82f30042007-02-13 12:45:44 +01001202static struct hda_input_mux cxt5047_toshiba_capture_source = {
1203 .num_items = 2,
1204 .items = {
1205 { "ExtMic", 0x2 },
1206 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207 }
1208};
1209
1210/* turn on/off EAPD (+ mute HP) as a master switch */
1211static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1212 struct snd_ctl_elem_value *ucontrol)
1213{
1214 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1215 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001216 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217
Tobin Davis82f30042007-02-13 12:45:44 +01001218 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001219 return 0;
1220
Tobin Davis82f30042007-02-13 12:45:44 +01001221 /* toggle internal speakers mute depending of presence of
1222 * the headphone jack
1223 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001224 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001225 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1226 * pin widgets unlike other codecs. In this case, we need to
1227 * set index 0x01 for the volume from the mixer amp 0x19.
1228 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001229 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001230 HDA_AMP_MUTE, bits);
1231 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1232 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1233 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 return 1;
1235}
1236
Tobin Davisc9b443d2006-11-14 12:13:39 +01001237/* mute internal speaker if HP is plugged */
1238static void cxt5047_hp_automute(struct hda_codec *codec)
1239{
Tobin Davis82f30042007-02-13 12:45:44 +01001240 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001241 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242
Takashi Iwaid56757a2009-11-18 08:00:14 +01001243 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001244
Takashi Iwai47fd8302007-08-10 17:11:07 +02001245 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001246 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001247 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001248 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001249}
1250
1251/* toggle input of built-in and mic jack appropriately */
1252static void cxt5047_hp_automic(struct hda_codec *codec)
1253{
1254 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001255 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1256 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257 {}
1258 };
1259 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001260 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1261 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 {}
1263 };
1264 unsigned int present;
1265
Takashi Iwaid56757a2009-11-18 08:00:14 +01001266 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267 if (present)
1268 snd_hda_sequence_write(codec, mic_jack_on);
1269 else
1270 snd_hda_sequence_write(codec, mic_jack_off);
1271}
1272
1273/* unsolicited event for HP jack sensing */
1274static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1275 unsigned int res)
1276{
Marc Boucher9f113e02008-01-22 15:18:08 +01001277 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001278 case CONEXANT_HP_EVENT:
1279 cxt5047_hp_automute(codec);
1280 break;
1281 case CONEXANT_MIC_EVENT:
1282 cxt5047_hp_automic(codec);
1283 break;
1284 }
1285}
1286
Takashi Iwaidf481e42009-03-10 15:35:35 +01001287static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1288 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1289 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1290 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1292 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1293 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001295 {
1296 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1297 .name = "Master Playback Switch",
1298 .info = cxt_eapd_info,
1299 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 .put = cxt5047_hp_master_sw_put,
1301 .private_value = 0x13,
1302 },
1303
1304 {}
1305};
1306
Takashi Iwaidf481e42009-03-10 15:35:35 +01001307static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001308 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001309 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001310 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1311 {}
1312};
1313
1314static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316 { } /* end */
1317};
1318
1319static struct hda_verb cxt5047_init_verbs[] = {
1320 /* Line in, Mic, Built-in Mic */
1321 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1322 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1323 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001324 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001325 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001326 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1327 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001328 /* Record selector: Mic */
1329 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1330 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1331 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1332 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001333 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1334 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1335 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1336 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001337 /* SPDIF route: PCM */
1338 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001339 /* Enable unsolicited events */
1340 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1341 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 { } /* end */
1343};
1344
1345/* configuration for Toshiba Laptops */
1346static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001347 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001348 {}
1349};
1350
1351/* Test configuration for debugging, modelled after the ALC260 test
1352 * configuration.
1353 */
1354#ifdef CONFIG_SND_DEBUG
1355static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001356 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001358 { "LINE1 pin", 0x0 },
1359 { "MIC1 pin", 0x1 },
1360 { "MIC2 pin", 0x2 },
1361 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 },
1363};
1364
1365static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1366
1367 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001368 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1375 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001376 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1377 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1378 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001380
1381 /* Modes for retasking pin widgets */
1382 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1383 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1384
Tobin Davis82f30042007-02-13 12:45:44 +01001385 /* EAPD Switch Control */
1386 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1387
Tobin Davisc9b443d2006-11-14 12:13:39 +01001388 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001389 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1390 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1391 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1392 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1393 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1394 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1395 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1396 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001397
Tobin Davis82f30042007-02-13 12:45:44 +01001398 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1399 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1400 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1401 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1402 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1403 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1404 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1405 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001406 {
1407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1408 .name = "Input Source",
1409 .info = conexant_mux_enum_info,
1410 .get = conexant_mux_enum_get,
1411 .put = conexant_mux_enum_put,
1412 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001413 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001414
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 { } /* end */
1416};
1417
1418static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419 /* Enable retasking pins as output, initially without power amp */
1420 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1421 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1422 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1423
1424 /* Disable digital (SPDIF) pins initially, but users can enable
1425 * them via a mixer switch. In the case of SPDIF-out, this initverb
1426 * payload also sets the generation to 0, output to be in "consumer"
1427 * PCM format, copyright asserted, no pre-emphasis and no validity
1428 * control.
1429 */
1430 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1431
1432 /* Ensure mic1, mic2, line1 pin widgets take input from the
1433 * OUT1 sum bus when acting as an output.
1434 */
1435 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1436 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1437
1438 /* Start with output sum widgets muted and their output gains at min */
1439 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1440 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1441
1442 /* Unmute retasking pin widget output buffers since the default
1443 * state appears to be output. As the pin mode is changed by the
1444 * user the pin mode control will take care of enabling the pin's
1445 * input/output buffers as needed.
1446 */
1447 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1448 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1449 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1450
1451 /* Mute capture amp left and right */
1452 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1453
1454 /* Set ADC connection select to match default mixer setting (mic1
1455 * pin)
1456 */
1457 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1458
1459 /* Mute all inputs to mixer widget (even unconnected ones) */
1460 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1461 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1462 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1468
1469 { }
1470};
1471#endif
1472
1473
1474/* initialize jack-sensing, too */
1475static int cxt5047_hp_init(struct hda_codec *codec)
1476{
1477 conexant_init(codec);
1478 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001479 return 0;
1480}
1481
1482
1483enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001484 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1485 CXT5047_LAPTOP_HP, /* Some HP laptops */
1486 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001487#ifdef CONFIG_SND_DEBUG
1488 CXT5047_TEST,
1489#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001490 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001491};
1492
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001493static const char *cxt5047_models[CXT5047_MODELS] = {
1494 [CXT5047_LAPTOP] = "laptop",
1495 [CXT5047_LAPTOP_HP] = "laptop-hp",
1496 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001497#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001498 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001499#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001500};
1501
1502static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001503 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001504 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1505 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001506 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001507 {}
1508};
1509
1510static int patch_cxt5047(struct hda_codec *codec)
1511{
1512 struct conexant_spec *spec;
1513 int board_config;
1514
1515 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1516 if (!spec)
1517 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001518 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001519 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001520
1521 spec->multiout.max_channels = 2;
1522 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1523 spec->multiout.dac_nids = cxt5047_dac_nids;
1524 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1525 spec->num_adc_nids = 1;
1526 spec->adc_nids = cxt5047_adc_nids;
1527 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001528 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001529 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001530 spec->num_init_verbs = 1;
1531 spec->init_verbs[0] = cxt5047_init_verbs;
1532 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001533 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1534 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001535
1536 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001537
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001538 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1539 cxt5047_models,
1540 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001541 switch (board_config) {
1542 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001543 spec->num_mixers = 2;
1544 spec->mixers[1] = cxt5047_hp_spk_mixers;
1545 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001546 break;
1547 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001548 spec->num_mixers = 2;
1549 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001550 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001551 codec->patch_ops.init = cxt5047_hp_init;
1552 break;
1553 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001554 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001555 spec->num_mixers = 2;
1556 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557 spec->num_init_verbs = 2;
1558 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001559 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560 break;
1561#ifdef CONFIG_SND_DEBUG
1562 case CXT5047_TEST:
1563 spec->input_mux = &cxt5047_test_capture_source;
1564 spec->mixers[0] = cxt5047_test_mixer;
1565 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001566 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001567#endif
1568 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001569 spec->vmaster_nid = 0x13;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 return 0;
1571}
1572
Takashi Iwai461e2c72008-01-25 11:35:17 +01001573/* Conexant 5051 specific */
1574static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1575static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001576
1577static struct hda_channel_mode cxt5051_modes[1] = {
1578 { 2, NULL },
1579};
1580
1581static void cxt5051_update_speaker(struct hda_codec *codec)
1582{
1583 struct conexant_spec *spec = codec->spec;
1584 unsigned int pinctl;
1585 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1586 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1587 pinctl);
1588}
1589
1590/* turn on/off EAPD (+ mute HP) as a master switch */
1591static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1592 struct snd_ctl_elem_value *ucontrol)
1593{
1594 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1595
1596 if (!cxt_eapd_put(kcontrol, ucontrol))
1597 return 0;
1598 cxt5051_update_speaker(codec);
1599 return 1;
1600}
1601
1602/* toggle input of built-in and mic jack appropriately */
1603static void cxt5051_portb_automic(struct hda_codec *codec)
1604{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001605 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001606 unsigned int present;
1607
Takashi Iwai79d7d532009-03-04 09:03:50 +01001608 if (spec->no_auto_mic)
1609 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001610 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001611 snd_hda_codec_write(codec, 0x14, 0,
1612 AC_VERB_SET_CONNECT_SEL,
1613 present ? 0x01 : 0x00);
1614}
1615
1616/* switch the current ADC according to the jack state */
1617static void cxt5051_portc_automic(struct hda_codec *codec)
1618{
1619 struct conexant_spec *spec = codec->spec;
1620 unsigned int present;
1621 hda_nid_t new_adc;
1622
Takashi Iwai79d7d532009-03-04 09:03:50 +01001623 if (spec->no_auto_mic)
1624 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001625 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001626 if (present)
1627 spec->cur_adc_idx = 1;
1628 else
1629 spec->cur_adc_idx = 0;
1630 new_adc = spec->adc_nids[spec->cur_adc_idx];
1631 if (spec->cur_adc && spec->cur_adc != new_adc) {
1632 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001633 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001634 spec->cur_adc = new_adc;
1635 snd_hda_codec_setup_stream(codec, new_adc,
1636 spec->cur_adc_stream_tag, 0,
1637 spec->cur_adc_format);
1638 }
1639}
1640
1641/* mute internal speaker if HP is plugged */
1642static void cxt5051_hp_automute(struct hda_codec *codec)
1643{
1644 struct conexant_spec *spec = codec->spec;
1645
Takashi Iwaid56757a2009-11-18 08:00:14 +01001646 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001647 cxt5051_update_speaker(codec);
1648}
1649
1650/* unsolicited event for HP jack sensing */
1651static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1652 unsigned int res)
1653{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001654 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001655 switch (res >> 26) {
1656 case CONEXANT_HP_EVENT:
1657 cxt5051_hp_automute(codec);
1658 break;
1659 case CXT5051_PORTB_EVENT:
1660 cxt5051_portb_automic(codec);
1661 break;
1662 case CXT5051_PORTC_EVENT:
1663 cxt5051_portc_automic(codec);
1664 break;
1665 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001666 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001667}
1668
1669static struct snd_kcontrol_new cxt5051_mixers[] = {
1670 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1671 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1672 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1673 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1674 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1675 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1676 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1677 {
1678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1679 .name = "Master Playback Switch",
1680 .info = cxt_eapd_info,
1681 .get = cxt_eapd_get,
1682 .put = cxt5051_hp_master_sw_put,
1683 .private_value = 0x1a,
1684 },
1685
1686 {}
1687};
1688
1689static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1690 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1691 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1692 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1693 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1694 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1695 {
1696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1697 .name = "Master Playback Switch",
1698 .info = cxt_eapd_info,
1699 .get = cxt_eapd_get,
1700 .put = cxt5051_hp_master_sw_put,
1701 .private_value = 0x1a,
1702 },
1703
1704 {}
1705};
1706
Takashi Iwai79d7d532009-03-04 09:03:50 +01001707static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1708 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1709 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1710 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1711 {
1712 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1713 .name = "Master Playback Switch",
1714 .info = cxt_eapd_info,
1715 .get = cxt_eapd_get,
1716 .put = cxt5051_hp_master_sw_put,
1717 .private_value = 0x1a,
1718 },
1719
1720 {}
1721};
1722
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723static struct hda_verb cxt5051_init_verbs[] = {
1724 /* Line in, Mic */
1725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1726 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1727 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1728 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1729 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1730 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1731 /* SPK */
1732 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1733 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1734 /* HP, Amp */
1735 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1736 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1737 /* DAC1 */
1738 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1739 /* Record selector: Int mic */
1740 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1741 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1742 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1743 /* SPDIF route: PCM */
1744 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1745 /* EAPD */
1746 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1747 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1748 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1749 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1750 { } /* end */
1751};
1752
Takashi Iwai79d7d532009-03-04 09:03:50 +01001753static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1754 /* Line in, Mic */
1755 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1756 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1757 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1758 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1759 /* SPK */
1760 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1761 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1762 /* HP, Amp */
1763 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1764 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1765 /* DAC1 */
1766 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1767 /* Record selector: Int mic */
1768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1769 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1770 /* SPDIF route: PCM */
1771 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1772 /* EAPD */
1773 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1774 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1775 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1776 { } /* end */
1777};
1778
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001779static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1780 /* Line in, Mic */
1781 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1782 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1783 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1784 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1785 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1786 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1787 /* SPK */
1788 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1789 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1790 /* HP, Amp */
1791 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1792 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1793 /* Docking HP */
1794 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1795 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1796 /* DAC1 */
1797 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1798 /* Record selector: Int mic */
1799 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1801 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1802 /* SPDIF route: PCM */
1803 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1804 /* EAPD */
1805 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1806 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1807 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1808 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1809 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1810 { } /* end */
1811};
1812
Takashi Iwai461e2c72008-01-25 11:35:17 +01001813/* initialize jack-sensing, too */
1814static int cxt5051_init(struct hda_codec *codec)
1815{
1816 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001817 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001818 if (codec->patch_ops.unsol_event) {
1819 cxt5051_hp_automute(codec);
1820 cxt5051_portb_automic(codec);
1821 cxt5051_portc_automic(codec);
1822 }
1823 return 0;
1824}
1825
1826
1827enum {
1828 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1829 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001830 CXT5051_HP_DV6736, /* HP without mic switch */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001831 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001832 CXT5051_MODELS
1833};
1834
1835static const char *cxt5051_models[CXT5051_MODELS] = {
1836 [CXT5051_LAPTOP] = "laptop",
1837 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001838 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001839 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001840};
1841
1842static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001843 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001844 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001845 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1846 CXT5051_LAPTOP),
1847 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001848 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001849 {}
1850};
1851
1852static int patch_cxt5051(struct hda_codec *codec)
1853{
1854 struct conexant_spec *spec;
1855 int board_config;
1856
1857 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1858 if (!spec)
1859 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001860 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001861 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001862
1863 codec->patch_ops = conexant_patch_ops;
1864 codec->patch_ops.init = cxt5051_init;
1865
1866 spec->multiout.max_channels = 2;
1867 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1868 spec->multiout.dac_nids = cxt5051_dac_nids;
1869 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1870 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1871 spec->adc_nids = cxt5051_adc_nids;
1872 spec->num_mixers = 1;
1873 spec->mixers[0] = cxt5051_mixers;
1874 spec->num_init_verbs = 1;
1875 spec->init_verbs[0] = cxt5051_init_verbs;
1876 spec->spdif_route = 0;
1877 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1878 spec->channel_mode = cxt5051_modes;
1879 spec->cur_adc = 0;
1880 spec->cur_adc_idx = 0;
1881
Takashi Iwai79d7d532009-03-04 09:03:50 +01001882 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1883
Takashi Iwai461e2c72008-01-25 11:35:17 +01001884 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1885 cxt5051_models,
1886 cxt5051_cfg_tbl);
1887 switch (board_config) {
1888 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001889 spec->mixers[0] = cxt5051_hp_mixers;
1890 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001891 case CXT5051_HP_DV6736:
1892 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1893 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1894 spec->no_auto_mic = 1;
1895 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001896 case CXT5051_LENOVO_X200:
1897 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001898 break;
1899 }
1900
1901 return 0;
1902}
1903
Daniel Drake0fb67e92009-07-16 14:46:57 +01001904/* Conexant 5066 specific */
1905
1906static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1907static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1908static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1909#define CXT5066_SPDIF_OUT 0x21
1910
Daniel Drakedbaccc02009-11-09 15:17:24 +00001911/* OLPC's microphone port is DC coupled for use with external sensors,
1912 * therefore we use a 50% mic bias in order to center the input signal with
1913 * the DC input range of the codec. */
1914#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1915
Daniel Drake0fb67e92009-07-16 14:46:57 +01001916static struct hda_channel_mode cxt5066_modes[1] = {
1917 { 2, NULL },
1918};
1919
1920static void cxt5066_update_speaker(struct hda_codec *codec)
1921{
1922 struct conexant_spec *spec = codec->spec;
1923 unsigned int pinctl;
1924
1925 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1926 spec->hp_present);
1927
1928 /* Port A (HP) */
1929 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1930 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1931 pinctl);
1932
1933 /* Port D (HP/LO) */
1934 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1935 ? spec->port_d_mode : 0;
1936 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1937 pinctl);
1938
1939 /* CLASS_D AMP */
1940 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1941 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1942 pinctl);
1943
1944 if (spec->dell_automute) {
1945 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
1946 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1947 ? PIN_OUT : 0;
1948 snd_hda_codec_write(codec, 0x1c, 0,
1949 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1950 }
1951}
1952
1953/* turn on/off EAPD (+ mute HP) as a master switch */
1954static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1955 struct snd_ctl_elem_value *ucontrol)
1956{
1957 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1958
1959 if (!cxt_eapd_put(kcontrol, ucontrol))
1960 return 0;
1961
1962 cxt5066_update_speaker(codec);
1963 return 1;
1964}
1965
1966/* toggle input of built-in and mic jack appropriately */
1967static void cxt5066_automic(struct hda_codec *codec)
1968{
Daniel Drakedbaccc02009-11-09 15:17:24 +00001969 struct conexant_spec *spec = codec->spec;
1970 struct hda_verb ext_mic_present[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001971 /* enable external mic, port B */
Daniel Drakedbaccc02009-11-09 15:17:24 +00001972 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
Daniel Drake0fb67e92009-07-16 14:46:57 +01001973
1974 /* switch to external mic input */
1975 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
1976
1977 /* disable internal mic, port C */
1978 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1979 {}
1980 };
1981 static struct hda_verb ext_mic_absent[] = {
1982 /* enable internal mic, port C */
1983 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1984
1985 /* switch to internal mic input */
1986 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
1987
1988 /* disable external mic, port B */
1989 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1990 {}
1991 };
1992 unsigned int present;
1993
Takashi Iwaid56757a2009-11-18 08:00:14 +01001994 present = snd_hda_jack_detect(codec, 0x1a);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001995 if (present) {
1996 snd_printdd("CXT5066: external microphone detected\n");
1997 snd_hda_sequence_write(codec, ext_mic_present);
1998 } else {
1999 snd_printdd("CXT5066: external microphone absent\n");
2000 snd_hda_sequence_write(codec, ext_mic_absent);
2001 }
2002}
2003
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002004/* toggle input of built-in digital mic and mic jack appropriately */
2005static void cxt5066_vostro_automic(struct hda_codec *codec)
2006{
2007 struct conexant_spec *spec = codec->spec;
2008 unsigned int present;
2009
2010 struct hda_verb ext_mic_present[] = {
2011 /* enable external mic, port B */
2012 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2013
2014 /* switch to external mic input */
2015 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2016 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2017
2018 /* disable internal digital mic */
2019 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2020 {}
2021 };
2022 static struct hda_verb ext_mic_absent[] = {
2023 /* enable internal mic, port C */
2024 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2025
2026 /* switch to internal mic input */
2027 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2028
2029 /* disable external mic, port B */
2030 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2031 {}
2032 };
2033
2034 present = snd_hda_jack_detect(codec, 0x1a);
2035 if (present) {
2036 snd_printdd("CXT5066: external microphone detected\n");
2037 snd_hda_sequence_write(codec, ext_mic_present);
2038 } else {
2039 snd_printdd("CXT5066: external microphone absent\n");
2040 snd_hda_sequence_write(codec, ext_mic_absent);
2041 }
2042}
2043
Daniel Drake0fb67e92009-07-16 14:46:57 +01002044/* mute internal speaker if HP is plugged */
2045static void cxt5066_hp_automute(struct hda_codec *codec)
2046{
2047 struct conexant_spec *spec = codec->spec;
2048 unsigned int portA, portD;
2049
2050 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002051 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002052
2053 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002054 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002055
2056 spec->hp_present = !!(portA | portD);
2057 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2058 portA, portD, spec->hp_present);
2059 cxt5066_update_speaker(codec);
2060}
2061
2062/* unsolicited event for jack sensing */
2063static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2064{
2065 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2066 switch (res >> 26) {
2067 case CONEXANT_HP_EVENT:
2068 cxt5066_hp_automute(codec);
2069 break;
2070 case CONEXANT_MIC_EVENT:
2071 cxt5066_automic(codec);
2072 break;
2073 }
2074}
2075
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002076/* unsolicited event for jack sensing */
2077static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2078{
2079 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2080 switch (res >> 26) {
2081 case CONEXANT_HP_EVENT:
2082 cxt5066_hp_automute(codec);
2083 break;
2084 case CONEXANT_MIC_EVENT:
2085 cxt5066_vostro_automic(codec);
2086 break;
2087 }
2088}
2089
Daniel Drake0fb67e92009-07-16 14:46:57 +01002090static const struct hda_input_mux cxt5066_analog_mic_boost = {
2091 .num_items = 5,
2092 .items = {
2093 { "0dB", 0 },
2094 { "10dB", 1 },
2095 { "20dB", 2 },
2096 { "30dB", 3 },
2097 { "40dB", 4 },
2098 },
2099};
2100
2101static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2102 struct snd_ctl_elem_info *uinfo)
2103{
2104 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2105}
2106
2107static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2108 struct snd_ctl_elem_value *ucontrol)
2109{
2110 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2111 int val;
2112
2113 val = snd_hda_codec_read(codec, 0x17, 0,
2114 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
2115
2116 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2117 return 0;
2118}
2119
2120static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2121 struct snd_ctl_elem_value *ucontrol)
2122{
2123 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2124 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2125 unsigned int idx;
2126
2127 if (!imux->num_items)
2128 return 0;
2129 idx = ucontrol->value.enumerated.item[0];
2130 if (idx >= imux->num_items)
2131 idx = imux->num_items - 1;
2132
2133 snd_hda_codec_write_cache(codec, 0x17, 0,
2134 AC_VERB_SET_AMP_GAIN_MUTE,
2135 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2136 imux->items[idx].index);
2137
2138 return 1;
2139}
2140
2141static struct hda_input_mux cxt5066_capture_source = {
2142 .num_items = 4,
2143 .items = {
2144 { "Mic B", 0 },
2145 { "Mic C", 1 },
2146 { "Mic E", 2 },
2147 { "Mic F", 3 },
2148 },
2149};
2150
2151static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2152 .ops = &snd_hda_bind_vol,
2153 .values = {
2154 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2155 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2156 0
2157 },
2158};
2159
2160static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2161 .ops = &snd_hda_bind_sw,
2162 .values = {
2163 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2164 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2165 0
2166 },
2167};
2168
2169static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2170 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2171 {}
2172};
2173
2174static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2175 {
2176 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2177 .name = "Master Playback Volume",
2178 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2179 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2180 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2181 .info = snd_hda_mixer_amp_volume_info,
2182 .get = snd_hda_mixer_amp_volume_get,
2183 .put = snd_hda_mixer_amp_volume_put,
2184 .tlv = { .c = snd_hda_mixer_amp_tlv },
2185 /* offset by 28 volume steps to limit minimum gain to -46dB */
2186 .private_value =
2187 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2188 },
2189 {}
2190};
2191
2192static struct snd_kcontrol_new cxt5066_mixers[] = {
2193 {
2194 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2195 .name = "Master Playback Switch",
2196 .info = cxt_eapd_info,
2197 .get = cxt_eapd_get,
2198 .put = cxt5066_hp_master_sw_put,
2199 .private_value = 0x1d,
2200 },
2201
2202 {
2203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2204 .name = "Analog Mic Boost Capture Enum",
2205 .info = cxt5066_mic_boost_mux_enum_info,
2206 .get = cxt5066_mic_boost_mux_enum_get,
2207 .put = cxt5066_mic_boost_mux_enum_put,
2208 },
2209
2210 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2211 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2212 {}
2213};
2214
2215static struct hda_verb cxt5066_init_verbs[] = {
2216 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2217 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2218 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2219 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2220
2221 /* Speakers */
2222 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2223 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2224
2225 /* HP, Amp */
2226 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2227 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2228
2229 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2230 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2231
2232 /* DAC1 */
2233 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2234
2235 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2236 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2237 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2238 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2239 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2240 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2241
2242 /* no digital microphone support yet */
2243 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2244
2245 /* Audio input selector */
2246 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2247
2248 /* SPDIF route: PCM */
2249 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2250 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2251
2252 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2253 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2254
2255 /* EAPD */
2256 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2257
2258 /* not handling these yet */
2259 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2260 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2261 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2262 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2263 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2264 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2265 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2266 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2267 { } /* end */
2268};
2269
2270static struct hda_verb cxt5066_init_verbs_olpc[] = {
2271 /* Port A: headphones */
2272 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2273 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2274
2275 /* Port B: external microphone */
Daniel Drakedbaccc02009-11-09 15:17:24 +00002276 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002277
2278 /* Port C: internal microphone */
2279 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2280
2281 /* Port D: unused */
2282 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2283
2284 /* Port E: unused, but has primary EAPD */
2285 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2286 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2287
2288 /* Port F: unused */
2289 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2290
2291 /* Port G: internal speakers */
2292 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2293 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2294
2295 /* DAC1 */
2296 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2297
2298 /* DAC2: unused */
2299 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2300
2301 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2302 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2303 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2304 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2305 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2306 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2307 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2308 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2309 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2310 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2311 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2312 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2313
2314 /* Disable digital microphone port */
2315 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2316
2317 /* Audio input selectors */
2318 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2319 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2320
2321 /* Disable SPDIF */
2322 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2323 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2324
2325 /* enable unsolicited events for Port A and B */
2326 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2327 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2328 { } /* end */
2329};
2330
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002331static struct hda_verb cxt5066_init_verbs_vostro[] = {
2332 /* Port A: headphones */
2333 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2334 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2335
2336 /* Port B: external microphone */
2337 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2338
2339 /* Port C: unused */
2340 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2341
2342 /* Port D: unused */
2343 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2344
2345 /* Port E: unused, but has primary EAPD */
2346 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2347 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2348
2349 /* Port F: unused */
2350 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2351
2352 /* Port G: internal speakers */
2353 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2354 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2355
2356 /* DAC1 */
2357 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2358
2359 /* DAC2: unused */
2360 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2361
2362 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2363 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2364 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2365 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2366 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2367 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2368 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2369 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2370 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2371 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2372 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2373 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2374
2375 /* Digital microphone port */
2376 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2377
2378 /* Audio input selectors */
2379 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2380 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2381
2382 /* Disable SPDIF */
2383 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2384 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2385
2386 /* enable unsolicited events for Port A and B */
2387 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2388 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2389 { } /* end */
2390};
2391
Daniel Drake0fb67e92009-07-16 14:46:57 +01002392static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2393 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2394 { } /* end */
2395};
2396
2397/* initialize jack-sensing, too */
2398static int cxt5066_init(struct hda_codec *codec)
2399{
2400 snd_printdd("CXT5066: init\n");
2401 conexant_init(codec);
2402 if (codec->patch_ops.unsol_event) {
2403 cxt5066_hp_automute(codec);
2404 cxt5066_automic(codec);
2405 }
2406 return 0;
2407}
2408
2409enum {
2410 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2411 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2412 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002413 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002414 CXT5066_MODELS
2415};
2416
2417static const char *cxt5066_models[CXT5066_MODELS] = {
2418 [CXT5066_LAPTOP] = "laptop",
2419 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2420 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002421 [CXT5066_DELL_VOSTO] = "dell-vostro"
Daniel Drake0fb67e92009-07-16 14:46:57 +01002422};
2423
2424static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2425 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2426 CXT5066_LAPTOP),
2427 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2428 CXT5066_DELL_LAPTOP),
Daniel Drake798a8a12009-11-04 10:11:07 +00002429 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002430 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002431 {}
2432};
2433
2434static int patch_cxt5066(struct hda_codec *codec)
2435{
2436 struct conexant_spec *spec;
2437 int board_config;
2438
2439 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2440 if (!spec)
2441 return -ENOMEM;
2442 codec->spec = spec;
2443
2444 codec->patch_ops = conexant_patch_ops;
2445 codec->patch_ops.init = cxt5066_init;
2446
2447 spec->dell_automute = 0;
2448 spec->multiout.max_channels = 2;
2449 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2450 spec->multiout.dac_nids = cxt5066_dac_nids;
2451 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2452 spec->num_adc_nids = 1;
2453 spec->adc_nids = cxt5066_adc_nids;
2454 spec->capsrc_nids = cxt5066_capsrc_nids;
2455 spec->input_mux = &cxt5066_capture_source;
2456
2457 spec->port_d_mode = PIN_HP;
Daniel Drakedbaccc02009-11-09 15:17:24 +00002458 spec->ext_mic_bias = PIN_VREF80;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002459
2460 spec->num_init_verbs = 1;
2461 spec->init_verbs[0] = cxt5066_init_verbs;
2462 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2463 spec->channel_mode = cxt5066_modes;
2464 spec->cur_adc = 0;
2465 spec->cur_adc_idx = 0;
2466
2467 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2468 cxt5066_models, cxt5066_cfg_tbl);
2469 switch (board_config) {
2470 default:
2471 case CXT5066_LAPTOP:
2472 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2473 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2474 break;
2475 case CXT5066_DELL_LAPTOP:
2476 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2477 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2478
2479 spec->port_d_mode = PIN_OUT;
2480 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2481 spec->num_init_verbs++;
2482 spec->dell_automute = 1;
2483 break;
2484 case CXT5066_OLPC_XO_1_5:
2485 codec->patch_ops.unsol_event = cxt5066_unsol_event;
2486 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2487 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2488 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2489 spec->port_d_mode = 0;
Daniel Drakedbaccc02009-11-09 15:17:24 +00002490 spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002491
2492 /* no S/PDIF out */
2493 spec->multiout.dig_out_nid = 0;
2494
2495 /* input source automatically selected */
2496 spec->input_mux = NULL;
2497 break;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002498 case CXT5066_DELL_VOSTO:
2499 codec->patch_ops.unsol_event = cxt5066_vostro_event;
2500 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2501 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2502 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2503 spec->port_d_mode = 0;
2504
2505 /* no S/PDIF out */
2506 spec->multiout.dig_out_nid = 0;
2507
2508 /* input source automatically selected */
2509 spec->input_mux = NULL;
2510 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002511 }
2512
2513 return 0;
2514}
Takashi Iwai461e2c72008-01-25 11:35:17 +01002515
2516/*
2517 */
2518
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002519static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01002520 { .id = 0x14f15045, .name = "CX20549 (Venice)",
2521 .patch = patch_cxt5045 },
2522 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2523 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01002524 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2525 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01002526 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2527 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002528 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2529 .patch = patch_cxt5066 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01002530 {} /* terminator */
2531};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002532
2533MODULE_ALIAS("snd-hda-codec-id:14f15045");
2534MODULE_ALIAS("snd-hda-codec-id:14f15047");
2535MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01002536MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002537MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002538
2539MODULE_LICENSE("GPL");
2540MODULE_DESCRIPTION("Conexant HD-audio codec");
2541
2542static struct hda_codec_preset_list conexant_list = {
2543 .preset = snd_hda_preset_conexant,
2544 .owner = THIS_MODULE,
2545};
2546
2547static int __init patch_conexant_init(void)
2548{
2549 return snd_hda_add_codec_preset(&conexant_list);
2550}
2551
2552static void __exit patch_conexant_exit(void)
2553{
2554 snd_hda_delete_codec_preset(&conexant_list);
2555}
2556
2557module_init(patch_conexant_init)
2558module_exit(patch_conexant_exit)