blob: e4fa9a35848f317dc6993b014354b7e2ec427c0d [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"
Harvey Harrison3c9a3202008-02-29 11:59:26 +010030#include "hda_patch.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010031
32#define CXT_PIN_DIR_IN 0x00
33#define CXT_PIN_DIR_OUT 0x01
34#define CXT_PIN_DIR_INOUT 0x02
35#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
36#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
37
38#define CONEXANT_HP_EVENT 0x37
39#define CONEXANT_MIC_EVENT 0x38
40
41
42
43struct conexant_spec {
44
45 struct snd_kcontrol_new *mixers[5];
46 int num_mixers;
47
48 const struct hda_verb *init_verbs[5]; /* initialization verbs
49 * don't forget NULL
50 * termination!
51 */
52 unsigned int num_init_verbs;
53
54 /* playback */
55 struct hda_multi_out multiout; /* playback set-up
56 * max_channels, dacs must be set
57 * dig_out_nid and hp_nid are optional
58 */
59 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010060 unsigned int hp_present;
Tobin Davisc9b443d2006-11-14 12:13:39 +010061 unsigned int need_dac_fix;
62
63 /* capture */
64 unsigned int num_adc_nids;
65 hda_nid_t *adc_nids;
66 hda_nid_t dig_in_nid; /* digital-in NID; optional */
67
Takashi Iwai461e2c72008-01-25 11:35:17 +010068 unsigned int cur_adc_idx;
69 hda_nid_t cur_adc;
70 unsigned int cur_adc_stream_tag;
71 unsigned int cur_adc_format;
72
Tobin Davisc9b443d2006-11-14 12:13:39 +010073 /* capture source */
74 const struct hda_input_mux *input_mux;
75 hda_nid_t *capsrc_nids;
76 unsigned int cur_mux[3];
77
78 /* channel model */
79 const struct hda_channel_mode *channel_mode;
80 int num_channel_mode;
81
82 /* PCM information */
83 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
84
85 struct mutex amp_mutex; /* PCM volume/mute control mutex */
86 unsigned int spdif_route;
87
88 /* dynamic controls, init_verbs and input_mux */
89 struct auto_pin_cfg autocfg;
90 unsigned int num_kctl_alloc, num_kctl_used;
91 struct snd_kcontrol_new *kctl_alloc;
92 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020093 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +010094
95};
96
97static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
98 struct hda_codec *codec,
99 struct snd_pcm_substream *substream)
100{
101 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100102 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
103 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100104}
105
106static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
107 struct hda_codec *codec,
108 unsigned int stream_tag,
109 unsigned int format,
110 struct snd_pcm_substream *substream)
111{
112 struct conexant_spec *spec = codec->spec;
113 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
114 stream_tag,
115 format, substream);
116}
117
118static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
119 struct hda_codec *codec,
120 struct snd_pcm_substream *substream)
121{
122 struct conexant_spec *spec = codec->spec;
123 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
124}
125
126/*
127 * Digital out
128 */
129static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
130 struct hda_codec *codec,
131 struct snd_pcm_substream *substream)
132{
133 struct conexant_spec *spec = codec->spec;
134 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
135}
136
137static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
138 struct hda_codec *codec,
139 struct snd_pcm_substream *substream)
140{
141 struct conexant_spec *spec = codec->spec;
142 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
143}
144
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200145static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
146 struct hda_codec *codec,
147 unsigned int stream_tag,
148 unsigned int format,
149 struct snd_pcm_substream *substream)
150{
151 struct conexant_spec *spec = codec->spec;
152 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
153 stream_tag,
154 format, substream);
155}
156
Tobin Davisc9b443d2006-11-14 12:13:39 +0100157/*
158 * Analog capture
159 */
160static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
161 struct hda_codec *codec,
162 unsigned int stream_tag,
163 unsigned int format,
164 struct snd_pcm_substream *substream)
165{
166 struct conexant_spec *spec = codec->spec;
167 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
168 stream_tag, 0, format);
169 return 0;
170}
171
172static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec,
174 struct snd_pcm_substream *substream)
175{
176 struct conexant_spec *spec = codec->spec;
177 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
178 0, 0, 0);
179 return 0;
180}
181
182
183
184static struct hda_pcm_stream conexant_pcm_analog_playback = {
185 .substreams = 1,
186 .channels_min = 2,
187 .channels_max = 2,
188 .nid = 0, /* fill later */
189 .ops = {
190 .open = conexant_playback_pcm_open,
191 .prepare = conexant_playback_pcm_prepare,
192 .cleanup = conexant_playback_pcm_cleanup
193 },
194};
195
196static struct hda_pcm_stream conexant_pcm_analog_capture = {
197 .substreams = 1,
198 .channels_min = 2,
199 .channels_max = 2,
200 .nid = 0, /* fill later */
201 .ops = {
202 .prepare = conexant_capture_pcm_prepare,
203 .cleanup = conexant_capture_pcm_cleanup
204 },
205};
206
207
208static struct hda_pcm_stream conexant_pcm_digital_playback = {
209 .substreams = 1,
210 .channels_min = 2,
211 .channels_max = 2,
212 .nid = 0, /* fill later */
213 .ops = {
214 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200215 .close = conexant_dig_playback_pcm_close,
216 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100217 },
218};
219
220static struct hda_pcm_stream conexant_pcm_digital_capture = {
221 .substreams = 1,
222 .channels_min = 2,
223 .channels_max = 2,
224 /* NID is set in alc_build_pcms */
225};
226
Takashi Iwai461e2c72008-01-25 11:35:17 +0100227static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
228 struct hda_codec *codec,
229 unsigned int stream_tag,
230 unsigned int format,
231 struct snd_pcm_substream *substream)
232{
233 struct conexant_spec *spec = codec->spec;
234 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
235 spec->cur_adc_stream_tag = stream_tag;
236 spec->cur_adc_format = format;
237 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
238 return 0;
239}
240
241static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
242 struct hda_codec *codec,
243 struct snd_pcm_substream *substream)
244{
245 struct conexant_spec *spec = codec->spec;
246 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
247 spec->cur_adc = 0;
248 return 0;
249}
250
251static struct hda_pcm_stream cx5051_pcm_analog_capture = {
252 .substreams = 1,
253 .channels_min = 2,
254 .channels_max = 2,
255 .nid = 0, /* fill later */
256 .ops = {
257 .prepare = cx5051_capture_pcm_prepare,
258 .cleanup = cx5051_capture_pcm_cleanup
259 },
260};
261
Tobin Davisc9b443d2006-11-14 12:13:39 +0100262static int conexant_build_pcms(struct hda_codec *codec)
263{
264 struct conexant_spec *spec = codec->spec;
265 struct hda_pcm *info = spec->pcm_rec;
266
267 codec->num_pcms = 1;
268 codec->pcm_info = info;
269
270 info->name = "CONEXANT Analog";
271 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
272 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
273 spec->multiout.max_channels;
274 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
275 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100276 if (codec->vendor_id == 0x14f15051)
277 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
278 cx5051_pcm_analog_capture;
279 else
280 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
281 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100282 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
283 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
284
285 if (spec->multiout.dig_out_nid) {
286 info++;
287 codec->num_pcms++;
288 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100289 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100290 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
291 conexant_pcm_digital_playback;
292 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
293 spec->multiout.dig_out_nid;
294 if (spec->dig_in_nid) {
295 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
296 conexant_pcm_digital_capture;
297 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
298 spec->dig_in_nid;
299 }
300 }
301
302 return 0;
303}
304
305static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
306 struct snd_ctl_elem_info *uinfo)
307{
308 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
309 struct conexant_spec *spec = codec->spec;
310
311 return snd_hda_input_mux_info(spec->input_mux, uinfo);
312}
313
314static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_value *ucontrol)
316{
317 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
318 struct conexant_spec *spec = codec->spec;
319 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
320
321 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
322 return 0;
323}
324
325static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
327{
328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 struct conexant_spec *spec = codec->spec;
330 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
331
332 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
333 spec->capsrc_nids[adc_idx],
334 &spec->cur_mux[adc_idx]);
335}
336
337static int conexant_init(struct hda_codec *codec)
338{
339 struct conexant_spec *spec = codec->spec;
340 int i;
341
342 for (i = 0; i < spec->num_init_verbs; i++)
343 snd_hda_sequence_write(codec, spec->init_verbs[i]);
344 return 0;
345}
346
347static void conexant_free(struct hda_codec *codec)
348{
349 struct conexant_spec *spec = codec->spec;
350 unsigned int i;
351
352 if (spec->kctl_alloc) {
353 for (i = 0; i < spec->num_kctl_used; i++)
354 kfree(spec->kctl_alloc[i].name);
355 kfree(spec->kctl_alloc);
356 }
357
358 kfree(codec->spec);
359}
360
Tobin Davisc9b443d2006-11-14 12:13:39 +0100361static int conexant_build_controls(struct hda_codec *codec)
362{
363 struct conexant_spec *spec = codec->spec;
364 unsigned int i;
365 int err;
366
367 for (i = 0; i < spec->num_mixers; i++) {
368 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
369 if (err < 0)
370 return err;
371 }
372 if (spec->multiout.dig_out_nid) {
373 err = snd_hda_create_spdif_out_ctls(codec,
374 spec->multiout.dig_out_nid);
375 if (err < 0)
376 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100377 err = snd_hda_create_spdif_share_sw(codec,
378 &spec->multiout);
379 if (err < 0)
380 return err;
381 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100382 }
383 if (spec->dig_in_nid) {
384 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
385 if (err < 0)
386 return err;
387 }
388 return 0;
389}
390
391static struct hda_codec_ops conexant_patch_ops = {
392 .build_controls = conexant_build_controls,
393 .build_pcms = conexant_build_pcms,
394 .init = conexant_init,
395 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100396};
397
398/*
399 * EAPD control
400 * the private value = nid | (invert << 8)
401 */
402
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200403#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100404
Tobin Davis82f30042007-02-13 12:45:44 +0100405static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100406 struct snd_ctl_elem_value *ucontrol)
407{
408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409 struct conexant_spec *spec = codec->spec;
410 int invert = (kcontrol->private_value >> 8) & 1;
411 if (invert)
412 ucontrol->value.integer.value[0] = !spec->cur_eapd;
413 else
414 ucontrol->value.integer.value[0] = spec->cur_eapd;
415 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100416
Tobin Davisc9b443d2006-11-14 12:13:39 +0100417}
418
Tobin Davis82f30042007-02-13 12:45:44 +0100419static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100420 struct snd_ctl_elem_value *ucontrol)
421{
422 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
423 struct conexant_spec *spec = codec->spec;
424 int invert = (kcontrol->private_value >> 8) & 1;
425 hda_nid_t nid = kcontrol->private_value & 0xff;
426 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100427
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100428 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100429 if (invert)
430 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200431 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100432 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100433
Tobin Davisc9b443d2006-11-14 12:13:39 +0100434 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200435 snd_hda_codec_write_cache(codec, nid,
436 0, AC_VERB_SET_EAPD_BTLENABLE,
437 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100438 return 1;
439}
440
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100441/* controls for test mode */
442#ifdef CONFIG_SND_DEBUG
443
Tobin Davis82f30042007-02-13 12:45:44 +0100444#define CXT_EAPD_SWITCH(xname, nid, mask) \
445 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
446 .info = cxt_eapd_info, \
447 .get = cxt_eapd_get, \
448 .put = cxt_eapd_put, \
449 .private_value = nid | (mask<<16) }
450
451
452
Tobin Davisc9b443d2006-11-14 12:13:39 +0100453static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
454 struct snd_ctl_elem_info *uinfo)
455{
456 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
457 struct conexant_spec *spec = codec->spec;
458 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
459 spec->num_channel_mode);
460}
461
462static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
463 struct snd_ctl_elem_value *ucontrol)
464{
465 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
466 struct conexant_spec *spec = codec->spec;
467 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
468 spec->num_channel_mode,
469 spec->multiout.max_channels);
470}
471
472static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
473 struct snd_ctl_elem_value *ucontrol)
474{
475 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
476 struct conexant_spec *spec = codec->spec;
477 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
478 spec->num_channel_mode,
479 &spec->multiout.max_channels);
480 if (err >= 0 && spec->need_dac_fix)
481 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
482 return err;
483}
484
485#define CXT_PIN_MODE(xname, nid, dir) \
486 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
487 .info = conexant_ch_mode_info, \
488 .get = conexant_ch_mode_get, \
489 .put = conexant_ch_mode_put, \
490 .private_value = nid | (dir<<16) }
491
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100492#endif /* CONFIG_SND_DEBUG */
493
Tobin Davisc9b443d2006-11-14 12:13:39 +0100494/* Conexant 5045 specific */
495
496static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
497static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
498static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100499#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100500
Tobin Davis5cd57522006-11-20 17:42:09 +0100501static struct hda_channel_mode cxt5045_modes[1] = {
502 { 2, NULL },
503};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100504
505static struct hda_input_mux cxt5045_capture_source = {
506 .num_items = 2,
507 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100508 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100509 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100510 }
511};
512
Jiang Zhe5218c892008-01-17 11:18:41 +0100513static struct hda_input_mux cxt5045_capture_source_benq = {
514 .num_items = 3,
515 .items = {
516 { "IntMic", 0x1 },
517 { "ExtMic", 0x2 },
518 { "LineIn", 0x3 },
519 }
520};
521
Tobin Davisc9b443d2006-11-14 12:13:39 +0100522/* turn on/off EAPD (+ mute HP) as a master switch */
523static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
524 struct snd_ctl_elem_value *ucontrol)
525{
526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
527 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100528 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100529
Tobin Davis82f30042007-02-13 12:45:44 +0100530 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100531 return 0;
532
Tobin Davis82f30042007-02-13 12:45:44 +0100533 /* toggle internal speakers mute depending of presence of
534 * the headphone jack
535 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200536 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
537 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
538 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100539
Takashi Iwai47fd8302007-08-10 17:11:07 +0200540 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
541 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
542 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100543 return 1;
544}
545
546/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200547static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
548 .ops = &snd_hda_bind_vol,
549 .values = {
550 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
551 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
552 0
553 },
554};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100555
Tobin Davis7f296732007-03-12 11:39:01 +0100556/* toggle input of built-in and mic jack appropriately */
557static void cxt5045_hp_automic(struct hda_codec *codec)
558{
559 static struct hda_verb mic_jack_on[] = {
560 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
561 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
562 {}
563 };
564 static struct hda_verb mic_jack_off[] = {
565 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
566 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
567 {}
568 };
569 unsigned int present;
570
571 present = snd_hda_codec_read(codec, 0x12, 0,
572 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
573 if (present)
574 snd_hda_sequence_write(codec, mic_jack_on);
575 else
576 snd_hda_sequence_write(codec, mic_jack_off);
577}
578
Tobin Davisc9b443d2006-11-14 12:13:39 +0100579
580/* mute internal speaker if HP is plugged */
581static void cxt5045_hp_automute(struct hda_codec *codec)
582{
Tobin Davis82f30042007-02-13 12:45:44 +0100583 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100584 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100585
Tobin Davis82f30042007-02-13 12:45:44 +0100586 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100587 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100588
Takashi Iwai47fd8302007-08-10 17:11:07 +0200589 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
590 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
591 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100592}
593
594/* unsolicited event for HP jack sensing */
595static void cxt5045_hp_unsol_event(struct hda_codec *codec,
596 unsigned int res)
597{
598 res >>= 26;
599 switch (res) {
600 case CONEXANT_HP_EVENT:
601 cxt5045_hp_automute(codec);
602 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100603 case CONEXANT_MIC_EVENT:
604 cxt5045_hp_automic(codec);
605 break;
606
Tobin Davisc9b443d2006-11-14 12:13:39 +0100607 }
608}
609
610static struct snd_kcontrol_new cxt5045_mixers[] = {
611 {
612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
613 .name = "Capture Source",
614 .info = conexant_mux_enum_info,
615 .get = conexant_mux_enum_get,
616 .put = conexant_mux_enum_put
617 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200618 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
619 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
620 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
621 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
622 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
623 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
624 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
625 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
626 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
627 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200628 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629 {
630 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
631 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100632 .info = cxt_eapd_info,
633 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100634 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100635 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100636 },
637
638 {}
639};
640
Jiang Zhe5218c892008-01-17 11:18:41 +0100641static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
642 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
643 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
644 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
645 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
646
647 {}
648};
649
Tobin Davisc9b443d2006-11-14 12:13:39 +0100650static struct hda_verb cxt5045_init_verbs[] = {
651 /* Line in, Mic */
652 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Tobin Davis7f296732007-03-12 11:39:01 +0100653 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100654 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200655 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
656 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
657 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
658 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
659 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
660 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
661 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
662 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
663 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100664 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100665 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100666 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100667 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
668 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100669 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100670 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100671 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100672 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100673 { } /* end */
674};
675
Jiang Zhe5218c892008-01-17 11:18:41 +0100676static struct hda_verb cxt5045_benq_init_verbs[] = {
677 /* Int Mic, Mic */
678 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
679 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
680 /* Line In,HP, Amp */
681 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
682 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
683 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
684 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
685 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
686 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
687 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
688 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
689 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
690 /* Record selector: Int mic */
691 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
692 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
693 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
694 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100695 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100696 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
697 /* EAPD */
698 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
699 { } /* end */
700};
Tobin Davis7f296732007-03-12 11:39:01 +0100701
702static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
703 /* pin sensing on HP jack */
704 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200705 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100706};
707
708static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
709 /* pin sensing on HP jack */
710 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200711 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100712};
713
Tobin Davisc9b443d2006-11-14 12:13:39 +0100714#ifdef CONFIG_SND_DEBUG
715/* Test configuration for debugging, modelled after the ALC260 test
716 * configuration.
717 */
718static struct hda_input_mux cxt5045_test_capture_source = {
719 .num_items = 5,
720 .items = {
721 { "MIXER", 0x0 },
722 { "MIC1 pin", 0x1 },
723 { "LINE1 pin", 0x2 },
724 { "HP-OUT pin", 0x3 },
725 { "CD pin", 0x4 },
726 },
727};
728
729static struct snd_kcontrol_new cxt5045_test_mixer[] = {
730
731 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100732 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
733 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100734 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
735 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
736 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
737 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100738
739 /* Modes for retasking pin widgets */
740 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
741 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
742
Tobin Davis82f30042007-02-13 12:45:44 +0100743 /* EAPD Switch Control */
744 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
745
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100747
Tobin Davis7f296732007-03-12 11:39:01 +0100748 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
749 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
750 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
751 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
752 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
753 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
754 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
755 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
756 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
757 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100758 {
759 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
760 .name = "Input Source",
761 .info = conexant_mux_enum_info,
762 .get = conexant_mux_enum_get,
763 .put = conexant_mux_enum_put,
764 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200765 /* Audio input controls */
766 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
767 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
768 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
769 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
770 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
771 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
772 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
773 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
774 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
775 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100776 { } /* end */
777};
778
779static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100780 /* Set connections */
781 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
782 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
783 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784 /* Enable retasking pins as output, initially without power amp */
785 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100786 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100787
788 /* Disable digital (SPDIF) pins initially, but users can enable
789 * them via a mixer switch. In the case of SPDIF-out, this initverb
790 * payload also sets the generation to 0, output to be in "consumer"
791 * PCM format, copyright asserted, no pre-emphasis and no validity
792 * control.
793 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100794 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
795 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796
797 /* Start with output sum widgets muted and their output gains at min */
798 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
799 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
800
801 /* Unmute retasking pin widget output buffers since the default
802 * state appears to be output. As the pin mode is changed by the
803 * user the pin mode control will take care of enabling the pin's
804 * input/output buffers as needed.
805 */
806 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
807 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
808
809 /* Mute capture amp left and right */
810 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
811
812 /* Set ADC connection select to match default mixer setting (mic1
813 * pin)
814 */
815 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100816 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100817
818 /* Mute all inputs to mixer widget (even unconnected ones) */
819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
822 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
823 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
824
825 { }
826};
827#endif
828
829
830/* initialize jack-sensing, too */
831static int cxt5045_init(struct hda_codec *codec)
832{
833 conexant_init(codec);
834 cxt5045_hp_automute(codec);
835 return 0;
836}
837
838
839enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100840 CXT5045_LAPTOP_HPSENSE,
841 CXT5045_LAPTOP_MICSENSE,
842 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100843 CXT5045_BENQ,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100844#ifdef CONFIG_SND_DEBUG
845 CXT5045_TEST,
846#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100847 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100848};
849
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100850static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100851 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
852 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
853 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
854 [CXT5045_BENQ] = "benq",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100855#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100856 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100858};
859
860static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100861 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
862 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
863 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
864 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
865 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
866 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai0f6a5152008-01-29 13:26:04 +0100867 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +0100868 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
869 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +0100870 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +0100871 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
872 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
873 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
874 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
875 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
876 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
877 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
878 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
879 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100880 {}
881};
882
883static int patch_cxt5045(struct hda_codec *codec)
884{
885 struct conexant_spec *spec;
886 int board_config;
887
888 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
889 if (!spec)
890 return -ENOMEM;
891 mutex_init(&spec->amp_mutex);
892 codec->spec = spec;
893
894 spec->multiout.max_channels = 2;
895 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
896 spec->multiout.dac_nids = cxt5045_dac_nids;
897 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
898 spec->num_adc_nids = 1;
899 spec->adc_nids = cxt5045_adc_nids;
900 spec->capsrc_nids = cxt5045_capsrc_nids;
901 spec->input_mux = &cxt5045_capture_source;
902 spec->num_mixers = 1;
903 spec->mixers[0] = cxt5045_mixers;
904 spec->num_init_verbs = 1;
905 spec->init_verbs[0] = cxt5045_init_verbs;
906 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100907 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
908 spec->channel_mode = cxt5045_modes,
909
Tobin Davisc9b443d2006-11-14 12:13:39 +0100910
911 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100912
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100913 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
914 cxt5045_models,
915 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100916 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +0100917 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100918 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100919 spec->input_mux = &cxt5045_capture_source;
920 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100921 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
922 spec->mixers[0] = cxt5045_mixers;
923 codec->patch_ops.init = cxt5045_init;
924 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100925 case CXT5045_LAPTOP_MICSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100926 spec->input_mux = &cxt5045_capture_source;
927 spec->num_init_verbs = 2;
928 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929 spec->mixers[0] = cxt5045_mixers;
930 codec->patch_ops.init = cxt5045_init;
931 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100932 default:
933 case CXT5045_LAPTOP_HPMICSENSE:
934 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
935 spec->input_mux = &cxt5045_capture_source;
936 spec->num_init_verbs = 3;
937 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
938 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
939 spec->mixers[0] = cxt5045_mixers;
940 codec->patch_ops.init = cxt5045_init;
941 break;
Jiang Zhe5218c892008-01-17 11:18:41 +0100942 case CXT5045_BENQ:
943 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
944 spec->input_mux = &cxt5045_capture_source_benq;
945 spec->num_init_verbs = 1;
946 spec->init_verbs[0] = cxt5045_benq_init_verbs;
947 spec->mixers[0] = cxt5045_mixers;
948 spec->mixers[1] = cxt5045_benq_mixers;
949 spec->num_mixers = 2;
950 codec->patch_ops.init = cxt5045_init;
951 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952#ifdef CONFIG_SND_DEBUG
953 case CXT5045_TEST:
954 spec->input_mux = &cxt5045_test_capture_source;
955 spec->mixers[0] = cxt5045_test_mixer;
956 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +0100957 break;
958
Tobin Davisc9b443d2006-11-14 12:13:39 +0100959#endif
960 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +0100961
962 /*
963 * Fix max PCM level to 0 dB
964 * (originall it has 0x2b steps with 0dB offset 0x14)
965 */
966 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
967 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
968 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
969 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
970 (1 << AC_AMPCAP_MUTE_SHIFT));
971
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972 return 0;
973}
974
975
976/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100977#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100978
Tobin Davis82f30042007-02-13 12:45:44 +0100979static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100980static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
981static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100982
Tobin Davis5cd57522006-11-20 17:42:09 +0100983static struct hda_channel_mode cxt5047_modes[1] = {
984 { 2, NULL },
985};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100986
987static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +0100988 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100989 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +0100990 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100991 }
992};
993
994static struct hda_input_mux cxt5047_hp_capture_source = {
995 .num_items = 1,
996 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100997 { "ExtMic", 0x2 },
998 }
999};
1000
1001static struct hda_input_mux cxt5047_toshiba_capture_source = {
1002 .num_items = 2,
1003 .items = {
1004 { "ExtMic", 0x2 },
1005 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001006 }
1007};
1008
1009/* turn on/off EAPD (+ mute HP) as a master switch */
1010static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1011 struct snd_ctl_elem_value *ucontrol)
1012{
1013 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1014 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001015 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001016
Tobin Davis82f30042007-02-13 12:45:44 +01001017 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001018 return 0;
1019
Tobin Davis82f30042007-02-13 12:45:44 +01001020 /* toggle internal speakers mute depending of presence of
1021 * the headphone jack
1022 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001023 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1024 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1025 HDA_AMP_MUTE, bits);
1026 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1027 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1028 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001029 return 1;
1030}
1031
Tobin Davis82f30042007-02-13 12:45:44 +01001032/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001033static struct hda_bind_ctls cxt5047_bind_master_vol = {
1034 .ops = &snd_hda_bind_vol,
1035 .values = {
1036 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1037 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1038 0
1039 },
1040};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001041
1042/* mute internal speaker if HP is plugged */
1043static void cxt5047_hp_automute(struct hda_codec *codec)
1044{
Tobin Davis82f30042007-02-13 12:45:44 +01001045 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001046 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001047
Tobin Davis82f30042007-02-13 12:45:44 +01001048 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001049 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001050
Takashi Iwai47fd8302007-08-10 17:11:07 +02001051 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1052 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1053 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001054 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001055 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1056 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001057}
1058
Tobin Davisfb3409e2007-05-17 09:40:47 +02001059/* mute internal speaker if HP is plugged */
1060static void cxt5047_hp2_automute(struct hda_codec *codec)
1061{
1062 struct conexant_spec *spec = codec->spec;
1063 unsigned int bits;
1064
1065 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1066 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1067
Takashi Iwai47fd8302007-08-10 17:11:07 +02001068 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1069 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1070 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001071 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001072 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1073 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001074}
1075
Tobin Davisc9b443d2006-11-14 12:13:39 +01001076/* toggle input of built-in and mic jack appropriately */
1077static void cxt5047_hp_automic(struct hda_codec *codec)
1078{
1079 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001080 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1081 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001082 {}
1083 };
1084 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001085 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1086 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001087 {}
1088 };
1089 unsigned int present;
1090
Tobin Davis7f296732007-03-12 11:39:01 +01001091 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001092 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1093 if (present)
1094 snd_hda_sequence_write(codec, mic_jack_on);
1095 else
1096 snd_hda_sequence_write(codec, mic_jack_off);
1097}
1098
1099/* unsolicited event for HP jack sensing */
1100static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1101 unsigned int res)
1102{
Marc Boucher9f113e02008-01-22 15:18:08 +01001103 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001104 case CONEXANT_HP_EVENT:
1105 cxt5047_hp_automute(codec);
1106 break;
1107 case CONEXANT_MIC_EVENT:
1108 cxt5047_hp_automic(codec);
1109 break;
1110 }
1111}
1112
Tobin Davisfb3409e2007-05-17 09:40:47 +02001113/* unsolicited event for HP jack sensing - non-EAPD systems */
1114static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1115 unsigned int res)
1116{
1117 res >>= 26;
1118 switch (res) {
1119 case CONEXANT_HP_EVENT:
1120 cxt5047_hp2_automute(codec);
1121 break;
1122 case CONEXANT_MIC_EVENT:
1123 cxt5047_hp_automic(codec);
1124 break;
1125 }
1126}
1127
Tobin Davisc9b443d2006-11-14 12:13:39 +01001128static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001129 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1130 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001131 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1132 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001133 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1134 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1135 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1136 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001137 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1138 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001139 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1140 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1141 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1142 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001143
1144 {}
1145};
1146
1147static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1148 {
1149 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1150 .name = "Capture Source",
1151 .info = conexant_mux_enum_info,
1152 .get = conexant_mux_enum_get,
1153 .put = conexant_mux_enum_put
1154 },
1155 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1156 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1157 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1158 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1159 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1160 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001161 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001162 {
1163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1164 .name = "Master Playback Switch",
1165 .info = cxt_eapd_info,
1166 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001167 .put = cxt5047_hp_master_sw_put,
1168 .private_value = 0x13,
1169 },
1170
1171 {}
1172};
1173
1174static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1175 {
1176 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1177 .name = "Capture Source",
1178 .info = conexant_mux_enum_info,
1179 .get = conexant_mux_enum_get,
1180 .put = conexant_mux_enum_put
1181 },
1182 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1183 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1184 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1185 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1186 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1187 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1188 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1189 {
1190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1191 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001192 .info = cxt_eapd_info,
1193 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001194 .put = cxt5047_hp_master_sw_put,
1195 .private_value = 0x13,
1196 },
1197 { } /* end */
1198};
1199
1200static struct hda_verb cxt5047_init_verbs[] = {
1201 /* Line in, Mic, Built-in Mic */
1202 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1203 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1204 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001205 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001206 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1207 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001208 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1209 /* Record selector: Mic */
1210 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1211 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1212 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1213 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001214 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1215 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1216 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1217 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001218 /* SPDIF route: PCM */
1219 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001220 /* Enable unsolicited events */
1221 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1222 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223 { } /* end */
1224};
1225
1226/* configuration for Toshiba Laptops */
1227static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1228 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1229 /* pin sensing on HP and Mic jacks */
1230 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1231 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001232 /* Speaker routing */
1233 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 {}
1235};
1236
1237/* configuration for HP Laptops */
1238static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001239 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001240 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001241 /* 0x13 is actually shared by both HP and speaker;
1242 * setting the connection to 0 (=0x19) makes the master volume control
1243 * working mysteriouslly...
1244 */
1245 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001246 /* Record selector: Ext Mic */
1247 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001248 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1249 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1250 /* Speaker routing */
1251 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001252 {}
1253};
1254
1255/* Test configuration for debugging, modelled after the ALC260 test
1256 * configuration.
1257 */
1258#ifdef CONFIG_SND_DEBUG
1259static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001260 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001261 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001262 { "LINE1 pin", 0x0 },
1263 { "MIC1 pin", 0x1 },
1264 { "MIC2 pin", 0x2 },
1265 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001266 },
1267};
1268
1269static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1270
1271 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001272 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1273 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1274 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1275 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001276 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1277 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1278 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1279 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001280 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1281 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1282 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1283 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001284
1285 /* Modes for retasking pin widgets */
1286 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1287 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1288
Tobin Davis82f30042007-02-13 12:45:44 +01001289 /* EAPD Switch Control */
1290 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1291
Tobin Davisc9b443d2006-11-14 12:13:39 +01001292 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001293 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1294 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1295 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1296 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1297 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1298 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1299 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1300 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001301
Tobin Davis82f30042007-02-13 12:45:44 +01001302 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1303 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1304 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1305 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1306 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1307 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1308 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1309 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001310 {
1311 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1312 .name = "Input Source",
1313 .info = conexant_mux_enum_info,
1314 .get = conexant_mux_enum_get,
1315 .put = conexant_mux_enum_put,
1316 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001317 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1318 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1319 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1320 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1321 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1322 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1323 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1324 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1325 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1326 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1327
Tobin Davisc9b443d2006-11-14 12:13:39 +01001328 { } /* end */
1329};
1330
1331static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332 /* Enable retasking pins as output, initially without power amp */
1333 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1334 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1335 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1336
1337 /* Disable digital (SPDIF) pins initially, but users can enable
1338 * them via a mixer switch. In the case of SPDIF-out, this initverb
1339 * payload also sets the generation to 0, output to be in "consumer"
1340 * PCM format, copyright asserted, no pre-emphasis and no validity
1341 * control.
1342 */
1343 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1344
1345 /* Ensure mic1, mic2, line1 pin widgets take input from the
1346 * OUT1 sum bus when acting as an output.
1347 */
1348 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1349 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1350
1351 /* Start with output sum widgets muted and their output gains at min */
1352 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1353 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1354
1355 /* Unmute retasking pin widget output buffers since the default
1356 * state appears to be output. As the pin mode is changed by the
1357 * user the pin mode control will take care of enabling the pin's
1358 * input/output buffers as needed.
1359 */
1360 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1361 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1362 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1363
1364 /* Mute capture amp left and right */
1365 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1366
1367 /* Set ADC connection select to match default mixer setting (mic1
1368 * pin)
1369 */
1370 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1371
1372 /* Mute all inputs to mixer widget (even unconnected ones) */
1373 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1374 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1375 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1376 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1377 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1378 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1379 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1380 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1381
1382 { }
1383};
1384#endif
1385
1386
1387/* initialize jack-sensing, too */
1388static int cxt5047_hp_init(struct hda_codec *codec)
1389{
1390 conexant_init(codec);
1391 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001392 return 0;
1393}
1394
1395
1396enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001397 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1398 CXT5047_LAPTOP_HP, /* Some HP laptops */
1399 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001400#ifdef CONFIG_SND_DEBUG
1401 CXT5047_TEST,
1402#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001403 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001404};
1405
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001406static const char *cxt5047_models[CXT5047_MODELS] = {
1407 [CXT5047_LAPTOP] = "laptop",
1408 [CXT5047_LAPTOP_HP] = "laptop-hp",
1409 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001411 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001412#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001413};
1414
1415static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1416 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001417 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001418 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001419 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001420 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001421 {}
1422};
1423
1424static int patch_cxt5047(struct hda_codec *codec)
1425{
1426 struct conexant_spec *spec;
1427 int board_config;
1428
1429 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1430 if (!spec)
1431 return -ENOMEM;
1432 mutex_init(&spec->amp_mutex);
1433 codec->spec = spec;
1434
1435 spec->multiout.max_channels = 2;
1436 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1437 spec->multiout.dac_nids = cxt5047_dac_nids;
1438 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1439 spec->num_adc_nids = 1;
1440 spec->adc_nids = cxt5047_adc_nids;
1441 spec->capsrc_nids = cxt5047_capsrc_nids;
1442 spec->input_mux = &cxt5047_capture_source;
1443 spec->num_mixers = 1;
1444 spec->mixers[0] = cxt5047_mixers;
1445 spec->num_init_verbs = 1;
1446 spec->init_verbs[0] = cxt5047_init_verbs;
1447 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001448 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1449 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001450
1451 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001452
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001453 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1454 cxt5047_models,
1455 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001456 switch (board_config) {
1457 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001458 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001459 break;
1460 case CXT5047_LAPTOP_HP:
1461 spec->input_mux = &cxt5047_hp_capture_source;
1462 spec->num_init_verbs = 2;
1463 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1464 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001465 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001466 codec->patch_ops.init = cxt5047_hp_init;
1467 break;
1468 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001469 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001470 spec->num_init_verbs = 2;
1471 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001472 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001473 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001474 break;
1475#ifdef CONFIG_SND_DEBUG
1476 case CXT5047_TEST:
1477 spec->input_mux = &cxt5047_test_capture_source;
1478 spec->mixers[0] = cxt5047_test_mixer;
1479 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001480 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481#endif
1482 }
1483 return 0;
1484}
1485
Takashi Iwai461e2c72008-01-25 11:35:17 +01001486/* Conexant 5051 specific */
1487static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1488static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1489#define CXT5051_SPDIF_OUT 0x1C
1490#define CXT5051_PORTB_EVENT 0x38
1491#define CXT5051_PORTC_EVENT 0x39
1492
1493static struct hda_channel_mode cxt5051_modes[1] = {
1494 { 2, NULL },
1495};
1496
1497static void cxt5051_update_speaker(struct hda_codec *codec)
1498{
1499 struct conexant_spec *spec = codec->spec;
1500 unsigned int pinctl;
1501 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1502 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1503 pinctl);
1504}
1505
1506/* turn on/off EAPD (+ mute HP) as a master switch */
1507static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1508 struct snd_ctl_elem_value *ucontrol)
1509{
1510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1511
1512 if (!cxt_eapd_put(kcontrol, ucontrol))
1513 return 0;
1514 cxt5051_update_speaker(codec);
1515 return 1;
1516}
1517
1518/* toggle input of built-in and mic jack appropriately */
1519static void cxt5051_portb_automic(struct hda_codec *codec)
1520{
1521 unsigned int present;
1522
1523 present = snd_hda_codec_read(codec, 0x17, 0,
1524 AC_VERB_GET_PIN_SENSE, 0) &
1525 AC_PINSENSE_PRESENCE;
1526 snd_hda_codec_write(codec, 0x14, 0,
1527 AC_VERB_SET_CONNECT_SEL,
1528 present ? 0x01 : 0x00);
1529}
1530
1531/* switch the current ADC according to the jack state */
1532static void cxt5051_portc_automic(struct hda_codec *codec)
1533{
1534 struct conexant_spec *spec = codec->spec;
1535 unsigned int present;
1536 hda_nid_t new_adc;
1537
1538 present = snd_hda_codec_read(codec, 0x18, 0,
1539 AC_VERB_GET_PIN_SENSE, 0) &
1540 AC_PINSENSE_PRESENCE;
1541 if (present)
1542 spec->cur_adc_idx = 1;
1543 else
1544 spec->cur_adc_idx = 0;
1545 new_adc = spec->adc_nids[spec->cur_adc_idx];
1546 if (spec->cur_adc && spec->cur_adc != new_adc) {
1547 /* stream is running, let's swap the current ADC */
1548 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
1549 spec->cur_adc = new_adc;
1550 snd_hda_codec_setup_stream(codec, new_adc,
1551 spec->cur_adc_stream_tag, 0,
1552 spec->cur_adc_format);
1553 }
1554}
1555
1556/* mute internal speaker if HP is plugged */
1557static void cxt5051_hp_automute(struct hda_codec *codec)
1558{
1559 struct conexant_spec *spec = codec->spec;
1560
1561 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1562 AC_VERB_GET_PIN_SENSE, 0) &
1563 AC_PINSENSE_PRESENCE;
1564 cxt5051_update_speaker(codec);
1565}
1566
1567/* unsolicited event for HP jack sensing */
1568static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1569 unsigned int res)
1570{
1571 switch (res >> 26) {
1572 case CONEXANT_HP_EVENT:
1573 cxt5051_hp_automute(codec);
1574 break;
1575 case CXT5051_PORTB_EVENT:
1576 cxt5051_portb_automic(codec);
1577 break;
1578 case CXT5051_PORTC_EVENT:
1579 cxt5051_portc_automic(codec);
1580 break;
1581 }
1582}
1583
1584static struct snd_kcontrol_new cxt5051_mixers[] = {
1585 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1586 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1587 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1588 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1589 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1590 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1591 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1592 {
1593 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1594 .name = "Master Playback Switch",
1595 .info = cxt_eapd_info,
1596 .get = cxt_eapd_get,
1597 .put = cxt5051_hp_master_sw_put,
1598 .private_value = 0x1a,
1599 },
1600
1601 {}
1602};
1603
1604static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1605 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1606 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1607 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1608 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1609 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1610 {
1611 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1612 .name = "Master Playback Switch",
1613 .info = cxt_eapd_info,
1614 .get = cxt_eapd_get,
1615 .put = cxt5051_hp_master_sw_put,
1616 .private_value = 0x1a,
1617 },
1618
1619 {}
1620};
1621
1622static struct hda_verb cxt5051_init_verbs[] = {
1623 /* Line in, Mic */
1624 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1625 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1626 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1627 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1628 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1629 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1630 /* SPK */
1631 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1632 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1633 /* HP, Amp */
1634 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1635 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1636 /* DAC1 */
1637 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1638 /* Record selector: Int mic */
1639 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1640 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1641 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1642 /* SPDIF route: PCM */
1643 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1644 /* EAPD */
1645 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1646 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1647 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1648 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1649 { } /* end */
1650};
1651
1652/* initialize jack-sensing, too */
1653static int cxt5051_init(struct hda_codec *codec)
1654{
1655 conexant_init(codec);
1656 if (codec->patch_ops.unsol_event) {
1657 cxt5051_hp_automute(codec);
1658 cxt5051_portb_automic(codec);
1659 cxt5051_portc_automic(codec);
1660 }
1661 return 0;
1662}
1663
1664
1665enum {
1666 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1667 CXT5051_HP, /* no docking */
1668 CXT5051_MODELS
1669};
1670
1671static const char *cxt5051_models[CXT5051_MODELS] = {
1672 [CXT5051_LAPTOP] = "laptop",
1673 [CXT5051_HP] = "hp",
1674};
1675
1676static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1677 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1678 CXT5051_LAPTOP),
1679 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1680 {}
1681};
1682
1683static int patch_cxt5051(struct hda_codec *codec)
1684{
1685 struct conexant_spec *spec;
1686 int board_config;
1687
1688 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1689 if (!spec)
1690 return -ENOMEM;
1691 mutex_init(&spec->amp_mutex);
1692 codec->spec = spec;
1693
1694 codec->patch_ops = conexant_patch_ops;
1695 codec->patch_ops.init = cxt5051_init;
1696
1697 spec->multiout.max_channels = 2;
1698 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1699 spec->multiout.dac_nids = cxt5051_dac_nids;
1700 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1701 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1702 spec->adc_nids = cxt5051_adc_nids;
1703 spec->num_mixers = 1;
1704 spec->mixers[0] = cxt5051_mixers;
1705 spec->num_init_verbs = 1;
1706 spec->init_verbs[0] = cxt5051_init_verbs;
1707 spec->spdif_route = 0;
1708 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1709 spec->channel_mode = cxt5051_modes;
1710 spec->cur_adc = 0;
1711 spec->cur_adc_idx = 0;
1712
1713 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1714 cxt5051_models,
1715 cxt5051_cfg_tbl);
1716 switch (board_config) {
1717 case CXT5051_HP:
1718 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1719 spec->mixers[0] = cxt5051_hp_mixers;
1720 break;
1721 default:
1722 case CXT5051_LAPTOP:
1723 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1724 break;
1725 }
1726
1727 return 0;
1728}
1729
1730
1731/*
1732 */
1733
Tobin Davisc9b443d2006-11-14 12:13:39 +01001734struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001735 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1736 .patch = patch_cxt5045 },
1737 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1738 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001739 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1740 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001741 {} /* terminator */
1742};