blob: 7c1eb23f0cec09ae31901058b11222b1ddeca6e4 [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
Tobin Davisc9b443d2006-11-14 12:13:39 +010085 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;
Takashi Iwai888afa12008-03-18 09:57:50 +0100176 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100177 return 0;
178}
179
180
181
182static struct hda_pcm_stream conexant_pcm_analog_playback = {
183 .substreams = 1,
184 .channels_min = 2,
185 .channels_max = 2,
186 .nid = 0, /* fill later */
187 .ops = {
188 .open = conexant_playback_pcm_open,
189 .prepare = conexant_playback_pcm_prepare,
190 .cleanup = conexant_playback_pcm_cleanup
191 },
192};
193
194static struct hda_pcm_stream conexant_pcm_analog_capture = {
195 .substreams = 1,
196 .channels_min = 2,
197 .channels_max = 2,
198 .nid = 0, /* fill later */
199 .ops = {
200 .prepare = conexant_capture_pcm_prepare,
201 .cleanup = conexant_capture_pcm_cleanup
202 },
203};
204
205
206static struct hda_pcm_stream conexant_pcm_digital_playback = {
207 .substreams = 1,
208 .channels_min = 2,
209 .channels_max = 2,
210 .nid = 0, /* fill later */
211 .ops = {
212 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200213 .close = conexant_dig_playback_pcm_close,
214 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100215 },
216};
217
218static struct hda_pcm_stream conexant_pcm_digital_capture = {
219 .substreams = 1,
220 .channels_min = 2,
221 .channels_max = 2,
222 /* NID is set in alc_build_pcms */
223};
224
Takashi Iwai461e2c72008-01-25 11:35:17 +0100225static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
226 struct hda_codec *codec,
227 unsigned int stream_tag,
228 unsigned int format,
229 struct snd_pcm_substream *substream)
230{
231 struct conexant_spec *spec = codec->spec;
232 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
233 spec->cur_adc_stream_tag = stream_tag;
234 spec->cur_adc_format = format;
235 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
236 return 0;
237}
238
239static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
240 struct hda_codec *codec,
241 struct snd_pcm_substream *substream)
242{
243 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100244 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100245 spec->cur_adc = 0;
246 return 0;
247}
248
249static struct hda_pcm_stream cx5051_pcm_analog_capture = {
250 .substreams = 1,
251 .channels_min = 2,
252 .channels_max = 2,
253 .nid = 0, /* fill later */
254 .ops = {
255 .prepare = cx5051_capture_pcm_prepare,
256 .cleanup = cx5051_capture_pcm_cleanup
257 },
258};
259
Tobin Davisc9b443d2006-11-14 12:13:39 +0100260static int conexant_build_pcms(struct hda_codec *codec)
261{
262 struct conexant_spec *spec = codec->spec;
263 struct hda_pcm *info = spec->pcm_rec;
264
265 codec->num_pcms = 1;
266 codec->pcm_info = info;
267
268 info->name = "CONEXANT Analog";
269 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
270 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
271 spec->multiout.max_channels;
272 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
273 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100274 if (codec->vendor_id == 0x14f15051)
275 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
276 cx5051_pcm_analog_capture;
277 else
278 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
279 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100280 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
281 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
282
283 if (spec->multiout.dig_out_nid) {
284 info++;
285 codec->num_pcms++;
286 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100287 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100288 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
289 conexant_pcm_digital_playback;
290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
291 spec->multiout.dig_out_nid;
292 if (spec->dig_in_nid) {
293 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
294 conexant_pcm_digital_capture;
295 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
296 spec->dig_in_nid;
297 }
298 }
299
300 return 0;
301}
302
303static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
304 struct snd_ctl_elem_info *uinfo)
305{
306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
307 struct conexant_spec *spec = codec->spec;
308
309 return snd_hda_input_mux_info(spec->input_mux, uinfo);
310}
311
312static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
314{
315 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
316 struct conexant_spec *spec = codec->spec;
317 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
318
319 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
320 return 0;
321}
322
323static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_value *ucontrol)
325{
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct conexant_spec *spec = codec->spec;
328 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
329
330 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
331 spec->capsrc_nids[adc_idx],
332 &spec->cur_mux[adc_idx]);
333}
334
335static int conexant_init(struct hda_codec *codec)
336{
337 struct conexant_spec *spec = codec->spec;
338 int i;
339
340 for (i = 0; i < spec->num_init_verbs; i++)
341 snd_hda_sequence_write(codec, spec->init_verbs[i]);
342 return 0;
343}
344
345static void conexant_free(struct hda_codec *codec)
346{
347 struct conexant_spec *spec = codec->spec;
348 unsigned int i;
349
350 if (spec->kctl_alloc) {
351 for (i = 0; i < spec->num_kctl_used; i++)
352 kfree(spec->kctl_alloc[i].name);
353 kfree(spec->kctl_alloc);
354 }
355
356 kfree(codec->spec);
357}
358
Tobin Davisc9b443d2006-11-14 12:13:39 +0100359static int conexant_build_controls(struct hda_codec *codec)
360{
361 struct conexant_spec *spec = codec->spec;
362 unsigned int i;
363 int err;
364
365 for (i = 0; i < spec->num_mixers; i++) {
366 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
367 if (err < 0)
368 return err;
369 }
370 if (spec->multiout.dig_out_nid) {
371 err = snd_hda_create_spdif_out_ctls(codec,
372 spec->multiout.dig_out_nid);
373 if (err < 0)
374 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100375 err = snd_hda_create_spdif_share_sw(codec,
376 &spec->multiout);
377 if (err < 0)
378 return err;
379 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100380 }
381 if (spec->dig_in_nid) {
382 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
383 if (err < 0)
384 return err;
385 }
386 return 0;
387}
388
389static struct hda_codec_ops conexant_patch_ops = {
390 .build_controls = conexant_build_controls,
391 .build_pcms = conexant_build_pcms,
392 .init = conexant_init,
393 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100394};
395
396/*
397 * EAPD control
398 * the private value = nid | (invert << 8)
399 */
400
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200401#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100402
Tobin Davis82f30042007-02-13 12:45:44 +0100403static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100404 struct snd_ctl_elem_value *ucontrol)
405{
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 struct conexant_spec *spec = codec->spec;
408 int invert = (kcontrol->private_value >> 8) & 1;
409 if (invert)
410 ucontrol->value.integer.value[0] = !spec->cur_eapd;
411 else
412 ucontrol->value.integer.value[0] = spec->cur_eapd;
413 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100414
Tobin Davisc9b443d2006-11-14 12:13:39 +0100415}
416
Tobin Davis82f30042007-02-13 12:45:44 +0100417static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100418 struct snd_ctl_elem_value *ucontrol)
419{
420 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
421 struct conexant_spec *spec = codec->spec;
422 int invert = (kcontrol->private_value >> 8) & 1;
423 hda_nid_t nid = kcontrol->private_value & 0xff;
424 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100425
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100426 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100427 if (invert)
428 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200429 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100430 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100431
Tobin Davisc9b443d2006-11-14 12:13:39 +0100432 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200433 snd_hda_codec_write_cache(codec, nid,
434 0, AC_VERB_SET_EAPD_BTLENABLE,
435 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100436 return 1;
437}
438
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100439/* controls for test mode */
440#ifdef CONFIG_SND_DEBUG
441
Tobin Davis82f30042007-02-13 12:45:44 +0100442#define CXT_EAPD_SWITCH(xname, nid, mask) \
443 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
444 .info = cxt_eapd_info, \
445 .get = cxt_eapd_get, \
446 .put = cxt_eapd_put, \
447 .private_value = nid | (mask<<16) }
448
449
450
Tobin Davisc9b443d2006-11-14 12:13:39 +0100451static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
452 struct snd_ctl_elem_info *uinfo)
453{
454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
455 struct conexant_spec *spec = codec->spec;
456 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
457 spec->num_channel_mode);
458}
459
460static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
462{
463 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
464 struct conexant_spec *spec = codec->spec;
465 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
466 spec->num_channel_mode,
467 spec->multiout.max_channels);
468}
469
470static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
471 struct snd_ctl_elem_value *ucontrol)
472{
473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474 struct conexant_spec *spec = codec->spec;
475 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
476 spec->num_channel_mode,
477 &spec->multiout.max_channels);
478 if (err >= 0 && spec->need_dac_fix)
479 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
480 return err;
481}
482
483#define CXT_PIN_MODE(xname, nid, dir) \
484 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
485 .info = conexant_ch_mode_info, \
486 .get = conexant_ch_mode_get, \
487 .put = conexant_ch_mode_put, \
488 .private_value = nid | (dir<<16) }
489
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100490#endif /* CONFIG_SND_DEBUG */
491
Tobin Davisc9b443d2006-11-14 12:13:39 +0100492/* Conexant 5045 specific */
493
494static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
495static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
496static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100497#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100498
Tobin Davis5cd57522006-11-20 17:42:09 +0100499static struct hda_channel_mode cxt5045_modes[1] = {
500 { 2, NULL },
501};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100502
503static struct hda_input_mux cxt5045_capture_source = {
504 .num_items = 2,
505 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100506 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100507 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100508 }
509};
510
Jiang Zhe5218c892008-01-17 11:18:41 +0100511static struct hda_input_mux cxt5045_capture_source_benq = {
512 .num_items = 3,
513 .items = {
514 { "IntMic", 0x1 },
515 { "ExtMic", 0x2 },
516 { "LineIn", 0x3 },
517 }
518};
519
Jiang zhe2de3c232008-03-06 11:09:09 +0100520static struct hda_input_mux cxt5045_capture_source_hp530 = {
521 .num_items = 2,
522 .items = {
523 { "ExtMic", 0x1 },
524 { "IntMic", 0x2 },
525 }
526};
527
Tobin Davisc9b443d2006-11-14 12:13:39 +0100528/* turn on/off EAPD (+ mute HP) as a master switch */
529static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
530 struct snd_ctl_elem_value *ucontrol)
531{
532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
533 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100534 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100535
Tobin Davis82f30042007-02-13 12:45:44 +0100536 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100537 return 0;
538
Tobin Davis82f30042007-02-13 12:45:44 +0100539 /* toggle internal speakers mute depending of presence of
540 * the headphone jack
541 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200542 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
543 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
544 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100545
Takashi Iwai47fd8302007-08-10 17:11:07 +0200546 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
547 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
548 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100549 return 1;
550}
551
552/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200553static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
554 .ops = &snd_hda_bind_vol,
555 .values = {
556 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
557 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
558 0
559 },
560};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100561
Tobin Davis7f296732007-03-12 11:39:01 +0100562/* toggle input of built-in and mic jack appropriately */
563static void cxt5045_hp_automic(struct hda_codec *codec)
564{
565 static struct hda_verb mic_jack_on[] = {
566 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
567 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
568 {}
569 };
570 static struct hda_verb mic_jack_off[] = {
571 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
572 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
573 {}
574 };
575 unsigned int present;
576
577 present = snd_hda_codec_read(codec, 0x12, 0,
578 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
579 if (present)
580 snd_hda_sequence_write(codec, mic_jack_on);
581 else
582 snd_hda_sequence_write(codec, mic_jack_off);
583}
584
Tobin Davisc9b443d2006-11-14 12:13:39 +0100585
586/* mute internal speaker if HP is plugged */
587static void cxt5045_hp_automute(struct hda_codec *codec)
588{
Tobin Davis82f30042007-02-13 12:45:44 +0100589 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100590 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100591
Tobin Davis82f30042007-02-13 12:45:44 +0100592 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100593 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100594
Takashi Iwai47fd8302007-08-10 17:11:07 +0200595 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
596 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
597 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598}
599
600/* unsolicited event for HP jack sensing */
601static void cxt5045_hp_unsol_event(struct hda_codec *codec,
602 unsigned int res)
603{
604 res >>= 26;
605 switch (res) {
606 case CONEXANT_HP_EVENT:
607 cxt5045_hp_automute(codec);
608 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100609 case CONEXANT_MIC_EVENT:
610 cxt5045_hp_automic(codec);
611 break;
612
Tobin Davisc9b443d2006-11-14 12:13:39 +0100613 }
614}
615
616static struct snd_kcontrol_new cxt5045_mixers[] = {
617 {
618 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
619 .name = "Capture Source",
620 .info = conexant_mux_enum_info,
621 .get = conexant_mux_enum_get,
622 .put = conexant_mux_enum_put
623 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200624 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
625 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
626 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
627 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
628 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
629 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
630 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
631 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
632 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
633 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200634 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100635 {
636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
637 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100638 .info = cxt_eapd_info,
639 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100640 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100641 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100642 },
643
644 {}
645};
646
Jiang Zhe5218c892008-01-17 11:18:41 +0100647static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
648 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
649 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
650 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
651 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
652
653 {}
654};
655
Jiang zhe2de3c232008-03-06 11:09:09 +0100656static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
657 {
658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
659 .name = "Capture Source",
660 .info = conexant_mux_enum_info,
661 .get = conexant_mux_enum_get,
662 .put = conexant_mux_enum_put
663 },
664 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
665 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
666 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
667 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
668 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
669 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
670 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
671 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
672 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
673 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
674 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
675 {
676 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
677 .name = "Master Playback Switch",
678 .info = cxt_eapd_info,
679 .get = cxt_eapd_get,
680 .put = cxt5045_hp_master_sw_put,
681 .private_value = 0x10,
682 },
683
684 {}
685};
686
Tobin Davisc9b443d2006-11-14 12:13:39 +0100687static struct hda_verb cxt5045_init_verbs[] = {
688 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200689 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100690 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200692 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
693 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
694 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
695 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
696 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
697 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
698 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
699 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
700 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100701 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100702 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100703 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100704 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
705 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100706 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100707 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100708 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100709 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100710 { } /* end */
711};
712
Jiang Zhe5218c892008-01-17 11:18:41 +0100713static struct hda_verb cxt5045_benq_init_verbs[] = {
714 /* Int Mic, Mic */
715 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
716 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
717 /* Line In,HP, Amp */
718 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
719 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
720 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
721 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
722 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
723 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
724 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
726 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
727 /* Record selector: Int mic */
728 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
729 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
730 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
731 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100732 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100733 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
734 /* EAPD */
735 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
736 { } /* end */
737};
Tobin Davis7f296732007-03-12 11:39:01 +0100738
739static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
740 /* pin sensing on HP jack */
741 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200742 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100743};
744
745static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
746 /* pin sensing on HP jack */
747 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200748 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100749};
750
Tobin Davisc9b443d2006-11-14 12:13:39 +0100751#ifdef CONFIG_SND_DEBUG
752/* Test configuration for debugging, modelled after the ALC260 test
753 * configuration.
754 */
755static struct hda_input_mux cxt5045_test_capture_source = {
756 .num_items = 5,
757 .items = {
758 { "MIXER", 0x0 },
759 { "MIC1 pin", 0x1 },
760 { "LINE1 pin", 0x2 },
761 { "HP-OUT pin", 0x3 },
762 { "CD pin", 0x4 },
763 },
764};
765
766static struct snd_kcontrol_new cxt5045_test_mixer[] = {
767
768 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
770 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100771 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
772 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
773 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
774 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775
776 /* Modes for retasking pin widgets */
777 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
778 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
779
Tobin Davis82f30042007-02-13 12:45:44 +0100780 /* EAPD Switch Control */
781 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
782
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784
Tobin Davis7f296732007-03-12 11:39:01 +0100785 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
786 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
787 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
788 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
789 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
790 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
791 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
792 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
793 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
794 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795 {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "Input Source",
798 .info = conexant_mux_enum_info,
799 .get = conexant_mux_enum_get,
800 .put = conexant_mux_enum_put,
801 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200802 /* Audio input controls */
803 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
804 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
805 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
806 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
807 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
808 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
809 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
810 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
811 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
812 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100813 { } /* end */
814};
815
816static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100817 /* Set connections */
818 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
819 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
820 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100821 /* Enable retasking pins as output, initially without power amp */
822 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100823 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100824
825 /* Disable digital (SPDIF) pins initially, but users can enable
826 * them via a mixer switch. In the case of SPDIF-out, this initverb
827 * payload also sets the generation to 0, output to be in "consumer"
828 * PCM format, copyright asserted, no pre-emphasis and no validity
829 * control.
830 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100831 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
832 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100833
834 /* Start with output sum widgets muted and their output gains at min */
835 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
836 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
837
838 /* Unmute retasking pin widget output buffers since the default
839 * state appears to be output. As the pin mode is changed by the
840 * user the pin mode control will take care of enabling the pin's
841 * input/output buffers as needed.
842 */
843 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
844 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
845
846 /* Mute capture amp left and right */
847 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
848
849 /* Set ADC connection select to match default mixer setting (mic1
850 * pin)
851 */
852 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100853 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100854
855 /* Mute all inputs to mixer widget (even unconnected ones) */
856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
857 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
859 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
860 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
861
862 { }
863};
864#endif
865
866
867/* initialize jack-sensing, too */
868static int cxt5045_init(struct hda_codec *codec)
869{
870 conexant_init(codec);
871 cxt5045_hp_automute(codec);
872 return 0;
873}
874
875
876enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100877 CXT5045_LAPTOP_HPSENSE,
878 CXT5045_LAPTOP_MICSENSE,
879 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100880 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +0100881 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100882#ifdef CONFIG_SND_DEBUG
883 CXT5045_TEST,
884#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100885 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100886};
887
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100888static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100889 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
890 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
891 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
892 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +0100893 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100894#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100895 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100896#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100897};
898
899static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100900 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
901 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
902 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
903 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
904 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
905 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai0f6a5152008-01-29 13:26:04 +0100906 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
Jiang zhe2de3c232008-03-06 11:09:09 +0100907 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Marc Boucher15908c32008-01-22 15:15:59 +0100908 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +0200909 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +0100910 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +0100911 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
912 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +0200913 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
914 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +0100915 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
916 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
917 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
918 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
919 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
920 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100921 {}
922};
923
924static int patch_cxt5045(struct hda_codec *codec)
925{
926 struct conexant_spec *spec;
927 int board_config;
928
929 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
930 if (!spec)
931 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932 codec->spec = spec;
933
934 spec->multiout.max_channels = 2;
935 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
936 spec->multiout.dac_nids = cxt5045_dac_nids;
937 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
938 spec->num_adc_nids = 1;
939 spec->adc_nids = cxt5045_adc_nids;
940 spec->capsrc_nids = cxt5045_capsrc_nids;
941 spec->input_mux = &cxt5045_capture_source;
942 spec->num_mixers = 1;
943 spec->mixers[0] = cxt5045_mixers;
944 spec->num_init_verbs = 1;
945 spec->init_verbs[0] = cxt5045_init_verbs;
946 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100947 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
948 spec->channel_mode = cxt5045_modes,
949
Tobin Davisc9b443d2006-11-14 12:13:39 +0100950
951 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100953 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
954 cxt5045_models,
955 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100956 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +0100957 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100958 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100959 spec->input_mux = &cxt5045_capture_source;
960 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100961 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
962 spec->mixers[0] = cxt5045_mixers;
963 codec->patch_ops.init = cxt5045_init;
964 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100965 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +0200966 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +0100967 spec->input_mux = &cxt5045_capture_source;
968 spec->num_init_verbs = 2;
969 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100970 spec->mixers[0] = cxt5045_mixers;
971 codec->patch_ops.init = cxt5045_init;
972 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100973 default:
974 case CXT5045_LAPTOP_HPMICSENSE:
975 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
976 spec->input_mux = &cxt5045_capture_source;
977 spec->num_init_verbs = 3;
978 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
979 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
980 spec->mixers[0] = cxt5045_mixers;
981 codec->patch_ops.init = cxt5045_init;
982 break;
Jiang Zhe5218c892008-01-17 11:18:41 +0100983 case CXT5045_BENQ:
984 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
985 spec->input_mux = &cxt5045_capture_source_benq;
986 spec->num_init_verbs = 1;
987 spec->init_verbs[0] = cxt5045_benq_init_verbs;
988 spec->mixers[0] = cxt5045_mixers;
989 spec->mixers[1] = cxt5045_benq_mixers;
990 spec->num_mixers = 2;
991 codec->patch_ops.init = cxt5045_init;
992 break;
Jiang zhe2de3c232008-03-06 11:09:09 +0100993 case CXT5045_LAPTOP_HP530:
994 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
995 spec->input_mux = &cxt5045_capture_source_hp530;
996 spec->num_init_verbs = 2;
997 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
998 spec->mixers[0] = cxt5045_mixers_hp530;
999 codec->patch_ops.init = cxt5045_init;
1000 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001#ifdef CONFIG_SND_DEBUG
1002 case CXT5045_TEST:
1003 spec->input_mux = &cxt5045_test_capture_source;
1004 spec->mixers[0] = cxt5045_test_mixer;
1005 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001006 break;
1007
Tobin Davisc9b443d2006-11-14 12:13:39 +01001008#endif
1009 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001010
Takashi Iwai031005f2008-06-26 14:49:58 +02001011 switch (codec->subsystem_id >> 16) {
1012 case 0x103c:
1013 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1014 * Fix max PCM level to 0 dB
1015 * (originall it has 0x2b steps with 0dB offset 0x14)
1016 */
1017 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1018 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1019 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1020 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1021 (1 << AC_AMPCAP_MUTE_SHIFT));
1022 break;
1023 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001024
Tobin Davisc9b443d2006-11-14 12:13:39 +01001025 return 0;
1026}
1027
1028
1029/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001030#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001031
Tobin Davis82f30042007-02-13 12:45:44 +01001032static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001033static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1034static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001035
Tobin Davis5cd57522006-11-20 17:42:09 +01001036static struct hda_channel_mode cxt5047_modes[1] = {
1037 { 2, NULL },
1038};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001039
1040static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +01001041 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001042 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +01001043 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001044 }
1045};
1046
1047static struct hda_input_mux cxt5047_hp_capture_source = {
1048 .num_items = 1,
1049 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001050 { "ExtMic", 0x2 },
1051 }
1052};
1053
1054static struct hda_input_mux cxt5047_toshiba_capture_source = {
1055 .num_items = 2,
1056 .items = {
1057 { "ExtMic", 0x2 },
1058 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001059 }
1060};
1061
1062/* turn on/off EAPD (+ mute HP) as a master switch */
1063static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1064 struct snd_ctl_elem_value *ucontrol)
1065{
1066 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1067 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001068 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001069
Tobin Davis82f30042007-02-13 12:45:44 +01001070 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001071 return 0;
1072
Tobin Davis82f30042007-02-13 12:45:44 +01001073 /* toggle internal speakers mute depending of presence of
1074 * the headphone jack
1075 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001076 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1077 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1078 HDA_AMP_MUTE, bits);
1079 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1080 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1081 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001082 return 1;
1083}
1084
Tobin Davis82f30042007-02-13 12:45:44 +01001085/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001086static struct hda_bind_ctls cxt5047_bind_master_vol = {
1087 .ops = &snd_hda_bind_vol,
1088 .values = {
1089 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1090 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1091 0
1092 },
1093};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001094
1095/* mute internal speaker if HP is plugged */
1096static void cxt5047_hp_automute(struct hda_codec *codec)
1097{
Tobin Davis82f30042007-02-13 12:45:44 +01001098 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001099 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001100
Tobin Davis82f30042007-02-13 12:45:44 +01001101 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001102 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001103
Takashi Iwai47fd8302007-08-10 17:11:07 +02001104 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1105 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1106 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001107 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001108 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1109 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001110}
1111
Tobin Davisfb3409e2007-05-17 09:40:47 +02001112/* mute internal speaker if HP is plugged */
1113static void cxt5047_hp2_automute(struct hda_codec *codec)
1114{
1115 struct conexant_spec *spec = codec->spec;
1116 unsigned int bits;
1117
1118 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1119 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1120
Takashi Iwai47fd8302007-08-10 17:11:07 +02001121 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1122 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1123 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001124 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001125 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1126 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001127}
1128
Tobin Davisc9b443d2006-11-14 12:13:39 +01001129/* toggle input of built-in and mic jack appropriately */
1130static void cxt5047_hp_automic(struct hda_codec *codec)
1131{
1132 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001133 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1134 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135 {}
1136 };
1137 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001138 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1139 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001140 {}
1141 };
1142 unsigned int present;
1143
Tobin Davis7f296732007-03-12 11:39:01 +01001144 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001145 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1146 if (present)
1147 snd_hda_sequence_write(codec, mic_jack_on);
1148 else
1149 snd_hda_sequence_write(codec, mic_jack_off);
1150}
1151
1152/* unsolicited event for HP jack sensing */
1153static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1154 unsigned int res)
1155{
Marc Boucher9f113e02008-01-22 15:18:08 +01001156 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157 case CONEXANT_HP_EVENT:
1158 cxt5047_hp_automute(codec);
1159 break;
1160 case CONEXANT_MIC_EVENT:
1161 cxt5047_hp_automic(codec);
1162 break;
1163 }
1164}
1165
Tobin Davisfb3409e2007-05-17 09:40:47 +02001166/* unsolicited event for HP jack sensing - non-EAPD systems */
1167static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1168 unsigned int res)
1169{
1170 res >>= 26;
1171 switch (res) {
1172 case CONEXANT_HP_EVENT:
1173 cxt5047_hp2_automute(codec);
1174 break;
1175 case CONEXANT_MIC_EVENT:
1176 cxt5047_hp_automic(codec);
1177 break;
1178 }
1179}
1180
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001182 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1183 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001184 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1185 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001186 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1187 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1188 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1189 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001190 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1191 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001192 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1193 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1194 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1195 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001196
1197 {}
1198};
1199
1200static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1201 {
1202 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1203 .name = "Capture Source",
1204 .info = conexant_mux_enum_info,
1205 .get = conexant_mux_enum_get,
1206 .put = conexant_mux_enum_put
1207 },
1208 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1209 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1210 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1211 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1212 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1213 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001214 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001215 {
1216 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1217 .name = "Master Playback Switch",
1218 .info = cxt_eapd_info,
1219 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001220 .put = cxt5047_hp_master_sw_put,
1221 .private_value = 0x13,
1222 },
1223
1224 {}
1225};
1226
1227static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1228 {
1229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1230 .name = "Capture Source",
1231 .info = conexant_mux_enum_info,
1232 .get = conexant_mux_enum_get,
1233 .put = conexant_mux_enum_put
1234 },
1235 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1236 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1237 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1238 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1239 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1240 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1241 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1242 {
1243 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1244 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001245 .info = cxt_eapd_info,
1246 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247 .put = cxt5047_hp_master_sw_put,
1248 .private_value = 0x13,
1249 },
1250 { } /* end */
1251};
1252
1253static struct hda_verb cxt5047_init_verbs[] = {
1254 /* Line in, Mic, Built-in Mic */
1255 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1256 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1257 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001258 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001259 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1260 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001261 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1262 /* Record selector: Mic */
1263 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1264 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1265 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1266 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1268 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1269 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1270 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001271 /* SPDIF route: PCM */
1272 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001273 /* Enable unsolicited events */
1274 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1275 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001276 { } /* end */
1277};
1278
1279/* configuration for Toshiba Laptops */
1280static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1281 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1282 /* pin sensing on HP and Mic jacks */
1283 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1284 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001285 /* Speaker routing */
1286 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287 {}
1288};
1289
1290/* configuration for HP Laptops */
1291static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001292 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001293 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001294 /* 0x13 is actually shared by both HP and speaker;
1295 * setting the connection to 0 (=0x19) makes the master volume control
1296 * working mysteriouslly...
1297 */
1298 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001299 /* Record selector: Ext Mic */
1300 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001301 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1302 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1303 /* Speaker routing */
1304 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001305 {}
1306};
1307
1308/* Test configuration for debugging, modelled after the ALC260 test
1309 * configuration.
1310 */
1311#ifdef CONFIG_SND_DEBUG
1312static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001313 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001314 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001315 { "LINE1 pin", 0x0 },
1316 { "MIC1 pin", 0x1 },
1317 { "MIC2 pin", 0x2 },
1318 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001319 },
1320};
1321
1322static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1323
1324 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001325 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1326 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1327 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1328 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001329 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1330 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1331 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1332 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001333 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1334 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1335 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1336 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001337
1338 /* Modes for retasking pin widgets */
1339 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1340 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1341
Tobin Davis82f30042007-02-13 12:45:44 +01001342 /* EAPD Switch Control */
1343 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1344
Tobin Davisc9b443d2006-11-14 12:13:39 +01001345 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001346 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1347 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1348 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1349 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1350 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1351 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1352 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1353 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001354
Tobin Davis82f30042007-02-13 12:45:44 +01001355 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1356 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1357 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1358 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1359 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1360 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1361 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1362 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001363 {
1364 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1365 .name = "Input Source",
1366 .info = conexant_mux_enum_info,
1367 .get = conexant_mux_enum_get,
1368 .put = conexant_mux_enum_put,
1369 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001370 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1371 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1372 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1373 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1374 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1375 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1376 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1377 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1378 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1379 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1380
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 { } /* end */
1382};
1383
1384static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001385 /* Enable retasking pins as output, initially without power amp */
1386 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1387 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1388 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1389
1390 /* Disable digital (SPDIF) pins initially, but users can enable
1391 * them via a mixer switch. In the case of SPDIF-out, this initverb
1392 * payload also sets the generation to 0, output to be in "consumer"
1393 * PCM format, copyright asserted, no pre-emphasis and no validity
1394 * control.
1395 */
1396 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1397
1398 /* Ensure mic1, mic2, line1 pin widgets take input from the
1399 * OUT1 sum bus when acting as an output.
1400 */
1401 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1402 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1403
1404 /* Start with output sum widgets muted and their output gains at min */
1405 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1406 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1407
1408 /* Unmute retasking pin widget output buffers since the default
1409 * state appears to be output. As the pin mode is changed by the
1410 * user the pin mode control will take care of enabling the pin's
1411 * input/output buffers as needed.
1412 */
1413 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1414 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1415 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1416
1417 /* Mute capture amp left and right */
1418 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1419
1420 /* Set ADC connection select to match default mixer setting (mic1
1421 * pin)
1422 */
1423 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1424
1425 /* Mute all inputs to mixer widget (even unconnected ones) */
1426 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1427 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1428 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1429 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1430 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1431 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1432 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1433 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1434
1435 { }
1436};
1437#endif
1438
1439
1440/* initialize jack-sensing, too */
1441static int cxt5047_hp_init(struct hda_codec *codec)
1442{
1443 conexant_init(codec);
1444 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001445 return 0;
1446}
1447
1448
1449enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001450 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1451 CXT5047_LAPTOP_HP, /* Some HP laptops */
1452 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001453#ifdef CONFIG_SND_DEBUG
1454 CXT5047_TEST,
1455#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001456 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001457};
1458
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001459static const char *cxt5047_models[CXT5047_MODELS] = {
1460 [CXT5047_LAPTOP] = "laptop",
1461 [CXT5047_LAPTOP_HP] = "laptop-hp",
1462 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001463#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001464 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001465#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001466};
1467
1468static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1469 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001470 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001471 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001472 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001473 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001474 {}
1475};
1476
1477static int patch_cxt5047(struct hda_codec *codec)
1478{
1479 struct conexant_spec *spec;
1480 int board_config;
1481
1482 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1483 if (!spec)
1484 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001485 codec->spec = spec;
1486
1487 spec->multiout.max_channels = 2;
1488 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1489 spec->multiout.dac_nids = cxt5047_dac_nids;
1490 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1491 spec->num_adc_nids = 1;
1492 spec->adc_nids = cxt5047_adc_nids;
1493 spec->capsrc_nids = cxt5047_capsrc_nids;
1494 spec->input_mux = &cxt5047_capture_source;
1495 spec->num_mixers = 1;
1496 spec->mixers[0] = cxt5047_mixers;
1497 spec->num_init_verbs = 1;
1498 spec->init_verbs[0] = cxt5047_init_verbs;
1499 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001500 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1501 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001502
1503 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001504
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001505 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1506 cxt5047_models,
1507 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001508 switch (board_config) {
1509 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001510 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001511 break;
1512 case CXT5047_LAPTOP_HP:
1513 spec->input_mux = &cxt5047_hp_capture_source;
1514 spec->num_init_verbs = 2;
1515 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1516 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001517 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001518 codec->patch_ops.init = cxt5047_hp_init;
1519 break;
1520 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001521 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001522 spec->num_init_verbs = 2;
1523 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001524 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001525 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001526 break;
1527#ifdef CONFIG_SND_DEBUG
1528 case CXT5047_TEST:
1529 spec->input_mux = &cxt5047_test_capture_source;
1530 spec->mixers[0] = cxt5047_test_mixer;
1531 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001532 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001533#endif
1534 }
1535 return 0;
1536}
1537
Takashi Iwai461e2c72008-01-25 11:35:17 +01001538/* Conexant 5051 specific */
1539static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1540static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1541#define CXT5051_SPDIF_OUT 0x1C
1542#define CXT5051_PORTB_EVENT 0x38
1543#define CXT5051_PORTC_EVENT 0x39
1544
1545static struct hda_channel_mode cxt5051_modes[1] = {
1546 { 2, NULL },
1547};
1548
1549static void cxt5051_update_speaker(struct hda_codec *codec)
1550{
1551 struct conexant_spec *spec = codec->spec;
1552 unsigned int pinctl;
1553 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1554 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1555 pinctl);
1556}
1557
1558/* turn on/off EAPD (+ mute HP) as a master switch */
1559static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1560 struct snd_ctl_elem_value *ucontrol)
1561{
1562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1563
1564 if (!cxt_eapd_put(kcontrol, ucontrol))
1565 return 0;
1566 cxt5051_update_speaker(codec);
1567 return 1;
1568}
1569
1570/* toggle input of built-in and mic jack appropriately */
1571static void cxt5051_portb_automic(struct hda_codec *codec)
1572{
1573 unsigned int present;
1574
1575 present = snd_hda_codec_read(codec, 0x17, 0,
1576 AC_VERB_GET_PIN_SENSE, 0) &
1577 AC_PINSENSE_PRESENCE;
1578 snd_hda_codec_write(codec, 0x14, 0,
1579 AC_VERB_SET_CONNECT_SEL,
1580 present ? 0x01 : 0x00);
1581}
1582
1583/* switch the current ADC according to the jack state */
1584static void cxt5051_portc_automic(struct hda_codec *codec)
1585{
1586 struct conexant_spec *spec = codec->spec;
1587 unsigned int present;
1588 hda_nid_t new_adc;
1589
1590 present = snd_hda_codec_read(codec, 0x18, 0,
1591 AC_VERB_GET_PIN_SENSE, 0) &
1592 AC_PINSENSE_PRESENCE;
1593 if (present)
1594 spec->cur_adc_idx = 1;
1595 else
1596 spec->cur_adc_idx = 0;
1597 new_adc = spec->adc_nids[spec->cur_adc_idx];
1598 if (spec->cur_adc && spec->cur_adc != new_adc) {
1599 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001600 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001601 spec->cur_adc = new_adc;
1602 snd_hda_codec_setup_stream(codec, new_adc,
1603 spec->cur_adc_stream_tag, 0,
1604 spec->cur_adc_format);
1605 }
1606}
1607
1608/* mute internal speaker if HP is plugged */
1609static void cxt5051_hp_automute(struct hda_codec *codec)
1610{
1611 struct conexant_spec *spec = codec->spec;
1612
1613 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1614 AC_VERB_GET_PIN_SENSE, 0) &
1615 AC_PINSENSE_PRESENCE;
1616 cxt5051_update_speaker(codec);
1617}
1618
1619/* unsolicited event for HP jack sensing */
1620static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1621 unsigned int res)
1622{
1623 switch (res >> 26) {
1624 case CONEXANT_HP_EVENT:
1625 cxt5051_hp_automute(codec);
1626 break;
1627 case CXT5051_PORTB_EVENT:
1628 cxt5051_portb_automic(codec);
1629 break;
1630 case CXT5051_PORTC_EVENT:
1631 cxt5051_portc_automic(codec);
1632 break;
1633 }
1634}
1635
1636static struct snd_kcontrol_new cxt5051_mixers[] = {
1637 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1638 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1639 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1640 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1641 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1642 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1643 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1644 {
1645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1646 .name = "Master Playback Switch",
1647 .info = cxt_eapd_info,
1648 .get = cxt_eapd_get,
1649 .put = cxt5051_hp_master_sw_put,
1650 .private_value = 0x1a,
1651 },
1652
1653 {}
1654};
1655
1656static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1657 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1658 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1659 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1660 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1661 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1662 {
1663 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1664 .name = "Master Playback Switch",
1665 .info = cxt_eapd_info,
1666 .get = cxt_eapd_get,
1667 .put = cxt5051_hp_master_sw_put,
1668 .private_value = 0x1a,
1669 },
1670
1671 {}
1672};
1673
1674static struct hda_verb cxt5051_init_verbs[] = {
1675 /* Line in, Mic */
1676 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1677 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1678 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1679 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1680 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1681 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1682 /* SPK */
1683 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1684 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1685 /* HP, Amp */
1686 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1687 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1688 /* DAC1 */
1689 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1690 /* Record selector: Int mic */
1691 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1692 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1693 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1694 /* SPDIF route: PCM */
1695 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1696 /* EAPD */
1697 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1698 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1699 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1700 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1701 { } /* end */
1702};
1703
1704/* initialize jack-sensing, too */
1705static int cxt5051_init(struct hda_codec *codec)
1706{
1707 conexant_init(codec);
1708 if (codec->patch_ops.unsol_event) {
1709 cxt5051_hp_automute(codec);
1710 cxt5051_portb_automic(codec);
1711 cxt5051_portc_automic(codec);
1712 }
1713 return 0;
1714}
1715
1716
1717enum {
1718 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1719 CXT5051_HP, /* no docking */
1720 CXT5051_MODELS
1721};
1722
1723static const char *cxt5051_models[CXT5051_MODELS] = {
1724 [CXT5051_LAPTOP] = "laptop",
1725 [CXT5051_HP] = "hp",
1726};
1727
1728static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1729 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1730 CXT5051_LAPTOP),
1731 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1732 {}
1733};
1734
1735static int patch_cxt5051(struct hda_codec *codec)
1736{
1737 struct conexant_spec *spec;
1738 int board_config;
1739
1740 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1741 if (!spec)
1742 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001743 codec->spec = spec;
1744
1745 codec->patch_ops = conexant_patch_ops;
1746 codec->patch_ops.init = cxt5051_init;
1747
1748 spec->multiout.max_channels = 2;
1749 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1750 spec->multiout.dac_nids = cxt5051_dac_nids;
1751 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1752 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1753 spec->adc_nids = cxt5051_adc_nids;
1754 spec->num_mixers = 1;
1755 spec->mixers[0] = cxt5051_mixers;
1756 spec->num_init_verbs = 1;
1757 spec->init_verbs[0] = cxt5051_init_verbs;
1758 spec->spdif_route = 0;
1759 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1760 spec->channel_mode = cxt5051_modes;
1761 spec->cur_adc = 0;
1762 spec->cur_adc_idx = 0;
1763
1764 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1765 cxt5051_models,
1766 cxt5051_cfg_tbl);
1767 switch (board_config) {
1768 case CXT5051_HP:
1769 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1770 spec->mixers[0] = cxt5051_hp_mixers;
1771 break;
1772 default:
1773 case CXT5051_LAPTOP:
1774 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1775 break;
1776 }
1777
1778 return 0;
1779}
1780
1781
1782/*
1783 */
1784
Tobin Davisc9b443d2006-11-14 12:13:39 +01001785struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001786 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1787 .patch = patch_cxt5045 },
1788 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1789 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001790 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1791 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001792 {} /* terminator */
1793};