]>
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 | ||
c9b443d4 TD |
23 | #include <linux/init.h> |
24 | #include <linux/delay.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/pci.h> | |
27 | #include <sound/core.h> | |
28 | #include "hda_codec.h" | |
29 | #include "hda_local.h" | |
3c9a3203 | 30 | #include "hda_patch.h" |
c9b443d4 TD |
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 | ||
461e2c78 TI |
68 | unsigned int cur_adc_idx; |
69 | hda_nid_t cur_adc; | |
70 | unsigned int cur_adc_stream_tag; | |
71 | unsigned int cur_adc_format; | |
72 | ||
c9b443d4 TD |
73 | /* capture source */ |
74 | const struct hda_input_mux *input_mux; | |
75 | hda_nid_t *capsrc_nids; | |
76 | unsigned int cur_mux[3]; | |
77 | ||
78 | /* channel model */ | |
79 | const struct hda_channel_mode *channel_mode; | |
80 | int num_channel_mode; | |
81 | ||
82 | /* PCM information */ | |
83 | struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ | |
84 | ||
85 | struct mutex amp_mutex; /* PCM volume/mute control mutex */ | |
86 | unsigned int spdif_route; | |
87 | ||
88 | /* dynamic controls, init_verbs and input_mux */ | |
89 | struct auto_pin_cfg autocfg; | |
90 | unsigned int num_kctl_alloc, num_kctl_used; | |
91 | struct snd_kcontrol_new *kctl_alloc; | |
92 | struct hda_input_mux private_imux; | |
41923e44 | 93 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
c9b443d4 TD |
94 | |
95 | }; | |
96 | ||
97 | static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
98 | struct hda_codec *codec, | |
99 | struct snd_pcm_substream *substream) | |
100 | { | |
101 | struct conexant_spec *spec = codec->spec; | |
9a08160b TI |
102 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
103 | hinfo); | |
c9b443d4 TD |
104 | } |
105 | ||
106 | static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
107 | struct hda_codec *codec, | |
108 | unsigned int stream_tag, | |
109 | unsigned int format, | |
110 | struct snd_pcm_substream *substream) | |
111 | { | |
112 | struct conexant_spec *spec = codec->spec; | |
113 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | |
114 | stream_tag, | |
115 | format, substream); | |
116 | } | |
117 | ||
118 | static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
119 | struct hda_codec *codec, | |
120 | struct snd_pcm_substream *substream) | |
121 | { | |
122 | struct conexant_spec *spec = codec->spec; | |
123 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
124 | } | |
125 | ||
126 | /* | |
127 | * Digital out | |
128 | */ | |
129 | static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
130 | struct hda_codec *codec, | |
131 | struct snd_pcm_substream *substream) | |
132 | { | |
133 | struct conexant_spec *spec = codec->spec; | |
134 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
135 | } | |
136 | ||
137 | static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
138 | struct hda_codec *codec, | |
139 | struct snd_pcm_substream *substream) | |
140 | { | |
141 | struct conexant_spec *spec = codec->spec; | |
142 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
143 | } | |
144 | ||
6b97eb45 TI |
145 | static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
146 | struct hda_codec *codec, | |
147 | unsigned int stream_tag, | |
148 | unsigned int format, | |
149 | struct snd_pcm_substream *substream) | |
150 | { | |
151 | struct conexant_spec *spec = codec->spec; | |
152 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, | |
153 | stream_tag, | |
154 | format, substream); | |
155 | } | |
156 | ||
c9b443d4 TD |
157 | /* |
158 | * Analog capture | |
159 | */ | |
160 | static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
161 | struct hda_codec *codec, | |
162 | unsigned int stream_tag, | |
163 | unsigned int format, | |
164 | struct snd_pcm_substream *substream) | |
165 | { | |
166 | struct conexant_spec *spec = codec->spec; | |
167 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
168 | stream_tag, 0, format); | |
169 | return 0; | |
170 | } | |
171 | ||
172 | static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
173 | struct hda_codec *codec, | |
174 | struct snd_pcm_substream *substream) | |
175 | { | |
176 | struct conexant_spec *spec = codec->spec; | |
177 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
178 | 0, 0, 0); | |
179 | return 0; | |
180 | } | |
181 | ||
182 | ||
183 | ||
184 | static struct hda_pcm_stream conexant_pcm_analog_playback = { | |
185 | .substreams = 1, | |
186 | .channels_min = 2, | |
187 | .channels_max = 2, | |
188 | .nid = 0, /* fill later */ | |
189 | .ops = { | |
190 | .open = conexant_playback_pcm_open, | |
191 | .prepare = conexant_playback_pcm_prepare, | |
192 | .cleanup = conexant_playback_pcm_cleanup | |
193 | }, | |
194 | }; | |
195 | ||
196 | static struct hda_pcm_stream conexant_pcm_analog_capture = { | |
197 | .substreams = 1, | |
198 | .channels_min = 2, | |
199 | .channels_max = 2, | |
200 | .nid = 0, /* fill later */ | |
201 | .ops = { | |
202 | .prepare = conexant_capture_pcm_prepare, | |
203 | .cleanup = conexant_capture_pcm_cleanup | |
204 | }, | |
205 | }; | |
206 | ||
207 | ||
208 | static struct hda_pcm_stream conexant_pcm_digital_playback = { | |
209 | .substreams = 1, | |
210 | .channels_min = 2, | |
211 | .channels_max = 2, | |
212 | .nid = 0, /* fill later */ | |
213 | .ops = { | |
214 | .open = conexant_dig_playback_pcm_open, | |
6b97eb45 TI |
215 | .close = conexant_dig_playback_pcm_close, |
216 | .prepare = conexant_dig_playback_pcm_prepare | |
c9b443d4 TD |
217 | }, |
218 | }; | |
219 | ||
220 | static struct hda_pcm_stream conexant_pcm_digital_capture = { | |
221 | .substreams = 1, | |
222 | .channels_min = 2, | |
223 | .channels_max = 2, | |
224 | /* NID is set in alc_build_pcms */ | |
225 | }; | |
226 | ||
461e2c78 TI |
227 | static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
228 | struct hda_codec *codec, | |
229 | unsigned int stream_tag, | |
230 | unsigned int format, | |
231 | struct snd_pcm_substream *substream) | |
232 | { | |
233 | struct conexant_spec *spec = codec->spec; | |
234 | spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; | |
235 | spec->cur_adc_stream_tag = stream_tag; | |
236 | spec->cur_adc_format = format; | |
237 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | |
238 | return 0; | |
239 | } | |
240 | ||
241 | static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
242 | struct hda_codec *codec, | |
243 | struct snd_pcm_substream *substream) | |
244 | { | |
245 | struct conexant_spec *spec = codec->spec; | |
246 | snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); | |
247 | spec->cur_adc = 0; | |
248 | return 0; | |
249 | } | |
250 | ||
251 | static struct hda_pcm_stream cx5051_pcm_analog_capture = { | |
252 | .substreams = 1, | |
253 | .channels_min = 2, | |
254 | .channels_max = 2, | |
255 | .nid = 0, /* fill later */ | |
256 | .ops = { | |
257 | .prepare = cx5051_capture_pcm_prepare, | |
258 | .cleanup = cx5051_capture_pcm_cleanup | |
259 | }, | |
260 | }; | |
261 | ||
c9b443d4 TD |
262 | static int conexant_build_pcms(struct hda_codec *codec) |
263 | { | |
264 | struct conexant_spec *spec = codec->spec; | |
265 | struct hda_pcm *info = spec->pcm_rec; | |
266 | ||
267 | codec->num_pcms = 1; | |
268 | codec->pcm_info = info; | |
269 | ||
270 | info->name = "CONEXANT Analog"; | |
271 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; | |
272 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | |
273 | spec->multiout.max_channels; | |
274 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
275 | spec->multiout.dac_nids[0]; | |
461e2c78 TI |
276 | if (codec->vendor_id == 0x14f15051) |
277 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
278 | cx5051_pcm_analog_capture; | |
279 | else | |
280 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
281 | conexant_pcm_analog_capture; | |
c9b443d4 TD |
282 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; |
283 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | |
284 | ||
285 | if (spec->multiout.dig_out_nid) { | |
286 | info++; | |
287 | codec->num_pcms++; | |
288 | info->name = "Conexant Digital"; | |
7ba72ba1 | 289 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
c9b443d4 TD |
290 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
291 | conexant_pcm_digital_playback; | |
292 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
293 | spec->multiout.dig_out_nid; | |
294 | if (spec->dig_in_nid) { | |
295 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
296 | conexant_pcm_digital_capture; | |
297 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | |
298 | spec->dig_in_nid; | |
299 | } | |
300 | } | |
301 | ||
302 | return 0; | |
303 | } | |
304 | ||
305 | static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, | |
306 | struct snd_ctl_elem_info *uinfo) | |
307 | { | |
308 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
309 | struct conexant_spec *spec = codec->spec; | |
310 | ||
311 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | |
312 | } | |
313 | ||
314 | static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, | |
315 | struct snd_ctl_elem_value *ucontrol) | |
316 | { | |
317 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
318 | struct conexant_spec *spec = codec->spec; | |
319 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
320 | ||
321 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
322 | return 0; | |
323 | } | |
324 | ||
325 | static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, | |
326 | struct snd_ctl_elem_value *ucontrol) | |
327 | { | |
328 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
329 | struct conexant_spec *spec = codec->spec; | |
330 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
331 | ||
332 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
333 | spec->capsrc_nids[adc_idx], | |
334 | &spec->cur_mux[adc_idx]); | |
335 | } | |
336 | ||
337 | static int conexant_init(struct hda_codec *codec) | |
338 | { | |
339 | struct conexant_spec *spec = codec->spec; | |
340 | int i; | |
341 | ||
342 | for (i = 0; i < spec->num_init_verbs; i++) | |
343 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
344 | return 0; | |
345 | } | |
346 | ||
347 | static void conexant_free(struct hda_codec *codec) | |
348 | { | |
349 | struct conexant_spec *spec = codec->spec; | |
350 | unsigned int i; | |
351 | ||
352 | if (spec->kctl_alloc) { | |
353 | for (i = 0; i < spec->num_kctl_used; i++) | |
354 | kfree(spec->kctl_alloc[i].name); | |
355 | kfree(spec->kctl_alloc); | |
356 | } | |
357 | ||
358 | kfree(codec->spec); | |
359 | } | |
360 | ||
c9b443d4 TD |
361 | static int conexant_build_controls(struct hda_codec *codec) |
362 | { | |
363 | struct conexant_spec *spec = codec->spec; | |
364 | unsigned int i; | |
365 | int err; | |
366 | ||
367 | for (i = 0; i < spec->num_mixers; i++) { | |
368 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
369 | if (err < 0) | |
370 | return err; | |
371 | } | |
372 | if (spec->multiout.dig_out_nid) { | |
373 | err = snd_hda_create_spdif_out_ctls(codec, | |
374 | spec->multiout.dig_out_nid); | |
375 | if (err < 0) | |
376 | return err; | |
9a08160b TI |
377 | err = snd_hda_create_spdif_share_sw(codec, |
378 | &spec->multiout); | |
379 | if (err < 0) | |
380 | return err; | |
381 | spec->multiout.share_spdif = 1; | |
c9b443d4 TD |
382 | } |
383 | if (spec->dig_in_nid) { | |
384 | err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); | |
385 | if (err < 0) | |
386 | return err; | |
387 | } | |
388 | return 0; | |
389 | } | |
390 | ||
391 | static struct hda_codec_ops conexant_patch_ops = { | |
392 | .build_controls = conexant_build_controls, | |
393 | .build_pcms = conexant_build_pcms, | |
394 | .init = conexant_init, | |
395 | .free = conexant_free, | |
c9b443d4 TD |
396 | }; |
397 | ||
398 | /* | |
399 | * EAPD control | |
400 | * the private value = nid | (invert << 8) | |
401 | */ | |
402 | ||
a5ce8890 | 403 | #define cxt_eapd_info snd_ctl_boolean_mono_info |
c9b443d4 | 404 | |
82f30040 | 405 | static int cxt_eapd_get(struct snd_kcontrol *kcontrol, |
c9b443d4 TD |
406 | struct snd_ctl_elem_value *ucontrol) |
407 | { | |
408 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
409 | struct conexant_spec *spec = codec->spec; | |
410 | int invert = (kcontrol->private_value >> 8) & 1; | |
411 | if (invert) | |
412 | ucontrol->value.integer.value[0] = !spec->cur_eapd; | |
413 | else | |
414 | ucontrol->value.integer.value[0] = spec->cur_eapd; | |
415 | return 0; | |
82f30040 | 416 | |
c9b443d4 TD |
417 | } |
418 | ||
82f30040 | 419 | static int cxt_eapd_put(struct snd_kcontrol *kcontrol, |
c9b443d4 TD |
420 | struct snd_ctl_elem_value *ucontrol) |
421 | { | |
422 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
423 | struct conexant_spec *spec = codec->spec; | |
424 | int invert = (kcontrol->private_value >> 8) & 1; | |
425 | hda_nid_t nid = kcontrol->private_value & 0xff; | |
426 | unsigned int eapd; | |
82f30040 | 427 | |
68ea7b2f | 428 | eapd = !!ucontrol->value.integer.value[0]; |
c9b443d4 TD |
429 | if (invert) |
430 | eapd = !eapd; | |
82beb8fd | 431 | if (eapd == spec->cur_eapd) |
c9b443d4 | 432 | return 0; |
82f30040 | 433 | |
c9b443d4 | 434 | spec->cur_eapd = eapd; |
82beb8fd TI |
435 | snd_hda_codec_write_cache(codec, nid, |
436 | 0, AC_VERB_SET_EAPD_BTLENABLE, | |
437 | eapd ? 0x02 : 0x00); | |
c9b443d4 TD |
438 | return 1; |
439 | } | |
440 | ||
86d72bdf TI |
441 | /* controls for test mode */ |
442 | #ifdef CONFIG_SND_DEBUG | |
443 | ||
82f30040 TD |
444 | #define CXT_EAPD_SWITCH(xname, nid, mask) \ |
445 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
446 | .info = cxt_eapd_info, \ | |
447 | .get = cxt_eapd_get, \ | |
448 | .put = cxt_eapd_put, \ | |
449 | .private_value = nid | (mask<<16) } | |
450 | ||
451 | ||
452 | ||
c9b443d4 TD |
453 | static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, |
454 | struct snd_ctl_elem_info *uinfo) | |
455 | { | |
456 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
457 | struct conexant_spec *spec = codec->spec; | |
458 | return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, | |
459 | spec->num_channel_mode); | |
460 | } | |
461 | ||
462 | static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, | |
463 | struct snd_ctl_elem_value *ucontrol) | |
464 | { | |
465 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
466 | struct conexant_spec *spec = codec->spec; | |
467 | return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, | |
468 | spec->num_channel_mode, | |
469 | spec->multiout.max_channels); | |
470 | } | |
471 | ||
472 | static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, | |
473 | struct snd_ctl_elem_value *ucontrol) | |
474 | { | |
475 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
476 | struct conexant_spec *spec = codec->spec; | |
477 | int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, | |
478 | spec->num_channel_mode, | |
479 | &spec->multiout.max_channels); | |
480 | if (err >= 0 && spec->need_dac_fix) | |
481 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; | |
482 | return err; | |
483 | } | |
484 | ||
485 | #define CXT_PIN_MODE(xname, nid, dir) \ | |
486 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
487 | .info = conexant_ch_mode_info, \ | |
488 | .get = conexant_ch_mode_get, \ | |
489 | .put = conexant_ch_mode_put, \ | |
490 | .private_value = nid | (dir<<16) } | |
491 | ||
86d72bdf TI |
492 | #endif /* CONFIG_SND_DEBUG */ |
493 | ||
c9b443d4 TD |
494 | /* Conexant 5045 specific */ |
495 | ||
496 | static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; | |
497 | static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; | |
498 | static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; | |
cbef9789 | 499 | #define CXT5045_SPDIF_OUT 0x18 |
c9b443d4 | 500 | |
5cd57529 TD |
501 | static struct hda_channel_mode cxt5045_modes[1] = { |
502 | { 2, NULL }, | |
503 | }; | |
c9b443d4 TD |
504 | |
505 | static struct hda_input_mux cxt5045_capture_source = { | |
506 | .num_items = 2, | |
507 | .items = { | |
82f30040 | 508 | { "IntMic", 0x1 }, |
f4beee94 | 509 | { "ExtMic", 0x2 }, |
c9b443d4 TD |
510 | } |
511 | }; | |
512 | ||
5218c892 JZ |
513 | static struct hda_input_mux cxt5045_capture_source_benq = { |
514 | .num_items = 3, | |
515 | .items = { | |
516 | { "IntMic", 0x1 }, | |
517 | { "ExtMic", 0x2 }, | |
518 | { "LineIn", 0x3 }, | |
519 | } | |
520 | }; | |
521 | ||
2de3c232 J |
522 | static struct hda_input_mux cxt5045_capture_source_hp530 = { |
523 | .num_items = 2, | |
524 | .items = { | |
525 | { "ExtMic", 0x1 }, | |
526 | { "IntMic", 0x2 }, | |
527 | } | |
528 | }; | |
529 | ||
c9b443d4 TD |
530 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
531 | static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
532 | struct snd_ctl_elem_value *ucontrol) | |
533 | { | |
534 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
535 | struct conexant_spec *spec = codec->spec; | |
82f30040 | 536 | unsigned int bits; |
c9b443d4 | 537 | |
82f30040 | 538 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
c9b443d4 TD |
539 | return 0; |
540 | ||
82f30040 TD |
541 | /* toggle internal speakers mute depending of presence of |
542 | * the headphone jack | |
543 | */ | |
47fd830a TI |
544 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
545 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, | |
546 | HDA_AMP_MUTE, bits); | |
7f29673b | 547 | |
47fd830a TI |
548 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; |
549 | snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, | |
550 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
551 | return 1; |
552 | } | |
553 | ||
554 | /* bind volumes of both NID 0x10 and 0x11 */ | |
cca3b371 TI |
555 | static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { |
556 | .ops = &snd_hda_bind_vol, | |
557 | .values = { | |
558 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), | |
559 | HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), | |
560 | 0 | |
561 | }, | |
562 | }; | |
c9b443d4 | 563 | |
7f29673b TD |
564 | /* toggle input of built-in and mic jack appropriately */ |
565 | static void cxt5045_hp_automic(struct hda_codec *codec) | |
566 | { | |
567 | static struct hda_verb mic_jack_on[] = { | |
568 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
569 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
570 | {} | |
571 | }; | |
572 | static struct hda_verb mic_jack_off[] = { | |
573 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
574 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
575 | {} | |
576 | }; | |
577 | unsigned int present; | |
578 | ||
579 | present = snd_hda_codec_read(codec, 0x12, 0, | |
580 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
581 | if (present) | |
582 | snd_hda_sequence_write(codec, mic_jack_on); | |
583 | else | |
584 | snd_hda_sequence_write(codec, mic_jack_off); | |
585 | } | |
586 | ||
c9b443d4 TD |
587 | |
588 | /* mute internal speaker if HP is plugged */ | |
589 | static void cxt5045_hp_automute(struct hda_codec *codec) | |
590 | { | |
82f30040 | 591 | struct conexant_spec *spec = codec->spec; |
dd87da1c | 592 | unsigned int bits; |
c9b443d4 | 593 | |
82f30040 | 594 | spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, |
c9b443d4 | 595 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
dd87da1c | 596 | |
47fd830a TI |
597 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
598 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, | |
599 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
600 | } |
601 | ||
602 | /* unsolicited event for HP jack sensing */ | |
603 | static void cxt5045_hp_unsol_event(struct hda_codec *codec, | |
604 | unsigned int res) | |
605 | { | |
606 | res >>= 26; | |
607 | switch (res) { | |
608 | case CONEXANT_HP_EVENT: | |
609 | cxt5045_hp_automute(codec); | |
610 | break; | |
7f29673b TD |
611 | case CONEXANT_MIC_EVENT: |
612 | cxt5045_hp_automic(codec); | |
613 | break; | |
614 | ||
c9b443d4 TD |
615 | } |
616 | } | |
617 | ||
618 | static struct snd_kcontrol_new cxt5045_mixers[] = { | |
619 | { | |
620 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
621 | .name = "Capture Source", | |
622 | .info = conexant_mux_enum_info, | |
623 | .get = conexant_mux_enum_get, | |
624 | .put = conexant_mux_enum_put | |
625 | }, | |
c8229c38 TI |
626 | HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), |
627 | HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), | |
628 | HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), | |
629 | HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), | |
630 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), | |
631 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), | |
632 | HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), | |
633 | HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), | |
634 | HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), | |
635 | HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), | |
cca3b371 | 636 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), |
c9b443d4 TD |
637 | { |
638 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
639 | .name = "Master Playback Switch", | |
82f30040 TD |
640 | .info = cxt_eapd_info, |
641 | .get = cxt_eapd_get, | |
c9b443d4 | 642 | .put = cxt5045_hp_master_sw_put, |
82f30040 | 643 | .private_value = 0x10, |
c9b443d4 TD |
644 | }, |
645 | ||
646 | {} | |
647 | }; | |
648 | ||
5218c892 JZ |
649 | static struct snd_kcontrol_new cxt5045_benq_mixers[] = { |
650 | HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), | |
651 | HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), | |
652 | HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), | |
653 | HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), | |
654 | ||
655 | {} | |
656 | }; | |
657 | ||
2de3c232 J |
658 | static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { |
659 | { | |
660 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
661 | .name = "Capture Source", | |
662 | .info = conexant_mux_enum_info, | |
663 | .get = conexant_mux_enum_get, | |
664 | .put = conexant_mux_enum_put | |
665 | }, | |
666 | HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), | |
667 | HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), | |
668 | HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), | |
669 | HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), | |
670 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), | |
671 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), | |
672 | HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), | |
673 | HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), | |
674 | HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), | |
675 | HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), | |
676 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), | |
677 | { | |
678 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
679 | .name = "Master Playback Switch", | |
680 | .info = cxt_eapd_info, | |
681 | .get = cxt_eapd_get, | |
682 | .put = cxt5045_hp_master_sw_put, | |
683 | .private_value = 0x10, | |
684 | }, | |
685 | ||
686 | {} | |
687 | }; | |
688 | ||
c9b443d4 TD |
689 | static struct hda_verb cxt5045_init_verbs[] = { |
690 | /* Line in, Mic */ | |
691 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
7f29673b | 692 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
c9b443d4 | 693 | /* HP, Amp */ |
c8229c38 TI |
694 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
695 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
696 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
697 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
698 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
699 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
700 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
701 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
702 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
82f30040 | 703 | /* Record selector: Int mic */ |
7f29673b | 704 | {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, |
82f30040 | 705 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, |
c9b443d4 TD |
706 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
707 | /* SPDIF route: PCM */ | |
cbef9789 | 708 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
c9b443d4 | 709 | { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
c9b443d4 | 710 | /* EAPD */ |
82f30040 | 711 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ |
c9b443d4 TD |
712 | { } /* end */ |
713 | }; | |
714 | ||
5218c892 JZ |
715 | static struct hda_verb cxt5045_benq_init_verbs[] = { |
716 | /* Int Mic, Mic */ | |
717 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, | |
718 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, | |
719 | /* Line In,HP, Amp */ | |
720 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
721 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
722 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
723 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
724 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
725 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
726 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
727 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
728 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
729 | /* Record selector: Int mic */ | |
730 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
731 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, | |
732 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
733 | /* SPDIF route: PCM */ | |
cbef9789 | 734 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
5218c892 JZ |
735 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, |
736 | /* EAPD */ | |
737 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
738 | { } /* end */ | |
739 | }; | |
7f29673b TD |
740 | |
741 | static struct hda_verb cxt5045_hp_sense_init_verbs[] = { | |
742 | /* pin sensing on HP jack */ | |
743 | {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
d3091fad | 744 | { } /* end */ |
7f29673b TD |
745 | }; |
746 | ||
747 | static struct hda_verb cxt5045_mic_sense_init_verbs[] = { | |
748 | /* pin sensing on HP jack */ | |
749 | {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
d3091fad | 750 | { } /* end */ |
7f29673b TD |
751 | }; |
752 | ||
c9b443d4 TD |
753 | #ifdef CONFIG_SND_DEBUG |
754 | /* Test configuration for debugging, modelled after the ALC260 test | |
755 | * configuration. | |
756 | */ | |
757 | static struct hda_input_mux cxt5045_test_capture_source = { | |
758 | .num_items = 5, | |
759 | .items = { | |
760 | { "MIXER", 0x0 }, | |
761 | { "MIC1 pin", 0x1 }, | |
762 | { "LINE1 pin", 0x2 }, | |
763 | { "HP-OUT pin", 0x3 }, | |
764 | { "CD pin", 0x4 }, | |
765 | }, | |
766 | }; | |
767 | ||
768 | static struct snd_kcontrol_new cxt5045_test_mixer[] = { | |
769 | ||
770 | /* Output controls */ | |
c9b443d4 TD |
771 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), |
772 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), | |
7f29673b TD |
773 | HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), |
774 | HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), | |
775 | HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), | |
776 | HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
777 | |
778 | /* Modes for retasking pin widgets */ | |
779 | CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), | |
780 | CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), | |
781 | ||
82f30040 TD |
782 | /* EAPD Switch Control */ |
783 | CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), | |
784 | ||
c9b443d4 | 785 | /* Loopback mixer controls */ |
7f29673b TD |
786 | |
787 | HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), | |
788 | HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), | |
789 | HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), | |
790 | HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), | |
791 | HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), | |
792 | HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), | |
793 | HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), | |
794 | HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), | |
795 | HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), | |
796 | HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), | |
c9b443d4 TD |
797 | { |
798 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
799 | .name = "Input Source", | |
800 | .info = conexant_mux_enum_info, | |
801 | .get = conexant_mux_enum_get, | |
802 | .put = conexant_mux_enum_put, | |
803 | }, | |
fb3409e7 TD |
804 | /* Audio input controls */ |
805 | HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), | |
806 | HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), | |
807 | HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), | |
808 | HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), | |
809 | HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), | |
810 | HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), | |
811 | HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), | |
812 | HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), | |
813 | HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), | |
814 | HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), | |
c9b443d4 TD |
815 | { } /* end */ |
816 | }; | |
817 | ||
818 | static struct hda_verb cxt5045_test_init_verbs[] = { | |
7f29673b TD |
819 | /* Set connections */ |
820 | { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
821 | { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
822 | { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
c9b443d4 TD |
823 | /* Enable retasking pins as output, initially without power amp */ |
824 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
7f29673b | 825 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
c9b443d4 TD |
826 | |
827 | /* Disable digital (SPDIF) pins initially, but users can enable | |
828 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
829 | * payload also sets the generation to 0, output to be in "consumer" | |
830 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
831 | * control. | |
832 | */ | |
cbef9789 TI |
833 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
834 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
c9b443d4 TD |
835 | |
836 | /* Start with output sum widgets muted and their output gains at min */ | |
837 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
838 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
839 | ||
840 | /* Unmute retasking pin widget output buffers since the default | |
841 | * state appears to be output. As the pin mode is changed by the | |
842 | * user the pin mode control will take care of enabling the pin's | |
843 | * input/output buffers as needed. | |
844 | */ | |
845 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
846 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
847 | ||
848 | /* Mute capture amp left and right */ | |
849 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
850 | ||
851 | /* Set ADC connection select to match default mixer setting (mic1 | |
852 | * pin) | |
853 | */ | |
854 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
7f29673b | 855 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, |
c9b443d4 TD |
856 | |
857 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
858 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ | |
859 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ | |
860 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ | |
861 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ | |
862 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
863 | ||
864 | { } | |
865 | }; | |
866 | #endif | |
867 | ||
868 | ||
869 | /* initialize jack-sensing, too */ | |
870 | static int cxt5045_init(struct hda_codec *codec) | |
871 | { | |
872 | conexant_init(codec); | |
873 | cxt5045_hp_automute(codec); | |
874 | return 0; | |
875 | } | |
876 | ||
877 | ||
878 | enum { | |
15908c36 MB |
879 | CXT5045_LAPTOP_HPSENSE, |
880 | CXT5045_LAPTOP_MICSENSE, | |
881 | CXT5045_LAPTOP_HPMICSENSE, | |
5218c892 | 882 | CXT5045_BENQ, |
2de3c232 | 883 | CXT5045_LAPTOP_HP530, |
c9b443d4 TD |
884 | #ifdef CONFIG_SND_DEBUG |
885 | CXT5045_TEST, | |
886 | #endif | |
f5fcc13c | 887 | CXT5045_MODELS |
c9b443d4 TD |
888 | }; |
889 | ||
f5fcc13c | 890 | static const char *cxt5045_models[CXT5045_MODELS] = { |
15908c36 MB |
891 | [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", |
892 | [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", | |
893 | [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", | |
894 | [CXT5045_BENQ] = "benq", | |
2de3c232 | 895 | [CXT5045_LAPTOP_HP530] = "laptop-hp530", |
c9b443d4 | 896 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 897 | [CXT5045_TEST] = "test", |
c9b443d4 | 898 | #endif |
f5fcc13c TI |
899 | }; |
900 | ||
901 | static struct snd_pci_quirk cxt5045_cfg_tbl[] = { | |
15908c36 MB |
902 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE), |
903 | SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE), | |
904 | SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE), | |
905 | SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE), | |
906 | SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE), | |
907 | SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE), | |
0f6a5156 | 908 | SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE), |
2de3c232 | 909 | SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), |
15908c36 | 910 | SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE), |
5218c892 | 911 | SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), |
15908c36 MB |
912 | SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), |
913 | SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), | |
914 | SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE), | |
915 | SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), | |
916 | SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), | |
917 | SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), | |
918 | SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), | |
919 | SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), | |
920 | SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), | |
c9b443d4 TD |
921 | {} |
922 | }; | |
923 | ||
924 | static int patch_cxt5045(struct hda_codec *codec) | |
925 | { | |
926 | struct conexant_spec *spec; | |
927 | int board_config; | |
928 | ||
929 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
930 | if (!spec) | |
931 | return -ENOMEM; | |
932 | mutex_init(&spec->amp_mutex); | |
933 | codec->spec = spec; | |
934 | ||
935 | spec->multiout.max_channels = 2; | |
936 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); | |
937 | spec->multiout.dac_nids = cxt5045_dac_nids; | |
938 | spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; | |
939 | spec->num_adc_nids = 1; | |
940 | spec->adc_nids = cxt5045_adc_nids; | |
941 | spec->capsrc_nids = cxt5045_capsrc_nids; | |
942 | spec->input_mux = &cxt5045_capture_source; | |
943 | spec->num_mixers = 1; | |
944 | spec->mixers[0] = cxt5045_mixers; | |
945 | spec->num_init_verbs = 1; | |
946 | spec->init_verbs[0] = cxt5045_init_verbs; | |
947 | spec->spdif_route = 0; | |
5cd57529 TD |
948 | spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), |
949 | spec->channel_mode = cxt5045_modes, | |
950 | ||
c9b443d4 TD |
951 | |
952 | codec->patch_ops = conexant_patch_ops; | |
c9b443d4 | 953 | |
f5fcc13c TI |
954 | board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, |
955 | cxt5045_models, | |
956 | cxt5045_cfg_tbl); | |
c9b443d4 | 957 | switch (board_config) { |
15908c36 | 958 | case CXT5045_LAPTOP_HPSENSE: |
7f29673b TD |
959 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
960 | spec->input_mux = &cxt5045_capture_source; | |
961 | spec->num_init_verbs = 2; | |
962 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | |
963 | spec->mixers[0] = cxt5045_mixers; | |
964 | codec->patch_ops.init = cxt5045_init; | |
965 | break; | |
15908c36 | 966 | case CXT5045_LAPTOP_MICSENSE: |
c9b443d4 TD |
967 | spec->input_mux = &cxt5045_capture_source; |
968 | spec->num_init_verbs = 2; | |
7f29673b | 969 | spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; |
c9b443d4 TD |
970 | spec->mixers[0] = cxt5045_mixers; |
971 | codec->patch_ops.init = cxt5045_init; | |
972 | break; | |
15908c36 MB |
973 | default: |
974 | case CXT5045_LAPTOP_HPMICSENSE: | |
975 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | |
976 | spec->input_mux = &cxt5045_capture_source; | |
977 | spec->num_init_verbs = 3; | |
978 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | |
979 | spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; | |
980 | spec->mixers[0] = cxt5045_mixers; | |
981 | codec->patch_ops.init = cxt5045_init; | |
982 | break; | |
5218c892 JZ |
983 | case CXT5045_BENQ: |
984 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | |
985 | spec->input_mux = &cxt5045_capture_source_benq; | |
986 | spec->num_init_verbs = 1; | |
987 | spec->init_verbs[0] = cxt5045_benq_init_verbs; | |
988 | spec->mixers[0] = cxt5045_mixers; | |
989 | spec->mixers[1] = cxt5045_benq_mixers; | |
990 | spec->num_mixers = 2; | |
991 | codec->patch_ops.init = cxt5045_init; | |
992 | break; | |
2de3c232 J |
993 | case CXT5045_LAPTOP_HP530: |
994 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | |
995 | spec->input_mux = &cxt5045_capture_source_hp530; | |
996 | spec->num_init_verbs = 2; | |
997 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | |
998 | spec->mixers[0] = cxt5045_mixers_hp530; | |
999 | codec->patch_ops.init = cxt5045_init; | |
1000 | break; | |
c9b443d4 TD |
1001 | #ifdef CONFIG_SND_DEBUG |
1002 | case CXT5045_TEST: | |
1003 | spec->input_mux = &cxt5045_test_capture_source; | |
1004 | spec->mixers[0] = cxt5045_test_mixer; | |
1005 | spec->init_verbs[0] = cxt5045_test_init_verbs; | |
15908c36 MB |
1006 | break; |
1007 | ||
c9b443d4 TD |
1008 | #endif |
1009 | } | |
48ecb7e8 TI |
1010 | |
1011 | /* | |
1012 | * Fix max PCM level to 0 dB | |
1013 | * (originall it has 0x2b steps with 0dB offset 0x14) | |
1014 | */ | |
1015 | snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, | |
1016 | (0x14 << AC_AMPCAP_OFFSET_SHIFT) | | |
1017 | (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
1018 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
1019 | (1 << AC_AMPCAP_MUTE_SHIFT)); | |
1020 | ||
c9b443d4 TD |
1021 | return 0; |
1022 | } | |
1023 | ||
1024 | ||
1025 | /* Conexant 5047 specific */ | |
82f30040 | 1026 | #define CXT5047_SPDIF_OUT 0x11 |
c9b443d4 | 1027 | |
82f30040 | 1028 | static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c }; |
c9b443d4 TD |
1029 | static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; |
1030 | static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; | |
c9b443d4 | 1031 | |
5cd57529 TD |
1032 | static struct hda_channel_mode cxt5047_modes[1] = { |
1033 | { 2, NULL }, | |
1034 | }; | |
c9b443d4 TD |
1035 | |
1036 | static struct hda_input_mux cxt5047_capture_source = { | |
7f29673b | 1037 | .num_items = 1, |
c9b443d4 | 1038 | .items = { |
7f29673b | 1039 | { "Mic", 0x2 }, |
c9b443d4 TD |
1040 | } |
1041 | }; | |
1042 | ||
1043 | static struct hda_input_mux cxt5047_hp_capture_source = { | |
1044 | .num_items = 1, | |
1045 | .items = { | |
82f30040 TD |
1046 | { "ExtMic", 0x2 }, |
1047 | } | |
1048 | }; | |
1049 | ||
1050 | static struct hda_input_mux cxt5047_toshiba_capture_source = { | |
1051 | .num_items = 2, | |
1052 | .items = { | |
1053 | { "ExtMic", 0x2 }, | |
1054 | { "Line-In", 0x1 }, | |
c9b443d4 TD |
1055 | } |
1056 | }; | |
1057 | ||
1058 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
1059 | static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
1060 | struct snd_ctl_elem_value *ucontrol) | |
1061 | { | |
1062 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1063 | struct conexant_spec *spec = codec->spec; | |
82f30040 | 1064 | unsigned int bits; |
c9b443d4 | 1065 | |
82f30040 | 1066 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
c9b443d4 TD |
1067 | return 0; |
1068 | ||
82f30040 TD |
1069 | /* toggle internal speakers mute depending of presence of |
1070 | * the headphone jack | |
1071 | */ | |
47fd830a TI |
1072 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
1073 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, | |
1074 | HDA_AMP_MUTE, bits); | |
1075 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; | |
1076 | snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, | |
1077 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
1078 | return 1; |
1079 | } | |
1080 | ||
82f30040 | 1081 | /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */ |
cca3b371 TI |
1082 | static struct hda_bind_ctls cxt5047_bind_master_vol = { |
1083 | .ops = &snd_hda_bind_vol, | |
1084 | .values = { | |
1085 | HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT), | |
1086 | HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT), | |
1087 | 0 | |
1088 | }, | |
1089 | }; | |
c9b443d4 TD |
1090 | |
1091 | /* mute internal speaker if HP is plugged */ | |
1092 | static void cxt5047_hp_automute(struct hda_codec *codec) | |
1093 | { | |
82f30040 | 1094 | struct conexant_spec *spec = codec->spec; |
dd87da1c | 1095 | unsigned int bits; |
c9b443d4 | 1096 | |
82f30040 | 1097 | spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, |
c9b443d4 | 1098 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
dd87da1c | 1099 | |
47fd830a TI |
1100 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
1101 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, | |
1102 | HDA_AMP_MUTE, bits); | |
82f30040 | 1103 | /* Mute/Unmute PCM 2 for good measure - some systems need this */ |
47fd830a TI |
1104 | snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, |
1105 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
1106 | } |
1107 | ||
fb3409e7 TD |
1108 | /* mute internal speaker if HP is plugged */ |
1109 | static void cxt5047_hp2_automute(struct hda_codec *codec) | |
1110 | { | |
1111 | struct conexant_spec *spec = codec->spec; | |
1112 | unsigned int bits; | |
1113 | ||
1114 | spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, | |
1115 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
1116 | ||
47fd830a TI |
1117 | bits = spec->hp_present ? HDA_AMP_MUTE : 0; |
1118 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, | |
1119 | HDA_AMP_MUTE, bits); | |
fb3409e7 | 1120 | /* Mute/Unmute PCM 2 for good measure - some systems need this */ |
47fd830a TI |
1121 | snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, |
1122 | HDA_AMP_MUTE, bits); | |
fb3409e7 TD |
1123 | } |
1124 | ||
c9b443d4 TD |
1125 | /* toggle input of built-in and mic jack appropriately */ |
1126 | static void cxt5047_hp_automic(struct hda_codec *codec) | |
1127 | { | |
1128 | static struct hda_verb mic_jack_on[] = { | |
9f113e0e MB |
1129 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
1130 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
c9b443d4 TD |
1131 | {} |
1132 | }; | |
1133 | static struct hda_verb mic_jack_off[] = { | |
9f113e0e MB |
1134 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
1135 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
c9b443d4 TD |
1136 | {} |
1137 | }; | |
1138 | unsigned int present; | |
1139 | ||
7f29673b | 1140 | present = snd_hda_codec_read(codec, 0x15, 0, |
c9b443d4 TD |
1141 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
1142 | if (present) | |
1143 | snd_hda_sequence_write(codec, mic_jack_on); | |
1144 | else | |
1145 | snd_hda_sequence_write(codec, mic_jack_off); | |
1146 | } | |
1147 | ||
1148 | /* unsolicited event for HP jack sensing */ | |
1149 | static void cxt5047_hp_unsol_event(struct hda_codec *codec, | |
1150 | unsigned int res) | |
1151 | { | |
9f113e0e | 1152 | switch (res >> 26) { |
c9b443d4 TD |
1153 | case CONEXANT_HP_EVENT: |
1154 | cxt5047_hp_automute(codec); | |
1155 | break; | |
1156 | case CONEXANT_MIC_EVENT: | |
1157 | cxt5047_hp_automic(codec); | |
1158 | break; | |
1159 | } | |
1160 | } | |
1161 | ||
fb3409e7 TD |
1162 | /* unsolicited event for HP jack sensing - non-EAPD systems */ |
1163 | static void cxt5047_hp2_unsol_event(struct hda_codec *codec, | |
1164 | unsigned int res) | |
1165 | { | |
1166 | res >>= 26; | |
1167 | switch (res) { | |
1168 | case CONEXANT_HP_EVENT: | |
1169 | cxt5047_hp2_automute(codec); | |
1170 | break; | |
1171 | case CONEXANT_MIC_EVENT: | |
1172 | cxt5047_hp_automic(codec); | |
1173 | break; | |
1174 | } | |
1175 | } | |
1176 | ||
c9b443d4 | 1177 | static struct snd_kcontrol_new cxt5047_mixers[] = { |
c9b443d4 TD |
1178 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), |
1179 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), | |
7f29673b TD |
1180 | HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT), |
1181 | HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1182 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), |
1183 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1184 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1185 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
82f30040 TD |
1186 | HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT), |
1187 | HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT), | |
b7589ceb TD |
1188 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT), |
1189 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT), | |
1190 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), | |
1191 | HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT), | |
82f30040 TD |
1192 | |
1193 | {} | |
1194 | }; | |
1195 | ||
1196 | static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = { | |
1197 | { | |
1198 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1199 | .name = "Capture Source", | |
1200 | .info = conexant_mux_enum_info, | |
1201 | .get = conexant_mux_enum_get, | |
1202 | .put = conexant_mux_enum_put | |
1203 | }, | |
1204 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), | |
1205 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), | |
1206 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), | |
1207 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1208 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1209 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
cca3b371 | 1210 | HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol), |
82f30040 TD |
1211 | { |
1212 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1213 | .name = "Master Playback Switch", | |
1214 | .info = cxt_eapd_info, | |
1215 | .get = cxt_eapd_get, | |
c9b443d4 TD |
1216 | .put = cxt5047_hp_master_sw_put, |
1217 | .private_value = 0x13, | |
1218 | }, | |
1219 | ||
1220 | {} | |
1221 | }; | |
1222 | ||
1223 | static struct snd_kcontrol_new cxt5047_hp_mixers[] = { | |
1224 | { | |
1225 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1226 | .name = "Capture Source", | |
1227 | .info = conexant_mux_enum_info, | |
1228 | .get = conexant_mux_enum_get, | |
1229 | .put = conexant_mux_enum_put | |
1230 | }, | |
1231 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), | |
1232 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT), | |
1233 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), | |
1234 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1235 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1236 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
1237 | HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), | |
1238 | { | |
1239 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1240 | .name = "Master Playback Switch", | |
82f30040 TD |
1241 | .info = cxt_eapd_info, |
1242 | .get = cxt_eapd_get, | |
c9b443d4 TD |
1243 | .put = cxt5047_hp_master_sw_put, |
1244 | .private_value = 0x13, | |
1245 | }, | |
1246 | { } /* end */ | |
1247 | }; | |
1248 | ||
1249 | static struct hda_verb cxt5047_init_verbs[] = { | |
1250 | /* Line in, Mic, Built-in Mic */ | |
1251 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
1252 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
1253 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
7f29673b | 1254 | /* HP, Speaker */ |
b7589ceb TD |
1255 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1256 | {0x13, AC_VERB_SET_CONNECT_SEL,0x1}, | |
82f30040 | 1257 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x0}, |
7f29673b | 1258 | /* Record selector: Mic */ |
c9b443d4 TD |
1259 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, |
1260 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, | |
1261 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
7f29673b TD |
1262 | {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, |
1263 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
1264 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, | |
1265 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
1266 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, | |
c9b443d4 TD |
1267 | /* SPDIF route: PCM */ |
1268 | { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
82f30040 TD |
1269 | /* Enable unsolicited events */ |
1270 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
1271 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
c9b443d4 TD |
1272 | { } /* end */ |
1273 | }; | |
1274 | ||
1275 | /* configuration for Toshiba Laptops */ | |
1276 | static struct hda_verb cxt5047_toshiba_init_verbs[] = { | |
1277 | {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ | |
1278 | /* pin sensing on HP and Mic jacks */ | |
1279 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
1280 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
82f30040 TD |
1281 | /* Speaker routing */ |
1282 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, | |
c9b443d4 TD |
1283 | {} |
1284 | }; | |
1285 | ||
1286 | /* configuration for HP Laptops */ | |
1287 | static struct hda_verb cxt5047_hp_init_verbs[] = { | |
82f30040 | 1288 | /* pin sensing on HP jack */ |
c9b443d4 | 1289 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
b84f08d4 TI |
1290 | /* 0x13 is actually shared by both HP and speaker; |
1291 | * setting the connection to 0 (=0x19) makes the master volume control | |
1292 | * working mysteriouslly... | |
1293 | */ | |
1294 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
82f30040 TD |
1295 | /* Record selector: Ext Mic */ |
1296 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, | |
82f30040 TD |
1297 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, |
1298 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
1299 | /* Speaker routing */ | |
1300 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, | |
c9b443d4 TD |
1301 | {} |
1302 | }; | |
1303 | ||
1304 | /* Test configuration for debugging, modelled after the ALC260 test | |
1305 | * configuration. | |
1306 | */ | |
1307 | #ifdef CONFIG_SND_DEBUG | |
1308 | static struct hda_input_mux cxt5047_test_capture_source = { | |
82f30040 | 1309 | .num_items = 4, |
c9b443d4 | 1310 | .items = { |
82f30040 TD |
1311 | { "LINE1 pin", 0x0 }, |
1312 | { "MIC1 pin", 0x1 }, | |
1313 | { "MIC2 pin", 0x2 }, | |
1314 | { "CD pin", 0x3 }, | |
c9b443d4 TD |
1315 | }, |
1316 | }; | |
1317 | ||
1318 | static struct snd_kcontrol_new cxt5047_test_mixer[] = { | |
1319 | ||
1320 | /* Output only controls */ | |
82f30040 TD |
1321 | HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), |
1322 | HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), | |
1323 | HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), | |
1324 | HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1325 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), |
1326 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), | |
1327 | HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
1328 | HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
82f30040 TD |
1329 | HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), |
1330 | HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), | |
1331 | HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), | |
1332 | HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1333 | |
1334 | /* Modes for retasking pin widgets */ | |
1335 | CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), | |
1336 | CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), | |
1337 | ||
82f30040 TD |
1338 | /* EAPD Switch Control */ |
1339 | CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), | |
c9b443d4 | 1340 | |
82f30040 TD |
1341 | /* Loopback mixer controls */ |
1342 | HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), | |
1343 | HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), | |
1344 | HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), | |
1345 | HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), | |
1346 | HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), | |
1347 | HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), | |
1348 | HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), | |
1349 | HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), | |
1350 | ||
1351 | HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), | |
1352 | HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), | |
1353 | HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), | |
1354 | HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), | |
1355 | HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), | |
1356 | HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), | |
1357 | HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), | |
1358 | HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), | |
c9b443d4 TD |
1359 | { |
1360 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1361 | .name = "Input Source", | |
1362 | .info = conexant_mux_enum_info, | |
1363 | .get = conexant_mux_enum_get, | |
1364 | .put = conexant_mux_enum_put, | |
1365 | }, | |
9f113e0e MB |
1366 | HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), |
1367 | HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), | |
1368 | HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), | |
1369 | HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), | |
1370 | HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), | |
1371 | HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), | |
1372 | HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), | |
1373 | HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), | |
1374 | HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), | |
1375 | HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), | |
1376 | ||
c9b443d4 TD |
1377 | { } /* end */ |
1378 | }; | |
1379 | ||
1380 | static struct hda_verb cxt5047_test_init_verbs[] = { | |
c9b443d4 TD |
1381 | /* Enable retasking pins as output, initially without power amp */ |
1382 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1383 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1384 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1385 | ||
1386 | /* Disable digital (SPDIF) pins initially, but users can enable | |
1387 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
1388 | * payload also sets the generation to 0, output to be in "consumer" | |
1389 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
1390 | * control. | |
1391 | */ | |
1392 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
1393 | ||
1394 | /* Ensure mic1, mic2, line1 pin widgets take input from the | |
1395 | * OUT1 sum bus when acting as an output. | |
1396 | */ | |
1397 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, | |
1398 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, | |
1399 | ||
1400 | /* Start with output sum widgets muted and their output gains at min */ | |
1401 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1402 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1403 | ||
1404 | /* Unmute retasking pin widget output buffers since the default | |
1405 | * state appears to be output. As the pin mode is changed by the | |
1406 | * user the pin mode control will take care of enabling the pin's | |
1407 | * input/output buffers as needed. | |
1408 | */ | |
1409 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1410 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1411 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1412 | ||
1413 | /* Mute capture amp left and right */ | |
1414 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1415 | ||
1416 | /* Set ADC connection select to match default mixer setting (mic1 | |
1417 | * pin) | |
1418 | */ | |
1419 | {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1420 | ||
1421 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
1422 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ | |
1423 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ | |
1424 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ | |
1425 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ | |
1426 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
1427 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ | |
1428 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ | |
1429 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ | |
1430 | ||
1431 | { } | |
1432 | }; | |
1433 | #endif | |
1434 | ||
1435 | ||
1436 | /* initialize jack-sensing, too */ | |
1437 | static int cxt5047_hp_init(struct hda_codec *codec) | |
1438 | { | |
1439 | conexant_init(codec); | |
1440 | cxt5047_hp_automute(codec); | |
c9b443d4 TD |
1441 | return 0; |
1442 | } | |
1443 | ||
1444 | ||
1445 | enum { | |
f5fcc13c TI |
1446 | CXT5047_LAPTOP, /* Laptops w/o EAPD support */ |
1447 | CXT5047_LAPTOP_HP, /* Some HP laptops */ | |
1448 | CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ | |
c9b443d4 TD |
1449 | #ifdef CONFIG_SND_DEBUG |
1450 | CXT5047_TEST, | |
1451 | #endif | |
f5fcc13c | 1452 | CXT5047_MODELS |
c9b443d4 TD |
1453 | }; |
1454 | ||
f5fcc13c TI |
1455 | static const char *cxt5047_models[CXT5047_MODELS] = { |
1456 | [CXT5047_LAPTOP] = "laptop", | |
1457 | [CXT5047_LAPTOP_HP] = "laptop-hp", | |
1458 | [CXT5047_LAPTOP_EAPD] = "laptop-eapd", | |
c9b443d4 | 1459 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 1460 | [CXT5047_TEST] = "test", |
c9b443d4 | 1461 | #endif |
f5fcc13c TI |
1462 | }; |
1463 | ||
1464 | static struct snd_pci_quirk cxt5047_cfg_tbl[] = { | |
1465 | SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP), | |
ac3e3741 | 1466 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), |
f5fcc13c | 1467 | SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP), |
82f30040 | 1468 | SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP), |
f5fcc13c | 1469 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), |
c9b443d4 TD |
1470 | {} |
1471 | }; | |
1472 | ||
1473 | static int patch_cxt5047(struct hda_codec *codec) | |
1474 | { | |
1475 | struct conexant_spec *spec; | |
1476 | int board_config; | |
1477 | ||
1478 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1479 | if (!spec) | |
1480 | return -ENOMEM; | |
1481 | mutex_init(&spec->amp_mutex); | |
1482 | codec->spec = spec; | |
1483 | ||
1484 | spec->multiout.max_channels = 2; | |
1485 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); | |
1486 | spec->multiout.dac_nids = cxt5047_dac_nids; | |
1487 | spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; | |
1488 | spec->num_adc_nids = 1; | |
1489 | spec->adc_nids = cxt5047_adc_nids; | |
1490 | spec->capsrc_nids = cxt5047_capsrc_nids; | |
1491 | spec->input_mux = &cxt5047_capture_source; | |
1492 | spec->num_mixers = 1; | |
1493 | spec->mixers[0] = cxt5047_mixers; | |
1494 | spec->num_init_verbs = 1; | |
1495 | spec->init_verbs[0] = cxt5047_init_verbs; | |
1496 | spec->spdif_route = 0; | |
5cd57529 TD |
1497 | spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), |
1498 | spec->channel_mode = cxt5047_modes, | |
c9b443d4 TD |
1499 | |
1500 | codec->patch_ops = conexant_patch_ops; | |
c9b443d4 | 1501 | |
f5fcc13c TI |
1502 | board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, |
1503 | cxt5047_models, | |
1504 | cxt5047_cfg_tbl); | |
c9b443d4 TD |
1505 | switch (board_config) { |
1506 | case CXT5047_LAPTOP: | |
fb3409e7 | 1507 | codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event; |
c9b443d4 TD |
1508 | break; |
1509 | case CXT5047_LAPTOP_HP: | |
1510 | spec->input_mux = &cxt5047_hp_capture_source; | |
1511 | spec->num_init_verbs = 2; | |
1512 | spec->init_verbs[1] = cxt5047_hp_init_verbs; | |
1513 | spec->mixers[0] = cxt5047_hp_mixers; | |
fb3409e7 | 1514 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1515 | codec->patch_ops.init = cxt5047_hp_init; |
1516 | break; | |
1517 | case CXT5047_LAPTOP_EAPD: | |
82f30040 | 1518 | spec->input_mux = &cxt5047_toshiba_capture_source; |
c9b443d4 TD |
1519 | spec->num_init_verbs = 2; |
1520 | spec->init_verbs[1] = cxt5047_toshiba_init_verbs; | |
82f30040 | 1521 | spec->mixers[0] = cxt5047_toshiba_mixers; |
fb3409e7 | 1522 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1523 | break; |
1524 | #ifdef CONFIG_SND_DEBUG | |
1525 | case CXT5047_TEST: | |
1526 | spec->input_mux = &cxt5047_test_capture_source; | |
1527 | spec->mixers[0] = cxt5047_test_mixer; | |
1528 | spec->init_verbs[0] = cxt5047_test_init_verbs; | |
fb3409e7 | 1529 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1530 | #endif |
1531 | } | |
1532 | return 0; | |
1533 | } | |
1534 | ||
461e2c78 TI |
1535 | /* Conexant 5051 specific */ |
1536 | static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; | |
1537 | static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; | |
1538 | #define CXT5051_SPDIF_OUT 0x1C | |
1539 | #define CXT5051_PORTB_EVENT 0x38 | |
1540 | #define CXT5051_PORTC_EVENT 0x39 | |
1541 | ||
1542 | static struct hda_channel_mode cxt5051_modes[1] = { | |
1543 | { 2, NULL }, | |
1544 | }; | |
1545 | ||
1546 | static void cxt5051_update_speaker(struct hda_codec *codec) | |
1547 | { | |
1548 | struct conexant_spec *spec = codec->spec; | |
1549 | unsigned int pinctl; | |
1550 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; | |
1551 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1552 | pinctl); | |
1553 | } | |
1554 | ||
1555 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
1556 | static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
1557 | struct snd_ctl_elem_value *ucontrol) | |
1558 | { | |
1559 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1560 | ||
1561 | if (!cxt_eapd_put(kcontrol, ucontrol)) | |
1562 | return 0; | |
1563 | cxt5051_update_speaker(codec); | |
1564 | return 1; | |
1565 | } | |
1566 | ||
1567 | /* toggle input of built-in and mic jack appropriately */ | |
1568 | static void cxt5051_portb_automic(struct hda_codec *codec) | |
1569 | { | |
1570 | unsigned int present; | |
1571 | ||
1572 | present = snd_hda_codec_read(codec, 0x17, 0, | |
1573 | AC_VERB_GET_PIN_SENSE, 0) & | |
1574 | AC_PINSENSE_PRESENCE; | |
1575 | snd_hda_codec_write(codec, 0x14, 0, | |
1576 | AC_VERB_SET_CONNECT_SEL, | |
1577 | present ? 0x01 : 0x00); | |
1578 | } | |
1579 | ||
1580 | /* switch the current ADC according to the jack state */ | |
1581 | static void cxt5051_portc_automic(struct hda_codec *codec) | |
1582 | { | |
1583 | struct conexant_spec *spec = codec->spec; | |
1584 | unsigned int present; | |
1585 | hda_nid_t new_adc; | |
1586 | ||
1587 | present = snd_hda_codec_read(codec, 0x18, 0, | |
1588 | AC_VERB_GET_PIN_SENSE, 0) & | |
1589 | AC_PINSENSE_PRESENCE; | |
1590 | if (present) | |
1591 | spec->cur_adc_idx = 1; | |
1592 | else | |
1593 | spec->cur_adc_idx = 0; | |
1594 | new_adc = spec->adc_nids[spec->cur_adc_idx]; | |
1595 | if (spec->cur_adc && spec->cur_adc != new_adc) { | |
1596 | /* stream is running, let's swap the current ADC */ | |
1597 | snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); | |
1598 | spec->cur_adc = new_adc; | |
1599 | snd_hda_codec_setup_stream(codec, new_adc, | |
1600 | spec->cur_adc_stream_tag, 0, | |
1601 | spec->cur_adc_format); | |
1602 | } | |
1603 | } | |
1604 | ||
1605 | /* mute internal speaker if HP is plugged */ | |
1606 | static void cxt5051_hp_automute(struct hda_codec *codec) | |
1607 | { | |
1608 | struct conexant_spec *spec = codec->spec; | |
1609 | ||
1610 | spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, | |
1611 | AC_VERB_GET_PIN_SENSE, 0) & | |
1612 | AC_PINSENSE_PRESENCE; | |
1613 | cxt5051_update_speaker(codec); | |
1614 | } | |
1615 | ||
1616 | /* unsolicited event for HP jack sensing */ | |
1617 | static void cxt5051_hp_unsol_event(struct hda_codec *codec, | |
1618 | unsigned int res) | |
1619 | { | |
1620 | switch (res >> 26) { | |
1621 | case CONEXANT_HP_EVENT: | |
1622 | cxt5051_hp_automute(codec); | |
1623 | break; | |
1624 | case CXT5051_PORTB_EVENT: | |
1625 | cxt5051_portb_automic(codec); | |
1626 | break; | |
1627 | case CXT5051_PORTC_EVENT: | |
1628 | cxt5051_portc_automic(codec); | |
1629 | break; | |
1630 | } | |
1631 | } | |
1632 | ||
1633 | static struct snd_kcontrol_new cxt5051_mixers[] = { | |
1634 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), | |
1635 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | |
1636 | HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), | |
1637 | HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), | |
1638 | HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), | |
1639 | HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), | |
1640 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), | |
1641 | { | |
1642 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1643 | .name = "Master Playback Switch", | |
1644 | .info = cxt_eapd_info, | |
1645 | .get = cxt_eapd_get, | |
1646 | .put = cxt5051_hp_master_sw_put, | |
1647 | .private_value = 0x1a, | |
1648 | }, | |
1649 | ||
1650 | {} | |
1651 | }; | |
1652 | ||
1653 | static struct snd_kcontrol_new cxt5051_hp_mixers[] = { | |
1654 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), | |
1655 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | |
1656 | HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), | |
1657 | HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), | |
1658 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), | |
1659 | { | |
1660 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1661 | .name = "Master Playback Switch", | |
1662 | .info = cxt_eapd_info, | |
1663 | .get = cxt_eapd_get, | |
1664 | .put = cxt5051_hp_master_sw_put, | |
1665 | .private_value = 0x1a, | |
1666 | }, | |
1667 | ||
1668 | {} | |
1669 | }; | |
1670 | ||
1671 | static struct hda_verb cxt5051_init_verbs[] = { | |
1672 | /* Line in, Mic */ | |
1673 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1674 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1675 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1676 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1677 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
1678 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1679 | /* SPK */ | |
1680 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1681 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1682 | /* HP, Amp */ | |
1683 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1684 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1685 | /* DAC1 */ | |
1686 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1687 | /* Record selector: Int mic */ | |
1688 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, | |
1689 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, | |
1690 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, | |
1691 | /* SPDIF route: PCM */ | |
1692 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
1693 | /* EAPD */ | |
1694 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
1695 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | |
1696 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, | |
1697 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT}, | |
1698 | { } /* end */ | |
1699 | }; | |
1700 | ||
1701 | /* initialize jack-sensing, too */ | |
1702 | static int cxt5051_init(struct hda_codec *codec) | |
1703 | { | |
1704 | conexant_init(codec); | |
1705 | if (codec->patch_ops.unsol_event) { | |
1706 | cxt5051_hp_automute(codec); | |
1707 | cxt5051_portb_automic(codec); | |
1708 | cxt5051_portc_automic(codec); | |
1709 | } | |
1710 | return 0; | |
1711 | } | |
1712 | ||
1713 | ||
1714 | enum { | |
1715 | CXT5051_LAPTOP, /* Laptops w/ EAPD support */ | |
1716 | CXT5051_HP, /* no docking */ | |
1717 | CXT5051_MODELS | |
1718 | }; | |
1719 | ||
1720 | static const char *cxt5051_models[CXT5051_MODELS] = { | |
1721 | [CXT5051_LAPTOP] = "laptop", | |
1722 | [CXT5051_HP] = "hp", | |
1723 | }; | |
1724 | ||
1725 | static struct snd_pci_quirk cxt5051_cfg_tbl[] = { | |
1726 | SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", | |
1727 | CXT5051_LAPTOP), | |
1728 | SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), | |
1729 | {} | |
1730 | }; | |
1731 | ||
1732 | static int patch_cxt5051(struct hda_codec *codec) | |
1733 | { | |
1734 | struct conexant_spec *spec; | |
1735 | int board_config; | |
1736 | ||
1737 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1738 | if (!spec) | |
1739 | return -ENOMEM; | |
1740 | mutex_init(&spec->amp_mutex); | |
1741 | codec->spec = spec; | |
1742 | ||
1743 | codec->patch_ops = conexant_patch_ops; | |
1744 | codec->patch_ops.init = cxt5051_init; | |
1745 | ||
1746 | spec->multiout.max_channels = 2; | |
1747 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); | |
1748 | spec->multiout.dac_nids = cxt5051_dac_nids; | |
1749 | spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; | |
1750 | spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ | |
1751 | spec->adc_nids = cxt5051_adc_nids; | |
1752 | spec->num_mixers = 1; | |
1753 | spec->mixers[0] = cxt5051_mixers; | |
1754 | spec->num_init_verbs = 1; | |
1755 | spec->init_verbs[0] = cxt5051_init_verbs; | |
1756 | spec->spdif_route = 0; | |
1757 | spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); | |
1758 | spec->channel_mode = cxt5051_modes; | |
1759 | spec->cur_adc = 0; | |
1760 | spec->cur_adc_idx = 0; | |
1761 | ||
1762 | board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, | |
1763 | cxt5051_models, | |
1764 | cxt5051_cfg_tbl); | |
1765 | switch (board_config) { | |
1766 | case CXT5051_HP: | |
1767 | codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; | |
1768 | spec->mixers[0] = cxt5051_hp_mixers; | |
1769 | break; | |
1770 | default: | |
1771 | case CXT5051_LAPTOP: | |
1772 | codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; | |
1773 | break; | |
1774 | } | |
1775 | ||
1776 | return 0; | |
1777 | } | |
1778 | ||
1779 | ||
1780 | /* | |
1781 | */ | |
1782 | ||
c9b443d4 | 1783 | struct hda_codec_preset snd_hda_preset_conexant[] = { |
82f30040 TD |
1784 | { .id = 0x14f15045, .name = "CX20549 (Venice)", |
1785 | .patch = patch_cxt5045 }, | |
1786 | { .id = 0x14f15047, .name = "CX20551 (Waikiki)", | |
1787 | .patch = patch_cxt5047 }, | |
461e2c78 TI |
1788 | { .id = 0x14f15051, .name = "CX20561 (Hermosa)", |
1789 | .patch = patch_cxt5051 }, | |
c9b443d4 TD |
1790 | {} /* terminator */ |
1791 | }; |