blob: e9e47574c613199f215e9d53b9df9c53388f57c5 [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
111};
112
113static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
114 struct hda_codec *codec,
115 struct snd_pcm_substream *substream)
116{
117 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100118 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
119 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100120}
121
122static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
123 struct hda_codec *codec,
124 unsigned int stream_tag,
125 unsigned int format,
126 struct snd_pcm_substream *substream)
127{
128 struct conexant_spec *spec = codec->spec;
129 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
130 stream_tag,
131 format, substream);
132}
133
134static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
135 struct hda_codec *codec,
136 struct snd_pcm_substream *substream)
137{
138 struct conexant_spec *spec = codec->spec;
139 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
140}
141
142/*
143 * Digital out
144 */
145static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
146 struct hda_codec *codec,
147 struct snd_pcm_substream *substream)
148{
149 struct conexant_spec *spec = codec->spec;
150 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
151}
152
153static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
154 struct hda_codec *codec,
155 struct snd_pcm_substream *substream)
156{
157 struct conexant_spec *spec = codec->spec;
158 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
159}
160
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200161static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
162 struct hda_codec *codec,
163 unsigned int stream_tag,
164 unsigned int format,
165 struct snd_pcm_substream *substream)
166{
167 struct conexant_spec *spec = codec->spec;
168 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
169 stream_tag,
170 format, substream);
171}
172
Tobin Davisc9b443d2006-11-14 12:13:39 +0100173/*
174 * Analog capture
175 */
176static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 unsigned int stream_tag,
179 unsigned int format,
180 struct snd_pcm_substream *substream)
181{
182 struct conexant_spec *spec = codec->spec;
183 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
184 stream_tag, 0, format);
185 return 0;
186}
187
188static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
190 struct snd_pcm_substream *substream)
191{
192 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100193 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100194 return 0;
195}
196
197
198
199static struct hda_pcm_stream conexant_pcm_analog_playback = {
200 .substreams = 1,
201 .channels_min = 2,
202 .channels_max = 2,
203 .nid = 0, /* fill later */
204 .ops = {
205 .open = conexant_playback_pcm_open,
206 .prepare = conexant_playback_pcm_prepare,
207 .cleanup = conexant_playback_pcm_cleanup
208 },
209};
210
211static struct hda_pcm_stream conexant_pcm_analog_capture = {
212 .substreams = 1,
213 .channels_min = 2,
214 .channels_max = 2,
215 .nid = 0, /* fill later */
216 .ops = {
217 .prepare = conexant_capture_pcm_prepare,
218 .cleanup = conexant_capture_pcm_cleanup
219 },
220};
221
222
223static struct hda_pcm_stream conexant_pcm_digital_playback = {
224 .substreams = 1,
225 .channels_min = 2,
226 .channels_max = 2,
227 .nid = 0, /* fill later */
228 .ops = {
229 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200230 .close = conexant_dig_playback_pcm_close,
231 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100232 },
233};
234
235static struct hda_pcm_stream conexant_pcm_digital_capture = {
236 .substreams = 1,
237 .channels_min = 2,
238 .channels_max = 2,
239 /* NID is set in alc_build_pcms */
240};
241
Takashi Iwai461e2c72008-01-25 11:35:17 +0100242static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
243 struct hda_codec *codec,
244 unsigned int stream_tag,
245 unsigned int format,
246 struct snd_pcm_substream *substream)
247{
248 struct conexant_spec *spec = codec->spec;
249 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
250 spec->cur_adc_stream_tag = stream_tag;
251 spec->cur_adc_format = format;
252 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
253 return 0;
254}
255
256static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
258 struct snd_pcm_substream *substream)
259{
260 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100261 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100262 spec->cur_adc = 0;
263 return 0;
264}
265
266static struct hda_pcm_stream cx5051_pcm_analog_capture = {
267 .substreams = 1,
268 .channels_min = 2,
269 .channels_max = 2,
270 .nid = 0, /* fill later */
271 .ops = {
272 .prepare = cx5051_capture_pcm_prepare,
273 .cleanup = cx5051_capture_pcm_cleanup
274 },
275};
276
Tobin Davisc9b443d2006-11-14 12:13:39 +0100277static int conexant_build_pcms(struct hda_codec *codec)
278{
279 struct conexant_spec *spec = codec->spec;
280 struct hda_pcm *info = spec->pcm_rec;
281
282 codec->num_pcms = 1;
283 codec->pcm_info = info;
284
285 info->name = "CONEXANT Analog";
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
288 spec->multiout.max_channels;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
290 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100291 if (codec->vendor_id == 0x14f15051)
292 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
293 cx5051_pcm_analog_capture;
294 else
295 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
296 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100297 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
298 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
299
300 if (spec->multiout.dig_out_nid) {
301 info++;
302 codec->num_pcms++;
303 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100304 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100305 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
306 conexant_pcm_digital_playback;
307 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
308 spec->multiout.dig_out_nid;
309 if (spec->dig_in_nid) {
310 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
311 conexant_pcm_digital_capture;
312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
313 spec->dig_in_nid;
314 }
315 }
316
317 return 0;
318}
319
320static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_info *uinfo)
322{
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct conexant_spec *spec = codec->spec;
325
326 return snd_hda_input_mux_info(spec->input_mux, uinfo);
327}
328
329static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_value *ucontrol)
331{
332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
333 struct conexant_spec *spec = codec->spec;
334 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
335
336 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
337 return 0;
338}
339
340static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_value *ucontrol)
342{
343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344 struct conexant_spec *spec = codec->spec;
345 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
346
347 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
348 spec->capsrc_nids[adc_idx],
349 &spec->cur_mux[adc_idx]);
350}
351
Takashi Iwai5801f992009-01-27 12:53:22 +0100352#ifdef CONFIG_SND_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100353static int conexant_add_jack(struct hda_codec *codec,
354 hda_nid_t nid, int type)
355{
356 struct conexant_spec *spec;
357 struct conexant_jack *jack;
358 const char *name;
359
360 spec = codec->spec;
361 snd_array_init(&spec->jacks, sizeof(*jack), 32);
362 jack = snd_array_new(&spec->jacks);
363 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
364
365 if (!jack)
366 return -ENOMEM;
367
368 jack->nid = nid;
369 jack->type = type;
370
371 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
372}
373
374static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
375{
376 struct conexant_spec *spec = codec->spec;
377 struct conexant_jack *jacks = spec->jacks.list;
378
379 if (jacks) {
380 int i;
381 for (i = 0; i < spec->jacks.used; i++) {
382 if (jacks->nid == nid) {
383 unsigned int present;
384 present = snd_hda_codec_read(codec, nid, 0,
385 AC_VERB_GET_PIN_SENSE, 0) &
386 AC_PINSENSE_PRESENCE;
387
388 present = (present) ? jacks->type : 0 ;
389
390 snd_jack_report(jacks->jack,
391 present);
392 }
393 jacks++;
394 }
395 }
396}
397
398static int conexant_init_jacks(struct hda_codec *codec)
399{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100400 struct conexant_spec *spec = codec->spec;
401 int i;
402
403 for (i = 0; i < spec->num_init_verbs; i++) {
404 const struct hda_verb *hv;
405
406 hv = spec->init_verbs[i];
407 while (hv->nid) {
408 int err = 0;
409 switch (hv->param ^ AC_USRSP_EN) {
410 case CONEXANT_HP_EVENT:
411 err = conexant_add_jack(codec, hv->nid,
412 SND_JACK_HEADPHONE);
413 conexant_report_jack(codec, hv->nid);
414 break;
415 case CXT5051_PORTC_EVENT:
416 case CONEXANT_MIC_EVENT:
417 err = conexant_add_jack(codec, hv->nid,
418 SND_JACK_MICROPHONE);
419 conexant_report_jack(codec, hv->nid);
420 break;
421 }
422 if (err < 0)
423 return err;
424 ++hv;
425 }
426 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100427 return 0;
428
429}
Takashi Iwai5801f992009-01-27 12:53:22 +0100430#else
431static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
432{
433}
434
435static inline int conexant_init_jacks(struct hda_codec *codec)
436{
437 return 0;
438}
439#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100440
Tobin Davisc9b443d2006-11-14 12:13:39 +0100441static int conexant_init(struct hda_codec *codec)
442{
443 struct conexant_spec *spec = codec->spec;
444 int i;
445
446 for (i = 0; i < spec->num_init_verbs; i++)
447 snd_hda_sequence_write(codec, spec->init_verbs[i]);
448 return 0;
449}
450
451static void conexant_free(struct hda_codec *codec)
452{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100453#ifdef CONFIG_SND_JACK
454 struct conexant_spec *spec = codec->spec;
455 if (spec->jacks.list) {
456 struct conexant_jack *jacks = spec->jacks.list;
457 int i;
458 for (i = 0; i < spec->jacks.used; i++)
459 snd_device_free(codec->bus->card, &jacks[i].jack);
460 snd_array_free(&spec->jacks);
461 }
462#endif
Tobin Davisc9b443d2006-11-14 12:13:39 +0100463 kfree(codec->spec);
464}
465
Takashi Iwaib880c742009-03-10 14:41:05 +0100466static struct snd_kcontrol_new cxt_capture_mixers[] = {
467 {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "Capture Source",
470 .info = conexant_mux_enum_info,
471 .get = conexant_mux_enum_get,
472 .put = conexant_mux_enum_put
473 },
474 {}
475};
476
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100477static const char *slave_vols[] = {
478 "Headphone Playback Volume",
479 "Speaker Playback Volume",
480 NULL
481};
482
483static const char *slave_sws[] = {
484 "Headphone Playback Switch",
485 "Speaker Playback Switch",
486 NULL
487};
488
Tobin Davisc9b443d2006-11-14 12:13:39 +0100489static int conexant_build_controls(struct hda_codec *codec)
490{
491 struct conexant_spec *spec = codec->spec;
492 unsigned int i;
493 int err;
494
495 for (i = 0; i < spec->num_mixers; i++) {
496 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
497 if (err < 0)
498 return err;
499 }
500 if (spec->multiout.dig_out_nid) {
501 err = snd_hda_create_spdif_out_ctls(codec,
502 spec->multiout.dig_out_nid);
503 if (err < 0)
504 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100505 err = snd_hda_create_spdif_share_sw(codec,
506 &spec->multiout);
507 if (err < 0)
508 return err;
509 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100510 }
511 if (spec->dig_in_nid) {
512 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
513 if (err < 0)
514 return err;
515 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100516
517 /* if we have no master control, let's create it */
518 if (spec->vmaster_nid &&
519 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
520 unsigned int vmaster_tlv[4];
521 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
522 HDA_OUTPUT, vmaster_tlv);
523 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
524 vmaster_tlv, slave_vols);
525 if (err < 0)
526 return err;
527 }
528 if (spec->vmaster_nid &&
529 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
530 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
531 NULL, slave_sws);
532 if (err < 0)
533 return err;
534 }
535
Takashi Iwaib880c742009-03-10 14:41:05 +0100536 if (spec->input_mux) {
537 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
538 if (err < 0)
539 return err;
540 }
541
Tobin Davisc9b443d2006-11-14 12:13:39 +0100542 return 0;
543}
544
545static struct hda_codec_ops conexant_patch_ops = {
546 .build_controls = conexant_build_controls,
547 .build_pcms = conexant_build_pcms,
548 .init = conexant_init,
549 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100550};
551
552/*
553 * EAPD control
554 * the private value = nid | (invert << 8)
555 */
556
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200557#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100558
Tobin Davis82f30042007-02-13 12:45:44 +0100559static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100560 struct snd_ctl_elem_value *ucontrol)
561{
562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
563 struct conexant_spec *spec = codec->spec;
564 int invert = (kcontrol->private_value >> 8) & 1;
565 if (invert)
566 ucontrol->value.integer.value[0] = !spec->cur_eapd;
567 else
568 ucontrol->value.integer.value[0] = spec->cur_eapd;
569 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100570
Tobin Davisc9b443d2006-11-14 12:13:39 +0100571}
572
Tobin Davis82f30042007-02-13 12:45:44 +0100573static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100574 struct snd_ctl_elem_value *ucontrol)
575{
576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
577 struct conexant_spec *spec = codec->spec;
578 int invert = (kcontrol->private_value >> 8) & 1;
579 hda_nid_t nid = kcontrol->private_value & 0xff;
580 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100581
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100582 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100583 if (invert)
584 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200585 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100586 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100587
Tobin Davisc9b443d2006-11-14 12:13:39 +0100588 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200589 snd_hda_codec_write_cache(codec, nid,
590 0, AC_VERB_SET_EAPD_BTLENABLE,
591 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100592 return 1;
593}
594
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100595/* controls for test mode */
596#ifdef CONFIG_SND_DEBUG
597
Tobin Davis82f30042007-02-13 12:45:44 +0100598#define CXT_EAPD_SWITCH(xname, nid, mask) \
599 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
600 .info = cxt_eapd_info, \
601 .get = cxt_eapd_get, \
602 .put = cxt_eapd_put, \
603 .private_value = nid | (mask<<16) }
604
605
606
Tobin Davisc9b443d2006-11-14 12:13:39 +0100607static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_info *uinfo)
609{
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct conexant_spec *spec = codec->spec;
612 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
613 spec->num_channel_mode);
614}
615
616static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol)
618{
619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620 struct conexant_spec *spec = codec->spec;
621 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
622 spec->num_channel_mode,
623 spec->multiout.max_channels);
624}
625
626static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_value *ucontrol)
628{
629 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630 struct conexant_spec *spec = codec->spec;
631 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
632 spec->num_channel_mode,
633 &spec->multiout.max_channels);
634 if (err >= 0 && spec->need_dac_fix)
635 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
636 return err;
637}
638
639#define CXT_PIN_MODE(xname, nid, dir) \
640 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
641 .info = conexant_ch_mode_info, \
642 .get = conexant_ch_mode_get, \
643 .put = conexant_ch_mode_put, \
644 .private_value = nid | (dir<<16) }
645
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100646#endif /* CONFIG_SND_DEBUG */
647
Tobin Davisc9b443d2006-11-14 12:13:39 +0100648/* Conexant 5045 specific */
649
650static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
651static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
652static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100653#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100654
Tobin Davis5cd57522006-11-20 17:42:09 +0100655static struct hda_channel_mode cxt5045_modes[1] = {
656 { 2, NULL },
657};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100658
659static struct hda_input_mux cxt5045_capture_source = {
660 .num_items = 2,
661 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100662 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100663 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100664 }
665};
666
Jiang Zhe5218c892008-01-17 11:18:41 +0100667static struct hda_input_mux cxt5045_capture_source_benq = {
668 .num_items = 3,
669 .items = {
670 { "IntMic", 0x1 },
671 { "ExtMic", 0x2 },
672 { "LineIn", 0x3 },
673 }
674};
675
Jiang zhe2de3c232008-03-06 11:09:09 +0100676static struct hda_input_mux cxt5045_capture_source_hp530 = {
677 .num_items = 2,
678 .items = {
679 { "ExtMic", 0x1 },
680 { "IntMic", 0x2 },
681 }
682};
683
Tobin Davisc9b443d2006-11-14 12:13:39 +0100684/* turn on/off EAPD (+ mute HP) as a master switch */
685static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol)
687{
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
689 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100690 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691
Tobin Davis82f30042007-02-13 12:45:44 +0100692 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100693 return 0;
694
Tobin Davis82f30042007-02-13 12:45:44 +0100695 /* toggle internal speakers mute depending of presence of
696 * the headphone jack
697 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200698 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
699 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
700 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100701
Takashi Iwai47fd8302007-08-10 17:11:07 +0200702 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
703 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
704 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100705 return 1;
706}
707
708/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200709static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
710 .ops = &snd_hda_bind_vol,
711 .values = {
712 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
713 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
714 0
715 },
716};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100717
Tobin Davis7f296732007-03-12 11:39:01 +0100718/* toggle input of built-in and mic jack appropriately */
719static void cxt5045_hp_automic(struct hda_codec *codec)
720{
721 static struct hda_verb mic_jack_on[] = {
722 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
724 {}
725 };
726 static struct hda_verb mic_jack_off[] = {
727 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
729 {}
730 };
731 unsigned int present;
732
733 present = snd_hda_codec_read(codec, 0x12, 0,
734 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
735 if (present)
736 snd_hda_sequence_write(codec, mic_jack_on);
737 else
738 snd_hda_sequence_write(codec, mic_jack_off);
739}
740
Tobin Davisc9b443d2006-11-14 12:13:39 +0100741
742/* mute internal speaker if HP is plugged */
743static void cxt5045_hp_automute(struct hda_codec *codec)
744{
Tobin Davis82f30042007-02-13 12:45:44 +0100745 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100746 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100747
Tobin Davis82f30042007-02-13 12:45:44 +0100748 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100749 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100750
Takashi Iwai47fd8302007-08-10 17:11:07 +0200751 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
752 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
753 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100754}
755
756/* unsolicited event for HP jack sensing */
757static void cxt5045_hp_unsol_event(struct hda_codec *codec,
758 unsigned int res)
759{
760 res >>= 26;
761 switch (res) {
762 case CONEXANT_HP_EVENT:
763 cxt5045_hp_automute(codec);
764 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100765 case CONEXANT_MIC_EVENT:
766 cxt5045_hp_automic(codec);
767 break;
768
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769 }
770}
771
772static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200773 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
774 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
775 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
776 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
777 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
778 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
779 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
780 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
781 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
782 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200783 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784 {
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100787 .info = cxt_eapd_info,
788 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100789 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100790 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100791 },
792
793 {}
794};
795
Jiang Zhe5218c892008-01-17 11:18:41 +0100796static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
797 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
798 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
799 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
800 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
801
802 {}
803};
804
Jiang zhe2de3c232008-03-06 11:09:09 +0100805static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100806 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
807 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
808 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
809 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
810 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
811 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
812 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
813 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
814 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
815 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
816 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
817 {
818 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
819 .name = "Master Playback Switch",
820 .info = cxt_eapd_info,
821 .get = cxt_eapd_get,
822 .put = cxt5045_hp_master_sw_put,
823 .private_value = 0x10,
824 },
825
826 {}
827};
828
Tobin Davisc9b443d2006-11-14 12:13:39 +0100829static struct hda_verb cxt5045_init_verbs[] = {
830 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200831 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100832 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100833 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200834 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
835 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
836 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
837 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
838 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
839 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
840 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
841 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
842 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100843 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100844 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100845 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100846 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
847 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100848 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100849 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100850 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100851 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100852 { } /* end */
853};
854
Jiang Zhe5218c892008-01-17 11:18:41 +0100855static struct hda_verb cxt5045_benq_init_verbs[] = {
856 /* Int Mic, Mic */
857 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
858 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
859 /* Line In,HP, Amp */
860 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
861 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
862 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
863 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
864 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
865 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
867 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
868 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
869 /* Record selector: Int mic */
870 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
871 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
872 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
873 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100874 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100875 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
876 /* EAPD */
877 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
878 { } /* end */
879};
Tobin Davis7f296732007-03-12 11:39:01 +0100880
881static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
882 /* pin sensing on HP jack */
883 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200884 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100885};
886
887static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
888 /* pin sensing on HP jack */
889 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200890 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100891};
892
Tobin Davisc9b443d2006-11-14 12:13:39 +0100893#ifdef CONFIG_SND_DEBUG
894/* Test configuration for debugging, modelled after the ALC260 test
895 * configuration.
896 */
897static struct hda_input_mux cxt5045_test_capture_source = {
898 .num_items = 5,
899 .items = {
900 { "MIXER", 0x0 },
901 { "MIC1 pin", 0x1 },
902 { "LINE1 pin", 0x2 },
903 { "HP-OUT pin", 0x3 },
904 { "CD pin", 0x4 },
905 },
906};
907
908static struct snd_kcontrol_new cxt5045_test_mixer[] = {
909
910 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100911 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
912 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100913 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
914 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
915 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
916 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100917
918 /* Modes for retasking pin widgets */
919 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
920 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
921
Tobin Davis82f30042007-02-13 12:45:44 +0100922 /* EAPD Switch Control */
923 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
924
Tobin Davisc9b443d2006-11-14 12:13:39 +0100925 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926
Tobin Davis7f296732007-03-12 11:39:01 +0100927 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
928 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
929 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
930 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
931 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
932 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
933 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
934 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
935 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
936 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100937 {
938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
939 .name = "Input Source",
940 .info = conexant_mux_enum_info,
941 .get = conexant_mux_enum_get,
942 .put = conexant_mux_enum_put,
943 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200944 /* Audio input controls */
945 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
946 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
947 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
948 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
949 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
950 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
951 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
952 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
953 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
954 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100955 { } /* end */
956};
957
958static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100959 /* Set connections */
960 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
961 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
962 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100963 /* Enable retasking pins as output, initially without power amp */
964 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100965 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100966
967 /* Disable digital (SPDIF) pins initially, but users can enable
968 * them via a mixer switch. In the case of SPDIF-out, this initverb
969 * payload also sets the generation to 0, output to be in "consumer"
970 * PCM format, copyright asserted, no pre-emphasis and no validity
971 * control.
972 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100973 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
974 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100975
976 /* Start with output sum widgets muted and their output gains at min */
977 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
978 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
979
980 /* Unmute retasking pin widget output buffers since the default
981 * state appears to be output. As the pin mode is changed by the
982 * user the pin mode control will take care of enabling the pin's
983 * input/output buffers as needed.
984 */
985 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
986 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
987
988 /* Mute capture amp left and right */
989 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
990
991 /* Set ADC connection select to match default mixer setting (mic1
992 * pin)
993 */
994 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100995 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100996
997 /* Mute all inputs to mixer widget (even unconnected ones) */
998 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
999 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1000 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1001 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1003
1004 { }
1005};
1006#endif
1007
1008
1009/* initialize jack-sensing, too */
1010static int cxt5045_init(struct hda_codec *codec)
1011{
1012 conexant_init(codec);
1013 cxt5045_hp_automute(codec);
1014 return 0;
1015}
1016
1017
1018enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001019 CXT5045_LAPTOP_HPSENSE,
1020 CXT5045_LAPTOP_MICSENSE,
1021 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001022 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001023 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001024#ifdef CONFIG_SND_DEBUG
1025 CXT5045_TEST,
1026#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001027 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001028};
1029
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001030static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001031 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1032 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1033 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1034 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001035 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001036#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001037 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001038#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001039};
1040
1041static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001042 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001043 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1044 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001045 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001046 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001047 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1048 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001049 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1050 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001051 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1052 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1053 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001054 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1055 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001056 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001057 {}
1058};
1059
1060static int patch_cxt5045(struct hda_codec *codec)
1061{
1062 struct conexant_spec *spec;
1063 int board_config;
1064
1065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1066 if (!spec)
1067 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001068 codec->spec = spec;
1069
1070 spec->multiout.max_channels = 2;
1071 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1072 spec->multiout.dac_nids = cxt5045_dac_nids;
1073 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1074 spec->num_adc_nids = 1;
1075 spec->adc_nids = cxt5045_adc_nids;
1076 spec->capsrc_nids = cxt5045_capsrc_nids;
1077 spec->input_mux = &cxt5045_capture_source;
1078 spec->num_mixers = 1;
1079 spec->mixers[0] = cxt5045_mixers;
1080 spec->num_init_verbs = 1;
1081 spec->init_verbs[0] = cxt5045_init_verbs;
1082 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001083 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1084 spec->channel_mode = cxt5045_modes,
1085
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086
1087 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001088
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001089 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1090 cxt5045_models,
1091 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001092 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001093 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001094 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001095 spec->input_mux = &cxt5045_capture_source;
1096 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001097 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1098 spec->mixers[0] = cxt5045_mixers;
1099 codec->patch_ops.init = cxt5045_init;
1100 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001101 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001102 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001103 spec->input_mux = &cxt5045_capture_source;
1104 spec->num_init_verbs = 2;
1105 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001106 spec->mixers[0] = cxt5045_mixers;
1107 codec->patch_ops.init = cxt5045_init;
1108 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001109 default:
1110 case CXT5045_LAPTOP_HPMICSENSE:
1111 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1112 spec->input_mux = &cxt5045_capture_source;
1113 spec->num_init_verbs = 3;
1114 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1115 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1116 spec->mixers[0] = cxt5045_mixers;
1117 codec->patch_ops.init = cxt5045_init;
1118 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001119 case CXT5045_BENQ:
1120 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1121 spec->input_mux = &cxt5045_capture_source_benq;
1122 spec->num_init_verbs = 1;
1123 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1124 spec->mixers[0] = cxt5045_mixers;
1125 spec->mixers[1] = cxt5045_benq_mixers;
1126 spec->num_mixers = 2;
1127 codec->patch_ops.init = cxt5045_init;
1128 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001129 case CXT5045_LAPTOP_HP530:
1130 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131 spec->input_mux = &cxt5045_capture_source_hp530;
1132 spec->num_init_verbs = 2;
1133 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1134 spec->mixers[0] = cxt5045_mixers_hp530;
1135 codec->patch_ops.init = cxt5045_init;
1136 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137#ifdef CONFIG_SND_DEBUG
1138 case CXT5045_TEST:
1139 spec->input_mux = &cxt5045_test_capture_source;
1140 spec->mixers[0] = cxt5045_test_mixer;
1141 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001142 break;
1143
Tobin Davisc9b443d2006-11-14 12:13:39 +01001144#endif
1145 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001146
Takashi Iwai031005f2008-06-26 14:49:58 +02001147 switch (codec->subsystem_id >> 16) {
1148 case 0x103c:
1149 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1150 * Fix max PCM level to 0 dB
1151 * (originall it has 0x2b steps with 0dB offset 0x14)
1152 */
1153 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1154 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1155 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1156 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1157 (1 << AC_AMPCAP_MUTE_SHIFT));
1158 break;
1159 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001160
Tobin Davisc9b443d2006-11-14 12:13:39 +01001161 return 0;
1162}
1163
1164
1165/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001166#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001167
Tobin Davis82f30042007-02-13 12:45:44 +01001168static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001169static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1170static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001171
Tobin Davis5cd57522006-11-20 17:42:09 +01001172static struct hda_channel_mode cxt5047_modes[1] = {
1173 { 2, NULL },
1174};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001175
Tobin Davis82f30042007-02-13 12:45:44 +01001176static struct hda_input_mux cxt5047_toshiba_capture_source = {
1177 .num_items = 2,
1178 .items = {
1179 { "ExtMic", 0x2 },
1180 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181 }
1182};
1183
1184/* turn on/off EAPD (+ mute HP) as a master switch */
1185static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1186 struct snd_ctl_elem_value *ucontrol)
1187{
1188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1189 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001190 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191
Tobin Davis82f30042007-02-13 12:45:44 +01001192 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193 return 0;
1194
Tobin Davis82f30042007-02-13 12:45:44 +01001195 /* toggle internal speakers mute depending of presence of
1196 * the headphone jack
1197 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001198 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1199 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1200 HDA_AMP_MUTE, bits);
1201 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1202 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1203 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001204 return 1;
1205}
1206
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207/* mute internal speaker if HP is plugged */
1208static void cxt5047_hp_automute(struct hda_codec *codec)
1209{
Tobin Davis82f30042007-02-13 12:45:44 +01001210 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001211 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001212
Tobin Davis82f30042007-02-13 12:45:44 +01001213 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001214 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001215
Takashi Iwai47fd8302007-08-10 17:11:07 +02001216 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1217 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1218 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001219 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001220 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1221 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001222}
1223
Tobin Davisfb3409e2007-05-17 09:40:47 +02001224/* mute internal speaker if HP is plugged */
1225static void cxt5047_hp2_automute(struct hda_codec *codec)
1226{
1227 struct conexant_spec *spec = codec->spec;
1228 unsigned int bits;
1229
1230 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1231 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1232
Takashi Iwai47fd8302007-08-10 17:11:07 +02001233 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1234 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1235 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001236 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001237 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1238 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001239}
1240
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241/* toggle input of built-in and mic jack appropriately */
1242static void cxt5047_hp_automic(struct hda_codec *codec)
1243{
1244 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001245 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1246 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247 {}
1248 };
1249 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001250 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1251 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001252 {}
1253 };
1254 unsigned int present;
1255
Tobin Davis7f296732007-03-12 11:39:01 +01001256 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1258 if (present)
1259 snd_hda_sequence_write(codec, mic_jack_on);
1260 else
1261 snd_hda_sequence_write(codec, mic_jack_off);
1262}
1263
1264/* unsolicited event for HP jack sensing */
1265static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1266 unsigned int res)
1267{
Marc Boucher9f113e02008-01-22 15:18:08 +01001268 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001269 case CONEXANT_HP_EVENT:
1270 cxt5047_hp_automute(codec);
1271 break;
1272 case CONEXANT_MIC_EVENT:
1273 cxt5047_hp_automic(codec);
1274 break;
1275 }
1276}
1277
Tobin Davisfb3409e2007-05-17 09:40:47 +02001278/* unsolicited event for HP jack sensing - non-EAPD systems */
1279static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1280 unsigned int res)
1281{
1282 res >>= 26;
1283 switch (res) {
1284 case CONEXANT_HP_EVENT:
1285 cxt5047_hp2_automute(codec);
1286 break;
1287 case CONEXANT_MIC_EVENT:
1288 cxt5047_hp_automic(codec);
1289 break;
1290 }
1291}
1292
Tobin Davisc9b443d2006-11-14 12:13:39 +01001293static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001294 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1295 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001296 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1297 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001298 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1299 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1300 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1301 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001302 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1303 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001304 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1305 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1306 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1307 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001308
1309 {}
1310};
1311
1312static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001313 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1315 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1316 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1317 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1318 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001319 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1320 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001321 {
1322 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1323 .name = "Master Playback Switch",
1324 .info = cxt_eapd_info,
1325 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001326 .put = cxt5047_hp_master_sw_put,
1327 .private_value = 0x13,
1328 },
1329
1330 {}
1331};
1332
1333static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001334 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1335 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1336 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1337 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1340 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1341 {
1342 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1343 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001344 .info = cxt_eapd_info,
1345 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 .put = cxt5047_hp_master_sw_put,
1347 .private_value = 0x13,
1348 },
1349 { } /* end */
1350};
1351
1352static struct hda_verb cxt5047_init_verbs[] = {
1353 /* Line in, Mic, Built-in Mic */
1354 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1355 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1356 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001357 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001358 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1359 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001360 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1361 /* Record selector: Mic */
1362 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1363 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1365 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1367 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1368 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1369 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370 /* SPDIF route: PCM */
1371 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001372 /* Enable unsolicited events */
1373 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1374 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001375 { } /* end */
1376};
1377
1378/* configuration for Toshiba Laptops */
1379static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001380 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davis82f30042007-02-13 12:45:44 +01001381 /* Speaker routing */
Takashi Iwai3b628862009-03-10 14:53:54 +01001382 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001383 {}
1384};
1385
1386/* configuration for HP Laptops */
1387static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001388 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001389 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001390 /* 0x13 is actually shared by both HP and speaker;
1391 * setting the connection to 0 (=0x19) makes the master volume control
1392 * working mysteriouslly...
1393 */
1394 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001395 /* Record selector: Ext Mic */
1396 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001397 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1398 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1399 /* Speaker routing */
1400 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001401 {}
1402};
1403
1404/* Test configuration for debugging, modelled after the ALC260 test
1405 * configuration.
1406 */
1407#ifdef CONFIG_SND_DEBUG
1408static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001409 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001411 { "LINE1 pin", 0x0 },
1412 { "MIC1 pin", 0x1 },
1413 { "MIC2 pin", 0x2 },
1414 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 },
1416};
1417
1418static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1419
1420 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001421 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1423 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001425 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001429 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001433
1434 /* Modes for retasking pin widgets */
1435 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1436 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1437
Tobin Davis82f30042007-02-13 12:45:44 +01001438 /* EAPD Switch Control */
1439 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1440
Tobin Davisc9b443d2006-11-14 12:13:39 +01001441 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001442 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1443 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1444 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1445 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1446 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1447 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1448 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1449 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001450
Tobin Davis82f30042007-02-13 12:45:44 +01001451 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1452 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1453 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1454 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1455 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1456 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1457 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1458 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001459 {
1460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1461 .name = "Input Source",
1462 .info = conexant_mux_enum_info,
1463 .get = conexant_mux_enum_get,
1464 .put = conexant_mux_enum_put,
1465 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001466 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1467 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1468 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1469 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1470 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1471 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1472 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1473 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1474 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1475 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1476
Tobin Davisc9b443d2006-11-14 12:13:39 +01001477 { } /* end */
1478};
1479
1480static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481 /* Enable retasking pins as output, initially without power amp */
1482 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1483 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1484 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1485
1486 /* Disable digital (SPDIF) pins initially, but users can enable
1487 * them via a mixer switch. In the case of SPDIF-out, this initverb
1488 * payload also sets the generation to 0, output to be in "consumer"
1489 * PCM format, copyright asserted, no pre-emphasis and no validity
1490 * control.
1491 */
1492 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1493
1494 /* Ensure mic1, mic2, line1 pin widgets take input from the
1495 * OUT1 sum bus when acting as an output.
1496 */
1497 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1498 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1499
1500 /* Start with output sum widgets muted and their output gains at min */
1501 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1502 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1503
1504 /* Unmute retasking pin widget output buffers since the default
1505 * state appears to be output. As the pin mode is changed by the
1506 * user the pin mode control will take care of enabling the pin's
1507 * input/output buffers as needed.
1508 */
1509 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1510 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1511 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1512
1513 /* Mute capture amp left and right */
1514 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1515
1516 /* Set ADC connection select to match default mixer setting (mic1
1517 * pin)
1518 */
1519 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1520
1521 /* Mute all inputs to mixer widget (even unconnected ones) */
1522 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1523 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1524 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1530
1531 { }
1532};
1533#endif
1534
1535
1536/* initialize jack-sensing, too */
1537static int cxt5047_hp_init(struct hda_codec *codec)
1538{
1539 conexant_init(codec);
1540 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001541 return 0;
1542}
1543
1544
1545enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001546 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1547 CXT5047_LAPTOP_HP, /* Some HP laptops */
1548 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001549#ifdef CONFIG_SND_DEBUG
1550 CXT5047_TEST,
1551#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001552 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553};
1554
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001555static const char *cxt5047_models[CXT5047_MODELS] = {
1556 [CXT5047_LAPTOP] = "laptop",
1557 [CXT5047_LAPTOP_HP] = "laptop-hp",
1558 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001559#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001560 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001561#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001562};
1563
1564static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001565 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001566 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1567 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001568 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001569 {}
1570};
1571
1572static int patch_cxt5047(struct hda_codec *codec)
1573{
1574 struct conexant_spec *spec;
1575 int board_config;
1576
1577 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1578 if (!spec)
1579 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580 codec->spec = spec;
1581
1582 spec->multiout.max_channels = 2;
1583 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1584 spec->multiout.dac_nids = cxt5047_dac_nids;
1585 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1586 spec->num_adc_nids = 1;
1587 spec->adc_nids = cxt5047_adc_nids;
1588 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001589 spec->num_mixers = 1;
1590 spec->mixers[0] = cxt5047_mixers;
1591 spec->num_init_verbs = 1;
1592 spec->init_verbs[0] = cxt5047_init_verbs;
1593 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001594 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1595 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596
1597 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001598
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001599 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1600 cxt5047_models,
1601 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001602 switch (board_config) {
1603 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001604 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001605 break;
1606 case CXT5047_LAPTOP_HP:
Tobin Davisc9b443d2006-11-14 12:13:39 +01001607 spec->num_init_verbs = 2;
1608 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1609 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001610 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001611 codec->patch_ops.init = cxt5047_hp_init;
1612 break;
1613 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001614 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001615 spec->num_init_verbs = 2;
1616 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001617 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001618 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001619 break;
1620#ifdef CONFIG_SND_DEBUG
1621 case CXT5047_TEST:
1622 spec->input_mux = &cxt5047_test_capture_source;
1623 spec->mixers[0] = cxt5047_test_mixer;
1624 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001625 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001626#endif
1627 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001628 spec->vmaster_nid = 0x13;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001629 return 0;
1630}
1631
Takashi Iwai461e2c72008-01-25 11:35:17 +01001632/* Conexant 5051 specific */
1633static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1634static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001635
1636static struct hda_channel_mode cxt5051_modes[1] = {
1637 { 2, NULL },
1638};
1639
1640static void cxt5051_update_speaker(struct hda_codec *codec)
1641{
1642 struct conexant_spec *spec = codec->spec;
1643 unsigned int pinctl;
1644 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1645 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1646 pinctl);
1647}
1648
1649/* turn on/off EAPD (+ mute HP) as a master switch */
1650static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1651 struct snd_ctl_elem_value *ucontrol)
1652{
1653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1654
1655 if (!cxt_eapd_put(kcontrol, ucontrol))
1656 return 0;
1657 cxt5051_update_speaker(codec);
1658 return 1;
1659}
1660
1661/* toggle input of built-in and mic jack appropriately */
1662static void cxt5051_portb_automic(struct hda_codec *codec)
1663{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001664 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001665 unsigned int present;
1666
Takashi Iwai79d7d532009-03-04 09:03:50 +01001667 if (spec->no_auto_mic)
1668 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001669 present = snd_hda_codec_read(codec, 0x17, 0,
1670 AC_VERB_GET_PIN_SENSE, 0) &
1671 AC_PINSENSE_PRESENCE;
1672 snd_hda_codec_write(codec, 0x14, 0,
1673 AC_VERB_SET_CONNECT_SEL,
1674 present ? 0x01 : 0x00);
1675}
1676
1677/* switch the current ADC according to the jack state */
1678static void cxt5051_portc_automic(struct hda_codec *codec)
1679{
1680 struct conexant_spec *spec = codec->spec;
1681 unsigned int present;
1682 hda_nid_t new_adc;
1683
Takashi Iwai79d7d532009-03-04 09:03:50 +01001684 if (spec->no_auto_mic)
1685 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001686 present = snd_hda_codec_read(codec, 0x18, 0,
1687 AC_VERB_GET_PIN_SENSE, 0) &
1688 AC_PINSENSE_PRESENCE;
1689 if (present)
1690 spec->cur_adc_idx = 1;
1691 else
1692 spec->cur_adc_idx = 0;
1693 new_adc = spec->adc_nids[spec->cur_adc_idx];
1694 if (spec->cur_adc && spec->cur_adc != new_adc) {
1695 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001696 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001697 spec->cur_adc = new_adc;
1698 snd_hda_codec_setup_stream(codec, new_adc,
1699 spec->cur_adc_stream_tag, 0,
1700 spec->cur_adc_format);
1701 }
1702}
1703
1704/* mute internal speaker if HP is plugged */
1705static void cxt5051_hp_automute(struct hda_codec *codec)
1706{
1707 struct conexant_spec *spec = codec->spec;
1708
1709 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1710 AC_VERB_GET_PIN_SENSE, 0) &
1711 AC_PINSENSE_PRESENCE;
1712 cxt5051_update_speaker(codec);
1713}
1714
1715/* unsolicited event for HP jack sensing */
1716static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1717 unsigned int res)
1718{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001719 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001720 switch (res >> 26) {
1721 case CONEXANT_HP_EVENT:
1722 cxt5051_hp_automute(codec);
1723 break;
1724 case CXT5051_PORTB_EVENT:
1725 cxt5051_portb_automic(codec);
1726 break;
1727 case CXT5051_PORTC_EVENT:
1728 cxt5051_portc_automic(codec);
1729 break;
1730 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001731 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001732}
1733
1734static struct snd_kcontrol_new cxt5051_mixers[] = {
1735 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1737 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1738 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1739 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1740 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1741 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1742 {
1743 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1744 .name = "Master Playback Switch",
1745 .info = cxt_eapd_info,
1746 .get = cxt_eapd_get,
1747 .put = cxt5051_hp_master_sw_put,
1748 .private_value = 0x1a,
1749 },
1750
1751 {}
1752};
1753
1754static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1755 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1756 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1757 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1758 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1759 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1760 {
1761 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1762 .name = "Master Playback Switch",
1763 .info = cxt_eapd_info,
1764 .get = cxt_eapd_get,
1765 .put = cxt5051_hp_master_sw_put,
1766 .private_value = 0x1a,
1767 },
1768
1769 {}
1770};
1771
Takashi Iwai79d7d532009-03-04 09:03:50 +01001772static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1773 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1774 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1775 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1776 {
1777 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1778 .name = "Master Playback Switch",
1779 .info = cxt_eapd_info,
1780 .get = cxt_eapd_get,
1781 .put = cxt5051_hp_master_sw_put,
1782 .private_value = 0x1a,
1783 },
1784
1785 {}
1786};
1787
Takashi Iwai461e2c72008-01-25 11:35:17 +01001788static struct hda_verb cxt5051_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 /* DAC1 */
1803 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1804 /* Record selector: Int mic */
1805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1807 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1808 /* SPDIF route: PCM */
1809 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1810 /* EAPD */
1811 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1812 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1813 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1814 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1815 { } /* end */
1816};
1817
Takashi Iwai79d7d532009-03-04 09:03:50 +01001818static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1819 /* Line in, Mic */
1820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1821 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1822 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1823 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1824 /* SPK */
1825 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1826 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1827 /* HP, Amp */
1828 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1829 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1830 /* DAC1 */
1831 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1832 /* Record selector: Int mic */
1833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1834 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1835 /* SPDIF route: PCM */
1836 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1837 /* EAPD */
1838 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1839 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1840 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1841 { } /* end */
1842};
1843
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001844static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1845 /* Line in, Mic */
1846 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1847 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1848 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1849 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1850 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1851 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1852 /* SPK */
1853 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1854 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1855 /* HP, Amp */
1856 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1857 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1858 /* Docking HP */
1859 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1860 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1861 /* DAC1 */
1862 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1863 /* Record selector: Int mic */
1864 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1866 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1867 /* SPDIF route: PCM */
1868 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1869 /* EAPD */
1870 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1871 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1872 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1873 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1874 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1875 { } /* end */
1876};
1877
Takashi Iwai461e2c72008-01-25 11:35:17 +01001878/* initialize jack-sensing, too */
1879static int cxt5051_init(struct hda_codec *codec)
1880{
1881 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001882 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001883 if (codec->patch_ops.unsol_event) {
1884 cxt5051_hp_automute(codec);
1885 cxt5051_portb_automic(codec);
1886 cxt5051_portc_automic(codec);
1887 }
1888 return 0;
1889}
1890
1891
1892enum {
1893 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1894 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001895 CXT5051_HP_DV6736, /* HP without mic switch */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001896 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001897 CXT5051_MODELS
1898};
1899
1900static const char *cxt5051_models[CXT5051_MODELS] = {
1901 [CXT5051_LAPTOP] = "laptop",
1902 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001903 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001904 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001905};
1906
1907static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001908 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001909 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1910 CXT5051_LAPTOP),
1911 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001912 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001913 {}
1914};
1915
1916static int patch_cxt5051(struct hda_codec *codec)
1917{
1918 struct conexant_spec *spec;
1919 int board_config;
1920
1921 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1922 if (!spec)
1923 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001924 codec->spec = spec;
1925
1926 codec->patch_ops = conexant_patch_ops;
1927 codec->patch_ops.init = cxt5051_init;
1928
1929 spec->multiout.max_channels = 2;
1930 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1931 spec->multiout.dac_nids = cxt5051_dac_nids;
1932 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1933 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1934 spec->adc_nids = cxt5051_adc_nids;
1935 spec->num_mixers = 1;
1936 spec->mixers[0] = cxt5051_mixers;
1937 spec->num_init_verbs = 1;
1938 spec->init_verbs[0] = cxt5051_init_verbs;
1939 spec->spdif_route = 0;
1940 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1941 spec->channel_mode = cxt5051_modes;
1942 spec->cur_adc = 0;
1943 spec->cur_adc_idx = 0;
1944
Takashi Iwai79d7d532009-03-04 09:03:50 +01001945 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1946
Takashi Iwai461e2c72008-01-25 11:35:17 +01001947 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1948 cxt5051_models,
1949 cxt5051_cfg_tbl);
1950 switch (board_config) {
1951 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001952 spec->mixers[0] = cxt5051_hp_mixers;
1953 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001954 case CXT5051_HP_DV6736:
1955 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1956 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1957 spec->no_auto_mic = 1;
1958 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001959 case CXT5051_LENOVO_X200:
1960 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001961 break;
1962 }
1963
1964 return 0;
1965}
1966
1967
1968/*
1969 */
1970
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001971static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001972 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1973 .patch = patch_cxt5045 },
1974 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1975 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001976 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1977 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001978 {} /* terminator */
1979};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001980
1981MODULE_ALIAS("snd-hda-codec-id:14f15045");
1982MODULE_ALIAS("snd-hda-codec-id:14f15047");
1983MODULE_ALIAS("snd-hda-codec-id:14f15051");
1984
1985MODULE_LICENSE("GPL");
1986MODULE_DESCRIPTION("Conexant HD-audio codec");
1987
1988static struct hda_codec_preset_list conexant_list = {
1989 .preset = snd_hda_preset_conexant,
1990 .owner = THIS_MODULE,
1991};
1992
1993static int __init patch_conexant_init(void)
1994{
1995 return snd_hda_add_codec_preset(&conexant_list);
1996}
1997
1998static void __exit patch_conexant_exit(void)
1999{
2000 snd_hda_delete_codec_preset(&conexant_list);
2001}
2002
2003module_init(patch_conexant_init)
2004module_exit(patch_conexant_exit)