Commit | Line | Data |
---|---|---|
c9b443d4 TD |
1 | /* |
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 | ||
43 | struct 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; | |
82f30040 | 60 | unsigned int hp_present; |
c9b443d4 TD |
61 | 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; | |
88 | hda_nid_t private_dac_nids[4]; | |
89 | ||
90 | }; | |
91 | ||
92 | static 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 | ||
100 | static 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 | ||
112 | static 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 | */ | |
123 | static 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 | ||
131 | static 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 | ||
6b97eb45 TI |
139 | static 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 | ||
c9b443d4 TD |
151 | /* |
152 | * Analog capture | |
153 | */ | |
154 | static 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 | ||
166 | static 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 | ||
178 | static 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 | ||
190 | static 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 | ||
202 | static 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, | |
6b97eb45 TI |
209 | .close = conexant_dig_playback_pcm_close, |
210 | .prepare = conexant_dig_playback_pcm_prepare | |
c9b443d4 TD |
211 | }, |
212 | }; | |
213 | ||
214 | static 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 | ||
221 | static 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 | ||
258 | static 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 | ||
267 | static 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 | ||
278 | static 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 | ||
290 | static 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 | ||
300 | static 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 | ||
c9b443d4 TD |
314 | static 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 | ||
339 | static 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, | |
c9b443d4 TD |
344 | }; |
345 | ||
346 | /* | |
347 | * EAPD control | |
348 | * the private value = nid | (invert << 8) | |
349 | */ | |
350 | ||
a5ce8890 | 351 | #define cxt_eapd_info snd_ctl_boolean_mono_info |
c9b443d4 | 352 | |
82f30040 | 353 | static int cxt_eapd_get(struct snd_kcontrol *kcontrol, |
c9b443d4 TD |
354 | 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; | |
82f30040 | 364 | |
c9b443d4 TD |
365 | } |
366 | ||
82f30040 | 367 | static int cxt_eapd_put(struct snd_kcontrol *kcontrol, |
c9b443d4 TD |
368 | 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; | |
82f30040 | 375 | |
c9b443d4 TD |
376 | eapd = ucontrol->value.integer.value[0]; |
377 | if (invert) | |
378 | eapd = !eapd; | |
82beb8fd | 379 | if (eapd == spec->cur_eapd) |
c9b443d4 | 380 | return 0; |
82f30040 | 381 | |
c9b443d4 | 382 | spec->cur_eapd = eapd; |
82beb8fd TI |
383 | snd_hda_codec_write_cache(codec, nid, |
384 | 0, AC_VERB_SET_EAPD_BTLENABLE, | |
385 | eapd ? 0x02 : 0x00); | |
c9b443d4 TD |
386 | return 1; |
387 | } | |
388 | ||
86d72bdf TI |
389 | /* controls for test mode */ |
390 | #ifdef CONFIG_SND_DEBUG | |
391 | ||
82f30040 TD |
392 | #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 | ||
c9b443d4 TD |
401 | static 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 | ||
410 | static 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 | ||
420 | static 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 | ||
86d72bdf TI |
440 | #endif /* CONFIG_SND_DEBUG */ |
441 | ||
c9b443d4 TD |
442 | /* Conexant 5045 specific */ |
443 | ||
444 | static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; | |
445 | static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; | |
446 | static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; | |
447 | #define CXT5045_SPDIF_OUT 0x13 | |
448 | ||
5cd57529 TD |
449 | static struct hda_channel_mode cxt5045_modes[1] = { |
450 | { 2, NULL }, | |
451 | }; | |
c9b443d4 TD |
452 | |
453 | static struct hda_input_mux cxt5045_capture_source = { | |
454 | .num_items = 2, | |
455 | .items = { | |
82f30040 | 456 | { "IntMic", 0x1 }, |
c9b443d4 TD |
457 | { "LineIn", 0x2 }, |
458 | } | |
459 | }; | |
460 | ||
461 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
462 | static 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; | |
82f30040 | 467 | unsigned int bits; |
c9b443d4 | 468 | |
82f30040 | 469 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
c9b443d4 TD |
470 | return 0; |
471 | ||
82f30040 TD |
472 | /* toggle internal speakers mute depending of presence of |
473 | * the headphone jack | |
474 | */ | |
47fd830a TI |
475 | 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); | |
7f29673b | 478 | |
47fd830a TI |
479 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; |
480 | snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, | |
481 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
482 | return 1; |
483 | } | |
484 | ||
485 | /* bind volumes of both NID 0x10 and 0x11 */ | |
486 | static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol, | |
487 | struct snd_ctl_elem_value *ucontrol) | |
488 | { | |
489 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
490 | long *valp = ucontrol->value.integer.value; | |
491 | int change; | |
492 | ||
493 | change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, | |
47fd830a | 494 | HDA_AMP_VOLMASK, valp[0]); |
c9b443d4 | 495 | change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, |
47fd830a | 496 | HDA_AMP_VOLMASK, valp[1]); |
c9b443d4 | 497 | snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, |
47fd830a | 498 | HDA_AMP_VOLMASK, valp[0]); |
c9b443d4 | 499 | snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, |
47fd830a | 500 | HDA_AMP_VOLMASK, valp[1]); |
c9b443d4 TD |
501 | return change; |
502 | } | |
503 | ||
7f29673b TD |
504 | /* toggle input of built-in and mic jack appropriately */ |
505 | static void cxt5045_hp_automic(struct hda_codec *codec) | |
506 | { | |
507 | static struct hda_verb mic_jack_on[] = { | |
508 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
509 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
510 | {} | |
511 | }; | |
512 | static struct hda_verb mic_jack_off[] = { | |
513 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
514 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
515 | {} | |
516 | }; | |
517 | unsigned int present; | |
518 | ||
519 | present = snd_hda_codec_read(codec, 0x12, 0, | |
520 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
521 | if (present) | |
522 | snd_hda_sequence_write(codec, mic_jack_on); | |
523 | else | |
524 | snd_hda_sequence_write(codec, mic_jack_off); | |
525 | } | |
526 | ||
c9b443d4 TD |
527 | |
528 | /* mute internal speaker if HP is plugged */ | |
529 | static void cxt5045_hp_automute(struct hda_codec *codec) | |
530 | { | |
82f30040 | 531 | struct conexant_spec *spec = codec->spec; |
dd87da1c | 532 | unsigned int bits; |
c9b443d4 | 533 | |
82f30040 | 534 | spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, |
c9b443d4 | 535 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
dd87da1c | 536 | |
47fd830a TI |
537 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
538 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, | |
539 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
540 | } |
541 | ||
542 | /* unsolicited event for HP jack sensing */ | |
543 | static void cxt5045_hp_unsol_event(struct hda_codec *codec, | |
544 | unsigned int res) | |
545 | { | |
546 | res >>= 26; | |
547 | switch (res) { | |
548 | case CONEXANT_HP_EVENT: | |
549 | cxt5045_hp_automute(codec); | |
550 | break; | |
7f29673b TD |
551 | case CONEXANT_MIC_EVENT: |
552 | cxt5045_hp_automic(codec); | |
553 | break; | |
554 | ||
c9b443d4 TD |
555 | } |
556 | } | |
557 | ||
558 | static struct snd_kcontrol_new cxt5045_mixers[] = { | |
559 | { | |
560 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
561 | .name = "Capture Source", | |
562 | .info = conexant_mux_enum_info, | |
563 | .get = conexant_mux_enum_get, | |
564 | .put = conexant_mux_enum_put | |
565 | }, | |
7f29673b TD |
566 | HDA_CODEC_VOLUME("Int Mic Volume", 0x1a, 0x01, HDA_INPUT), |
567 | HDA_CODEC_MUTE("Int Mic Switch", 0x1a, 0x01, HDA_INPUT), | |
568 | HDA_CODEC_VOLUME("Ext Mic Volume", 0x1a, 0x02, HDA_INPUT), | |
569 | HDA_CODEC_MUTE("Ext Mic Switch", 0x1a, 0x02, HDA_INPUT), | |
c9b443d4 TD |
570 | { |
571 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
572 | .name = "Master Playback Volume", | |
573 | .info = snd_hda_mixer_amp_volume_info, | |
574 | .get = snd_hda_mixer_amp_volume_get, | |
575 | .put = cxt5045_hp_master_vol_put, | |
82f30040 | 576 | .private_value = HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), |
c9b443d4 TD |
577 | }, |
578 | { | |
579 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
580 | .name = "Master Playback Switch", | |
82f30040 TD |
581 | .info = cxt_eapd_info, |
582 | .get = cxt_eapd_get, | |
c9b443d4 | 583 | .put = cxt5045_hp_master_sw_put, |
82f30040 | 584 | .private_value = 0x10, |
c9b443d4 TD |
585 | }, |
586 | ||
587 | {} | |
588 | }; | |
589 | ||
590 | static struct hda_verb cxt5045_init_verbs[] = { | |
591 | /* Line in, Mic */ | |
592 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
7f29673b | 593 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
c9b443d4 | 594 | /* HP, Amp */ |
82f30040 TD |
595 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
596 | {0x17, AC_VERB_SET_CONNECT_SEL,0x01}, | |
597 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, | |
598 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x01}, | |
599 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, | |
600 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x02}, | |
601 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, | |
c9b443d4 | 602 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, |
c9b443d4 | 603 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, |
82f30040 TD |
604 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x04}, |
605 | /* Record selector: Int mic */ | |
7f29673b | 606 | {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, |
82f30040 | 607 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, |
c9b443d4 TD |
608 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
609 | /* SPDIF route: PCM */ | |
610 | { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
c9b443d4 | 611 | /* EAPD */ |
82f30040 | 612 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ |
c9b443d4 TD |
613 | { } /* end */ |
614 | }; | |
615 | ||
7f29673b TD |
616 | |
617 | static struct hda_verb cxt5045_hp_sense_init_verbs[] = { | |
618 | /* pin sensing on HP jack */ | |
619 | {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
d3091fad | 620 | { } /* end */ |
7f29673b TD |
621 | }; |
622 | ||
623 | static struct hda_verb cxt5045_mic_sense_init_verbs[] = { | |
624 | /* pin sensing on HP jack */ | |
625 | {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
d3091fad | 626 | { } /* end */ |
7f29673b TD |
627 | }; |
628 | ||
c9b443d4 TD |
629 | #ifdef CONFIG_SND_DEBUG |
630 | /* Test configuration for debugging, modelled after the ALC260 test | |
631 | * configuration. | |
632 | */ | |
633 | static struct hda_input_mux cxt5045_test_capture_source = { | |
634 | .num_items = 5, | |
635 | .items = { | |
636 | { "MIXER", 0x0 }, | |
637 | { "MIC1 pin", 0x1 }, | |
638 | { "LINE1 pin", 0x2 }, | |
639 | { "HP-OUT pin", 0x3 }, | |
640 | { "CD pin", 0x4 }, | |
641 | }, | |
642 | }; | |
643 | ||
644 | static struct snd_kcontrol_new cxt5045_test_mixer[] = { | |
645 | ||
646 | /* Output controls */ | |
c9b443d4 TD |
647 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), |
648 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), | |
7f29673b TD |
649 | HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), |
650 | HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), | |
651 | HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), | |
652 | HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
653 | |
654 | /* Modes for retasking pin widgets */ | |
655 | CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), | |
656 | CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), | |
657 | ||
82f30040 TD |
658 | /* EAPD Switch Control */ |
659 | CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), | |
660 | ||
c9b443d4 | 661 | /* Loopback mixer controls */ |
7f29673b TD |
662 | |
663 | HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), | |
664 | HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), | |
665 | HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), | |
666 | HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), | |
667 | HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), | |
668 | HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), | |
669 | HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), | |
670 | HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), | |
671 | HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), | |
672 | HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), | |
c9b443d4 TD |
673 | { |
674 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
675 | .name = "Input Source", | |
676 | .info = conexant_mux_enum_info, | |
677 | .get = conexant_mux_enum_get, | |
678 | .put = conexant_mux_enum_put, | |
679 | }, | |
fb3409e7 TD |
680 | /* Audio input controls */ |
681 | HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), | |
682 | HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), | |
683 | HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), | |
684 | HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), | |
685 | HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), | |
686 | HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), | |
687 | HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), | |
688 | HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), | |
689 | HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), | |
690 | HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), | |
c9b443d4 TD |
691 | { } /* end */ |
692 | }; | |
693 | ||
694 | static struct hda_verb cxt5045_test_init_verbs[] = { | |
7f29673b TD |
695 | /* Set connections */ |
696 | { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
697 | { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
698 | { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
c9b443d4 TD |
699 | /* Enable retasking pins as output, initially without power amp */ |
700 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
7f29673b | 701 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
c9b443d4 TD |
702 | |
703 | /* Disable digital (SPDIF) pins initially, but users can enable | |
704 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
705 | * payload also sets the generation to 0, output to be in "consumer" | |
706 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
707 | * control. | |
708 | */ | |
709 | {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
710 | ||
711 | /* Start with output sum widgets muted and their output gains at min */ | |
712 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
713 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
714 | ||
715 | /* Unmute retasking pin widget output buffers since the default | |
716 | * state appears to be output. As the pin mode is changed by the | |
717 | * user the pin mode control will take care of enabling the pin's | |
718 | * input/output buffers as needed. | |
719 | */ | |
720 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
721 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
722 | ||
723 | /* Mute capture amp left and right */ | |
724 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
725 | ||
726 | /* Set ADC connection select to match default mixer setting (mic1 | |
727 | * pin) | |
728 | */ | |
729 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
7f29673b | 730 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, |
c9b443d4 TD |
731 | |
732 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
733 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ | |
734 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ | |
735 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ | |
736 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ | |
737 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
738 | ||
739 | { } | |
740 | }; | |
741 | #endif | |
742 | ||
743 | ||
744 | /* initialize jack-sensing, too */ | |
745 | static int cxt5045_init(struct hda_codec *codec) | |
746 | { | |
747 | conexant_init(codec); | |
748 | cxt5045_hp_automute(codec); | |
749 | return 0; | |
750 | } | |
751 | ||
752 | ||
753 | enum { | |
7f29673b TD |
754 | CXT5045_LAPTOP, /* Laptops w/ EAPD support */ |
755 | CXT5045_FUJITSU, /* Laptops w/ EAPD support */ | |
c9b443d4 TD |
756 | #ifdef CONFIG_SND_DEBUG |
757 | CXT5045_TEST, | |
758 | #endif | |
f5fcc13c | 759 | CXT5045_MODELS |
c9b443d4 TD |
760 | }; |
761 | ||
f5fcc13c TI |
762 | static const char *cxt5045_models[CXT5045_MODELS] = { |
763 | [CXT5045_LAPTOP] = "laptop", | |
7f29673b | 764 | [CXT5045_FUJITSU] = "fujitsu", |
c9b443d4 | 765 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 766 | [CXT5045_TEST] = "test", |
c9b443d4 | 767 | #endif |
f5fcc13c TI |
768 | }; |
769 | ||
770 | static struct snd_pci_quirk cxt5045_cfg_tbl[] = { | |
771 | SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP), | |
82f30040 | 772 | SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP), |
4d69d756 TD |
773 | SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP), |
774 | SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP), | |
775 | SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP), | |
8481da5a | 776 | SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP), |
7f29673b | 777 | SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU), |
f8f794ab | 778 | SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP), |
7f29673b | 779 | SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP), |
c9b443d4 TD |
780 | {} |
781 | }; | |
782 | ||
783 | static int patch_cxt5045(struct hda_codec *codec) | |
784 | { | |
785 | struct conexant_spec *spec; | |
786 | int board_config; | |
787 | ||
788 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
789 | if (!spec) | |
790 | return -ENOMEM; | |
791 | mutex_init(&spec->amp_mutex); | |
792 | codec->spec = spec; | |
793 | ||
794 | spec->multiout.max_channels = 2; | |
795 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); | |
796 | spec->multiout.dac_nids = cxt5045_dac_nids; | |
797 | spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; | |
798 | spec->num_adc_nids = 1; | |
799 | spec->adc_nids = cxt5045_adc_nids; | |
800 | spec->capsrc_nids = cxt5045_capsrc_nids; | |
801 | spec->input_mux = &cxt5045_capture_source; | |
802 | spec->num_mixers = 1; | |
803 | spec->mixers[0] = cxt5045_mixers; | |
804 | spec->num_init_verbs = 1; | |
805 | spec->init_verbs[0] = cxt5045_init_verbs; | |
806 | spec->spdif_route = 0; | |
5cd57529 TD |
807 | spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), |
808 | spec->channel_mode = cxt5045_modes, | |
809 | ||
c9b443d4 TD |
810 | |
811 | codec->patch_ops = conexant_patch_ops; | |
c9b443d4 | 812 | |
f5fcc13c TI |
813 | board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, |
814 | cxt5045_models, | |
815 | cxt5045_cfg_tbl); | |
c9b443d4 TD |
816 | switch (board_config) { |
817 | case CXT5045_LAPTOP: | |
7f29673b TD |
818 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
819 | spec->input_mux = &cxt5045_capture_source; | |
820 | spec->num_init_verbs = 2; | |
821 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | |
822 | spec->mixers[0] = cxt5045_mixers; | |
823 | codec->patch_ops.init = cxt5045_init; | |
824 | break; | |
825 | case CXT5045_FUJITSU: | |
c9b443d4 TD |
826 | spec->input_mux = &cxt5045_capture_source; |
827 | spec->num_init_verbs = 2; | |
7f29673b | 828 | spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; |
c9b443d4 TD |
829 | spec->mixers[0] = cxt5045_mixers; |
830 | codec->patch_ops.init = cxt5045_init; | |
831 | break; | |
832 | #ifdef CONFIG_SND_DEBUG | |
833 | case CXT5045_TEST: | |
834 | spec->input_mux = &cxt5045_test_capture_source; | |
835 | spec->mixers[0] = cxt5045_test_mixer; | |
836 | spec->init_verbs[0] = cxt5045_test_init_verbs; | |
837 | #endif | |
838 | } | |
839 | return 0; | |
840 | } | |
841 | ||
842 | ||
843 | /* Conexant 5047 specific */ | |
82f30040 | 844 | #define CXT5047_SPDIF_OUT 0x11 |
c9b443d4 | 845 | |
82f30040 | 846 | static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c }; |
c9b443d4 TD |
847 | static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; |
848 | static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; | |
c9b443d4 | 849 | |
5cd57529 TD |
850 | static struct hda_channel_mode cxt5047_modes[1] = { |
851 | { 2, NULL }, | |
852 | }; | |
c9b443d4 TD |
853 | |
854 | static struct hda_input_mux cxt5047_capture_source = { | |
7f29673b | 855 | .num_items = 1, |
c9b443d4 | 856 | .items = { |
7f29673b | 857 | { "Mic", 0x2 }, |
c9b443d4 TD |
858 | } |
859 | }; | |
860 | ||
861 | static struct hda_input_mux cxt5047_hp_capture_source = { | |
862 | .num_items = 1, | |
863 | .items = { | |
82f30040 TD |
864 | { "ExtMic", 0x2 }, |
865 | } | |
866 | }; | |
867 | ||
868 | static struct hda_input_mux cxt5047_toshiba_capture_source = { | |
869 | .num_items = 2, | |
870 | .items = { | |
871 | { "ExtMic", 0x2 }, | |
872 | { "Line-In", 0x1 }, | |
c9b443d4 TD |
873 | } |
874 | }; | |
875 | ||
876 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
877 | static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
878 | struct snd_ctl_elem_value *ucontrol) | |
879 | { | |
880 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
881 | struct conexant_spec *spec = codec->spec; | |
82f30040 | 882 | unsigned int bits; |
c9b443d4 | 883 | |
82f30040 | 884 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
c9b443d4 TD |
885 | return 0; |
886 | ||
82f30040 TD |
887 | /* toggle internal speakers mute depending of presence of |
888 | * the headphone jack | |
889 | */ | |
47fd830a TI |
890 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
891 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, | |
892 | HDA_AMP_MUTE, bits); | |
893 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; | |
894 | snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, | |
895 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
896 | return 1; |
897 | } | |
898 | ||
82f30040 | 899 | /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */ |
c9b443d4 TD |
900 | static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol, |
901 | struct snd_ctl_elem_value *ucontrol) | |
902 | { | |
903 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
904 | long *valp = ucontrol->value.integer.value; | |
905 | int change; | |
906 | ||
82f30040 | 907 | change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, |
47fd830a | 908 | HDA_AMP_VOLMASK, valp[0]); |
82f30040 | 909 | change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, |
47fd830a | 910 | HDA_AMP_VOLMASK, valp[1]); |
c9b443d4 | 911 | snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, |
47fd830a | 912 | HDA_AMP_VOLMASK, valp[0]); |
c9b443d4 | 913 | snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, |
47fd830a | 914 | HDA_AMP_VOLMASK, valp[1]); |
c9b443d4 TD |
915 | return change; |
916 | } | |
c9b443d4 TD |
917 | |
918 | /* mute internal speaker if HP is plugged */ | |
919 | static void cxt5047_hp_automute(struct hda_codec *codec) | |
920 | { | |
82f30040 | 921 | struct conexant_spec *spec = codec->spec; |
dd87da1c | 922 | unsigned int bits; |
c9b443d4 | 923 | |
82f30040 | 924 | spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, |
c9b443d4 | 925 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
dd87da1c | 926 | |
47fd830a TI |
927 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
928 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, | |
929 | HDA_AMP_MUTE, bits); | |
82f30040 | 930 | /* Mute/Unmute PCM 2 for good measure - some systems need this */ |
47fd830a TI |
931 | snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, |
932 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
933 | } |
934 | ||
fb3409e7 TD |
935 | /* mute internal speaker if HP is plugged */ |
936 | static void cxt5047_hp2_automute(struct hda_codec *codec) | |
937 | { | |
938 | struct conexant_spec *spec = codec->spec; | |
939 | unsigned int bits; | |
940 | ||
941 | spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, | |
942 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
943 | ||
47fd830a TI |
944 | bits = spec->hp_present ? HDA_AMP_MUTE : 0; |
945 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, | |
946 | HDA_AMP_MUTE, bits); | |
fb3409e7 | 947 | /* Mute/Unmute PCM 2 for good measure - some systems need this */ |
47fd830a TI |
948 | snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, |
949 | HDA_AMP_MUTE, bits); | |
fb3409e7 TD |
950 | } |
951 | ||
c9b443d4 TD |
952 | /* toggle input of built-in and mic jack appropriately */ |
953 | static void cxt5047_hp_automic(struct hda_codec *codec) | |
954 | { | |
955 | static struct hda_verb mic_jack_on[] = { | |
956 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
957 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
958 | {} | |
959 | }; | |
960 | static struct hda_verb mic_jack_off[] = { | |
961 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
962 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
963 | {} | |
964 | }; | |
965 | unsigned int present; | |
966 | ||
7f29673b | 967 | present = snd_hda_codec_read(codec, 0x15, 0, |
c9b443d4 TD |
968 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
969 | if (present) | |
970 | snd_hda_sequence_write(codec, mic_jack_on); | |
971 | else | |
972 | snd_hda_sequence_write(codec, mic_jack_off); | |
973 | } | |
974 | ||
975 | /* unsolicited event for HP jack sensing */ | |
976 | static void cxt5047_hp_unsol_event(struct hda_codec *codec, | |
977 | unsigned int res) | |
978 | { | |
979 | res >>= 26; | |
980 | switch (res) { | |
981 | case CONEXANT_HP_EVENT: | |
982 | cxt5047_hp_automute(codec); | |
983 | break; | |
984 | case CONEXANT_MIC_EVENT: | |
985 | cxt5047_hp_automic(codec); | |
986 | break; | |
987 | } | |
988 | } | |
989 | ||
fb3409e7 TD |
990 | /* unsolicited event for HP jack sensing - non-EAPD systems */ |
991 | static void cxt5047_hp2_unsol_event(struct hda_codec *codec, | |
992 | unsigned int res) | |
993 | { | |
994 | res >>= 26; | |
995 | switch (res) { | |
996 | case CONEXANT_HP_EVENT: | |
997 | cxt5047_hp2_automute(codec); | |
998 | break; | |
999 | case CONEXANT_MIC_EVENT: | |
1000 | cxt5047_hp_automic(codec); | |
1001 | break; | |
1002 | } | |
1003 | } | |
1004 | ||
c9b443d4 | 1005 | static struct snd_kcontrol_new cxt5047_mixers[] = { |
c9b443d4 TD |
1006 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), |
1007 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), | |
7f29673b TD |
1008 | HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT), |
1009 | HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1010 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), |
1011 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1012 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1013 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
82f30040 TD |
1014 | HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT), |
1015 | HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT), | |
b7589ceb TD |
1016 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT), |
1017 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT), | |
1018 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), | |
1019 | HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT), | |
82f30040 TD |
1020 | |
1021 | {} | |
1022 | }; | |
1023 | ||
1024 | static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = { | |
1025 | { | |
1026 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1027 | .name = "Capture Source", | |
1028 | .info = conexant_mux_enum_info, | |
1029 | .get = conexant_mux_enum_get, | |
1030 | .put = conexant_mux_enum_put | |
1031 | }, | |
1032 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), | |
1033 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), | |
1034 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), | |
1035 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1036 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1037 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
1038 | { | |
1039 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1040 | .name = "Master Playback Volume", | |
1041 | .info = snd_hda_mixer_amp_volume_info, | |
1042 | .get = snd_hda_mixer_amp_volume_get, | |
1043 | .put = cxt5047_hp_master_vol_put, | |
1044 | .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT), | |
1045 | }, | |
1046 | { | |
1047 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1048 | .name = "Master Playback Switch", | |
1049 | .info = cxt_eapd_info, | |
1050 | .get = cxt_eapd_get, | |
c9b443d4 TD |
1051 | .put = cxt5047_hp_master_sw_put, |
1052 | .private_value = 0x13, | |
1053 | }, | |
1054 | ||
1055 | {} | |
1056 | }; | |
1057 | ||
1058 | static struct snd_kcontrol_new cxt5047_hp_mixers[] = { | |
1059 | { | |
1060 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1061 | .name = "Capture Source", | |
1062 | .info = conexant_mux_enum_info, | |
1063 | .get = conexant_mux_enum_get, | |
1064 | .put = conexant_mux_enum_put | |
1065 | }, | |
1066 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), | |
1067 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT), | |
1068 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), | |
1069 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1070 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1071 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
1072 | HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), | |
1073 | { | |
1074 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1075 | .name = "Master Playback Switch", | |
82f30040 TD |
1076 | .info = cxt_eapd_info, |
1077 | .get = cxt_eapd_get, | |
c9b443d4 TD |
1078 | .put = cxt5047_hp_master_sw_put, |
1079 | .private_value = 0x13, | |
1080 | }, | |
1081 | { } /* end */ | |
1082 | }; | |
1083 | ||
1084 | static struct hda_verb cxt5047_init_verbs[] = { | |
1085 | /* Line in, Mic, Built-in Mic */ | |
1086 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
1087 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
1088 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
7f29673b | 1089 | /* HP, Speaker */ |
b7589ceb TD |
1090 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1091 | {0x13, AC_VERB_SET_CONNECT_SEL,0x1}, | |
82f30040 | 1092 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x0}, |
7f29673b | 1093 | /* Record selector: Mic */ |
c9b443d4 TD |
1094 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, |
1095 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, | |
1096 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
7f29673b TD |
1097 | {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, |
1098 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
1099 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, | |
1100 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
1101 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, | |
c9b443d4 TD |
1102 | /* SPDIF route: PCM */ |
1103 | { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
82f30040 TD |
1104 | /* Enable unsolicited events */ |
1105 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
1106 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
c9b443d4 TD |
1107 | { } /* end */ |
1108 | }; | |
1109 | ||
1110 | /* configuration for Toshiba Laptops */ | |
1111 | static struct hda_verb cxt5047_toshiba_init_verbs[] = { | |
1112 | {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ | |
1113 | /* pin sensing on HP and Mic jacks */ | |
1114 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
1115 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
82f30040 TD |
1116 | /* Speaker routing */ |
1117 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, | |
c9b443d4 TD |
1118 | {} |
1119 | }; | |
1120 | ||
1121 | /* configuration for HP Laptops */ | |
1122 | static struct hda_verb cxt5047_hp_init_verbs[] = { | |
82f30040 | 1123 | /* pin sensing on HP jack */ |
c9b443d4 | 1124 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
82f30040 TD |
1125 | /* Record selector: Ext Mic */ |
1126 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, | |
82f30040 TD |
1127 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, |
1128 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
1129 | /* Speaker routing */ | |
1130 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, | |
c9b443d4 TD |
1131 | {} |
1132 | }; | |
1133 | ||
1134 | /* Test configuration for debugging, modelled after the ALC260 test | |
1135 | * configuration. | |
1136 | */ | |
1137 | #ifdef CONFIG_SND_DEBUG | |
1138 | static struct hda_input_mux cxt5047_test_capture_source = { | |
82f30040 | 1139 | .num_items = 4, |
c9b443d4 | 1140 | .items = { |
82f30040 TD |
1141 | { "LINE1 pin", 0x0 }, |
1142 | { "MIC1 pin", 0x1 }, | |
1143 | { "MIC2 pin", 0x2 }, | |
1144 | { "CD pin", 0x3 }, | |
c9b443d4 TD |
1145 | }, |
1146 | }; | |
1147 | ||
1148 | static struct snd_kcontrol_new cxt5047_test_mixer[] = { | |
1149 | ||
1150 | /* Output only controls */ | |
82f30040 TD |
1151 | HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), |
1152 | HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), | |
1153 | HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), | |
1154 | HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1155 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), |
1156 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), | |
1157 | HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
1158 | HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
82f30040 TD |
1159 | HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), |
1160 | HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), | |
1161 | HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), | |
1162 | HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1163 | |
1164 | /* Modes for retasking pin widgets */ | |
1165 | CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), | |
1166 | CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), | |
1167 | ||
82f30040 TD |
1168 | /* EAPD Switch Control */ |
1169 | CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), | |
c9b443d4 | 1170 | |
82f30040 TD |
1171 | /* Loopback mixer controls */ |
1172 | HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), | |
1173 | HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), | |
1174 | HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), | |
1175 | HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), | |
1176 | HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), | |
1177 | HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), | |
1178 | HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), | |
1179 | HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), | |
1180 | ||
1181 | HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), | |
1182 | HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), | |
1183 | HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), | |
1184 | HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), | |
1185 | HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), | |
1186 | HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), | |
1187 | HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), | |
1188 | HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), | |
c9b443d4 TD |
1189 | { |
1190 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1191 | .name = "Input Source", | |
1192 | .info = conexant_mux_enum_info, | |
1193 | .get = conexant_mux_enum_get, | |
1194 | .put = conexant_mux_enum_put, | |
1195 | }, | |
c9b443d4 TD |
1196 | { } /* end */ |
1197 | }; | |
1198 | ||
1199 | static struct hda_verb cxt5047_test_init_verbs[] = { | |
c9b443d4 TD |
1200 | /* Enable retasking pins as output, initially without power amp */ |
1201 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1202 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1203 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1204 | ||
1205 | /* Disable digital (SPDIF) pins initially, but users can enable | |
1206 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
1207 | * payload also sets the generation to 0, output to be in "consumer" | |
1208 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
1209 | * control. | |
1210 | */ | |
1211 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
1212 | ||
1213 | /* Ensure mic1, mic2, line1 pin widgets take input from the | |
1214 | * OUT1 sum bus when acting as an output. | |
1215 | */ | |
1216 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, | |
1217 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, | |
1218 | ||
1219 | /* Start with output sum widgets muted and their output gains at min */ | |
1220 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1221 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1222 | ||
1223 | /* Unmute retasking pin widget output buffers since the default | |
1224 | * state appears to be output. As the pin mode is changed by the | |
1225 | * user the pin mode control will take care of enabling the pin's | |
1226 | * input/output buffers as needed. | |
1227 | */ | |
1228 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1229 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1230 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1231 | ||
1232 | /* Mute capture amp left and right */ | |
1233 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1234 | ||
1235 | /* Set ADC connection select to match default mixer setting (mic1 | |
1236 | * pin) | |
1237 | */ | |
1238 | {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1239 | ||
1240 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
1241 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ | |
1242 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ | |
1243 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ | |
1244 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ | |
1245 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
1246 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ | |
1247 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ | |
1248 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ | |
1249 | ||
1250 | { } | |
1251 | }; | |
1252 | #endif | |
1253 | ||
1254 | ||
1255 | /* initialize jack-sensing, too */ | |
1256 | static int cxt5047_hp_init(struct hda_codec *codec) | |
1257 | { | |
1258 | conexant_init(codec); | |
1259 | cxt5047_hp_automute(codec); | |
c9b443d4 TD |
1260 | return 0; |
1261 | } | |
1262 | ||
1263 | ||
1264 | enum { | |
f5fcc13c TI |
1265 | CXT5047_LAPTOP, /* Laptops w/o EAPD support */ |
1266 | CXT5047_LAPTOP_HP, /* Some HP laptops */ | |
1267 | CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ | |
c9b443d4 TD |
1268 | #ifdef CONFIG_SND_DEBUG |
1269 | CXT5047_TEST, | |
1270 | #endif | |
f5fcc13c | 1271 | CXT5047_MODELS |
c9b443d4 TD |
1272 | }; |
1273 | ||
f5fcc13c TI |
1274 | static const char *cxt5047_models[CXT5047_MODELS] = { |
1275 | [CXT5047_LAPTOP] = "laptop", | |
1276 | [CXT5047_LAPTOP_HP] = "laptop-hp", | |
1277 | [CXT5047_LAPTOP_EAPD] = "laptop-eapd", | |
c9b443d4 | 1278 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 1279 | [CXT5047_TEST] = "test", |
c9b443d4 | 1280 | #endif |
f5fcc13c TI |
1281 | }; |
1282 | ||
1283 | static struct snd_pci_quirk cxt5047_cfg_tbl[] = { | |
1284 | SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP), | |
1285 | SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP), | |
82f30040 | 1286 | SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP), |
f5fcc13c TI |
1287 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), |
1288 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), | |
c9b443d4 TD |
1289 | {} |
1290 | }; | |
1291 | ||
1292 | static int patch_cxt5047(struct hda_codec *codec) | |
1293 | { | |
1294 | struct conexant_spec *spec; | |
1295 | int board_config; | |
1296 | ||
1297 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1298 | if (!spec) | |
1299 | return -ENOMEM; | |
1300 | mutex_init(&spec->amp_mutex); | |
1301 | codec->spec = spec; | |
1302 | ||
1303 | spec->multiout.max_channels = 2; | |
1304 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); | |
1305 | spec->multiout.dac_nids = cxt5047_dac_nids; | |
1306 | spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; | |
1307 | spec->num_adc_nids = 1; | |
1308 | spec->adc_nids = cxt5047_adc_nids; | |
1309 | spec->capsrc_nids = cxt5047_capsrc_nids; | |
1310 | spec->input_mux = &cxt5047_capture_source; | |
1311 | spec->num_mixers = 1; | |
1312 | spec->mixers[0] = cxt5047_mixers; | |
1313 | spec->num_init_verbs = 1; | |
1314 | spec->init_verbs[0] = cxt5047_init_verbs; | |
1315 | spec->spdif_route = 0; | |
5cd57529 TD |
1316 | spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), |
1317 | spec->channel_mode = cxt5047_modes, | |
c9b443d4 TD |
1318 | |
1319 | codec->patch_ops = conexant_patch_ops; | |
c9b443d4 | 1320 | |
f5fcc13c TI |
1321 | board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, |
1322 | cxt5047_models, | |
1323 | cxt5047_cfg_tbl); | |
c9b443d4 TD |
1324 | switch (board_config) { |
1325 | case CXT5047_LAPTOP: | |
fb3409e7 | 1326 | codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event; |
c9b443d4 TD |
1327 | break; |
1328 | case CXT5047_LAPTOP_HP: | |
1329 | spec->input_mux = &cxt5047_hp_capture_source; | |
1330 | spec->num_init_verbs = 2; | |
1331 | spec->init_verbs[1] = cxt5047_hp_init_verbs; | |
1332 | spec->mixers[0] = cxt5047_hp_mixers; | |
fb3409e7 | 1333 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1334 | codec->patch_ops.init = cxt5047_hp_init; |
1335 | break; | |
1336 | case CXT5047_LAPTOP_EAPD: | |
82f30040 | 1337 | spec->input_mux = &cxt5047_toshiba_capture_source; |
c9b443d4 TD |
1338 | spec->num_init_verbs = 2; |
1339 | spec->init_verbs[1] = cxt5047_toshiba_init_verbs; | |
82f30040 | 1340 | spec->mixers[0] = cxt5047_toshiba_mixers; |
fb3409e7 | 1341 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1342 | break; |
1343 | #ifdef CONFIG_SND_DEBUG | |
1344 | case CXT5047_TEST: | |
1345 | spec->input_mux = &cxt5047_test_capture_source; | |
1346 | spec->mixers[0] = cxt5047_test_mixer; | |
1347 | spec->init_verbs[0] = cxt5047_test_init_verbs; | |
fb3409e7 | 1348 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1349 | #endif |
1350 | } | |
1351 | return 0; | |
1352 | } | |
1353 | ||
1354 | struct hda_codec_preset snd_hda_preset_conexant[] = { | |
82f30040 TD |
1355 | { .id = 0x14f15045, .name = "CX20549 (Venice)", |
1356 | .patch = patch_cxt5045 }, | |
1357 | { .id = 0x14f15047, .name = "CX20551 (Waikiki)", | |
1358 | .patch = patch_cxt5047 }, | |
c9b443d4 TD |
1359 | {} /* terminator */ |
1360 | }; |