blob: 2bb9a58db9fa2ee93b989ca958e0e266def95583 [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>
28#include "hda_codec.h"
29#include "hda_local.h"
30
31#define CXT_PIN_DIR_IN 0x00
32#define CXT_PIN_DIR_OUT 0x01
33#define CXT_PIN_DIR_INOUT 0x02
34#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
35#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
36
37#define CONEXANT_HP_EVENT 0x37
38#define CONEXANT_MIC_EVENT 0x38
39
40
41
42struct conexant_spec {
43
44 struct snd_kcontrol_new *mixers[5];
45 int num_mixers;
46
47 const struct hda_verb *init_verbs[5]; /* initialization verbs
48 * don't forget NULL
49 * termination!
50 */
51 unsigned int num_init_verbs;
52
53 /* playback */
54 struct hda_multi_out multiout; /* playback set-up
55 * max_channels, dacs must be set
56 * dig_out_nid and hp_nid are optional
57 */
58 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010059 unsigned int hp_present;
Tobin Davisc9b443d2006-11-14 12:13:39 +010060 unsigned int need_dac_fix;
61
62 /* capture */
63 unsigned int num_adc_nids;
64 hda_nid_t *adc_nids;
65 hda_nid_t dig_in_nid; /* digital-in NID; optional */
66
Takashi Iwai461e2c72008-01-25 11:35:17 +010067 unsigned int cur_adc_idx;
68 hda_nid_t cur_adc;
69 unsigned int cur_adc_stream_tag;
70 unsigned int cur_adc_format;
71
Tobin Davisc9b443d2006-11-14 12:13:39 +010072 /* capture source */
73 const struct hda_input_mux *input_mux;
74 hda_nid_t *capsrc_nids;
75 unsigned int cur_mux[3];
76
77 /* channel model */
78 const struct hda_channel_mode *channel_mode;
79 int num_channel_mode;
80
81 /* PCM information */
82 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
83
84 struct mutex amp_mutex; /* PCM volume/mute control mutex */
85 unsigned int spdif_route;
86
87 /* dynamic controls, init_verbs and input_mux */
88 struct auto_pin_cfg autocfg;
89 unsigned int num_kctl_alloc, num_kctl_used;
90 struct snd_kcontrol_new *kctl_alloc;
91 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020092 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +010093
94};
95
96static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
97 struct hda_codec *codec,
98 struct snd_pcm_substream *substream)
99{
100 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100101 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
102 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100103}
104
105static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
106 struct hda_codec *codec,
107 unsigned int stream_tag,
108 unsigned int format,
109 struct snd_pcm_substream *substream)
110{
111 struct conexant_spec *spec = codec->spec;
112 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
113 stream_tag,
114 format, substream);
115}
116
117static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
118 struct hda_codec *codec,
119 struct snd_pcm_substream *substream)
120{
121 struct conexant_spec *spec = codec->spec;
122 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
123}
124
125/*
126 * Digital out
127 */
128static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
129 struct hda_codec *codec,
130 struct snd_pcm_substream *substream)
131{
132 struct conexant_spec *spec = codec->spec;
133 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
134}
135
136static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
137 struct hda_codec *codec,
138 struct snd_pcm_substream *substream)
139{
140 struct conexant_spec *spec = codec->spec;
141 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
142}
143
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200144static int conexant_dig_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_dig_prepare(codec, &spec->multiout,
152 stream_tag,
153 format, substream);
154}
155
Tobin Davisc9b443d2006-11-14 12:13:39 +0100156/*
157 * Analog capture
158 */
159static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
160 struct hda_codec *codec,
161 unsigned int stream_tag,
162 unsigned int format,
163 struct snd_pcm_substream *substream)
164{
165 struct conexant_spec *spec = codec->spec;
166 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
167 stream_tag, 0, format);
168 return 0;
169}
170
171static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
172 struct hda_codec *codec,
173 struct snd_pcm_substream *substream)
174{
175 struct conexant_spec *spec = codec->spec;
176 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
177 0, 0, 0);
178 return 0;
179}
180
181
182
183static struct hda_pcm_stream conexant_pcm_analog_playback = {
184 .substreams = 1,
185 .channels_min = 2,
186 .channels_max = 2,
187 .nid = 0, /* fill later */
188 .ops = {
189 .open = conexant_playback_pcm_open,
190 .prepare = conexant_playback_pcm_prepare,
191 .cleanup = conexant_playback_pcm_cleanup
192 },
193};
194
195static struct hda_pcm_stream conexant_pcm_analog_capture = {
196 .substreams = 1,
197 .channels_min = 2,
198 .channels_max = 2,
199 .nid = 0, /* fill later */
200 .ops = {
201 .prepare = conexant_capture_pcm_prepare,
202 .cleanup = conexant_capture_pcm_cleanup
203 },
204};
205
206
207static struct hda_pcm_stream conexant_pcm_digital_playback = {
208 .substreams = 1,
209 .channels_min = 2,
210 .channels_max = 2,
211 .nid = 0, /* fill later */
212 .ops = {
213 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200214 .close = conexant_dig_playback_pcm_close,
215 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100216 },
217};
218
219static struct hda_pcm_stream conexant_pcm_digital_capture = {
220 .substreams = 1,
221 .channels_min = 2,
222 .channels_max = 2,
223 /* NID is set in alc_build_pcms */
224};
225
Takashi Iwai461e2c72008-01-25 11:35:17 +0100226static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
227 struct hda_codec *codec,
228 unsigned int stream_tag,
229 unsigned int format,
230 struct snd_pcm_substream *substream)
231{
232 struct conexant_spec *spec = codec->spec;
233 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
234 spec->cur_adc_stream_tag = stream_tag;
235 spec->cur_adc_format = format;
236 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
237 return 0;
238}
239
240static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
241 struct hda_codec *codec,
242 struct snd_pcm_substream *substream)
243{
244 struct conexant_spec *spec = codec->spec;
245 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
246 spec->cur_adc = 0;
247 return 0;
248}
249
250static struct hda_pcm_stream cx5051_pcm_analog_capture = {
251 .substreams = 1,
252 .channels_min = 2,
253 .channels_max = 2,
254 .nid = 0, /* fill later */
255 .ops = {
256 .prepare = cx5051_capture_pcm_prepare,
257 .cleanup = cx5051_capture_pcm_cleanup
258 },
259};
260
Tobin Davisc9b443d2006-11-14 12:13:39 +0100261static int conexant_build_pcms(struct hda_codec *codec)
262{
263 struct conexant_spec *spec = codec->spec;
264 struct hda_pcm *info = spec->pcm_rec;
265
266 codec->num_pcms = 1;
267 codec->pcm_info = info;
268
269 info->name = "CONEXANT Analog";
270 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
271 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
272 spec->multiout.max_channels;
273 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
274 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100275 if (codec->vendor_id == 0x14f15051)
276 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
277 cx5051_pcm_analog_capture;
278 else
279 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
280 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100281 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
282 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
283
284 if (spec->multiout.dig_out_nid) {
285 info++;
286 codec->num_pcms++;
287 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100288 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
290 conexant_pcm_digital_playback;
291 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
292 spec->multiout.dig_out_nid;
293 if (spec->dig_in_nid) {
294 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
295 conexant_pcm_digital_capture;
296 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
297 spec->dig_in_nid;
298 }
299 }
300
301 return 0;
302}
303
304static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_info *uinfo)
306{
307 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
308 struct conexant_spec *spec = codec->spec;
309
310 return snd_hda_input_mux_info(spec->input_mux, uinfo);
311}
312
313static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
314 struct snd_ctl_elem_value *ucontrol)
315{
316 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
317 struct conexant_spec *spec = codec->spec;
318 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
319
320 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
321 return 0;
322}
323
324static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_value *ucontrol)
326{
327 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
328 struct conexant_spec *spec = codec->spec;
329 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
330
331 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
332 spec->capsrc_nids[adc_idx],
333 &spec->cur_mux[adc_idx]);
334}
335
336static int conexant_init(struct hda_codec *codec)
337{
338 struct conexant_spec *spec = codec->spec;
339 int i;
340
341 for (i = 0; i < spec->num_init_verbs; i++)
342 snd_hda_sequence_write(codec, spec->init_verbs[i]);
343 return 0;
344}
345
346static void conexant_free(struct hda_codec *codec)
347{
348 struct conexant_spec *spec = codec->spec;
349 unsigned int i;
350
351 if (spec->kctl_alloc) {
352 for (i = 0; i < spec->num_kctl_used; i++)
353 kfree(spec->kctl_alloc[i].name);
354 kfree(spec->kctl_alloc);
355 }
356
357 kfree(codec->spec);
358}
359
Tobin Davisc9b443d2006-11-14 12:13:39 +0100360static int conexant_build_controls(struct hda_codec *codec)
361{
362 struct conexant_spec *spec = codec->spec;
363 unsigned int i;
364 int err;
365
366 for (i = 0; i < spec->num_mixers; i++) {
367 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
368 if (err < 0)
369 return err;
370 }
371 if (spec->multiout.dig_out_nid) {
372 err = snd_hda_create_spdif_out_ctls(codec,
373 spec->multiout.dig_out_nid);
374 if (err < 0)
375 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100376 err = snd_hda_create_spdif_share_sw(codec,
377 &spec->multiout);
378 if (err < 0)
379 return err;
380 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100381 }
382 if (spec->dig_in_nid) {
383 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
384 if (err < 0)
385 return err;
386 }
387 return 0;
388}
389
390static struct hda_codec_ops conexant_patch_ops = {
391 .build_controls = conexant_build_controls,
392 .build_pcms = conexant_build_pcms,
393 .init = conexant_init,
394 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100395};
396
397/*
398 * EAPD control
399 * the private value = nid | (invert << 8)
400 */
401
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200402#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100403
Tobin Davis82f30042007-02-13 12:45:44 +0100404static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100405 struct snd_ctl_elem_value *ucontrol)
406{
407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
408 struct conexant_spec *spec = codec->spec;
409 int invert = (kcontrol->private_value >> 8) & 1;
410 if (invert)
411 ucontrol->value.integer.value[0] = !spec->cur_eapd;
412 else
413 ucontrol->value.integer.value[0] = spec->cur_eapd;
414 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100415
Tobin Davisc9b443d2006-11-14 12:13:39 +0100416}
417
Tobin Davis82f30042007-02-13 12:45:44 +0100418static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100419 struct snd_ctl_elem_value *ucontrol)
420{
421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
422 struct conexant_spec *spec = codec->spec;
423 int invert = (kcontrol->private_value >> 8) & 1;
424 hda_nid_t nid = kcontrol->private_value & 0xff;
425 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100426
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100427 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100428 if (invert)
429 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200430 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100431 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100432
Tobin Davisc9b443d2006-11-14 12:13:39 +0100433 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200434 snd_hda_codec_write_cache(codec, nid,
435 0, AC_VERB_SET_EAPD_BTLENABLE,
436 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100437 return 1;
438}
439
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100440/* controls for test mode */
441#ifdef CONFIG_SND_DEBUG
442
Tobin Davis82f30042007-02-13 12:45:44 +0100443#define CXT_EAPD_SWITCH(xname, nid, mask) \
444 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
445 .info = cxt_eapd_info, \
446 .get = cxt_eapd_get, \
447 .put = cxt_eapd_put, \
448 .private_value = nid | (mask<<16) }
449
450
451
Tobin Davisc9b443d2006-11-14 12:13:39 +0100452static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
453 struct snd_ctl_elem_info *uinfo)
454{
455 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
456 struct conexant_spec *spec = codec->spec;
457 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
458 spec->num_channel_mode);
459}
460
461static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
462 struct snd_ctl_elem_value *ucontrol)
463{
464 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465 struct conexant_spec *spec = codec->spec;
466 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
467 spec->num_channel_mode,
468 spec->multiout.max_channels);
469}
470
471static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
472 struct snd_ctl_elem_value *ucontrol)
473{
474 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
475 struct conexant_spec *spec = codec->spec;
476 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
477 spec->num_channel_mode,
478 &spec->multiout.max_channels);
479 if (err >= 0 && spec->need_dac_fix)
480 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
481 return err;
482}
483
484#define CXT_PIN_MODE(xname, nid, dir) \
485 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
486 .info = conexant_ch_mode_info, \
487 .get = conexant_ch_mode_get, \
488 .put = conexant_ch_mode_put, \
489 .private_value = nid | (dir<<16) }
490
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100491#endif /* CONFIG_SND_DEBUG */
492
Tobin Davisc9b443d2006-11-14 12:13:39 +0100493/* Conexant 5045 specific */
494
495static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
496static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
497static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100498#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100499
Tobin Davis5cd57522006-11-20 17:42:09 +0100500static struct hda_channel_mode cxt5045_modes[1] = {
501 { 2, NULL },
502};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100503
504static struct hda_input_mux cxt5045_capture_source = {
505 .num_items = 2,
506 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100507 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100508 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100509 }
510};
511
Jiang Zhe5218c892008-01-17 11:18:41 +0100512static struct hda_input_mux cxt5045_capture_source_benq = {
513 .num_items = 3,
514 .items = {
515 { "IntMic", 0x1 },
516 { "ExtMic", 0x2 },
517 { "LineIn", 0x3 },
518 }
519};
520
Tobin Davisc9b443d2006-11-14 12:13:39 +0100521/* turn on/off EAPD (+ mute HP) as a master switch */
522static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
523 struct snd_ctl_elem_value *ucontrol)
524{
525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
526 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100527 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100528
Tobin Davis82f30042007-02-13 12:45:44 +0100529 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100530 return 0;
531
Tobin Davis82f30042007-02-13 12:45:44 +0100532 /* toggle internal speakers mute depending of presence of
533 * the headphone jack
534 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200535 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
536 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
537 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100538
Takashi Iwai47fd8302007-08-10 17:11:07 +0200539 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
540 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
541 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100542 return 1;
543}
544
545/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200546static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
547 .ops = &snd_hda_bind_vol,
548 .values = {
549 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
550 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
551 0
552 },
553};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100554
Tobin Davis7f296732007-03-12 11:39:01 +0100555/* toggle input of built-in and mic jack appropriately */
556static void cxt5045_hp_automic(struct hda_codec *codec)
557{
558 static struct hda_verb mic_jack_on[] = {
559 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
560 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
561 {}
562 };
563 static struct hda_verb mic_jack_off[] = {
564 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
565 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
566 {}
567 };
568 unsigned int present;
569
570 present = snd_hda_codec_read(codec, 0x12, 0,
571 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
572 if (present)
573 snd_hda_sequence_write(codec, mic_jack_on);
574 else
575 snd_hda_sequence_write(codec, mic_jack_off);
576}
577
Tobin Davisc9b443d2006-11-14 12:13:39 +0100578
579/* mute internal speaker if HP is plugged */
580static void cxt5045_hp_automute(struct hda_codec *codec)
581{
Tobin Davis82f30042007-02-13 12:45:44 +0100582 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100583 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100584
Tobin Davis82f30042007-02-13 12:45:44 +0100585 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100586 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100587
Takashi Iwai47fd8302007-08-10 17:11:07 +0200588 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
589 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
590 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100591}
592
593/* unsolicited event for HP jack sensing */
594static void cxt5045_hp_unsol_event(struct hda_codec *codec,
595 unsigned int res)
596{
597 res >>= 26;
598 switch (res) {
599 case CONEXANT_HP_EVENT:
600 cxt5045_hp_automute(codec);
601 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100602 case CONEXANT_MIC_EVENT:
603 cxt5045_hp_automic(codec);
604 break;
605
Tobin Davisc9b443d2006-11-14 12:13:39 +0100606 }
607}
608
609static struct snd_kcontrol_new cxt5045_mixers[] = {
610 {
611 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
612 .name = "Capture Source",
613 .info = conexant_mux_enum_info,
614 .get = conexant_mux_enum_get,
615 .put = conexant_mux_enum_put
616 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200617 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
618 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
619 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
620 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
621 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
622 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
623 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
624 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
625 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
626 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200627 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100628 {
629 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
630 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100631 .info = cxt_eapd_info,
632 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100634 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100635 },
636
637 {}
638};
639
Jiang Zhe5218c892008-01-17 11:18:41 +0100640static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
641 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
642 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
643 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
644 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
645
646 {}
647};
648
Tobin Davisc9b443d2006-11-14 12:13:39 +0100649static struct hda_verb cxt5045_init_verbs[] = {
650 /* Line in, Mic */
651 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Tobin Davis7f296732007-03-12 11:39:01 +0100652 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100653 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200654 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
655 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
656 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
657 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
658 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
659 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
660 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
661 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
662 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100663 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100664 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100665 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100666 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
667 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100668 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100669 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100670 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100671 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100672 { } /* end */
673};
674
Jiang Zhe5218c892008-01-17 11:18:41 +0100675static struct hda_verb cxt5045_benq_init_verbs[] = {
676 /* Int Mic, Mic */
677 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
678 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
679 /* Line In,HP, Amp */
680 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
681 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
682 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
683 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
684 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
685 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
686 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
687 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
688 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
689 /* Record selector: Int mic */
690 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
691 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
692 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
693 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100694 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100695 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
696 /* EAPD */
697 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
698 { } /* end */
699};
Tobin Davis7f296732007-03-12 11:39:01 +0100700
701static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
702 /* pin sensing on HP jack */
703 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200704 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100705};
706
707static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
708 /* pin sensing on HP jack */
709 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200710 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100711};
712
Tobin Davisc9b443d2006-11-14 12:13:39 +0100713#ifdef CONFIG_SND_DEBUG
714/* Test configuration for debugging, modelled after the ALC260 test
715 * configuration.
716 */
717static struct hda_input_mux cxt5045_test_capture_source = {
718 .num_items = 5,
719 .items = {
720 { "MIXER", 0x0 },
721 { "MIC1 pin", 0x1 },
722 { "LINE1 pin", 0x2 },
723 { "HP-OUT pin", 0x3 },
724 { "CD pin", 0x4 },
725 },
726};
727
728static struct snd_kcontrol_new cxt5045_test_mixer[] = {
729
730 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100731 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
732 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100733 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
734 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
735 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
736 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100737
738 /* Modes for retasking pin widgets */
739 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
740 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
741
Tobin Davis82f30042007-02-13 12:45:44 +0100742 /* EAPD Switch Control */
743 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
744
Tobin Davisc9b443d2006-11-14 12:13:39 +0100745 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746
Tobin Davis7f296732007-03-12 11:39:01 +0100747 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
748 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
749 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
750 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
751 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
752 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
753 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
754 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
755 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
756 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100757 {
758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
759 .name = "Input Source",
760 .info = conexant_mux_enum_info,
761 .get = conexant_mux_enum_get,
762 .put = conexant_mux_enum_put,
763 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200764 /* Audio input controls */
765 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
766 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
767 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
768 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
769 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
770 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
771 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
772 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
773 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
774 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775 { } /* end */
776};
777
778static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100779 /* Set connections */
780 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
781 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
782 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783 /* Enable retasking pins as output, initially without power amp */
784 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100785 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100786
787 /* Disable digital (SPDIF) pins initially, but users can enable
788 * them via a mixer switch. In the case of SPDIF-out, this initverb
789 * payload also sets the generation to 0, output to be in "consumer"
790 * PCM format, copyright asserted, no pre-emphasis and no validity
791 * control.
792 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100793 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
794 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795
796 /* Start with output sum widgets muted and their output gains at min */
797 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
798 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
799
800 /* Unmute retasking pin widget output buffers since the default
801 * state appears to be output. As the pin mode is changed by the
802 * user the pin mode control will take care of enabling the pin's
803 * input/output buffers as needed.
804 */
805 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
806 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
807
808 /* Mute capture amp left and right */
809 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
810
811 /* Set ADC connection select to match default mixer setting (mic1
812 * pin)
813 */
814 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100815 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100816
817 /* Mute all inputs to mixer widget (even unconnected ones) */
818 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
822 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
823
824 { }
825};
826#endif
827
828
829/* initialize jack-sensing, too */
830static int cxt5045_init(struct hda_codec *codec)
831{
832 conexant_init(codec);
833 cxt5045_hp_automute(codec);
834 return 0;
835}
836
837
838enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100839 CXT5045_LAPTOP_HPSENSE,
840 CXT5045_LAPTOP_MICSENSE,
841 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100842 CXT5045_BENQ,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100843#ifdef CONFIG_SND_DEBUG
844 CXT5045_TEST,
845#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100846 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100847};
848
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100849static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100850 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
851 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
852 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
853 [CXT5045_BENQ] = "benq",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100854#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100855 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100856#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100857};
858
859static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100860 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
861 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
862 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
863 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
864 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
865 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai0f6a5152008-01-29 13:26:04 +0100866 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +0100867 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
868 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +0100869 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +0100870 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
871 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
872 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
873 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
874 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
875 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
876 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
877 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
878 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100879 {}
880};
881
882static int patch_cxt5045(struct hda_codec *codec)
883{
884 struct conexant_spec *spec;
885 int board_config;
886
887 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
888 if (!spec)
889 return -ENOMEM;
890 mutex_init(&spec->amp_mutex);
891 codec->spec = spec;
892
893 spec->multiout.max_channels = 2;
894 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
895 spec->multiout.dac_nids = cxt5045_dac_nids;
896 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
897 spec->num_adc_nids = 1;
898 spec->adc_nids = cxt5045_adc_nids;
899 spec->capsrc_nids = cxt5045_capsrc_nids;
900 spec->input_mux = &cxt5045_capture_source;
901 spec->num_mixers = 1;
902 spec->mixers[0] = cxt5045_mixers;
903 spec->num_init_verbs = 1;
904 spec->init_verbs[0] = cxt5045_init_verbs;
905 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100906 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
907 spec->channel_mode = cxt5045_modes,
908
Tobin Davisc9b443d2006-11-14 12:13:39 +0100909
910 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100911
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100912 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
913 cxt5045_models,
914 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100915 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +0100916 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100917 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100918 spec->input_mux = &cxt5045_capture_source;
919 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100920 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
921 spec->mixers[0] = cxt5045_mixers;
922 codec->patch_ops.init = cxt5045_init;
923 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100924 case CXT5045_LAPTOP_MICSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100925 spec->input_mux = &cxt5045_capture_source;
926 spec->num_init_verbs = 2;
927 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928 spec->mixers[0] = cxt5045_mixers;
929 codec->patch_ops.init = cxt5045_init;
930 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100931 default:
932 case CXT5045_LAPTOP_HPMICSENSE:
933 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
934 spec->input_mux = &cxt5045_capture_source;
935 spec->num_init_verbs = 3;
936 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
937 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
938 spec->mixers[0] = cxt5045_mixers;
939 codec->patch_ops.init = cxt5045_init;
940 break;
Jiang Zhe5218c892008-01-17 11:18:41 +0100941 case CXT5045_BENQ:
942 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
943 spec->input_mux = &cxt5045_capture_source_benq;
944 spec->num_init_verbs = 1;
945 spec->init_verbs[0] = cxt5045_benq_init_verbs;
946 spec->mixers[0] = cxt5045_mixers;
947 spec->mixers[1] = cxt5045_benq_mixers;
948 spec->num_mixers = 2;
949 codec->patch_ops.init = cxt5045_init;
950 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100951#ifdef CONFIG_SND_DEBUG
952 case CXT5045_TEST:
953 spec->input_mux = &cxt5045_test_capture_source;
954 spec->mixers[0] = cxt5045_test_mixer;
955 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +0100956 break;
957
Tobin Davisc9b443d2006-11-14 12:13:39 +0100958#endif
959 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +0100960
961 /*
962 * Fix max PCM level to 0 dB
963 * (originall it has 0x2b steps with 0dB offset 0x14)
964 */
965 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
966 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
967 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
968 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
969 (1 << AC_AMPCAP_MUTE_SHIFT));
970
Tobin Davisc9b443d2006-11-14 12:13:39 +0100971 return 0;
972}
973
974
975/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100976#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100977
Tobin Davis82f30042007-02-13 12:45:44 +0100978static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100979static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
980static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100981
Tobin Davis5cd57522006-11-20 17:42:09 +0100982static struct hda_channel_mode cxt5047_modes[1] = {
983 { 2, NULL },
984};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100985
986static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +0100987 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100988 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +0100989 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990 }
991};
992
993static struct hda_input_mux cxt5047_hp_capture_source = {
994 .num_items = 1,
995 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100996 { "ExtMic", 0x2 },
997 }
998};
999
1000static struct hda_input_mux cxt5047_toshiba_capture_source = {
1001 .num_items = 2,
1002 .items = {
1003 { "ExtMic", 0x2 },
1004 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001005 }
1006};
1007
1008/* turn on/off EAPD (+ mute HP) as a master switch */
1009static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1010 struct snd_ctl_elem_value *ucontrol)
1011{
1012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1013 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001014 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001015
Tobin Davis82f30042007-02-13 12:45:44 +01001016 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001017 return 0;
1018
Tobin Davis82f30042007-02-13 12:45:44 +01001019 /* toggle internal speakers mute depending of presence of
1020 * the headphone jack
1021 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001022 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1023 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1024 HDA_AMP_MUTE, bits);
1025 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1026 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1027 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001028 return 1;
1029}
1030
Tobin Davis82f30042007-02-13 12:45:44 +01001031/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001032static struct hda_bind_ctls cxt5047_bind_master_vol = {
1033 .ops = &snd_hda_bind_vol,
1034 .values = {
1035 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1036 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1037 0
1038 },
1039};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001040
1041/* mute internal speaker if HP is plugged */
1042static void cxt5047_hp_automute(struct hda_codec *codec)
1043{
Tobin Davis82f30042007-02-13 12:45:44 +01001044 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001045 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001046
Tobin Davis82f30042007-02-13 12:45:44 +01001047 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001048 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001049
Takashi Iwai47fd8302007-08-10 17:11:07 +02001050 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1051 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1052 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001053 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001054 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1055 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001056}
1057
Tobin Davisfb3409e2007-05-17 09:40:47 +02001058/* mute internal speaker if HP is plugged */
1059static void cxt5047_hp2_automute(struct hda_codec *codec)
1060{
1061 struct conexant_spec *spec = codec->spec;
1062 unsigned int bits;
1063
1064 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1065 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1066
Takashi Iwai47fd8302007-08-10 17:11:07 +02001067 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1068 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1069 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001070 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001071 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1072 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001073}
1074
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075/* toggle input of built-in and mic jack appropriately */
1076static void cxt5047_hp_automic(struct hda_codec *codec)
1077{
1078 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001079 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1080 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001081 {}
1082 };
1083 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001084 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1085 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086 {}
1087 };
1088 unsigned int present;
1089
Tobin Davis7f296732007-03-12 11:39:01 +01001090 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001091 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1092 if (present)
1093 snd_hda_sequence_write(codec, mic_jack_on);
1094 else
1095 snd_hda_sequence_write(codec, mic_jack_off);
1096}
1097
1098/* unsolicited event for HP jack sensing */
1099static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1100 unsigned int res)
1101{
Marc Boucher9f113e02008-01-22 15:18:08 +01001102 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001103 case CONEXANT_HP_EVENT:
1104 cxt5047_hp_automute(codec);
1105 break;
1106 case CONEXANT_MIC_EVENT:
1107 cxt5047_hp_automic(codec);
1108 break;
1109 }
1110}
1111
Tobin Davisfb3409e2007-05-17 09:40:47 +02001112/* unsolicited event for HP jack sensing - non-EAPD systems */
1113static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1114 unsigned int res)
1115{
1116 res >>= 26;
1117 switch (res) {
1118 case CONEXANT_HP_EVENT:
1119 cxt5047_hp2_automute(codec);
1120 break;
1121 case CONEXANT_MIC_EVENT:
1122 cxt5047_hp_automic(codec);
1123 break;
1124 }
1125}
1126
Tobin Davisc9b443d2006-11-14 12:13:39 +01001127static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001128 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1129 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001130 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1131 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001132 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1133 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1134 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1135 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001136 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1137 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001138 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1139 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1140 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1141 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001142
1143 {}
1144};
1145
1146static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1147 {
1148 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1149 .name = "Capture Source",
1150 .info = conexant_mux_enum_info,
1151 .get = conexant_mux_enum_get,
1152 .put = conexant_mux_enum_put
1153 },
1154 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1155 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1156 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1157 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1158 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1159 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001160 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001161 {
1162 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1163 .name = "Master Playback Switch",
1164 .info = cxt_eapd_info,
1165 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001166 .put = cxt5047_hp_master_sw_put,
1167 .private_value = 0x13,
1168 },
1169
1170 {}
1171};
1172
1173static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1174 {
1175 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1176 .name = "Capture Source",
1177 .info = conexant_mux_enum_info,
1178 .get = conexant_mux_enum_get,
1179 .put = conexant_mux_enum_put
1180 },
1181 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1182 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1183 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1184 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1185 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1186 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1187 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1188 {
1189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1190 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001191 .info = cxt_eapd_info,
1192 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193 .put = cxt5047_hp_master_sw_put,
1194 .private_value = 0x13,
1195 },
1196 { } /* end */
1197};
1198
1199static struct hda_verb cxt5047_init_verbs[] = {
1200 /* Line in, Mic, Built-in Mic */
1201 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1202 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1203 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001204 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001205 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1206 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001207 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1208 /* Record selector: Mic */
1209 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1210 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1211 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1212 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001213 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1214 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1215 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1216 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217 /* SPDIF route: PCM */
1218 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001219 /* Enable unsolicited events */
1220 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1221 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001222 { } /* end */
1223};
1224
1225/* configuration for Toshiba Laptops */
1226static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1227 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1228 /* pin sensing on HP and Mic jacks */
1229 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1230 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001231 /* Speaker routing */
1232 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233 {}
1234};
1235
1236/* configuration for HP Laptops */
1237static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001238 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001239 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001240 /* 0x13 is actually shared by both HP and speaker;
1241 * setting the connection to 0 (=0x19) makes the master volume control
1242 * working mysteriouslly...
1243 */
1244 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001245 /* Record selector: Ext Mic */
1246 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001247 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1248 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1249 /* Speaker routing */
1250 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001251 {}
1252};
1253
1254/* Test configuration for debugging, modelled after the ALC260 test
1255 * configuration.
1256 */
1257#ifdef CONFIG_SND_DEBUG
1258static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001259 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001260 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001261 { "LINE1 pin", 0x0 },
1262 { "MIC1 pin", 0x1 },
1263 { "MIC2 pin", 0x2 },
1264 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001265 },
1266};
1267
1268static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1269
1270 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001271 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1272 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1273 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1274 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001275 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1276 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1277 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1278 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001279 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1280 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1281 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1282 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283
1284 /* Modes for retasking pin widgets */
1285 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1286 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1287
Tobin Davis82f30042007-02-13 12:45:44 +01001288 /* EAPD Switch Control */
1289 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1290
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001292 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1293 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1294 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1295 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1296 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1297 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1298 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1299 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300
Tobin Davis82f30042007-02-13 12:45:44 +01001301 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1302 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1303 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1304 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1305 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1306 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1307 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1308 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001309 {
1310 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1311 .name = "Input Source",
1312 .info = conexant_mux_enum_info,
1313 .get = conexant_mux_enum_get,
1314 .put = conexant_mux_enum_put,
1315 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001316 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1317 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1318 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1319 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1320 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1321 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1322 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1323 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1324 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1325 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1326
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327 { } /* end */
1328};
1329
1330static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001331 /* Enable retasking pins as output, initially without power amp */
1332 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1333 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1334 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1335
1336 /* Disable digital (SPDIF) pins initially, but users can enable
1337 * them via a mixer switch. In the case of SPDIF-out, this initverb
1338 * payload also sets the generation to 0, output to be in "consumer"
1339 * PCM format, copyright asserted, no pre-emphasis and no validity
1340 * control.
1341 */
1342 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1343
1344 /* Ensure mic1, mic2, line1 pin widgets take input from the
1345 * OUT1 sum bus when acting as an output.
1346 */
1347 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1348 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1349
1350 /* Start with output sum widgets muted and their output gains at min */
1351 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1352 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1353
1354 /* Unmute retasking pin widget output buffers since the default
1355 * state appears to be output. As the pin mode is changed by the
1356 * user the pin mode control will take care of enabling the pin's
1357 * input/output buffers as needed.
1358 */
1359 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1360 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1361 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1362
1363 /* Mute capture amp left and right */
1364 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1365
1366 /* Set ADC connection select to match default mixer setting (mic1
1367 * pin)
1368 */
1369 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1370
1371 /* Mute all inputs to mixer widget (even unconnected ones) */
1372 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1373 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1374 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1375 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1376 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1377 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1378 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1379 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1380
1381 { }
1382};
1383#endif
1384
1385
1386/* initialize jack-sensing, too */
1387static int cxt5047_hp_init(struct hda_codec *codec)
1388{
1389 conexant_init(codec);
1390 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001391 return 0;
1392}
1393
1394
1395enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001396 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1397 CXT5047_LAPTOP_HP, /* Some HP laptops */
1398 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001399#ifdef CONFIG_SND_DEBUG
1400 CXT5047_TEST,
1401#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001402 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001403};
1404
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001405static const char *cxt5047_models[CXT5047_MODELS] = {
1406 [CXT5047_LAPTOP] = "laptop",
1407 [CXT5047_LAPTOP_HP] = "laptop-hp",
1408 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001409#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001410 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001411#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001412};
1413
1414static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1415 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001416 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001417 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001418 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001419 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001420 {}
1421};
1422
1423static int patch_cxt5047(struct hda_codec *codec)
1424{
1425 struct conexant_spec *spec;
1426 int board_config;
1427
1428 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1429 if (!spec)
1430 return -ENOMEM;
1431 mutex_init(&spec->amp_mutex);
1432 codec->spec = spec;
1433
1434 spec->multiout.max_channels = 2;
1435 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1436 spec->multiout.dac_nids = cxt5047_dac_nids;
1437 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1438 spec->num_adc_nids = 1;
1439 spec->adc_nids = cxt5047_adc_nids;
1440 spec->capsrc_nids = cxt5047_capsrc_nids;
1441 spec->input_mux = &cxt5047_capture_source;
1442 spec->num_mixers = 1;
1443 spec->mixers[0] = cxt5047_mixers;
1444 spec->num_init_verbs = 1;
1445 spec->init_verbs[0] = cxt5047_init_verbs;
1446 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001447 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1448 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001449
1450 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001451
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001452 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1453 cxt5047_models,
1454 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001455 switch (board_config) {
1456 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001457 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001458 break;
1459 case CXT5047_LAPTOP_HP:
1460 spec->input_mux = &cxt5047_hp_capture_source;
1461 spec->num_init_verbs = 2;
1462 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1463 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001464 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001465 codec->patch_ops.init = cxt5047_hp_init;
1466 break;
1467 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001468 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001469 spec->num_init_verbs = 2;
1470 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001471 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001472 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001473 break;
1474#ifdef CONFIG_SND_DEBUG
1475 case CXT5047_TEST:
1476 spec->input_mux = &cxt5047_test_capture_source;
1477 spec->mixers[0] = cxt5047_test_mixer;
1478 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001479 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001480#endif
1481 }
1482 return 0;
1483}
1484
Takashi Iwai461e2c72008-01-25 11:35:17 +01001485/* Conexant 5051 specific */
1486static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1487static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1488#define CXT5051_SPDIF_OUT 0x1C
1489#define CXT5051_PORTB_EVENT 0x38
1490#define CXT5051_PORTC_EVENT 0x39
1491
1492static struct hda_channel_mode cxt5051_modes[1] = {
1493 { 2, NULL },
1494};
1495
1496static void cxt5051_update_speaker(struct hda_codec *codec)
1497{
1498 struct conexant_spec *spec = codec->spec;
1499 unsigned int pinctl;
1500 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1501 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1502 pinctl);
1503}
1504
1505/* turn on/off EAPD (+ mute HP) as a master switch */
1506static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1507 struct snd_ctl_elem_value *ucontrol)
1508{
1509 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1510
1511 if (!cxt_eapd_put(kcontrol, ucontrol))
1512 return 0;
1513 cxt5051_update_speaker(codec);
1514 return 1;
1515}
1516
1517/* toggle input of built-in and mic jack appropriately */
1518static void cxt5051_portb_automic(struct hda_codec *codec)
1519{
1520 unsigned int present;
1521
1522 present = snd_hda_codec_read(codec, 0x17, 0,
1523 AC_VERB_GET_PIN_SENSE, 0) &
1524 AC_PINSENSE_PRESENCE;
1525 snd_hda_codec_write(codec, 0x14, 0,
1526 AC_VERB_SET_CONNECT_SEL,
1527 present ? 0x01 : 0x00);
1528}
1529
1530/* switch the current ADC according to the jack state */
1531static void cxt5051_portc_automic(struct hda_codec *codec)
1532{
1533 struct conexant_spec *spec = codec->spec;
1534 unsigned int present;
1535 hda_nid_t new_adc;
1536
1537 present = snd_hda_codec_read(codec, 0x18, 0,
1538 AC_VERB_GET_PIN_SENSE, 0) &
1539 AC_PINSENSE_PRESENCE;
1540 if (present)
1541 spec->cur_adc_idx = 1;
1542 else
1543 spec->cur_adc_idx = 0;
1544 new_adc = spec->adc_nids[spec->cur_adc_idx];
1545 if (spec->cur_adc && spec->cur_adc != new_adc) {
1546 /* stream is running, let's swap the current ADC */
1547 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
1548 spec->cur_adc = new_adc;
1549 snd_hda_codec_setup_stream(codec, new_adc,
1550 spec->cur_adc_stream_tag, 0,
1551 spec->cur_adc_format);
1552 }
1553}
1554
1555/* mute internal speaker if HP is plugged */
1556static void cxt5051_hp_automute(struct hda_codec *codec)
1557{
1558 struct conexant_spec *spec = codec->spec;
1559
1560 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1561 AC_VERB_GET_PIN_SENSE, 0) &
1562 AC_PINSENSE_PRESENCE;
1563 cxt5051_update_speaker(codec);
1564}
1565
1566/* unsolicited event for HP jack sensing */
1567static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1568 unsigned int res)
1569{
1570 switch (res >> 26) {
1571 case CONEXANT_HP_EVENT:
1572 cxt5051_hp_automute(codec);
1573 break;
1574 case CXT5051_PORTB_EVENT:
1575 cxt5051_portb_automic(codec);
1576 break;
1577 case CXT5051_PORTC_EVENT:
1578 cxt5051_portc_automic(codec);
1579 break;
1580 }
1581}
1582
1583static struct snd_kcontrol_new cxt5051_mixers[] = {
1584 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1585 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1586 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1587 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1588 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1589 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1590 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1591 {
1592 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1593 .name = "Master Playback Switch",
1594 .info = cxt_eapd_info,
1595 .get = cxt_eapd_get,
1596 .put = cxt5051_hp_master_sw_put,
1597 .private_value = 0x1a,
1598 },
1599
1600 {}
1601};
1602
1603static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1604 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1605 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1606 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1607 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1608 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1609 {
1610 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1611 .name = "Master Playback Switch",
1612 .info = cxt_eapd_info,
1613 .get = cxt_eapd_get,
1614 .put = cxt5051_hp_master_sw_put,
1615 .private_value = 0x1a,
1616 },
1617
1618 {}
1619};
1620
1621static struct hda_verb cxt5051_init_verbs[] = {
1622 /* Line in, Mic */
1623 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1624 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1625 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1626 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1627 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1628 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1629 /* SPK */
1630 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1631 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1632 /* HP, Amp */
1633 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1634 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1635 /* DAC1 */
1636 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1637 /* Record selector: Int mic */
1638 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1639 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1640 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1641 /* SPDIF route: PCM */
1642 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1643 /* EAPD */
1644 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1645 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1646 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1647 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1648 { } /* end */
1649};
1650
1651/* initialize jack-sensing, too */
1652static int cxt5051_init(struct hda_codec *codec)
1653{
1654 conexant_init(codec);
1655 if (codec->patch_ops.unsol_event) {
1656 cxt5051_hp_automute(codec);
1657 cxt5051_portb_automic(codec);
1658 cxt5051_portc_automic(codec);
1659 }
1660 return 0;
1661}
1662
1663
1664enum {
1665 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1666 CXT5051_HP, /* no docking */
1667 CXT5051_MODELS
1668};
1669
1670static const char *cxt5051_models[CXT5051_MODELS] = {
1671 [CXT5051_LAPTOP] = "laptop",
1672 [CXT5051_HP] = "hp",
1673};
1674
1675static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1676 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1677 CXT5051_LAPTOP),
1678 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1679 {}
1680};
1681
1682static int patch_cxt5051(struct hda_codec *codec)
1683{
1684 struct conexant_spec *spec;
1685 int board_config;
1686
1687 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1688 if (!spec)
1689 return -ENOMEM;
1690 mutex_init(&spec->amp_mutex);
1691 codec->spec = spec;
1692
1693 codec->patch_ops = conexant_patch_ops;
1694 codec->patch_ops.init = cxt5051_init;
1695
1696 spec->multiout.max_channels = 2;
1697 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1698 spec->multiout.dac_nids = cxt5051_dac_nids;
1699 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1700 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1701 spec->adc_nids = cxt5051_adc_nids;
1702 spec->num_mixers = 1;
1703 spec->mixers[0] = cxt5051_mixers;
1704 spec->num_init_verbs = 1;
1705 spec->init_verbs[0] = cxt5051_init_verbs;
1706 spec->spdif_route = 0;
1707 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1708 spec->channel_mode = cxt5051_modes;
1709 spec->cur_adc = 0;
1710 spec->cur_adc_idx = 0;
1711
1712 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1713 cxt5051_models,
1714 cxt5051_cfg_tbl);
1715 switch (board_config) {
1716 case CXT5051_HP:
1717 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1718 spec->mixers[0] = cxt5051_hp_mixers;
1719 break;
1720 default:
1721 case CXT5051_LAPTOP:
1722 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1723 break;
1724 }
1725
1726 return 0;
1727}
1728
1729
1730/*
1731 */
1732
Tobin Davisc9b443d2006-11-14 12:13:39 +01001733struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001734 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1735 .patch = patch_cxt5045 },
1736 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1737 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001738 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1739 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001740 {} /* terminator */
1741};