blob: ac868c59f9e334ad0dad50b00f0bb77b9bf59cdb [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 Iwai8c8145b2009-06-22 17:00:38 +0200352#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200353static void conexant_free_jack_priv(struct snd_jack *jack)
354{
355 struct conexant_jack *jacks = jack->private_data;
356 jacks->nid = 0;
357 jacks->jack = NULL;
358}
359
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100360static int conexant_add_jack(struct hda_codec *codec,
361 hda_nid_t nid, int type)
362{
363 struct conexant_spec *spec;
364 struct conexant_jack *jack;
365 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200366 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100367
368 spec = codec->spec;
369 snd_array_init(&spec->jacks, sizeof(*jack), 32);
370 jack = snd_array_new(&spec->jacks);
371 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
372
373 if (!jack)
374 return -ENOMEM;
375
376 jack->nid = nid;
377 jack->type = type;
378
Takashi Iwai95c09092009-04-14 16:15:29 +0200379 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
380 if (err < 0)
381 return err;
382 jack->jack->private_data = jack;
383 jack->jack->private_free = conexant_free_jack_priv;
384 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100385}
386
387static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
388{
389 struct conexant_spec *spec = codec->spec;
390 struct conexant_jack *jacks = spec->jacks.list;
391
392 if (jacks) {
393 int i;
394 for (i = 0; i < spec->jacks.used; i++) {
395 if (jacks->nid == nid) {
396 unsigned int present;
397 present = snd_hda_codec_read(codec, nid, 0,
398 AC_VERB_GET_PIN_SENSE, 0) &
399 AC_PINSENSE_PRESENCE;
400
401 present = (present) ? jacks->type : 0 ;
402
403 snd_jack_report(jacks->jack,
404 present);
405 }
406 jacks++;
407 }
408 }
409}
410
411static int conexant_init_jacks(struct hda_codec *codec)
412{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100413 struct conexant_spec *spec = codec->spec;
414 int i;
415
416 for (i = 0; i < spec->num_init_verbs; i++) {
417 const struct hda_verb *hv;
418
419 hv = spec->init_verbs[i];
420 while (hv->nid) {
421 int err = 0;
422 switch (hv->param ^ AC_USRSP_EN) {
423 case CONEXANT_HP_EVENT:
424 err = conexant_add_jack(codec, hv->nid,
425 SND_JACK_HEADPHONE);
426 conexant_report_jack(codec, hv->nid);
427 break;
428 case CXT5051_PORTC_EVENT:
429 case CONEXANT_MIC_EVENT:
430 err = conexant_add_jack(codec, hv->nid,
431 SND_JACK_MICROPHONE);
432 conexant_report_jack(codec, hv->nid);
433 break;
434 }
435 if (err < 0)
436 return err;
437 ++hv;
438 }
439 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100440 return 0;
441
442}
Takashi Iwai5801f992009-01-27 12:53:22 +0100443#else
444static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
445{
446}
447
448static inline int conexant_init_jacks(struct hda_codec *codec)
449{
450 return 0;
451}
452#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100453
Tobin Davisc9b443d2006-11-14 12:13:39 +0100454static int conexant_init(struct hda_codec *codec)
455{
456 struct conexant_spec *spec = codec->spec;
457 int i;
458
459 for (i = 0; i < spec->num_init_verbs; i++)
460 snd_hda_sequence_write(codec, spec->init_verbs[i]);
461 return 0;
462}
463
464static void conexant_free(struct hda_codec *codec)
465{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200466#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100467 struct conexant_spec *spec = codec->spec;
468 if (spec->jacks.list) {
469 struct conexant_jack *jacks = spec->jacks.list;
470 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200471 for (i = 0; i < spec->jacks.used; i++, jacks++) {
472 if (jacks->jack)
473 snd_device_free(codec->bus->card, jacks->jack);
474 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100475 snd_array_free(&spec->jacks);
476 }
477#endif
Tobin Davisc9b443d2006-11-14 12:13:39 +0100478 kfree(codec->spec);
479}
480
Takashi Iwaib880c742009-03-10 14:41:05 +0100481static struct snd_kcontrol_new cxt_capture_mixers[] = {
482 {
483 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
484 .name = "Capture Source",
485 .info = conexant_mux_enum_info,
486 .get = conexant_mux_enum_get,
487 .put = conexant_mux_enum_put
488 },
489 {}
490};
491
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100492static const char *slave_vols[] = {
493 "Headphone Playback Volume",
494 "Speaker Playback Volume",
495 NULL
496};
497
498static const char *slave_sws[] = {
499 "Headphone Playback Switch",
500 "Speaker Playback Switch",
501 NULL
502};
503
Tobin Davisc9b443d2006-11-14 12:13:39 +0100504static int conexant_build_controls(struct hda_codec *codec)
505{
506 struct conexant_spec *spec = codec->spec;
507 unsigned int i;
508 int err;
509
510 for (i = 0; i < spec->num_mixers; i++) {
511 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
512 if (err < 0)
513 return err;
514 }
515 if (spec->multiout.dig_out_nid) {
516 err = snd_hda_create_spdif_out_ctls(codec,
517 spec->multiout.dig_out_nid);
518 if (err < 0)
519 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100520 err = snd_hda_create_spdif_share_sw(codec,
521 &spec->multiout);
522 if (err < 0)
523 return err;
524 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100525 }
526 if (spec->dig_in_nid) {
527 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
528 if (err < 0)
529 return err;
530 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100531
532 /* if we have no master control, let's create it */
533 if (spec->vmaster_nid &&
534 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
535 unsigned int vmaster_tlv[4];
536 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
537 HDA_OUTPUT, vmaster_tlv);
538 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
539 vmaster_tlv, slave_vols);
540 if (err < 0)
541 return err;
542 }
543 if (spec->vmaster_nid &&
544 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
545 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
546 NULL, slave_sws);
547 if (err < 0)
548 return err;
549 }
550
Takashi Iwaib880c742009-03-10 14:41:05 +0100551 if (spec->input_mux) {
552 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
553 if (err < 0)
554 return err;
555 }
556
Tobin Davisc9b443d2006-11-14 12:13:39 +0100557 return 0;
558}
559
560static struct hda_codec_ops conexant_patch_ops = {
561 .build_controls = conexant_build_controls,
562 .build_pcms = conexant_build_pcms,
563 .init = conexant_init,
564 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100565};
566
567/*
568 * EAPD control
569 * the private value = nid | (invert << 8)
570 */
571
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200572#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100573
Tobin Davis82f30042007-02-13 12:45:44 +0100574static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100575 struct snd_ctl_elem_value *ucontrol)
576{
577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
578 struct conexant_spec *spec = codec->spec;
579 int invert = (kcontrol->private_value >> 8) & 1;
580 if (invert)
581 ucontrol->value.integer.value[0] = !spec->cur_eapd;
582 else
583 ucontrol->value.integer.value[0] = spec->cur_eapd;
584 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100585
Tobin Davisc9b443d2006-11-14 12:13:39 +0100586}
587
Tobin Davis82f30042007-02-13 12:45:44 +0100588static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100589 struct snd_ctl_elem_value *ucontrol)
590{
591 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
592 struct conexant_spec *spec = codec->spec;
593 int invert = (kcontrol->private_value >> 8) & 1;
594 hda_nid_t nid = kcontrol->private_value & 0xff;
595 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100596
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100597 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598 if (invert)
599 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200600 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100602
Tobin Davisc9b443d2006-11-14 12:13:39 +0100603 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200604 snd_hda_codec_write_cache(codec, nid,
605 0, AC_VERB_SET_EAPD_BTLENABLE,
606 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100607 return 1;
608}
609
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100610/* controls for test mode */
611#ifdef CONFIG_SND_DEBUG
612
Tobin Davis82f30042007-02-13 12:45:44 +0100613#define CXT_EAPD_SWITCH(xname, nid, mask) \
614 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
615 .info = cxt_eapd_info, \
616 .get = cxt_eapd_get, \
617 .put = cxt_eapd_put, \
618 .private_value = nid | (mask<<16) }
619
620
621
Tobin Davisc9b443d2006-11-14 12:13:39 +0100622static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
623 struct snd_ctl_elem_info *uinfo)
624{
625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626 struct conexant_spec *spec = codec->spec;
627 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
628 spec->num_channel_mode);
629}
630
631static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_value *ucontrol)
633{
634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
635 struct conexant_spec *spec = codec->spec;
636 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
637 spec->num_channel_mode,
638 spec->multiout.max_channels);
639}
640
641static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
642 struct snd_ctl_elem_value *ucontrol)
643{
644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645 struct conexant_spec *spec = codec->spec;
646 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
647 spec->num_channel_mode,
648 &spec->multiout.max_channels);
649 if (err >= 0 && spec->need_dac_fix)
650 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
651 return err;
652}
653
654#define CXT_PIN_MODE(xname, nid, dir) \
655 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
656 .info = conexant_ch_mode_info, \
657 .get = conexant_ch_mode_get, \
658 .put = conexant_ch_mode_put, \
659 .private_value = nid | (dir<<16) }
660
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100661#endif /* CONFIG_SND_DEBUG */
662
Tobin Davisc9b443d2006-11-14 12:13:39 +0100663/* Conexant 5045 specific */
664
665static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
666static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
667static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100668#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100669
Tobin Davis5cd57522006-11-20 17:42:09 +0100670static struct hda_channel_mode cxt5045_modes[1] = {
671 { 2, NULL },
672};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100673
674static struct hda_input_mux cxt5045_capture_source = {
675 .num_items = 2,
676 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100677 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100678 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100679 }
680};
681
Jiang Zhe5218c892008-01-17 11:18:41 +0100682static struct hda_input_mux cxt5045_capture_source_benq = {
683 .num_items = 3,
684 .items = {
685 { "IntMic", 0x1 },
686 { "ExtMic", 0x2 },
687 { "LineIn", 0x3 },
688 }
689};
690
Jiang zhe2de3c232008-03-06 11:09:09 +0100691static struct hda_input_mux cxt5045_capture_source_hp530 = {
692 .num_items = 2,
693 .items = {
694 { "ExtMic", 0x1 },
695 { "IntMic", 0x2 },
696 }
697};
698
Tobin Davisc9b443d2006-11-14 12:13:39 +0100699/* turn on/off EAPD (+ mute HP) as a master switch */
700static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
701 struct snd_ctl_elem_value *ucontrol)
702{
703 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
704 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100705 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100706
Tobin Davis82f30042007-02-13 12:45:44 +0100707 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100708 return 0;
709
Tobin Davis82f30042007-02-13 12:45:44 +0100710 /* toggle internal speakers mute depending of presence of
711 * the headphone jack
712 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200713 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
714 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
715 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100716
Takashi Iwai47fd8302007-08-10 17:11:07 +0200717 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
718 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
719 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100720 return 1;
721}
722
723/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200724static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
725 .ops = &snd_hda_bind_vol,
726 .values = {
727 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
728 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
729 0
730 },
731};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100732
Tobin Davis7f296732007-03-12 11:39:01 +0100733/* toggle input of built-in and mic jack appropriately */
734static void cxt5045_hp_automic(struct hda_codec *codec)
735{
736 static struct hda_verb mic_jack_on[] = {
737 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
738 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
739 {}
740 };
741 static struct hda_verb mic_jack_off[] = {
742 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
744 {}
745 };
746 unsigned int present;
747
748 present = snd_hda_codec_read(codec, 0x12, 0,
749 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
750 if (present)
751 snd_hda_sequence_write(codec, mic_jack_on);
752 else
753 snd_hda_sequence_write(codec, mic_jack_off);
754}
755
Tobin Davisc9b443d2006-11-14 12:13:39 +0100756
757/* mute internal speaker if HP is plugged */
758static void cxt5045_hp_automute(struct hda_codec *codec)
759{
Tobin Davis82f30042007-02-13 12:45:44 +0100760 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100761 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100762
Tobin Davis82f30042007-02-13 12:45:44 +0100763 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100764 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100765
Takashi Iwai47fd8302007-08-10 17:11:07 +0200766 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
767 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
768 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769}
770
771/* unsolicited event for HP jack sensing */
772static void cxt5045_hp_unsol_event(struct hda_codec *codec,
773 unsigned int res)
774{
775 res >>= 26;
776 switch (res) {
777 case CONEXANT_HP_EVENT:
778 cxt5045_hp_automute(codec);
779 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100780 case CONEXANT_MIC_EVENT:
781 cxt5045_hp_automic(codec);
782 break;
783
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784 }
785}
786
787static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200788 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
789 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
790 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
791 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
792 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
793 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
794 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
795 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
796 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
797 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200798 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100799 {
800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
801 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100802 .info = cxt_eapd_info,
803 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100804 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100805 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100806 },
807
808 {}
809};
810
Jiang Zhe5218c892008-01-17 11:18:41 +0100811static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
812 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
813 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
814 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
815 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
816
817 {}
818};
819
Jiang zhe2de3c232008-03-06 11:09:09 +0100820static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100821 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
822 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
823 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
824 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
825 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
826 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
827 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
828 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
829 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
830 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
831 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
832 {
833 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
834 .name = "Master Playback Switch",
835 .info = cxt_eapd_info,
836 .get = cxt_eapd_get,
837 .put = cxt5045_hp_master_sw_put,
838 .private_value = 0x10,
839 },
840
841 {}
842};
843
Tobin Davisc9b443d2006-11-14 12:13:39 +0100844static struct hda_verb cxt5045_init_verbs[] = {
845 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200846 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100847 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100848 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200849 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
850 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
851 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
852 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
853 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
854 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
857 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100858 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100859 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100860 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100861 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
862 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100863 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100864 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100865 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100866 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100867 { } /* end */
868};
869
Jiang Zhe5218c892008-01-17 11:18:41 +0100870static struct hda_verb cxt5045_benq_init_verbs[] = {
871 /* Int Mic, Mic */
872 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
873 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
874 /* Line In,HP, Amp */
875 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
876 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
877 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
878 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
881 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
884 /* Record selector: Int mic */
885 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
886 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
887 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
888 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100889 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100890 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
891 /* EAPD */
892 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
893 { } /* end */
894};
Tobin Davis7f296732007-03-12 11:39:01 +0100895
896static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
897 /* pin sensing on HP jack */
898 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200899 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100900};
901
902static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
903 /* pin sensing on HP jack */
904 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200905 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100906};
907
Tobin Davisc9b443d2006-11-14 12:13:39 +0100908#ifdef CONFIG_SND_DEBUG
909/* Test configuration for debugging, modelled after the ALC260 test
910 * configuration.
911 */
912static struct hda_input_mux cxt5045_test_capture_source = {
913 .num_items = 5,
914 .items = {
915 { "MIXER", 0x0 },
916 { "MIC1 pin", 0x1 },
917 { "LINE1 pin", 0x2 },
918 { "HP-OUT pin", 0x3 },
919 { "CD pin", 0x4 },
920 },
921};
922
923static struct snd_kcontrol_new cxt5045_test_mixer[] = {
924
925 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
927 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100928 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
929 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
930 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
931 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932
933 /* Modes for retasking pin widgets */
934 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
935 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
936
Tobin Davis82f30042007-02-13 12:45:44 +0100937 /* EAPD Switch Control */
938 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
939
Tobin Davisc9b443d2006-11-14 12:13:39 +0100940 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941
Tobin Davis7f296732007-03-12 11:39:01 +0100942 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
943 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
944 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
945 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
946 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
947 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
948 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
949 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
950 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
951 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952 {
953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
954 .name = "Input Source",
955 .info = conexant_mux_enum_info,
956 .get = conexant_mux_enum_get,
957 .put = conexant_mux_enum_put,
958 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200959 /* Audio input controls */
960 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
961 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
962 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
963 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
964 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
965 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
966 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
967 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
968 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
969 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100970 { } /* end */
971};
972
973static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100974 /* Set connections */
975 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
976 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
977 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100978 /* Enable retasking pins as output, initially without power amp */
979 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100980 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100981
982 /* Disable digital (SPDIF) pins initially, but users can enable
983 * them via a mixer switch. In the case of SPDIF-out, this initverb
984 * payload also sets the generation to 0, output to be in "consumer"
985 * PCM format, copyright asserted, no pre-emphasis and no validity
986 * control.
987 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100988 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
989 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990
991 /* Start with output sum widgets muted and their output gains at min */
992 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
993 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
994
995 /* Unmute retasking pin widget output buffers since the default
996 * state appears to be output. As the pin mode is changed by the
997 * user the pin mode control will take care of enabling the pin's
998 * input/output buffers as needed.
999 */
1000 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1001 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1002
1003 /* Mute capture amp left and right */
1004 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1005
1006 /* Set ADC connection select to match default mixer setting (mic1
1007 * pin)
1008 */
1009 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001010 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001011
1012 /* Mute all inputs to mixer widget (even unconnected ones) */
1013 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1014 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1015 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1017 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1018
1019 { }
1020};
1021#endif
1022
1023
1024/* initialize jack-sensing, too */
1025static int cxt5045_init(struct hda_codec *codec)
1026{
1027 conexant_init(codec);
1028 cxt5045_hp_automute(codec);
1029 return 0;
1030}
1031
1032
1033enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001034 CXT5045_LAPTOP_HPSENSE,
1035 CXT5045_LAPTOP_MICSENSE,
1036 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001037 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001038 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001039#ifdef CONFIG_SND_DEBUG
1040 CXT5045_TEST,
1041#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001042 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001043};
1044
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001045static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001046 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1047 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1048 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1049 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001050 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001051#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001052 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001053#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001054};
1055
1056static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001057 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001058 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1059 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001060 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001061 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001062 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1063 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001064 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1065 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001066 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1067 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1068 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001069 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1070 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001071 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072 {}
1073};
1074
1075static int patch_cxt5045(struct hda_codec *codec)
1076{
1077 struct conexant_spec *spec;
1078 int board_config;
1079
1080 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1081 if (!spec)
1082 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001083 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001084 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001085
1086 spec->multiout.max_channels = 2;
1087 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1088 spec->multiout.dac_nids = cxt5045_dac_nids;
1089 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1090 spec->num_adc_nids = 1;
1091 spec->adc_nids = cxt5045_adc_nids;
1092 spec->capsrc_nids = cxt5045_capsrc_nids;
1093 spec->input_mux = &cxt5045_capture_source;
1094 spec->num_mixers = 1;
1095 spec->mixers[0] = cxt5045_mixers;
1096 spec->num_init_verbs = 1;
1097 spec->init_verbs[0] = cxt5045_init_verbs;
1098 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001099 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1100 spec->channel_mode = cxt5045_modes,
1101
Tobin Davisc9b443d2006-11-14 12:13:39 +01001102
1103 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001104
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001105 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1106 cxt5045_models,
1107 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001108 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001109 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001110 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111 spec->input_mux = &cxt5045_capture_source;
1112 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001113 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1114 spec->mixers[0] = cxt5045_mixers;
1115 codec->patch_ops.init = cxt5045_init;
1116 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001117 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001118 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001119 spec->input_mux = &cxt5045_capture_source;
1120 spec->num_init_verbs = 2;
1121 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001122 spec->mixers[0] = cxt5045_mixers;
1123 codec->patch_ops.init = cxt5045_init;
1124 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001125 default:
1126 case CXT5045_LAPTOP_HPMICSENSE:
1127 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1128 spec->input_mux = &cxt5045_capture_source;
1129 spec->num_init_verbs = 3;
1130 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1131 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1132 spec->mixers[0] = cxt5045_mixers;
1133 codec->patch_ops.init = cxt5045_init;
1134 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001135 case CXT5045_BENQ:
1136 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1137 spec->input_mux = &cxt5045_capture_source_benq;
1138 spec->num_init_verbs = 1;
1139 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1140 spec->mixers[0] = cxt5045_mixers;
1141 spec->mixers[1] = cxt5045_benq_mixers;
1142 spec->num_mixers = 2;
1143 codec->patch_ops.init = cxt5045_init;
1144 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001145 case CXT5045_LAPTOP_HP530:
1146 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1147 spec->input_mux = &cxt5045_capture_source_hp530;
1148 spec->num_init_verbs = 2;
1149 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1150 spec->mixers[0] = cxt5045_mixers_hp530;
1151 codec->patch_ops.init = cxt5045_init;
1152 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001153#ifdef CONFIG_SND_DEBUG
1154 case CXT5045_TEST:
1155 spec->input_mux = &cxt5045_test_capture_source;
1156 spec->mixers[0] = cxt5045_test_mixer;
1157 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001158 break;
1159
Tobin Davisc9b443d2006-11-14 12:13:39 +01001160#endif
1161 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001162
Takashi Iwai031005f2008-06-26 14:49:58 +02001163 switch (codec->subsystem_id >> 16) {
1164 case 0x103c:
1165 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1166 * Fix max PCM level to 0 dB
1167 * (originall it has 0x2b steps with 0dB offset 0x14)
1168 */
1169 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1170 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1171 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1172 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1173 (1 << AC_AMPCAP_MUTE_SHIFT));
1174 break;
1175 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001176
Tobin Davisc9b443d2006-11-14 12:13:39 +01001177 return 0;
1178}
1179
1180
1181/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001182#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001183
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001184static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001185static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1186static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187
Tobin Davis5cd57522006-11-20 17:42:09 +01001188static struct hda_channel_mode cxt5047_modes[1] = {
1189 { 2, NULL },
1190};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191
Tobin Davis82f30042007-02-13 12:45:44 +01001192static struct hda_input_mux cxt5047_toshiba_capture_source = {
1193 .num_items = 2,
1194 .items = {
1195 { "ExtMic", 0x2 },
1196 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197 }
1198};
1199
1200/* turn on/off EAPD (+ mute HP) as a master switch */
1201static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1202 struct snd_ctl_elem_value *ucontrol)
1203{
1204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1205 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001206 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207
Tobin Davis82f30042007-02-13 12:45:44 +01001208 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209 return 0;
1210
Tobin Davis82f30042007-02-13 12:45:44 +01001211 /* toggle internal speakers mute depending of presence of
1212 * the headphone jack
1213 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001214 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001215 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1216 * pin widgets unlike other codecs. In this case, we need to
1217 * set index 0x01 for the volume from the mixer amp 0x19.
1218 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001219 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001220 HDA_AMP_MUTE, bits);
1221 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1222 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1223 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001224 return 1;
1225}
1226
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227/* mute internal speaker if HP is plugged */
1228static void cxt5047_hp_automute(struct hda_codec *codec)
1229{
Tobin Davis82f30042007-02-13 12:45:44 +01001230 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001231 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001232
Tobin Davis82f30042007-02-13 12:45:44 +01001233 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001235
Takashi Iwai47fd8302007-08-10 17:11:07 +02001236 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001237 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001238 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001239 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001240}
1241
1242/* toggle input of built-in and mic jack appropriately */
1243static void cxt5047_hp_automic(struct hda_codec *codec)
1244{
1245 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001246 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1247 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001248 {}
1249 };
1250 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001251 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1252 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 {}
1254 };
1255 unsigned int present;
1256
Tobin Davis7f296732007-03-12 11:39:01 +01001257 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001258 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1259 if (present)
1260 snd_hda_sequence_write(codec, mic_jack_on);
1261 else
1262 snd_hda_sequence_write(codec, mic_jack_off);
1263}
1264
1265/* unsolicited event for HP jack sensing */
1266static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1267 unsigned int res)
1268{
Marc Boucher9f113e02008-01-22 15:18:08 +01001269 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001270 case CONEXANT_HP_EVENT:
1271 cxt5047_hp_automute(codec);
1272 break;
1273 case CONEXANT_MIC_EVENT:
1274 cxt5047_hp_automic(codec);
1275 break;
1276 }
1277}
1278
Takashi Iwaidf481e42009-03-10 15:35:35 +01001279static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1280 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1281 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1282 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1284 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1285 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1286 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001287 {
1288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1289 .name = "Master Playback Switch",
1290 .info = cxt_eapd_info,
1291 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001292 .put = cxt5047_hp_master_sw_put,
1293 .private_value = 0x13,
1294 },
1295
1296 {}
1297};
1298
Takashi Iwaidf481e42009-03-10 15:35:35 +01001299static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001300 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001301 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001302 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1303 {}
1304};
1305
1306static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001307 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001308 { } /* end */
1309};
1310
1311static struct hda_verb cxt5047_init_verbs[] = {
1312 /* Line in, Mic, Built-in Mic */
1313 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1314 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1315 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001316 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001317 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001318 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1319 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001320 /* Record selector: Mic */
1321 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1322 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1323 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1324 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1326 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1327 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1328 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001329 /* SPDIF route: PCM */
1330 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001331 /* Enable unsolicited events */
1332 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1333 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001334 { } /* end */
1335};
1336
1337/* configuration for Toshiba Laptops */
1338static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001339 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340 {}
1341};
1342
1343/* Test configuration for debugging, modelled after the ALC260 test
1344 * configuration.
1345 */
1346#ifdef CONFIG_SND_DEBUG
1347static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001348 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001349 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001350 { "LINE1 pin", 0x0 },
1351 { "MIC1 pin", 0x1 },
1352 { "MIC2 pin", 0x2 },
1353 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001354 },
1355};
1356
1357static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1358
1359 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001360 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1362 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001364 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1366 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001368 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372
1373 /* Modes for retasking pin widgets */
1374 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1375 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1376
Tobin Davis82f30042007-02-13 12:45:44 +01001377 /* EAPD Switch Control */
1378 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1379
Tobin Davisc9b443d2006-11-14 12:13:39 +01001380 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001381 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1382 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1383 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1384 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1385 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1386 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1387 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1388 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001389
Tobin Davis82f30042007-02-13 12:45:44 +01001390 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1391 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1392 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1393 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1394 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1395 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1396 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1397 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001398 {
1399 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1400 .name = "Input Source",
1401 .info = conexant_mux_enum_info,
1402 .get = conexant_mux_enum_get,
1403 .put = conexant_mux_enum_put,
1404 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001405 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1406 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1407 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1408 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1409 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1410 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1411 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1412 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1413 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1414 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1415
Tobin Davisc9b443d2006-11-14 12:13:39 +01001416 { } /* end */
1417};
1418
1419static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001420 /* Enable retasking pins as output, initially without power amp */
1421 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1422 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1423 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1424
1425 /* Disable digital (SPDIF) pins initially, but users can enable
1426 * them via a mixer switch. In the case of SPDIF-out, this initverb
1427 * payload also sets the generation to 0, output to be in "consumer"
1428 * PCM format, copyright asserted, no pre-emphasis and no validity
1429 * control.
1430 */
1431 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1432
1433 /* Ensure mic1, mic2, line1 pin widgets take input from the
1434 * OUT1 sum bus when acting as an output.
1435 */
1436 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1437 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1438
1439 /* Start with output sum widgets muted and their output gains at min */
1440 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1441 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1442
1443 /* Unmute retasking pin widget output buffers since the default
1444 * state appears to be output. As the pin mode is changed by the
1445 * user the pin mode control will take care of enabling the pin's
1446 * input/output buffers as needed.
1447 */
1448 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1449 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1450 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1451
1452 /* Mute capture amp left and right */
1453 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1454
1455 /* Set ADC connection select to match default mixer setting (mic1
1456 * pin)
1457 */
1458 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1459
1460 /* Mute all inputs to mixer widget (even unconnected ones) */
1461 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1462 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1468 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1469
1470 { }
1471};
1472#endif
1473
1474
1475/* initialize jack-sensing, too */
1476static int cxt5047_hp_init(struct hda_codec *codec)
1477{
1478 conexant_init(codec);
1479 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001480 return 0;
1481}
1482
1483
1484enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001485 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1486 CXT5047_LAPTOP_HP, /* Some HP laptops */
1487 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001488#ifdef CONFIG_SND_DEBUG
1489 CXT5047_TEST,
1490#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001491 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001492};
1493
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001494static const char *cxt5047_models[CXT5047_MODELS] = {
1495 [CXT5047_LAPTOP] = "laptop",
1496 [CXT5047_LAPTOP_HP] = "laptop-hp",
1497 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001498#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001499 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001500#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001501};
1502
1503static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001504 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001505 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1506 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001507 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001508 {}
1509};
1510
1511static int patch_cxt5047(struct hda_codec *codec)
1512{
1513 struct conexant_spec *spec;
1514 int board_config;
1515
1516 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1517 if (!spec)
1518 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001519 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001520 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001521
1522 spec->multiout.max_channels = 2;
1523 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1524 spec->multiout.dac_nids = cxt5047_dac_nids;
1525 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1526 spec->num_adc_nids = 1;
1527 spec->adc_nids = cxt5047_adc_nids;
1528 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001529 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001530 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001531 spec->num_init_verbs = 1;
1532 spec->init_verbs[0] = cxt5047_init_verbs;
1533 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001534 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1535 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001536
1537 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001539 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1540 cxt5047_models,
1541 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001542 switch (board_config) {
1543 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001544 spec->num_mixers = 2;
1545 spec->mixers[1] = cxt5047_hp_spk_mixers;
1546 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001547 break;
1548 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001549 spec->num_mixers = 2;
1550 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001551 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552 codec->patch_ops.init = cxt5047_hp_init;
1553 break;
1554 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001555 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001556 spec->num_mixers = 2;
1557 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558 spec->num_init_verbs = 2;
1559 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001560 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001561 break;
1562#ifdef CONFIG_SND_DEBUG
1563 case CXT5047_TEST:
1564 spec->input_mux = &cxt5047_test_capture_source;
1565 spec->mixers[0] = cxt5047_test_mixer;
1566 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001567 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001568#endif
1569 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001570 spec->vmaster_nid = 0x13;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001571 return 0;
1572}
1573
Takashi Iwai461e2c72008-01-25 11:35:17 +01001574/* Conexant 5051 specific */
1575static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1576static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001577
1578static struct hda_channel_mode cxt5051_modes[1] = {
1579 { 2, NULL },
1580};
1581
1582static void cxt5051_update_speaker(struct hda_codec *codec)
1583{
1584 struct conexant_spec *spec = codec->spec;
1585 unsigned int pinctl;
1586 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1587 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1588 pinctl);
1589}
1590
1591/* turn on/off EAPD (+ mute HP) as a master switch */
1592static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1594{
1595 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1596
1597 if (!cxt_eapd_put(kcontrol, ucontrol))
1598 return 0;
1599 cxt5051_update_speaker(codec);
1600 return 1;
1601}
1602
1603/* toggle input of built-in and mic jack appropriately */
1604static void cxt5051_portb_automic(struct hda_codec *codec)
1605{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001606 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001607 unsigned int present;
1608
Takashi Iwai79d7d532009-03-04 09:03:50 +01001609 if (spec->no_auto_mic)
1610 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001611 present = snd_hda_codec_read(codec, 0x17, 0,
1612 AC_VERB_GET_PIN_SENSE, 0) &
1613 AC_PINSENSE_PRESENCE;
1614 snd_hda_codec_write(codec, 0x14, 0,
1615 AC_VERB_SET_CONNECT_SEL,
1616 present ? 0x01 : 0x00);
1617}
1618
1619/* switch the current ADC according to the jack state */
1620static void cxt5051_portc_automic(struct hda_codec *codec)
1621{
1622 struct conexant_spec *spec = codec->spec;
1623 unsigned int present;
1624 hda_nid_t new_adc;
1625
Takashi Iwai79d7d532009-03-04 09:03:50 +01001626 if (spec->no_auto_mic)
1627 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001628 present = snd_hda_codec_read(codec, 0x18, 0,
1629 AC_VERB_GET_PIN_SENSE, 0) &
1630 AC_PINSENSE_PRESENCE;
1631 if (present)
1632 spec->cur_adc_idx = 1;
1633 else
1634 spec->cur_adc_idx = 0;
1635 new_adc = spec->adc_nids[spec->cur_adc_idx];
1636 if (spec->cur_adc && spec->cur_adc != new_adc) {
1637 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001638 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001639 spec->cur_adc = new_adc;
1640 snd_hda_codec_setup_stream(codec, new_adc,
1641 spec->cur_adc_stream_tag, 0,
1642 spec->cur_adc_format);
1643 }
1644}
1645
1646/* mute internal speaker if HP is plugged */
1647static void cxt5051_hp_automute(struct hda_codec *codec)
1648{
1649 struct conexant_spec *spec = codec->spec;
1650
1651 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1652 AC_VERB_GET_PIN_SENSE, 0) &
1653 AC_PINSENSE_PRESENCE;
1654 cxt5051_update_speaker(codec);
1655}
1656
1657/* unsolicited event for HP jack sensing */
1658static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1659 unsigned int res)
1660{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001661 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001662 switch (res >> 26) {
1663 case CONEXANT_HP_EVENT:
1664 cxt5051_hp_automute(codec);
1665 break;
1666 case CXT5051_PORTB_EVENT:
1667 cxt5051_portb_automic(codec);
1668 break;
1669 case CXT5051_PORTC_EVENT:
1670 cxt5051_portc_automic(codec);
1671 break;
1672 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001673 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001674}
1675
1676static struct snd_kcontrol_new cxt5051_mixers[] = {
1677 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1678 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1679 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1680 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1681 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1682 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1683 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1684 {
1685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1686 .name = "Master Playback Switch",
1687 .info = cxt_eapd_info,
1688 .get = cxt_eapd_get,
1689 .put = cxt5051_hp_master_sw_put,
1690 .private_value = 0x1a,
1691 },
1692
1693 {}
1694};
1695
1696static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1697 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1698 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1699 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1700 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1701 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1702 {
1703 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1704 .name = "Master Playback Switch",
1705 .info = cxt_eapd_info,
1706 .get = cxt_eapd_get,
1707 .put = cxt5051_hp_master_sw_put,
1708 .private_value = 0x1a,
1709 },
1710
1711 {}
1712};
1713
Takashi Iwai79d7d532009-03-04 09:03:50 +01001714static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1715 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1716 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1717 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1718 {
1719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1720 .name = "Master Playback Switch",
1721 .info = cxt_eapd_info,
1722 .get = cxt_eapd_get,
1723 .put = cxt5051_hp_master_sw_put,
1724 .private_value = 0x1a,
1725 },
1726
1727 {}
1728};
1729
Takashi Iwai461e2c72008-01-25 11:35:17 +01001730static struct hda_verb cxt5051_init_verbs[] = {
1731 /* Line in, Mic */
1732 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1733 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1734 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1735 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1736 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1737 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1738 /* SPK */
1739 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1740 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1741 /* HP, Amp */
1742 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1743 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1744 /* DAC1 */
1745 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1746 /* Record selector: Int mic */
1747 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1748 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1749 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1750 /* SPDIF route: PCM */
1751 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1752 /* EAPD */
1753 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1754 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1755 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1756 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1757 { } /* end */
1758};
1759
Takashi Iwai79d7d532009-03-04 09:03:50 +01001760static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1761 /* Line in, Mic */
1762 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1763 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1764 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1765 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1766 /* SPK */
1767 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1768 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1769 /* HP, Amp */
1770 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1771 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1772 /* DAC1 */
1773 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1774 /* Record selector: Int mic */
1775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1776 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1777 /* SPDIF route: PCM */
1778 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1779 /* EAPD */
1780 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1781 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1782 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1783 { } /* end */
1784};
1785
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001786static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1787 /* Line in, Mic */
1788 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1789 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1790 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1791 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1792 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1793 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1794 /* SPK */
1795 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1796 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1797 /* HP, Amp */
1798 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1799 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1800 /* Docking HP */
1801 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1802 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1803 /* DAC1 */
1804 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1805 /* Record selector: Int mic */
1806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1808 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1809 /* SPDIF route: PCM */
1810 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1811 /* EAPD */
1812 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1813 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1814 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1815 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1816 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1817 { } /* end */
1818};
1819
Takashi Iwai461e2c72008-01-25 11:35:17 +01001820/* initialize jack-sensing, too */
1821static int cxt5051_init(struct hda_codec *codec)
1822{
1823 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001824 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001825 if (codec->patch_ops.unsol_event) {
1826 cxt5051_hp_automute(codec);
1827 cxt5051_portb_automic(codec);
1828 cxt5051_portc_automic(codec);
1829 }
1830 return 0;
1831}
1832
1833
1834enum {
1835 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1836 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001837 CXT5051_HP_DV6736, /* HP without mic switch */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001838 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001839 CXT5051_MODELS
1840};
1841
1842static const char *cxt5051_models[CXT5051_MODELS] = {
1843 [CXT5051_LAPTOP] = "laptop",
1844 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001845 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001846 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001847};
1848
1849static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001850 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001851 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001852 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1853 CXT5051_LAPTOP),
1854 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001855 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001856 {}
1857};
1858
1859static int patch_cxt5051(struct hda_codec *codec)
1860{
1861 struct conexant_spec *spec;
1862 int board_config;
1863
1864 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1865 if (!spec)
1866 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001867 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001868 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001869
1870 codec->patch_ops = conexant_patch_ops;
1871 codec->patch_ops.init = cxt5051_init;
1872
1873 spec->multiout.max_channels = 2;
1874 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1875 spec->multiout.dac_nids = cxt5051_dac_nids;
1876 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1877 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1878 spec->adc_nids = cxt5051_adc_nids;
1879 spec->num_mixers = 1;
1880 spec->mixers[0] = cxt5051_mixers;
1881 spec->num_init_verbs = 1;
1882 spec->init_verbs[0] = cxt5051_init_verbs;
1883 spec->spdif_route = 0;
1884 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1885 spec->channel_mode = cxt5051_modes;
1886 spec->cur_adc = 0;
1887 spec->cur_adc_idx = 0;
1888
Takashi Iwai79d7d532009-03-04 09:03:50 +01001889 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1890
Takashi Iwai461e2c72008-01-25 11:35:17 +01001891 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1892 cxt5051_models,
1893 cxt5051_cfg_tbl);
1894 switch (board_config) {
1895 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001896 spec->mixers[0] = cxt5051_hp_mixers;
1897 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001898 case CXT5051_HP_DV6736:
1899 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1900 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1901 spec->no_auto_mic = 1;
1902 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001903 case CXT5051_LENOVO_X200:
1904 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001905 break;
1906 }
1907
1908 return 0;
1909}
1910
1911
1912/*
1913 */
1914
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001915static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001916 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1917 .patch = patch_cxt5045 },
1918 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1919 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001920 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1921 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001922 {} /* terminator */
1923};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001924
1925MODULE_ALIAS("snd-hda-codec-id:14f15045");
1926MODULE_ALIAS("snd-hda-codec-id:14f15047");
1927MODULE_ALIAS("snd-hda-codec-id:14f15051");
1928
1929MODULE_LICENSE("GPL");
1930MODULE_DESCRIPTION("Conexant HD-audio codec");
1931
1932static struct hda_codec_preset_list conexant_list = {
1933 .preset = snd_hda_preset_conexant,
1934 .owner = THIS_MODULE,
1935};
1936
1937static int __init patch_conexant_init(void)
1938{
1939 return snd_hda_add_codec_preset(&conexant_list);
1940}
1941
1942static void __exit patch_conexant_exit(void)
1943{
1944 snd_hda_delete_codec_preset(&conexant_list);
1945}
1946
1947module_init(patch_conexant_init)
1948module_exit(patch_conexant_exit)