blob: 6aa073986747bd20a26c0c7a4e1e154a173e5c39 [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
23#include <sound/driver.h>
24#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27#include <linux/pci.h>
28#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
31
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
68 /* capture source */
69 const struct hda_input_mux *input_mux;
70 hda_nid_t *capsrc_nids;
71 unsigned int cur_mux[3];
72
73 /* channel model */
74 const struct hda_channel_mode *channel_mode;
75 int num_channel_mode;
76
77 /* PCM information */
78 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
79
80 struct mutex amp_mutex; /* PCM volume/mute control mutex */
81 unsigned int spdif_route;
82
83 /* dynamic controls, init_verbs and input_mux */
84 struct auto_pin_cfg autocfg;
85 unsigned int num_kctl_alloc, num_kctl_used;
86 struct snd_kcontrol_new *kctl_alloc;
87 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020088 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +010089
90};
91
92static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
93 struct hda_codec *codec,
94 struct snd_pcm_substream *substream)
95{
96 struct conexant_spec *spec = codec->spec;
97 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
98}
99
100static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
101 struct hda_codec *codec,
102 unsigned int stream_tag,
103 unsigned int format,
104 struct snd_pcm_substream *substream)
105{
106 struct conexant_spec *spec = codec->spec;
107 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
108 stream_tag,
109 format, substream);
110}
111
112static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
113 struct hda_codec *codec,
114 struct snd_pcm_substream *substream)
115{
116 struct conexant_spec *spec = codec->spec;
117 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
118}
119
120/*
121 * Digital out
122 */
123static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
124 struct hda_codec *codec,
125 struct snd_pcm_substream *substream)
126{
127 struct conexant_spec *spec = codec->spec;
128 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
129}
130
131static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
132 struct hda_codec *codec,
133 struct snd_pcm_substream *substream)
134{
135 struct conexant_spec *spec = codec->spec;
136 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
137}
138
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200139static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
140 struct hda_codec *codec,
141 unsigned int stream_tag,
142 unsigned int format,
143 struct snd_pcm_substream *substream)
144{
145 struct conexant_spec *spec = codec->spec;
146 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
147 stream_tag,
148 format, substream);
149}
150
Tobin Davisc9b443d2006-11-14 12:13:39 +0100151/*
152 * Analog capture
153 */
154static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
155 struct hda_codec *codec,
156 unsigned int stream_tag,
157 unsigned int format,
158 struct snd_pcm_substream *substream)
159{
160 struct conexant_spec *spec = codec->spec;
161 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
162 stream_tag, 0, format);
163 return 0;
164}
165
166static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
167 struct hda_codec *codec,
168 struct snd_pcm_substream *substream)
169{
170 struct conexant_spec *spec = codec->spec;
171 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
172 0, 0, 0);
173 return 0;
174}
175
176
177
178static struct hda_pcm_stream conexant_pcm_analog_playback = {
179 .substreams = 1,
180 .channels_min = 2,
181 .channels_max = 2,
182 .nid = 0, /* fill later */
183 .ops = {
184 .open = conexant_playback_pcm_open,
185 .prepare = conexant_playback_pcm_prepare,
186 .cleanup = conexant_playback_pcm_cleanup
187 },
188};
189
190static struct hda_pcm_stream conexant_pcm_analog_capture = {
191 .substreams = 1,
192 .channels_min = 2,
193 .channels_max = 2,
194 .nid = 0, /* fill later */
195 .ops = {
196 .prepare = conexant_capture_pcm_prepare,
197 .cleanup = conexant_capture_pcm_cleanup
198 },
199};
200
201
202static struct hda_pcm_stream conexant_pcm_digital_playback = {
203 .substreams = 1,
204 .channels_min = 2,
205 .channels_max = 2,
206 .nid = 0, /* fill later */
207 .ops = {
208 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200209 .close = conexant_dig_playback_pcm_close,
210 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100211 },
212};
213
214static struct hda_pcm_stream conexant_pcm_digital_capture = {
215 .substreams = 1,
216 .channels_min = 2,
217 .channels_max = 2,
218 /* NID is set in alc_build_pcms */
219};
220
221static int conexant_build_pcms(struct hda_codec *codec)
222{
223 struct conexant_spec *spec = codec->spec;
224 struct hda_pcm *info = spec->pcm_rec;
225
226 codec->num_pcms = 1;
227 codec->pcm_info = info;
228
229 info->name = "CONEXANT Analog";
230 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
231 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
232 spec->multiout.max_channels;
233 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
234 spec->multiout.dac_nids[0];
235 info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
236 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
237 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
238
239 if (spec->multiout.dig_out_nid) {
240 info++;
241 codec->num_pcms++;
242 info->name = "Conexant Digital";
243 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
244 conexant_pcm_digital_playback;
245 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
246 spec->multiout.dig_out_nid;
247 if (spec->dig_in_nid) {
248 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
249 conexant_pcm_digital_capture;
250 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
251 spec->dig_in_nid;
252 }
253 }
254
255 return 0;
256}
257
258static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
259 struct snd_ctl_elem_info *uinfo)
260{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct conexant_spec *spec = codec->spec;
263
264 return snd_hda_input_mux_info(spec->input_mux, uinfo);
265}
266
267static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
268 struct snd_ctl_elem_value *ucontrol)
269{
270 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
271 struct conexant_spec *spec = codec->spec;
272 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
273
274 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
275 return 0;
276}
277
278static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
279 struct snd_ctl_elem_value *ucontrol)
280{
281 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
282 struct conexant_spec *spec = codec->spec;
283 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
284
285 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
286 spec->capsrc_nids[adc_idx],
287 &spec->cur_mux[adc_idx]);
288}
289
290static int conexant_init(struct hda_codec *codec)
291{
292 struct conexant_spec *spec = codec->spec;
293 int i;
294
295 for (i = 0; i < spec->num_init_verbs; i++)
296 snd_hda_sequence_write(codec, spec->init_verbs[i]);
297 return 0;
298}
299
300static void conexant_free(struct hda_codec *codec)
301{
302 struct conexant_spec *spec = codec->spec;
303 unsigned int i;
304
305 if (spec->kctl_alloc) {
306 for (i = 0; i < spec->num_kctl_used; i++)
307 kfree(spec->kctl_alloc[i].name);
308 kfree(spec->kctl_alloc);
309 }
310
311 kfree(codec->spec);
312}
313
Tobin Davisc9b443d2006-11-14 12:13:39 +0100314static int conexant_build_controls(struct hda_codec *codec)
315{
316 struct conexant_spec *spec = codec->spec;
317 unsigned int i;
318 int err;
319
320 for (i = 0; i < spec->num_mixers; i++) {
321 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
322 if (err < 0)
323 return err;
324 }
325 if (spec->multiout.dig_out_nid) {
326 err = snd_hda_create_spdif_out_ctls(codec,
327 spec->multiout.dig_out_nid);
328 if (err < 0)
329 return err;
330 }
331 if (spec->dig_in_nid) {
332 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
333 if (err < 0)
334 return err;
335 }
336 return 0;
337}
338
339static struct hda_codec_ops conexant_patch_ops = {
340 .build_controls = conexant_build_controls,
341 .build_pcms = conexant_build_pcms,
342 .init = conexant_init,
343 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100344};
345
346/*
347 * EAPD control
348 * the private value = nid | (invert << 8)
349 */
350
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200351#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100352
Tobin Davis82f30042007-02-13 12:45:44 +0100353static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100354 struct snd_ctl_elem_value *ucontrol)
355{
356 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357 struct conexant_spec *spec = codec->spec;
358 int invert = (kcontrol->private_value >> 8) & 1;
359 if (invert)
360 ucontrol->value.integer.value[0] = !spec->cur_eapd;
361 else
362 ucontrol->value.integer.value[0] = spec->cur_eapd;
363 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100364
Tobin Davisc9b443d2006-11-14 12:13:39 +0100365}
366
Tobin Davis82f30042007-02-13 12:45:44 +0100367static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100368 struct snd_ctl_elem_value *ucontrol)
369{
370 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
371 struct conexant_spec *spec = codec->spec;
372 int invert = (kcontrol->private_value >> 8) & 1;
373 hda_nid_t nid = kcontrol->private_value & 0xff;
374 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100375
Tobin Davisc9b443d2006-11-14 12:13:39 +0100376 eapd = ucontrol->value.integer.value[0];
377 if (invert)
378 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200379 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100380 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100381
Tobin Davisc9b443d2006-11-14 12:13:39 +0100382 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200383 snd_hda_codec_write_cache(codec, nid,
384 0, AC_VERB_SET_EAPD_BTLENABLE,
385 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100386 return 1;
387}
388
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100389/* controls for test mode */
390#ifdef CONFIG_SND_DEBUG
391
Tobin Davis82f30042007-02-13 12:45:44 +0100392#define CXT_EAPD_SWITCH(xname, nid, mask) \
393 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
394 .info = cxt_eapd_info, \
395 .get = cxt_eapd_get, \
396 .put = cxt_eapd_put, \
397 .private_value = nid | (mask<<16) }
398
399
400
Tobin Davisc9b443d2006-11-14 12:13:39 +0100401static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
402 struct snd_ctl_elem_info *uinfo)
403{
404 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
405 struct conexant_spec *spec = codec->spec;
406 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
407 spec->num_channel_mode);
408}
409
410static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
411 struct snd_ctl_elem_value *ucontrol)
412{
413 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
414 struct conexant_spec *spec = codec->spec;
415 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
416 spec->num_channel_mode,
417 spec->multiout.max_channels);
418}
419
420static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_value *ucontrol)
422{
423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424 struct conexant_spec *spec = codec->spec;
425 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
426 spec->num_channel_mode,
427 &spec->multiout.max_channels);
428 if (err >= 0 && spec->need_dac_fix)
429 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
430 return err;
431}
432
433#define CXT_PIN_MODE(xname, nid, dir) \
434 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
435 .info = conexant_ch_mode_info, \
436 .get = conexant_ch_mode_get, \
437 .put = conexant_ch_mode_put, \
438 .private_value = nid | (dir<<16) }
439
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100440#endif /* CONFIG_SND_DEBUG */
441
Tobin Davisc9b443d2006-11-14 12:13:39 +0100442/* Conexant 5045 specific */
443
444static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
445static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
446static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
447#define CXT5045_SPDIF_OUT 0x13
448
Tobin Davis5cd57522006-11-20 17:42:09 +0100449static struct hda_channel_mode cxt5045_modes[1] = {
450 { 2, NULL },
451};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100452
453static struct hda_input_mux cxt5045_capture_source = {
454 .num_items = 2,
455 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100456 { "IntMic", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100457 { "LineIn", 0x2 },
458 }
459};
460
461/* turn on/off EAPD (+ mute HP) as a master switch */
462static int cxt5045_hp_master_sw_put(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;
Tobin Davis82f30042007-02-13 12:45:44 +0100467 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100468
Tobin Davis82f30042007-02-13 12:45:44 +0100469 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100470 return 0;
471
Tobin Davis82f30042007-02-13 12:45:44 +0100472 /* toggle internal speakers mute depending of presence of
473 * the headphone jack
474 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200475 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
476 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
477 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100478
Takashi Iwai47fd8302007-08-10 17:11:07 +0200479 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
480 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
481 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100482 return 1;
483}
484
485/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200486static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
487 .ops = &snd_hda_bind_vol,
488 .values = {
489 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
490 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
491 0
492 },
493};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100494
Tobin Davis7f296732007-03-12 11:39:01 +0100495/* toggle input of built-in and mic jack appropriately */
496static void cxt5045_hp_automic(struct hda_codec *codec)
497{
498 static struct hda_verb mic_jack_on[] = {
499 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
500 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
501 {}
502 };
503 static struct hda_verb mic_jack_off[] = {
504 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
505 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
506 {}
507 };
508 unsigned int present;
509
510 present = snd_hda_codec_read(codec, 0x12, 0,
511 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
512 if (present)
513 snd_hda_sequence_write(codec, mic_jack_on);
514 else
515 snd_hda_sequence_write(codec, mic_jack_off);
516}
517
Tobin Davisc9b443d2006-11-14 12:13:39 +0100518
519/* mute internal speaker if HP is plugged */
520static void cxt5045_hp_automute(struct hda_codec *codec)
521{
Tobin Davis82f30042007-02-13 12:45:44 +0100522 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100523 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100524
Tobin Davis82f30042007-02-13 12:45:44 +0100525 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100526 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100527
Takashi Iwai47fd8302007-08-10 17:11:07 +0200528 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
529 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
530 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100531}
532
533/* unsolicited event for HP jack sensing */
534static void cxt5045_hp_unsol_event(struct hda_codec *codec,
535 unsigned int res)
536{
537 res >>= 26;
538 switch (res) {
539 case CONEXANT_HP_EVENT:
540 cxt5045_hp_automute(codec);
541 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100542 case CONEXANT_MIC_EVENT:
543 cxt5045_hp_automic(codec);
544 break;
545
Tobin Davisc9b443d2006-11-14 12:13:39 +0100546 }
547}
548
549static struct snd_kcontrol_new cxt5045_mixers[] = {
550 {
551 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
552 .name = "Capture Source",
553 .info = conexant_mux_enum_info,
554 .get = conexant_mux_enum_get,
555 .put = conexant_mux_enum_put
556 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200557 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
558 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
559 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
560 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
561 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
562 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
563 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
564 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
565 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
566 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200567 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100568 {
569 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
570 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100571 .info = cxt_eapd_info,
572 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100573 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100574 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100575 },
576
577 {}
578};
579
580static struct hda_verb cxt5045_init_verbs[] = {
581 /* Line in, Mic */
582 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Tobin Davis7f296732007-03-12 11:39:01 +0100583 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100584 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200585 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
586 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
587 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
588 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
589 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
590 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
591 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
592 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
593 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100594 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100595 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100596 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100597 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
598 /* SPDIF route: PCM */
599 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100600 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100601 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100602 { } /* end */
603};
604
Tobin Davis7f296732007-03-12 11:39:01 +0100605
606static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
607 /* pin sensing on HP jack */
608 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200609 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100610};
611
612static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
613 /* pin sensing on HP jack */
614 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200615 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100616};
617
Tobin Davisc9b443d2006-11-14 12:13:39 +0100618#ifdef CONFIG_SND_DEBUG
619/* Test configuration for debugging, modelled after the ALC260 test
620 * configuration.
621 */
622static struct hda_input_mux cxt5045_test_capture_source = {
623 .num_items = 5,
624 .items = {
625 { "MIXER", 0x0 },
626 { "MIC1 pin", 0x1 },
627 { "LINE1 pin", 0x2 },
628 { "HP-OUT pin", 0x3 },
629 { "CD pin", 0x4 },
630 },
631};
632
633static struct snd_kcontrol_new cxt5045_test_mixer[] = {
634
635 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100636 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
637 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100638 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
639 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
640 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
641 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100642
643 /* Modes for retasking pin widgets */
644 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
645 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
646
Tobin Davis82f30042007-02-13 12:45:44 +0100647 /* EAPD Switch Control */
648 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
649
Tobin Davisc9b443d2006-11-14 12:13:39 +0100650 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100651
Tobin Davis7f296732007-03-12 11:39:01 +0100652 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
653 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
654 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
655 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
656 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
657 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
658 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
659 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
660 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
661 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100662 {
663 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
664 .name = "Input Source",
665 .info = conexant_mux_enum_info,
666 .get = conexant_mux_enum_get,
667 .put = conexant_mux_enum_put,
668 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200669 /* Audio input controls */
670 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
671 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
672 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
673 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
674 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
675 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
676 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
677 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
678 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
679 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100680 { } /* end */
681};
682
683static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100684 /* Set connections */
685 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
686 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
687 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100688 /* Enable retasking pins as output, initially without power amp */
689 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100690 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691
692 /* Disable digital (SPDIF) pins initially, but users can enable
693 * them via a mixer switch. In the case of SPDIF-out, this initverb
694 * payload also sets the generation to 0, output to be in "consumer"
695 * PCM format, copyright asserted, no pre-emphasis and no validity
696 * control.
697 */
698 {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
699
700 /* Start with output sum widgets muted and their output gains at min */
701 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
702 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
703
704 /* Unmute retasking pin widget output buffers since the default
705 * state appears to be output. As the pin mode is changed by the
706 * user the pin mode control will take care of enabling the pin's
707 * input/output buffers as needed.
708 */
709 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
710 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
711
712 /* Mute capture amp left and right */
713 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
714
715 /* Set ADC connection select to match default mixer setting (mic1
716 * pin)
717 */
718 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100719 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100720
721 /* Mute all inputs to mixer widget (even unconnected ones) */
722 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
723 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
724 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
726 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
727
728 { }
729};
730#endif
731
732
733/* initialize jack-sensing, too */
734static int cxt5045_init(struct hda_codec *codec)
735{
736 conexant_init(codec);
737 cxt5045_hp_automute(codec);
738 return 0;
739}
740
741
742enum {
Tobin Davis7f296732007-03-12 11:39:01 +0100743 CXT5045_LAPTOP, /* Laptops w/ EAPD support */
744 CXT5045_FUJITSU, /* Laptops w/ EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100745#ifdef CONFIG_SND_DEBUG
746 CXT5045_TEST,
747#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100748 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100749};
750
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100751static const char *cxt5045_models[CXT5045_MODELS] = {
752 [CXT5045_LAPTOP] = "laptop",
Tobin Davis7f296732007-03-12 11:39:01 +0100753 [CXT5045_FUJITSU] = "fujitsu",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100754#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100755 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100756#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100757};
758
759static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
760 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +0100761 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
Tobin Davis4d69d752007-05-03 12:17:11 +0200762 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP),
763 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP),
764 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP),
Claudio Matsuoka8481da52007-07-03 20:05:19 +0200765 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP),
Tobin Davis7f296732007-03-12 11:39:01 +0100766 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU),
Tobin Davisf8f794a2007-06-25 12:14:25 +0200767 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP),
Tobin Davis7f296732007-03-12 11:39:01 +0100768 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769 {}
770};
771
772static int patch_cxt5045(struct hda_codec *codec)
773{
774 struct conexant_spec *spec;
775 int board_config;
776
777 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
778 if (!spec)
779 return -ENOMEM;
780 mutex_init(&spec->amp_mutex);
781 codec->spec = spec;
782
783 spec->multiout.max_channels = 2;
784 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
785 spec->multiout.dac_nids = cxt5045_dac_nids;
786 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
787 spec->num_adc_nids = 1;
788 spec->adc_nids = cxt5045_adc_nids;
789 spec->capsrc_nids = cxt5045_capsrc_nids;
790 spec->input_mux = &cxt5045_capture_source;
791 spec->num_mixers = 1;
792 spec->mixers[0] = cxt5045_mixers;
793 spec->num_init_verbs = 1;
794 spec->init_verbs[0] = cxt5045_init_verbs;
795 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100796 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
797 spec->channel_mode = cxt5045_modes,
798
Tobin Davisc9b443d2006-11-14 12:13:39 +0100799
800 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100801
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100802 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
803 cxt5045_models,
804 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100805 switch (board_config) {
806 case CXT5045_LAPTOP:
Tobin Davis7f296732007-03-12 11:39:01 +0100807 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100808 spec->input_mux = &cxt5045_capture_source;
809 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100810 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
811 spec->mixers[0] = cxt5045_mixers;
812 codec->patch_ops.init = cxt5045_init;
813 break;
814 case CXT5045_FUJITSU:
815 spec->input_mux = &cxt5045_capture_source;
816 spec->num_init_verbs = 2;
817 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 spec->mixers[0] = cxt5045_mixers;
819 codec->patch_ops.init = cxt5045_init;
820 break;
821#ifdef CONFIG_SND_DEBUG
822 case CXT5045_TEST:
823 spec->input_mux = &cxt5045_test_capture_source;
824 spec->mixers[0] = cxt5045_test_mixer;
825 spec->init_verbs[0] = cxt5045_test_init_verbs;
826#endif
827 }
828 return 0;
829}
830
831
832/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100833#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100834
Tobin Davis82f30042007-02-13 12:45:44 +0100835static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100836static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
837static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100838
Tobin Davis5cd57522006-11-20 17:42:09 +0100839static struct hda_channel_mode cxt5047_modes[1] = {
840 { 2, NULL },
841};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100842
843static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +0100844 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100845 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +0100846 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100847 }
848};
849
850static struct hda_input_mux cxt5047_hp_capture_source = {
851 .num_items = 1,
852 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100853 { "ExtMic", 0x2 },
854 }
855};
856
857static struct hda_input_mux cxt5047_toshiba_capture_source = {
858 .num_items = 2,
859 .items = {
860 { "ExtMic", 0x2 },
861 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100862 }
863};
864
865/* turn on/off EAPD (+ mute HP) as a master switch */
866static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
867 struct snd_ctl_elem_value *ucontrol)
868{
869 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
870 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100871 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100872
Tobin Davis82f30042007-02-13 12:45:44 +0100873 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100874 return 0;
875
Tobin Davis82f30042007-02-13 12:45:44 +0100876 /* toggle internal speakers mute depending of presence of
877 * the headphone jack
878 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200879 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
880 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
881 HDA_AMP_MUTE, bits);
882 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
883 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
884 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100885 return 1;
886}
887
Tobin Davis82f30042007-02-13 12:45:44 +0100888/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200889static struct hda_bind_ctls cxt5047_bind_master_vol = {
890 .ops = &snd_hda_bind_vol,
891 .values = {
892 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
893 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
894 0
895 },
896};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100897
898/* mute internal speaker if HP is plugged */
899static void cxt5047_hp_automute(struct hda_codec *codec)
900{
Tobin Davis82f30042007-02-13 12:45:44 +0100901 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100902 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100903
Tobin Davis82f30042007-02-13 12:45:44 +0100904 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100905 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100906
Takashi Iwai47fd8302007-08-10 17:11:07 +0200907 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
908 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
909 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +0100910 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200911 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
912 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100913}
914
Tobin Davisfb3409e2007-05-17 09:40:47 +0200915/* mute internal speaker if HP is plugged */
916static void cxt5047_hp2_automute(struct hda_codec *codec)
917{
918 struct conexant_spec *spec = codec->spec;
919 unsigned int bits;
920
921 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
922 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
923
Takashi Iwai47fd8302007-08-10 17:11:07 +0200924 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
925 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
926 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +0200927 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200928 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
929 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +0200930}
931
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932/* toggle input of built-in and mic jack appropriately */
933static void cxt5047_hp_automic(struct hda_codec *codec)
934{
935 static struct hda_verb mic_jack_on[] = {
936 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
937 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
938 {}
939 };
940 static struct hda_verb mic_jack_off[] = {
941 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
942 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
943 {}
944 };
945 unsigned int present;
946
Tobin Davis7f296732007-03-12 11:39:01 +0100947 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100948 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
949 if (present)
950 snd_hda_sequence_write(codec, mic_jack_on);
951 else
952 snd_hda_sequence_write(codec, mic_jack_off);
953}
954
955/* unsolicited event for HP jack sensing */
956static void cxt5047_hp_unsol_event(struct hda_codec *codec,
957 unsigned int res)
958{
959 res >>= 26;
960 switch (res) {
961 case CONEXANT_HP_EVENT:
962 cxt5047_hp_automute(codec);
963 break;
964 case CONEXANT_MIC_EVENT:
965 cxt5047_hp_automic(codec);
966 break;
967 }
968}
969
Tobin Davisfb3409e2007-05-17 09:40:47 +0200970/* unsolicited event for HP jack sensing - non-EAPD systems */
971static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
972 unsigned int res)
973{
974 res >>= 26;
975 switch (res) {
976 case CONEXANT_HP_EVENT:
977 cxt5047_hp2_automute(codec);
978 break;
979 case CONEXANT_MIC_EVENT:
980 cxt5047_hp_automic(codec);
981 break;
982 }
983}
984
Tobin Davisc9b443d2006-11-14 12:13:39 +0100985static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100986 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
987 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100988 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
989 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
991 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
992 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
993 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +0100994 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
995 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +0200996 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
997 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
998 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
999 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001000
1001 {}
1002};
1003
1004static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1005 {
1006 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1007 .name = "Capture Source",
1008 .info = conexant_mux_enum_info,
1009 .get = conexant_mux_enum_get,
1010 .put = conexant_mux_enum_put
1011 },
1012 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1013 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1014 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1015 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1016 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1017 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001018 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001019 {
1020 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1021 .name = "Master Playback Switch",
1022 .info = cxt_eapd_info,
1023 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001024 .put = cxt5047_hp_master_sw_put,
1025 .private_value = 0x13,
1026 },
1027
1028 {}
1029};
1030
1031static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1032 {
1033 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1034 .name = "Capture Source",
1035 .info = conexant_mux_enum_info,
1036 .get = conexant_mux_enum_get,
1037 .put = conexant_mux_enum_put
1038 },
1039 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1040 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1041 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1042 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1043 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1044 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1045 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1046 {
1047 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1048 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001049 .info = cxt_eapd_info,
1050 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001051 .put = cxt5047_hp_master_sw_put,
1052 .private_value = 0x13,
1053 },
1054 { } /* end */
1055};
1056
1057static struct hda_verb cxt5047_init_verbs[] = {
1058 /* Line in, Mic, Built-in Mic */
1059 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1060 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1061 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001062 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001063 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1064 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001065 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1066 /* Record selector: Mic */
1067 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1068 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1069 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1070 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001071 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1072 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1073 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1074 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075 /* SPDIF route: PCM */
1076 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001077 /* Enable unsolicited events */
1078 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1079 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001080 { } /* end */
1081};
1082
1083/* configuration for Toshiba Laptops */
1084static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1085 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1086 /* pin sensing on HP and Mic jacks */
1087 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1088 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001089 /* Speaker routing */
1090 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001091 {}
1092};
1093
1094/* configuration for HP Laptops */
1095static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001096 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001097 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001098 /* Record selector: Ext Mic */
1099 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001100 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1101 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1102 /* Speaker routing */
1103 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001104 {}
1105};
1106
1107/* Test configuration for debugging, modelled after the ALC260 test
1108 * configuration.
1109 */
1110#ifdef CONFIG_SND_DEBUG
1111static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001112 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001114 { "LINE1 pin", 0x0 },
1115 { "MIC1 pin", 0x1 },
1116 { "MIC2 pin", 0x2 },
1117 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001118 },
1119};
1120
1121static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1122
1123 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001124 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1125 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1126 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1127 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001128 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1129 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1130 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1131 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001132 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1133 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1134 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1135 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136
1137 /* Modes for retasking pin widgets */
1138 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1139 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1140
Tobin Davis82f30042007-02-13 12:45:44 +01001141 /* EAPD Switch Control */
1142 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1143
Tobin Davisc9b443d2006-11-14 12:13:39 +01001144 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001145 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1146 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1147 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1148 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1149 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1150 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1151 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1152 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001153
Tobin Davis82f30042007-02-13 12:45:44 +01001154 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1155 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1156 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1157 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1158 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1159 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1160 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1161 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001162 {
1163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1164 .name = "Input Source",
1165 .info = conexant_mux_enum_info,
1166 .get = conexant_mux_enum_get,
1167 .put = conexant_mux_enum_put,
1168 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001169 { } /* end */
1170};
1171
1172static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001173 /* Enable retasking pins as output, initially without power amp */
1174 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1175 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1176 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1177
1178 /* Disable digital (SPDIF) pins initially, but users can enable
1179 * them via a mixer switch. In the case of SPDIF-out, this initverb
1180 * payload also sets the generation to 0, output to be in "consumer"
1181 * PCM format, copyright asserted, no pre-emphasis and no validity
1182 * control.
1183 */
1184 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1185
1186 /* Ensure mic1, mic2, line1 pin widgets take input from the
1187 * OUT1 sum bus when acting as an output.
1188 */
1189 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1190 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1191
1192 /* Start with output sum widgets muted and their output gains at min */
1193 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1194 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1195
1196 /* Unmute retasking pin widget output buffers since the default
1197 * state appears to be output. As the pin mode is changed by the
1198 * user the pin mode control will take care of enabling the pin's
1199 * input/output buffers as needed.
1200 */
1201 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1202 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1203 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1204
1205 /* Mute capture amp left and right */
1206 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1207
1208 /* Set ADC connection select to match default mixer setting (mic1
1209 * pin)
1210 */
1211 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1212
1213 /* Mute all inputs to mixer widget (even unconnected ones) */
1214 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1215 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1216 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1217 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1218 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1219 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1220 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1221 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1222
1223 { }
1224};
1225#endif
1226
1227
1228/* initialize jack-sensing, too */
1229static int cxt5047_hp_init(struct hda_codec *codec)
1230{
1231 conexant_init(codec);
1232 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233 return 0;
1234}
1235
1236
1237enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001238 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1239 CXT5047_LAPTOP_HP, /* Some HP laptops */
1240 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241#ifdef CONFIG_SND_DEBUG
1242 CXT5047_TEST,
1243#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001244 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245};
1246
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001247static const char *cxt5047_models[CXT5047_MODELS] = {
1248 [CXT5047_LAPTOP] = "laptop",
1249 [CXT5047_LAPTOP_HP] = "laptop-hp",
1250 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001251#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001252 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001254};
1255
1256static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1257 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1258 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001259 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001260 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1261 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 {}
1263};
1264
1265static int patch_cxt5047(struct hda_codec *codec)
1266{
1267 struct conexant_spec *spec;
1268 int board_config;
1269
1270 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1271 if (!spec)
1272 return -ENOMEM;
1273 mutex_init(&spec->amp_mutex);
1274 codec->spec = spec;
1275
1276 spec->multiout.max_channels = 2;
1277 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1278 spec->multiout.dac_nids = cxt5047_dac_nids;
1279 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1280 spec->num_adc_nids = 1;
1281 spec->adc_nids = cxt5047_adc_nids;
1282 spec->capsrc_nids = cxt5047_capsrc_nids;
1283 spec->input_mux = &cxt5047_capture_source;
1284 spec->num_mixers = 1;
1285 spec->mixers[0] = cxt5047_mixers;
1286 spec->num_init_verbs = 1;
1287 spec->init_verbs[0] = cxt5047_init_verbs;
1288 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001289 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1290 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291
1292 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001293
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001294 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1295 cxt5047_models,
1296 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297 switch (board_config) {
1298 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001299 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 break;
1301 case CXT5047_LAPTOP_HP:
1302 spec->input_mux = &cxt5047_hp_capture_source;
1303 spec->num_init_verbs = 2;
1304 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1305 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001306 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001307 codec->patch_ops.init = cxt5047_hp_init;
1308 break;
1309 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001310 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001311 spec->num_init_verbs = 2;
1312 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001313 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001314 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315 break;
1316#ifdef CONFIG_SND_DEBUG
1317 case CXT5047_TEST:
1318 spec->input_mux = &cxt5047_test_capture_source;
1319 spec->mixers[0] = cxt5047_test_mixer;
1320 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001321 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001322#endif
1323 }
1324 return 0;
1325}
1326
1327struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001328 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1329 .patch = patch_cxt5045 },
1330 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1331 .patch = patch_cxt5047 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332 {} /* terminator */
1333};