]>
Commit | Line | Data |
---|---|---|
c9b443d4 TD |
1 | /* |
2 | * HD audio interface patch for Conexant HDA audio codec | |
3 | * | |
4 | * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> | |
5 | * Takashi Iwai <tiwai@suse.de> | |
6 | * Tobin Davis <tdavis@dsl-only.net> | |
7 | * | |
8 | * This driver is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This driver is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | */ | |
22 | ||
23 | #include <sound/driver.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/delay.h> | |
26 | #include <linux/slab.h> | |
27 | #include <linux/pci.h> | |
28 | #include <sound/core.h> | |
29 | #include "hda_codec.h" | |
30 | #include "hda_local.h" | |
31 | ||
32 | #define CXT_PIN_DIR_IN 0x00 | |
33 | #define CXT_PIN_DIR_OUT 0x01 | |
34 | #define CXT_PIN_DIR_INOUT 0x02 | |
35 | #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 | |
36 | #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 | |
37 | ||
38 | #define CONEXANT_HP_EVENT 0x37 | |
39 | #define CONEXANT_MIC_EVENT 0x38 | |
40 | ||
41 | ||
42 | ||
43 | struct conexant_spec { | |
44 | ||
45 | struct snd_kcontrol_new *mixers[5]; | |
46 | int num_mixers; | |
47 | ||
48 | const struct hda_verb *init_verbs[5]; /* initialization verbs | |
49 | * don't forget NULL | |
50 | * termination! | |
51 | */ | |
52 | unsigned int num_init_verbs; | |
53 | ||
54 | /* playback */ | |
55 | struct hda_multi_out multiout; /* playback set-up | |
56 | * max_channels, dacs must be set | |
57 | * dig_out_nid and hp_nid are optional | |
58 | */ | |
59 | unsigned int cur_eapd; | |
60 | unsigned int need_dac_fix; | |
61 | ||
62 | /* capture */ | |
63 | unsigned int num_adc_nids; | |
64 | hda_nid_t *adc_nids; | |
65 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ | |
66 | ||
67 | /* capture source */ | |
68 | const struct hda_input_mux *input_mux; | |
69 | hda_nid_t *capsrc_nids; | |
70 | unsigned int cur_mux[3]; | |
71 | ||
72 | /* channel model */ | |
73 | const struct hda_channel_mode *channel_mode; | |
74 | int num_channel_mode; | |
75 | ||
76 | /* PCM information */ | |
77 | struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ | |
78 | ||
79 | struct mutex amp_mutex; /* PCM volume/mute control mutex */ | |
80 | unsigned int spdif_route; | |
81 | ||
82 | /* dynamic controls, init_verbs and input_mux */ | |
83 | struct auto_pin_cfg autocfg; | |
84 | unsigned int num_kctl_alloc, num_kctl_used; | |
85 | struct snd_kcontrol_new *kctl_alloc; | |
86 | struct hda_input_mux private_imux; | |
87 | hda_nid_t private_dac_nids[4]; | |
88 | ||
89 | }; | |
90 | ||
91 | static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
92 | struct hda_codec *codec, | |
93 | struct snd_pcm_substream *substream) | |
94 | { | |
95 | struct conexant_spec *spec = codec->spec; | |
96 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); | |
97 | } | |
98 | ||
99 | static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
100 | struct hda_codec *codec, | |
101 | unsigned int stream_tag, | |
102 | unsigned int format, | |
103 | struct snd_pcm_substream *substream) | |
104 | { | |
105 | struct conexant_spec *spec = codec->spec; | |
106 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | |
107 | stream_tag, | |
108 | format, substream); | |
109 | } | |
110 | ||
111 | static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
112 | struct hda_codec *codec, | |
113 | struct snd_pcm_substream *substream) | |
114 | { | |
115 | struct conexant_spec *spec = codec->spec; | |
116 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
117 | } | |
118 | ||
119 | /* | |
120 | * Digital out | |
121 | */ | |
122 | static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
123 | struct hda_codec *codec, | |
124 | struct snd_pcm_substream *substream) | |
125 | { | |
126 | struct conexant_spec *spec = codec->spec; | |
127 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
128 | } | |
129 | ||
130 | static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
131 | struct hda_codec *codec, | |
132 | struct snd_pcm_substream *substream) | |
133 | { | |
134 | struct conexant_spec *spec = codec->spec; | |
135 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
136 | } | |
137 | ||
138 | /* | |
139 | * Analog capture | |
140 | */ | |
141 | static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
142 | struct hda_codec *codec, | |
143 | unsigned int stream_tag, | |
144 | unsigned int format, | |
145 | struct snd_pcm_substream *substream) | |
146 | { | |
147 | struct conexant_spec *spec = codec->spec; | |
148 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
149 | stream_tag, 0, format); | |
150 | return 0; | |
151 | } | |
152 | ||
153 | static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
154 | struct hda_codec *codec, | |
155 | struct snd_pcm_substream *substream) | |
156 | { | |
157 | struct conexant_spec *spec = codec->spec; | |
158 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
159 | 0, 0, 0); | |
160 | return 0; | |
161 | } | |
162 | ||
163 | ||
164 | ||
165 | static struct hda_pcm_stream conexant_pcm_analog_playback = { | |
166 | .substreams = 1, | |
167 | .channels_min = 2, | |
168 | .channels_max = 2, | |
169 | .nid = 0, /* fill later */ | |
170 | .ops = { | |
171 | .open = conexant_playback_pcm_open, | |
172 | .prepare = conexant_playback_pcm_prepare, | |
173 | .cleanup = conexant_playback_pcm_cleanup | |
174 | }, | |
175 | }; | |
176 | ||
177 | static struct hda_pcm_stream conexant_pcm_analog_capture = { | |
178 | .substreams = 1, | |
179 | .channels_min = 2, | |
180 | .channels_max = 2, | |
181 | .nid = 0, /* fill later */ | |
182 | .ops = { | |
183 | .prepare = conexant_capture_pcm_prepare, | |
184 | .cleanup = conexant_capture_pcm_cleanup | |
185 | }, | |
186 | }; | |
187 | ||
188 | ||
189 | static struct hda_pcm_stream conexant_pcm_digital_playback = { | |
190 | .substreams = 1, | |
191 | .channels_min = 2, | |
192 | .channels_max = 2, | |
193 | .nid = 0, /* fill later */ | |
194 | .ops = { | |
195 | .open = conexant_dig_playback_pcm_open, | |
196 | .close = conexant_dig_playback_pcm_close | |
197 | }, | |
198 | }; | |
199 | ||
200 | static struct hda_pcm_stream conexant_pcm_digital_capture = { | |
201 | .substreams = 1, | |
202 | .channels_min = 2, | |
203 | .channels_max = 2, | |
204 | /* NID is set in alc_build_pcms */ | |
205 | }; | |
206 | ||
207 | static int conexant_build_pcms(struct hda_codec *codec) | |
208 | { | |
209 | struct conexant_spec *spec = codec->spec; | |
210 | struct hda_pcm *info = spec->pcm_rec; | |
211 | ||
212 | codec->num_pcms = 1; | |
213 | codec->pcm_info = info; | |
214 | ||
215 | info->name = "CONEXANT Analog"; | |
216 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; | |
217 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | |
218 | spec->multiout.max_channels; | |
219 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
220 | spec->multiout.dac_nids[0]; | |
221 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture; | |
222 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; | |
223 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | |
224 | ||
225 | if (spec->multiout.dig_out_nid) { | |
226 | info++; | |
227 | codec->num_pcms++; | |
228 | info->name = "Conexant Digital"; | |
229 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | |
230 | conexant_pcm_digital_playback; | |
231 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
232 | spec->multiout.dig_out_nid; | |
233 | if (spec->dig_in_nid) { | |
234 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
235 | conexant_pcm_digital_capture; | |
236 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | |
237 | spec->dig_in_nid; | |
238 | } | |
239 | } | |
240 | ||
241 | return 0; | |
242 | } | |
243 | ||
244 | static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, | |
245 | struct snd_ctl_elem_info *uinfo) | |
246 | { | |
247 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
248 | struct conexant_spec *spec = codec->spec; | |
249 | ||
250 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | |
251 | } | |
252 | ||
253 | static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, | |
254 | struct snd_ctl_elem_value *ucontrol) | |
255 | { | |
256 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
257 | struct conexant_spec *spec = codec->spec; | |
258 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
259 | ||
260 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
261 | return 0; | |
262 | } | |
263 | ||
264 | static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, | |
265 | struct snd_ctl_elem_value *ucontrol) | |
266 | { | |
267 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
268 | struct conexant_spec *spec = codec->spec; | |
269 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
270 | ||
271 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
272 | spec->capsrc_nids[adc_idx], | |
273 | &spec->cur_mux[adc_idx]); | |
274 | } | |
275 | ||
276 | static int conexant_init(struct hda_codec *codec) | |
277 | { | |
278 | struct conexant_spec *spec = codec->spec; | |
279 | int i; | |
280 | ||
281 | for (i = 0; i < spec->num_init_verbs; i++) | |
282 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
283 | return 0; | |
284 | } | |
285 | ||
286 | static void conexant_free(struct hda_codec *codec) | |
287 | { | |
288 | struct conexant_spec *spec = codec->spec; | |
289 | unsigned int i; | |
290 | ||
291 | if (spec->kctl_alloc) { | |
292 | for (i = 0; i < spec->num_kctl_used; i++) | |
293 | kfree(spec->kctl_alloc[i].name); | |
294 | kfree(spec->kctl_alloc); | |
295 | } | |
296 | ||
297 | kfree(codec->spec); | |
298 | } | |
299 | ||
300 | #ifdef CONFIG_PM | |
301 | static int conexant_resume(struct hda_codec *codec) | |
302 | { | |
303 | struct conexant_spec *spec = codec->spec; | |
304 | int i; | |
305 | ||
306 | codec->patch_ops.init(codec); | |
307 | for (i = 0; i < spec->num_mixers; i++) | |
308 | snd_hda_resume_ctls(codec, spec->mixers[i]); | |
309 | if (spec->multiout.dig_out_nid) | |
310 | snd_hda_resume_spdif_out(codec); | |
311 | if (spec->dig_in_nid) | |
312 | snd_hda_resume_spdif_in(codec); | |
313 | return 0; | |
314 | } | |
315 | #endif | |
316 | ||
317 | static int conexant_build_controls(struct hda_codec *codec) | |
318 | { | |
319 | struct conexant_spec *spec = codec->spec; | |
320 | unsigned int i; | |
321 | int err; | |
322 | ||
323 | for (i = 0; i < spec->num_mixers; i++) { | |
324 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
325 | if (err < 0) | |
326 | return err; | |
327 | } | |
328 | if (spec->multiout.dig_out_nid) { | |
329 | err = snd_hda_create_spdif_out_ctls(codec, | |
330 | spec->multiout.dig_out_nid); | |
331 | if (err < 0) | |
332 | return err; | |
333 | } | |
334 | if (spec->dig_in_nid) { | |
335 | err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); | |
336 | if (err < 0) | |
337 | return err; | |
338 | } | |
339 | return 0; | |
340 | } | |
341 | ||
342 | static struct hda_codec_ops conexant_patch_ops = { | |
343 | .build_controls = conexant_build_controls, | |
344 | .build_pcms = conexant_build_pcms, | |
345 | .init = conexant_init, | |
346 | .free = conexant_free, | |
347 | #ifdef CONFIG_PM | |
348 | .resume = conexant_resume, | |
349 | #endif | |
350 | }; | |
351 | ||
352 | /* | |
353 | * EAPD control | |
354 | * the private value = nid | (invert << 8) | |
355 | */ | |
356 | ||
357 | static int conexant_eapd_info(struct snd_kcontrol *kcontrol, | |
358 | struct snd_ctl_elem_info *uinfo) | |
359 | { | |
360 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
361 | uinfo->count = 1; | |
362 | uinfo->value.integer.min = 0; | |
363 | uinfo->value.integer.max = 1; | |
364 | return 0; | |
365 | } | |
366 | ||
367 | static int conexant_eapd_get(struct snd_kcontrol *kcontrol, | |
368 | struct snd_ctl_elem_value *ucontrol) | |
369 | { | |
370 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
371 | struct conexant_spec *spec = codec->spec; | |
372 | int invert = (kcontrol->private_value >> 8) & 1; | |
373 | if (invert) | |
374 | ucontrol->value.integer.value[0] = !spec->cur_eapd; | |
375 | else | |
376 | ucontrol->value.integer.value[0] = spec->cur_eapd; | |
377 | return 0; | |
378 | } | |
379 | ||
380 | static int conexant_eapd_put(struct snd_kcontrol *kcontrol, | |
381 | struct snd_ctl_elem_value *ucontrol) | |
382 | { | |
383 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
384 | struct conexant_spec *spec = codec->spec; | |
385 | int invert = (kcontrol->private_value >> 8) & 1; | |
386 | hda_nid_t nid = kcontrol->private_value & 0xff; | |
387 | unsigned int eapd; | |
388 | eapd = ucontrol->value.integer.value[0]; | |
389 | if (invert) | |
390 | eapd = !eapd; | |
391 | if (eapd == spec->cur_eapd && !codec->in_resume) | |
392 | return 0; | |
393 | spec->cur_eapd = eapd; | |
394 | snd_hda_codec_write(codec, nid, | |
395 | 0, AC_VERB_SET_EAPD_BTLENABLE, | |
396 | eapd ? 0x02 : 0x00); | |
397 | return 1; | |
398 | } | |
399 | ||
400 | static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, | |
401 | struct snd_ctl_elem_info *uinfo) | |
402 | { | |
403 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
404 | struct conexant_spec *spec = codec->spec; | |
405 | return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, | |
406 | spec->num_channel_mode); | |
407 | } | |
408 | ||
409 | static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, | |
410 | struct snd_ctl_elem_value *ucontrol) | |
411 | { | |
412 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
413 | struct conexant_spec *spec = codec->spec; | |
414 | return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, | |
415 | spec->num_channel_mode, | |
416 | spec->multiout.max_channels); | |
417 | } | |
418 | ||
419 | static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, | |
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 err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, | |
425 | spec->num_channel_mode, | |
426 | &spec->multiout.max_channels); | |
427 | if (err >= 0 && spec->need_dac_fix) | |
428 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; | |
429 | return err; | |
430 | } | |
431 | ||
432 | #define CXT_PIN_MODE(xname, nid, dir) \ | |
433 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
434 | .info = conexant_ch_mode_info, \ | |
435 | .get = conexant_ch_mode_get, \ | |
436 | .put = conexant_ch_mode_put, \ | |
437 | .private_value = nid | (dir<<16) } | |
438 | ||
439 | static int cxt_gpio_data_info(struct snd_kcontrol *kcontrol, | |
440 | struct snd_ctl_elem_info *uinfo) | |
441 | { | |
442 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
443 | uinfo->count = 1; | |
444 | uinfo->value.integer.min = 0; | |
445 | uinfo->value.integer.max = 1; | |
446 | return 0; | |
447 | } | |
448 | ||
449 | static int cxt_gpio_data_get(struct snd_kcontrol *kcontrol, | |
450 | struct snd_ctl_elem_value *ucontrol) | |
451 | { | |
452 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
453 | hda_nid_t nid = kcontrol->private_value & 0xffff; | |
454 | unsigned char mask = (kcontrol->private_value >> 16) & 0xff; | |
455 | long *valp = ucontrol->value.integer.value; | |
456 | unsigned int val = snd_hda_codec_read(codec, nid, 0, | |
457 | AC_VERB_GET_GPIO_DATA, 0x00); | |
458 | ||
459 | *valp = (val & mask) != 0; | |
460 | return 0; | |
461 | } | |
462 | ||
463 | static int cxt_gpio_data_put(struct snd_kcontrol *kcontrol, | |
464 | struct snd_ctl_elem_value *ucontrol) | |
465 | { | |
466 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
467 | hda_nid_t nid = kcontrol->private_value & 0xffff; | |
468 | unsigned char mask = (kcontrol->private_value >> 16) & 0xff; | |
469 | long val = *ucontrol->value.integer.value; | |
470 | unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0, | |
471 | AC_VERB_GET_GPIO_DATA, | |
472 | 0x00); | |
473 | unsigned int old_data = gpio_data; | |
474 | ||
475 | /* Set/unset the masked GPIO bit(s) as needed */ | |
476 | if (val == 0) | |
477 | gpio_data &= ~mask; | |
478 | else | |
479 | gpio_data |= mask; | |
480 | if (gpio_data == old_data && !codec->in_resume) | |
481 | return 0; | |
482 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data); | |
483 | return 1; | |
484 | } | |
485 | ||
486 | #define CXT_GPIO_DATA_SWITCH(xname, nid, mask) \ | |
487 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
488 | .info = cxt_gpio_data_info, \ | |
489 | .get = cxt_gpio_data_get, \ | |
490 | .put = cxt_gpio_data_put, \ | |
491 | .private_value = nid | (mask<<16) } | |
492 | ||
493 | static int cxt_spdif_ctrl_info(struct snd_kcontrol *kcontrol, | |
494 | struct snd_ctl_elem_info *uinfo) | |
495 | { | |
496 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
497 | uinfo->count = 1; | |
498 | uinfo->value.integer.min = 0; | |
499 | uinfo->value.integer.max = 1; | |
500 | return 0; | |
501 | } | |
502 | ||
503 | static int cxt_spdif_ctrl_get(struct snd_kcontrol *kcontrol, | |
504 | struct snd_ctl_elem_value *ucontrol) | |
505 | { | |
506 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
507 | hda_nid_t nid = kcontrol->private_value & 0xffff; | |
508 | unsigned char mask = (kcontrol->private_value >> 16) & 0xff; | |
509 | long *valp = ucontrol->value.integer.value; | |
510 | unsigned int val = snd_hda_codec_read(codec, nid, 0, | |
511 | AC_VERB_GET_DIGI_CONVERT, 0x00); | |
512 | ||
513 | *valp = (val & mask) != 0; | |
514 | return 0; | |
515 | } | |
516 | ||
517 | static int cxt_spdif_ctrl_put(struct snd_kcontrol *kcontrol, | |
518 | struct snd_ctl_elem_value *ucontrol) | |
519 | { | |
520 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
521 | hda_nid_t nid = kcontrol->private_value & 0xffff; | |
522 | unsigned char mask = (kcontrol->private_value >> 16) & 0xff; | |
523 | long val = *ucontrol->value.integer.value; | |
524 | unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0, | |
525 | AC_VERB_GET_DIGI_CONVERT, | |
526 | 0x00); | |
527 | unsigned int old_data = ctrl_data; | |
528 | ||
529 | /* Set/unset the masked control bit(s) as needed */ | |
530 | if (val == 0) | |
531 | ctrl_data &= ~mask; | |
532 | else | |
533 | ctrl_data |= mask; | |
534 | if (ctrl_data == old_data && !codec->in_resume) | |
535 | return 0; | |
536 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, | |
537 | ctrl_data); | |
538 | return 1; | |
539 | } | |
540 | ||
541 | #define CXT_SPDIF_CTRL_SWITCH(xname, nid, mask) \ | |
542 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
543 | .info = cxt_spdif_ctrl_info, \ | |
544 | .get = cxt_spdif_ctrl_get, \ | |
545 | .put = cxt_spdif_ctrl_put, \ | |
546 | .private_value = nid | (mask<<16) } | |
547 | ||
548 | /* Conexant 5045 specific */ | |
549 | ||
550 | static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; | |
551 | static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; | |
552 | static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; | |
553 | #define CXT5045_SPDIF_OUT 0x13 | |
554 | ||
5cd57529 TD |
555 | static struct hda_channel_mode cxt5045_modes[1] = { |
556 | { 2, NULL }, | |
557 | }; | |
c9b443d4 TD |
558 | |
559 | static struct hda_input_mux cxt5045_capture_source = { | |
560 | .num_items = 2, | |
561 | .items = { | |
562 | { "ExtMic", 0x1 }, | |
563 | { "LineIn", 0x2 }, | |
564 | } | |
565 | }; | |
566 | ||
567 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
568 | static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
569 | struct snd_ctl_elem_value *ucontrol) | |
570 | { | |
571 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
572 | struct conexant_spec *spec = codec->spec; | |
573 | ||
574 | if (!conexant_eapd_put(kcontrol, ucontrol)) | |
575 | return 0; | |
576 | ||
577 | /* toggle HP mute appropriately */ | |
578 | snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, | |
579 | 0x80, spec->cur_eapd ? 0 : 0x80); | |
580 | snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, | |
581 | 0x80, spec->cur_eapd ? 0 : 0x80); | |
582 | return 1; | |
583 | } | |
584 | ||
585 | /* bind volumes of both NID 0x10 and 0x11 */ | |
586 | static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol, | |
587 | struct snd_ctl_elem_value *ucontrol) | |
588 | { | |
589 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
590 | long *valp = ucontrol->value.integer.value; | |
591 | int change; | |
592 | ||
593 | change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, | |
594 | 0x7f, valp[0] & 0x7f); | |
595 | change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, | |
596 | 0x7f, valp[1] & 0x7f); | |
597 | snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, | |
598 | 0x7f, valp[0] & 0x7f); | |
599 | snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, | |
600 | 0x7f, valp[1] & 0x7f); | |
601 | return change; | |
602 | } | |
603 | ||
604 | ||
605 | /* mute internal speaker if HP is plugged */ | |
606 | static void cxt5045_hp_automute(struct hda_codec *codec) | |
607 | { | |
608 | unsigned int present; | |
609 | ||
610 | present = snd_hda_codec_read(codec, 0x11, 0, | |
611 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
612 | snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, | |
613 | 0x80, present ? 0x80 : 0); | |
614 | snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, | |
615 | 0x80, present ? 0x80 : 0); | |
616 | } | |
617 | ||
618 | /* unsolicited event for HP jack sensing */ | |
619 | static void cxt5045_hp_unsol_event(struct hda_codec *codec, | |
620 | unsigned int res) | |
621 | { | |
622 | res >>= 26; | |
623 | switch (res) { | |
624 | case CONEXANT_HP_EVENT: | |
625 | cxt5045_hp_automute(codec); | |
626 | break; | |
627 | } | |
628 | } | |
629 | ||
630 | static struct snd_kcontrol_new cxt5045_mixers[] = { | |
631 | { | |
632 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
633 | .name = "Capture Source", | |
634 | .info = conexant_mux_enum_info, | |
635 | .get = conexant_mux_enum_get, | |
636 | .put = conexant_mux_enum_put | |
637 | }, | |
638 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x17, 0x02, HDA_INPUT), | |
639 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x17, 0x02, HDA_INPUT), | |
640 | HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x02, HDA_INPUT), | |
641 | HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x02, HDA_INPUT), | |
642 | { | |
643 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
644 | .name = "Master Playback Volume", | |
645 | .info = snd_hda_mixer_amp_volume_info, | |
646 | .get = snd_hda_mixer_amp_volume_get, | |
647 | .put = cxt5045_hp_master_vol_put, | |
648 | .private_value = HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), | |
649 | }, | |
650 | { | |
651 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
652 | .name = "Master Playback Switch", | |
653 | .info = conexant_eapd_info, | |
654 | .get = conexant_eapd_get, | |
655 | .put = cxt5045_hp_master_sw_put, | |
656 | .private_value = 0x11, | |
657 | }, | |
658 | ||
659 | {} | |
660 | }; | |
661 | ||
662 | static struct hda_verb cxt5045_init_verbs[] = { | |
663 | /* Line in, Mic */ | |
664 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
665 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
666 | /* HP, Amp */ | |
667 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, | |
668 | {0x1A, AC_VERB_SET_CONNECT_SEL,0x01}, | |
669 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
670 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, | |
671 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
672 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, | |
673 | /* Record selector: Front mic */ | |
674 | {0x14, AC_VERB_SET_CONNECT_SEL,0x03}, | |
675 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, | |
676 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
677 | /* SPDIF route: PCM */ | |
678 | { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
679 | /* pin sensing on HP and Mic jacks */ | |
680 | {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
681 | /* EAPD */ | |
682 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ | |
683 | { } /* end */ | |
684 | }; | |
685 | ||
686 | #ifdef CONFIG_SND_DEBUG | |
687 | /* Test configuration for debugging, modelled after the ALC260 test | |
688 | * configuration. | |
689 | */ | |
690 | static struct hda_input_mux cxt5045_test_capture_source = { | |
691 | .num_items = 5, | |
692 | .items = { | |
693 | { "MIXER", 0x0 }, | |
694 | { "MIC1 pin", 0x1 }, | |
695 | { "LINE1 pin", 0x2 }, | |
696 | { "HP-OUT pin", 0x3 }, | |
697 | { "CD pin", 0x4 }, | |
698 | }, | |
699 | }; | |
700 | ||
701 | static struct snd_kcontrol_new cxt5045_test_mixer[] = { | |
702 | ||
703 | /* Output controls */ | |
704 | HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x19, 0x00, HDA_OUTPUT), | |
705 | HDA_CODEC_MUTE("OutAmp-1 Switch", 0x19,0x00, HDA_OUTPUT), | |
706 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), | |
707 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), | |
708 | ||
709 | /* Modes for retasking pin widgets */ | |
710 | CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), | |
711 | CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), | |
712 | ||
713 | /* Loopback mixer controls */ | |
714 | HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x17, 0x01, HDA_INPUT), | |
715 | HDA_CODEC_MUTE("MIC1 Playback Switch", 0x17, 0x01, HDA_INPUT), | |
716 | HDA_CODEC_VOLUME("LINE loopback Playback Volume", 0x17, 0x02, HDA_INPUT), | |
717 | HDA_CODEC_MUTE("LINE loopback Playback Switch", 0x17, 0x02, HDA_INPUT), | |
718 | HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x17, 0x03, HDA_INPUT), | |
719 | HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x17, 0x03, HDA_INPUT), | |
720 | HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x04, HDA_INPUT), | |
721 | HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x04, HDA_INPUT), | |
722 | ||
723 | /* Controls for GPIO pins, assuming they exist and are configured as outputs */ | |
724 | CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01), | |
725 | #if 0 /* limit this to one GPIO pin for now */ | |
726 | CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02), | |
727 | CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04), | |
728 | CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08), | |
729 | #endif | |
730 | CXT_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x13, 0x01), | |
731 | ||
732 | HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_OUTPUT), | |
733 | HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_OUTPUT), | |
734 | { | |
735 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
736 | .name = "Input Source", | |
737 | .info = conexant_mux_enum_info, | |
738 | .get = conexant_mux_enum_get, | |
739 | .put = conexant_mux_enum_put, | |
740 | }, | |
741 | ||
742 | { } /* end */ | |
743 | }; | |
744 | ||
745 | static struct hda_verb cxt5045_test_init_verbs[] = { | |
746 | /* Enable all GPIOs as outputs with an initial value of 0 */ | |
747 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f}, | |
748 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, | |
749 | {0x01, AC_VERB_SET_GPIO_MASK, 0x0f}, | |
750 | ||
751 | /* Enable retasking pins as output, initially without power amp */ | |
752 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
753 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
754 | ||
755 | /* Disable digital (SPDIF) pins initially, but users can enable | |
756 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
757 | * payload also sets the generation to 0, output to be in "consumer" | |
758 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
759 | * control. | |
760 | */ | |
761 | {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
762 | ||
763 | /* Start with output sum widgets muted and their output gains at min */ | |
764 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
765 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
766 | ||
767 | /* Unmute retasking pin widget output buffers since the default | |
768 | * state appears to be output. As the pin mode is changed by the | |
769 | * user the pin mode control will take care of enabling the pin's | |
770 | * input/output buffers as needed. | |
771 | */ | |
772 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
773 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
774 | ||
775 | /* Mute capture amp left and right */ | |
776 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
777 | ||
778 | /* Set ADC connection select to match default mixer setting (mic1 | |
779 | * pin) | |
780 | */ | |
781 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
782 | ||
783 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
784 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ | |
785 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ | |
786 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ | |
787 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ | |
788 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
789 | ||
790 | { } | |
791 | }; | |
792 | #endif | |
793 | ||
794 | ||
795 | /* initialize jack-sensing, too */ | |
796 | static int cxt5045_init(struct hda_codec *codec) | |
797 | { | |
798 | conexant_init(codec); | |
799 | cxt5045_hp_automute(codec); | |
800 | return 0; | |
801 | } | |
802 | ||
803 | ||
804 | enum { | |
f5fcc13c | 805 | CXT5045_LAPTOP, /* Laptops w/ EAPD support */ |
c9b443d4 TD |
806 | #ifdef CONFIG_SND_DEBUG |
807 | CXT5045_TEST, | |
808 | #endif | |
f5fcc13c | 809 | CXT5045_MODELS |
c9b443d4 TD |
810 | }; |
811 | ||
f5fcc13c TI |
812 | static const char *cxt5045_models[CXT5045_MODELS] = { |
813 | [CXT5045_LAPTOP] = "laptop", | |
c9b443d4 | 814 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 815 | [CXT5045_TEST] = "test", |
c9b443d4 | 816 | #endif |
f5fcc13c TI |
817 | }; |
818 | ||
819 | static struct snd_pci_quirk cxt5045_cfg_tbl[] = { | |
820 | SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP), | |
c9b443d4 TD |
821 | {} |
822 | }; | |
823 | ||
824 | static int patch_cxt5045(struct hda_codec *codec) | |
825 | { | |
826 | struct conexant_spec *spec; | |
827 | int board_config; | |
828 | ||
829 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
830 | if (!spec) | |
831 | return -ENOMEM; | |
832 | mutex_init(&spec->amp_mutex); | |
833 | codec->spec = spec; | |
834 | ||
835 | spec->multiout.max_channels = 2; | |
836 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); | |
837 | spec->multiout.dac_nids = cxt5045_dac_nids; | |
838 | spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; | |
839 | spec->num_adc_nids = 1; | |
840 | spec->adc_nids = cxt5045_adc_nids; | |
841 | spec->capsrc_nids = cxt5045_capsrc_nids; | |
842 | spec->input_mux = &cxt5045_capture_source; | |
843 | spec->num_mixers = 1; | |
844 | spec->mixers[0] = cxt5045_mixers; | |
845 | spec->num_init_verbs = 1; | |
846 | spec->init_verbs[0] = cxt5045_init_verbs; | |
847 | spec->spdif_route = 0; | |
5cd57529 TD |
848 | spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), |
849 | spec->channel_mode = cxt5045_modes, | |
850 | ||
c9b443d4 TD |
851 | |
852 | codec->patch_ops = conexant_patch_ops; | |
853 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | |
854 | ||
f5fcc13c TI |
855 | board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, |
856 | cxt5045_models, | |
857 | cxt5045_cfg_tbl); | |
c9b443d4 TD |
858 | switch (board_config) { |
859 | case CXT5045_LAPTOP: | |
860 | spec->input_mux = &cxt5045_capture_source; | |
861 | spec->num_init_verbs = 2; | |
862 | spec->init_verbs[1] = cxt5045_init_verbs; | |
863 | spec->mixers[0] = cxt5045_mixers; | |
864 | codec->patch_ops.init = cxt5045_init; | |
865 | break; | |
866 | #ifdef CONFIG_SND_DEBUG | |
867 | case CXT5045_TEST: | |
868 | spec->input_mux = &cxt5045_test_capture_source; | |
869 | spec->mixers[0] = cxt5045_test_mixer; | |
870 | spec->init_verbs[0] = cxt5045_test_init_verbs; | |
871 | #endif | |
872 | } | |
873 | return 0; | |
874 | } | |
875 | ||
876 | ||
877 | /* Conexant 5047 specific */ | |
878 | ||
879 | static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; | |
880 | static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; | |
881 | static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; | |
882 | #define CXT5047_SPDIF_OUT 0x11 | |
883 | ||
5cd57529 TD |
884 | static struct hda_channel_mode cxt5047_modes[1] = { |
885 | { 2, NULL }, | |
886 | }; | |
c9b443d4 TD |
887 | |
888 | static struct hda_input_mux cxt5047_capture_source = { | |
889 | .num_items = 2, | |
890 | .items = { | |
891 | { "ExtMic", 0x1 }, | |
892 | { "IntMic", 0x2 }, | |
893 | } | |
894 | }; | |
895 | ||
896 | static struct hda_input_mux cxt5047_hp_capture_source = { | |
897 | .num_items = 1, | |
898 | .items = { | |
899 | { "ExtMic", 0x1 }, | |
900 | } | |
901 | }; | |
902 | ||
903 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
904 | static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
905 | struct snd_ctl_elem_value *ucontrol) | |
906 | { | |
907 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
908 | struct conexant_spec *spec = codec->spec; | |
909 | ||
910 | if (!conexant_eapd_put(kcontrol, ucontrol)) | |
911 | return 0; | |
912 | ||
913 | /* toggle HP mute appropriately */ | |
914 | snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, | |
915 | 0x80, spec->cur_eapd ? 0 : 0x80); | |
916 | snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, | |
917 | 0x80, spec->cur_eapd ? 0 : 0x80); | |
918 | return 1; | |
919 | } | |
920 | ||
921 | #if 0 | |
922 | /* bind volumes of both NID 0x13 and 0x1d */ | |
923 | static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol, | |
924 | struct snd_ctl_elem_value *ucontrol) | |
925 | { | |
926 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
927 | long *valp = ucontrol->value.integer.value; | |
928 | int change; | |
929 | ||
930 | change = snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, | |
931 | 0x7f, valp[0] & 0x7f); | |
932 | change |= snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, | |
933 | 0x7f, valp[1] & 0x7f); | |
934 | snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, | |
935 | 0x7f, valp[0] & 0x7f); | |
936 | snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, | |
937 | 0x7f, valp[1] & 0x7f); | |
938 | return change; | |
939 | } | |
940 | #endif | |
941 | ||
942 | /* mute internal speaker if HP is plugged */ | |
943 | static void cxt5047_hp_automute(struct hda_codec *codec) | |
944 | { | |
945 | unsigned int present; | |
946 | ||
947 | present = snd_hda_codec_read(codec, 0x13, 0, | |
948 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
949 | snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, | |
950 | 0x80, present ? 0x80 : 0); | |
951 | snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, | |
952 | 0x80, present ? 0x80 : 0); | |
953 | } | |
954 | ||
955 | /* toggle input of built-in and mic jack appropriately */ | |
956 | static void cxt5047_hp_automic(struct hda_codec *codec) | |
957 | { | |
958 | static struct hda_verb mic_jack_on[] = { | |
959 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
960 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
961 | {} | |
962 | }; | |
963 | static struct hda_verb mic_jack_off[] = { | |
964 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
965 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
966 | {} | |
967 | }; | |
968 | unsigned int present; | |
969 | ||
970 | present = snd_hda_codec_read(codec, 0x08, 0, | |
971 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
972 | if (present) | |
973 | snd_hda_sequence_write(codec, mic_jack_on); | |
974 | else | |
975 | snd_hda_sequence_write(codec, mic_jack_off); | |
976 | } | |
977 | ||
978 | /* unsolicited event for HP jack sensing */ | |
979 | static void cxt5047_hp_unsol_event(struct hda_codec *codec, | |
980 | unsigned int res) | |
981 | { | |
982 | res >>= 26; | |
983 | switch (res) { | |
984 | case CONEXANT_HP_EVENT: | |
985 | cxt5047_hp_automute(codec); | |
986 | break; | |
987 | case CONEXANT_MIC_EVENT: | |
988 | cxt5047_hp_automic(codec); | |
989 | break; | |
990 | } | |
991 | } | |
992 | ||
993 | static struct snd_kcontrol_new cxt5047_mixers[] = { | |
994 | { | |
995 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
996 | .name = "Capture Source", | |
997 | .info = conexant_mux_enum_info, | |
998 | .get = conexant_mux_enum_get, | |
999 | .put = conexant_mux_enum_put | |
1000 | }, | |
1001 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), | |
1002 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), | |
1003 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), | |
1004 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1005 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1006 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
1007 | HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), | |
1008 | { | |
1009 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1010 | .name = "Master Playback Switch", | |
1011 | .info = conexant_eapd_info, | |
1012 | .get = conexant_eapd_get, | |
1013 | .put = cxt5047_hp_master_sw_put, | |
1014 | .private_value = 0x13, | |
1015 | }, | |
1016 | ||
1017 | {} | |
1018 | }; | |
1019 | ||
1020 | static struct snd_kcontrol_new cxt5047_hp_mixers[] = { | |
1021 | { | |
1022 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1023 | .name = "Capture Source", | |
1024 | .info = conexant_mux_enum_info, | |
1025 | .get = conexant_mux_enum_get, | |
1026 | .put = conexant_mux_enum_put | |
1027 | }, | |
1028 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), | |
1029 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT), | |
1030 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), | |
1031 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1032 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1033 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
1034 | HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), | |
1035 | { | |
1036 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1037 | .name = "Master Playback Switch", | |
1038 | .info = conexant_eapd_info, | |
1039 | .get = conexant_eapd_get, | |
1040 | .put = cxt5047_hp_master_sw_put, | |
1041 | .private_value = 0x13, | |
1042 | }, | |
1043 | { } /* end */ | |
1044 | }; | |
1045 | ||
1046 | static struct hda_verb cxt5047_init_verbs[] = { | |
1047 | /* Line in, Mic, Built-in Mic */ | |
1048 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
1049 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
1050 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
1051 | /* HP, Amp */ | |
1052 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, | |
5cd57529 | 1053 | {0x1A, AC_VERB_SET_CONNECT_SEL,0x03}, |
c9b443d4 TD |
1054 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, |
1055 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, | |
1056 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
1057 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, | |
1058 | /* Record selector: Front mic */ | |
1059 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, | |
1060 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, | |
1061 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
1062 | /* SPDIF route: PCM */ | |
1063 | { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
1064 | { } /* end */ | |
1065 | }; | |
1066 | ||
1067 | /* configuration for Toshiba Laptops */ | |
1068 | static struct hda_verb cxt5047_toshiba_init_verbs[] = { | |
1069 | {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ | |
1070 | /* pin sensing on HP and Mic jacks */ | |
1071 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
1072 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
1073 | {} | |
1074 | }; | |
1075 | ||
1076 | /* configuration for HP Laptops */ | |
1077 | static struct hda_verb cxt5047_hp_init_verbs[] = { | |
1078 | /* pin sensing on HP and Mic jacks */ | |
1079 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
1080 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
1081 | {} | |
1082 | }; | |
1083 | ||
1084 | /* Test configuration for debugging, modelled after the ALC260 test | |
1085 | * configuration. | |
1086 | */ | |
1087 | #ifdef CONFIG_SND_DEBUG | |
1088 | static struct hda_input_mux cxt5047_test_capture_source = { | |
1089 | .num_items = 5, | |
1090 | .items = { | |
1091 | { "MIXER", 0x0 }, | |
1092 | { "LINE1 pin", 0x1 }, | |
1093 | { "MIC1 pin", 0x2 }, | |
1094 | { "MIC2 pin", 0x3 }, | |
1095 | { "CD pin", 0x4 }, | |
1096 | }, | |
1097 | }; | |
1098 | ||
1099 | static struct snd_kcontrol_new cxt5047_test_mixer[] = { | |
1100 | ||
1101 | /* Output only controls */ | |
1102 | HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x00, HDA_OUTPUT), | |
1103 | HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x00, HDA_OUTPUT), | |
1104 | HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x00, HDA_OUTPUT), | |
1105 | HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x00, HDA_OUTPUT), | |
1106 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), | |
1107 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), | |
1108 | HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
1109 | HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
1110 | ||
1111 | /* Modes for retasking pin widgets */ | |
1112 | CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), | |
1113 | CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), | |
1114 | ||
1115 | /* Loopback mixer controls */ | |
1116 | HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x19, 0x02, HDA_INPUT), | |
1117 | HDA_CODEC_MUTE("MIC1 Playback Switch", 0x19, 0x02, HDA_INPUT), | |
1118 | HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x19, 0x03, HDA_INPUT), | |
1119 | HDA_CODEC_MUTE("MIC2 Playback Switch", 0x19, 0x03, HDA_INPUT), | |
1120 | HDA_CODEC_VOLUME("LINE Playback Volume", 0x19, 0x01, HDA_INPUT), | |
1121 | HDA_CODEC_MUTE("LINE Playback Switch", 0x19, 0x01, HDA_INPUT), | |
1122 | HDA_CODEC_VOLUME("CD Playback Volume", 0x19, 0x04, HDA_INPUT), | |
1123 | HDA_CODEC_MUTE("CD Playback Switch", 0x19, 0x04, HDA_INPUT), | |
1124 | ||
5cd57529 | 1125 | #if 0 |
c9b443d4 TD |
1126 | /* Controls for GPIO pins, assuming they exist and are configured as outputs */ |
1127 | CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01), | |
c9b443d4 TD |
1128 | CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02), |
1129 | CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04), | |
1130 | CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08), | |
1131 | #endif | |
1132 | CXT_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x18, 0x01), | |
1133 | ||
1134 | HDA_CODEC_VOLUME("Capture Volume", 0x19, 0x0, HDA_OUTPUT), | |
1135 | HDA_CODEC_MUTE("Capture Switch", 0x19, 0x0, HDA_OUTPUT), | |
1136 | { | |
1137 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1138 | .name = "Input Source", | |
1139 | .info = conexant_mux_enum_info, | |
1140 | .get = conexant_mux_enum_get, | |
1141 | .put = conexant_mux_enum_put, | |
1142 | }, | |
1143 | ||
1144 | { } /* end */ | |
1145 | }; | |
1146 | ||
1147 | static struct hda_verb cxt5047_test_init_verbs[] = { | |
1148 | /* Enable all GPIOs as outputs with an initial value of 0 */ | |
1149 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f}, | |
1150 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, | |
1151 | {0x01, AC_VERB_SET_GPIO_MASK, 0x0f}, | |
1152 | ||
1153 | /* Enable retasking pins as output, initially without power amp */ | |
1154 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1155 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1156 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1157 | ||
1158 | /* Disable digital (SPDIF) pins initially, but users can enable | |
1159 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
1160 | * payload also sets the generation to 0, output to be in "consumer" | |
1161 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
1162 | * control. | |
1163 | */ | |
1164 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
1165 | ||
1166 | /* Ensure mic1, mic2, line1 pin widgets take input from the | |
1167 | * OUT1 sum bus when acting as an output. | |
1168 | */ | |
1169 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, | |
1170 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, | |
1171 | ||
1172 | /* Start with output sum widgets muted and their output gains at min */ | |
1173 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1174 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1175 | ||
1176 | /* Unmute retasking pin widget output buffers since the default | |
1177 | * state appears to be output. As the pin mode is changed by the | |
1178 | * user the pin mode control will take care of enabling the pin's | |
1179 | * input/output buffers as needed. | |
1180 | */ | |
1181 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1182 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1183 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1184 | ||
1185 | /* Mute capture amp left and right */ | |
1186 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1187 | ||
1188 | /* Set ADC connection select to match default mixer setting (mic1 | |
1189 | * pin) | |
1190 | */ | |
1191 | {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1192 | ||
1193 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
1194 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ | |
1195 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ | |
1196 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ | |
1197 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ | |
1198 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
1199 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ | |
1200 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ | |
1201 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ | |
1202 | ||
1203 | { } | |
1204 | }; | |
1205 | #endif | |
1206 | ||
1207 | ||
1208 | /* initialize jack-sensing, too */ | |
1209 | static int cxt5047_hp_init(struct hda_codec *codec) | |
1210 | { | |
1211 | conexant_init(codec); | |
1212 | cxt5047_hp_automute(codec); | |
1213 | cxt5047_hp_automic(codec); | |
1214 | return 0; | |
1215 | } | |
1216 | ||
1217 | ||
1218 | enum { | |
f5fcc13c TI |
1219 | CXT5047_LAPTOP, /* Laptops w/o EAPD support */ |
1220 | CXT5047_LAPTOP_HP, /* Some HP laptops */ | |
1221 | CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ | |
c9b443d4 TD |
1222 | #ifdef CONFIG_SND_DEBUG |
1223 | CXT5047_TEST, | |
1224 | #endif | |
f5fcc13c | 1225 | CXT5047_MODELS |
c9b443d4 TD |
1226 | }; |
1227 | ||
f5fcc13c TI |
1228 | static const char *cxt5047_models[CXT5047_MODELS] = { |
1229 | [CXT5047_LAPTOP] = "laptop", | |
1230 | [CXT5047_LAPTOP_HP] = "laptop-hp", | |
1231 | [CXT5047_LAPTOP_EAPD] = "laptop-eapd", | |
c9b443d4 | 1232 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 1233 | [CXT5047_TEST] = "test", |
c9b443d4 | 1234 | #endif |
f5fcc13c TI |
1235 | }; |
1236 | ||
1237 | static struct snd_pci_quirk cxt5047_cfg_tbl[] = { | |
1238 | SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP), | |
1239 | SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP), | |
1240 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), | |
1241 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), | |
c9b443d4 TD |
1242 | {} |
1243 | }; | |
1244 | ||
1245 | static int patch_cxt5047(struct hda_codec *codec) | |
1246 | { | |
1247 | struct conexant_spec *spec; | |
1248 | int board_config; | |
1249 | ||
1250 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1251 | if (!spec) | |
1252 | return -ENOMEM; | |
1253 | mutex_init(&spec->amp_mutex); | |
1254 | codec->spec = spec; | |
1255 | ||
1256 | spec->multiout.max_channels = 2; | |
1257 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); | |
1258 | spec->multiout.dac_nids = cxt5047_dac_nids; | |
1259 | spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; | |
1260 | spec->num_adc_nids = 1; | |
1261 | spec->adc_nids = cxt5047_adc_nids; | |
1262 | spec->capsrc_nids = cxt5047_capsrc_nids; | |
1263 | spec->input_mux = &cxt5047_capture_source; | |
1264 | spec->num_mixers = 1; | |
1265 | spec->mixers[0] = cxt5047_mixers; | |
1266 | spec->num_init_verbs = 1; | |
1267 | spec->init_verbs[0] = cxt5047_init_verbs; | |
1268 | spec->spdif_route = 0; | |
5cd57529 TD |
1269 | spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), |
1270 | spec->channel_mode = cxt5047_modes, | |
c9b443d4 TD |
1271 | |
1272 | codec->patch_ops = conexant_patch_ops; | |
1273 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; | |
1274 | ||
f5fcc13c TI |
1275 | board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, |
1276 | cxt5047_models, | |
1277 | cxt5047_cfg_tbl); | |
c9b443d4 TD |
1278 | switch (board_config) { |
1279 | case CXT5047_LAPTOP: | |
1280 | break; | |
1281 | case CXT5047_LAPTOP_HP: | |
1282 | spec->input_mux = &cxt5047_hp_capture_source; | |
1283 | spec->num_init_verbs = 2; | |
1284 | spec->init_verbs[1] = cxt5047_hp_init_verbs; | |
1285 | spec->mixers[0] = cxt5047_hp_mixers; | |
1286 | codec->patch_ops.init = cxt5047_hp_init; | |
1287 | break; | |
1288 | case CXT5047_LAPTOP_EAPD: | |
1289 | spec->num_init_verbs = 2; | |
1290 | spec->init_verbs[1] = cxt5047_toshiba_init_verbs; | |
1291 | break; | |
1292 | #ifdef CONFIG_SND_DEBUG | |
1293 | case CXT5047_TEST: | |
1294 | spec->input_mux = &cxt5047_test_capture_source; | |
1295 | spec->mixers[0] = cxt5047_test_mixer; | |
1296 | spec->init_verbs[0] = cxt5047_test_init_verbs; | |
1297 | #endif | |
1298 | } | |
1299 | return 0; | |
1300 | } | |
1301 | ||
1302 | struct hda_codec_preset snd_hda_preset_conexant[] = { | |
1303 | { .id = 0x14f15045, .name = "CXT5045", .patch = patch_cxt5045 }, | |
1304 | { .id = 0x14f15047, .name = "CXT5047", .patch = patch_cxt5047 }, | |
1305 | {} /* terminator */ | |
1306 | }; |