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