blob: 194a28c5499219b99d3b10ed2ae357cde7707679 [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020032#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010033
34#define CXT_PIN_DIR_IN 0x00
35#define CXT_PIN_DIR_OUT 0x01
36#define CXT_PIN_DIR_INOUT 0x02
37#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39
40#define CONEXANT_HP_EVENT 0x37
41#define CONEXANT_MIC_EVENT 0x38
42
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010043/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010044
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010045#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046#define CXT5051_PORTB_EVENT 0x38
47#define CXT5051_PORTC_EVENT 0x39
48
Takashi Iwaifaddaa52010-01-23 22:31:36 +010049#define AUTO_MIC_PORTB (1 << 1)
50#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010051
52struct conexant_jack {
53
54 hda_nid_t nid;
55 int type;
56 struct snd_jack *jack;
57
58};
Tobin Davisc9b443d2006-11-14 12:13:39 +010059
60struct conexant_spec {
61
62 struct snd_kcontrol_new *mixers[5];
63 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010064 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010065
66 const struct hda_verb *init_verbs[5]; /* initialization verbs
67 * don't forget NULL
68 * termination!
69 */
70 unsigned int num_init_verbs;
71
72 /* playback */
73 struct hda_multi_out multiout; /* playback set-up
74 * max_channels, dacs must be set
75 * dig_out_nid and hp_nid are optional
76 */
77 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010078 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010079 unsigned int auto_mic;
Tobin Davisc9b443d2006-11-14 12:13:39 +010080 unsigned int need_dac_fix;
81
82 /* capture */
83 unsigned int num_adc_nids;
84 hda_nid_t *adc_nids;
85 hda_nid_t dig_in_nid; /* digital-in NID; optional */
86
Takashi Iwai461e2c72008-01-25 11:35:17 +010087 unsigned int cur_adc_idx;
88 hda_nid_t cur_adc;
89 unsigned int cur_adc_stream_tag;
90 unsigned int cur_adc_format;
91
Tobin Davisc9b443d2006-11-14 12:13:39 +010092 /* capture source */
93 const struct hda_input_mux *input_mux;
94 hda_nid_t *capsrc_nids;
95 unsigned int cur_mux[3];
96
97 /* channel model */
98 const struct hda_channel_mode *channel_mode;
99 int num_channel_mode;
100
101 /* PCM information */
102 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
103
Tobin Davisc9b443d2006-11-14 12:13:39 +0100104 unsigned int spdif_route;
105
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100106 /* jack detection */
107 struct snd_array jacks;
108
Tobin Davisc9b443d2006-11-14 12:13:39 +0100109 /* dynamic controls, init_verbs and input_mux */
110 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100111 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200112 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100113
Daniel Drake0fb67e92009-07-16 14:46:57 +0100114 unsigned int dell_automute;
115 unsigned int port_d_mode;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500116 unsigned int dell_vostro:1;
117 unsigned int ideapad:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100118
119 unsigned int ext_mic_present;
120 unsigned int recording;
121 void (*capture_prepare)(struct hda_codec *codec);
122 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100123
124 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
125 * through the microphone jack.
126 * When the user enables this through a mixer switch, both internal and
127 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
128 * we also allow the bias to be configured through a separate mixer
129 * control. */
130 unsigned int dc_enable;
131 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
132 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100133};
134
135static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
136 struct hda_codec *codec,
137 struct snd_pcm_substream *substream)
138{
139 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100140 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
141 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100142}
143
144static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
145 struct hda_codec *codec,
146 unsigned int stream_tag,
147 unsigned int format,
148 struct snd_pcm_substream *substream)
149{
150 struct conexant_spec *spec = codec->spec;
151 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
152 stream_tag,
153 format, substream);
154}
155
156static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
157 struct hda_codec *codec,
158 struct snd_pcm_substream *substream)
159{
160 struct conexant_spec *spec = codec->spec;
161 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
162}
163
164/*
165 * Digital out
166 */
167static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
168 struct hda_codec *codec,
169 struct snd_pcm_substream *substream)
170{
171 struct conexant_spec *spec = codec->spec;
172 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
173}
174
175static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
176 struct hda_codec *codec,
177 struct snd_pcm_substream *substream)
178{
179 struct conexant_spec *spec = codec->spec;
180 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
181}
182
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200183static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
184 struct hda_codec *codec,
185 unsigned int stream_tag,
186 unsigned int format,
187 struct snd_pcm_substream *substream)
188{
189 struct conexant_spec *spec = codec->spec;
190 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
191 stream_tag,
192 format, substream);
193}
194
Tobin Davisc9b443d2006-11-14 12:13:39 +0100195/*
196 * Analog capture
197 */
198static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 unsigned int stream_tag,
201 unsigned int format,
202 struct snd_pcm_substream *substream)
203{
204 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100205 if (spec->capture_prepare)
206 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100207 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
208 stream_tag, 0, format);
209 return 0;
210}
211
212static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
213 struct hda_codec *codec,
214 struct snd_pcm_substream *substream)
215{
216 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100217 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100218 if (spec->capture_cleanup)
219 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100220 return 0;
221}
222
223
224
225static struct hda_pcm_stream conexant_pcm_analog_playback = {
226 .substreams = 1,
227 .channels_min = 2,
228 .channels_max = 2,
229 .nid = 0, /* fill later */
230 .ops = {
231 .open = conexant_playback_pcm_open,
232 .prepare = conexant_playback_pcm_prepare,
233 .cleanup = conexant_playback_pcm_cleanup
234 },
235};
236
237static struct hda_pcm_stream conexant_pcm_analog_capture = {
238 .substreams = 1,
239 .channels_min = 2,
240 .channels_max = 2,
241 .nid = 0, /* fill later */
242 .ops = {
243 .prepare = conexant_capture_pcm_prepare,
244 .cleanup = conexant_capture_pcm_cleanup
245 },
246};
247
248
249static struct hda_pcm_stream conexant_pcm_digital_playback = {
250 .substreams = 1,
251 .channels_min = 2,
252 .channels_max = 2,
253 .nid = 0, /* fill later */
254 .ops = {
255 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200256 .close = conexant_dig_playback_pcm_close,
257 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100258 },
259};
260
261static struct hda_pcm_stream conexant_pcm_digital_capture = {
262 .substreams = 1,
263 .channels_min = 2,
264 .channels_max = 2,
265 /* NID is set in alc_build_pcms */
266};
267
Takashi Iwai461e2c72008-01-25 11:35:17 +0100268static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
269 struct hda_codec *codec,
270 unsigned int stream_tag,
271 unsigned int format,
272 struct snd_pcm_substream *substream)
273{
274 struct conexant_spec *spec = codec->spec;
275 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
276 spec->cur_adc_stream_tag = stream_tag;
277 spec->cur_adc_format = format;
278 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
279 return 0;
280}
281
282static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
283 struct hda_codec *codec,
284 struct snd_pcm_substream *substream)
285{
286 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100287 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100288 spec->cur_adc = 0;
289 return 0;
290}
291
292static struct hda_pcm_stream cx5051_pcm_analog_capture = {
293 .substreams = 1,
294 .channels_min = 2,
295 .channels_max = 2,
296 .nid = 0, /* fill later */
297 .ops = {
298 .prepare = cx5051_capture_pcm_prepare,
299 .cleanup = cx5051_capture_pcm_cleanup
300 },
301};
302
Tobin Davisc9b443d2006-11-14 12:13:39 +0100303static int conexant_build_pcms(struct hda_codec *codec)
304{
305 struct conexant_spec *spec = codec->spec;
306 struct hda_pcm *info = spec->pcm_rec;
307
308 codec->num_pcms = 1;
309 codec->pcm_info = info;
310
311 info->name = "CONEXANT Analog";
312 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
313 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
314 spec->multiout.max_channels;
315 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
316 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100317 if (codec->vendor_id == 0x14f15051)
318 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
319 cx5051_pcm_analog_capture;
320 else
321 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
322 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100323 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
324 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
325
326 if (spec->multiout.dig_out_nid) {
327 info++;
328 codec->num_pcms++;
329 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100330 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
332 conexant_pcm_digital_playback;
333 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
334 spec->multiout.dig_out_nid;
335 if (spec->dig_in_nid) {
336 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
337 conexant_pcm_digital_capture;
338 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
339 spec->dig_in_nid;
340 }
341 }
342
343 return 0;
344}
345
346static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
347 struct snd_ctl_elem_info *uinfo)
348{
349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
350 struct conexant_spec *spec = codec->spec;
351
352 return snd_hda_input_mux_info(spec->input_mux, uinfo);
353}
354
355static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
357{
358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359 struct conexant_spec *spec = codec->spec;
360 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
361
362 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
363 return 0;
364}
365
366static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
367 struct snd_ctl_elem_value *ucontrol)
368{
369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370 struct conexant_spec *spec = codec->spec;
371 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
372
373 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
374 spec->capsrc_nids[adc_idx],
375 &spec->cur_mux[adc_idx]);
376}
377
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200378#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200379static void conexant_free_jack_priv(struct snd_jack *jack)
380{
381 struct conexant_jack *jacks = jack->private_data;
382 jacks->nid = 0;
383 jacks->jack = NULL;
384}
385
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100386static int conexant_add_jack(struct hda_codec *codec,
387 hda_nid_t nid, int type)
388{
389 struct conexant_spec *spec;
390 struct conexant_jack *jack;
391 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200392 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100393
394 spec = codec->spec;
395 snd_array_init(&spec->jacks, sizeof(*jack), 32);
396 jack = snd_array_new(&spec->jacks);
397 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
398
399 if (!jack)
400 return -ENOMEM;
401
402 jack->nid = nid;
403 jack->type = type;
404
Takashi Iwai95c09092009-04-14 16:15:29 +0200405 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
406 if (err < 0)
407 return err;
408 jack->jack->private_data = jack;
409 jack->jack->private_free = conexant_free_jack_priv;
410 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100411}
412
413static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
414{
415 struct conexant_spec *spec = codec->spec;
416 struct conexant_jack *jacks = spec->jacks.list;
417
418 if (jacks) {
419 int i;
420 for (i = 0; i < spec->jacks.used; i++) {
421 if (jacks->nid == nid) {
422 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100423 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100424
425 present = (present) ? jacks->type : 0 ;
426
427 snd_jack_report(jacks->jack,
428 present);
429 }
430 jacks++;
431 }
432 }
433}
434
435static int conexant_init_jacks(struct hda_codec *codec)
436{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100437 struct conexant_spec *spec = codec->spec;
438 int i;
439
440 for (i = 0; i < spec->num_init_verbs; i++) {
441 const struct hda_verb *hv;
442
443 hv = spec->init_verbs[i];
444 while (hv->nid) {
445 int err = 0;
446 switch (hv->param ^ AC_USRSP_EN) {
447 case CONEXANT_HP_EVENT:
448 err = conexant_add_jack(codec, hv->nid,
449 SND_JACK_HEADPHONE);
450 conexant_report_jack(codec, hv->nid);
451 break;
452 case CXT5051_PORTC_EVENT:
453 case CONEXANT_MIC_EVENT:
454 err = conexant_add_jack(codec, hv->nid,
455 SND_JACK_MICROPHONE);
456 conexant_report_jack(codec, hv->nid);
457 break;
458 }
459 if (err < 0)
460 return err;
461 ++hv;
462 }
463 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100464 return 0;
465
466}
Takashi Iwai5801f992009-01-27 12:53:22 +0100467#else
468static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
469{
470}
471
472static inline int conexant_init_jacks(struct hda_codec *codec)
473{
474 return 0;
475}
476#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100477
Tobin Davisc9b443d2006-11-14 12:13:39 +0100478static int conexant_init(struct hda_codec *codec)
479{
480 struct conexant_spec *spec = codec->spec;
481 int i;
482
483 for (i = 0; i < spec->num_init_verbs; i++)
484 snd_hda_sequence_write(codec, spec->init_verbs[i]);
485 return 0;
486}
487
488static void conexant_free(struct hda_codec *codec)
489{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200490#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100491 struct conexant_spec *spec = codec->spec;
492 if (spec->jacks.list) {
493 struct conexant_jack *jacks = spec->jacks.list;
494 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200495 for (i = 0; i < spec->jacks.used; i++, jacks++) {
496 if (jacks->jack)
497 snd_device_free(codec->bus->card, jacks->jack);
498 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100499 snd_array_free(&spec->jacks);
500 }
501#endif
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200502 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100503 kfree(codec->spec);
504}
505
Takashi Iwaib880c742009-03-10 14:41:05 +0100506static struct snd_kcontrol_new cxt_capture_mixers[] = {
507 {
508 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
509 .name = "Capture Source",
510 .info = conexant_mux_enum_info,
511 .get = conexant_mux_enum_get,
512 .put = conexant_mux_enum_put
513 },
514 {}
515};
516
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100517static const char *slave_vols[] = {
518 "Headphone Playback Volume",
519 "Speaker Playback Volume",
520 NULL
521};
522
523static const char *slave_sws[] = {
524 "Headphone Playback Switch",
525 "Speaker Playback Switch",
526 NULL
527};
528
Tobin Davisc9b443d2006-11-14 12:13:39 +0100529static int conexant_build_controls(struct hda_codec *codec)
530{
531 struct conexant_spec *spec = codec->spec;
532 unsigned int i;
533 int err;
534
535 for (i = 0; i < spec->num_mixers; i++) {
536 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
537 if (err < 0)
538 return err;
539 }
540 if (spec->multiout.dig_out_nid) {
541 err = snd_hda_create_spdif_out_ctls(codec,
542 spec->multiout.dig_out_nid);
543 if (err < 0)
544 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100545 err = snd_hda_create_spdif_share_sw(codec,
546 &spec->multiout);
547 if (err < 0)
548 return err;
549 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100550 }
551 if (spec->dig_in_nid) {
552 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
553 if (err < 0)
554 return err;
555 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100556
557 /* if we have no master control, let's create it */
558 if (spec->vmaster_nid &&
559 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
560 unsigned int vmaster_tlv[4];
561 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
562 HDA_OUTPUT, vmaster_tlv);
563 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
564 vmaster_tlv, slave_vols);
565 if (err < 0)
566 return err;
567 }
568 if (spec->vmaster_nid &&
569 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
570 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
571 NULL, slave_sws);
572 if (err < 0)
573 return err;
574 }
575
Takashi Iwaib880c742009-03-10 14:41:05 +0100576 if (spec->input_mux) {
577 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
578 if (err < 0)
579 return err;
580 }
581
Tobin Davisc9b443d2006-11-14 12:13:39 +0100582 return 0;
583}
584
585static struct hda_codec_ops conexant_patch_ops = {
586 .build_controls = conexant_build_controls,
587 .build_pcms = conexant_build_pcms,
588 .init = conexant_init,
589 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100590};
591
592/*
593 * EAPD control
594 * the private value = nid | (invert << 8)
595 */
596
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200597#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598
Tobin Davis82f30042007-02-13 12:45:44 +0100599static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100600 struct snd_ctl_elem_value *ucontrol)
601{
602 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
603 struct conexant_spec *spec = codec->spec;
604 int invert = (kcontrol->private_value >> 8) & 1;
605 if (invert)
606 ucontrol->value.integer.value[0] = !spec->cur_eapd;
607 else
608 ucontrol->value.integer.value[0] = spec->cur_eapd;
609 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100610
Tobin Davisc9b443d2006-11-14 12:13:39 +0100611}
612
Tobin Davis82f30042007-02-13 12:45:44 +0100613static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 struct snd_ctl_elem_value *ucontrol)
615{
616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617 struct conexant_spec *spec = codec->spec;
618 int invert = (kcontrol->private_value >> 8) & 1;
619 hda_nid_t nid = kcontrol->private_value & 0xff;
620 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100621
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100622 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623 if (invert)
624 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200625 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100626 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100627
Tobin Davisc9b443d2006-11-14 12:13:39 +0100628 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200629 snd_hda_codec_write_cache(codec, nid,
630 0, AC_VERB_SET_EAPD_BTLENABLE,
631 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100632 return 1;
633}
634
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100635/* controls for test mode */
636#ifdef CONFIG_SND_DEBUG
637
Tobin Davis82f30042007-02-13 12:45:44 +0100638#define CXT_EAPD_SWITCH(xname, nid, mask) \
639 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
640 .info = cxt_eapd_info, \
641 .get = cxt_eapd_get, \
642 .put = cxt_eapd_put, \
643 .private_value = nid | (mask<<16) }
644
645
646
Tobin Davisc9b443d2006-11-14 12:13:39 +0100647static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_info *uinfo)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct conexant_spec *spec = codec->spec;
652 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
653 spec->num_channel_mode);
654}
655
656static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
657 struct snd_ctl_elem_value *ucontrol)
658{
659 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660 struct conexant_spec *spec = codec->spec;
661 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
662 spec->num_channel_mode,
663 spec->multiout.max_channels);
664}
665
666static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
668{
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct conexant_spec *spec = codec->spec;
671 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
672 spec->num_channel_mode,
673 &spec->multiout.max_channels);
674 if (err >= 0 && spec->need_dac_fix)
675 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
676 return err;
677}
678
679#define CXT_PIN_MODE(xname, nid, dir) \
680 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
681 .info = conexant_ch_mode_info, \
682 .get = conexant_ch_mode_get, \
683 .put = conexant_ch_mode_put, \
684 .private_value = nid | (dir<<16) }
685
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100686#endif /* CONFIG_SND_DEBUG */
687
Tobin Davisc9b443d2006-11-14 12:13:39 +0100688/* Conexant 5045 specific */
689
690static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
691static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
692static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100693#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100694
Tobin Davis5cd57522006-11-20 17:42:09 +0100695static struct hda_channel_mode cxt5045_modes[1] = {
696 { 2, NULL },
697};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100698
699static struct hda_input_mux cxt5045_capture_source = {
700 .num_items = 2,
701 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100702 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100703 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100704 }
705};
706
Jiang Zhe5218c892008-01-17 11:18:41 +0100707static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200708 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100709 .items = {
710 { "IntMic", 0x1 },
711 { "ExtMic", 0x2 },
712 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200713 { "CD", 0x4 },
714 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100715 }
716};
717
Jiang zhe2de3c232008-03-06 11:09:09 +0100718static struct hda_input_mux cxt5045_capture_source_hp530 = {
719 .num_items = 2,
720 .items = {
721 { "ExtMic", 0x1 },
722 { "IntMic", 0x2 },
723 }
724};
725
Tobin Davisc9b443d2006-11-14 12:13:39 +0100726/* turn on/off EAPD (+ mute HP) as a master switch */
727static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
728 struct snd_ctl_elem_value *ucontrol)
729{
730 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
731 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100732 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100733
Tobin Davis82f30042007-02-13 12:45:44 +0100734 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100735 return 0;
736
Tobin Davis82f30042007-02-13 12:45:44 +0100737 /* toggle internal speakers mute depending of presence of
738 * the headphone jack
739 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200740 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
741 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
742 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100743
Takashi Iwai47fd8302007-08-10 17:11:07 +0200744 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
745 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
746 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100747 return 1;
748}
749
750/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200751static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
752 .ops = &snd_hda_bind_vol,
753 .values = {
754 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
755 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
756 0
757 },
758};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100759
Tobin Davis7f296732007-03-12 11:39:01 +0100760/* toggle input of built-in and mic jack appropriately */
761static void cxt5045_hp_automic(struct hda_codec *codec)
762{
763 static struct hda_verb mic_jack_on[] = {
764 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
765 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
766 {}
767 };
768 static struct hda_verb mic_jack_off[] = {
769 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
771 {}
772 };
773 unsigned int present;
774
Takashi Iwaid56757a2009-11-18 08:00:14 +0100775 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100776 if (present)
777 snd_hda_sequence_write(codec, mic_jack_on);
778 else
779 snd_hda_sequence_write(codec, mic_jack_off);
780}
781
Tobin Davisc9b443d2006-11-14 12:13:39 +0100782
783/* mute internal speaker if HP is plugged */
784static void cxt5045_hp_automute(struct hda_codec *codec)
785{
Tobin Davis82f30042007-02-13 12:45:44 +0100786 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100787 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100788
Takashi Iwaid56757a2009-11-18 08:00:14 +0100789 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100790
Takashi Iwai47fd8302007-08-10 17:11:07 +0200791 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
792 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
793 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100794}
795
796/* unsolicited event for HP jack sensing */
797static void cxt5045_hp_unsol_event(struct hda_codec *codec,
798 unsigned int res)
799{
800 res >>= 26;
801 switch (res) {
802 case CONEXANT_HP_EVENT:
803 cxt5045_hp_automute(codec);
804 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100805 case CONEXANT_MIC_EVENT:
806 cxt5045_hp_automic(codec);
807 break;
808
Tobin Davisc9b443d2006-11-14 12:13:39 +0100809 }
810}
811
812static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200813 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
814 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
815 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
816 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
817 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
818 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
819 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
820 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
821 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
822 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200823 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100824 {
825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
826 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100827 .info = cxt_eapd_info,
828 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100829 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100830 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100831 },
832
833 {}
834};
835
Jiang Zhe5218c892008-01-17 11:18:41 +0100836static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200837 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
838 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
839 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
840 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
841
Jiang Zhe5218c892008-01-17 11:18:41 +0100842 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
843 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
844 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
845 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
846
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200847 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
848 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
849
Jiang Zhe5218c892008-01-17 11:18:41 +0100850 {}
851};
852
Jiang zhe2de3c232008-03-06 11:09:09 +0100853static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100854 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
855 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
856 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
857 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
858 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
859 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
860 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
861 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
862 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
863 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
864 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
865 {
866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
867 .name = "Master Playback Switch",
868 .info = cxt_eapd_info,
869 .get = cxt_eapd_get,
870 .put = cxt5045_hp_master_sw_put,
871 .private_value = 0x10,
872 },
873
874 {}
875};
876
Tobin Davisc9b443d2006-11-14 12:13:39 +0100877static struct hda_verb cxt5045_init_verbs[] = {
878 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200879 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100880 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100881 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200882 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
883 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
884 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
885 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
886 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100891 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100892 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100893 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100894 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
895 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100896 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100897 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100898 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100899 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100900 { } /* end */
901};
902
Jiang Zhe5218c892008-01-17 11:18:41 +0100903static struct hda_verb cxt5045_benq_init_verbs[] = {
904 /* Int Mic, Mic */
905 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
906 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
907 /* Line In,HP, Amp */
908 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
909 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
910 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
911 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
912 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
915 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
917 /* Record selector: Int mic */
918 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
919 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
920 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
921 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100922 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100923 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
924 /* EAPD */
925 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
926 { } /* end */
927};
Tobin Davis7f296732007-03-12 11:39:01 +0100928
929static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
930 /* pin sensing on HP jack */
931 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200932 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100933};
934
935static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
936 /* pin sensing on HP jack */
937 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200938 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100939};
940
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941#ifdef CONFIG_SND_DEBUG
942/* Test configuration for debugging, modelled after the ALC260 test
943 * configuration.
944 */
945static struct hda_input_mux cxt5045_test_capture_source = {
946 .num_items = 5,
947 .items = {
948 { "MIXER", 0x0 },
949 { "MIC1 pin", 0x1 },
950 { "LINE1 pin", 0x2 },
951 { "HP-OUT pin", 0x3 },
952 { "CD pin", 0x4 },
953 },
954};
955
956static struct snd_kcontrol_new cxt5045_test_mixer[] = {
957
958 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100959 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
960 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100961 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
962 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
963 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
964 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100965
966 /* Modes for retasking pin widgets */
967 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
968 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
969
Tobin Davis82f30042007-02-13 12:45:44 +0100970 /* EAPD Switch Control */
971 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
972
Tobin Davisc9b443d2006-11-14 12:13:39 +0100973 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100974
Tobin Davis7f296732007-03-12 11:39:01 +0100975 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
976 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
977 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
978 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
979 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
980 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
981 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
982 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
983 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
984 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100985 {
986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
987 .name = "Input Source",
988 .info = conexant_mux_enum_info,
989 .get = conexant_mux_enum_get,
990 .put = conexant_mux_enum_put,
991 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200992 /* Audio input controls */
993 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
994 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
995 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
996 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
997 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
998 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
999 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1000 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1001 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1002 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001003 { } /* end */
1004};
1005
1006static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001007 /* Set connections */
1008 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1009 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1010 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001011 /* Enable retasking pins as output, initially without power amp */
1012 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001013 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001014
1015 /* Disable digital (SPDIF) pins initially, but users can enable
1016 * them via a mixer switch. In the case of SPDIF-out, this initverb
1017 * payload also sets the generation to 0, output to be in "consumer"
1018 * PCM format, copyright asserted, no pre-emphasis and no validity
1019 * control.
1020 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001021 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1022 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001023
1024 /* Start with output sum widgets muted and their output gains at min */
1025 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1026 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1027
1028 /* Unmute retasking pin widget output buffers since the default
1029 * state appears to be output. As the pin mode is changed by the
1030 * user the pin mode control will take care of enabling the pin's
1031 * input/output buffers as needed.
1032 */
1033 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1034 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1035
1036 /* Mute capture amp left and right */
1037 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1038
1039 /* Set ADC connection select to match default mixer setting (mic1
1040 * pin)
1041 */
1042 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001043 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001044
1045 /* Mute all inputs to mixer widget (even unconnected ones) */
1046 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1047 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1048 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1049 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1050 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1051
1052 { }
1053};
1054#endif
1055
1056
1057/* initialize jack-sensing, too */
1058static int cxt5045_init(struct hda_codec *codec)
1059{
1060 conexant_init(codec);
1061 cxt5045_hp_automute(codec);
1062 return 0;
1063}
1064
1065
1066enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001067 CXT5045_LAPTOP_HPSENSE,
1068 CXT5045_LAPTOP_MICSENSE,
1069 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001070 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001071 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072#ifdef CONFIG_SND_DEBUG
1073 CXT5045_TEST,
1074#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001075 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001076};
1077
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001078static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001079 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1080 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1081 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1082 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001083 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001084#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001085 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001087};
1088
1089static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001090 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001091 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1092 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001093 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001094 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001095 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1096 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001097 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1098 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001099 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1100 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1101 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001102 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1103 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001104 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001105 {}
1106};
1107
1108static int patch_cxt5045(struct hda_codec *codec)
1109{
1110 struct conexant_spec *spec;
1111 int board_config;
1112
1113 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1114 if (!spec)
1115 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001117 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001118
1119 spec->multiout.max_channels = 2;
1120 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1121 spec->multiout.dac_nids = cxt5045_dac_nids;
1122 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1123 spec->num_adc_nids = 1;
1124 spec->adc_nids = cxt5045_adc_nids;
1125 spec->capsrc_nids = cxt5045_capsrc_nids;
1126 spec->input_mux = &cxt5045_capture_source;
1127 spec->num_mixers = 1;
1128 spec->mixers[0] = cxt5045_mixers;
1129 spec->num_init_verbs = 1;
1130 spec->init_verbs[0] = cxt5045_init_verbs;
1131 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001132 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1133 spec->channel_mode = cxt5045_modes,
1134
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135
1136 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001138 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1139 cxt5045_models,
1140 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001141 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001142 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001143 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001144 spec->input_mux = &cxt5045_capture_source;
1145 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001146 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1147 spec->mixers[0] = cxt5045_mixers;
1148 codec->patch_ops.init = cxt5045_init;
1149 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001150 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001151 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001152 spec->input_mux = &cxt5045_capture_source;
1153 spec->num_init_verbs = 2;
1154 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001155 spec->mixers[0] = cxt5045_mixers;
1156 codec->patch_ops.init = cxt5045_init;
1157 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001158 default:
1159 case CXT5045_LAPTOP_HPMICSENSE:
1160 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1161 spec->input_mux = &cxt5045_capture_source;
1162 spec->num_init_verbs = 3;
1163 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1164 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1165 spec->mixers[0] = cxt5045_mixers;
1166 codec->patch_ops.init = cxt5045_init;
1167 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001168 case CXT5045_BENQ:
1169 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1170 spec->input_mux = &cxt5045_capture_source_benq;
1171 spec->num_init_verbs = 1;
1172 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1173 spec->mixers[0] = cxt5045_mixers;
1174 spec->mixers[1] = cxt5045_benq_mixers;
1175 spec->num_mixers = 2;
1176 codec->patch_ops.init = cxt5045_init;
1177 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001178 case CXT5045_LAPTOP_HP530:
1179 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1180 spec->input_mux = &cxt5045_capture_source_hp530;
1181 spec->num_init_verbs = 2;
1182 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1183 spec->mixers[0] = cxt5045_mixers_hp530;
1184 codec->patch_ops.init = cxt5045_init;
1185 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001186#ifdef CONFIG_SND_DEBUG
1187 case CXT5045_TEST:
1188 spec->input_mux = &cxt5045_test_capture_source;
1189 spec->mixers[0] = cxt5045_test_mixer;
1190 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001191 break;
1192
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193#endif
1194 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001195
Takashi Iwai031005f2008-06-26 14:49:58 +02001196 switch (codec->subsystem_id >> 16) {
1197 case 0x103c:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001198 case 0x1734:
1199 /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
1200 * on NID 0x17. Fix max PCM level to 0 dB
1201 * (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001202 */
1203 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1204 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1205 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1206 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1207 (1 << AC_AMPCAP_MUTE_SHIFT));
1208 break;
1209 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001210
Tobin Davisc9b443d2006-11-14 12:13:39 +01001211 return 0;
1212}
1213
1214
1215/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001216#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001218static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001219static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1220static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001221
Tobin Davis5cd57522006-11-20 17:42:09 +01001222static struct hda_channel_mode cxt5047_modes[1] = {
1223 { 2, NULL },
1224};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001225
Tobin Davis82f30042007-02-13 12:45:44 +01001226static struct hda_input_mux cxt5047_toshiba_capture_source = {
1227 .num_items = 2,
1228 .items = {
1229 { "ExtMic", 0x2 },
1230 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231 }
1232};
1233
1234/* turn on/off EAPD (+ mute HP) as a master switch */
1235static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1236 struct snd_ctl_elem_value *ucontrol)
1237{
1238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1239 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001240 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241
Tobin Davis82f30042007-02-13 12:45:44 +01001242 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001243 return 0;
1244
Tobin Davis82f30042007-02-13 12:45:44 +01001245 /* toggle internal speakers mute depending of presence of
1246 * the headphone jack
1247 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001248 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001249 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1250 * pin widgets unlike other codecs. In this case, we need to
1251 * set index 0x01 for the volume from the mixer amp 0x19.
1252 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001253 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001254 HDA_AMP_MUTE, bits);
1255 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1256 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1257 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001258 return 1;
1259}
1260
Tobin Davisc9b443d2006-11-14 12:13:39 +01001261/* mute internal speaker if HP is plugged */
1262static void cxt5047_hp_automute(struct hda_codec *codec)
1263{
Tobin Davis82f30042007-02-13 12:45:44 +01001264 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001265 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001266
Takashi Iwaid56757a2009-11-18 08:00:14 +01001267 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001268
Takashi Iwai47fd8302007-08-10 17:11:07 +02001269 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001270 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001271 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001272 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001273}
1274
1275/* toggle input of built-in and mic jack appropriately */
1276static void cxt5047_hp_automic(struct hda_codec *codec)
1277{
1278 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001279 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1280 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001281 {}
1282 };
1283 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001284 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1285 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286 {}
1287 };
1288 unsigned int present;
1289
Takashi Iwaid56757a2009-11-18 08:00:14 +01001290 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 if (present)
1292 snd_hda_sequence_write(codec, mic_jack_on);
1293 else
1294 snd_hda_sequence_write(codec, mic_jack_off);
1295}
1296
1297/* unsolicited event for HP jack sensing */
1298static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1299 unsigned int res)
1300{
Marc Boucher9f113e02008-01-22 15:18:08 +01001301 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001302 case CONEXANT_HP_EVENT:
1303 cxt5047_hp_automute(codec);
1304 break;
1305 case CONEXANT_MIC_EVENT:
1306 cxt5047_hp_automic(codec);
1307 break;
1308 }
1309}
1310
Takashi Iwaidf481e42009-03-10 15:35:35 +01001311static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1312 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1313 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315 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),
Tobin Davis82f30042007-02-13 12:45:44 +01001319 {
1320 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1321 .name = "Master Playback Switch",
1322 .info = cxt_eapd_info,
1323 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001324 .put = cxt5047_hp_master_sw_put,
1325 .private_value = 0x13,
1326 },
1327
1328 {}
1329};
1330
Takashi Iwaidf481e42009-03-10 15:35:35 +01001331static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001332 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001333 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001334 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1335 {}
1336};
1337
1338static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001339 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340 { } /* end */
1341};
1342
1343static struct hda_verb cxt5047_init_verbs[] = {
1344 /* Line in, Mic, Built-in Mic */
1345 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1346 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1347 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001348 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001349 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001350 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1351 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001352 /* Record selector: Mic */
1353 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1354 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1355 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1356 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1358 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1359 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1360 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001361 /* SPDIF route: PCM */
1362 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001363 /* Enable unsolicited events */
1364 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1365 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 { } /* end */
1367};
1368
1369/* configuration for Toshiba Laptops */
1370static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001371 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 {}
1373};
1374
1375/* Test configuration for debugging, modelled after the ALC260 test
1376 * configuration.
1377 */
1378#ifdef CONFIG_SND_DEBUG
1379static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001380 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001382 { "LINE1 pin", 0x0 },
1383 { "MIC1 pin", 0x1 },
1384 { "MIC2 pin", 0x2 },
1385 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001386 },
1387};
1388
1389static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1390
1391 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001392 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1393 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1394 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1395 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001396 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001400 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001404
1405 /* Modes for retasking pin widgets */
1406 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1407 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1408
Tobin Davis82f30042007-02-13 12:45:44 +01001409 /* EAPD Switch Control */
1410 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1411
Tobin Davisc9b443d2006-11-14 12:13:39 +01001412 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001413 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1414 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1415 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1416 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1417 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1418 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1419 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1420 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001421
Tobin Davis82f30042007-02-13 12:45:44 +01001422 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1423 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1425 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1427 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1428 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1429 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001430 {
1431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1432 .name = "Input Source",
1433 .info = conexant_mux_enum_info,
1434 .get = conexant_mux_enum_get,
1435 .put = conexant_mux_enum_put,
1436 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001437 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001438
Tobin Davisc9b443d2006-11-14 12:13:39 +01001439 { } /* end */
1440};
1441
1442static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001443 /* Enable retasking pins as output, initially without power amp */
1444 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1445 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1446 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1447
1448 /* Disable digital (SPDIF) pins initially, but users can enable
1449 * them via a mixer switch. In the case of SPDIF-out, this initverb
1450 * payload also sets the generation to 0, output to be in "consumer"
1451 * PCM format, copyright asserted, no pre-emphasis and no validity
1452 * control.
1453 */
1454 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1455
1456 /* Ensure mic1, mic2, line1 pin widgets take input from the
1457 * OUT1 sum bus when acting as an output.
1458 */
1459 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1460 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1461
1462 /* Start with output sum widgets muted and their output gains at min */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1465
1466 /* Unmute retasking pin widget output buffers since the default
1467 * state appears to be output. As the pin mode is changed by the
1468 * user the pin mode control will take care of enabling the pin's
1469 * input/output buffers as needed.
1470 */
1471 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1472 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1474
1475 /* Mute capture amp left and right */
1476 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1477
1478 /* Set ADC connection select to match default mixer setting (mic1
1479 * pin)
1480 */
1481 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1482
1483 /* Mute all inputs to mixer widget (even unconnected ones) */
1484 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1492
1493 { }
1494};
1495#endif
1496
1497
1498/* initialize jack-sensing, too */
1499static int cxt5047_hp_init(struct hda_codec *codec)
1500{
1501 conexant_init(codec);
1502 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001503 return 0;
1504}
1505
1506
1507enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001508 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1509 CXT5047_LAPTOP_HP, /* Some HP laptops */
1510 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001511#ifdef CONFIG_SND_DEBUG
1512 CXT5047_TEST,
1513#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001514 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001515};
1516
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001517static const char *cxt5047_models[CXT5047_MODELS] = {
1518 [CXT5047_LAPTOP] = "laptop",
1519 [CXT5047_LAPTOP_HP] = "laptop-hp",
1520 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001521#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001522 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001523#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001524};
1525
1526static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001527 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001528 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1529 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001531 {}
1532};
1533
1534static int patch_cxt5047(struct hda_codec *codec)
1535{
1536 struct conexant_spec *spec;
1537 int board_config;
1538
1539 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1540 if (!spec)
1541 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001542 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001543 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544
1545 spec->multiout.max_channels = 2;
1546 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1547 spec->multiout.dac_nids = cxt5047_dac_nids;
1548 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1549 spec->num_adc_nids = 1;
1550 spec->adc_nids = cxt5047_adc_nids;
1551 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001553 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001554 spec->num_init_verbs = 1;
1555 spec->init_verbs[0] = cxt5047_init_verbs;
1556 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001557 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1558 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001559
1560 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001561
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001562 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1563 cxt5047_models,
1564 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001565 switch (board_config) {
1566 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001567 spec->num_mixers = 2;
1568 spec->mixers[1] = cxt5047_hp_spk_mixers;
1569 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 break;
1571 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001572 spec->num_mixers = 2;
1573 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001574 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575 codec->patch_ops.init = cxt5047_hp_init;
1576 break;
1577 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001578 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001579 spec->num_mixers = 2;
1580 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001581 spec->num_init_verbs = 2;
1582 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001583 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001584 break;
1585#ifdef CONFIG_SND_DEBUG
1586 case CXT5047_TEST:
1587 spec->input_mux = &cxt5047_test_capture_source;
1588 spec->mixers[0] = cxt5047_test_mixer;
1589 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001590 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001591#endif
1592 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001593 spec->vmaster_nid = 0x13;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001594 return 0;
1595}
1596
Takashi Iwai461e2c72008-01-25 11:35:17 +01001597/* Conexant 5051 specific */
1598static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1599static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001600
1601static struct hda_channel_mode cxt5051_modes[1] = {
1602 { 2, NULL },
1603};
1604
1605static void cxt5051_update_speaker(struct hda_codec *codec)
1606{
1607 struct conexant_spec *spec = codec->spec;
1608 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001609 /* headphone pin */
1610 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1611 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1612 pinctl);
1613 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001614 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1615 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1616 pinctl);
1617}
1618
1619/* turn on/off EAPD (+ mute HP) as a master switch */
1620static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1621 struct snd_ctl_elem_value *ucontrol)
1622{
1623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1624
1625 if (!cxt_eapd_put(kcontrol, ucontrol))
1626 return 0;
1627 cxt5051_update_speaker(codec);
1628 return 1;
1629}
1630
1631/* toggle input of built-in and mic jack appropriately */
1632static void cxt5051_portb_automic(struct hda_codec *codec)
1633{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001634 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001635 unsigned int present;
1636
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001637 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001638 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001639 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001640 snd_hda_codec_write(codec, 0x14, 0,
1641 AC_VERB_SET_CONNECT_SEL,
1642 present ? 0x01 : 0x00);
1643}
1644
1645/* switch the current ADC according to the jack state */
1646static void cxt5051_portc_automic(struct hda_codec *codec)
1647{
1648 struct conexant_spec *spec = codec->spec;
1649 unsigned int present;
1650 hda_nid_t new_adc;
1651
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001652 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001653 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001654 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001655 if (present)
1656 spec->cur_adc_idx = 1;
1657 else
1658 spec->cur_adc_idx = 0;
1659 new_adc = spec->adc_nids[spec->cur_adc_idx];
1660 if (spec->cur_adc && spec->cur_adc != new_adc) {
1661 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001662 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001663 spec->cur_adc = new_adc;
1664 snd_hda_codec_setup_stream(codec, new_adc,
1665 spec->cur_adc_stream_tag, 0,
1666 spec->cur_adc_format);
1667 }
1668}
1669
1670/* mute internal speaker if HP is plugged */
1671static void cxt5051_hp_automute(struct hda_codec *codec)
1672{
1673 struct conexant_spec *spec = codec->spec;
1674
Takashi Iwaid56757a2009-11-18 08:00:14 +01001675 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001676 cxt5051_update_speaker(codec);
1677}
1678
1679/* unsolicited event for HP jack sensing */
1680static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1681 unsigned int res)
1682{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001683 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001684 switch (res >> 26) {
1685 case CONEXANT_HP_EVENT:
1686 cxt5051_hp_automute(codec);
1687 break;
1688 case CXT5051_PORTB_EVENT:
1689 cxt5051_portb_automic(codec);
1690 break;
1691 case CXT5051_PORTC_EVENT:
1692 cxt5051_portc_automic(codec);
1693 break;
1694 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001695 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001696}
1697
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001698static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001699 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1700 {
1701 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1702 .name = "Master Playback Switch",
1703 .info = cxt_eapd_info,
1704 .get = cxt_eapd_get,
1705 .put = cxt5051_hp_master_sw_put,
1706 .private_value = 0x1a,
1707 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001708 {}
1709};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001710
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001711static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1712 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1713 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1714 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1715 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1716 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1717 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001718 {}
1719};
1720
1721static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1722 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1723 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1724 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1725 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001726 {}
1727};
1728
Takashi Iwai79d7d532009-03-04 09:03:50 +01001729static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001730 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1731 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001732 {}
1733};
1734
Ken Proxcd9d95a2010-01-08 09:01:47 +01001735static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001736 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1737 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001738 {}
1739};
1740
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001741static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1742 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1743 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1744 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1745 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001746 {}
1747};
1748
Takashi Iwai461e2c72008-01-25 11:35:17 +01001749static struct hda_verb cxt5051_init_verbs[] = {
1750 /* Line in, Mic */
1751 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1752 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1753 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1754 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1755 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1756 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1757 /* SPK */
1758 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1759 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1760 /* HP, Amp */
1761 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1762 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1763 /* DAC1 */
1764 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1765 /* Record selector: Int mic */
1766 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1767 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1768 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1769 /* SPDIF route: PCM */
1770 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1771 /* EAPD */
1772 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1773 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001774 { } /* end */
1775};
1776
Takashi Iwai79d7d532009-03-04 09:03:50 +01001777static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1778 /* Line in, Mic */
1779 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1780 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1781 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1782 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1783 /* SPK */
1784 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1785 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1786 /* HP, Amp */
1787 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1788 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1789 /* DAC1 */
1790 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1791 /* Record selector: Int mic */
1792 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1793 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1794 /* SPDIF route: PCM */
1795 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1796 /* EAPD */
1797 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1798 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001799 { } /* end */
1800};
1801
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001802static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1803 /* Line in, Mic */
1804 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1805 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1806 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1807 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1808 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1809 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1810 /* SPK */
1811 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1812 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1813 /* HP, Amp */
1814 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1815 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1816 /* Docking HP */
1817 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1818 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1819 /* DAC1 */
1820 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1821 /* Record selector: Int mic */
1822 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1824 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1825 /* SPDIF route: PCM */
1826 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1827 /* EAPD */
1828 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1829 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001830 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1831 { } /* end */
1832};
1833
Ken Proxcd9d95a2010-01-08 09:01:47 +01001834static struct hda_verb cxt5051_f700_init_verbs[] = {
1835 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001836 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001837 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1838 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1839 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1840 /* SPK */
1841 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1842 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1843 /* HP, Amp */
1844 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1845 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1846 /* DAC1 */
1847 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1848 /* Record selector: Int mic */
1849 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1850 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1851 /* SPDIF route: PCM */
1852 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1853 /* EAPD */
1854 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1855 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001856 { } /* end */
1857};
1858
Takashi Iwai6953e552010-01-24 11:00:27 +01001859static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1860 unsigned int event)
1861{
1862 snd_hda_codec_write(codec, nid, 0,
1863 AC_VERB_SET_UNSOLICITED_ENABLE,
1864 AC_USRSP_EN | event);
1865#ifdef CONFIG_SND_HDA_INPUT_JACK
1866 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1867 conexant_report_jack(codec, nid);
1868#endif
1869}
1870
Takashi Iwai461e2c72008-01-25 11:35:17 +01001871/* initialize jack-sensing, too */
1872static int cxt5051_init(struct hda_codec *codec)
1873{
Takashi Iwai6953e552010-01-24 11:00:27 +01001874 struct conexant_spec *spec = codec->spec;
1875
Takashi Iwai461e2c72008-01-25 11:35:17 +01001876 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001877 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001878
1879 if (spec->auto_mic & AUTO_MIC_PORTB)
1880 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1881 if (spec->auto_mic & AUTO_MIC_PORTC)
1882 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1883
Takashi Iwai461e2c72008-01-25 11:35:17 +01001884 if (codec->patch_ops.unsol_event) {
1885 cxt5051_hp_automute(codec);
1886 cxt5051_portb_automic(codec);
1887 cxt5051_portc_automic(codec);
1888 }
1889 return 0;
1890}
1891
1892
1893enum {
1894 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1895 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001896 CXT5051_HP_DV6736, /* HP without mic switch */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001897 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001898 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001899 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001900 CXT5051_MODELS
1901};
1902
1903static const char *cxt5051_models[CXT5051_MODELS] = {
1904 [CXT5051_LAPTOP] = "laptop",
1905 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001906 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001907 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001908 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001909 [CXT5051_TOSHIBA] = "toshiba",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001910};
1911
1912static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001913 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001914 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001915 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001916 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001917 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1918 CXT5051_LAPTOP),
1919 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001920 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001921 {}
1922};
1923
1924static int patch_cxt5051(struct hda_codec *codec)
1925{
1926 struct conexant_spec *spec;
1927 int board_config;
1928
1929 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1930 if (!spec)
1931 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001932 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001933 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001934
1935 codec->patch_ops = conexant_patch_ops;
1936 codec->patch_ops.init = cxt5051_init;
1937
1938 spec->multiout.max_channels = 2;
1939 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1940 spec->multiout.dac_nids = cxt5051_dac_nids;
1941 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1942 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1943 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001944 spec->num_mixers = 2;
1945 spec->mixers[0] = cxt5051_capture_mixers;
1946 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001947 spec->num_init_verbs = 1;
1948 spec->init_verbs[0] = cxt5051_init_verbs;
1949 spec->spdif_route = 0;
1950 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1951 spec->channel_mode = cxt5051_modes;
1952 spec->cur_adc = 0;
1953 spec->cur_adc_idx = 0;
1954
Takashi Iwai79d7d532009-03-04 09:03:50 +01001955 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1956
Takashi Iwai461e2c72008-01-25 11:35:17 +01001957 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1958 cxt5051_models,
1959 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001960 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001961 switch (board_config) {
1962 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001963 spec->mixers[0] = cxt5051_hp_mixers;
1964 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001965 case CXT5051_HP_DV6736:
1966 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1967 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001968 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001969 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001970 case CXT5051_LENOVO_X200:
1971 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001972 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001973 case CXT5051_F700:
1974 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1975 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001976 spec->auto_mic = 0;
1977 break;
1978 case CXT5051_TOSHIBA:
1979 spec->mixers[0] = cxt5051_toshiba_mixers;
1980 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001981 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001982 }
1983
1984 return 0;
1985}
1986
Daniel Drake0fb67e92009-07-16 14:46:57 +01001987/* Conexant 5066 specific */
1988
1989static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1990static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1991static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1992#define CXT5066_SPDIF_OUT 0x21
1993
Daniel Drakedbaccc02009-11-09 15:17:24 +00001994/* OLPC's microphone port is DC coupled for use with external sensors,
1995 * therefore we use a 50% mic bias in order to center the input signal with
1996 * the DC input range of the codec. */
1997#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1998
Daniel Drake0fb67e92009-07-16 14:46:57 +01001999static struct hda_channel_mode cxt5066_modes[1] = {
2000 { 2, NULL },
2001};
2002
2003static void cxt5066_update_speaker(struct hda_codec *codec)
2004{
2005 struct conexant_spec *spec = codec->spec;
2006 unsigned int pinctl;
2007
2008 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
2009 spec->hp_present);
2010
2011 /* Port A (HP) */
2012 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2013 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2014 pinctl);
2015
2016 /* Port D (HP/LO) */
2017 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2018 ? spec->port_d_mode : 0;
2019 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2020 pinctl);
2021
2022 /* CLASS_D AMP */
2023 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2024 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2025 pinctl);
2026
2027 if (spec->dell_automute) {
2028 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2029 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2030 ? PIN_OUT : 0;
2031 snd_hda_codec_write(codec, 0x1c, 0,
2032 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2033 }
2034}
2035
2036/* turn on/off EAPD (+ mute HP) as a master switch */
2037static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2038 struct snd_ctl_elem_value *ucontrol)
2039{
2040 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2041
2042 if (!cxt_eapd_put(kcontrol, ucontrol))
2043 return 0;
2044
2045 cxt5066_update_speaker(codec);
2046 return 1;
2047}
2048
Daniel Drakec4cfe662010-01-07 13:47:04 +01002049static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2050 .num_items = 3,
2051 .items = {
2052 { "Off", PIN_IN },
2053 { "50%", PIN_VREF50 },
2054 { "80%", PIN_VREF80 },
2055 },
2056};
2057
2058static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2059{
2060 struct conexant_spec *spec = codec->spec;
2061 /* Even though port F is the DC input, the bias is controlled on port B.
2062 * we also leave that port as an active input (but unselected) in DC mode
2063 * just in case that is necessary to make the bias setting take effect. */
2064 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2065 AC_VERB_SET_PIN_WIDGET_CONTROL,
2066 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2067}
2068
Daniel Drake75f89912010-01-07 13:46:25 +01002069/* OLPC defers mic widget control until when capture is started because the
2070 * microphone LED comes on as soon as these settings are put in place. if we
2071 * did this before recording, it would give the false indication that recording
2072 * is happening when it is not. */
2073static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002074{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002075 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002076 if (!spec->recording)
2077 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002078
Daniel Drakec4cfe662010-01-07 13:47:04 +01002079 if (spec->dc_enable) {
2080 /* in DC mode we ignore presence detection and just use the jack
2081 * through our special DC port */
2082 const struct hda_verb enable_dc_mode[] = {
2083 /* disble internal mic, port C */
2084 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2085
2086 /* enable DC capture, port F */
2087 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2088 {},
2089 };
2090
2091 snd_hda_sequence_write(codec, enable_dc_mode);
2092 /* port B input disabled (and bias set) through the following call */
2093 cxt5066_set_olpc_dc_bias(codec);
2094 return;
2095 }
2096
2097 /* disable DC (port F) */
2098 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2099
Daniel Drake75f89912010-01-07 13:46:25 +01002100 /* external mic, port B */
2101 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2102 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002103
Daniel Drake75f89912010-01-07 13:46:25 +01002104 /* internal mic, port C */
2105 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2106 spec->ext_mic_present ? 0 : PIN_VREF80);
2107}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002108
Daniel Drake75f89912010-01-07 13:46:25 +01002109/* toggle input of built-in and mic jack appropriately */
2110static void cxt5066_olpc_automic(struct hda_codec *codec)
2111{
2112 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002113 unsigned int present;
2114
Daniel Drakec4cfe662010-01-07 13:47:04 +01002115 if (spec->dc_enable) /* don't do presence detection in DC mode */
2116 return;
2117
Daniel Drake75f89912010-01-07 13:46:25 +01002118 present = snd_hda_codec_read(codec, 0x1a, 0,
2119 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2120 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002121 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002122 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002123 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002124
2125 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2126 present ? 0 : 1);
2127 spec->ext_mic_present = !!present;
2128
2129 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002130}
2131
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002132/* toggle input of built-in digital mic and mic jack appropriately */
2133static void cxt5066_vostro_automic(struct hda_codec *codec)
2134{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002135 unsigned int present;
2136
2137 struct hda_verb ext_mic_present[] = {
2138 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002139 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002140
2141 /* switch to external mic input */
2142 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2143 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2144
2145 /* disable internal digital mic */
2146 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2147 {}
2148 };
2149 static struct hda_verb ext_mic_absent[] = {
2150 /* enable internal mic, port C */
2151 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2152
2153 /* switch to internal mic input */
2154 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2155
2156 /* disable external mic, port B */
2157 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2158 {}
2159 };
2160
2161 present = snd_hda_jack_detect(codec, 0x1a);
2162 if (present) {
2163 snd_printdd("CXT5066: external microphone detected\n");
2164 snd_hda_sequence_write(codec, ext_mic_present);
2165 } else {
2166 snd_printdd("CXT5066: external microphone absent\n");
2167 snd_hda_sequence_write(codec, ext_mic_absent);
2168 }
2169}
2170
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002171/* toggle input of built-in digital mic and mic jack appropriately */
2172static void cxt5066_ideapad_automic(struct hda_codec *codec)
2173{
2174 unsigned int present;
2175
2176 struct hda_verb ext_mic_present[] = {
2177 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2178 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2179 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2180 {}
2181 };
2182 static struct hda_verb ext_mic_absent[] = {
2183 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2184 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2185 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2186 {}
2187 };
2188
2189 present = snd_hda_jack_detect(codec, 0x1b);
2190 if (present) {
2191 snd_printdd("CXT5066: external microphone detected\n");
2192 snd_hda_sequence_write(codec, ext_mic_present);
2193 } else {
2194 snd_printdd("CXT5066: external microphone absent\n");
2195 snd_hda_sequence_write(codec, ext_mic_absent);
2196 }
2197}
2198
Daniel Drake0fb67e92009-07-16 14:46:57 +01002199/* mute internal speaker if HP is plugged */
2200static void cxt5066_hp_automute(struct hda_codec *codec)
2201{
2202 struct conexant_spec *spec = codec->spec;
2203 unsigned int portA, portD;
2204
2205 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002206 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002207
2208 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002209 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002210
2211 spec->hp_present = !!(portA | portD);
2212 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2213 portA, portD, spec->hp_present);
2214 cxt5066_update_speaker(codec);
2215}
2216
2217/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002218static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002219{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002220 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002221 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2222 switch (res >> 26) {
2223 case CONEXANT_HP_EVENT:
2224 cxt5066_hp_automute(codec);
2225 break;
2226 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002227 /* ignore mic events in DC mode; we're always using the jack */
2228 if (!spec->dc_enable)
2229 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002230 break;
2231 }
2232}
2233
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002234/* unsolicited event for jack sensing */
2235static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2236{
2237 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2238 switch (res >> 26) {
2239 case CONEXANT_HP_EVENT:
2240 cxt5066_hp_automute(codec);
2241 break;
2242 case CONEXANT_MIC_EVENT:
2243 cxt5066_vostro_automic(codec);
2244 break;
2245 }
2246}
2247
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002248/* unsolicited event for jack sensing */
2249static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2250{
2251 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2252 switch (res >> 26) {
2253 case CONEXANT_HP_EVENT:
2254 cxt5066_hp_automute(codec);
2255 break;
2256 case CONEXANT_MIC_EVENT:
2257 cxt5066_ideapad_automic(codec);
2258 break;
2259 }
2260}
2261
Daniel Drake0fb67e92009-07-16 14:46:57 +01002262static const struct hda_input_mux cxt5066_analog_mic_boost = {
2263 .num_items = 5,
2264 .items = {
2265 { "0dB", 0 },
2266 { "10dB", 1 },
2267 { "20dB", 2 },
2268 { "30dB", 3 },
2269 { "40dB", 4 },
2270 },
2271};
2272
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002273static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002274{
2275 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002276 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002277 AC_VERB_SET_AMP_GAIN_MUTE,
2278 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2279 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002280 if (spec->ideapad) {
2281 /* adjust the internal mic as well...it is not through 0x17 */
2282 snd_hda_codec_write_cache(codec, 0x23, 0,
2283 AC_VERB_SET_AMP_GAIN_MUTE,
2284 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2285 cxt5066_analog_mic_boost.
2286 items[spec->mic_boost].index);
2287 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002288}
2289
Daniel Drake0fb67e92009-07-16 14:46:57 +01002290static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2291 struct snd_ctl_elem_info *uinfo)
2292{
2293 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2294}
2295
2296static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2297 struct snd_ctl_elem_value *ucontrol)
2298{
2299 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002300 struct conexant_spec *spec = codec->spec;
2301 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002302 return 0;
2303}
2304
2305static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2306 struct snd_ctl_elem_value *ucontrol)
2307{
2308 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002309 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002310 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2311 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002312 idx = ucontrol->value.enumerated.item[0];
2313 if (idx >= imux->num_items)
2314 idx = imux->num_items - 1;
2315
Daniel Drakec4cfe662010-01-07 13:47:04 +01002316 spec->mic_boost = idx;
2317 if (!spec->dc_enable)
2318 cxt5066_set_mic_boost(codec);
2319 return 1;
2320}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002321
Daniel Drakec4cfe662010-01-07 13:47:04 +01002322static void cxt5066_enable_dc(struct hda_codec *codec)
2323{
2324 const struct hda_verb enable_dc_mode[] = {
2325 /* disable gain */
2326 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2327
2328 /* switch to DC input */
2329 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2330 {}
2331 };
2332
2333 /* configure as input source */
2334 snd_hda_sequence_write(codec, enable_dc_mode);
2335 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2336}
2337
2338static void cxt5066_disable_dc(struct hda_codec *codec)
2339{
2340 /* reconfigure input source */
2341 cxt5066_set_mic_boost(codec);
2342 /* automic also selects the right mic if we're recording */
2343 cxt5066_olpc_automic(codec);
2344}
2345
2346static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2347 struct snd_ctl_elem_value *ucontrol)
2348{
2349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2350 struct conexant_spec *spec = codec->spec;
2351 ucontrol->value.integer.value[0] = spec->dc_enable;
2352 return 0;
2353}
2354
2355static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2356 struct snd_ctl_elem_value *ucontrol)
2357{
2358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2359 struct conexant_spec *spec = codec->spec;
2360 int dc_enable = !!ucontrol->value.integer.value[0];
2361
2362 if (dc_enable == spec->dc_enable)
2363 return 0;
2364
2365 spec->dc_enable = dc_enable;
2366 if (dc_enable)
2367 cxt5066_enable_dc(codec);
2368 else
2369 cxt5066_disable_dc(codec);
2370
2371 return 1;
2372}
2373
2374static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2375 struct snd_ctl_elem_info *uinfo)
2376{
2377 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2378}
2379
2380static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2381 struct snd_ctl_elem_value *ucontrol)
2382{
2383 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2384 struct conexant_spec *spec = codec->spec;
2385 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2386 return 0;
2387}
2388
2389static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2390 struct snd_ctl_elem_value *ucontrol)
2391{
2392 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2393 struct conexant_spec *spec = codec->spec;
2394 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2395 unsigned int idx;
2396
2397 idx = ucontrol->value.enumerated.item[0];
2398 if (idx >= imux->num_items)
2399 idx = imux->num_items - 1;
2400
2401 spec->dc_input_bias = idx;
2402 if (spec->dc_enable)
2403 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002404 return 1;
2405}
2406
Daniel Drake75f89912010-01-07 13:46:25 +01002407static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2408{
2409 struct conexant_spec *spec = codec->spec;
2410 /* mark as recording and configure the microphone widget so that the
2411 * recording LED comes on. */
2412 spec->recording = 1;
2413 cxt5066_olpc_select_mic(codec);
2414}
2415
2416static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2417{
2418 struct conexant_spec *spec = codec->spec;
2419 const struct hda_verb disable_mics[] = {
2420 /* disable external mic, port B */
2421 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2422
2423 /* disble internal mic, port C */
2424 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002425
2426 /* disable DC capture, port F */
2427 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002428 {},
2429 };
2430
2431 snd_hda_sequence_write(codec, disable_mics);
2432 spec->recording = 0;
2433}
2434
Daniel Drake0fb67e92009-07-16 14:46:57 +01002435static struct hda_input_mux cxt5066_capture_source = {
2436 .num_items = 4,
2437 .items = {
2438 { "Mic B", 0 },
2439 { "Mic C", 1 },
2440 { "Mic E", 2 },
2441 { "Mic F", 3 },
2442 },
2443};
2444
2445static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2446 .ops = &snd_hda_bind_vol,
2447 .values = {
2448 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2449 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2450 0
2451 },
2452};
2453
2454static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2455 .ops = &snd_hda_bind_sw,
2456 .values = {
2457 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2458 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2459 0
2460 },
2461};
2462
2463static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2464 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2465 {}
2466};
2467
2468static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2469 {
2470 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2471 .name = "Master Playback Volume",
2472 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2473 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2474 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002475 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002476 .info = snd_hda_mixer_amp_volume_info,
2477 .get = snd_hda_mixer_amp_volume_get,
2478 .put = snd_hda_mixer_amp_volume_put,
2479 .tlv = { .c = snd_hda_mixer_amp_tlv },
2480 /* offset by 28 volume steps to limit minimum gain to -46dB */
2481 .private_value =
2482 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2483 },
2484 {}
2485};
2486
Daniel Drakec4cfe662010-01-07 13:47:04 +01002487static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2488 {
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2490 .name = "DC Mode Enable Switch",
2491 .info = snd_ctl_boolean_mono_info,
2492 .get = cxt5066_olpc_dc_get,
2493 .put = cxt5066_olpc_dc_put,
2494 },
2495 {
2496 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2497 .name = "DC Input Bias Enum",
2498 .info = cxt5066_olpc_dc_bias_enum_info,
2499 .get = cxt5066_olpc_dc_bias_enum_get,
2500 .put = cxt5066_olpc_dc_bias_enum_put,
2501 },
2502 {}
2503};
2504
Daniel Drake0fb67e92009-07-16 14:46:57 +01002505static struct snd_kcontrol_new cxt5066_mixers[] = {
2506 {
2507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2508 .name = "Master Playback Switch",
2509 .info = cxt_eapd_info,
2510 .get = cxt_eapd_get,
2511 .put = cxt5066_hp_master_sw_put,
2512 .private_value = 0x1d,
2513 },
2514
2515 {
2516 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002517 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002518 .info = cxt5066_mic_boost_mux_enum_info,
2519 .get = cxt5066_mic_boost_mux_enum_get,
2520 .put = cxt5066_mic_boost_mux_enum_put,
2521 },
2522
2523 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2524 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2525 {}
2526};
2527
Einar Rünkaru254bba62009-12-16 22:16:13 +02002528static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2529 {
2530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2531 .name = "Int Mic Boost Capture Enum",
2532 .info = cxt5066_mic_boost_mux_enum_info,
2533 .get = cxt5066_mic_boost_mux_enum_get,
2534 .put = cxt5066_mic_boost_mux_enum_put,
2535 .private_value = 0x23 | 0x100,
2536 },
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +02002537 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
Einar Rünkaru254bba62009-12-16 22:16:13 +02002538 {}
2539};
2540
Daniel Drake0fb67e92009-07-16 14:46:57 +01002541static struct hda_verb cxt5066_init_verbs[] = {
2542 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2543 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2544 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2545 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2546
2547 /* Speakers */
2548 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2549 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2550
2551 /* HP, Amp */
2552 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2553 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2554
2555 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2556 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2557
2558 /* DAC1 */
2559 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2560
2561 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2562 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2563 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2564 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2565 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2566 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2567
2568 /* no digital microphone support yet */
2569 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2570
2571 /* Audio input selector */
2572 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2573
2574 /* SPDIF route: PCM */
2575 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2576 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2577
2578 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2579 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2580
2581 /* EAPD */
2582 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2583
2584 /* not handling these yet */
2585 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2586 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2587 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2588 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2589 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2590 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2591 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2592 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2593 { } /* end */
2594};
2595
2596static struct hda_verb cxt5066_init_verbs_olpc[] = {
2597 /* Port A: headphones */
2598 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2599 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2600
2601 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002602 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002603
2604 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002605 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002606
2607 /* Port D: unused */
2608 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2609
2610 /* Port E: unused, but has primary EAPD */
2611 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2612 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2613
Daniel Drakec4cfe662010-01-07 13:47:04 +01002614 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002615 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2616
2617 /* Port G: internal speakers */
2618 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2619 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2620
2621 /* DAC1 */
2622 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2623
2624 /* DAC2: unused */
2625 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2626
2627 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2628 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2629 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2630 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2631 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2632 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2633 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2634 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2635 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2636 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2637 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2638 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2639
2640 /* Disable digital microphone port */
2641 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2642
2643 /* Audio input selectors */
2644 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2645 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2646
2647 /* Disable SPDIF */
2648 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2649 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2650
2651 /* enable unsolicited events for Port A and B */
2652 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2653 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2654 { } /* end */
2655};
2656
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002657static struct hda_verb cxt5066_init_verbs_vostro[] = {
2658 /* Port A: headphones */
2659 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2660 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2661
2662 /* Port B: external microphone */
2663 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2664
2665 /* Port C: unused */
2666 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2667
2668 /* Port D: unused */
2669 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2670
2671 /* Port E: unused, but has primary EAPD */
2672 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2673 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2674
2675 /* Port F: unused */
2676 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2677
2678 /* Port G: internal speakers */
2679 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2680 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2681
2682 /* DAC1 */
2683 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2684
2685 /* DAC2: unused */
2686 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2687
2688 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2689 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2690 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2691 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2692 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2693 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2694 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2695 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2696 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2697 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2698 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2699 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2700
2701 /* Digital microphone port */
2702 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2703
2704 /* Audio input selectors */
2705 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2706 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2707
2708 /* Disable SPDIF */
2709 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2710 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2711
2712 /* enable unsolicited events for Port A and B */
2713 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2714 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2715 { } /* end */
2716};
2717
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002718static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2719 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2720 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2721 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2722 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2723
2724 /* Speakers */
2725 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2726 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2727
2728 /* HP, Amp */
2729 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2730 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2731
2732 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2733 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2734
2735 /* DAC1 */
2736 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2737
2738 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2739 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2740 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2741 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2742 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2744 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2745
2746 /* Audio input selector */
2747 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2748 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2749
2750 /* SPDIF route: PCM */
2751 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2752 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2753
2754 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2755 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2756
2757 /* internal microphone */
2758 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2759
2760 /* EAPD */
2761 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2762
2763 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2764 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2765 { } /* end */
2766};
2767
Daniel Drake0fb67e92009-07-16 14:46:57 +01002768static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2769 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2770 { } /* end */
2771};
2772
2773/* initialize jack-sensing, too */
2774static int cxt5066_init(struct hda_codec *codec)
2775{
Einar Rünkaru254bba62009-12-16 22:16:13 +02002776 struct conexant_spec *spec = codec->spec;
2777
Daniel Drake0fb67e92009-07-16 14:46:57 +01002778 snd_printdd("CXT5066: init\n");
2779 conexant_init(codec);
2780 if (codec->patch_ops.unsol_event) {
2781 cxt5066_hp_automute(codec);
Einar Rünkaru254bba62009-12-16 22:16:13 +02002782 if (spec->dell_vostro)
2783 cxt5066_vostro_automic(codec);
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002784 else if (spec->ideapad)
2785 cxt5066_ideapad_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002786 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002787 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002788 return 0;
2789}
2790
Daniel Drake75f89912010-01-07 13:46:25 +01002791static int cxt5066_olpc_init(struct hda_codec *codec)
2792{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002793 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002794 snd_printdd("CXT5066: init\n");
2795 conexant_init(codec);
2796 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002797 if (!spec->dc_enable) {
2798 cxt5066_set_mic_boost(codec);
2799 cxt5066_olpc_automic(codec);
2800 } else {
2801 cxt5066_enable_dc(codec);
2802 }
Daniel Drake75f89912010-01-07 13:46:25 +01002803 return 0;
2804}
2805
Daniel Drake0fb67e92009-07-16 14:46:57 +01002806enum {
2807 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2808 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2809 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002810 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002811 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002812 CXT5066_MODELS
2813};
2814
2815static const char *cxt5066_models[CXT5066_MODELS] = {
2816 [CXT5066_LAPTOP] = "laptop",
2817 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2818 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002819 [CXT5066_DELL_VOSTO] = "dell-vostro",
2820 [CXT5066_IDEAPAD] = "ideapad",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002821};
2822
2823static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2824 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2825 CXT5066_LAPTOP),
2826 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2827 CXT5066_DELL_LAPTOP),
Daniel Drake798a8a12009-11-04 10:11:07 +00002828 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002829 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002830 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002831 {}
2832};
2833
2834static int patch_cxt5066(struct hda_codec *codec)
2835{
2836 struct conexant_spec *spec;
2837 int board_config;
2838
2839 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2840 if (!spec)
2841 return -ENOMEM;
2842 codec->spec = spec;
2843
2844 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01002845 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002846
2847 spec->dell_automute = 0;
2848 spec->multiout.max_channels = 2;
2849 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2850 spec->multiout.dac_nids = cxt5066_dac_nids;
2851 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2852 spec->num_adc_nids = 1;
2853 spec->adc_nids = cxt5066_adc_nids;
2854 spec->capsrc_nids = cxt5066_capsrc_nids;
2855 spec->input_mux = &cxt5066_capture_source;
2856
2857 spec->port_d_mode = PIN_HP;
2858
2859 spec->num_init_verbs = 1;
2860 spec->init_verbs[0] = cxt5066_init_verbs;
2861 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2862 spec->channel_mode = cxt5066_modes;
2863 spec->cur_adc = 0;
2864 spec->cur_adc_idx = 0;
2865
2866 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2867 cxt5066_models, cxt5066_cfg_tbl);
2868 switch (board_config) {
2869 default:
2870 case CXT5066_LAPTOP:
2871 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2872 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2873 break;
2874 case CXT5066_DELL_LAPTOP:
2875 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2876 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2877
2878 spec->port_d_mode = PIN_OUT;
2879 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2880 spec->num_init_verbs++;
2881 spec->dell_automute = 1;
2882 break;
2883 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01002884 codec->patch_ops.init = cxt5066_olpc_init;
2885 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002886 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2887 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01002888 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002889 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2890 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01002891 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002892
2893 /* no S/PDIF out */
2894 spec->multiout.dig_out_nid = 0;
2895
2896 /* input source automatically selected */
2897 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01002898
2899 /* our capture hooks which allow us to turn on the microphone LED
2900 * at the right time */
2901 spec->capture_prepare = cxt5066_olpc_capture_prepare;
2902 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002903 break;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002904 case CXT5066_DELL_VOSTO:
Daniel Drake75f89912010-01-07 13:46:25 +01002905 codec->patch_ops.init = cxt5066_init;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002906 codec->patch_ops.unsol_event = cxt5066_vostro_event;
2907 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2908 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2909 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02002910 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002911 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02002912 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01002913 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +02002914 snd_hda_attach_beep_device(codec, 0x13);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002915
2916 /* no S/PDIF out */
2917 spec->multiout.dig_out_nid = 0;
2918
2919 /* input source automatically selected */
2920 spec->input_mux = NULL;
2921 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002922 case CXT5066_IDEAPAD:
2923 codec->patch_ops.init = cxt5066_init;
2924 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
2925 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2926 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2927 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
2928 spec->port_d_mode = 0;
2929 spec->ideapad = 1;
2930 spec->mic_boost = 2; /* default 20dB gain */
2931
2932 /* no S/PDIF out */
2933 spec->multiout.dig_out_nid = 0;
2934
2935 /* input source automatically selected */
2936 spec->input_mux = NULL;
2937 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002938 }
2939
2940 return 0;
2941}
Takashi Iwai461e2c72008-01-25 11:35:17 +01002942
2943/*
2944 */
2945
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002946static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01002947 { .id = 0x14f15045, .name = "CX20549 (Venice)",
2948 .patch = patch_cxt5045 },
2949 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2950 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01002951 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2952 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01002953 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2954 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002955 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2956 .patch = patch_cxt5066 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01002957 {} /* terminator */
2958};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002959
2960MODULE_ALIAS("snd-hda-codec-id:14f15045");
2961MODULE_ALIAS("snd-hda-codec-id:14f15047");
2962MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01002963MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002964MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002965
2966MODULE_LICENSE("GPL");
2967MODULE_DESCRIPTION("Conexant HD-audio codec");
2968
2969static struct hda_codec_preset_list conexant_list = {
2970 .preset = snd_hda_preset_conexant,
2971 .owner = THIS_MODULE,
2972};
2973
2974static int __init patch_conexant_init(void)
2975{
2976 return snd_hda_add_codec_preset(&conexant_list);
2977}
2978
2979static void __exit patch_conexant_exit(void)
2980{
2981 snd_hda_delete_codec_preset(&conexant_list);
2982}
2983
2984module_init(patch_conexant_init)
2985module_exit(patch_conexant_exit)