blob: 9d899eda44d779695a1506598f8d5662d8a4a0f1 [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;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100113};
114
115static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
116 struct hda_codec *codec,
117 struct snd_pcm_substream *substream)
118{
119 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100120 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
121 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100122}
123
124static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
125 struct hda_codec *codec,
126 unsigned int stream_tag,
127 unsigned int format,
128 struct snd_pcm_substream *substream)
129{
130 struct conexant_spec *spec = codec->spec;
131 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
132 stream_tag,
133 format, substream);
134}
135
136static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
137 struct hda_codec *codec,
138 struct snd_pcm_substream *substream)
139{
140 struct conexant_spec *spec = codec->spec;
141 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
142}
143
144/*
145 * Digital out
146 */
147static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
148 struct hda_codec *codec,
149 struct snd_pcm_substream *substream)
150{
151 struct conexant_spec *spec = codec->spec;
152 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
153}
154
155static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
156 struct hda_codec *codec,
157 struct snd_pcm_substream *substream)
158{
159 struct conexant_spec *spec = codec->spec;
160 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
161}
162
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200163static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
164 struct hda_codec *codec,
165 unsigned int stream_tag,
166 unsigned int format,
167 struct snd_pcm_substream *substream)
168{
169 struct conexant_spec *spec = codec->spec;
170 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
171 stream_tag,
172 format, substream);
173}
174
Tobin Davisc9b443d2006-11-14 12:13:39 +0100175/*
176 * Analog capture
177 */
178static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
179 struct hda_codec *codec,
180 unsigned int stream_tag,
181 unsigned int format,
182 struct snd_pcm_substream *substream)
183{
184 struct conexant_spec *spec = codec->spec;
185 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
186 stream_tag, 0, format);
187 return 0;
188}
189
190static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
191 struct hda_codec *codec,
192 struct snd_pcm_substream *substream)
193{
194 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100195 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100196 return 0;
197}
198
199
200
201static struct hda_pcm_stream conexant_pcm_analog_playback = {
202 .substreams = 1,
203 .channels_min = 2,
204 .channels_max = 2,
205 .nid = 0, /* fill later */
206 .ops = {
207 .open = conexant_playback_pcm_open,
208 .prepare = conexant_playback_pcm_prepare,
209 .cleanup = conexant_playback_pcm_cleanup
210 },
211};
212
213static struct hda_pcm_stream conexant_pcm_analog_capture = {
214 .substreams = 1,
215 .channels_min = 2,
216 .channels_max = 2,
217 .nid = 0, /* fill later */
218 .ops = {
219 .prepare = conexant_capture_pcm_prepare,
220 .cleanup = conexant_capture_pcm_cleanup
221 },
222};
223
224
225static struct hda_pcm_stream conexant_pcm_digital_playback = {
226 .substreams = 1,
227 .channels_min = 2,
228 .channels_max = 2,
229 .nid = 0, /* fill later */
230 .ops = {
231 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200232 .close = conexant_dig_playback_pcm_close,
233 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100234 },
235};
236
237static struct hda_pcm_stream conexant_pcm_digital_capture = {
238 .substreams = 1,
239 .channels_min = 2,
240 .channels_max = 2,
241 /* NID is set in alc_build_pcms */
242};
243
Takashi Iwai461e2c72008-01-25 11:35:17 +0100244static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
245 struct hda_codec *codec,
246 unsigned int stream_tag,
247 unsigned int format,
248 struct snd_pcm_substream *substream)
249{
250 struct conexant_spec *spec = codec->spec;
251 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
252 spec->cur_adc_stream_tag = stream_tag;
253 spec->cur_adc_format = format;
254 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
255 return 0;
256}
257
258static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
259 struct hda_codec *codec,
260 struct snd_pcm_substream *substream)
261{
262 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100263 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100264 spec->cur_adc = 0;
265 return 0;
266}
267
268static struct hda_pcm_stream cx5051_pcm_analog_capture = {
269 .substreams = 1,
270 .channels_min = 2,
271 .channels_max = 2,
272 .nid = 0, /* fill later */
273 .ops = {
274 .prepare = cx5051_capture_pcm_prepare,
275 .cleanup = cx5051_capture_pcm_cleanup
276 },
277};
278
Tobin Davisc9b443d2006-11-14 12:13:39 +0100279static int conexant_build_pcms(struct hda_codec *codec)
280{
281 struct conexant_spec *spec = codec->spec;
282 struct hda_pcm *info = spec->pcm_rec;
283
284 codec->num_pcms = 1;
285 codec->pcm_info = info;
286
287 info->name = "CONEXANT Analog";
288 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
290 spec->multiout.max_channels;
291 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
292 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100293 if (codec->vendor_id == 0x14f15051)
294 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
295 cx5051_pcm_analog_capture;
296 else
297 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
298 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100299 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
300 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
301
302 if (spec->multiout.dig_out_nid) {
303 info++;
304 codec->num_pcms++;
305 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100306 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100307 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
308 conexant_pcm_digital_playback;
309 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
310 spec->multiout.dig_out_nid;
311 if (spec->dig_in_nid) {
312 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
313 conexant_pcm_digital_capture;
314 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
315 spec->dig_in_nid;
316 }
317 }
318
319 return 0;
320}
321
322static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
323 struct snd_ctl_elem_info *uinfo)
324{
325 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
326 struct conexant_spec *spec = codec->spec;
327
328 return snd_hda_input_mux_info(spec->input_mux, uinfo);
329}
330
331static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
332 struct snd_ctl_elem_value *ucontrol)
333{
334 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
335 struct conexant_spec *spec = codec->spec;
336 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
337
338 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
339 return 0;
340}
341
342static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
343 struct snd_ctl_elem_value *ucontrol)
344{
345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
346 struct conexant_spec *spec = codec->spec;
347 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
348
349 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
350 spec->capsrc_nids[adc_idx],
351 &spec->cur_mux[adc_idx]);
352}
353
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200354#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200355static void conexant_free_jack_priv(struct snd_jack *jack)
356{
357 struct conexant_jack *jacks = jack->private_data;
358 jacks->nid = 0;
359 jacks->jack = NULL;
360}
361
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100362static int conexant_add_jack(struct hda_codec *codec,
363 hda_nid_t nid, int type)
364{
365 struct conexant_spec *spec;
366 struct conexant_jack *jack;
367 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200368 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100369
370 spec = codec->spec;
371 snd_array_init(&spec->jacks, sizeof(*jack), 32);
372 jack = snd_array_new(&spec->jacks);
373 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
374
375 if (!jack)
376 return -ENOMEM;
377
378 jack->nid = nid;
379 jack->type = type;
380
Takashi Iwai95c09092009-04-14 16:15:29 +0200381 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
382 if (err < 0)
383 return err;
384 jack->jack->private_data = jack;
385 jack->jack->private_free = conexant_free_jack_priv;
386 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100387}
388
389static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
390{
391 struct conexant_spec *spec = codec->spec;
392 struct conexant_jack *jacks = spec->jacks.list;
393
394 if (jacks) {
395 int i;
396 for (i = 0; i < spec->jacks.used; i++) {
397 if (jacks->nid == nid) {
398 unsigned int present;
399 present = snd_hda_codec_read(codec, nid, 0,
400 AC_VERB_GET_PIN_SENSE, 0) &
401 AC_PINSENSE_PRESENCE;
402
403 present = (present) ? jacks->type : 0 ;
404
405 snd_jack_report(jacks->jack,
406 present);
407 }
408 jacks++;
409 }
410 }
411}
412
413static int conexant_init_jacks(struct hda_codec *codec)
414{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100415 struct conexant_spec *spec = codec->spec;
416 int i;
417
418 for (i = 0; i < spec->num_init_verbs; i++) {
419 const struct hda_verb *hv;
420
421 hv = spec->init_verbs[i];
422 while (hv->nid) {
423 int err = 0;
424 switch (hv->param ^ AC_USRSP_EN) {
425 case CONEXANT_HP_EVENT:
426 err = conexant_add_jack(codec, hv->nid,
427 SND_JACK_HEADPHONE);
428 conexant_report_jack(codec, hv->nid);
429 break;
430 case CXT5051_PORTC_EVENT:
431 case CONEXANT_MIC_EVENT:
432 err = conexant_add_jack(codec, hv->nid,
433 SND_JACK_MICROPHONE);
434 conexant_report_jack(codec, hv->nid);
435 break;
436 }
437 if (err < 0)
438 return err;
439 ++hv;
440 }
441 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100442 return 0;
443
444}
Takashi Iwai5801f992009-01-27 12:53:22 +0100445#else
446static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
447{
448}
449
450static inline int conexant_init_jacks(struct hda_codec *codec)
451{
452 return 0;
453}
454#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100455
Tobin Davisc9b443d2006-11-14 12:13:39 +0100456static int conexant_init(struct hda_codec *codec)
457{
458 struct conexant_spec *spec = codec->spec;
459 int i;
460
461 for (i = 0; i < spec->num_init_verbs; i++)
462 snd_hda_sequence_write(codec, spec->init_verbs[i]);
463 return 0;
464}
465
466static void conexant_free(struct hda_codec *codec)
467{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200468#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100469 struct conexant_spec *spec = codec->spec;
470 if (spec->jacks.list) {
471 struct conexant_jack *jacks = spec->jacks.list;
472 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200473 for (i = 0; i < spec->jacks.used; i++, jacks++) {
474 if (jacks->jack)
475 snd_device_free(codec->bus->card, jacks->jack);
476 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100477 snd_array_free(&spec->jacks);
478 }
479#endif
Tobin Davisc9b443d2006-11-14 12:13:39 +0100480 kfree(codec->spec);
481}
482
Takashi Iwaib880c742009-03-10 14:41:05 +0100483static struct snd_kcontrol_new cxt_capture_mixers[] = {
484 {
485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
486 .name = "Capture Source",
487 .info = conexant_mux_enum_info,
488 .get = conexant_mux_enum_get,
489 .put = conexant_mux_enum_put
490 },
491 {}
492};
493
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100494static const char *slave_vols[] = {
495 "Headphone Playback Volume",
496 "Speaker Playback Volume",
497 NULL
498};
499
500static const char *slave_sws[] = {
501 "Headphone Playback Switch",
502 "Speaker Playback Switch",
503 NULL
504};
505
Tobin Davisc9b443d2006-11-14 12:13:39 +0100506static int conexant_build_controls(struct hda_codec *codec)
507{
508 struct conexant_spec *spec = codec->spec;
509 unsigned int i;
510 int err;
511
512 for (i = 0; i < spec->num_mixers; i++) {
513 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
514 if (err < 0)
515 return err;
516 }
517 if (spec->multiout.dig_out_nid) {
518 err = snd_hda_create_spdif_out_ctls(codec,
519 spec->multiout.dig_out_nid);
520 if (err < 0)
521 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100522 err = snd_hda_create_spdif_share_sw(codec,
523 &spec->multiout);
524 if (err < 0)
525 return err;
526 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100527 }
528 if (spec->dig_in_nid) {
529 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
530 if (err < 0)
531 return err;
532 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100533
534 /* if we have no master control, let's create it */
535 if (spec->vmaster_nid &&
536 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
537 unsigned int vmaster_tlv[4];
538 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
539 HDA_OUTPUT, vmaster_tlv);
540 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
541 vmaster_tlv, slave_vols);
542 if (err < 0)
543 return err;
544 }
545 if (spec->vmaster_nid &&
546 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
547 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
548 NULL, slave_sws);
549 if (err < 0)
550 return err;
551 }
552
Takashi Iwaib880c742009-03-10 14:41:05 +0100553 if (spec->input_mux) {
554 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
555 if (err < 0)
556 return err;
557 }
558
Tobin Davisc9b443d2006-11-14 12:13:39 +0100559 return 0;
560}
561
562static struct hda_codec_ops conexant_patch_ops = {
563 .build_controls = conexant_build_controls,
564 .build_pcms = conexant_build_pcms,
565 .init = conexant_init,
566 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100567};
568
569/*
570 * EAPD control
571 * the private value = nid | (invert << 8)
572 */
573
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200574#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100575
Tobin Davis82f30042007-02-13 12:45:44 +0100576static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100577 struct snd_ctl_elem_value *ucontrol)
578{
579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
580 struct conexant_spec *spec = codec->spec;
581 int invert = (kcontrol->private_value >> 8) & 1;
582 if (invert)
583 ucontrol->value.integer.value[0] = !spec->cur_eapd;
584 else
585 ucontrol->value.integer.value[0] = spec->cur_eapd;
586 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100587
Tobin Davisc9b443d2006-11-14 12:13:39 +0100588}
589
Tobin Davis82f30042007-02-13 12:45:44 +0100590static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100591 struct snd_ctl_elem_value *ucontrol)
592{
593 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
594 struct conexant_spec *spec = codec->spec;
595 int invert = (kcontrol->private_value >> 8) & 1;
596 hda_nid_t nid = kcontrol->private_value & 0xff;
597 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100598
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100599 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100600 if (invert)
601 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200602 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100603 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100604
Tobin Davisc9b443d2006-11-14 12:13:39 +0100605 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200606 snd_hda_codec_write_cache(codec, nid,
607 0, AC_VERB_SET_EAPD_BTLENABLE,
608 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100609 return 1;
610}
611
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100612/* controls for test mode */
613#ifdef CONFIG_SND_DEBUG
614
Tobin Davis82f30042007-02-13 12:45:44 +0100615#define CXT_EAPD_SWITCH(xname, nid, mask) \
616 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
617 .info = cxt_eapd_info, \
618 .get = cxt_eapd_get, \
619 .put = cxt_eapd_put, \
620 .private_value = nid | (mask<<16) }
621
622
623
Tobin Davisc9b443d2006-11-14 12:13:39 +0100624static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *uinfo)
626{
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct conexant_spec *spec = codec->spec;
629 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
630 spec->num_channel_mode);
631}
632
633static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_value *ucontrol)
635{
636 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
637 struct conexant_spec *spec = codec->spec;
638 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
639 spec->num_channel_mode,
640 spec->multiout.max_channels);
641}
642
643static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct conexant_spec *spec = codec->spec;
648 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
649 spec->num_channel_mode,
650 &spec->multiout.max_channels);
651 if (err >= 0 && spec->need_dac_fix)
652 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
653 return err;
654}
655
656#define CXT_PIN_MODE(xname, nid, dir) \
657 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
658 .info = conexant_ch_mode_info, \
659 .get = conexant_ch_mode_get, \
660 .put = conexant_ch_mode_put, \
661 .private_value = nid | (dir<<16) }
662
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100663#endif /* CONFIG_SND_DEBUG */
664
Tobin Davisc9b443d2006-11-14 12:13:39 +0100665/* Conexant 5045 specific */
666
667static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
668static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
669static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100670#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100671
Tobin Davis5cd57522006-11-20 17:42:09 +0100672static struct hda_channel_mode cxt5045_modes[1] = {
673 { 2, NULL },
674};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100675
676static struct hda_input_mux cxt5045_capture_source = {
677 .num_items = 2,
678 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100679 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100680 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681 }
682};
683
Jiang Zhe5218c892008-01-17 11:18:41 +0100684static struct hda_input_mux cxt5045_capture_source_benq = {
685 .num_items = 3,
686 .items = {
687 { "IntMic", 0x1 },
688 { "ExtMic", 0x2 },
689 { "LineIn", 0x3 },
690 }
691};
692
Jiang zhe2de3c232008-03-06 11:09:09 +0100693static struct hda_input_mux cxt5045_capture_source_hp530 = {
694 .num_items = 2,
695 .items = {
696 { "ExtMic", 0x1 },
697 { "IntMic", 0x2 },
698 }
699};
700
Tobin Davisc9b443d2006-11-14 12:13:39 +0100701/* turn on/off EAPD (+ mute HP) as a master switch */
702static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
704{
705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
706 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100707 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100708
Tobin Davis82f30042007-02-13 12:45:44 +0100709 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100710 return 0;
711
Tobin Davis82f30042007-02-13 12:45:44 +0100712 /* toggle internal speakers mute depending of presence of
713 * the headphone jack
714 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200715 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
716 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
717 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100718
Takashi Iwai47fd8302007-08-10 17:11:07 +0200719 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
720 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
721 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722 return 1;
723}
724
725/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200726static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
727 .ops = &snd_hda_bind_vol,
728 .values = {
729 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
730 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
731 0
732 },
733};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734
Tobin Davis7f296732007-03-12 11:39:01 +0100735/* toggle input of built-in and mic jack appropriately */
736static void cxt5045_hp_automic(struct hda_codec *codec)
737{
738 static struct hda_verb mic_jack_on[] = {
739 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
740 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
741 {}
742 };
743 static struct hda_verb mic_jack_off[] = {
744 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
745 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
746 {}
747 };
748 unsigned int present;
749
750 present = snd_hda_codec_read(codec, 0x12, 0,
751 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
752 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
Tobin Davis82f30042007-02-13 12:45:44 +0100765 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100766 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100767
Takashi Iwai47fd8302007-08-10 17:11:07 +0200768 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
769 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
770 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100771}
772
773/* unsolicited event for HP jack sensing */
774static void cxt5045_hp_unsol_event(struct hda_codec *codec,
775 unsigned int res)
776{
777 res >>= 26;
778 switch (res) {
779 case CONEXANT_HP_EVENT:
780 cxt5045_hp_automute(codec);
781 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100782 case CONEXANT_MIC_EVENT:
783 cxt5045_hp_automic(codec);
784 break;
785
Tobin Davisc9b443d2006-11-14 12:13:39 +0100786 }
787}
788
789static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200790 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
791 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
792 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
793 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
794 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
795 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
796 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
797 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
798 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
799 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200800 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100801 {
802 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
803 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100804 .info = cxt_eapd_info,
805 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100806 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100807 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100808 },
809
810 {}
811};
812
Jiang Zhe5218c892008-01-17 11:18:41 +0100813static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
814 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
815 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
816 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
817 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
818
819 {}
820};
821
Jiang zhe2de3c232008-03-06 11:09:09 +0100822static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100823 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
824 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
825 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
826 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
827 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
828 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
829 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
830 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
831 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
832 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
833 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
834 {
835 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
836 .name = "Master Playback Switch",
837 .info = cxt_eapd_info,
838 .get = cxt_eapd_get,
839 .put = cxt5045_hp_master_sw_put,
840 .private_value = 0x10,
841 },
842
843 {}
844};
845
Tobin Davisc9b443d2006-11-14 12:13:39 +0100846static struct hda_verb cxt5045_init_verbs[] = {
847 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200848 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100849 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100850 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200851 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
852 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
853 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
854 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
857 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
859 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100860 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100861 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100862 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100863 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
864 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100865 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100866 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100867 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100868 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100869 { } /* end */
870};
871
Jiang Zhe5218c892008-01-17 11:18:41 +0100872static struct hda_verb cxt5045_benq_init_verbs[] = {
873 /* Int Mic, Mic */
874 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
875 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
876 /* Line In,HP, Amp */
877 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
878 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
879 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
880 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
881 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
884 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
885 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
886 /* Record selector: Int mic */
887 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
888 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
889 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
890 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100891 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100892 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
893 /* EAPD */
894 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
895 { } /* end */
896};
Tobin Davis7f296732007-03-12 11:39:01 +0100897
898static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
899 /* pin sensing on HP jack */
900 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200901 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100902};
903
904static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
905 /* pin sensing on HP jack */
906 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200907 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100908};
909
Tobin Davisc9b443d2006-11-14 12:13:39 +0100910#ifdef CONFIG_SND_DEBUG
911/* Test configuration for debugging, modelled after the ALC260 test
912 * configuration.
913 */
914static struct hda_input_mux cxt5045_test_capture_source = {
915 .num_items = 5,
916 .items = {
917 { "MIXER", 0x0 },
918 { "MIC1 pin", 0x1 },
919 { "LINE1 pin", 0x2 },
920 { "HP-OUT pin", 0x3 },
921 { "CD pin", 0x4 },
922 },
923};
924
925static struct snd_kcontrol_new cxt5045_test_mixer[] = {
926
927 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
929 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100930 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
931 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
932 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
933 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100934
935 /* Modes for retasking pin widgets */
936 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
937 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
938
Tobin Davis82f30042007-02-13 12:45:44 +0100939 /* EAPD Switch Control */
940 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
941
Tobin Davisc9b443d2006-11-14 12:13:39 +0100942 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100943
Tobin Davis7f296732007-03-12 11:39:01 +0100944 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
945 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
946 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
947 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
948 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
949 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
950 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
951 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
952 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
953 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100954 {
955 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
956 .name = "Input Source",
957 .info = conexant_mux_enum_info,
958 .get = conexant_mux_enum_get,
959 .put = conexant_mux_enum_put,
960 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200961 /* Audio input controls */
962 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
963 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
964 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
965 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
966 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
967 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
968 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
969 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
970 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
971 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972 { } /* end */
973};
974
975static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100976 /* Set connections */
977 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
978 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
979 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100980 /* Enable retasking pins as output, initially without power amp */
981 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100982 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100983
984 /* Disable digital (SPDIF) pins initially, but users can enable
985 * them via a mixer switch. In the case of SPDIF-out, this initverb
986 * payload also sets the generation to 0, output to be in "consumer"
987 * PCM format, copyright asserted, no pre-emphasis and no validity
988 * control.
989 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100990 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
991 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100992
993 /* Start with output sum widgets muted and their output gains at min */
994 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
995 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
996
997 /* Unmute retasking pin widget output buffers since the default
998 * state appears to be output. As the pin mode is changed by the
999 * user the pin mode control will take care of enabling the pin's
1000 * input/output buffers as needed.
1001 */
1002 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1003 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1004
1005 /* Mute capture amp left and right */
1006 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1007
1008 /* Set ADC connection select to match default mixer setting (mic1
1009 * pin)
1010 */
1011 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001012 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001013
1014 /* Mute all inputs to mixer widget (even unconnected ones) */
1015 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1017 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1018 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1019 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1020
1021 { }
1022};
1023#endif
1024
1025
1026/* initialize jack-sensing, too */
1027static int cxt5045_init(struct hda_codec *codec)
1028{
1029 conexant_init(codec);
1030 cxt5045_hp_automute(codec);
1031 return 0;
1032}
1033
1034
1035enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001036 CXT5045_LAPTOP_HPSENSE,
1037 CXT5045_LAPTOP_MICSENSE,
1038 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001039 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001040 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001041#ifdef CONFIG_SND_DEBUG
1042 CXT5045_TEST,
1043#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001044 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001045};
1046
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001047static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001048 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1049 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1050 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1051 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001052 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001053#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001054 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001056};
1057
1058static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001059 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001060 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1061 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001062 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001063 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001064 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1065 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001066 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1067 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001068 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1069 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1070 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001071 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1072 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001073 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001074 {}
1075};
1076
1077static int patch_cxt5045(struct hda_codec *codec)
1078{
1079 struct conexant_spec *spec;
1080 int board_config;
1081
1082 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1083 if (!spec)
1084 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001085 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001086 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001087
1088 spec->multiout.max_channels = 2;
1089 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1090 spec->multiout.dac_nids = cxt5045_dac_nids;
1091 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1092 spec->num_adc_nids = 1;
1093 spec->adc_nids = cxt5045_adc_nids;
1094 spec->capsrc_nids = cxt5045_capsrc_nids;
1095 spec->input_mux = &cxt5045_capture_source;
1096 spec->num_mixers = 1;
1097 spec->mixers[0] = cxt5045_mixers;
1098 spec->num_init_verbs = 1;
1099 spec->init_verbs[0] = cxt5045_init_verbs;
1100 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001101 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1102 spec->channel_mode = cxt5045_modes,
1103
Tobin Davisc9b443d2006-11-14 12:13:39 +01001104
1105 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001106
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001107 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1108 cxt5045_models,
1109 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001110 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001111 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001112 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113 spec->input_mux = &cxt5045_capture_source;
1114 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001115 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1116 spec->mixers[0] = cxt5045_mixers;
1117 codec->patch_ops.init = cxt5045_init;
1118 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001119 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001120 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001121 spec->input_mux = &cxt5045_capture_source;
1122 spec->num_init_verbs = 2;
1123 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001124 spec->mixers[0] = cxt5045_mixers;
1125 codec->patch_ops.init = cxt5045_init;
1126 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001127 default:
1128 case CXT5045_LAPTOP_HPMICSENSE:
1129 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1130 spec->input_mux = &cxt5045_capture_source;
1131 spec->num_init_verbs = 3;
1132 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1133 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1134 spec->mixers[0] = cxt5045_mixers;
1135 codec->patch_ops.init = cxt5045_init;
1136 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001137 case CXT5045_BENQ:
1138 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1139 spec->input_mux = &cxt5045_capture_source_benq;
1140 spec->num_init_verbs = 1;
1141 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1142 spec->mixers[0] = cxt5045_mixers;
1143 spec->mixers[1] = cxt5045_benq_mixers;
1144 spec->num_mixers = 2;
1145 codec->patch_ops.init = cxt5045_init;
1146 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001147 case CXT5045_LAPTOP_HP530:
1148 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1149 spec->input_mux = &cxt5045_capture_source_hp530;
1150 spec->num_init_verbs = 2;
1151 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1152 spec->mixers[0] = cxt5045_mixers_hp530;
1153 codec->patch_ops.init = cxt5045_init;
1154 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001155#ifdef CONFIG_SND_DEBUG
1156 case CXT5045_TEST:
1157 spec->input_mux = &cxt5045_test_capture_source;
1158 spec->mixers[0] = cxt5045_test_mixer;
1159 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001160 break;
1161
Tobin Davisc9b443d2006-11-14 12:13:39 +01001162#endif
1163 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001164
Takashi Iwai031005f2008-06-26 14:49:58 +02001165 switch (codec->subsystem_id >> 16) {
1166 case 0x103c:
1167 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1168 * Fix max PCM level to 0 dB
1169 * (originall it has 0x2b steps with 0dB offset 0x14)
1170 */
1171 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1172 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1173 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1174 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1175 (1 << AC_AMPCAP_MUTE_SHIFT));
1176 break;
1177 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001178
Tobin Davisc9b443d2006-11-14 12:13:39 +01001179 return 0;
1180}
1181
1182
1183/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001184#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001185
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001186static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1188static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001189
Tobin Davis5cd57522006-11-20 17:42:09 +01001190static struct hda_channel_mode cxt5047_modes[1] = {
1191 { 2, NULL },
1192};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193
Tobin Davis82f30042007-02-13 12:45:44 +01001194static struct hda_input_mux cxt5047_toshiba_capture_source = {
1195 .num_items = 2,
1196 .items = {
1197 { "ExtMic", 0x2 },
1198 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001199 }
1200};
1201
1202/* turn on/off EAPD (+ mute HP) as a master switch */
1203static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1204 struct snd_ctl_elem_value *ucontrol)
1205{
1206 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1207 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001208 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209
Tobin Davis82f30042007-02-13 12:45:44 +01001210 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001211 return 0;
1212
Tobin Davis82f30042007-02-13 12:45:44 +01001213 /* toggle internal speakers mute depending of presence of
1214 * the headphone jack
1215 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001216 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001217 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1218 * pin widgets unlike other codecs. In this case, we need to
1219 * set index 0x01 for the volume from the mixer amp 0x19.
1220 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001221 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001222 HDA_AMP_MUTE, bits);
1223 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1224 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1225 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001226 return 1;
1227}
1228
Tobin Davisc9b443d2006-11-14 12:13:39 +01001229/* mute internal speaker if HP is plugged */
1230static void cxt5047_hp_automute(struct hda_codec *codec)
1231{
Tobin Davis82f30042007-02-13 12:45:44 +01001232 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001233 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234
Tobin Davis82f30042007-02-13 12:45:44 +01001235 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001236 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001237
Takashi Iwai47fd8302007-08-10 17:11:07 +02001238 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001239 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001240 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001241 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242}
1243
1244/* toggle input of built-in and mic jack appropriately */
1245static void cxt5047_hp_automic(struct hda_codec *codec)
1246{
1247 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001248 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1249 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001250 {}
1251 };
1252 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001253 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1254 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001255 {}
1256 };
1257 unsigned int present;
1258
Tobin Davis7f296732007-03-12 11:39:01 +01001259 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001260 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1261 if (present)
1262 snd_hda_sequence_write(codec, mic_jack_on);
1263 else
1264 snd_hda_sequence_write(codec, mic_jack_off);
1265}
1266
1267/* unsolicited event for HP jack sensing */
1268static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1269 unsigned int res)
1270{
Marc Boucher9f113e02008-01-22 15:18:08 +01001271 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001272 case CONEXANT_HP_EVENT:
1273 cxt5047_hp_automute(codec);
1274 break;
1275 case CONEXANT_MIC_EVENT:
1276 cxt5047_hp_automic(codec);
1277 break;
1278 }
1279}
1280
Takashi Iwaidf481e42009-03-10 15:35:35 +01001281static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1282 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1283 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1284 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1286 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1287 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1288 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001289 {
1290 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1291 .name = "Master Playback Switch",
1292 .info = cxt_eapd_info,
1293 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001294 .put = cxt5047_hp_master_sw_put,
1295 .private_value = 0x13,
1296 },
1297
1298 {}
1299};
1300
Takashi Iwaidf481e42009-03-10 15:35:35 +01001301static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001302 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001303 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001304 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1305 {}
1306};
1307
1308static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001309 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001310 { } /* end */
1311};
1312
1313static struct hda_verb cxt5047_init_verbs[] = {
1314 /* Line in, Mic, Built-in Mic */
1315 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1316 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1317 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001318 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001319 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001320 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1321 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001322 /* Record selector: Mic */
1323 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1324 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1325 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1326 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1328 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1329 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1330 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001331 /* SPDIF route: PCM */
1332 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001333 /* Enable unsolicited events */
1334 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1335 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001336 { } /* end */
1337};
1338
1339/* configuration for Toshiba Laptops */
1340static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001341 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 {}
1343};
1344
1345/* Test configuration for debugging, modelled after the ALC260 test
1346 * configuration.
1347 */
1348#ifdef CONFIG_SND_DEBUG
1349static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001350 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001351 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001352 { "LINE1 pin", 0x0 },
1353 { "MIC1 pin", 0x1 },
1354 { "MIC2 pin", 0x2 },
1355 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001356 },
1357};
1358
1359static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1360
1361 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001362 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1368 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001370 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1372 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001374
1375 /* Modes for retasking pin widgets */
1376 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1377 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1378
Tobin Davis82f30042007-02-13 12:45:44 +01001379 /* EAPD Switch Control */
1380 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1381
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001383 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1384 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1385 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1386 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1387 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1388 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1389 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1390 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001391
Tobin Davis82f30042007-02-13 12:45:44 +01001392 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1393 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1394 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1395 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1396 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1397 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1398 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1399 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001400 {
1401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1402 .name = "Input Source",
1403 .info = conexant_mux_enum_info,
1404 .get = conexant_mux_enum_get,
1405 .put = conexant_mux_enum_put,
1406 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001407 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1408 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1409 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1410 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1411 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1412 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1413 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1414 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1415 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1416 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1417
Tobin Davisc9b443d2006-11-14 12:13:39 +01001418 { } /* end */
1419};
1420
1421static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001422 /* Enable retasking pins as output, initially without power amp */
1423 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1424 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1425 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426
1427 /* Disable digital (SPDIF) pins initially, but users can enable
1428 * them via a mixer switch. In the case of SPDIF-out, this initverb
1429 * payload also sets the generation to 0, output to be in "consumer"
1430 * PCM format, copyright asserted, no pre-emphasis and no validity
1431 * control.
1432 */
1433 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1434
1435 /* Ensure mic1, mic2, line1 pin widgets take input from the
1436 * OUT1 sum bus when acting as an output.
1437 */
1438 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1439 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1440
1441 /* Start with output sum widgets muted and their output gains at min */
1442 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1443 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1444
1445 /* Unmute retasking pin widget output buffers since the default
1446 * state appears to be output. As the pin mode is changed by the
1447 * user the pin mode control will take care of enabling the pin's
1448 * input/output buffers as needed.
1449 */
1450 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1451 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1452 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1453
1454 /* Mute capture amp left and right */
1455 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1456
1457 /* Set ADC connection select to match default mixer setting (mic1
1458 * pin)
1459 */
1460 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1461
1462 /* Mute all inputs to mixer widget (even unconnected ones) */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1468 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1470 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1471
1472 { }
1473};
1474#endif
1475
1476
1477/* initialize jack-sensing, too */
1478static int cxt5047_hp_init(struct hda_codec *codec)
1479{
1480 conexant_init(codec);
1481 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001482 return 0;
1483}
1484
1485
1486enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001487 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1488 CXT5047_LAPTOP_HP, /* Some HP laptops */
1489 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001490#ifdef CONFIG_SND_DEBUG
1491 CXT5047_TEST,
1492#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001493 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001494};
1495
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001496static const char *cxt5047_models[CXT5047_MODELS] = {
1497 [CXT5047_LAPTOP] = "laptop",
1498 [CXT5047_LAPTOP_HP] = "laptop-hp",
1499 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001500#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001501 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001502#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001503};
1504
1505static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001506 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001507 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1508 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001509 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001510 {}
1511};
1512
1513static int patch_cxt5047(struct hda_codec *codec)
1514{
1515 struct conexant_spec *spec;
1516 int board_config;
1517
1518 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1519 if (!spec)
1520 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001521 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001522 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001523
1524 spec->multiout.max_channels = 2;
1525 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1526 spec->multiout.dac_nids = cxt5047_dac_nids;
1527 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1528 spec->num_adc_nids = 1;
1529 spec->adc_nids = cxt5047_adc_nids;
1530 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001531 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001532 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001533 spec->num_init_verbs = 1;
1534 spec->init_verbs[0] = cxt5047_init_verbs;
1535 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001536 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1537 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538
1539 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001540
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001541 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1542 cxt5047_models,
1543 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544 switch (board_config) {
1545 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001546 spec->num_mixers = 2;
1547 spec->mixers[1] = cxt5047_hp_spk_mixers;
1548 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001549 break;
1550 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001551 spec->num_mixers = 2;
1552 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001553 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001554 codec->patch_ops.init = cxt5047_hp_init;
1555 break;
1556 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001557 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001558 spec->num_mixers = 2;
1559 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560 spec->num_init_verbs = 2;
1561 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001562 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001563 break;
1564#ifdef CONFIG_SND_DEBUG
1565 case CXT5047_TEST:
1566 spec->input_mux = &cxt5047_test_capture_source;
1567 spec->mixers[0] = cxt5047_test_mixer;
1568 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001569 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570#endif
1571 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001572 spec->vmaster_nid = 0x13;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001573 return 0;
1574}
1575
Takashi Iwai461e2c72008-01-25 11:35:17 +01001576/* Conexant 5051 specific */
1577static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1578static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001579
1580static struct hda_channel_mode cxt5051_modes[1] = {
1581 { 2, NULL },
1582};
1583
1584static void cxt5051_update_speaker(struct hda_codec *codec)
1585{
1586 struct conexant_spec *spec = codec->spec;
1587 unsigned int pinctl;
1588 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1589 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1590 pinctl);
1591}
1592
1593/* turn on/off EAPD (+ mute HP) as a master switch */
1594static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1595 struct snd_ctl_elem_value *ucontrol)
1596{
1597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1598
1599 if (!cxt_eapd_put(kcontrol, ucontrol))
1600 return 0;
1601 cxt5051_update_speaker(codec);
1602 return 1;
1603}
1604
1605/* toggle input of built-in and mic jack appropriately */
1606static void cxt5051_portb_automic(struct hda_codec *codec)
1607{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001608 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001609 unsigned int present;
1610
Takashi Iwai79d7d532009-03-04 09:03:50 +01001611 if (spec->no_auto_mic)
1612 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001613 present = snd_hda_codec_read(codec, 0x17, 0,
1614 AC_VERB_GET_PIN_SENSE, 0) &
1615 AC_PINSENSE_PRESENCE;
1616 snd_hda_codec_write(codec, 0x14, 0,
1617 AC_VERB_SET_CONNECT_SEL,
1618 present ? 0x01 : 0x00);
1619}
1620
1621/* switch the current ADC according to the jack state */
1622static void cxt5051_portc_automic(struct hda_codec *codec)
1623{
1624 struct conexant_spec *spec = codec->spec;
1625 unsigned int present;
1626 hda_nid_t new_adc;
1627
Takashi Iwai79d7d532009-03-04 09:03:50 +01001628 if (spec->no_auto_mic)
1629 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001630 present = snd_hda_codec_read(codec, 0x18, 0,
1631 AC_VERB_GET_PIN_SENSE, 0) &
1632 AC_PINSENSE_PRESENCE;
1633 if (present)
1634 spec->cur_adc_idx = 1;
1635 else
1636 spec->cur_adc_idx = 0;
1637 new_adc = spec->adc_nids[spec->cur_adc_idx];
1638 if (spec->cur_adc && spec->cur_adc != new_adc) {
1639 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001640 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001641 spec->cur_adc = new_adc;
1642 snd_hda_codec_setup_stream(codec, new_adc,
1643 spec->cur_adc_stream_tag, 0,
1644 spec->cur_adc_format);
1645 }
1646}
1647
1648/* mute internal speaker if HP is plugged */
1649static void cxt5051_hp_automute(struct hda_codec *codec)
1650{
1651 struct conexant_spec *spec = codec->spec;
1652
1653 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1654 AC_VERB_GET_PIN_SENSE, 0) &
1655 AC_PINSENSE_PRESENCE;
1656 cxt5051_update_speaker(codec);
1657}
1658
1659/* unsolicited event for HP jack sensing */
1660static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1661 unsigned int res)
1662{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001663 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001664 switch (res >> 26) {
1665 case CONEXANT_HP_EVENT:
1666 cxt5051_hp_automute(codec);
1667 break;
1668 case CXT5051_PORTB_EVENT:
1669 cxt5051_portb_automic(codec);
1670 break;
1671 case CXT5051_PORTC_EVENT:
1672 cxt5051_portc_automic(codec);
1673 break;
1674 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001675 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001676}
1677
1678static struct snd_kcontrol_new cxt5051_mixers[] = {
1679 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1680 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1681 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1682 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1683 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1684 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1685 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1686 {
1687 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1688 .name = "Master Playback Switch",
1689 .info = cxt_eapd_info,
1690 .get = cxt_eapd_get,
1691 .put = cxt5051_hp_master_sw_put,
1692 .private_value = 0x1a,
1693 },
1694
1695 {}
1696};
1697
1698static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1699 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1700 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1701 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1702 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1703 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1704 {
1705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1706 .name = "Master Playback Switch",
1707 .info = cxt_eapd_info,
1708 .get = cxt_eapd_get,
1709 .put = cxt5051_hp_master_sw_put,
1710 .private_value = 0x1a,
1711 },
1712
1713 {}
1714};
1715
Takashi Iwai79d7d532009-03-04 09:03:50 +01001716static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1717 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1718 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1719 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1720 {
1721 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1722 .name = "Master Playback Switch",
1723 .info = cxt_eapd_info,
1724 .get = cxt_eapd_get,
1725 .put = cxt5051_hp_master_sw_put,
1726 .private_value = 0x1a,
1727 },
1728
1729 {}
1730};
1731
Takashi Iwai461e2c72008-01-25 11:35:17 +01001732static struct hda_verb cxt5051_init_verbs[] = {
1733 /* Line in, Mic */
1734 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1735 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1736 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1737 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1738 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1739 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1740 /* SPK */
1741 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1742 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1743 /* HP, Amp */
1744 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1745 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1746 /* DAC1 */
1747 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1748 /* Record selector: Int mic */
1749 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1750 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1751 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1752 /* SPDIF route: PCM */
1753 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1754 /* EAPD */
1755 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1756 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1757 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1758 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1759 { } /* end */
1760};
1761
Takashi Iwai79d7d532009-03-04 09:03:50 +01001762static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1763 /* Line in, Mic */
1764 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1765 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1766 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1767 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1768 /* SPK */
1769 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1770 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1771 /* HP, Amp */
1772 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1773 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1774 /* DAC1 */
1775 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1776 /* Record selector: Int mic */
1777 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1778 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1779 /* SPDIF route: PCM */
1780 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1781 /* EAPD */
1782 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1783 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1784 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1785 { } /* end */
1786};
1787
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001788static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1789 /* Line in, Mic */
1790 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1791 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1792 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1793 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1794 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1795 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1796 /* SPK */
1797 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1798 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1799 /* HP, Amp */
1800 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1801 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1802 /* Docking HP */
1803 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1804 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1805 /* DAC1 */
1806 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1807 /* Record selector: Int mic */
1808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1810 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1811 /* SPDIF route: PCM */
1812 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1813 /* EAPD */
1814 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1815 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1816 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1817 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1818 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1819 { } /* end */
1820};
1821
Takashi Iwai461e2c72008-01-25 11:35:17 +01001822/* initialize jack-sensing, too */
1823static int cxt5051_init(struct hda_codec *codec)
1824{
1825 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001826 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001827 if (codec->patch_ops.unsol_event) {
1828 cxt5051_hp_automute(codec);
1829 cxt5051_portb_automic(codec);
1830 cxt5051_portc_automic(codec);
1831 }
1832 return 0;
1833}
1834
1835
1836enum {
1837 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1838 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001839 CXT5051_HP_DV6736, /* HP without mic switch */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001840 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001841 CXT5051_MODELS
1842};
1843
1844static const char *cxt5051_models[CXT5051_MODELS] = {
1845 [CXT5051_LAPTOP] = "laptop",
1846 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001847 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001848 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001849};
1850
1851static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001852 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001853 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001854 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1855 CXT5051_LAPTOP),
1856 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001857 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001858 {}
1859};
1860
1861static int patch_cxt5051(struct hda_codec *codec)
1862{
1863 struct conexant_spec *spec;
1864 int board_config;
1865
1866 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1867 if (!spec)
1868 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001869 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001870 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001871
1872 codec->patch_ops = conexant_patch_ops;
1873 codec->patch_ops.init = cxt5051_init;
1874
1875 spec->multiout.max_channels = 2;
1876 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1877 spec->multiout.dac_nids = cxt5051_dac_nids;
1878 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1879 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1880 spec->adc_nids = cxt5051_adc_nids;
1881 spec->num_mixers = 1;
1882 spec->mixers[0] = cxt5051_mixers;
1883 spec->num_init_verbs = 1;
1884 spec->init_verbs[0] = cxt5051_init_verbs;
1885 spec->spdif_route = 0;
1886 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1887 spec->channel_mode = cxt5051_modes;
1888 spec->cur_adc = 0;
1889 spec->cur_adc_idx = 0;
1890
Takashi Iwai79d7d532009-03-04 09:03:50 +01001891 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1892
Takashi Iwai461e2c72008-01-25 11:35:17 +01001893 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1894 cxt5051_models,
1895 cxt5051_cfg_tbl);
1896 switch (board_config) {
1897 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001898 spec->mixers[0] = cxt5051_hp_mixers;
1899 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001900 case CXT5051_HP_DV6736:
1901 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1902 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1903 spec->no_auto_mic = 1;
1904 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001905 case CXT5051_LENOVO_X200:
1906 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001907 break;
1908 }
1909
1910 return 0;
1911}
1912
Daniel Drake0fb67e92009-07-16 14:46:57 +01001913/* Conexant 5066 specific */
1914
1915static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1916static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1917static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1918#define CXT5066_SPDIF_OUT 0x21
1919
1920static struct hda_channel_mode cxt5066_modes[1] = {
1921 { 2, NULL },
1922};
1923
1924static void cxt5066_update_speaker(struct hda_codec *codec)
1925{
1926 struct conexant_spec *spec = codec->spec;
1927 unsigned int pinctl;
1928
1929 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1930 spec->hp_present);
1931
1932 /* Port A (HP) */
1933 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1934 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1935 pinctl);
1936
1937 /* Port D (HP/LO) */
1938 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1939 ? spec->port_d_mode : 0;
1940 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1941 pinctl);
1942
1943 /* CLASS_D AMP */
1944 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1945 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1946 pinctl);
1947
1948 if (spec->dell_automute) {
1949 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
1950 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1951 ? PIN_OUT : 0;
1952 snd_hda_codec_write(codec, 0x1c, 0,
1953 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1954 }
1955}
1956
1957/* turn on/off EAPD (+ mute HP) as a master switch */
1958static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1959 struct snd_ctl_elem_value *ucontrol)
1960{
1961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1962
1963 if (!cxt_eapd_put(kcontrol, ucontrol))
1964 return 0;
1965
1966 cxt5066_update_speaker(codec);
1967 return 1;
1968}
1969
1970/* toggle input of built-in and mic jack appropriately */
1971static void cxt5066_automic(struct hda_codec *codec)
1972{
1973 static struct hda_verb ext_mic_present[] = {
1974 /* enable external mic, port B */
1975 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1976
1977 /* switch to external mic input */
1978 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
1979
1980 /* disable internal mic, port C */
1981 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1982 {}
1983 };
1984 static struct hda_verb ext_mic_absent[] = {
1985 /* enable internal mic, port C */
1986 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1987
1988 /* switch to internal mic input */
1989 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
1990
1991 /* disable external mic, port B */
1992 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1993 {}
1994 };
1995 unsigned int present;
1996
1997 present = snd_hda_codec_read(codec, 0x1a, 0,
1998 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1999 if (present) {
2000 snd_printdd("CXT5066: external microphone detected\n");
2001 snd_hda_sequence_write(codec, ext_mic_present);
2002 } else {
2003 snd_printdd("CXT5066: external microphone absent\n");
2004 snd_hda_sequence_write(codec, ext_mic_absent);
2005 }
2006}
2007
2008/* mute internal speaker if HP is plugged */
2009static void cxt5066_hp_automute(struct hda_codec *codec)
2010{
2011 struct conexant_spec *spec = codec->spec;
2012 unsigned int portA, portD;
2013
2014 /* Port A */
2015 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0)
2016 & AC_PINSENSE_PRESENCE;
2017
2018 /* Port D */
2019 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0)
2020 & AC_PINSENSE_PRESENCE) << 1;
2021
2022 spec->hp_present = !!(portA | portD);
2023 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2024 portA, portD, spec->hp_present);
2025 cxt5066_update_speaker(codec);
2026}
2027
2028/* unsolicited event for jack sensing */
2029static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2030{
2031 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2032 switch (res >> 26) {
2033 case CONEXANT_HP_EVENT:
2034 cxt5066_hp_automute(codec);
2035 break;
2036 case CONEXANT_MIC_EVENT:
2037 cxt5066_automic(codec);
2038 break;
2039 }
2040}
2041
2042static const struct hda_input_mux cxt5066_analog_mic_boost = {
2043 .num_items = 5,
2044 .items = {
2045 { "0dB", 0 },
2046 { "10dB", 1 },
2047 { "20dB", 2 },
2048 { "30dB", 3 },
2049 { "40dB", 4 },
2050 },
2051};
2052
2053static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2054 struct snd_ctl_elem_info *uinfo)
2055{
2056 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2057}
2058
2059static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2060 struct snd_ctl_elem_value *ucontrol)
2061{
2062 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2063 int val;
2064
2065 val = snd_hda_codec_read(codec, 0x17, 0,
2066 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
2067
2068 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2069 return 0;
2070}
2071
2072static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2073 struct snd_ctl_elem_value *ucontrol)
2074{
2075 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2076 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2077 unsigned int idx;
2078
2079 if (!imux->num_items)
2080 return 0;
2081 idx = ucontrol->value.enumerated.item[0];
2082 if (idx >= imux->num_items)
2083 idx = imux->num_items - 1;
2084
2085 snd_hda_codec_write_cache(codec, 0x17, 0,
2086 AC_VERB_SET_AMP_GAIN_MUTE,
2087 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2088 imux->items[idx].index);
2089
2090 return 1;
2091}
2092
2093static struct hda_input_mux cxt5066_capture_source = {
2094 .num_items = 4,
2095 .items = {
2096 { "Mic B", 0 },
2097 { "Mic C", 1 },
2098 { "Mic E", 2 },
2099 { "Mic F", 3 },
2100 },
2101};
2102
2103static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2104 .ops = &snd_hda_bind_vol,
2105 .values = {
2106 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2107 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2108 0
2109 },
2110};
2111
2112static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2113 .ops = &snd_hda_bind_sw,
2114 .values = {
2115 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2116 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2117 0
2118 },
2119};
2120
2121static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2122 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2123 {}
2124};
2125
2126static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2127 {
2128 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2129 .name = "Master Playback Volume",
2130 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2131 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2132 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2133 .info = snd_hda_mixer_amp_volume_info,
2134 .get = snd_hda_mixer_amp_volume_get,
2135 .put = snd_hda_mixer_amp_volume_put,
2136 .tlv = { .c = snd_hda_mixer_amp_tlv },
2137 /* offset by 28 volume steps to limit minimum gain to -46dB */
2138 .private_value =
2139 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2140 },
2141 {}
2142};
2143
2144static struct snd_kcontrol_new cxt5066_mixers[] = {
2145 {
2146 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2147 .name = "Master Playback Switch",
2148 .info = cxt_eapd_info,
2149 .get = cxt_eapd_get,
2150 .put = cxt5066_hp_master_sw_put,
2151 .private_value = 0x1d,
2152 },
2153
2154 {
2155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2156 .name = "Analog Mic Boost Capture Enum",
2157 .info = cxt5066_mic_boost_mux_enum_info,
2158 .get = cxt5066_mic_boost_mux_enum_get,
2159 .put = cxt5066_mic_boost_mux_enum_put,
2160 },
2161
2162 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2163 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2164 {}
2165};
2166
2167static struct hda_verb cxt5066_init_verbs[] = {
2168 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2169 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2170 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2171 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2172
2173 /* Speakers */
2174 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2176
2177 /* HP, Amp */
2178 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2179 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2180
2181 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2182 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2183
2184 /* DAC1 */
2185 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2186
2187 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2188 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2189 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2190 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2191 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2192 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2193
2194 /* no digital microphone support yet */
2195 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2196
2197 /* Audio input selector */
2198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2199
2200 /* SPDIF route: PCM */
2201 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2202 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2203
2204 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2205 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2206
2207 /* EAPD */
2208 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2209
2210 /* not handling these yet */
2211 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2212 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2213 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2214 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2215 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2216 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2217 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2218 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2219 { } /* end */
2220};
2221
2222static struct hda_verb cxt5066_init_verbs_olpc[] = {
2223 /* Port A: headphones */
2224 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2225 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2226
2227 /* Port B: external microphone */
2228 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2229
2230 /* Port C: internal microphone */
2231 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2232
2233 /* Port D: unused */
2234 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2235
2236 /* Port E: unused, but has primary EAPD */
2237 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2239
2240 /* Port F: unused */
2241 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2242
2243 /* Port G: internal speakers */
2244 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2245 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2246
2247 /* DAC1 */
2248 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249
2250 /* DAC2: unused */
2251 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2252
2253 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2254 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2255 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2256 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2257 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2258 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2259 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2260 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2261 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2262 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2263 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2264 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2265
2266 /* Disable digital microphone port */
2267 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2268
2269 /* Audio input selectors */
2270 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2271 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2272
2273 /* Disable SPDIF */
2274 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2275 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2276
2277 /* enable unsolicited events for Port A and B */
2278 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2279 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2280 { } /* end */
2281};
2282
2283static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2284 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2285 { } /* end */
2286};
2287
2288/* initialize jack-sensing, too */
2289static int cxt5066_init(struct hda_codec *codec)
2290{
2291 snd_printdd("CXT5066: init\n");
2292 conexant_init(codec);
2293 if (codec->patch_ops.unsol_event) {
2294 cxt5066_hp_automute(codec);
2295 cxt5066_automic(codec);
2296 }
2297 return 0;
2298}
2299
2300enum {
2301 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2302 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2303 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2304 CXT5066_MODELS
2305};
2306
2307static const char *cxt5066_models[CXT5066_MODELS] = {
2308 [CXT5066_LAPTOP] = "laptop",
2309 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2310 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2311};
2312
2313static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2314 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2315 CXT5066_LAPTOP),
2316 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2317 CXT5066_DELL_LAPTOP),
2318 {}
2319};
2320
2321static int patch_cxt5066(struct hda_codec *codec)
2322{
2323 struct conexant_spec *spec;
2324 int board_config;
2325
2326 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2327 if (!spec)
2328 return -ENOMEM;
2329 codec->spec = spec;
2330
2331 codec->patch_ops = conexant_patch_ops;
2332 codec->patch_ops.init = cxt5066_init;
2333
2334 spec->dell_automute = 0;
2335 spec->multiout.max_channels = 2;
2336 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2337 spec->multiout.dac_nids = cxt5066_dac_nids;
2338 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2339 spec->num_adc_nids = 1;
2340 spec->adc_nids = cxt5066_adc_nids;
2341 spec->capsrc_nids = cxt5066_capsrc_nids;
2342 spec->input_mux = &cxt5066_capture_source;
2343
2344 spec->port_d_mode = PIN_HP;
2345
2346 spec->num_init_verbs = 1;
2347 spec->init_verbs[0] = cxt5066_init_verbs;
2348 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2349 spec->channel_mode = cxt5066_modes;
2350 spec->cur_adc = 0;
2351 spec->cur_adc_idx = 0;
2352
2353 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2354 cxt5066_models, cxt5066_cfg_tbl);
2355 switch (board_config) {
2356 default:
2357 case CXT5066_LAPTOP:
2358 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2359 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2360 break;
2361 case CXT5066_DELL_LAPTOP:
2362 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2363 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2364
2365 spec->port_d_mode = PIN_OUT;
2366 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2367 spec->num_init_verbs++;
2368 spec->dell_automute = 1;
2369 break;
2370 case CXT5066_OLPC_XO_1_5:
2371 codec->patch_ops.unsol_event = cxt5066_unsol_event;
2372 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2373 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2374 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2375 spec->port_d_mode = 0;
2376
2377 /* no S/PDIF out */
2378 spec->multiout.dig_out_nid = 0;
2379
2380 /* input source automatically selected */
2381 spec->input_mux = NULL;
2382 break;
2383 }
2384
2385 return 0;
2386}
Takashi Iwai461e2c72008-01-25 11:35:17 +01002387
2388/*
2389 */
2390
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002391static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01002392 { .id = 0x14f15045, .name = "CX20549 (Venice)",
2393 .patch = patch_cxt5045 },
2394 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2395 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01002396 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2397 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01002398 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2399 .patch = patch_cxt5066 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01002400 {} /* terminator */
2401};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002402
2403MODULE_ALIAS("snd-hda-codec-id:14f15045");
2404MODULE_ALIAS("snd-hda-codec-id:14f15047");
2405MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01002406MODULE_ALIAS("snd-hda-codec-id:14f15066");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002407
2408MODULE_LICENSE("GPL");
2409MODULE_DESCRIPTION("Conexant HD-audio codec");
2410
2411static struct hda_codec_preset_list conexant_list = {
2412 .preset = snd_hda_preset_conexant,
2413 .owner = THIS_MODULE,
2414};
2415
2416static int __init patch_conexant_init(void)
2417{
2418 return snd_hda_add_codec_preset(&conexant_list);
2419}
2420
2421static void __exit patch_conexant_exit(void)
2422{
2423 snd_hda_delete_codec_preset(&conexant_list);
2424}
2425
2426module_init(patch_conexant_init)
2427module_exit(patch_conexant_exit)