1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HD audio interface patch for Creative CA0132 chip
5 * Copyright (c) 2011, Creative Technology Ltd.
7 * Based on patch_ca0110.c
8 * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
14 #include <linux/mutex.h>
15 #include <linux/module.h>
16 #include <linux/firmware.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
20 #include <linux/pci.h>
22 #include <sound/core.h>
23 #include <sound/hda_codec.h>
24 #include "hda_local.h"
25 #include "hda_auto_parser.h"
28 #include "ca0132_regs.h"
30 /* Enable this to see controls for tuning purpose. */
31 /*#define ENABLE_TUNING_CONTROLS*/
33 #ifdef ENABLE_TUNING_CONTROLS
34 #include <sound/tlv.h>
37 #define FLOAT_ZERO 0x00000000
38 #define FLOAT_ONE 0x3f800000
39 #define FLOAT_TWO 0x40000000
40 #define FLOAT_THREE 0x40400000
41 #define FLOAT_EIGHT 0x41000000
42 #define FLOAT_MINUS_5 0xc0a00000
44 #define UNSOL_TAG_DSP 0x16
46 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
47 #define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
49 #define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
50 #define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
51 #define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
53 #define MASTERCONTROL 0x80
54 #define MASTERCONTROL_ALLOC_DMA_CHAN 10
55 #define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
57 #define WIDGET_CHIP_CTRL 0x15
58 #define WIDGET_DSP_CTRL 0x16
60 #define MEM_CONNID_MICIN1 3
61 #define MEM_CONNID_MICIN2 5
62 #define MEM_CONNID_MICOUT1 12
63 #define MEM_CONNID_MICOUT2 14
64 #define MEM_CONNID_WUH 10
65 #define MEM_CONNID_DSP 16
66 #define MEM_CONNID_DMIC 100
71 #define EFX_FILE "ctefx.bin"
72 #define DESKTOP_EFX_FILE "ctefx-desktop.bin"
73 #define R3DI_EFX_FILE "ctefx-r3di.bin"
75 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
76 MODULE_FIRMWARE(EFX_FILE);
77 MODULE_FIRMWARE(DESKTOP_EFX_FILE);
78 MODULE_FIRMWARE(R3DI_EFX_FILE);
81 static const char *const dirstr[2] = { "Playback", "Capture" };
83 #define NUM_OF_OUTPUTS 3
95 /* Strings for Input Source Enum Control */
96 static const char *const in_src_str[3] = {"Rear Mic", "Line", "Front Mic" };
97 #define IN_SRC_NUM_OF_INPUTS 3
105 #define VNODE_START_NID 0x80
106 VNID_SPK = VNODE_START_NID, /* Speaker vnid */
113 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
115 #define EFFECT_START_NID 0x90
116 #define OUT_EFFECT_START_NID EFFECT_START_NID
117 SURROUND = OUT_EFFECT_START_NID,
124 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
126 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
127 ECHO_CANCELLATION = IN_EFFECT_START_NID,
132 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
134 VOICEFX = IN_EFFECT_END_NID,
144 AE5_HEADPHONE_GAIN_ENUM,
145 AE5_SOUND_FILTER_ENUM,
147 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
150 /* Effects values size*/
151 #define EFFECT_VALS_MAX_COUNT 12
154 * Default values for the effect slider controls, they are in order of their
155 * effect NID's. Surround, Crystalizer, Dialog Plus, Smart Volume, and then
158 static const unsigned int effect_slider_defaults[] = {67, 65, 50, 74, 50};
159 /* Amount of effect level sliders for ca0132_alt controls. */
160 #define EFFECT_LEVEL_SLIDERS 5
162 /* Latency introduced by DSP blocks in milliseconds. */
163 #define DSP_CAPTURE_INIT_LATENCY 0
164 #define DSP_CRYSTAL_VOICE_LATENCY 124
165 #define DSP_PLAYBACK_INIT_LATENCY 13
166 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
167 #define DSP_SPEAKER_OUT_LATENCY 7
170 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
172 int mid; /*effect module ID*/
173 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
174 int direct; /* 0:output; 1:input*/
175 int params; /* number of default non-on/off params */
176 /*effect default values, 1st is on/off. */
177 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
180 #define EFX_DIR_OUT 0
183 static const struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
184 { .name = "Surround",
188 .direct = EFX_DIR_OUT,
190 .def_vals = {0x3F800000, 0x3F2B851F}
192 { .name = "Crystalizer",
196 .direct = EFX_DIR_OUT,
198 .def_vals = {0x3F800000, 0x3F266666}
200 { .name = "Dialog Plus",
204 .direct = EFX_DIR_OUT,
206 .def_vals = {0x00000000, 0x3F000000}
208 { .name = "Smart Volume",
212 .direct = EFX_DIR_OUT,
214 .def_vals = {0x3F800000, 0x3F3D70A4, 0x00000000}
219 .reqs = {24, 23, 25},
220 .direct = EFX_DIR_OUT,
222 .def_vals = {0x3F800000, 0x42A00000, 0x3F000000}
224 { .name = "Equalizer",
227 .reqs = {9, 10, 11, 12, 13, 14,
228 15, 16, 17, 18, 19, 20},
229 .direct = EFX_DIR_OUT,
231 .def_vals = {0x00000000, 0x00000000, 0x00000000, 0x00000000,
232 0x00000000, 0x00000000, 0x00000000, 0x00000000,
233 0x00000000, 0x00000000, 0x00000000, 0x00000000}
235 { .name = "Echo Cancellation",
236 .nid = ECHO_CANCELLATION,
238 .reqs = {0, 1, 2, 3},
239 .direct = EFX_DIR_IN,
241 .def_vals = {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
243 { .name = "Voice Focus",
246 .reqs = {6, 7, 8, 9},
247 .direct = EFX_DIR_IN,
249 .def_vals = {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
255 .direct = EFX_DIR_IN,
257 .def_vals = {0x00000000, 0x3F3D70A4}
259 { .name = "Noise Reduction",
260 .nid = NOISE_REDUCTION,
263 .direct = EFX_DIR_IN,
265 .def_vals = {0x3F800000, 0x3F000000}
270 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18},
271 .direct = EFX_DIR_IN,
273 .def_vals = {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
274 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
279 /* Tuning controls */
280 #ifdef ENABLE_TUNING_CONTROLS
283 #define TUNING_CTL_START_NID 0xC0
284 WEDGE_ANGLE = TUNING_CTL_START_NID,
297 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
300 struct ct_tuning_ctl {
301 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
302 hda_nid_t parent_nid;
304 int mid; /*effect module ID*/
305 int req; /*effect module request*/
306 int direct; /* 0:output; 1:input*/
307 unsigned int def_val;/*effect default values*/
310 static const struct ct_tuning_ctl ca0132_tuning_ctls[] = {
311 { .name = "Wedge Angle",
312 .parent_nid = VOICE_FOCUS,
316 .direct = EFX_DIR_IN,
317 .def_val = 0x41F00000
319 { .name = "SVM Level",
320 .parent_nid = MIC_SVM,
324 .direct = EFX_DIR_IN,
325 .def_val = 0x3F3D70A4
327 { .name = "EQ Band0",
328 .parent_nid = EQUALIZER,
329 .nid = EQUALIZER_BAND_0,
332 .direct = EFX_DIR_OUT,
333 .def_val = 0x00000000
335 { .name = "EQ Band1",
336 .parent_nid = EQUALIZER,
337 .nid = EQUALIZER_BAND_1,
340 .direct = EFX_DIR_OUT,
341 .def_val = 0x00000000
343 { .name = "EQ Band2",
344 .parent_nid = EQUALIZER,
345 .nid = EQUALIZER_BAND_2,
348 .direct = EFX_DIR_OUT,
349 .def_val = 0x00000000
351 { .name = "EQ Band3",
352 .parent_nid = EQUALIZER,
353 .nid = EQUALIZER_BAND_3,
356 .direct = EFX_DIR_OUT,
357 .def_val = 0x00000000
359 { .name = "EQ Band4",
360 .parent_nid = EQUALIZER,
361 .nid = EQUALIZER_BAND_4,
364 .direct = EFX_DIR_OUT,
365 .def_val = 0x00000000
367 { .name = "EQ Band5",
368 .parent_nid = EQUALIZER,
369 .nid = EQUALIZER_BAND_5,
372 .direct = EFX_DIR_OUT,
373 .def_val = 0x00000000
375 { .name = "EQ Band6",
376 .parent_nid = EQUALIZER,
377 .nid = EQUALIZER_BAND_6,
380 .direct = EFX_DIR_OUT,
381 .def_val = 0x00000000
383 { .name = "EQ Band7",
384 .parent_nid = EQUALIZER,
385 .nid = EQUALIZER_BAND_7,
388 .direct = EFX_DIR_OUT,
389 .def_val = 0x00000000
391 { .name = "EQ Band8",
392 .parent_nid = EQUALIZER,
393 .nid = EQUALIZER_BAND_8,
396 .direct = EFX_DIR_OUT,
397 .def_val = 0x00000000
399 { .name = "EQ Band9",
400 .parent_nid = EQUALIZER,
401 .nid = EQUALIZER_BAND_9,
404 .direct = EFX_DIR_OUT,
405 .def_val = 0x00000000
410 /* Voice FX Presets */
411 #define VOICEFX_MAX_PARAM_COUNT 9
417 int reqs[VOICEFX_MAX_PARAM_COUNT]; /*effect module request*/
420 struct ct_voicefx_preset {
421 char *name; /*preset name*/
422 unsigned int vals[VOICEFX_MAX_PARAM_COUNT];
425 static const struct ct_voicefx ca0132_voicefx = {
426 .name = "VoiceFX Capture Switch",
429 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18}
432 static const struct ct_voicefx_preset ca0132_voicefx_presets[] = {
434 .vals = { 0x00000000, 0x43C80000, 0x44AF0000,
435 0x44FA0000, 0x3F800000, 0x3F800000,
436 0x3F800000, 0x00000000, 0x00000000 }
438 { .name = "Female2Male",
439 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
440 0x44FA0000, 0x3F19999A, 0x3F866666,
441 0x3F800000, 0x00000000, 0x00000000 }
443 { .name = "Male2Female",
444 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
445 0x450AC000, 0x4017AE14, 0x3F6B851F,
446 0x3F800000, 0x00000000, 0x00000000 }
448 { .name = "ScrappyKid",
449 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
450 0x44FA0000, 0x40400000, 0x3F28F5C3,
451 0x3F800000, 0x00000000, 0x00000000 }
454 .vals = { 0x3F800000, 0x44324000, 0x44BB8000,
455 0x44E10000, 0x3FB33333, 0x3FB9999A,
456 0x3F800000, 0x3E3A2E43, 0x00000000 }
459 .vals = { 0x3F800000, 0x43EA0000, 0x44A52000,
460 0x45098000, 0x3F266666, 0x3FC00000,
461 0x3F800000, 0x00000000, 0x00000000 }
464 .vals = { 0x3F800000, 0x43C70000, 0x44AE6000,
465 0x45193000, 0x3F8E147B, 0x3F75C28F,
466 0x3F800000, 0x00000000, 0x00000000 }
469 .vals = { 0x3F800000, 0x43930000, 0x44BEE000,
470 0x45007000, 0x3F451EB8, 0x3F7851EC,
471 0x3F800000, 0x00000000, 0x00000000 }
473 { .name = "AlienBrute",
474 .vals = { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
475 0x451F6000, 0x3F266666, 0x3FA7D945,
476 0x3F800000, 0x3CF5C28F, 0x00000000 }
479 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
480 0x44FA0000, 0x3FB2718B, 0x3F800000,
481 0xBC07010E, 0x00000000, 0x00000000 }
484 .vals = { 0x3F800000, 0x43C20000, 0x44906000,
485 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
486 0x3F0A3D71, 0x00000000, 0x00000000 }
489 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
490 0x44FA0000, 0x3F800000, 0x3F800000,
491 0x3E4CCCCD, 0x00000000, 0x00000000 }
493 { .name = "DeepVoice",
494 .vals = { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
495 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
496 0x3F800000, 0x00000000, 0x00000000 }
498 { .name = "Munchkin",
499 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
500 0x44FA0000, 0x3F800000, 0x3F1A043C,
501 0x3F800000, 0x00000000, 0x00000000 }
505 /* ca0132 EQ presets, taken from Windows Sound Blaster Z Driver */
507 #define EQ_PRESET_MAX_PARAM_COUNT 11
513 int reqs[EQ_PRESET_MAX_PARAM_COUNT]; /*effect module request*/
516 struct ct_eq_preset {
517 char *name; /*preset name*/
518 unsigned int vals[EQ_PRESET_MAX_PARAM_COUNT];
521 static const struct ct_eq ca0132_alt_eq_enum = {
522 .name = "FX: Equalizer Preset Switch",
523 .nid = EQ_PRESET_ENUM,
525 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
529 static const struct ct_eq_preset ca0132_alt_eq_presets[] = {
531 .vals = { 0x00000000, 0x00000000, 0x00000000,
532 0x00000000, 0x00000000, 0x00000000,
533 0x00000000, 0x00000000, 0x00000000,
534 0x00000000, 0x00000000 }
536 { .name = "Acoustic",
537 .vals = { 0x00000000, 0x00000000, 0x3F8CCCCD,
538 0x40000000, 0x00000000, 0x00000000,
539 0x00000000, 0x00000000, 0x40000000,
540 0x40000000, 0x40000000 }
542 { .name = "Classical",
543 .vals = { 0x00000000, 0x00000000, 0x40C00000,
544 0x40C00000, 0x40466666, 0x00000000,
545 0x00000000, 0x00000000, 0x00000000,
546 0x40466666, 0x40466666 }
549 .vals = { 0x00000000, 0xBF99999A, 0x00000000,
550 0x3FA66666, 0x3FA66666, 0x3F8CCCCD,
551 0x00000000, 0x00000000, 0x40000000,
552 0x40466666, 0x40800000 }
555 .vals = { 0x00000000, 0xBF99999A, 0x40000000,
556 0x40466666, 0x40866666, 0xBF99999A,
557 0xBF99999A, 0x00000000, 0x00000000,
558 0x40800000, 0x40800000 }
561 .vals = { 0x00000000, 0x00000000, 0x00000000,
562 0x3F8CCCCD, 0x40800000, 0x40800000,
563 0x40800000, 0x00000000, 0x3F8CCCCD,
564 0x40466666, 0x40466666 }
567 .vals = { 0x00000000, 0x00000000, 0x40000000,
568 0x40000000, 0x00000000, 0x00000000,
569 0x00000000, 0x3F8CCCCD, 0x40000000,
570 0x40000000, 0x40000000 }
573 .vals = { 0x00000000, 0xBFCCCCCD, 0x00000000,
574 0x40000000, 0x40000000, 0x00000000,
575 0xBF99999A, 0xBF99999A, 0x00000000,
576 0x40466666, 0x40C00000 }
579 .vals = { 0x00000000, 0xBF99999A, 0xBF99999A,
580 0x3F8CCCCD, 0x40000000, 0xBF99999A,
581 0xBF99999A, 0x00000000, 0x00000000,
582 0x40800000, 0x40800000 }
585 .vals = { 0x00000000, 0xC0000000, 0xBF99999A,
586 0xBF99999A, 0x00000000, 0x40466666,
587 0x40800000, 0x40466666, 0x00000000,
588 0x00000000, 0x3F8CCCCD }
592 /* DSP command sequences for ca0132_alt_select_out */
593 #define ALT_OUT_SET_MAX_COMMANDS 9 /* Max number of commands in sequence */
594 struct ca0132_alt_out_set {
595 char *name; /*preset name*/
596 unsigned char commands;
597 unsigned int mids[ALT_OUT_SET_MAX_COMMANDS];
598 unsigned int reqs[ALT_OUT_SET_MAX_COMMANDS];
599 unsigned int vals[ALT_OUT_SET_MAX_COMMANDS];
602 static const struct ca0132_alt_out_set alt_out_presets[] = {
603 { .name = "Line Out",
605 .mids = { 0x96, 0x96, 0x96, 0x8F,
607 .reqs = { 0x19, 0x17, 0x18, 0x01,
609 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
610 0x00000000, 0x00000000, 0x00000000,
613 { .name = "Headphone",
615 .mids = { 0x96, 0x96, 0x96, 0x8F,
617 .reqs = { 0x19, 0x17, 0x18, 0x01,
619 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
620 0x00000000, 0x00000000, 0x00000000,
623 { .name = "Surround",
625 .mids = { 0x96, 0x8F, 0x96, 0x96,
626 0x96, 0x96, 0x96, 0x96 },
627 .reqs = { 0x18, 0x01, 0x1F, 0x15,
628 0x3A, 0x1A, 0x1B, 0x1C },
629 .vals = { 0x00000000, 0x00000000, 0x00000000,
630 0x00000000, 0x00000000, 0x00000000,
631 0x00000000, 0x00000000 }
636 * DSP volume setting structs. Req 1 is left volume, req 2 is right volume,
637 * and I don't know what the third req is, but it's always zero. I assume it's
638 * some sort of update or set command to tell the DSP there's new volume info.
640 #define DSP_VOL_OUT 0
643 struct ct_dsp_volume_ctl {
645 int mid; /* module ID*/
646 unsigned int reqs[3]; /* scp req ID */
649 static const struct ct_dsp_volume_ctl ca0132_alt_vol_ctls[] = {
660 /* Values for ca0113_mmio_command_set for selecting output. */
661 #define AE5_CA0113_OUT_SET_COMMANDS 6
662 struct ae5_ca0113_output_set {
663 unsigned int group[AE5_CA0113_OUT_SET_COMMANDS];
664 unsigned int target[AE5_CA0113_OUT_SET_COMMANDS];
665 unsigned int vals[AE5_CA0113_OUT_SET_COMMANDS];
668 static const struct ae5_ca0113_output_set ae5_ca0113_output_presets[] = {
669 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
670 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
671 .vals = { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f }
673 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
674 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
675 .vals = { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 }
677 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
678 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
679 .vals = { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f }
683 /* ae5 ca0113 command sequences to set headphone gain levels. */
684 #define AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS 4
685 struct ae5_headphone_gain_set {
687 unsigned int vals[AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS];
690 static const struct ae5_headphone_gain_set ae5_headphone_gain_presets[] = {
691 { .name = "Low (16-31",
692 .vals = { 0xff, 0x2c, 0xf5, 0x32 }
694 { .name = "Medium (32-149",
695 .vals = { 0x38, 0xa8, 0x3e, 0x4c }
697 { .name = "High (150-600",
698 .vals = { 0xff, 0xff, 0xff, 0x7f }
702 struct ae5_filter_set {
707 static const struct ae5_filter_set ae5_filter_presets[] = {
708 { .name = "Slow Roll Off",
711 { .name = "Minimum Phase",
714 { .name = "Fast Roll Off",
719 enum hda_cmd_vendor_io {
721 VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000,
722 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100,
724 VENDOR_DSPIO_STATUS = 0xF01,
725 VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702,
726 VENDOR_DSPIO_SCP_READ_DATA = 0xF02,
727 VENDOR_DSPIO_DSP_INIT = 0x703,
728 VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704,
729 VENDOR_DSPIO_SCP_READ_COUNT = 0xF04,
731 /* for ChipIO node */
732 VENDOR_CHIPIO_ADDRESS_LOW = 0x000,
733 VENDOR_CHIPIO_ADDRESS_HIGH = 0x100,
734 VENDOR_CHIPIO_STREAM_FORMAT = 0x200,
735 VENDOR_CHIPIO_DATA_LOW = 0x300,
736 VENDOR_CHIPIO_DATA_HIGH = 0x400,
738 VENDOR_CHIPIO_8051_WRITE_DIRECT = 0x500,
739 VENDOR_CHIPIO_8051_READ_DIRECT = 0xD00,
741 VENDOR_CHIPIO_GET_PARAMETER = 0xF00,
742 VENDOR_CHIPIO_STATUS = 0xF01,
743 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
744 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
746 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
747 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
748 VENDOR_CHIPIO_8051_PMEM_READ = 0xF08,
749 VENDOR_CHIPIO_8051_IRAM_WRITE = 0x709,
750 VENDOR_CHIPIO_8051_IRAM_READ = 0xF09,
752 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
753 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
755 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
756 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
757 VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D,
758 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
759 VENDOR_CHIPIO_FLAG_SET = 0x70F,
760 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
761 VENDOR_CHIPIO_PARAM_SET = 0x710,
762 VENDOR_CHIPIO_PARAM_GET = 0xF10,
764 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
765 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
766 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
767 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
769 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
770 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
771 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
772 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
774 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
775 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
776 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
777 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
778 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
779 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
781 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
787 enum control_flag_id {
788 /* Connection manager stream setup is bypassed/enabled */
789 CONTROL_FLAG_C_MGR = 0,
790 /* DSP DMA is bypassed/enabled */
791 CONTROL_FLAG_DMA = 1,
792 /* 8051 'idle' mode is disabled/enabled */
793 CONTROL_FLAG_IDLE_ENABLE = 2,
794 /* Tracker for the SPDIF-in path is bypassed/enabled */
795 CONTROL_FLAG_TRACKER = 3,
796 /* DigitalOut to Spdif2Out connection is disabled/enabled */
797 CONTROL_FLAG_SPDIF2OUT = 4,
798 /* Digital Microphone is disabled/enabled */
799 CONTROL_FLAG_DMIC = 5,
800 /* ADC_B rate is 48 kHz/96 kHz */
801 CONTROL_FLAG_ADC_B_96KHZ = 6,
802 /* ADC_C rate is 48 kHz/96 kHz */
803 CONTROL_FLAG_ADC_C_96KHZ = 7,
804 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
805 CONTROL_FLAG_DAC_96KHZ = 8,
806 /* DSP rate is 48 kHz/96 kHz */
807 CONTROL_FLAG_DSP_96KHZ = 9,
808 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
809 CONTROL_FLAG_SRC_CLOCK_196MHZ = 10,
810 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
811 CONTROL_FLAG_SRC_RATE_96KHZ = 11,
812 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
813 CONTROL_FLAG_DECODE_LOOP = 12,
814 /* De-emphasis filter on DAC-1 disabled/enabled */
815 CONTROL_FLAG_DAC1_DEEMPHASIS = 13,
816 /* De-emphasis filter on DAC-2 disabled/enabled */
817 CONTROL_FLAG_DAC2_DEEMPHASIS = 14,
818 /* De-emphasis filter on DAC-3 disabled/enabled */
819 CONTROL_FLAG_DAC3_DEEMPHASIS = 15,
820 /* High-pass filter on ADC_B disabled/enabled */
821 CONTROL_FLAG_ADC_B_HIGH_PASS = 16,
822 /* High-pass filter on ADC_C disabled/enabled */
823 CONTROL_FLAG_ADC_C_HIGH_PASS = 17,
824 /* Common mode on Port_A disabled/enabled */
825 CONTROL_FLAG_PORT_A_COMMON_MODE = 18,
826 /* Common mode on Port_D disabled/enabled */
827 CONTROL_FLAG_PORT_D_COMMON_MODE = 19,
828 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
829 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
830 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
831 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
832 /* ASI rate is 48kHz/96kHz */
833 CONTROL_FLAG_ASI_96KHZ = 22,
834 /* DAC power settings able to control attached ports no/yes */
835 CONTROL_FLAG_DACS_CONTROL_PORTS = 23,
836 /* Clock Stop OK reporting is disabled/enabled */
837 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24,
838 /* Number of control flags */
839 CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1)
843 * Control parameter IDs
845 enum control_param_id {
846 /* 0: None, 1: Mic1In*/
847 CONTROL_PARAM_VIP_SOURCE = 1,
848 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
849 CONTROL_PARAM_SPDIF1_SOURCE = 2,
850 /* Port A output stage gain setting to use when 16 Ohm output
851 * impedance is selected*/
852 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
853 /* Port D output stage gain setting to use when 16 Ohm output
854 * impedance is selected*/
855 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
858 * This control param name was found in the 8051 memory, and makes
859 * sense given the fact the AE-5 uses it and has the ASI flag set.
861 CONTROL_PARAM_ASI = 23,
865 /* Select stream with the given ID */
866 CONTROL_PARAM_STREAM_ID = 24,
867 /* Source connection point for the selected stream */
868 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25,
869 /* Destination connection point for the selected stream */
870 CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26,
871 /* Number of audio channels in the selected stream */
872 CONTROL_PARAM_STREAMS_CHANNELS = 27,
873 /*Enable control for the selected stream */
874 CONTROL_PARAM_STREAM_CONTROL = 28,
876 /* Connection Point Control */
878 /* Select connection point with the given ID */
879 CONTROL_PARAM_CONN_POINT_ID = 29,
880 /* Connection point sample rate */
881 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30,
885 /* Select HDA node with the given ID */
886 CONTROL_PARAM_NODE_ID = 31
890 * Dsp Io Status codes
892 enum hda_vendor_status_dspio {
894 VENDOR_STATUS_DSPIO_OK = 0x00,
895 /* Busy, unable to accept new command, the host must retry */
896 VENDOR_STATUS_DSPIO_BUSY = 0x01,
897 /* SCP command queue is full */
898 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02,
899 /* SCP response queue is empty */
900 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03
904 * Chip Io Status codes
906 enum hda_vendor_status_chipio {
908 VENDOR_STATUS_CHIPIO_OK = 0x00,
909 /* Busy, unable to accept new command, the host must retry */
910 VENDOR_STATUS_CHIPIO_BUSY = 0x01
916 enum ca0132_sample_rate {
936 SR_RATE_UNKNOWN = 0x1F
939 enum dsp_download_state {
940 DSP_DOWNLOAD_FAILED = -1,
941 DSP_DOWNLOAD_INIT = 0,
946 /* retrieve parameters from hda format */
947 #define get_hdafmt_chs(fmt) (fmt & 0xf)
948 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
949 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
950 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
957 const struct snd_kcontrol_new *mixers[5];
958 unsigned int num_mixers;
959 const struct hda_verb *base_init_verbs;
960 const struct hda_verb *base_exit_verbs;
961 const struct hda_verb *chip_init_verbs;
962 const struct hda_verb *desktop_init_verbs;
963 struct hda_verb *spec_init_verbs;
964 struct auto_pin_cfg autocfg;
966 /* Nodes configurations */
967 struct hda_multi_out multiout;
968 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
969 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
970 unsigned int num_outputs;
971 hda_nid_t input_pins[AUTO_PIN_LAST];
972 hda_nid_t adcs[AUTO_PIN_LAST];
975 unsigned int num_inputs;
976 hda_nid_t shared_mic_nid;
977 hda_nid_t shared_out_nid;
978 hda_nid_t unsol_tag_hp;
979 hda_nid_t unsol_tag_front_hp; /* for desktop ca0132 codecs */
980 hda_nid_t unsol_tag_amic1;
983 struct mutex chipio_mutex; /* chip access mutex */
986 /* DSP download related */
987 enum dsp_download_state dsp_state;
988 unsigned int dsp_stream_id;
989 unsigned int wait_scp;
990 unsigned int wait_scp_header;
991 unsigned int wait_num_data;
992 unsigned int scp_resp_header;
993 unsigned int scp_resp_data[4];
994 unsigned int scp_resp_count;
995 bool startup_check_entered;
998 /* mixer and effects related */
999 unsigned char dmic_ctl;
1002 long vnode_lvol[VNODES_COUNT];
1003 long vnode_rvol[VNODES_COUNT];
1004 long vnode_lswitch[VNODES_COUNT];
1005 long vnode_rswitch[VNODES_COUNT];
1006 long effects_switch[EFFECTS_COUNT];
1009 /* ca0132_alt control related values */
1010 unsigned char in_enum_val;
1011 unsigned char out_enum_val;
1012 unsigned char mic_boost_enum_val;
1013 unsigned char smart_volume_setting;
1014 long fx_ctl_val[EFFECT_LEVEL_SLIDERS];
1015 long xbass_xover_freq;
1017 unsigned int tlv[4];
1018 struct hda_vmaster_mute_hook vmaster_mute;
1019 /* AE-5 Control values */
1020 unsigned char ae5_headphone_gain_val;
1021 unsigned char ae5_filter_val;
1022 /* ZxR Control Values */
1023 unsigned char zxr_gain_set;
1025 struct hda_codec *codec;
1026 struct delayed_work unsol_hp_work;
1029 #ifdef ENABLE_TUNING_CONTROLS
1030 long cur_ctl_vals[TUNING_CTLS_COUNT];
1033 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
1034 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
1038 void __iomem *mem_base;
1041 * Whether or not to use the alt functions like alt_select_out,
1042 * alt_select_in, etc. Only used on desktop codecs for now, because of
1043 * surround sound support.
1045 bool use_alt_functions;
1048 * Whether or not to use alt controls: volume effect sliders, EQ
1049 * presets, smart volume presets, and new control names with FX prefix.
1050 * Renames PlayEnhancement and CrystalVoice too.
1052 bool use_alt_controls;
1056 * CA0132 quirks table
1061 QUIRK_ALIENWARE_M17XR4,
1071 #define ca0132_quirk(spec) ((spec)->quirk)
1072 #define ca0132_use_pci_mmio(spec) ((spec)->use_pci_mmio)
1073 #define ca0132_use_alt_functions(spec) ((spec)->use_alt_functions)
1074 #define ca0132_use_alt_controls(spec) ((spec)->use_alt_controls)
1076 #define ca0132_quirk(spec) ({ (void)(spec); QUIRK_NONE; })
1077 #define ca0132_use_alt_functions(spec) ({ (void)(spec); false; })
1078 #define ca0132_use_pci_mmio(spec) ({ (void)(spec); false; })
1079 #define ca0132_use_alt_controls(spec) ({ (void)(spec); false; })
1082 static const struct hda_pintbl alienware_pincfgs[] = {
1083 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1084 { 0x0c, 0x411111f0 }, /* N/A */
1085 { 0x0d, 0x411111f0 }, /* N/A */
1086 { 0x0e, 0x411111f0 }, /* N/A */
1087 { 0x0f, 0x0321101f }, /* HP */
1088 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1089 { 0x11, 0x03a11021 }, /* Mic */
1090 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1091 { 0x13, 0x411111f0 }, /* N/A */
1092 { 0x18, 0x411111f0 }, /* N/A */
1096 /* Sound Blaster Z pin configs taken from Windows Driver */
1097 static const struct hda_pintbl sbz_pincfgs[] = {
1098 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1099 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1100 { 0x0d, 0x014510f0 }, /* Digital Out */
1101 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1102 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1103 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1104 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1105 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1106 { 0x13, 0x908700f0 }, /* What U Hear In*/
1107 { 0x18, 0x50d000f0 }, /* N/A */
1111 /* Sound Blaster ZxR pin configs taken from Windows Driver */
1112 static const struct hda_pintbl zxr_pincfgs[] = {
1113 { 0x0b, 0x01047110 }, /* Port G -- Lineout FRONT L/R */
1114 { 0x0c, 0x414510f0 }, /* SPDIF Out 1 - Disabled*/
1115 { 0x0d, 0x014510f0 }, /* Digital Out */
1116 { 0x0e, 0x41c520f0 }, /* SPDIF In - Disabled*/
1117 { 0x0f, 0x0122711f }, /* Port A -- BackPanel HP */
1118 { 0x10, 0x01017111 }, /* Port D -- Center/LFE */
1119 { 0x11, 0x01017114 }, /* Port B -- LineMicIn2 / Rear L/R */
1120 { 0x12, 0x01a271f0 }, /* Port C -- LineIn1 */
1121 { 0x13, 0x908700f0 }, /* What U Hear In*/
1122 { 0x18, 0x50d000f0 }, /* N/A */
1126 /* Recon3D pin configs taken from Windows Driver */
1127 static const struct hda_pintbl r3d_pincfgs[] = {
1128 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1129 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1130 { 0x0d, 0x014510f0 }, /* Digital Out */
1131 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1132 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1133 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1134 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1135 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1136 { 0x13, 0x908700f0 }, /* What U Hear In*/
1137 { 0x18, 0x50d000f0 }, /* N/A */
1141 /* Sound Blaster AE-5 pin configs taken from Windows Driver */
1142 static const struct hda_pintbl ae5_pincfgs[] = {
1143 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1144 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1145 { 0x0d, 0x014510f0 }, /* Digital Out */
1146 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1147 { 0x0f, 0x01017114 }, /* Port A -- Rear L/R. */
1148 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1149 { 0x11, 0x01a170ff }, /* Port B -- LineMicIn2 / Rear Headphone */
1150 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1151 { 0x13, 0x908700f0 }, /* What U Hear In*/
1152 { 0x18, 0x50d000f0 }, /* N/A */
1156 /* Recon3D integrated pin configs taken from Windows Driver */
1157 static const struct hda_pintbl r3di_pincfgs[] = {
1158 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1159 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1160 { 0x0d, 0x014510f0 }, /* Digital Out */
1161 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1162 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1163 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1164 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1165 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1166 { 0x13, 0x908700f0 }, /* What U Hear In*/
1167 { 0x18, 0x500000f0 }, /* N/A */
1171 static const struct snd_pci_quirk ca0132_quirks[] = {
1172 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4),
1173 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE),
1174 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE),
1175 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE),
1176 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ),
1177 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ),
1178 SND_PCI_QUIRK(0x1102, 0x0027, "Sound Blaster Z", QUIRK_SBZ),
1179 SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ),
1180 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
1181 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
1182 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
1183 SND_PCI_QUIRK(0x3842, 0x1038, "EVGA X99 Classified", QUIRK_R3DI),
1184 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1185 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5),
1190 * CA0132 codec access
1192 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1193 unsigned int verb, unsigned int parm, unsigned int *res)
1195 unsigned int response;
1196 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1199 return ((response == -1) ? -1 : 0);
1202 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1203 unsigned short converter_format, unsigned int *res)
1205 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1206 converter_format & 0xffff, res);
1209 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1210 hda_nid_t nid, unsigned char stream,
1211 unsigned char channel, unsigned int *res)
1213 unsigned char converter_stream_channel = 0;
1215 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1216 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1217 converter_stream_channel, res);
1220 /* Chip access helper function */
1221 static int chipio_send(struct hda_codec *codec,
1226 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1228 /* send bits of data specified by reg */
1230 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1232 if (res == VENDOR_STATUS_CHIPIO_OK)
1235 } while (time_before(jiffies, timeout));
1241 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1243 static int chipio_write_address(struct hda_codec *codec,
1244 unsigned int chip_addx)
1246 struct ca0132_spec *spec = codec->spec;
1249 if (spec->curr_chip_addx == chip_addx)
1252 /* send low 16 bits of the address */
1253 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1254 chip_addx & 0xffff);
1257 /* send high 16 bits of the address */
1258 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1262 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1268 * Write data through the vendor widget -- NOT protected by the Mutex!
1270 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1272 struct ca0132_spec *spec = codec->spec;
1275 /* send low 16 bits of the data */
1276 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1279 /* send high 16 bits of the data */
1280 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1284 /*If no error encountered, automatically increment the address
1285 as per chip behaviour*/
1286 spec->curr_chip_addx = (res != -EIO) ?
1287 (spec->curr_chip_addx + 4) : ~0U;
1292 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1294 static int chipio_write_data_multiple(struct hda_codec *codec,
1301 codec_dbg(codec, "chipio_write_data null ptr\n");
1305 while ((count-- != 0) && (status == 0))
1306 status = chipio_write_data(codec, *data++);
1313 * Read data through the vendor widget -- NOT protected by the Mutex!
1315 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1317 struct ca0132_spec *spec = codec->spec;
1321 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1325 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1330 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1331 VENDOR_CHIPIO_HIC_READ_DATA,
1335 /*If no error encountered, automatically increment the address
1336 as per chip behaviour*/
1337 spec->curr_chip_addx = (res != -EIO) ?
1338 (spec->curr_chip_addx + 4) : ~0U;
1343 * Write given value to the given address through the chip I/O widget.
1344 * protected by the Mutex
1346 static int chipio_write(struct hda_codec *codec,
1347 unsigned int chip_addx, const unsigned int data)
1349 struct ca0132_spec *spec = codec->spec;
1352 mutex_lock(&spec->chipio_mutex);
1354 /* write the address, and if successful proceed to write data */
1355 err = chipio_write_address(codec, chip_addx);
1359 err = chipio_write_data(codec, data);
1364 mutex_unlock(&spec->chipio_mutex);
1369 * Write given value to the given address through the chip I/O widget.
1370 * not protected by the Mutex
1372 static int chipio_write_no_mutex(struct hda_codec *codec,
1373 unsigned int chip_addx, const unsigned int data)
1378 /* write the address, and if successful proceed to write data */
1379 err = chipio_write_address(codec, chip_addx);
1383 err = chipio_write_data(codec, data);
1392 * Write multiple values to the given address through the chip I/O widget.
1393 * protected by the Mutex
1395 static int chipio_write_multiple(struct hda_codec *codec,
1400 struct ca0132_spec *spec = codec->spec;
1403 mutex_lock(&spec->chipio_mutex);
1404 status = chipio_write_address(codec, chip_addx);
1408 status = chipio_write_data_multiple(codec, data, count);
1410 mutex_unlock(&spec->chipio_mutex);
1416 * Read the given address through the chip I/O widget
1417 * protected by the Mutex
1419 static int chipio_read(struct hda_codec *codec,
1420 unsigned int chip_addx, unsigned int *data)
1422 struct ca0132_spec *spec = codec->spec;
1425 mutex_lock(&spec->chipio_mutex);
1427 /* write the address, and if successful proceed to write data */
1428 err = chipio_write_address(codec, chip_addx);
1432 err = chipio_read_data(codec, data);
1437 mutex_unlock(&spec->chipio_mutex);
1442 * Set chip control flags through the chip I/O widget.
1444 static void chipio_set_control_flag(struct hda_codec *codec,
1445 enum control_flag_id flag_id,
1449 unsigned int flag_bit;
1451 flag_bit = (flag_state ? 1 : 0);
1452 val = (flag_bit << 7) | (flag_id);
1453 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1454 VENDOR_CHIPIO_FLAG_SET, val);
1458 * Set chip parameters through the chip I/O widget.
1460 static void chipio_set_control_param(struct hda_codec *codec,
1461 enum control_param_id param_id, int param_val)
1463 struct ca0132_spec *spec = codec->spec;
1466 if ((param_id < 32) && (param_val < 8)) {
1467 val = (param_val << 5) | (param_id);
1468 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1469 VENDOR_CHIPIO_PARAM_SET, val);
1471 mutex_lock(&spec->chipio_mutex);
1472 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1473 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1474 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1476 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1477 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1480 mutex_unlock(&spec->chipio_mutex);
1485 * Set chip parameters through the chip I/O widget. NO MUTEX.
1487 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1488 enum control_param_id param_id, int param_val)
1492 if ((param_id < 32) && (param_val < 8)) {
1493 val = (param_val << 5) | (param_id);
1494 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1495 VENDOR_CHIPIO_PARAM_SET, val);
1497 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1498 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1499 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1501 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1502 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1508 * Connect stream to a source point, and then connect
1509 * that source point to a destination point.
1511 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1512 int streamid, int source_point, int dest_point)
1514 chipio_set_control_param_no_mutex(codec,
1515 CONTROL_PARAM_STREAM_ID, streamid);
1516 chipio_set_control_param_no_mutex(codec,
1517 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1518 chipio_set_control_param_no_mutex(codec,
1519 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1523 * Set number of channels in the selected stream.
1525 static void chipio_set_stream_channels(struct hda_codec *codec,
1526 int streamid, unsigned int channels)
1528 chipio_set_control_param_no_mutex(codec,
1529 CONTROL_PARAM_STREAM_ID, streamid);
1530 chipio_set_control_param_no_mutex(codec,
1531 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1535 * Enable/Disable audio stream.
1537 static void chipio_set_stream_control(struct hda_codec *codec,
1538 int streamid, int enable)
1540 chipio_set_control_param_no_mutex(codec,
1541 CONTROL_PARAM_STREAM_ID, streamid);
1542 chipio_set_control_param_no_mutex(codec,
1543 CONTROL_PARAM_STREAM_CONTROL, enable);
1548 * Set sampling rate of the connection point. NO MUTEX.
1550 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1551 int connid, enum ca0132_sample_rate rate)
1553 chipio_set_control_param_no_mutex(codec,
1554 CONTROL_PARAM_CONN_POINT_ID, connid);
1555 chipio_set_control_param_no_mutex(codec,
1556 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1560 * Set sampling rate of the connection point.
1562 static void chipio_set_conn_rate(struct hda_codec *codec,
1563 int connid, enum ca0132_sample_rate rate)
1565 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1566 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1571 * Writes to the 8051's internal address space directly instead of indirectly,
1572 * giving access to the special function registers located at addresses
1575 static void chipio_8051_write_direct(struct hda_codec *codec,
1576 unsigned int addr, unsigned int data)
1580 verb = VENDOR_CHIPIO_8051_WRITE_DIRECT | data;
1581 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1587 static void chipio_enable_clocks(struct hda_codec *codec)
1589 struct ca0132_spec *spec = codec->spec;
1591 mutex_lock(&spec->chipio_mutex);
1592 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1593 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1594 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1595 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1596 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1597 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1598 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1599 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1600 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1601 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1602 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1603 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1604 mutex_unlock(&spec->chipio_mutex);
1608 * CA0132 DSP IO stuffs
1610 static int dspio_send(struct hda_codec *codec, unsigned int reg,
1614 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1616 /* send bits of data specified by reg to dsp */
1618 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1619 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1622 } while (time_before(jiffies, timeout));
1628 * Wait for DSP to be ready for commands
1630 static void dspio_write_wait(struct hda_codec *codec)
1633 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1636 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1637 VENDOR_DSPIO_STATUS, 0);
1638 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1639 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1642 } while (time_before(jiffies, timeout));
1646 * Write SCP data to DSP
1648 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1650 struct ca0132_spec *spec = codec->spec;
1653 dspio_write_wait(codec);
1655 mutex_lock(&spec->chipio_mutex);
1656 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1661 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1666 /* OK, now check if the write itself has executed*/
1667 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1668 VENDOR_DSPIO_STATUS, 0);
1670 mutex_unlock(&spec->chipio_mutex);
1672 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1677 * Write multiple SCP data to DSP
1679 static int dspio_write_multiple(struct hda_codec *codec,
1680 unsigned int *buffer, unsigned int size)
1689 while (count < size) {
1690 status = dspio_write(codec, *buffer++);
1699 static int dspio_read(struct hda_codec *codec, unsigned int *data)
1703 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1707 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1708 if (status == -EIO ||
1709 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
1712 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1713 VENDOR_DSPIO_SCP_READ_DATA, 0);
1718 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
1719 unsigned int *buf_size, unsigned int size_count)
1722 unsigned int size = *buf_size;
1724 unsigned int skip_count;
1731 while (count < size && count < size_count) {
1732 status = dspio_read(codec, buffer++);
1740 while (skip_count < size) {
1741 status = dspio_read(codec, &dummy);
1753 * Construct the SCP header using corresponding fields
1755 static inline unsigned int
1756 make_scp_header(unsigned int target_id, unsigned int source_id,
1757 unsigned int get_flag, unsigned int req,
1758 unsigned int device_flag, unsigned int resp_flag,
1759 unsigned int error_flag, unsigned int data_size)
1761 unsigned int header = 0;
1763 header = (data_size & 0x1f) << 27;
1764 header |= (error_flag & 0x01) << 26;
1765 header |= (resp_flag & 0x01) << 25;
1766 header |= (device_flag & 0x01) << 24;
1767 header |= (req & 0x7f) << 17;
1768 header |= (get_flag & 0x01) << 16;
1769 header |= (source_id & 0xff) << 8;
1770 header |= target_id & 0xff;
1776 * Extract corresponding fields from SCP header
1779 extract_scp_header(unsigned int header,
1780 unsigned int *target_id, unsigned int *source_id,
1781 unsigned int *get_flag, unsigned int *req,
1782 unsigned int *device_flag, unsigned int *resp_flag,
1783 unsigned int *error_flag, unsigned int *data_size)
1786 *data_size = (header >> 27) & 0x1f;
1788 *error_flag = (header >> 26) & 0x01;
1790 *resp_flag = (header >> 25) & 0x01;
1792 *device_flag = (header >> 24) & 0x01;
1794 *req = (header >> 17) & 0x7f;
1796 *get_flag = (header >> 16) & 0x01;
1798 *source_id = (header >> 8) & 0xff;
1800 *target_id = header & 0xff;
1803 #define SCP_MAX_DATA_WORDS (16)
1805 /* Structure to contain any SCP message */
1808 unsigned int data[SCP_MAX_DATA_WORDS];
1811 static void dspio_clear_response_queue(struct hda_codec *codec)
1813 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1814 unsigned int dummy = 0;
1817 /* clear all from the response queue */
1819 status = dspio_read(codec, &dummy);
1820 } while (status == 0 && time_before(jiffies, timeout));
1823 static int dspio_get_response_data(struct hda_codec *codec)
1825 struct ca0132_spec *spec = codec->spec;
1826 unsigned int data = 0;
1829 if (dspio_read(codec, &data) < 0)
1832 if ((data & 0x00ffffff) == spec->wait_scp_header) {
1833 spec->scp_resp_header = data;
1834 spec->scp_resp_count = data >> 27;
1835 count = spec->wait_num_data;
1836 dspio_read_multiple(codec, spec->scp_resp_data,
1837 &spec->scp_resp_count, count);
1845 * Send SCP message to DSP
1847 static int dspio_send_scp_message(struct hda_codec *codec,
1848 unsigned char *send_buf,
1849 unsigned int send_buf_size,
1850 unsigned char *return_buf,
1851 unsigned int return_buf_size,
1852 unsigned int *bytes_returned)
1854 struct ca0132_spec *spec = codec->spec;
1856 unsigned int scp_send_size = 0;
1857 unsigned int total_size;
1858 bool waiting_for_resp = false;
1859 unsigned int header;
1860 struct scp_msg *ret_msg;
1861 unsigned int resp_src_id, resp_target_id;
1862 unsigned int data_size, src_id, target_id, get_flag, device_flag;
1865 *bytes_returned = 0;
1867 /* get scp header from buffer */
1868 header = *((unsigned int *)send_buf);
1869 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
1870 &device_flag, NULL, NULL, &data_size);
1871 scp_send_size = data_size + 1;
1872 total_size = (scp_send_size * 4);
1874 if (send_buf_size < total_size)
1877 if (get_flag || device_flag) {
1878 if (!return_buf || return_buf_size < 4 || !bytes_returned)
1881 spec->wait_scp_header = *((unsigned int *)send_buf);
1883 /* swap source id with target id */
1884 resp_target_id = src_id;
1885 resp_src_id = target_id;
1886 spec->wait_scp_header &= 0xffff0000;
1887 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
1888 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
1890 waiting_for_resp = true;
1893 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
1900 if (waiting_for_resp) {
1901 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1902 memset(return_buf, 0, return_buf_size);
1905 } while (spec->wait_scp && time_before(jiffies, timeout));
1906 waiting_for_resp = false;
1907 if (!spec->wait_scp) {
1908 ret_msg = (struct scp_msg *)return_buf;
1909 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
1910 memcpy(&ret_msg->data, spec->scp_resp_data,
1911 spec->wait_num_data);
1912 *bytes_returned = (spec->scp_resp_count + 1) * 4;
1924 * Prepare and send the SCP message to DSP
1925 * @codec: the HDA codec
1926 * @mod_id: ID of the DSP module to send the command
1927 * @src_id: ID of the source
1928 * @req: ID of request to send to the DSP module
1930 * @data: pointer to the data to send with the request, request specific
1931 * @len: length of the data, in bytes
1932 * @reply: point to the buffer to hold data returned for a reply
1933 * @reply_len: length of the reply buffer returned from GET
1935 * Returns zero or a negative error code.
1937 static int dspio_scp(struct hda_codec *codec,
1938 int mod_id, int src_id, int req, int dir, const void *data,
1939 unsigned int len, void *reply, unsigned int *reply_len)
1942 struct scp_msg scp_send, scp_reply;
1943 unsigned int ret_bytes, send_size, ret_size;
1944 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
1945 unsigned int reply_data_size;
1947 memset(&scp_send, 0, sizeof(scp_send));
1948 memset(&scp_reply, 0, sizeof(scp_reply));
1950 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
1953 if (dir == SCP_GET && reply == NULL) {
1954 codec_dbg(codec, "dspio_scp get but has no buffer\n");
1958 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
1959 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
1963 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
1964 0, 0, 0, len/sizeof(unsigned int));
1965 if (data != NULL && len > 0) {
1966 len = min((unsigned int)(sizeof(scp_send.data)), len);
1967 memcpy(scp_send.data, data, len);
1971 send_size = sizeof(unsigned int) + len;
1972 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
1973 send_size, (unsigned char *)&scp_reply,
1974 sizeof(scp_reply), &ret_bytes);
1977 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
1981 /* extract send and reply headers members */
1982 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
1983 NULL, NULL, NULL, NULL, NULL);
1984 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
1985 &reply_resp_flag, &reply_error_flag,
1991 if (reply_resp_flag && !reply_error_flag) {
1992 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
1993 / sizeof(unsigned int);
1995 if (*reply_len < ret_size*sizeof(unsigned int)) {
1996 codec_dbg(codec, "reply too long for buf\n");
1998 } else if (ret_size != reply_data_size) {
1999 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
2001 } else if (!reply) {
2002 codec_dbg(codec, "NULL reply\n");
2005 *reply_len = ret_size*sizeof(unsigned int);
2006 memcpy(reply, scp_reply.data, *reply_len);
2009 codec_dbg(codec, "reply ill-formed or errflag set\n");
2017 * Set DSP parameters
2019 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2020 int src_id, int req, const void *data, unsigned int len)
2022 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2026 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2027 int req, const unsigned int data)
2029 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2030 sizeof(unsigned int));
2033 static int dspio_set_uint_param_no_source(struct hda_codec *codec, int mod_id,
2034 int req, const unsigned int data)
2036 return dspio_set_param(codec, mod_id, 0x00, req, &data,
2037 sizeof(unsigned int));
2041 * Allocate a DSP DMA channel via an SCP message
2043 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2046 unsigned int size = sizeof(dma_chan);
2048 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2049 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2050 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
2054 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2058 if ((*dma_chan + 1) == 0) {
2059 codec_dbg(codec, "no free dma channels to allocate\n");
2063 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2064 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2070 * Free a DSP DMA via an SCP message
2072 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2075 unsigned int dummy = 0;
2077 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2078 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2080 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2081 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
2082 sizeof(dma_chan), NULL, &dummy);
2085 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2089 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2097 static int dsp_set_run_state(struct hda_codec *codec)
2099 unsigned int dbg_ctrl_reg;
2100 unsigned int halt_state;
2103 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2107 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
2108 DSP_DBGCNTL_STATE_LOBIT;
2110 if (halt_state != 0) {
2111 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
2112 DSP_DBGCNTL_SS_MASK);
2113 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2118 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
2119 DSP_DBGCNTL_EXEC_MASK;
2120 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2132 static int dsp_reset(struct hda_codec *codec)
2137 codec_dbg(codec, "dsp_reset\n");
2139 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2141 } while (res == -EIO && retry);
2144 codec_dbg(codec, "dsp_reset timeout\n");
2152 * Convert chip address to DSP address
2154 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2155 bool *code, bool *yram)
2157 *code = *yram = false;
2159 if (UC_RANGE(chip_addx, 1)) {
2161 return UC_OFF(chip_addx);
2162 } else if (X_RANGE_ALL(chip_addx, 1)) {
2163 return X_OFF(chip_addx);
2164 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2166 return Y_OFF(chip_addx);
2169 return INVALID_CHIP_ADDRESS;
2173 * Check if the DSP DMA is active
2175 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2177 unsigned int dma_chnlstart_reg;
2179 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2181 return ((dma_chnlstart_reg & (1 <<
2182 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2185 static int dsp_dma_setup_common(struct hda_codec *codec,
2186 unsigned int chip_addx,
2187 unsigned int dma_chan,
2188 unsigned int port_map_mask,
2192 unsigned int chnl_prop;
2193 unsigned int dsp_addx;
2194 unsigned int active;
2197 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2199 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2200 codec_dbg(codec, "dma chan num invalid\n");
2204 if (dsp_is_dma_active(codec, dma_chan)) {
2205 codec_dbg(codec, "dma already active\n");
2209 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2211 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2212 codec_dbg(codec, "invalid chip addr\n");
2216 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2219 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2222 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2226 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2229 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2233 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2235 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2237 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2239 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2241 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2244 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2247 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2251 codec_dbg(codec, "read ACTIVE Reg fail\n");
2254 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2257 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2258 DSPDMAC_ACTIVE_AAR_MASK;
2260 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2262 codec_dbg(codec, "write ACTIVE Reg fail\n");
2266 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2268 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2271 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2274 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2276 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2277 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2279 codec_dbg(codec, "write IRQCNT Reg fail\n");
2282 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2285 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2286 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2287 chip_addx, dsp_addx, dma_chan,
2288 port_map_mask, chnl_prop, active);
2290 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2296 * Setup the DSP DMA per-transfer-specific registers
2298 static int dsp_dma_setup(struct hda_codec *codec,
2299 unsigned int chip_addx,
2301 unsigned int dma_chan)
2305 unsigned int dsp_addx;
2306 unsigned int addr_field;
2307 unsigned int incr_field;
2308 unsigned int base_cnt;
2309 unsigned int cur_cnt;
2310 unsigned int dma_cfg = 0;
2311 unsigned int adr_ofs = 0;
2312 unsigned int xfr_cnt = 0;
2313 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2314 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2316 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2318 if (count > max_dma_count) {
2319 codec_dbg(codec, "count too big\n");
2323 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2324 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2325 codec_dbg(codec, "invalid chip addr\n");
2329 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2331 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2337 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2339 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2342 dma_cfg = addr_field + incr_field;
2343 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2346 codec_dbg(codec, "write DMACFG Reg fail\n");
2349 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2351 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2354 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2357 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2360 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2362 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2364 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2366 xfr_cnt = base_cnt | cur_cnt;
2368 status = chipio_write(codec,
2369 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2371 codec_dbg(codec, "write XFRCNT Reg fail\n");
2374 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2377 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2378 "ADROFS=0x%x, XFRCNT=0x%x\n",
2379 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2381 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2389 static int dsp_dma_start(struct hda_codec *codec,
2390 unsigned int dma_chan, bool ovly)
2392 unsigned int reg = 0;
2395 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2398 status = chipio_read(codec,
2399 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2402 codec_dbg(codec, "read CHNLSTART reg fail\n");
2405 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2407 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2408 DSPDMAC_CHNLSTART_DIS_MASK);
2411 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2412 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2414 codec_dbg(codec, "write CHNLSTART reg fail\n");
2417 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2425 static int dsp_dma_stop(struct hda_codec *codec,
2426 unsigned int dma_chan, bool ovly)
2428 unsigned int reg = 0;
2431 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2434 status = chipio_read(codec,
2435 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2438 codec_dbg(codec, "read CHNLSTART reg fail\n");
2441 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2442 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2443 DSPDMAC_CHNLSTART_DIS_MASK);
2446 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2447 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2449 codec_dbg(codec, "write CHNLSTART reg fail\n");
2452 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2458 * Allocate router ports
2460 * @codec: the HDA codec
2461 * @num_chans: number of channels in the stream
2462 * @ports_per_channel: number of ports per channel
2463 * @start_device: start device
2464 * @port_map: pointer to the port list to hold the allocated ports
2466 * Returns zero or a negative error code.
2468 static int dsp_allocate_router_ports(struct hda_codec *codec,
2469 unsigned int num_chans,
2470 unsigned int ports_per_channel,
2471 unsigned int start_device,
2472 unsigned int *port_map)
2478 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2482 val = start_device << 6;
2483 val |= (ports_per_channel - 1) << 4;
2484 val |= num_chans - 1;
2486 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2487 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2490 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2491 VENDOR_CHIPIO_PORT_ALLOC_SET,
2494 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2498 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2499 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2503 return (res < 0) ? res : 0;
2509 static int dsp_free_router_ports(struct hda_codec *codec)
2513 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2517 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2518 VENDOR_CHIPIO_PORT_FREE_SET,
2521 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2527 * Allocate DSP ports for the download stream
2529 static int dsp_allocate_ports(struct hda_codec *codec,
2530 unsigned int num_chans,
2531 unsigned int rate_multi, unsigned int *port_map)
2535 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2537 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2538 codec_dbg(codec, "bad rate multiple\n");
2542 status = dsp_allocate_router_ports(codec, num_chans,
2543 rate_multi, 0, port_map);
2545 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2550 static int dsp_allocate_ports_format(struct hda_codec *codec,
2551 const unsigned short fmt,
2552 unsigned int *port_map)
2555 unsigned int num_chans;
2557 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2558 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2559 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2561 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2562 codec_dbg(codec, "bad rate multiple\n");
2566 num_chans = get_hdafmt_chs(fmt) + 1;
2568 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2576 static int dsp_free_ports(struct hda_codec *codec)
2580 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2582 status = dsp_free_router_ports(codec);
2584 codec_dbg(codec, "free router ports fail\n");
2587 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2593 * HDA DMA engine stuffs for DSP code download
2596 struct hda_codec *codec;
2597 unsigned short m_converter_format;
2598 struct snd_dma_buffer *dmab;
2599 unsigned int buf_size;
2608 static int dma_convert_to_hda_format(struct hda_codec *codec,
2609 unsigned int sample_rate,
2610 unsigned short channels,
2611 unsigned short *hda_format)
2613 unsigned int format_val;
2615 format_val = snd_hdac_calc_stream_format(sample_rate,
2616 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
2619 *hda_format = (unsigned short)format_val;
2625 * Reset DMA for DSP download
2627 static int dma_reset(struct dma_engine *dma)
2629 struct hda_codec *codec = dma->codec;
2630 struct ca0132_spec *spec = codec->spec;
2633 if (dma->dmab->area)
2634 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2636 status = snd_hda_codec_load_dsp_prepare(codec,
2637 dma->m_converter_format,
2642 spec->dsp_stream_id = status;
2646 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2651 case DMA_STATE_STOP:
2661 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2665 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2667 return dma->dmab->bytes;
2670 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2672 return dma->dmab->area;
2675 static int dma_xfer(struct dma_engine *dma,
2676 const unsigned int *data,
2679 memcpy(dma->dmab->area, data, count);
2683 static void dma_get_converter_format(
2684 struct dma_engine *dma,
2685 unsigned short *format)
2688 *format = dma->m_converter_format;
2691 static unsigned int dma_get_stream_id(struct dma_engine *dma)
2693 struct ca0132_spec *spec = dma->codec->spec;
2695 return spec->dsp_stream_id;
2698 struct dsp_image_seg {
2705 static const u32 g_magic_value = 0x4c46584d;
2706 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2708 static bool is_valid(const struct dsp_image_seg *p)
2710 return p->magic == g_magic_value;
2713 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
2715 return g_chip_addr_magic_value == p->chip_addr;
2718 static bool is_last(const struct dsp_image_seg *p)
2720 return p->count == 0;
2723 static size_t dsp_sizeof(const struct dsp_image_seg *p)
2725 return struct_size(p, data, p->count);
2728 static const struct dsp_image_seg *get_next_seg_ptr(
2729 const struct dsp_image_seg *p)
2731 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
2735 * CA0132 chip DSP transfer stuffs. For DSP download.
2737 #define INVALID_DMA_CHANNEL (~0U)
2740 * Program a list of address/data pairs via the ChipIO widget.
2741 * The segment data is in the format of successive pairs of words.
2742 * These are repeated as indicated by the segment's count field.
2744 static int dspxfr_hci_write(struct hda_codec *codec,
2745 const struct dsp_image_seg *fls)
2751 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
2752 codec_dbg(codec, "hci_write invalid params\n");
2757 data = (u32 *)(fls->data);
2758 while (count >= 2) {
2759 status = chipio_write(codec, data[0], data[1]);
2761 codec_dbg(codec, "hci_write chipio failed\n");
2771 * Write a block of data into DSP code or data RAM using pre-allocated
2774 * @codec: the HDA codec
2775 * @fls: pointer to a fast load image
2776 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2778 * @dma_engine: pointer to DMA engine to be used for DSP download
2779 * @dma_chan: The number of DMA channels used for DSP download
2780 * @port_map_mask: port mapping
2781 * @ovly: TRUE if overlay format is required
2783 * Returns zero or a negative error code.
2785 static int dspxfr_one_seg(struct hda_codec *codec,
2786 const struct dsp_image_seg *fls,
2788 struct dma_engine *dma_engine,
2789 unsigned int dma_chan,
2790 unsigned int port_map_mask,
2794 bool comm_dma_setup_done = false;
2795 const unsigned int *data;
2796 unsigned int chip_addx;
2797 unsigned int words_to_write;
2798 unsigned int buffer_size_words;
2799 unsigned char *buffer_addx;
2800 unsigned short hda_format;
2801 unsigned int sample_rate_div;
2802 unsigned int sample_rate_mul;
2803 unsigned int num_chans;
2804 unsigned int hda_frame_size_words;
2805 unsigned int remainder_words;
2806 const u32 *data_remainder;
2807 u32 chip_addx_remainder;
2808 unsigned int run_size_words;
2809 const struct dsp_image_seg *hci_write = NULL;
2810 unsigned long timeout;
2815 if (is_hci_prog_list_seg(fls)) {
2817 fls = get_next_seg_ptr(fls);
2820 if (hci_write && (!fls || is_last(fls))) {
2821 codec_dbg(codec, "hci_write\n");
2822 return dspxfr_hci_write(codec, hci_write);
2825 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2826 codec_dbg(codec, "Invalid Params\n");
2831 chip_addx = fls->chip_addr,
2832 words_to_write = fls->count;
2834 if (!words_to_write)
2835 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
2837 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
2839 if (!UC_RANGE(chip_addx, words_to_write) &&
2840 !X_RANGE_ALL(chip_addx, words_to_write) &&
2841 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2842 codec_dbg(codec, "Invalid chip_addx Params\n");
2846 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
2849 buffer_addx = dma_get_buffer_addr(dma_engine);
2851 if (buffer_addx == NULL) {
2852 codec_dbg(codec, "dma_engine buffer NULL\n");
2856 dma_get_converter_format(dma_engine, &hda_format);
2857 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
2858 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
2859 num_chans = get_hdafmt_chs(hda_format) + 1;
2861 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
2862 (num_chans * sample_rate_mul / sample_rate_div));
2864 if (hda_frame_size_words == 0) {
2865 codec_dbg(codec, "frmsz zero\n");
2869 buffer_size_words = min(buffer_size_words,
2870 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2872 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2874 "chpadr=0x%08x frmsz=%u nchan=%u "
2875 "rate_mul=%u div=%u bufsz=%u\n",
2876 chip_addx, hda_frame_size_words, num_chans,
2877 sample_rate_mul, sample_rate_div, buffer_size_words);
2879 if (buffer_size_words < hda_frame_size_words) {
2880 codec_dbg(codec, "dspxfr_one_seg:failed\n");
2884 remainder_words = words_to_write % hda_frame_size_words;
2885 data_remainder = data;
2886 chip_addx_remainder = chip_addx;
2888 data += remainder_words;
2889 chip_addx += remainder_words*sizeof(u32);
2890 words_to_write -= remainder_words;
2892 while (words_to_write != 0) {
2893 run_size_words = min(buffer_size_words, words_to_write);
2894 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2895 words_to_write, run_size_words, remainder_words);
2896 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2897 if (!comm_dma_setup_done) {
2898 status = dsp_dma_stop(codec, dma_chan, ovly);
2901 status = dsp_dma_setup_common(codec, chip_addx,
2902 dma_chan, port_map_mask, ovly);
2905 comm_dma_setup_done = true;
2908 status = dsp_dma_setup(codec, chip_addx,
2909 run_size_words, dma_chan);
2912 status = dsp_dma_start(codec, dma_chan, ovly);
2915 if (!dsp_is_dma_active(codec, dma_chan)) {
2916 codec_dbg(codec, "dspxfr:DMA did not start\n");
2919 status = dma_set_state(dma_engine, DMA_STATE_RUN);
2922 if (remainder_words != 0) {
2923 status = chipio_write_multiple(codec,
2924 chip_addx_remainder,
2929 remainder_words = 0;
2932 status = dspxfr_hci_write(codec, hci_write);
2938 timeout = jiffies + msecs_to_jiffies(2000);
2940 dma_active = dsp_is_dma_active(codec, dma_chan);
2944 } while (time_before(jiffies, timeout));
2948 codec_dbg(codec, "+++++ DMA complete\n");
2949 dma_set_state(dma_engine, DMA_STATE_STOP);
2950 status = dma_reset(dma_engine);
2955 data += run_size_words;
2956 chip_addx += run_size_words*sizeof(u32);
2957 words_to_write -= run_size_words;
2960 if (remainder_words != 0) {
2961 status = chipio_write_multiple(codec, chip_addx_remainder,
2962 data_remainder, remainder_words);
2969 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2971 * @codec: the HDA codec
2972 * @fls_data: pointer to a fast load image
2973 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2975 * @sample_rate: sampling rate of the stream used for DSP download
2976 * @channels: channels of the stream used for DSP download
2977 * @ovly: TRUE if overlay format is required
2979 * Returns zero or a negative error code.
2981 static int dspxfr_image(struct hda_codec *codec,
2982 const struct dsp_image_seg *fls_data,
2984 unsigned int sample_rate,
2985 unsigned short channels,
2988 struct ca0132_spec *spec = codec->spec;
2990 unsigned short hda_format = 0;
2991 unsigned int response;
2992 unsigned char stream_id = 0;
2993 struct dma_engine *dma_engine;
2994 unsigned int dma_chan;
2995 unsigned int port_map_mask;
2997 if (fls_data == NULL)
3000 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
3004 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
3005 if (!dma_engine->dmab) {
3010 dma_engine->codec = codec;
3011 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3012 dma_engine->m_converter_format = hda_format;
3013 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
3014 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
3016 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
3018 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3019 hda_format, &response);
3022 codec_dbg(codec, "set converter format fail\n");
3026 status = snd_hda_codec_load_dsp_prepare(codec,
3027 dma_engine->m_converter_format,
3028 dma_engine->buf_size,
3032 spec->dsp_stream_id = status;
3035 status = dspio_alloc_dma_chan(codec, &dma_chan);
3037 codec_dbg(codec, "alloc dmachan fail\n");
3038 dma_chan = INVALID_DMA_CHANNEL;
3044 status = dsp_allocate_ports_format(codec, hda_format,
3047 codec_dbg(codec, "alloc ports fail\n");
3051 stream_id = dma_get_stream_id(dma_engine);
3052 status = codec_set_converter_stream_channel(codec,
3053 WIDGET_CHIP_CTRL, stream_id, 0, &response);
3055 codec_dbg(codec, "set stream chan fail\n");
3059 while ((fls_data != NULL) && !is_last(fls_data)) {
3060 if (!is_valid(fls_data)) {
3061 codec_dbg(codec, "FLS check fail\n");
3065 status = dspxfr_one_seg(codec, fls_data, reloc,
3066 dma_engine, dma_chan,
3067 port_map_mask, ovly);
3071 if (is_hci_prog_list_seg(fls_data))
3072 fls_data = get_next_seg_ptr(fls_data);
3074 if ((fls_data != NULL) && !is_last(fls_data))
3075 fls_data = get_next_seg_ptr(fls_data);
3078 if (port_map_mask != 0)
3079 status = dsp_free_ports(codec);
3084 status = codec_set_converter_stream_channel(codec,
3085 WIDGET_CHIP_CTRL, 0, 0, &response);
3088 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
3089 dspio_free_dma_chan(codec, dma_chan);
3091 if (dma_engine->dmab->area)
3092 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3093 kfree(dma_engine->dmab);
3100 * CA0132 DSP download stuffs.
3102 static void dspload_post_setup(struct hda_codec *codec)
3104 struct ca0132_spec *spec = codec->spec;
3105 codec_dbg(codec, "---- dspload_post_setup ------\n");
3106 if (!ca0132_use_alt_functions(spec)) {
3107 /*set DSP speaker to 2.0 configuration*/
3108 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3109 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3111 /*update write pointer*/
3112 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3117 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3119 * @codec: the HDA codec
3120 * @fls: pointer to a fast load image
3121 * @ovly: TRUE if overlay format is required
3122 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3124 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3125 * @router_chans: number of audio router channels to be allocated (0 means use
3126 * internal defaults; max is 32)
3128 * Download DSP from a DSP Image Fast Load structure. This structure is a
3129 * linear, non-constant sized element array of structures, each of which
3130 * contain the count of the data to be loaded, the data itself, and the
3131 * corresponding starting chip address of the starting data location.
3132 * Returns zero or a negative error code.
3134 static int dspload_image(struct hda_codec *codec,
3135 const struct dsp_image_seg *fls,
3142 unsigned int sample_rate;
3143 unsigned short channels;
3145 codec_dbg(codec, "---- dspload_image begin ------\n");
3146 if (router_chans == 0) {
3148 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3150 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3153 sample_rate = 48000;
3154 channels = (unsigned short)router_chans;
3156 while (channels > 16) {
3162 codec_dbg(codec, "Ready to program DMA\n");
3164 status = dsp_reset(codec);
3169 codec_dbg(codec, "dsp_reset() complete\n");
3170 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3176 codec_dbg(codec, "dspxfr_image() complete\n");
3177 if (autostart && !ovly) {
3178 dspload_post_setup(codec);
3179 status = dsp_set_run_state(codec);
3182 codec_dbg(codec, "LOAD FINISHED\n");
3188 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3189 static bool dspload_is_loaded(struct hda_codec *codec)
3191 unsigned int data = 0;
3194 status = chipio_read(codec, 0x40004, &data);
3195 if ((status < 0) || (data != 1))
3201 #define dspload_is_loaded(codec) false
3204 static bool dspload_wait_loaded(struct hda_codec *codec)
3206 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3209 if (dspload_is_loaded(codec)) {
3210 codec_info(codec, "ca0132 DSP downloaded and running\n");
3214 } while (time_before(jiffies, timeout));
3216 codec_err(codec, "ca0132 failed to download DSP\n");
3221 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3222 * based cards, and has a second mmio region, region2, that's used for special
3227 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3228 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3229 * The first eight bits are just the number of the pin. So far, I've only seen
3230 * this number go to 7.
3231 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3232 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3233 * then off to send that bit.
3235 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3238 struct ca0132_spec *spec = codec->spec;
3239 unsigned short gpio_data;
3241 gpio_data = gpio_pin & 0xF;
3242 gpio_data |= ((enable << 8) & 0x100);
3244 writew(gpio_data, spec->mem_base + 0x320);
3248 * Special pci region2 commands that are only used by the AE-5. They follow
3249 * a set format, and require reads at certain points to seemingly 'clear'
3250 * the response data. My first tests didn't do these reads, and would cause
3251 * the card to get locked up until the memory was read. These commands
3252 * seem to work with three distinct values that I've taken to calling group,
3253 * target-id, and value.
3255 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3256 unsigned int target, unsigned int value)
3258 struct ca0132_spec *spec = codec->spec;
3259 unsigned int write_val;
3261 writel(0x0000007e, spec->mem_base + 0x210);
3262 readl(spec->mem_base + 0x210);
3263 writel(0x0000005a, spec->mem_base + 0x210);
3264 readl(spec->mem_base + 0x210);
3265 readl(spec->mem_base + 0x210);
3267 writel(0x00800005, spec->mem_base + 0x20c);
3268 writel(group, spec->mem_base + 0x804);
3270 writel(0x00800005, spec->mem_base + 0x20c);
3271 write_val = (target & 0xff);
3272 write_val |= (value << 8);
3275 writel(write_val, spec->mem_base + 0x204);
3277 * Need delay here or else it goes too fast and works inconsistently.
3281 readl(spec->mem_base + 0x860);
3282 readl(spec->mem_base + 0x854);
3283 readl(spec->mem_base + 0x840);
3285 writel(0x00800004, spec->mem_base + 0x20c);
3286 writel(0x00000000, spec->mem_base + 0x210);
3287 readl(spec->mem_base + 0x210);
3288 readl(spec->mem_base + 0x210);
3292 * This second type of command is used for setting the sound filter type.
3294 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3295 unsigned int group, unsigned int target, unsigned int value)
3297 struct ca0132_spec *spec = codec->spec;
3298 unsigned int write_val;
3300 writel(0x0000007e, spec->mem_base + 0x210);
3301 readl(spec->mem_base + 0x210);
3302 writel(0x0000005a, spec->mem_base + 0x210);
3303 readl(spec->mem_base + 0x210);
3304 readl(spec->mem_base + 0x210);
3306 writel(0x00800003, spec->mem_base + 0x20c);
3307 writel(group, spec->mem_base + 0x804);
3309 writel(0x00800005, spec->mem_base + 0x20c);
3310 write_val = (target & 0xff);
3311 write_val |= (value << 8);
3314 writel(write_val, spec->mem_base + 0x204);
3316 readl(spec->mem_base + 0x860);
3317 readl(spec->mem_base + 0x854);
3318 readl(spec->mem_base + 0x840);
3320 writel(0x00800004, spec->mem_base + 0x20c);
3321 writel(0x00000000, spec->mem_base + 0x210);
3322 readl(spec->mem_base + 0x210);
3323 readl(spec->mem_base + 0x210);
3327 * Setup GPIO for the other variants of Core3D.
3331 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3332 * the card shows as having no GPIO pins.
3334 static void ca0132_gpio_init(struct hda_codec *codec)
3336 struct ca0132_spec *spec = codec->spec;
3338 switch (ca0132_quirk(spec)) {
3341 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3342 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3343 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3346 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3347 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3355 /* Sets the GPIO for audio output. */
3356 static void ca0132_gpio_setup(struct hda_codec *codec)
3358 struct ca0132_spec *spec = codec->spec;
3360 switch (ca0132_quirk(spec)) {
3362 snd_hda_codec_write(codec, 0x01, 0,
3363 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3364 snd_hda_codec_write(codec, 0x01, 0,
3365 AC_VERB_SET_GPIO_MASK, 0x07);
3366 snd_hda_codec_write(codec, 0x01, 0,
3367 AC_VERB_SET_GPIO_DATA, 0x04);
3368 snd_hda_codec_write(codec, 0x01, 0,
3369 AC_VERB_SET_GPIO_DATA, 0x06);
3372 snd_hda_codec_write(codec, 0x01, 0,
3373 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3374 snd_hda_codec_write(codec, 0x01, 0,
3375 AC_VERB_SET_GPIO_MASK, 0x1F);
3376 snd_hda_codec_write(codec, 0x01, 0,
3377 AC_VERB_SET_GPIO_DATA, 0x0C);
3385 * GPIO control functions for the Recon3D integrated.
3388 enum r3di_gpio_bit {
3389 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3390 R3DI_MIC_SELECT_BIT = 1,
3391 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3392 R3DI_OUT_SELECT_BIT = 2,
3394 * I dunno what this actually does, but it stays on until the dsp
3397 R3DI_GPIO_DSP_DOWNLOADING = 3,
3399 * Same as above, no clue what it does, but it comes on after the dsp
3402 R3DI_GPIO_DSP_DOWNLOADED = 4
3405 enum r3di_mic_select {
3406 /* Set GPIO bit 1 to 0 for rear mic */
3408 /* Set GPIO bit 1 to 1 for front microphone*/
3412 enum r3di_out_select {
3413 /* Set GPIO bit 2 to 0 for headphone */
3414 R3DI_HEADPHONE_OUT = 0,
3415 /* Set GPIO bit 2 to 1 for speaker */
3418 enum r3di_dsp_status {
3419 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3420 R3DI_DSP_DOWNLOADING = 0,
3421 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3422 R3DI_DSP_DOWNLOADED = 1
3426 static void r3di_gpio_mic_set(struct hda_codec *codec,
3427 enum r3di_mic_select cur_mic)
3429 unsigned int cur_gpio;
3431 /* Get the current GPIO Data setup */
3432 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3436 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3438 case R3DI_FRONT_MIC:
3439 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3442 snd_hda_codec_write(codec, codec->core.afg, 0,
3443 AC_VERB_SET_GPIO_DATA, cur_gpio);
3446 static void r3di_gpio_out_set(struct hda_codec *codec,
3447 enum r3di_out_select cur_out)
3449 unsigned int cur_gpio;
3451 /* Get the current GPIO Data setup */
3452 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3455 case R3DI_HEADPHONE_OUT:
3456 cur_gpio &= ~(1 << R3DI_OUT_SELECT_BIT);
3459 cur_gpio |= (1 << R3DI_OUT_SELECT_BIT);
3462 snd_hda_codec_write(codec, codec->core.afg, 0,
3463 AC_VERB_SET_GPIO_DATA, cur_gpio);
3466 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3467 enum r3di_dsp_status dsp_status)
3469 unsigned int cur_gpio;
3471 /* Get the current GPIO Data setup */
3472 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3474 switch (dsp_status) {
3475 case R3DI_DSP_DOWNLOADING:
3476 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3477 snd_hda_codec_write(codec, codec->core.afg, 0,
3478 AC_VERB_SET_GPIO_DATA, cur_gpio);
3480 case R3DI_DSP_DOWNLOADED:
3481 /* Set DOWNLOADING bit to 0. */
3482 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3484 snd_hda_codec_write(codec, codec->core.afg, 0,
3485 AC_VERB_SET_GPIO_DATA, cur_gpio);
3487 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3491 snd_hda_codec_write(codec, codec->core.afg, 0,
3492 AC_VERB_SET_GPIO_DATA, cur_gpio);
3498 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3499 struct hda_codec *codec,
3500 unsigned int stream_tag,
3501 unsigned int format,
3502 struct snd_pcm_substream *substream)
3504 struct ca0132_spec *spec = codec->spec;
3506 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3511 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3512 struct hda_codec *codec,
3513 struct snd_pcm_substream *substream)
3515 struct ca0132_spec *spec = codec->spec;
3517 if (spec->dsp_state == DSP_DOWNLOADING)
3520 /*If Playback effects are on, allow stream some time to flush
3522 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3525 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3530 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3531 struct hda_codec *codec,
3532 struct snd_pcm_substream *substream)
3534 struct ca0132_spec *spec = codec->spec;
3535 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3536 struct snd_pcm_runtime *runtime = substream->runtime;
3538 if (spec->dsp_state != DSP_DOWNLOADED)
3541 /* Add latency if playback enhancement and either effect is enabled. */
3542 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3543 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3544 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3545 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3548 /* Applying Speaker EQ adds latency as well. */
3549 if (spec->cur_out_type == SPEAKER_OUT)
3550 latency += DSP_SPEAKER_OUT_LATENCY;
3552 return (latency * runtime->rate) / 1000;
3558 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3559 struct hda_codec *codec,
3560 struct snd_pcm_substream *substream)
3562 struct ca0132_spec *spec = codec->spec;
3563 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3566 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3567 struct hda_codec *codec,
3568 unsigned int stream_tag,
3569 unsigned int format,
3570 struct snd_pcm_substream *substream)
3572 struct ca0132_spec *spec = codec->spec;
3573 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3574 stream_tag, format, substream);
3577 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3578 struct hda_codec *codec,
3579 struct snd_pcm_substream *substream)
3581 struct ca0132_spec *spec = codec->spec;
3582 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3585 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3586 struct hda_codec *codec,
3587 struct snd_pcm_substream *substream)
3589 struct ca0132_spec *spec = codec->spec;
3590 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3596 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3597 struct hda_codec *codec,
3598 unsigned int stream_tag,
3599 unsigned int format,
3600 struct snd_pcm_substream *substream)
3602 snd_hda_codec_setup_stream(codec, hinfo->nid,
3603 stream_tag, 0, format);
3608 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3609 struct hda_codec *codec,
3610 struct snd_pcm_substream *substream)
3612 struct ca0132_spec *spec = codec->spec;
3614 if (spec->dsp_state == DSP_DOWNLOADING)
3617 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3621 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
3622 struct hda_codec *codec,
3623 struct snd_pcm_substream *substream)
3625 struct ca0132_spec *spec = codec->spec;
3626 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
3627 struct snd_pcm_runtime *runtime = substream->runtime;
3629 if (spec->dsp_state != DSP_DOWNLOADED)
3632 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3633 latency += DSP_CRYSTAL_VOICE_LATENCY;
3635 return (latency * runtime->rate) / 1000;
3643 * Mixer controls helpers.
3645 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
3646 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3648 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3649 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3650 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3651 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3652 .info = ca0132_volume_info, \
3653 .get = ca0132_volume_get, \
3654 .put = ca0132_volume_put, \
3655 .tlv = { .c = ca0132_volume_tlv }, \
3656 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3659 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
3660 * volume put, which is used for setting the DSP volume. This was done because
3661 * the ca0132 functions were taking too much time and causing lag.
3663 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
3664 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3666 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3667 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3668 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3669 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3670 .info = snd_hda_mixer_amp_volume_info, \
3671 .get = snd_hda_mixer_amp_volume_get, \
3672 .put = ca0132_alt_volume_put, \
3673 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
3674 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3676 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
3677 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3679 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3680 .info = snd_hda_mixer_amp_switch_info, \
3681 .get = ca0132_switch_get, \
3682 .put = ca0132_switch_put, \
3683 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3686 #define CA0132_CODEC_VOL(xname, nid, dir) \
3687 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
3688 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
3689 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
3690 #define CA0132_CODEC_MUTE(xname, nid, dir) \
3691 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
3695 * Lookup table with decibel values for the DSP. When volume is changed in
3696 * Windows, the DSP is also sent the dB value in floating point. In Windows,
3697 * these values have decimal points, probably because the Windows driver
3698 * actually uses floating point. We can't here, so I made a lookup table of
3699 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
3700 * DAC's, and 9 is the maximum.
3702 static const unsigned int float_vol_db_lookup[] = {
3703 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
3704 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
3705 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
3706 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
3707 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
3708 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
3709 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
3710 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
3711 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
3712 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
3713 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
3714 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3715 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3716 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3717 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3718 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3719 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
3723 * This table counts from float 0 to 1 in increments of .01, which is
3724 * useful for a few different sliders.
3726 static const unsigned int float_zero_to_one_lookup[] = {
3727 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3728 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3729 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3730 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3731 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3732 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3733 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3734 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3735 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3736 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3737 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3738 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3739 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3740 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3741 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3742 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3743 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3747 * This table counts from float 10 to 1000, which is the range of the x-bass
3748 * crossover slider in Windows.
3750 static const unsigned int float_xbass_xover_lookup[] = {
3751 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
3752 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
3753 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
3754 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
3755 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
3756 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
3757 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
3758 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
3759 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
3760 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
3761 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
3762 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
3763 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
3764 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
3765 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
3766 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
3767 0x44728000, 0x44750000, 0x44778000, 0x447A0000
3770 /* The following are for tuning of products */
3771 #ifdef ENABLE_TUNING_CONTROLS
3773 static const unsigned int voice_focus_vals_lookup[] = {
3774 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
3775 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
3776 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
3777 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
3778 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
3779 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
3780 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
3781 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
3782 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
3783 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
3784 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
3785 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
3786 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
3787 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
3788 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
3789 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
3790 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
3791 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
3792 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
3793 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
3794 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
3795 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
3796 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
3797 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
3798 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
3799 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
3800 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
3803 static const unsigned int mic_svm_vals_lookup[] = {
3804 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3805 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3806 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3807 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3808 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3809 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3810 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3811 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3812 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3813 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3814 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3815 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3816 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3817 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3818 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3819 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3820 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3823 static const unsigned int equalizer_vals_lookup[] = {
3824 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3825 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3826 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3827 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3828 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3829 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
3830 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
3831 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
3835 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
3836 const unsigned int *lookup, int idx)
3840 for (i = 0; i < TUNING_CTLS_COUNT; i++)
3841 if (nid == ca0132_tuning_ctls[i].nid)
3844 snd_hda_power_up(codec);
3845 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
3846 ca0132_tuning_ctls[i].req,
3847 &(lookup[idx]), sizeof(unsigned int));
3848 snd_hda_power_down(codec);
3853 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
3854 struct snd_ctl_elem_value *ucontrol)
3856 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3857 struct ca0132_spec *spec = codec->spec;
3858 hda_nid_t nid = get_amp_nid(kcontrol);
3859 long *valp = ucontrol->value.integer.value;
3860 int idx = nid - TUNING_CTL_START_NID;
3862 *valp = spec->cur_ctl_vals[idx];
3866 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
3867 struct snd_ctl_elem_info *uinfo)
3869 int chs = get_amp_channels(kcontrol);
3870 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3871 uinfo->count = chs == 3 ? 2 : 1;
3872 uinfo->value.integer.min = 20;
3873 uinfo->value.integer.max = 180;
3874 uinfo->value.integer.step = 1;
3879 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
3880 struct snd_ctl_elem_value *ucontrol)
3882 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3883 struct ca0132_spec *spec = codec->spec;
3884 hda_nid_t nid = get_amp_nid(kcontrol);
3885 long *valp = ucontrol->value.integer.value;
3888 idx = nid - TUNING_CTL_START_NID;
3890 if (spec->cur_ctl_vals[idx] == *valp)
3893 spec->cur_ctl_vals[idx] = *valp;
3896 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
3901 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
3902 struct snd_ctl_elem_info *uinfo)
3904 int chs = get_amp_channels(kcontrol);
3905 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3906 uinfo->count = chs == 3 ? 2 : 1;
3907 uinfo->value.integer.min = 0;
3908 uinfo->value.integer.max = 100;
3909 uinfo->value.integer.step = 1;
3914 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
3915 struct snd_ctl_elem_value *ucontrol)
3917 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3918 struct ca0132_spec *spec = codec->spec;
3919 hda_nid_t nid = get_amp_nid(kcontrol);
3920 long *valp = ucontrol->value.integer.value;
3923 idx = nid - TUNING_CTL_START_NID;
3925 if (spec->cur_ctl_vals[idx] == *valp)
3928 spec->cur_ctl_vals[idx] = *valp;
3931 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
3936 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
3937 struct snd_ctl_elem_info *uinfo)
3939 int chs = get_amp_channels(kcontrol);
3940 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3941 uinfo->count = chs == 3 ? 2 : 1;
3942 uinfo->value.integer.min = 0;
3943 uinfo->value.integer.max = 48;
3944 uinfo->value.integer.step = 1;
3949 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
3950 struct snd_ctl_elem_value *ucontrol)
3952 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3953 struct ca0132_spec *spec = codec->spec;
3954 hda_nid_t nid = get_amp_nid(kcontrol);
3955 long *valp = ucontrol->value.integer.value;
3958 idx = nid - TUNING_CTL_START_NID;
3960 if (spec->cur_ctl_vals[idx] == *valp)
3963 spec->cur_ctl_vals[idx] = *valp;
3966 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
3971 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
3972 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
3974 static int add_tuning_control(struct hda_codec *codec,
3975 hda_nid_t pnid, hda_nid_t nid,
3976 const char *name, int dir)
3978 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3979 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3980 struct snd_kcontrol_new knew =
3981 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
3983 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3984 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3989 knew.info = voice_focus_ctl_info;
3990 knew.get = tuning_ctl_get;
3991 knew.put = voice_focus_ctl_put;
3992 knew.tlv.p = voice_focus_db_scale;
3995 knew.info = mic_svm_ctl_info;
3996 knew.get = tuning_ctl_get;
3997 knew.put = mic_svm_ctl_put;
4000 knew.info = equalizer_ctl_info;
4001 knew.get = tuning_ctl_get;
4002 knew.put = equalizer_ctl_put;
4003 knew.tlv.p = eq_db_scale;
4008 knew.private_value =
4009 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
4010 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
4011 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
4014 static int add_tuning_ctls(struct hda_codec *codec)
4019 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
4020 err = add_tuning_control(codec,
4021 ca0132_tuning_ctls[i].parent_nid,
4022 ca0132_tuning_ctls[i].nid,
4023 ca0132_tuning_ctls[i].name,
4024 ca0132_tuning_ctls[i].direct);
4032 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
4034 struct ca0132_spec *spec = codec->spec;
4037 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
4038 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
4039 /* SVM level defaults to 0.74. */
4040 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
4042 /* EQ defaults to 0dB. */
4043 for (i = 2; i < TUNING_CTLS_COUNT; i++)
4044 spec->cur_ctl_vals[i] = 24;
4046 #endif /*ENABLE_TUNING_CONTROLS*/
4049 * Select the active output.
4050 * If autodetect is enabled, output will be selected based on jack detection.
4051 * If jack inserted, headphone will be selected, else built-in speakers
4052 * If autodetect is disabled, output will be selected based on selection.
4054 static int ca0132_select_out(struct hda_codec *codec)
4056 struct ca0132_spec *spec = codec->spec;
4057 unsigned int pin_ctl;
4063 codec_dbg(codec, "ca0132_select_out\n");
4065 snd_hda_power_up_pm(codec);
4067 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4070 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
4073 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
4076 spec->cur_out_type = HEADPHONE_OUT;
4078 spec->cur_out_type = SPEAKER_OUT;
4080 if (spec->cur_out_type == SPEAKER_OUT) {
4081 codec_dbg(codec, "ca0132_select_out speaker\n");
4082 /*speaker out config*/
4084 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4087 /*enable speaker EQ*/
4089 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4094 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4095 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4096 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4097 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4098 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4099 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4100 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4101 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4103 /* disable headphone node */
4104 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4105 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4106 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4108 /* enable speaker node */
4109 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4110 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4111 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4114 codec_dbg(codec, "ca0132_select_out hp\n");
4115 /*headphone out config*/
4117 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4120 /*disable speaker EQ*/
4122 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4127 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4128 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4129 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4130 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4131 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4132 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4133 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4134 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4136 /* disable speaker*/
4137 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4138 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4139 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4141 /* enable headphone*/
4142 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4143 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4144 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4149 snd_hda_power_down_pm(codec);
4151 return err < 0 ? err : 0;
4154 static int ae5_headphone_gain_set(struct hda_codec *codec, long val);
4155 static int zxr_headphone_gain_set(struct hda_codec *codec, long val);
4156 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4158 static void ae5_mmio_select_out(struct hda_codec *codec)
4160 struct ca0132_spec *spec = codec->spec;
4163 for (i = 0; i < AE5_CA0113_OUT_SET_COMMANDS; i++)
4164 ca0113_mmio_command_set(codec,
4165 ae5_ca0113_output_presets[spec->cur_out_type].group[i],
4166 ae5_ca0113_output_presets[spec->cur_out_type].target[i],
4167 ae5_ca0113_output_presets[spec->cur_out_type].vals[i]);
4171 * These are the commands needed to setup output on each of the different card
4174 static void ca0132_alt_select_out_quirk_handler(struct hda_codec *codec)
4176 struct ca0132_spec *spec = codec->spec;
4179 switch (spec->cur_out_type) {
4181 switch (ca0132_quirk(spec)) {
4183 ca0113_mmio_gpio_set(codec, 7, false);
4184 ca0113_mmio_gpio_set(codec, 4, true);
4185 ca0113_mmio_gpio_set(codec, 1, true);
4186 chipio_set_control_param(codec, 0x0d, 0x18);
4189 ca0113_mmio_gpio_set(codec, 2, true);
4190 ca0113_mmio_gpio_set(codec, 3, true);
4191 ca0113_mmio_gpio_set(codec, 5, false);
4192 zxr_headphone_gain_set(codec, 0);
4193 chipio_set_control_param(codec, 0x0d, 0x24);
4196 chipio_set_control_param(codec, 0x0d, 0x24);
4197 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
4200 chipio_set_control_param(codec, 0x0d, 0x24);
4201 ca0113_mmio_gpio_set(codec, 1, true);
4204 ae5_mmio_select_out(codec);
4205 ae5_headphone_gain_set(codec, 2);
4207 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4208 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4209 chipio_set_control_param(codec, 0x0d, 0xa4);
4210 chipio_write(codec, 0x18b03c, 0x00000012);
4217 switch (ca0132_quirk(spec)) {
4219 ca0113_mmio_gpio_set(codec, 7, true);
4220 ca0113_mmio_gpio_set(codec, 4, true);
4221 ca0113_mmio_gpio_set(codec, 1, false);
4222 chipio_set_control_param(codec, 0x0d, 0x12);
4225 ca0113_mmio_gpio_set(codec, 2, false);
4226 ca0113_mmio_gpio_set(codec, 3, false);
4227 ca0113_mmio_gpio_set(codec, 5, true);
4228 zxr_headphone_gain_set(codec, spec->zxr_gain_set);
4229 chipio_set_control_param(codec, 0x0d, 0x21);
4232 chipio_set_control_param(codec, 0x0d, 0x21);
4233 r3di_gpio_out_set(codec, R3DI_HEADPHONE_OUT);
4236 chipio_set_control_param(codec, 0x0d, 0x21);
4237 ca0113_mmio_gpio_set(codec, 0x1, false);
4240 ae5_mmio_select_out(codec);
4241 ae5_headphone_gain_set(codec,
4242 spec->ae5_headphone_gain_val);
4244 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4245 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4246 chipio_set_control_param(codec, 0x0d, 0xa1);
4247 chipio_write(codec, 0x18b03c, 0x00000012);
4254 switch (ca0132_quirk(spec)) {
4256 ca0113_mmio_gpio_set(codec, 7, false);
4257 ca0113_mmio_gpio_set(codec, 4, true);
4258 ca0113_mmio_gpio_set(codec, 1, true);
4259 chipio_set_control_param(codec, 0x0d, 0x18);
4262 ca0113_mmio_gpio_set(codec, 2, true);
4263 ca0113_mmio_gpio_set(codec, 3, true);
4264 ca0113_mmio_gpio_set(codec, 5, false);
4265 zxr_headphone_gain_set(codec, 0);
4266 chipio_set_control_param(codec, 0x0d, 0x24);
4269 chipio_set_control_param(codec, 0x0d, 0x24);
4270 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
4273 ca0113_mmio_gpio_set(codec, 1, true);
4274 chipio_set_control_param(codec, 0x0d, 0x24);
4277 ae5_mmio_select_out(codec);
4278 ae5_headphone_gain_set(codec, 2);
4280 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4281 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4282 chipio_set_control_param(codec, 0x0d, 0xa4);
4283 chipio_write(codec, 0x18b03c, 0x00000012);
4293 * This function behaves similarly to the ca0132_select_out funciton above,
4294 * except with a few differences. It adds the ability to select the current
4295 * output with an enumerated control "output source" if the auto detect
4296 * mute switch is set to off. If the auto detect mute switch is enabled, it
4297 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
4298 * It also adds the ability to auto-detect the front headphone port. The only
4299 * way to select surround is to disable auto detect, and set Surround with the
4300 * enumerated control.
4302 static int ca0132_alt_select_out(struct hda_codec *codec)
4304 struct ca0132_spec *spec = codec->spec;
4305 unsigned int pin_ctl;
4311 /* Default Headphone is rear headphone */
4312 hda_nid_t headphone_nid = spec->out_pins[1];
4314 codec_dbg(codec, "%s\n", __func__);
4316 snd_hda_power_up_pm(codec);
4318 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4321 * If headphone rear or front is plugged in, set to headphone.
4322 * If neither is plugged in, set to rear line out. Only if
4323 * hp/speaker auto detect is enabled.
4326 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
4327 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
4330 spec->cur_out_type = HEADPHONE_OUT;
4332 spec->cur_out_type = SPEAKER_OUT;
4334 spec->cur_out_type = spec->out_enum_val;
4336 /* Begin DSP output switch */
4338 err = dspio_set_uint_param(codec, 0x96, 0x3A, tmp);
4342 ca0132_alt_select_out_quirk_handler(codec);
4344 switch (spec->cur_out_type) {
4346 codec_dbg(codec, "%s speaker\n", __func__);
4348 /* disable headphone node */
4349 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4350 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4351 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4353 /* enable line-out node */
4354 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4355 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4356 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4359 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4360 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4362 /* If PlayEnhancement is enabled, set different source */
4363 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4364 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4366 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4369 codec_dbg(codec, "%s hp\n", __func__);
4371 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4372 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4374 /* disable speaker*/
4375 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4376 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4377 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4380 /* enable headphone, either front or rear */
4382 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4383 headphone_nid = spec->out_pins[2];
4384 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4385 headphone_nid = spec->out_pins[1];
4387 pin_ctl = snd_hda_codec_read(codec, headphone_nid, 0,
4388 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4389 snd_hda_set_pin_ctl(codec, headphone_nid,
4392 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4393 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4395 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4398 codec_dbg(codec, "%s surround\n", __func__);
4400 /* enable line out node */
4401 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4402 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4403 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4405 /* Disable headphone out */
4406 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4407 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4408 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4410 /* Enable EAPD on line out */
4411 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4412 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4413 /* enable center/lfe out node */
4414 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[2], 0,
4415 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4416 snd_hda_set_pin_ctl(codec, spec->out_pins[2],
4418 /* Now set rear surround node as out. */
4419 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[3], 0,
4420 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4421 snd_hda_set_pin_ctl(codec, spec->out_pins[3],
4424 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4428 * Surround always sets it's scp command to req 0x04 to FLOAT_EIGHT.
4429 * With this set though, X_BASS cannot be enabled. So, if we have OutFX
4430 * enabled, we need to make sure X_BASS is off, otherwise everything
4431 * sounds all muffled. Running ca0132_effects_set with X_BASS as the
4432 * effect should sort this out.
4434 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4435 ca0132_effects_set(codec, X_BASS,
4436 spec->effects_switch[X_BASS - EFFECT_START_NID]);
4438 /* run through the output dsp commands for the selected output. */
4439 for (i = 0; i < alt_out_presets[spec->cur_out_type].commands; i++) {
4440 err = dspio_set_uint_param(codec,
4441 alt_out_presets[spec->cur_out_type].mids[i],
4442 alt_out_presets[spec->cur_out_type].reqs[i],
4443 alt_out_presets[spec->cur_out_type].vals[i]);
4450 snd_hda_power_down_pm(codec);
4452 return err < 0 ? err : 0;
4455 static void ca0132_unsol_hp_delayed(struct work_struct *work)
4457 struct ca0132_spec *spec = container_of(
4458 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
4459 struct hda_jack_tbl *jack;
4461 if (ca0132_use_alt_functions(spec))
4462 ca0132_alt_select_out(spec->codec);
4464 ca0132_select_out(spec->codec);
4466 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4468 jack->block_report = 0;
4469 snd_hda_jack_report_sync(spec->codec);
4473 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4474 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4475 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4476 static int stop_mic1(struct hda_codec *codec);
4477 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4478 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4481 * Select the active VIP source
4483 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4485 struct ca0132_spec *spec = codec->spec;
4488 if (spec->dsp_state != DSP_DOWNLOADED)
4491 /* if CrystalVoice if off, vipsource should be 0 */
4492 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4494 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4495 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4496 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4497 if (spec->cur_mic_type == DIGITAL_MIC)
4501 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4503 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4505 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4506 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4507 if (spec->cur_mic_type == DIGITAL_MIC)
4511 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4513 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4515 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4521 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4523 struct ca0132_spec *spec = codec->spec;
4526 if (spec->dsp_state != DSP_DOWNLOADED)
4529 codec_dbg(codec, "%s\n", __func__);
4531 chipio_set_stream_control(codec, 0x03, 0);
4532 chipio_set_stream_control(codec, 0x04, 0);
4534 /* if CrystalVoice is off, vipsource should be 0 */
4535 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4536 (val == 0) || spec->in_enum_val == REAR_LINE_IN) {
4537 codec_dbg(codec, "%s: off.", __func__);
4538 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4541 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4543 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4544 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4545 if (ca0132_quirk(spec) == QUIRK_R3DI)
4546 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4549 if (spec->in_enum_val == REAR_LINE_IN)
4552 if (ca0132_quirk(spec) == QUIRK_SBZ)
4558 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4561 codec_dbg(codec, "%s: on.", __func__);
4562 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4563 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4564 if (ca0132_quirk(spec) == QUIRK_R3DI)
4565 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
4567 if (spec->effects_switch[VOICE_FOCUS - EFFECT_START_NID])
4571 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4574 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4577 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4580 chipio_set_stream_control(codec, 0x03, 1);
4581 chipio_set_stream_control(codec, 0x04, 1);
4587 * Select the active microphone.
4588 * If autodetect is enabled, mic will be selected based on jack detection.
4589 * If jack inserted, ext.mic will be selected, else built-in mic
4590 * If autodetect is disabled, mic will be selected based on selection.
4592 static int ca0132_select_mic(struct hda_codec *codec)
4594 struct ca0132_spec *spec = codec->spec;
4598 codec_dbg(codec, "ca0132_select_mic\n");
4600 snd_hda_power_up_pm(codec);
4602 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
4605 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
4608 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
4611 spec->cur_mic_type = LINE_MIC_IN;
4613 spec->cur_mic_type = DIGITAL_MIC;
4615 if (spec->cur_mic_type == DIGITAL_MIC) {
4616 /* enable digital Mic */
4617 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
4618 ca0132_set_dmic(codec, 1);
4619 ca0132_mic_boost_set(codec, 0);
4620 /* set voice focus */
4621 ca0132_effects_set(codec, VOICE_FOCUS,
4622 spec->effects_switch
4623 [VOICE_FOCUS - EFFECT_START_NID]);
4625 /* disable digital Mic */
4626 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
4627 ca0132_set_dmic(codec, 0);
4628 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
4629 /* disable voice focus */
4630 ca0132_effects_set(codec, VOICE_FOCUS, 0);
4633 snd_hda_power_down_pm(codec);
4639 * Select the active input.
4640 * Mic detection isn't used, because it's kind of pointless on the SBZ.
4641 * The front mic has no jack-detection, so the only way to switch to it
4642 * is to do it manually in alsamixer.
4644 static int ca0132_alt_select_in(struct hda_codec *codec)
4646 struct ca0132_spec *spec = codec->spec;
4649 codec_dbg(codec, "%s\n", __func__);
4651 snd_hda_power_up_pm(codec);
4653 chipio_set_stream_control(codec, 0x03, 0);
4654 chipio_set_stream_control(codec, 0x04, 0);
4656 spec->cur_mic_type = spec->in_enum_val;
4658 switch (spec->cur_mic_type) {
4660 switch (ca0132_quirk(spec)) {
4663 ca0113_mmio_gpio_set(codec, 0, false);
4670 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4674 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x00);
4682 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4683 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4684 if (ca0132_quirk(spec) == QUIRK_R3DI)
4685 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4687 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4689 chipio_set_stream_control(codec, 0x03, 1);
4690 chipio_set_stream_control(codec, 0x04, 1);
4691 switch (ca0132_quirk(spec)) {
4693 chipio_write(codec, 0x18B098, 0x0000000C);
4694 chipio_write(codec, 0x18B09C, 0x0000000C);
4697 chipio_write(codec, 0x18B098, 0x0000000C);
4698 chipio_write(codec, 0x18B09C, 0x000000CC);
4701 chipio_write(codec, 0x18B098, 0x0000000C);
4702 chipio_write(codec, 0x18B09C, 0x0000004C);
4707 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4710 ca0132_mic_boost_set(codec, 0);
4711 switch (ca0132_quirk(spec)) {
4714 ca0113_mmio_gpio_set(codec, 0, false);
4717 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4720 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x00);
4726 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4727 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4728 if (ca0132_quirk(spec) == QUIRK_R3DI)
4729 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4732 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4734 switch (ca0132_quirk(spec)) {
4737 chipio_write(codec, 0x18B098, 0x00000000);
4738 chipio_write(codec, 0x18B09C, 0x00000000);
4743 chipio_set_stream_control(codec, 0x03, 1);
4744 chipio_set_stream_control(codec, 0x04, 1);
4747 switch (ca0132_quirk(spec)) {
4750 ca0113_mmio_gpio_set(codec, 0, true);
4751 ca0113_mmio_gpio_set(codec, 5, false);
4755 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
4759 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x3f);
4767 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4768 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4769 if (ca0132_quirk(spec) == QUIRK_R3DI)
4770 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4772 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4774 chipio_set_stream_control(codec, 0x03, 1);
4775 chipio_set_stream_control(codec, 0x04, 1);
4777 switch (ca0132_quirk(spec)) {
4779 chipio_write(codec, 0x18B098, 0x0000000C);
4780 chipio_write(codec, 0x18B09C, 0x000000CC);
4783 chipio_write(codec, 0x18B098, 0x0000000C);
4784 chipio_write(codec, 0x18B09C, 0x0000004C);
4789 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4792 ca0132_cvoice_switch_set(codec);
4794 snd_hda_power_down_pm(codec);
4799 * Check if VNODE settings take effect immediately.
4801 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
4803 hda_nid_t *shared_nid)
4805 struct ca0132_spec *spec = codec->spec;
4810 nid = spec->shared_out_nid;
4813 nid = spec->shared_mic_nid;
4826 * The following functions are control change helpers.
4827 * They return 0 if no changed. Return 1 if changed.
4829 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
4831 struct ca0132_spec *spec = codec->spec;
4834 /* based on CrystalVoice state to enable VoiceFX. */
4836 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
4837 FLOAT_ONE : FLOAT_ZERO;
4842 dspio_set_uint_param(codec, ca0132_voicefx.mid,
4843 ca0132_voicefx.reqs[0], tmp);
4849 * Set the effects parameters
4851 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
4853 struct ca0132_spec *spec = codec->spec;
4854 unsigned int on, tmp;
4855 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
4857 int idx = nid - EFFECT_START_NID;
4859 if ((idx < 0) || (idx >= num_fx))
4860 return 0; /* no changed */
4862 /* for out effect, qualify with PE */
4863 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
4864 /* if PE if off, turn off out effects. */
4865 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4867 if (spec->cur_out_type == SURROUND_OUT && nid == X_BASS)
4871 /* for in effect, qualify with CrystalVoice */
4872 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
4873 /* if CrystalVoice if off, turn off in effects. */
4874 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
4877 /* Voice Focus applies to 2-ch Mic, Digital Mic */
4878 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
4881 /* If Voice Focus on SBZ, set to two channel. */
4882 if ((nid == VOICE_FOCUS) && ca0132_use_pci_mmio(spec)
4883 && (spec->cur_mic_type != REAR_LINE_IN)) {
4884 if (spec->effects_switch[CRYSTAL_VOICE -
4885 EFFECT_START_NID]) {
4887 if (spec->effects_switch[VOICE_FOCUS -
4888 EFFECT_START_NID]) {
4894 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4898 * For SBZ noise reduction, there's an extra command
4899 * to module ID 0x47. No clue why.
4901 if ((nid == NOISE_REDUCTION) && ca0132_use_pci_mmio(spec)
4902 && (spec->cur_mic_type != REAR_LINE_IN)) {
4903 if (spec->effects_switch[CRYSTAL_VOICE -
4904 EFFECT_START_NID]) {
4905 if (spec->effects_switch[NOISE_REDUCTION -
4913 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
4916 /* If rear line in disable effects. */
4917 if (ca0132_use_alt_functions(spec) &&
4918 spec->in_enum_val == REAR_LINE_IN)
4922 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
4925 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
4926 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
4927 ca0132_effects[idx].reqs[0], on);
4930 return 0; /* no changed */
4936 * Turn on/off Playback Enhancements
4938 static int ca0132_pe_switch_set(struct hda_codec *codec)
4940 struct ca0132_spec *spec = codec->spec;
4944 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
4945 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
4947 if (ca0132_use_alt_functions(spec))
4948 ca0132_alt_select_out(codec);
4950 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
4951 nid = OUT_EFFECT_START_NID;
4952 /* PE affects all out effects */
4953 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
4954 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
4959 /* Check if Mic1 is streaming, if so, stop streaming */
4960 static int stop_mic1(struct hda_codec *codec)
4962 struct ca0132_spec *spec = codec->spec;
4963 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
4964 AC_VERB_GET_CONV, 0);
4966 snd_hda_codec_write(codec, spec->adcs[0], 0,
4967 AC_VERB_SET_CHANNEL_STREAMID,
4972 /* Resume Mic1 streaming if it was stopped. */
4973 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
4975 struct ca0132_spec *spec = codec->spec;
4976 /* Restore the previous stream and channel */
4978 snd_hda_codec_write(codec, spec->adcs[0], 0,
4979 AC_VERB_SET_CHANNEL_STREAMID,
4984 * Turn on/off CrystalVoice
4986 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
4988 struct ca0132_spec *spec = codec->spec;
4991 unsigned int oldval;
4993 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
4994 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
4996 i = IN_EFFECT_START_NID - EFFECT_START_NID;
4997 nid = IN_EFFECT_START_NID;
4998 /* CrystalVoice affects all in effects */
4999 for (; nid < IN_EFFECT_END_NID; nid++, i++)
5000 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5002 /* including VoiceFX */
5003 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
5005 /* set correct vipsource */
5006 oldval = stop_mic1(codec);
5007 if (ca0132_use_alt_functions(spec))
5008 ret |= ca0132_alt_set_vipsource(codec, 1);
5010 ret |= ca0132_set_vipsource(codec, 1);
5011 resume_mic1(codec, oldval);
5015 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
5017 struct ca0132_spec *spec = codec->spec;
5021 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5022 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
5024 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5025 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
5030 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
5032 struct ca0132_spec *spec = codec->spec;
5035 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5036 HDA_INPUT, 0, HDA_AMP_VOLMASK, val);
5040 static int ae5_headphone_gain_set(struct hda_codec *codec, long val)
5044 for (i = 0; i < 4; i++)
5045 ca0113_mmio_command_set(codec, 0x48, 0x11 + i,
5046 ae5_headphone_gain_presets[val].vals[i]);
5051 * gpio pin 1 is a relay that switches on/off, apparently setting the headphone
5052 * amplifier to handle a 600 ohm load.
5054 static int zxr_headphone_gain_set(struct hda_codec *codec, long val)
5056 ca0113_mmio_gpio_set(codec, 1, val);
5061 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
5062 struct snd_ctl_elem_value *ucontrol)
5064 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5065 hda_nid_t nid = get_amp_nid(kcontrol);
5066 hda_nid_t shared_nid = 0;
5069 struct ca0132_spec *spec = codec->spec;
5072 if (nid == VNID_HP_SEL) {
5074 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5076 if (ca0132_use_alt_functions(spec))
5077 ca0132_alt_select_out(codec);
5079 ca0132_select_out(codec);
5084 if (nid == VNID_AMIC1_SEL) {
5086 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5088 ca0132_select_mic(codec);
5092 if (nid == VNID_HP_ASEL) {
5093 if (ca0132_use_alt_functions(spec))
5094 ca0132_alt_select_out(codec);
5096 ca0132_select_out(codec);
5100 if (nid == VNID_AMIC1_ASEL) {
5101 ca0132_select_mic(codec);
5105 /* if effective conditions, then update hw immediately. */
5106 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5108 int dir = get_amp_direction(kcontrol);
5109 int ch = get_amp_channels(kcontrol);
5112 mutex_lock(&codec->control_mutex);
5113 pval = kcontrol->private_value;
5114 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5116 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
5117 kcontrol->private_value = pval;
5118 mutex_unlock(&codec->control_mutex);
5123 /* End of control change helpers. */
5125 * Below I've added controls to mess with the effect levels, I've only enabled
5126 * them on the Sound Blaster Z, but they would probably also work on the
5127 * Chromebook. I figured they were probably tuned specifically for it, and left
5131 /* Sets DSP effect level from the sliders above the controls */
5132 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
5133 const unsigned int *lookup, int idx)
5138 * For X_BASS, req 2 is actually crossover freq instead of
5146 snd_hda_power_up(codec);
5147 if (nid == XBASS_XOVER) {
5148 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5149 if (ca0132_effects[i].nid == X_BASS)
5152 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5153 ca0132_effects[i].reqs[1],
5154 &(lookup[idx - 1]), sizeof(unsigned int));
5156 /* Find the actual effect structure */
5157 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5158 if (nid == ca0132_effects[i].nid)
5161 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5162 ca0132_effects[i].reqs[y],
5163 &(lookup[idx]), sizeof(unsigned int));
5166 snd_hda_power_down(codec);
5171 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol *kcontrol,
5172 struct snd_ctl_elem_value *ucontrol)
5174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5175 struct ca0132_spec *spec = codec->spec;
5176 long *valp = ucontrol->value.integer.value;
5178 *valp = spec->xbass_xover_freq;
5182 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol *kcontrol,
5183 struct snd_ctl_elem_value *ucontrol)
5185 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5186 struct ca0132_spec *spec = codec->spec;
5187 hda_nid_t nid = get_amp_nid(kcontrol);
5188 long *valp = ucontrol->value.integer.value;
5189 int idx = nid - OUT_EFFECT_START_NID;
5191 *valp = spec->fx_ctl_val[idx];
5196 * The X-bass crossover starts at 10hz, so the min is 1. The
5197 * frequency is set in multiples of 10.
5199 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol *kcontrol,
5200 struct snd_ctl_elem_info *uinfo)
5202 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5204 uinfo->value.integer.min = 1;
5205 uinfo->value.integer.max = 100;
5206 uinfo->value.integer.step = 1;
5211 static int ca0132_alt_effect_slider_info(struct snd_kcontrol *kcontrol,
5212 struct snd_ctl_elem_info *uinfo)
5214 int chs = get_amp_channels(kcontrol);
5216 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5217 uinfo->count = chs == 3 ? 2 : 1;
5218 uinfo->value.integer.min = 0;
5219 uinfo->value.integer.max = 100;
5220 uinfo->value.integer.step = 1;
5225 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol *kcontrol,
5226 struct snd_ctl_elem_value *ucontrol)
5228 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5229 struct ca0132_spec *spec = codec->spec;
5230 hda_nid_t nid = get_amp_nid(kcontrol);
5231 long *valp = ucontrol->value.integer.value;
5235 if (spec->xbass_xover_freq == *valp)
5238 spec->xbass_xover_freq = *valp;
5241 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
5246 static int ca0132_alt_effect_slider_put(struct snd_kcontrol *kcontrol,
5247 struct snd_ctl_elem_value *ucontrol)
5249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5250 struct ca0132_spec *spec = codec->spec;
5251 hda_nid_t nid = get_amp_nid(kcontrol);
5252 long *valp = ucontrol->value.integer.value;
5255 idx = nid - EFFECT_START_NID;
5257 if (spec->fx_ctl_val[idx] == *valp)
5260 spec->fx_ctl_val[idx] = *valp;
5263 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
5270 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
5271 * only has off or full 30 dB, and didn't like making a volume slider that has
5272 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
5274 #define MIC_BOOST_NUM_OF_STEPS 4
5275 #define MIC_BOOST_ENUM_MAX_STRLEN 10
5277 static int ca0132_alt_mic_boost_info(struct snd_kcontrol *kcontrol,
5278 struct snd_ctl_elem_info *uinfo)
5281 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5283 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5285 uinfo->value.enumerated.items = MIC_BOOST_NUM_OF_STEPS;
5286 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS)
5287 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1;
5288 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx);
5289 strcpy(uinfo->value.enumerated.name, namestr);
5293 static int ca0132_alt_mic_boost_get(struct snd_kcontrol *kcontrol,
5294 struct snd_ctl_elem_value *ucontrol)
5296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5297 struct ca0132_spec *spec = codec->spec;
5299 ucontrol->value.enumerated.item[0] = spec->mic_boost_enum_val;
5303 static int ca0132_alt_mic_boost_put(struct snd_kcontrol *kcontrol,
5304 struct snd_ctl_elem_value *ucontrol)
5306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5307 struct ca0132_spec *spec = codec->spec;
5308 int sel = ucontrol->value.enumerated.item[0];
5309 unsigned int items = MIC_BOOST_NUM_OF_STEPS;
5314 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
5317 spec->mic_boost_enum_val = sel;
5319 if (spec->in_enum_val != REAR_LINE_IN)
5320 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5326 * Sound BlasterX AE-5 Headphone Gain Controls.
5328 #define AE5_HEADPHONE_GAIN_MAX 3
5329 static int ae5_headphone_gain_info(struct snd_kcontrol *kcontrol,
5330 struct snd_ctl_elem_info *uinfo)
5332 char *sfx = " Ohms)";
5333 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5335 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5337 uinfo->value.enumerated.items = AE5_HEADPHONE_GAIN_MAX;
5338 if (uinfo->value.enumerated.item >= AE5_HEADPHONE_GAIN_MAX)
5339 uinfo->value.enumerated.item = AE5_HEADPHONE_GAIN_MAX - 1;
5340 sprintf(namestr, "%s %s",
5341 ae5_headphone_gain_presets[uinfo->value.enumerated.item].name,
5343 strcpy(uinfo->value.enumerated.name, namestr);
5347 static int ae5_headphone_gain_get(struct snd_kcontrol *kcontrol,
5348 struct snd_ctl_elem_value *ucontrol)
5350 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5351 struct ca0132_spec *spec = codec->spec;
5353 ucontrol->value.enumerated.item[0] = spec->ae5_headphone_gain_val;
5357 static int ae5_headphone_gain_put(struct snd_kcontrol *kcontrol,
5358 struct snd_ctl_elem_value *ucontrol)
5360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5361 struct ca0132_spec *spec = codec->spec;
5362 int sel = ucontrol->value.enumerated.item[0];
5363 unsigned int items = AE5_HEADPHONE_GAIN_MAX;
5368 codec_dbg(codec, "ae5_headphone_gain: boost=%d\n",
5371 spec->ae5_headphone_gain_val = sel;
5373 if (spec->out_enum_val == HEADPHONE_OUT)
5374 ae5_headphone_gain_set(codec, spec->ae5_headphone_gain_val);
5380 * Sound BlasterX AE-5 sound filter enumerated control.
5382 #define AE5_SOUND_FILTER_MAX 3
5384 static int ae5_sound_filter_info(struct snd_kcontrol *kcontrol,
5385 struct snd_ctl_elem_info *uinfo)
5387 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5389 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5391 uinfo->value.enumerated.items = AE5_SOUND_FILTER_MAX;
5392 if (uinfo->value.enumerated.item >= AE5_SOUND_FILTER_MAX)
5393 uinfo->value.enumerated.item = AE5_SOUND_FILTER_MAX - 1;
5394 sprintf(namestr, "%s",
5395 ae5_filter_presets[uinfo->value.enumerated.item].name);
5396 strcpy(uinfo->value.enumerated.name, namestr);
5400 static int ae5_sound_filter_get(struct snd_kcontrol *kcontrol,
5401 struct snd_ctl_elem_value *ucontrol)
5403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5404 struct ca0132_spec *spec = codec->spec;
5406 ucontrol->value.enumerated.item[0] = spec->ae5_filter_val;
5410 static int ae5_sound_filter_put(struct snd_kcontrol *kcontrol,
5411 struct snd_ctl_elem_value *ucontrol)
5413 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5414 struct ca0132_spec *spec = codec->spec;
5415 int sel = ucontrol->value.enumerated.item[0];
5416 unsigned int items = AE5_SOUND_FILTER_MAX;
5421 codec_dbg(codec, "ae5_sound_filter: %s\n",
5422 ae5_filter_presets[sel].name);
5424 spec->ae5_filter_val = sel;
5426 ca0113_mmio_command_set_type2(codec, 0x48, 0x07,
5427 ae5_filter_presets[sel].val);
5433 * Input Select Control for alternative ca0132 codecs. This exists because
5434 * front microphone has no auto-detect, and we need a way to set the rear
5437 static int ca0132_alt_input_source_info(struct snd_kcontrol *kcontrol,
5438 struct snd_ctl_elem_info *uinfo)
5440 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5442 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS;
5443 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS)
5444 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1;
5445 strcpy(uinfo->value.enumerated.name,
5446 in_src_str[uinfo->value.enumerated.item]);
5450 static int ca0132_alt_input_source_get(struct snd_kcontrol *kcontrol,
5451 struct snd_ctl_elem_value *ucontrol)
5453 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5454 struct ca0132_spec *spec = codec->spec;
5456 ucontrol->value.enumerated.item[0] = spec->in_enum_val;
5460 static int ca0132_alt_input_source_put(struct snd_kcontrol *kcontrol,
5461 struct snd_ctl_elem_value *ucontrol)
5463 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5464 struct ca0132_spec *spec = codec->spec;
5465 int sel = ucontrol->value.enumerated.item[0];
5466 unsigned int items = IN_SRC_NUM_OF_INPUTS;
5471 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5472 sel, in_src_str[sel]);
5474 spec->in_enum_val = sel;
5476 ca0132_alt_select_in(codec);
5481 /* Sound Blaster Z Output Select Control */
5482 static int ca0132_alt_output_select_get_info(struct snd_kcontrol *kcontrol,
5483 struct snd_ctl_elem_info *uinfo)
5485 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5487 uinfo->value.enumerated.items = NUM_OF_OUTPUTS;
5488 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS)
5489 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1;
5490 strcpy(uinfo->value.enumerated.name,
5491 alt_out_presets[uinfo->value.enumerated.item].name);
5495 static int ca0132_alt_output_select_get(struct snd_kcontrol *kcontrol,
5496 struct snd_ctl_elem_value *ucontrol)
5498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5499 struct ca0132_spec *spec = codec->spec;
5501 ucontrol->value.enumerated.item[0] = spec->out_enum_val;
5505 static int ca0132_alt_output_select_put(struct snd_kcontrol *kcontrol,
5506 struct snd_ctl_elem_value *ucontrol)
5508 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5509 struct ca0132_spec *spec = codec->spec;
5510 int sel = ucontrol->value.enumerated.item[0];
5511 unsigned int items = NUM_OF_OUTPUTS;
5512 unsigned int auto_jack;
5517 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
5518 sel, alt_out_presets[sel].name);
5520 spec->out_enum_val = sel;
5522 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5525 ca0132_alt_select_out(codec);
5531 * Smart Volume output setting control. Three different settings, Normal,
5532 * which takes the value from the smart volume slider. The two others, loud
5533 * and night, disregard the slider value and have uneditable values.
5535 #define NUM_OF_SVM_SETTINGS 3
5536 static const char *const out_svm_set_enum_str[3] = {"Normal", "Loud", "Night" };
5538 static int ca0132_alt_svm_setting_info(struct snd_kcontrol *kcontrol,
5539 struct snd_ctl_elem_info *uinfo)
5541 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5543 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS;
5544 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS)
5545 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1;
5546 strcpy(uinfo->value.enumerated.name,
5547 out_svm_set_enum_str[uinfo->value.enumerated.item]);
5551 static int ca0132_alt_svm_setting_get(struct snd_kcontrol *kcontrol,
5552 struct snd_ctl_elem_value *ucontrol)
5554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5555 struct ca0132_spec *spec = codec->spec;
5557 ucontrol->value.enumerated.item[0] = spec->smart_volume_setting;
5561 static int ca0132_alt_svm_setting_put(struct snd_kcontrol *kcontrol,
5562 struct snd_ctl_elem_value *ucontrol)
5564 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5565 struct ca0132_spec *spec = codec->spec;
5566 int sel = ucontrol->value.enumerated.item[0];
5567 unsigned int items = NUM_OF_SVM_SETTINGS;
5568 unsigned int idx = SMART_VOLUME - EFFECT_START_NID;
5574 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
5575 sel, out_svm_set_enum_str[sel]);
5577 spec->smart_volume_setting = sel;
5593 /* Req 2 is the Smart Volume Setting req. */
5594 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5595 ca0132_effects[idx].reqs[2], tmp);
5599 /* Sound Blaster Z EQ preset controls */
5600 static int ca0132_alt_eq_preset_info(struct snd_kcontrol *kcontrol,
5601 struct snd_ctl_elem_info *uinfo)
5603 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5605 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5607 uinfo->value.enumerated.items = items;
5608 if (uinfo->value.enumerated.item >= items)
5609 uinfo->value.enumerated.item = items - 1;
5610 strcpy(uinfo->value.enumerated.name,
5611 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name);
5615 static int ca0132_alt_eq_preset_get(struct snd_kcontrol *kcontrol,
5616 struct snd_ctl_elem_value *ucontrol)
5618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5619 struct ca0132_spec *spec = codec->spec;
5621 ucontrol->value.enumerated.item[0] = spec->eq_preset_val;
5625 static int ca0132_alt_eq_preset_put(struct snd_kcontrol *kcontrol,
5626 struct snd_ctl_elem_value *ucontrol)
5628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5629 struct ca0132_spec *spec = codec->spec;
5631 int sel = ucontrol->value.enumerated.item[0];
5632 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5637 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
5638 ca0132_alt_eq_presets[sel].name);
5641 * Default needs to qualify with CrystalVoice state.
5643 for (i = 0; i < EQ_PRESET_MAX_PARAM_COUNT; i++) {
5644 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
5645 ca0132_alt_eq_enum.reqs[i],
5646 ca0132_alt_eq_presets[sel].vals[i]);
5652 spec->eq_preset_val = sel;
5657 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
5658 struct snd_ctl_elem_info *uinfo)
5660 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
5662 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5664 uinfo->value.enumerated.items = items;
5665 if (uinfo->value.enumerated.item >= items)
5666 uinfo->value.enumerated.item = items - 1;
5667 strcpy(uinfo->value.enumerated.name,
5668 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
5672 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
5673 struct snd_ctl_elem_value *ucontrol)
5675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5676 struct ca0132_spec *spec = codec->spec;
5678 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
5682 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
5683 struct snd_ctl_elem_value *ucontrol)
5685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5686 struct ca0132_spec *spec = codec->spec;
5688 int sel = ucontrol->value.enumerated.item[0];
5690 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
5693 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
5694 sel, ca0132_voicefx_presets[sel].name);
5698 * Default needs to qualify with CrystalVoice state.
5700 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
5701 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
5702 ca0132_voicefx.reqs[i],
5703 ca0132_voicefx_presets[sel].vals[i]);
5709 spec->voicefx_val = sel;
5710 /* enable voice fx */
5711 ca0132_voicefx_set(codec, (sel ? 1 : 0));
5717 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
5718 struct snd_ctl_elem_value *ucontrol)
5720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5721 struct ca0132_spec *spec = codec->spec;
5722 hda_nid_t nid = get_amp_nid(kcontrol);
5723 int ch = get_amp_channels(kcontrol);
5724 long *valp = ucontrol->value.integer.value;
5727 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5729 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
5733 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
5739 /* effects, include PE and CrystalVoice */
5740 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
5741 *valp = spec->effects_switch[nid - EFFECT_START_NID];
5746 if (nid == spec->input_pins[0]) {
5747 *valp = spec->cur_mic_boost;
5754 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
5755 struct snd_ctl_elem_value *ucontrol)
5757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5758 struct ca0132_spec *spec = codec->spec;
5759 hda_nid_t nid = get_amp_nid(kcontrol);
5760 int ch = get_amp_channels(kcontrol);
5761 long *valp = ucontrol->value.integer.value;
5764 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
5767 snd_hda_power_up(codec);
5769 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5771 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
5775 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
5778 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
5783 if (nid == PLAY_ENHANCEMENT) {
5784 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5785 changed = ca0132_pe_switch_set(codec);
5790 if (nid == CRYSTAL_VOICE) {
5791 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5792 changed = ca0132_cvoice_switch_set(codec);
5796 /* out and in effects */
5797 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
5798 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
5799 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5800 changed = ca0132_effects_set(codec, nid, *valp);
5805 if (nid == spec->input_pins[0]) {
5806 spec->cur_mic_boost = *valp;
5807 if (ca0132_use_alt_functions(spec)) {
5808 if (spec->in_enum_val != REAR_LINE_IN)
5809 changed = ca0132_mic_boost_set(codec, *valp);
5811 /* Mic boost does not apply to Digital Mic */
5812 if (spec->cur_mic_type != DIGITAL_MIC)
5813 changed = ca0132_mic_boost_set(codec, *valp);
5819 if (nid == ZXR_HEADPHONE_GAIN) {
5820 spec->zxr_gain_set = *valp;
5821 if (spec->cur_out_type == HEADPHONE_OUT)
5822 changed = zxr_headphone_gain_set(codec, *valp);
5830 snd_hda_power_down(codec);
5838 * Sets the internal DSP decibel level to match the DAC for output, and the
5839 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
5840 * all alternative codecs set DSP playback volume.
5842 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
5844 struct ca0132_spec *spec = codec->spec;
5845 unsigned int dsp_dir;
5846 unsigned int lookup_val;
5848 if (nid == VNID_SPK)
5849 dsp_dir = DSP_VOL_OUT;
5851 dsp_dir = DSP_VOL_IN;
5853 lookup_val = spec->vnode_lvol[nid - VNODE_START_NID];
5855 dspio_set_uint_param(codec,
5856 ca0132_alt_vol_ctls[dsp_dir].mid,
5857 ca0132_alt_vol_ctls[dsp_dir].reqs[0],
5858 float_vol_db_lookup[lookup_val]);
5860 lookup_val = spec->vnode_rvol[nid - VNODE_START_NID];
5862 dspio_set_uint_param(codec,
5863 ca0132_alt_vol_ctls[dsp_dir].mid,
5864 ca0132_alt_vol_ctls[dsp_dir].reqs[1],
5865 float_vol_db_lookup[lookup_val]);
5867 dspio_set_uint_param(codec,
5868 ca0132_alt_vol_ctls[dsp_dir].mid,
5869 ca0132_alt_vol_ctls[dsp_dir].reqs[2], FLOAT_ZERO);
5872 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
5873 struct snd_ctl_elem_info *uinfo)
5875 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5876 struct ca0132_spec *spec = codec->spec;
5877 hda_nid_t nid = get_amp_nid(kcontrol);
5878 int ch = get_amp_channels(kcontrol);
5879 int dir = get_amp_direction(kcontrol);
5885 /* follow shared_out info */
5886 nid = spec->shared_out_nid;
5887 mutex_lock(&codec->control_mutex);
5888 pval = kcontrol->private_value;
5889 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5890 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5891 kcontrol->private_value = pval;
5892 mutex_unlock(&codec->control_mutex);
5895 /* follow shared_mic info */
5896 nid = spec->shared_mic_nid;
5897 mutex_lock(&codec->control_mutex);
5898 pval = kcontrol->private_value;
5899 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5900 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5901 kcontrol->private_value = pval;
5902 mutex_unlock(&codec->control_mutex);
5905 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5910 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
5911 struct snd_ctl_elem_value *ucontrol)
5913 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5914 struct ca0132_spec *spec = codec->spec;
5915 hda_nid_t nid = get_amp_nid(kcontrol);
5916 int ch = get_amp_channels(kcontrol);
5917 long *valp = ucontrol->value.integer.value;
5919 /* store the left and right volume */
5921 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
5925 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
5931 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
5932 struct snd_ctl_elem_value *ucontrol)
5934 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5935 struct ca0132_spec *spec = codec->spec;
5936 hda_nid_t nid = get_amp_nid(kcontrol);
5937 int ch = get_amp_channels(kcontrol);
5938 long *valp = ucontrol->value.integer.value;
5939 hda_nid_t shared_nid = 0;
5943 /* store the left and right volume */
5945 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
5949 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
5953 /* if effective conditions, then update hw immediately. */
5954 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5956 int dir = get_amp_direction(kcontrol);
5959 snd_hda_power_up(codec);
5960 mutex_lock(&codec->control_mutex);
5961 pval = kcontrol->private_value;
5962 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5964 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
5965 kcontrol->private_value = pval;
5966 mutex_unlock(&codec->control_mutex);
5967 snd_hda_power_down(codec);
5974 * This function is the same as the one above, because using an if statement
5975 * inside of the above volume control for the DSP volume would cause too much
5976 * lag. This is a lot more smooth.
5978 static int ca0132_alt_volume_put(struct snd_kcontrol *kcontrol,
5979 struct snd_ctl_elem_value *ucontrol)
5981 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5982 struct ca0132_spec *spec = codec->spec;
5983 hda_nid_t nid = get_amp_nid(kcontrol);
5984 int ch = get_amp_channels(kcontrol);
5985 long *valp = ucontrol->value.integer.value;
5998 /* store the left and right volume */
6000 spec->vnode_lvol[vnid - VNODE_START_NID] = *valp;
6004 spec->vnode_rvol[vnid - VNODE_START_NID] = *valp;
6008 snd_hda_power_up(codec);
6009 ca0132_alt_dsp_volume_put(codec, vnid);
6010 mutex_lock(&codec->control_mutex);
6011 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6012 mutex_unlock(&codec->control_mutex);
6013 snd_hda_power_down(codec);
6018 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
6019 unsigned int size, unsigned int __user *tlv)
6021 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6022 struct ca0132_spec *spec = codec->spec;
6023 hda_nid_t nid = get_amp_nid(kcontrol);
6024 int ch = get_amp_channels(kcontrol);
6025 int dir = get_amp_direction(kcontrol);
6031 /* follow shared_out tlv */
6032 nid = spec->shared_out_nid;
6033 mutex_lock(&codec->control_mutex);
6034 pval = kcontrol->private_value;
6035 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6036 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6037 kcontrol->private_value = pval;
6038 mutex_unlock(&codec->control_mutex);
6041 /* follow shared_mic tlv */
6042 nid = spec->shared_mic_nid;
6043 mutex_lock(&codec->control_mutex);
6044 pval = kcontrol->private_value;
6045 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6046 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6047 kcontrol->private_value = pval;
6048 mutex_unlock(&codec->control_mutex);
6051 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6056 /* Add volume slider control for effect level */
6057 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
6058 const char *pfx, int dir)
6060 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6061 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6062 struct snd_kcontrol_new knew =
6063 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
6065 sprintf(namestr, "FX: %s %s Volume", pfx, dirstr[dir]);
6071 knew.info = ca0132_alt_xbass_xover_slider_info;
6072 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6073 knew.put = ca0132_alt_xbass_xover_slider_put;
6076 knew.info = ca0132_alt_effect_slider_info;
6077 knew.get = ca0132_alt_slider_ctl_get;
6078 knew.put = ca0132_alt_effect_slider_put;
6079 knew.private_value =
6080 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
6084 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6088 * Added FX: prefix for the alternative codecs, because otherwise the surround
6089 * effect would conflict with the Surround sound volume control. Also seems more
6090 * clear as to what the switches do. Left alone for others.
6092 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
6093 const char *pfx, int dir)
6095 struct ca0132_spec *spec = codec->spec;
6096 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6097 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6098 struct snd_kcontrol_new knew =
6099 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
6100 /* If using alt_controls, add FX: prefix. But, don't add FX:
6101 * prefix to OutFX or InFX enable controls.
6103 if (ca0132_use_alt_controls(spec) && (nid <= IN_EFFECT_END_NID))
6104 sprintf(namestr, "FX: %s %s Switch", pfx, dirstr[dir]);
6106 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
6108 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6111 static int add_voicefx(struct hda_codec *codec)
6113 struct snd_kcontrol_new knew =
6114 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
6115 VOICEFX, 1, 0, HDA_INPUT);
6116 knew.info = ca0132_voicefx_info;
6117 knew.get = ca0132_voicefx_get;
6118 knew.put = ca0132_voicefx_put;
6119 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
6122 /* Create the EQ Preset control */
6123 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
6125 struct snd_kcontrol_new knew =
6126 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum.name,
6127 EQ_PRESET_ENUM, 1, 0, HDA_OUTPUT);
6128 knew.info = ca0132_alt_eq_preset_info;
6129 knew.get = ca0132_alt_eq_preset_get;
6130 knew.put = ca0132_alt_eq_preset_put;
6131 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
6132 snd_ctl_new1(&knew, codec));
6136 * Add enumerated control for the three different settings of the smart volume
6137 * output effect. Normal just uses the slider value, and loud and night are
6138 * their own things that ignore that value.
6140 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
6142 struct snd_kcontrol_new knew =
6143 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
6144 SMART_VOLUME_ENUM, 1, 0, HDA_OUTPUT);
6145 knew.info = ca0132_alt_svm_setting_info;
6146 knew.get = ca0132_alt_svm_setting_get;
6147 knew.put = ca0132_alt_svm_setting_put;
6148 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
6149 snd_ctl_new1(&knew, codec));
6154 * Create an Output Select enumerated control for codecs with surround
6157 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
6159 struct snd_kcontrol_new knew =
6160 HDA_CODEC_MUTE_MONO("Output Select",
6161 OUTPUT_SOURCE_ENUM, 1, 0, HDA_OUTPUT);
6162 knew.info = ca0132_alt_output_select_get_info;
6163 knew.get = ca0132_alt_output_select_get;
6164 knew.put = ca0132_alt_output_select_put;
6165 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
6166 snd_ctl_new1(&knew, codec));
6170 * Create an Input Source enumerated control for the alternate ca0132 codecs
6171 * because the front microphone has no auto-detect, and Line-in has to be set
6174 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
6176 struct snd_kcontrol_new knew =
6177 HDA_CODEC_MUTE_MONO("Input Source",
6178 INPUT_SOURCE_ENUM, 1, 0, HDA_INPUT);
6179 knew.info = ca0132_alt_input_source_info;
6180 knew.get = ca0132_alt_input_source_get;
6181 knew.put = ca0132_alt_input_source_put;
6182 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
6183 snd_ctl_new1(&knew, codec));
6187 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
6188 * more control than the original mic boost, which is either full 30dB or off.
6190 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
6192 struct snd_kcontrol_new knew =
6193 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
6194 MIC_BOOST_ENUM, 1, 0, HDA_INPUT);
6195 knew.info = ca0132_alt_mic_boost_info;
6196 knew.get = ca0132_alt_mic_boost_get;
6197 knew.put = ca0132_alt_mic_boost_put;
6198 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
6199 snd_ctl_new1(&knew, codec));
6204 * Add headphone gain enumerated control for the AE-5. This switches between
6205 * three modes, low, medium, and high. When non-headphone outputs are selected,
6206 * it is automatically set to high. This is the same behavior as Windows.
6208 static int ae5_add_headphone_gain_enum(struct hda_codec *codec)
6210 struct snd_kcontrol_new knew =
6211 HDA_CODEC_MUTE_MONO("AE-5: Headphone Gain",
6212 AE5_HEADPHONE_GAIN_ENUM, 1, 0, HDA_OUTPUT);
6213 knew.info = ae5_headphone_gain_info;
6214 knew.get = ae5_headphone_gain_get;
6215 knew.put = ae5_headphone_gain_put;
6216 return snd_hda_ctl_add(codec, AE5_HEADPHONE_GAIN_ENUM,
6217 snd_ctl_new1(&knew, codec));
6221 * Add sound filter enumerated control for the AE-5. This adds three different
6222 * settings: Slow Roll Off, Minimum Phase, and Fast Roll Off. From what I've
6223 * read into it, it changes the DAC's interpolation filter.
6225 static int ae5_add_sound_filter_enum(struct hda_codec *codec)
6227 struct snd_kcontrol_new knew =
6228 HDA_CODEC_MUTE_MONO("AE-5: Sound Filter",
6229 AE5_SOUND_FILTER_ENUM, 1, 0, HDA_OUTPUT);
6230 knew.info = ae5_sound_filter_info;
6231 knew.get = ae5_sound_filter_get;
6232 knew.put = ae5_sound_filter_put;
6233 return snd_hda_ctl_add(codec, AE5_SOUND_FILTER_ENUM,
6234 snd_ctl_new1(&knew, codec));
6237 static int zxr_add_headphone_gain_switch(struct hda_codec *codec)
6239 struct snd_kcontrol_new knew =
6240 CA0132_CODEC_MUTE_MONO("ZxR: 600 Ohm Gain",
6241 ZXR_HEADPHONE_GAIN, 1, HDA_OUTPUT);
6243 return snd_hda_ctl_add(codec, ZXR_HEADPHONE_GAIN,
6244 snd_ctl_new1(&knew, codec));
6248 * Need to create slave controls for the alternate codecs that have surround
6251 static const char * const ca0132_alt_slave_pfxs[] = {
6252 "Front", "Surround", "Center", "LFE", NULL,
6256 * Also need special channel map, because the default one is incorrect.
6257 * I think this has to do with the pin for rear surround being 0x11,
6258 * and the center/lfe being 0x10. Usually the pin order is the opposite.
6260 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps[] = {
6262 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
6264 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6265 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6267 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6268 SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE,
6269 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6273 /* Add the correct chmap for streams with 6 channels. */
6274 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
6277 struct hda_pcm *pcm;
6279 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
6280 struct hda_pcm_stream *hinfo =
6281 &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
6282 struct snd_pcm_chmap *chmap;
6283 const struct snd_pcm_chmap_elem *elem;
6285 elem = ca0132_alt_chmaps;
6286 if (hinfo->channels_max == 6) {
6287 err = snd_pcm_add_chmap_ctls(pcm->pcm,
6288 SNDRV_PCM_STREAM_PLAYBACK,
6289 elem, hinfo->channels_max, 0, &chmap);
6291 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
6297 * When changing Node IDs for Mixer Controls below, make sure to update
6298 * Node IDs in ca0132_config() as well.
6300 static const struct snd_kcontrol_new ca0132_mixer[] = {
6301 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
6302 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
6303 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6304 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6305 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
6306 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
6307 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6308 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6309 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
6310 0x12, 1, HDA_INPUT),
6311 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
6312 VNID_HP_SEL, 1, HDA_OUTPUT),
6313 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
6314 VNID_AMIC1_SEL, 1, HDA_INPUT),
6315 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6316 VNID_HP_ASEL, 1, HDA_OUTPUT),
6317 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
6318 VNID_AMIC1_ASEL, 1, HDA_INPUT),
6323 * Desktop specific control mixer. Removes auto-detect for mic, and adds
6324 * surround controls. Also sets both the Front Playback and Capture Volume
6325 * controls to alt so they set the DSP's decibel level.
6327 static const struct snd_kcontrol_new desktop_mixer[] = {
6328 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6329 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6330 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6331 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6332 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6333 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6334 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6335 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6336 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT),
6337 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6338 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6339 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6340 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6341 VNID_HP_ASEL, 1, HDA_OUTPUT),
6346 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
6347 * because it doesn't set decibel levels for the DSP for capture.
6349 static const struct snd_kcontrol_new r3di_mixer[] = {
6350 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6351 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6352 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6353 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6354 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6355 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6356 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6357 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6358 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6359 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6360 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6361 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6362 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6363 VNID_HP_ASEL, 1, HDA_OUTPUT),
6367 static int ca0132_build_controls(struct hda_codec *codec)
6369 struct ca0132_spec *spec = codec->spec;
6370 int i, num_fx, num_sliders;
6373 /* Add Mixer controls */
6374 for (i = 0; i < spec->num_mixers; i++) {
6375 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
6379 /* Setup vmaster with surround slaves for desktop ca0132 devices */
6380 if (ca0132_use_alt_functions(spec)) {
6381 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
6383 snd_hda_add_vmaster(codec, "Master Playback Volume",
6384 spec->tlv, ca0132_alt_slave_pfxs,
6386 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
6387 NULL, ca0132_alt_slave_pfxs,
6389 true, &spec->vmaster_mute.sw_kctl);
6394 /* Add in and out effects controls.
6395 * VoiceFX, PE and CrystalVoice are added separately.
6397 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
6398 for (i = 0; i < num_fx; i++) {
6399 /* Desktop cards break if Echo Cancellation is used. */
6400 if (ca0132_use_pci_mmio(spec)) {
6401 if (i == (ECHO_CANCELLATION - IN_EFFECT_START_NID +
6406 err = add_fx_switch(codec, ca0132_effects[i].nid,
6407 ca0132_effects[i].name,
6408 ca0132_effects[i].direct);
6413 * If codec has use_alt_controls set to true, add effect level sliders,
6414 * EQ presets, and Smart Volume presets. Also, change names to add FX
6415 * prefix, and change PlayEnhancement and CrystalVoice to match.
6417 if (ca0132_use_alt_controls(spec)) {
6418 err = ca0132_alt_add_svm_enum(codec);
6422 err = add_ca0132_alt_eq_presets(codec);
6426 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6431 err = add_fx_switch(codec, CRYSTAL_VOICE,
6436 num_sliders = OUT_EFFECTS_COUNT - 1;
6437 for (i = 0; i < num_sliders; i++) {
6438 err = ca0132_alt_add_effect_slider(codec,
6439 ca0132_effects[i].nid,
6440 ca0132_effects[i].name,
6441 ca0132_effects[i].direct);
6446 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
6447 "X-Bass Crossover", EFX_DIR_OUT);
6452 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6453 "PlayEnhancement", 0);
6457 err = add_fx_switch(codec, CRYSTAL_VOICE,
6462 err = add_voicefx(codec);
6467 * If the codec uses alt_functions, you need the enumerated controls
6468 * to select the new outputs and inputs, plus add the new mic boost
6471 if (ca0132_use_alt_functions(spec)) {
6472 err = ca0132_alt_add_output_enum(codec);
6475 err = ca0132_alt_add_mic_boost_enum(codec);
6479 * ZxR only has microphone input, there is no front panel
6480 * header on the card, and aux-in is handled by the DBPro board.
6482 if (ca0132_quirk(spec) != QUIRK_ZXR) {
6483 err = ca0132_alt_add_input_enum(codec);
6489 if (ca0132_quirk(spec) == QUIRK_AE5) {
6490 err = ae5_add_headphone_gain_enum(codec);
6493 err = ae5_add_sound_filter_enum(codec);
6498 if (ca0132_quirk(spec) == QUIRK_ZXR) {
6499 err = zxr_add_headphone_gain_switch(codec);
6503 #ifdef ENABLE_TUNING_CONTROLS
6504 add_tuning_ctls(codec);
6507 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
6511 if (spec->dig_out) {
6512 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
6516 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
6519 /* spec->multiout.share_spdif = 1; */
6523 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
6528 if (ca0132_use_alt_functions(spec))
6529 ca0132_alt_add_chmap_ctls(codec);
6534 static int dbpro_build_controls(struct hda_codec *codec)
6536 struct ca0132_spec *spec = codec->spec;
6539 if (spec->dig_out) {
6540 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
6547 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
6558 static const struct hda_pcm_stream ca0132_pcm_analog_playback = {
6563 .prepare = ca0132_playback_pcm_prepare,
6564 .cleanup = ca0132_playback_pcm_cleanup,
6565 .get_delay = ca0132_playback_pcm_delay,
6569 static const struct hda_pcm_stream ca0132_pcm_analog_capture = {
6574 .prepare = ca0132_capture_pcm_prepare,
6575 .cleanup = ca0132_capture_pcm_cleanup,
6576 .get_delay = ca0132_capture_pcm_delay,
6580 static const struct hda_pcm_stream ca0132_pcm_digital_playback = {
6585 .open = ca0132_dig_playback_pcm_open,
6586 .close = ca0132_dig_playback_pcm_close,
6587 .prepare = ca0132_dig_playback_pcm_prepare,
6588 .cleanup = ca0132_dig_playback_pcm_cleanup
6592 static const struct hda_pcm_stream ca0132_pcm_digital_capture = {
6598 static int ca0132_build_pcms(struct hda_codec *codec)
6600 struct ca0132_spec *spec = codec->spec;
6601 struct hda_pcm *info;
6603 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
6606 if (ca0132_use_alt_functions(spec)) {
6607 info->own_chmap = true;
6608 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap
6609 = ca0132_alt_chmaps;
6611 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
6612 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
6613 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
6614 spec->multiout.max_channels;
6615 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6616 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6617 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
6619 /* With the DSP enabled, desktops don't use this ADC. */
6620 if (!ca0132_use_alt_functions(spec)) {
6621 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
6624 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6625 ca0132_pcm_analog_capture;
6626 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6627 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
6630 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
6633 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6634 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6635 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
6637 if (!spec->dig_out && !spec->dig_in)
6640 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
6643 info->pcm_type = HDA_PCM_TYPE_SPDIF;
6644 if (spec->dig_out) {
6645 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
6646 ca0132_pcm_digital_playback;
6647 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
6650 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6651 ca0132_pcm_digital_capture;
6652 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
6658 static int dbpro_build_pcms(struct hda_codec *codec)
6660 struct ca0132_spec *spec = codec->spec;
6661 struct hda_pcm *info;
6663 info = snd_hda_codec_pcm_new(codec, "CA0132 Alt Analog");
6666 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6667 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6668 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
6671 if (!spec->dig_out && !spec->dig_in)
6674 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
6677 info->pcm_type = HDA_PCM_TYPE_SPDIF;
6678 if (spec->dig_out) {
6679 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
6680 ca0132_pcm_digital_playback;
6681 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
6684 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6685 ca0132_pcm_digital_capture;
6686 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
6692 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
6695 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
6696 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
6697 snd_hda_codec_write(codec, pin, 0,
6698 AC_VERB_SET_AMP_GAIN_MUTE,
6701 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
6702 snd_hda_codec_write(codec, dac, 0,
6703 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
6706 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
6709 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
6710 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
6711 snd_hda_codec_write(codec, pin, 0,
6712 AC_VERB_SET_AMP_GAIN_MUTE,
6715 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
6716 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6719 /* init to 0 dB and unmute. */
6720 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6721 HDA_AMP_VOLMASK, 0x5a);
6722 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6727 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
6731 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
6732 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
6733 snd_hda_override_amp_caps(codec, nid, dir, caps);
6737 * Switch between Digital built-in mic and analog mic.
6739 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
6741 struct ca0132_spec *spec = codec->spec;
6744 unsigned int oldval;
6746 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
6748 oldval = stop_mic1(codec);
6749 ca0132_set_vipsource(codec, 0);
6751 /* set DMic input as 2-ch */
6753 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6755 val = spec->dmic_ctl;
6757 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6758 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6760 if (!(spec->dmic_ctl & 0x20))
6761 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
6763 /* set AMic input as mono */
6765 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6767 val = spec->dmic_ctl;
6768 /* clear bit7 and bit5 to disable dmic */
6770 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6771 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6773 if (!(spec->dmic_ctl & 0x20))
6774 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
6776 ca0132_set_vipsource(codec, 1);
6777 resume_mic1(codec, oldval);
6781 * Initialization for Digital Mic.
6783 static void ca0132_init_dmic(struct hda_codec *codec)
6785 struct ca0132_spec *spec = codec->spec;
6788 /* Setup Digital Mic here, but don't enable.
6789 * Enable based on jack detect.
6792 /* MCLK uses MPIO1, set to enable.
6793 * Bit 2-0: MPIO select
6794 * Bit 3: set to disable
6798 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6799 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
6801 /* Data1 uses MPIO3. Data2 not use
6802 * Bit 2-0: Data1 MPIO select
6803 * Bit 3: set disable Data1
6804 * Bit 6-4: Data2 MPIO select
6805 * Bit 7: set disable Data2
6808 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6809 VENDOR_CHIPIO_DMIC_PIN_SET, val);
6811 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
6812 * Bit 3-0: Channel mask
6813 * Bit 4: set for 48KHz, clear for 32KHz
6815 * Bit 6: set to select Data2, clear for Data1
6816 * Bit 7: set to enable DMic, clear for AMic
6818 if (ca0132_quirk(spec) == QUIRK_ALIENWARE_M17XR4)
6822 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
6823 spec->dmic_ctl = val;
6824 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6825 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6829 * Initialization for Analog Mic 2
6831 static void ca0132_init_analog_mic2(struct hda_codec *codec)
6833 struct ca0132_spec *spec = codec->spec;
6835 mutex_lock(&spec->chipio_mutex);
6836 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6837 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
6838 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6839 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6840 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6841 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6842 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6843 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
6844 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6845 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6846 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6847 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6848 mutex_unlock(&spec->chipio_mutex);
6851 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
6853 struct ca0132_spec *spec = codec->spec;
6856 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
6857 snd_hda_codec_update_widgets(codec);
6859 for (i = 0; i < spec->multiout.num_dacs; i++)
6860 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
6862 for (i = 0; i < spec->num_outputs; i++)
6863 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
6865 for (i = 0; i < spec->num_inputs; i++) {
6866 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
6867 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
6872 * Creates a dummy stream to bind the output to. This seems to have to be done
6873 * after changing the main outputs source and destination streams.
6875 static void ca0132_alt_create_dummy_stream(struct hda_codec *codec)
6877 struct ca0132_spec *spec = codec->spec;
6878 unsigned int stream_format;
6880 stream_format = snd_hdac_calc_stream_format(48000, 2,
6881 SNDRV_PCM_FORMAT_S32_LE, 32, 0);
6883 snd_hda_codec_setup_stream(codec, spec->dacs[0], spec->dsp_stream_id,
6886 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
6890 * Initialize mic for non-chromebook ca0132 implementations.
6892 static void ca0132_alt_init_analog_mics(struct hda_codec *codec)
6894 struct ca0132_spec *spec = codec->spec;
6898 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
6899 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
6900 if (ca0132_quirk(spec) == QUIRK_R3DI) {
6901 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6905 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6907 /* Mic 2 setup (not present on desktop cards) */
6908 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
6909 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
6910 if (ca0132_quirk(spec) == QUIRK_R3DI)
6911 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6913 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
6917 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
6918 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
6919 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
6920 * having an updated DAC, which changes the destination to that DAC.
6922 static void sbz_connect_streams(struct hda_codec *codec)
6924 struct ca0132_spec *spec = codec->spec;
6926 mutex_lock(&spec->chipio_mutex);
6928 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
6930 chipio_set_stream_channels(codec, 0x0C, 6);
6931 chipio_set_stream_control(codec, 0x0C, 1);
6933 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
6934 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
6936 /* Setup stream 0x14 with it's source and destination points */
6937 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
6938 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
6939 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
6940 chipio_set_stream_channels(codec, 0x14, 2);
6941 chipio_set_stream_control(codec, 0x14, 1);
6943 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
6945 mutex_unlock(&spec->chipio_mutex);
6949 * Write data through ChipIO to setup proper stream destinations.
6950 * Not sure how it exactly works, but it seems to direct data
6951 * to different destinations. Example is f8 to c0, e0 to c0.
6952 * All I know is, if you don't set these, you get no sound.
6954 static void sbz_chipio_startup_data(struct hda_codec *codec)
6956 struct ca0132_spec *spec = codec->spec;
6958 mutex_lock(&spec->chipio_mutex);
6959 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
6961 /* These control audio output */
6962 chipio_write_no_mutex(codec, 0x190060, 0x0001f8c0);
6963 chipio_write_no_mutex(codec, 0x190064, 0x0001f9c1);
6964 chipio_write_no_mutex(codec, 0x190068, 0x0001fac6);
6965 chipio_write_no_mutex(codec, 0x19006c, 0x0001fbc7);
6966 /* Signal to update I think */
6967 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
6969 chipio_set_stream_channels(codec, 0x0C, 6);
6970 chipio_set_stream_control(codec, 0x0C, 1);
6971 /* No clue what these control */
6972 if (ca0132_quirk(spec) == QUIRK_SBZ) {
6973 chipio_write_no_mutex(codec, 0x190030, 0x0001e0c0);
6974 chipio_write_no_mutex(codec, 0x190034, 0x0001e1c1);
6975 chipio_write_no_mutex(codec, 0x190038, 0x0001e4c2);
6976 chipio_write_no_mutex(codec, 0x19003c, 0x0001e5c3);
6977 chipio_write_no_mutex(codec, 0x190040, 0x0001e2c4);
6978 chipio_write_no_mutex(codec, 0x190044, 0x0001e3c5);
6979 chipio_write_no_mutex(codec, 0x190048, 0x0001e8c6);
6980 chipio_write_no_mutex(codec, 0x19004c, 0x0001e9c7);
6981 chipio_write_no_mutex(codec, 0x190050, 0x0001ecc8);
6982 chipio_write_no_mutex(codec, 0x190054, 0x0001edc9);
6983 chipio_write_no_mutex(codec, 0x190058, 0x0001eaca);
6984 chipio_write_no_mutex(codec, 0x19005c, 0x0001ebcb);
6985 } else if (ca0132_quirk(spec) == QUIRK_ZXR) {
6986 chipio_write_no_mutex(codec, 0x190038, 0x000140c2);
6987 chipio_write_no_mutex(codec, 0x19003c, 0x000141c3);
6988 chipio_write_no_mutex(codec, 0x190040, 0x000150c4);
6989 chipio_write_no_mutex(codec, 0x190044, 0x000151c5);
6990 chipio_write_no_mutex(codec, 0x190050, 0x000142c8);
6991 chipio_write_no_mutex(codec, 0x190054, 0x000143c9);
6992 chipio_write_no_mutex(codec, 0x190058, 0x000152ca);
6993 chipio_write_no_mutex(codec, 0x19005c, 0x000153cb);
6995 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
6997 codec_dbg(codec, "Startup Data exited, mutex released.\n");
6998 mutex_unlock(&spec->chipio_mutex);
7002 * Custom DSP SCP commands where the src value is 0x00 instead of 0x20. This is
7003 * done after the DSP is loaded.
7005 static void ca0132_alt_dsp_scp_startup(struct hda_codec *codec)
7007 struct ca0132_spec *spec = codec->spec;
7008 unsigned int tmp, i;
7011 * Gotta run these twice, or else mic works inconsistently. Not clear
7012 * why this is, but multiple tests have confirmed it.
7014 for (i = 0; i < 2; i++) {
7015 switch (ca0132_quirk(spec)) {
7019 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7021 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7023 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7025 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7027 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7029 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7034 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7036 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7038 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7040 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7042 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7051 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec *codec)
7053 struct ca0132_spec *spec = codec->spec;
7056 chipio_set_stream_control(codec, 0x03, 0);
7057 chipio_set_stream_control(codec, 0x04, 0);
7059 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7060 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7063 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7065 chipio_set_stream_control(codec, 0x03, 1);
7066 chipio_set_stream_control(codec, 0x04, 1);
7068 switch (ca0132_quirk(spec)) {
7070 chipio_write(codec, 0x18b098, 0x0000000c);
7071 chipio_write(codec, 0x18b09C, 0x0000000c);
7074 chipio_write(codec, 0x18b098, 0x0000000c);
7075 chipio_write(codec, 0x18b09c, 0x0000004c);
7082 static void ae5_post_dsp_register_set(struct hda_codec *codec)
7084 struct ca0132_spec *spec = codec->spec;
7086 chipio_8051_write_direct(codec, 0x93, 0x10);
7087 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7088 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
7089 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7090 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
7092 writeb(0xff, spec->mem_base + 0x304);
7093 writeb(0xff, spec->mem_base + 0x304);
7094 writeb(0xff, spec->mem_base + 0x304);
7095 writeb(0xff, spec->mem_base + 0x304);
7096 writeb(0x00, spec->mem_base + 0x100);
7097 writeb(0xff, spec->mem_base + 0x304);
7098 writeb(0x00, spec->mem_base + 0x100);
7099 writeb(0xff, spec->mem_base + 0x304);
7100 writeb(0x00, spec->mem_base + 0x100);
7101 writeb(0xff, spec->mem_base + 0x304);
7102 writeb(0x00, spec->mem_base + 0x100);
7103 writeb(0xff, spec->mem_base + 0x304);
7105 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x3f);
7106 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
7107 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7110 static void ae5_post_dsp_param_setup(struct hda_codec *codec)
7113 * Param3 in the 8051's memory is represented by the ascii string 'mch'
7114 * which seems to be 'multichannel'. This is also mentioned in the
7115 * AE-5's registry values in Windows.
7117 chipio_set_control_param(codec, 3, 0);
7119 * I believe ASI is 'audio serial interface' and that it's used to
7120 * change colors on the external LED strip connected to the AE-5.
7122 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
7124 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
7125 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7127 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7128 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x92);
7129 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7130 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0xfa);
7131 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7132 VENDOR_CHIPIO_8051_DATA_WRITE, 0x22);
7135 static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
7137 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7138 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x41);
7139 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7140 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc8);
7142 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7143 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x45);
7144 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7145 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcc);
7147 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7148 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x40);
7149 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7150 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcb);
7152 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7153 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7154 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7155 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7157 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7158 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x51);
7159 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7160 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x8d);
7163 static void ae5_post_dsp_stream_setup(struct hda_codec *codec)
7165 struct ca0132_spec *spec = codec->spec;
7167 mutex_lock(&spec->chipio_mutex);
7169 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7171 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7173 chipio_set_stream_channels(codec, 0x0C, 6);
7174 chipio_set_stream_control(codec, 0x0C, 1);
7176 chipio_set_stream_source_dest(codec, 0x5, 0x43, 0x0);
7178 chipio_set_stream_source_dest(codec, 0x18, 0x9, 0xd0);
7179 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7180 chipio_set_stream_channels(codec, 0x18, 6);
7181 chipio_set_stream_control(codec, 0x18, 1);
7183 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7185 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7186 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7187 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7188 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7190 ca0113_mmio_command_set(codec, 0x48, 0x01, 0x80);
7192 mutex_unlock(&spec->chipio_mutex);
7195 static void ae5_post_dsp_startup_data(struct hda_codec *codec)
7197 struct ca0132_spec *spec = codec->spec;
7199 mutex_lock(&spec->chipio_mutex);
7201 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
7202 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
7203 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
7204 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
7206 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7207 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
7208 ca0113_mmio_command_set(codec, 0x48, 0x0b, 0x12);
7209 ca0113_mmio_command_set(codec, 0x48, 0x04, 0x00);
7210 ca0113_mmio_command_set(codec, 0x48, 0x06, 0x48);
7211 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7212 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7213 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7214 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7215 ca0113_mmio_gpio_set(codec, 0, true);
7216 ca0113_mmio_gpio_set(codec, 1, true);
7217 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x80);
7219 chipio_write_no_mutex(codec, 0x18b03c, 0x00000012);
7221 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7222 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7224 mutex_unlock(&spec->chipio_mutex);
7228 * Setup default parameters for DSP
7230 static void ca0132_setup_defaults(struct hda_codec *codec)
7232 struct ca0132_spec *spec = codec->spec;
7237 if (spec->dsp_state != DSP_DOWNLOADED)
7240 /* out, in effects + voicefx */
7241 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7242 for (idx = 0; idx < num_fx; idx++) {
7243 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7244 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
7245 ca0132_effects[idx].reqs[i],
7246 ca0132_effects[idx].def_vals[i]);
7250 /*remove DSP headroom*/
7252 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7254 /*set speaker EQ bypass attenuation*/
7255 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
7257 /* set AMic1 and AMic2 as mono mic */
7259 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7260 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
7262 /* set AMic1 as CrystalVoice input */
7264 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
7266 /* set WUH source */
7268 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7272 * Setup default parameters for Recon3D/Recon3Di DSP.
7275 static void r3d_setup_defaults(struct hda_codec *codec)
7277 struct ca0132_spec *spec = codec->spec;
7282 if (spec->dsp_state != DSP_DOWNLOADED)
7285 ca0132_alt_dsp_scp_startup(codec);
7286 ca0132_alt_init_analog_mics(codec);
7288 /*remove DSP headroom*/
7290 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7292 /* set WUH source */
7294 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7295 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7297 /* Set speaker source? */
7298 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7300 if (ca0132_quirk(spec) == QUIRK_R3DI)
7301 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
7303 /* Setup effect defaults */
7304 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7305 for (idx = 0; idx < num_fx; idx++) {
7306 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7307 dspio_set_uint_param(codec,
7308 ca0132_effects[idx].mid,
7309 ca0132_effects[idx].reqs[i],
7310 ca0132_effects[idx].def_vals[i]);
7316 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
7317 * than the Chromebook setup.
7319 static void sbz_setup_defaults(struct hda_codec *codec)
7321 struct ca0132_spec *spec = codec->spec;
7326 if (spec->dsp_state != DSP_DOWNLOADED)
7329 ca0132_alt_dsp_scp_startup(codec);
7330 ca0132_alt_init_analog_mics(codec);
7331 sbz_connect_streams(codec);
7332 sbz_chipio_startup_data(codec);
7334 chipio_set_stream_control(codec, 0x03, 1);
7335 chipio_set_stream_control(codec, 0x04, 1);
7338 * Sets internal input loopback to off, used to have a switch to
7339 * enable input loopback, but turned out to be way too buggy.
7342 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
7343 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
7345 /*remove DSP headroom*/
7347 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7349 /* set WUH source */
7351 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7352 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7354 /* Set speaker source? */
7355 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7357 ca0132_alt_dsp_initial_mic_setup(codec);
7359 /* out, in effects + voicefx */
7360 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7361 for (idx = 0; idx < num_fx; idx++) {
7362 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7363 dspio_set_uint_param(codec,
7364 ca0132_effects[idx].mid,
7365 ca0132_effects[idx].reqs[i],
7366 ca0132_effects[idx].def_vals[i]);
7370 ca0132_alt_create_dummy_stream(codec);
7374 * Setup default parameters for the Sound BlasterX AE-5 DSP.
7376 static void ae5_setup_defaults(struct hda_codec *codec)
7378 struct ca0132_spec *spec = codec->spec;
7383 if (spec->dsp_state != DSP_DOWNLOADED)
7386 ca0132_alt_dsp_scp_startup(codec);
7387 ca0132_alt_init_analog_mics(codec);
7388 chipio_set_stream_control(codec, 0x03, 1);
7389 chipio_set_stream_control(codec, 0x04, 1);
7391 /* New, unknown SCP req's */
7393 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
7394 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
7395 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
7396 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
7398 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
7399 ca0113_mmio_gpio_set(codec, 0, false);
7400 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
7402 /* Internal loopback off */
7404 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
7405 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
7407 /*remove DSP headroom*/
7409 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7411 /* set WUH source */
7413 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7414 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7416 /* Set speaker source? */
7417 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7419 ca0132_alt_dsp_initial_mic_setup(codec);
7420 ae5_post_dsp_register_set(codec);
7421 ae5_post_dsp_param_setup(codec);
7422 ae5_post_dsp_pll_setup(codec);
7423 ae5_post_dsp_stream_setup(codec);
7424 ae5_post_dsp_startup_data(codec);
7426 /* out, in effects + voicefx */
7427 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7428 for (idx = 0; idx < num_fx; idx++) {
7429 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7430 dspio_set_uint_param(codec,
7431 ca0132_effects[idx].mid,
7432 ca0132_effects[idx].reqs[i],
7433 ca0132_effects[idx].def_vals[i]);
7437 ca0132_alt_create_dummy_stream(codec);
7441 * Initialization of flags in chip
7443 static void ca0132_init_flags(struct hda_codec *codec)
7445 struct ca0132_spec *spec = codec->spec;
7447 if (ca0132_use_alt_functions(spec)) {
7448 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
7449 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
7450 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
7451 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
7452 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
7453 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
7454 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
7455 chipio_set_control_flag(codec,
7456 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
7457 chipio_set_control_flag(codec,
7458 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 1);
7460 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
7461 chipio_set_control_flag(codec,
7462 CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
7463 chipio_set_control_flag(codec,
7464 CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
7465 chipio_set_control_flag(codec,
7466 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
7467 chipio_set_control_flag(codec,
7468 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
7469 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
7474 * Initialization of parameters in chip
7476 static void ca0132_init_params(struct hda_codec *codec)
7478 struct ca0132_spec *spec = codec->spec;
7480 if (ca0132_use_alt_functions(spec)) {
7481 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7482 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
7483 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
7484 chipio_set_control_param(codec, 0, 0);
7485 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
7488 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
7489 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
7492 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
7494 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
7495 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
7496 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
7497 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
7498 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
7499 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
7501 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7502 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7503 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7506 static bool ca0132_download_dsp_images(struct hda_codec *codec)
7508 bool dsp_loaded = false;
7509 struct ca0132_spec *spec = codec->spec;
7510 const struct dsp_image_seg *dsp_os_image;
7511 const struct firmware *fw_entry = NULL;
7513 * Alternate firmwares for different variants. The Recon3Di apparently
7514 * can use the default firmware, but I'll leave the option in case
7515 * it needs it again.
7517 switch (ca0132_quirk(spec)) {
7521 if (request_firmware(&fw_entry, DESKTOP_EFX_FILE,
7522 codec->card->dev) != 0)
7523 codec_dbg(codec, "Desktop firmware not found.");
7525 codec_dbg(codec, "Desktop firmware selected.");
7528 if (request_firmware(&fw_entry, R3DI_EFX_FILE,
7529 codec->card->dev) != 0)
7530 codec_dbg(codec, "Recon3Di alt firmware not detected.");
7532 codec_dbg(codec, "Recon3Di firmware selected.");
7538 * Use default ctefx.bin if no alt firmware is detected, or if none
7539 * exists for your particular codec.
7542 codec_dbg(codec, "Default firmware selected.");
7543 if (request_firmware(&fw_entry, EFX_FILE,
7544 codec->card->dev) != 0)
7548 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
7549 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
7550 codec_err(codec, "ca0132 DSP load image failed\n");
7554 dsp_loaded = dspload_wait_loaded(codec);
7557 release_firmware(fw_entry);
7562 static void ca0132_download_dsp(struct hda_codec *codec)
7564 struct ca0132_spec *spec = codec->spec;
7566 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
7570 if (spec->dsp_state == DSP_DOWNLOAD_FAILED)
7571 return; /* don't retry failures */
7573 chipio_enable_clocks(codec);
7574 if (spec->dsp_state != DSP_DOWNLOADED) {
7575 spec->dsp_state = DSP_DOWNLOADING;
7577 if (!ca0132_download_dsp_images(codec))
7578 spec->dsp_state = DSP_DOWNLOAD_FAILED;
7580 spec->dsp_state = DSP_DOWNLOADED;
7583 /* For codecs using alt functions, this is already done earlier */
7584 if (spec->dsp_state == DSP_DOWNLOADED && !ca0132_use_alt_functions(spec))
7585 ca0132_set_dsp_msr(codec, true);
7588 static void ca0132_process_dsp_response(struct hda_codec *codec,
7589 struct hda_jack_callback *callback)
7591 struct ca0132_spec *spec = codec->spec;
7593 codec_dbg(codec, "ca0132_process_dsp_response\n");
7594 snd_hda_power_up_pm(codec);
7595 if (spec->wait_scp) {
7596 if (dspio_get_response_data(codec) >= 0)
7600 dspio_clear_response_queue(codec);
7601 snd_hda_power_down_pm(codec);
7604 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
7606 struct ca0132_spec *spec = codec->spec;
7607 struct hda_jack_tbl *tbl;
7609 /* Delay enabling the HP amp, to let the mic-detection
7610 * state machine run.
7612 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
7614 tbl->block_report = 1;
7615 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
7618 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
7620 struct ca0132_spec *spec = codec->spec;
7622 if (ca0132_use_alt_functions(spec))
7623 ca0132_alt_select_in(codec);
7625 ca0132_select_mic(codec);
7628 static void ca0132_init_unsol(struct hda_codec *codec)
7630 struct ca0132_spec *spec = codec->spec;
7631 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
7632 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
7634 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
7635 ca0132_process_dsp_response);
7636 /* Front headphone jack detection */
7637 if (ca0132_use_alt_functions(spec))
7638 snd_hda_jack_detect_enable_callback(codec,
7639 spec->unsol_tag_front_hp, hp_callback);
7646 /* Sends before DSP download. */
7647 static const struct hda_verb ca0132_base_init_verbs[] = {
7648 /*enable ct extension*/
7649 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
7654 static const struct hda_verb ca0132_base_exit_verbs[] = {
7656 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
7657 /*disable ct extension*/
7658 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
7662 /* Other verbs tables. Sends after DSP download. */
7664 static const struct hda_verb ca0132_init_verbs0[] = {
7665 /* chip init verbs */
7666 {0x15, 0x70D, 0xF0},
7667 {0x15, 0x70E, 0xFE},
7668 {0x15, 0x707, 0x75},
7669 {0x15, 0x707, 0xD3},
7670 {0x15, 0x707, 0x09},
7671 {0x15, 0x707, 0x53},
7672 {0x15, 0x707, 0xD4},
7673 {0x15, 0x707, 0xEF},
7674 {0x15, 0x707, 0x75},
7675 {0x15, 0x707, 0xD3},
7676 {0x15, 0x707, 0x09},
7677 {0x15, 0x707, 0x02},
7678 {0x15, 0x707, 0x37},
7679 {0x15, 0x707, 0x78},
7680 {0x15, 0x53C, 0xCE},
7681 {0x15, 0x575, 0xC9},
7682 {0x15, 0x53D, 0xCE},
7683 {0x15, 0x5B7, 0xC9},
7684 {0x15, 0x70D, 0xE8},
7685 {0x15, 0x70E, 0xFE},
7686 {0x15, 0x707, 0x02},
7687 {0x15, 0x707, 0x68},
7688 {0x15, 0x707, 0x62},
7689 {0x15, 0x53A, 0xCE},
7690 {0x15, 0x546, 0xC9},
7691 {0x15, 0x53B, 0xCE},
7692 {0x15, 0x5E8, 0xC9},
7696 /* Extra init verbs for desktop cards. */
7697 static const struct hda_verb ca0132_init_verbs1[] = {
7698 {0x15, 0x70D, 0x20},
7699 {0x15, 0x70E, 0x19},
7700 {0x15, 0x707, 0x00},
7701 {0x15, 0x539, 0xCE},
7702 {0x15, 0x546, 0xC9},
7703 {0x15, 0x70D, 0xB7},
7704 {0x15, 0x70E, 0x09},
7705 {0x15, 0x707, 0x10},
7706 {0x15, 0x70D, 0xAF},
7707 {0x15, 0x70E, 0x09},
7708 {0x15, 0x707, 0x01},
7709 {0x15, 0x707, 0x05},
7710 {0x15, 0x70D, 0x73},
7711 {0x15, 0x70E, 0x09},
7712 {0x15, 0x707, 0x14},
7713 {0x15, 0x6FF, 0xC4},
7717 static void ca0132_init_chip(struct hda_codec *codec)
7719 struct ca0132_spec *spec = codec->spec;
7724 mutex_init(&spec->chipio_mutex);
7726 spec->cur_out_type = SPEAKER_OUT;
7727 if (!ca0132_use_alt_functions(spec))
7728 spec->cur_mic_type = DIGITAL_MIC;
7730 spec->cur_mic_type = REAR_MIC;
7732 spec->cur_mic_boost = 0;
7734 for (i = 0; i < VNODES_COUNT; i++) {
7735 spec->vnode_lvol[i] = 0x5a;
7736 spec->vnode_rvol[i] = 0x5a;
7737 spec->vnode_lswitch[i] = 0;
7738 spec->vnode_rswitch[i] = 0;
7742 * Default states for effects are in ca0132_effects[].
7744 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
7745 for (i = 0; i < num_fx; i++) {
7746 on = (unsigned int)ca0132_effects[i].reqs[0];
7747 spec->effects_switch[i] = on ? 1 : 0;
7750 * Sets defaults for the effect slider controls, only for alternative
7751 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
7753 if (ca0132_use_alt_controls(spec)) {
7754 spec->xbass_xover_freq = 8;
7755 for (i = 0; i < EFFECT_LEVEL_SLIDERS; i++)
7756 spec->fx_ctl_val[i] = effect_slider_defaults[i];
7759 spec->voicefx_val = 0;
7760 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
7761 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
7764 * The ZxR doesn't have a front panel header, and it's line-in is on
7765 * the daughter board. So, there is no input enum control, and we need
7766 * to make sure that spec->in_enum_val is set properly.
7768 if (ca0132_quirk(spec) == QUIRK_ZXR)
7769 spec->in_enum_val = REAR_MIC;
7771 #ifdef ENABLE_TUNING_CONTROLS
7772 ca0132_init_tuning_defaults(codec);
7777 * Recon3Di exit specific commands.
7779 /* prevents popping noise on shutdown */
7780 static void r3di_gpio_shutdown(struct hda_codec *codec)
7782 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
7786 * Sound Blaster Z exit specific commands.
7788 static void sbz_region2_exit(struct hda_codec *codec)
7790 struct ca0132_spec *spec = codec->spec;
7793 for (i = 0; i < 4; i++)
7794 writeb(0x0, spec->mem_base + 0x100);
7795 for (i = 0; i < 8; i++)
7796 writeb(0xb3, spec->mem_base + 0x304);
7798 ca0113_mmio_gpio_set(codec, 0, false);
7799 ca0113_mmio_gpio_set(codec, 1, false);
7800 ca0113_mmio_gpio_set(codec, 4, true);
7801 ca0113_mmio_gpio_set(codec, 5, false);
7802 ca0113_mmio_gpio_set(codec, 7, false);
7805 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
7807 static const hda_nid_t pins[] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
7810 snd_hda_codec_write(codec, 0x11, 0,
7811 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40);
7813 for (i = 0; i < ARRAY_SIZE(pins); i++)
7814 snd_hda_codec_write(codec, pins[i], 0,
7815 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00);
7818 static void ca0132_clear_unsolicited(struct hda_codec *codec)
7820 static const hda_nid_t pins[] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
7823 for (i = 0; i < ARRAY_SIZE(pins); i++) {
7824 snd_hda_codec_write(codec, pins[i], 0,
7825 AC_VERB_SET_UNSOLICITED_ENABLE, 0x00);
7829 /* On shutdown, sends commands in sets of three */
7830 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
7834 snd_hda_codec_write(codec, 0x01, 0,
7835 AC_VERB_SET_GPIO_DIRECTION, dir);
7837 snd_hda_codec_write(codec, 0x01, 0,
7838 AC_VERB_SET_GPIO_MASK, mask);
7841 snd_hda_codec_write(codec, 0x01, 0,
7842 AC_VERB_SET_GPIO_DATA, data);
7845 static void zxr_dbpro_power_state_shutdown(struct hda_codec *codec)
7847 static const hda_nid_t pins[] = {0x05, 0x0c, 0x09, 0x0e, 0x08, 0x11, 0x01};
7850 for (i = 0; i < ARRAY_SIZE(pins); i++)
7851 snd_hda_codec_write(codec, pins[i], 0,
7852 AC_VERB_SET_POWER_STATE, 0x03);
7855 static void sbz_exit_chip(struct hda_codec *codec)
7857 chipio_set_stream_control(codec, 0x03, 0);
7858 chipio_set_stream_control(codec, 0x04, 0);
7860 /* Mess with GPIO */
7861 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
7862 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
7863 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
7865 chipio_set_stream_control(codec, 0x14, 0);
7866 chipio_set_stream_control(codec, 0x0C, 0);
7868 chipio_set_conn_rate(codec, 0x41, SR_192_000);
7869 chipio_set_conn_rate(codec, 0x91, SR_192_000);
7871 chipio_write(codec, 0x18a020, 0x00000083);
7873 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
7874 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
7875 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
7877 chipio_set_stream_control(codec, 0x0C, 0);
7879 chipio_set_control_param(codec, 0x0D, 0x24);
7881 ca0132_clear_unsolicited(codec);
7882 sbz_set_pin_ctl_default(codec);
7884 snd_hda_codec_write(codec, 0x0B, 0,
7885 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
7887 sbz_region2_exit(codec);
7890 static void r3d_exit_chip(struct hda_codec *codec)
7892 ca0132_clear_unsolicited(codec);
7893 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7894 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
7897 static void ae5_exit_chip(struct hda_codec *codec)
7899 chipio_set_stream_control(codec, 0x03, 0);
7900 chipio_set_stream_control(codec, 0x04, 0);
7902 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
7903 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7904 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7905 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
7906 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
7907 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x00);
7908 ca0113_mmio_gpio_set(codec, 0, false);
7909 ca0113_mmio_gpio_set(codec, 1, false);
7911 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7912 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
7914 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7916 chipio_set_stream_control(codec, 0x18, 0);
7917 chipio_set_stream_control(codec, 0x0c, 0);
7919 snd_hda_codec_write(codec, 0x01, 0, 0x724, 0x83);
7922 static void zxr_exit_chip(struct hda_codec *codec)
7924 chipio_set_stream_control(codec, 0x03, 0);
7925 chipio_set_stream_control(codec, 0x04, 0);
7926 chipio_set_stream_control(codec, 0x14, 0);
7927 chipio_set_stream_control(codec, 0x0C, 0);
7929 chipio_set_conn_rate(codec, 0x41, SR_192_000);
7930 chipio_set_conn_rate(codec, 0x91, SR_192_000);
7932 chipio_write(codec, 0x18a020, 0x00000083);
7934 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7935 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
7937 ca0132_clear_unsolicited(codec);
7938 sbz_set_pin_ctl_default(codec);
7939 snd_hda_codec_write(codec, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x00);
7941 ca0113_mmio_gpio_set(codec, 5, false);
7942 ca0113_mmio_gpio_set(codec, 2, false);
7943 ca0113_mmio_gpio_set(codec, 3, false);
7944 ca0113_mmio_gpio_set(codec, 0, false);
7945 ca0113_mmio_gpio_set(codec, 4, true);
7946 ca0113_mmio_gpio_set(codec, 0, true);
7947 ca0113_mmio_gpio_set(codec, 5, true);
7948 ca0113_mmio_gpio_set(codec, 2, false);
7949 ca0113_mmio_gpio_set(codec, 3, false);
7952 static void ca0132_exit_chip(struct hda_codec *codec)
7954 /* put any chip cleanup stuffs here. */
7956 if (dspload_is_loaded(codec))
7961 * This fixes a problem that was hard to reproduce. Very rarely, I would
7962 * boot up, and there would be no sound, but the DSP indicated it had loaded
7963 * properly. I did a few memory dumps to see if anything was different, and
7964 * there were a few areas of memory uninitialized with a1a2a3a4. This function
7965 * checks if those areas are uninitialized, and if they are, it'll attempt to
7966 * reload the card 3 times. Usually it fixes by the second.
7968 static void sbz_dsp_startup_check(struct hda_codec *codec)
7970 struct ca0132_spec *spec = codec->spec;
7971 unsigned int dsp_data_check[4];
7972 unsigned int cur_address = 0x390;
7974 unsigned int failure = 0;
7975 unsigned int reload = 3;
7977 if (spec->startup_check_entered)
7980 spec->startup_check_entered = true;
7982 for (i = 0; i < 4; i++) {
7983 chipio_read(codec, cur_address, &dsp_data_check[i]);
7986 for (i = 0; i < 4; i++) {
7987 if (dsp_data_check[i] == 0xa1a2a3a4)
7991 codec_dbg(codec, "Startup Check: %d ", failure);
7993 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
7995 * While the failure condition is true, and we haven't reached our
7996 * three reload limit, continue trying to reload the driver and
7999 while (failure && (reload != 0)) {
8000 codec_info(codec, "Reloading... Tries left: %d", reload);
8001 sbz_exit_chip(codec);
8002 spec->dsp_state = DSP_DOWNLOAD_INIT;
8003 codec->patch_ops.init(codec);
8005 for (i = 0; i < 4; i++) {
8006 chipio_read(codec, cur_address, &dsp_data_check[i]);
8009 for (i = 0; i < 4; i++) {
8010 if (dsp_data_check[i] == 0xa1a2a3a4)
8016 if (!failure && reload < 3)
8017 codec_info(codec, "DSP fixed.");
8022 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
8026 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
8027 * extra precision for decibel values. If you had the dB value in floating point
8028 * you would take the value after the decimal point, multiply by 64, and divide
8029 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
8030 * implement fixed point or floating point dB volumes. For now, I'll set them
8031 * to 0 just incase a value has lingered from a boot into Windows.
8033 static void ca0132_alt_vol_setup(struct hda_codec *codec)
8035 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
8036 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
8037 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
8038 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
8039 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
8040 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
8041 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
8042 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
8046 * Extra commands that don't really fit anywhere else.
8048 static void sbz_pre_dsp_setup(struct hda_codec *codec)
8050 struct ca0132_spec *spec = codec->spec;
8052 writel(0x00820680, spec->mem_base + 0x01C);
8053 writel(0x00820680, spec->mem_base + 0x01C);
8055 chipio_write(codec, 0x18b0a4, 0x000000c2);
8057 snd_hda_codec_write(codec, 0x11, 0,
8058 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
8061 static void r3d_pre_dsp_setup(struct hda_codec *codec)
8063 chipio_write(codec, 0x18b0a4, 0x000000c2);
8065 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8066 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
8067 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8068 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
8069 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8070 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
8072 snd_hda_codec_write(codec, 0x11, 0,
8073 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
8076 static void r3di_pre_dsp_setup(struct hda_codec *codec)
8078 chipio_write(codec, 0x18b0a4, 0x000000c2);
8080 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8081 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
8082 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8083 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
8084 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8085 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
8087 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8088 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
8089 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8090 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
8091 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8092 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
8093 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8094 VENDOR_CHIPIO_8051_DATA_WRITE, 0x40);
8096 snd_hda_codec_write(codec, 0x11, 0,
8097 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
8101 * These are sent before the DSP is downloaded. Not sure
8102 * what they do, or if they're necessary. Could possibly
8103 * be removed. Figure they're better to leave in.
8105 static void ca0132_mmio_init(struct hda_codec *codec)
8107 struct ca0132_spec *spec = codec->spec;
8109 if (ca0132_quirk(spec) == QUIRK_AE5)
8110 writel(0x00000001, spec->mem_base + 0x400);
8112 writel(0x00000000, spec->mem_base + 0x400);
8114 if (ca0132_quirk(spec) == QUIRK_AE5)
8115 writel(0x00000001, spec->mem_base + 0x408);
8117 writel(0x00000000, spec->mem_base + 0x408);
8119 if (ca0132_quirk(spec) == QUIRK_AE5)
8120 writel(0x00000001, spec->mem_base + 0x40c);
8122 writel(0x00000000, spec->mem_base + 0x40C);
8124 if (ca0132_quirk(spec) == QUIRK_ZXR)
8125 writel(0x00880640, spec->mem_base + 0x01C);
8127 writel(0x00880680, spec->mem_base + 0x01C);
8129 if (ca0132_quirk(spec) == QUIRK_AE5)
8130 writel(0x00000080, spec->mem_base + 0xC0C);
8132 writel(0x00000083, spec->mem_base + 0xC0C);
8134 writel(0x00000030, spec->mem_base + 0xC00);
8135 writel(0x00000000, spec->mem_base + 0xC04);
8137 if (ca0132_quirk(spec) == QUIRK_AE5)
8138 writel(0x00000000, spec->mem_base + 0xC0C);
8140 writel(0x00000003, spec->mem_base + 0xC0C);
8142 writel(0x00000003, spec->mem_base + 0xC0C);
8143 writel(0x00000003, spec->mem_base + 0xC0C);
8144 writel(0x00000003, spec->mem_base + 0xC0C);
8146 if (ca0132_quirk(spec) == QUIRK_AE5)
8147 writel(0x00000001, spec->mem_base + 0xC08);
8149 writel(0x000000C1, spec->mem_base + 0xC08);
8151 writel(0x000000F1, spec->mem_base + 0xC08);
8152 writel(0x00000001, spec->mem_base + 0xC08);
8153 writel(0x000000C7, spec->mem_base + 0xC08);
8154 writel(0x000000C1, spec->mem_base + 0xC08);
8155 writel(0x00000080, spec->mem_base + 0xC04);
8157 if (ca0132_quirk(spec) == QUIRK_AE5) {
8158 writel(0x00000000, spec->mem_base + 0x42c);
8159 writel(0x00000000, spec->mem_base + 0x46c);
8160 writel(0x00000000, spec->mem_base + 0x4ac);
8161 writel(0x00000000, spec->mem_base + 0x4ec);
8162 writel(0x00000000, spec->mem_base + 0x43c);
8163 writel(0x00000000, spec->mem_base + 0x47c);
8164 writel(0x00000000, spec->mem_base + 0x4bc);
8165 writel(0x00000000, spec->mem_base + 0x4fc);
8166 writel(0x00000600, spec->mem_base + 0x100);
8167 writel(0x00000014, spec->mem_base + 0x410);
8168 writel(0x0000060f, spec->mem_base + 0x100);
8169 writel(0x0000070f, spec->mem_base + 0x100);
8170 writel(0x00000aff, spec->mem_base + 0x830);
8171 writel(0x00000000, spec->mem_base + 0x86c);
8172 writel(0x0000006b, spec->mem_base + 0x800);
8173 writel(0x00000001, spec->mem_base + 0x86c);
8174 writel(0x0000006b, spec->mem_base + 0x800);
8175 writel(0x00000057, spec->mem_base + 0x804);
8176 writel(0x00800000, spec->mem_base + 0x20c);
8181 * This function writes to some SFR's, does some region2 writes, and then
8182 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
8185 static void ae5_register_set(struct hda_codec *codec)
8187 struct ca0132_spec *spec = codec->spec;
8189 chipio_8051_write_direct(codec, 0x93, 0x10);
8190 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8191 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
8192 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8193 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
8195 writeb(0x0f, spec->mem_base + 0x304);
8196 writeb(0x0f, spec->mem_base + 0x304);
8197 writeb(0x0f, spec->mem_base + 0x304);
8198 writeb(0x0f, spec->mem_base + 0x304);
8199 writeb(0x0e, spec->mem_base + 0x100);
8200 writeb(0x1f, spec->mem_base + 0x304);
8201 writeb(0x0c, spec->mem_base + 0x100);
8202 writeb(0x3f, spec->mem_base + 0x304);
8203 writeb(0x08, spec->mem_base + 0x100);
8204 writeb(0x7f, spec->mem_base + 0x304);
8205 writeb(0x00, spec->mem_base + 0x100);
8206 writeb(0xff, spec->mem_base + 0x304);
8208 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
8210 chipio_8051_write_direct(codec, 0x90, 0x00);
8211 chipio_8051_write_direct(codec, 0x90, 0x10);
8213 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8215 chipio_write(codec, 0x18b0a4, 0x000000c2);
8217 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
8218 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
8222 * Extra init functions for alternative ca0132 codecs. Done
8223 * here so they don't clutter up the main ca0132_init function
8224 * anymore than they have to.
8226 static void ca0132_alt_init(struct hda_codec *codec)
8228 struct ca0132_spec *spec = codec->spec;
8230 ca0132_alt_vol_setup(codec);
8232 switch (ca0132_quirk(spec)) {
8234 codec_dbg(codec, "SBZ alt_init");
8235 ca0132_gpio_init(codec);
8236 sbz_pre_dsp_setup(codec);
8237 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8238 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8241 codec_dbg(codec, "R3DI alt_init");
8242 ca0132_gpio_init(codec);
8243 ca0132_gpio_setup(codec);
8244 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
8245 r3di_pre_dsp_setup(codec);
8246 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8247 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
8250 r3d_pre_dsp_setup(codec);
8251 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8252 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8255 ca0132_gpio_init(codec);
8256 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8257 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x49);
8258 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8259 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x88);
8260 chipio_write(codec, 0x18b030, 0x00000020);
8261 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8262 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8263 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8266 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8267 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8274 static int ca0132_init(struct hda_codec *codec)
8276 struct ca0132_spec *spec = codec->spec;
8277 struct auto_pin_cfg *cfg = &spec->autocfg;
8282 * If the DSP is already downloaded, and init has been entered again,
8283 * there's only two reasons for it. One, the codec has awaken from a
8284 * suspended state, and in that case dspload_is_loaded will return
8285 * false, and the init will be ran again. The other reason it gets
8286 * re entered is on startup for some reason it triggers a suspend and
8287 * resume state. In this case, it will check if the DSP is downloaded,
8288 * and not run the init function again. For codecs using alt_functions,
8289 * it will check if the DSP is loaded properly.
8291 if (spec->dsp_state == DSP_DOWNLOADED) {
8292 dsp_loaded = dspload_is_loaded(codec);
8294 spec->dsp_reload = true;
8295 spec->dsp_state = DSP_DOWNLOAD_INIT;
8297 if (ca0132_quirk(spec) == QUIRK_SBZ)
8298 sbz_dsp_startup_check(codec);
8303 if (spec->dsp_state != DSP_DOWNLOAD_FAILED)
8304 spec->dsp_state = DSP_DOWNLOAD_INIT;
8305 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
8307 if (ca0132_use_pci_mmio(spec))
8308 ca0132_mmio_init(codec);
8310 snd_hda_power_up_pm(codec);
8312 if (ca0132_quirk(spec) == QUIRK_AE5)
8313 ae5_register_set(codec);
8315 ca0132_init_unsol(codec);
8316 ca0132_init_params(codec);
8317 ca0132_init_flags(codec);
8319 snd_hda_sequence_write(codec, spec->base_init_verbs);
8321 if (ca0132_use_alt_functions(spec))
8322 ca0132_alt_init(codec);
8324 ca0132_download_dsp(codec);
8326 ca0132_refresh_widget_caps(codec);
8328 switch (ca0132_quirk(spec)) {
8331 r3d_setup_defaults(codec);
8335 sbz_setup_defaults(codec);
8338 ae5_setup_defaults(codec);
8341 ca0132_setup_defaults(codec);
8342 ca0132_init_analog_mic2(codec);
8343 ca0132_init_dmic(codec);
8347 for (i = 0; i < spec->num_outputs; i++)
8348 init_output(codec, spec->out_pins[i], spec->dacs[0]);
8350 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
8352 for (i = 0; i < spec->num_inputs; i++)
8353 init_input(codec, spec->input_pins[i], spec->adcs[i]);
8355 init_input(codec, cfg->dig_in_pin, spec->dig_in);
8357 if (!ca0132_use_alt_functions(spec)) {
8358 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8359 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8360 VENDOR_CHIPIO_PARAM_EX_ID_SET, 0x0D);
8361 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8362 VENDOR_CHIPIO_PARAM_EX_VALUE_SET, 0x20);
8365 if (ca0132_quirk(spec) == QUIRK_SBZ)
8366 ca0132_gpio_setup(codec);
8368 snd_hda_sequence_write(codec, spec->spec_init_verbs);
8369 if (ca0132_use_alt_functions(spec)) {
8370 ca0132_alt_select_out(codec);
8371 ca0132_alt_select_in(codec);
8373 ca0132_select_out(codec);
8374 ca0132_select_mic(codec);
8377 snd_hda_jack_report_sync(codec);
8380 * Re set the PlayEnhancement switch on a resume event, because the
8381 * controls will not be reloaded.
8383 if (spec->dsp_reload) {
8384 spec->dsp_reload = false;
8385 ca0132_pe_switch_set(codec);
8388 snd_hda_power_down_pm(codec);
8393 static int dbpro_init(struct hda_codec *codec)
8395 struct ca0132_spec *spec = codec->spec;
8396 struct auto_pin_cfg *cfg = &spec->autocfg;
8399 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
8400 init_input(codec, cfg->dig_in_pin, spec->dig_in);
8402 for (i = 0; i < spec->num_inputs; i++)
8403 init_input(codec, spec->input_pins[i], spec->adcs[i]);
8408 static void ca0132_free(struct hda_codec *codec)
8410 struct ca0132_spec *spec = codec->spec;
8412 cancel_delayed_work_sync(&spec->unsol_hp_work);
8413 snd_hda_power_up(codec);
8414 switch (ca0132_quirk(spec)) {
8416 sbz_exit_chip(codec);
8419 zxr_exit_chip(codec);
8422 r3d_exit_chip(codec);
8425 ae5_exit_chip(codec);
8428 r3di_gpio_shutdown(codec);
8434 snd_hda_sequence_write(codec, spec->base_exit_verbs);
8435 ca0132_exit_chip(codec);
8437 snd_hda_power_down(codec);
8440 pci_iounmap(codec->bus->pci, spec->mem_base);
8442 kfree(spec->spec_init_verbs);
8446 static void dbpro_free(struct hda_codec *codec)
8448 struct ca0132_spec *spec = codec->spec;
8450 zxr_dbpro_power_state_shutdown(codec);
8452 kfree(spec->spec_init_verbs);
8456 static void ca0132_reboot_notify(struct hda_codec *codec)
8458 codec->patch_ops.free(codec);
8462 static int ca0132_suspend(struct hda_codec *codec)
8464 struct ca0132_spec *spec = codec->spec;
8466 cancel_delayed_work_sync(&spec->unsol_hp_work);
8471 static const struct hda_codec_ops ca0132_patch_ops = {
8472 .build_controls = ca0132_build_controls,
8473 .build_pcms = ca0132_build_pcms,
8474 .init = ca0132_init,
8475 .free = ca0132_free,
8476 .unsol_event = snd_hda_jack_unsol_event,
8478 .suspend = ca0132_suspend,
8480 .reboot_notify = ca0132_reboot_notify,
8483 static const struct hda_codec_ops dbpro_patch_ops = {
8484 .build_controls = dbpro_build_controls,
8485 .build_pcms = dbpro_build_pcms,
8490 static void ca0132_config(struct hda_codec *codec)
8492 struct ca0132_spec *spec = codec->spec;
8494 spec->dacs[0] = 0x2;
8495 spec->dacs[1] = 0x3;
8496 spec->dacs[2] = 0x4;
8498 spec->multiout.dac_nids = spec->dacs;
8499 spec->multiout.num_dacs = 3;
8501 if (!ca0132_use_alt_functions(spec))
8502 spec->multiout.max_channels = 2;
8504 spec->multiout.max_channels = 6;
8506 switch (ca0132_quirk(spec)) {
8507 case QUIRK_ALIENWARE:
8508 codec_dbg(codec, "%s: QUIRK_ALIENWARE applied.\n", __func__);
8509 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
8512 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
8513 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
8516 codec_dbg(codec, "%s: QUIRK_ZXR applied.\n", __func__);
8517 snd_hda_apply_pincfgs(codec, zxr_pincfgs);
8520 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
8521 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
8524 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
8525 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
8528 codec_dbg(codec, "%s: QUIRK_AE5 applied.\n", __func__);
8529 snd_hda_apply_pincfgs(codec, ae5_pincfgs);
8535 switch (ca0132_quirk(spec)) {
8536 case QUIRK_ALIENWARE:
8537 spec->num_outputs = 2;
8538 spec->out_pins[0] = 0x0b; /* speaker out */
8539 spec->out_pins[1] = 0x0f;
8540 spec->shared_out_nid = 0x2;
8541 spec->unsol_tag_hp = 0x0f;
8543 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
8544 spec->adcs[1] = 0x8; /* analog mic2 */
8545 spec->adcs[2] = 0xa; /* what u hear */
8547 spec->num_inputs = 3;
8548 spec->input_pins[0] = 0x12;
8549 spec->input_pins[1] = 0x11;
8550 spec->input_pins[2] = 0x13;
8551 spec->shared_mic_nid = 0x7;
8552 spec->unsol_tag_amic1 = 0x11;
8556 spec->num_outputs = 2;
8557 spec->out_pins[0] = 0x0B; /* Line out */
8558 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8559 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8560 spec->out_pins[3] = 0x11; /* Rear surround */
8561 spec->shared_out_nid = 0x2;
8562 spec->unsol_tag_hp = spec->out_pins[1];
8563 spec->unsol_tag_front_hp = spec->out_pins[2];
8565 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8566 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
8567 spec->adcs[2] = 0xa; /* what u hear */
8569 spec->num_inputs = 2;
8570 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8571 spec->input_pins[1] = 0x13; /* What U Hear */
8572 spec->shared_mic_nid = 0x7;
8573 spec->unsol_tag_amic1 = spec->input_pins[0];
8576 spec->dig_out = 0x05;
8577 spec->multiout.dig_out_nid = spec->dig_out;
8578 spec->dig_in = 0x09;
8581 spec->num_outputs = 2;
8582 spec->out_pins[0] = 0x0B; /* Line out */
8583 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8584 spec->out_pins[2] = 0x10; /* Center/LFE */
8585 spec->out_pins[3] = 0x11; /* Rear surround */
8586 spec->shared_out_nid = 0x2;
8587 spec->unsol_tag_hp = spec->out_pins[1];
8588 spec->unsol_tag_front_hp = spec->out_pins[2];
8590 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8591 spec->adcs[1] = 0x8; /* Not connected, no front mic */
8592 spec->adcs[2] = 0xa; /* what u hear */
8594 spec->num_inputs = 2;
8595 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8596 spec->input_pins[1] = 0x13; /* What U Hear */
8597 spec->shared_mic_nid = 0x7;
8598 spec->unsol_tag_amic1 = spec->input_pins[0];
8600 case QUIRK_ZXR_DBPRO:
8601 spec->adcs[0] = 0x8; /* ZxR DBPro Aux In */
8603 spec->num_inputs = 1;
8604 spec->input_pins[0] = 0x11; /* RCA Line-in */
8606 spec->dig_out = 0x05;
8607 spec->multiout.dig_out_nid = spec->dig_out;
8609 spec->dig_in = 0x09;
8612 spec->num_outputs = 2;
8613 spec->out_pins[0] = 0x0B; /* Line out */
8614 spec->out_pins[1] = 0x11; /* Rear headphone out */
8615 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8616 spec->out_pins[3] = 0x0F; /* Rear surround */
8617 spec->shared_out_nid = 0x2;
8618 spec->unsol_tag_hp = spec->out_pins[1];
8619 spec->unsol_tag_front_hp = spec->out_pins[2];
8621 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8622 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
8623 spec->adcs[2] = 0xa; /* what u hear */
8625 spec->num_inputs = 2;
8626 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8627 spec->input_pins[1] = 0x13; /* What U Hear */
8628 spec->shared_mic_nid = 0x7;
8629 spec->unsol_tag_amic1 = spec->input_pins[0];
8632 spec->dig_out = 0x05;
8633 spec->multiout.dig_out_nid = spec->dig_out;
8636 spec->num_outputs = 2;
8637 spec->out_pins[0] = 0x0B; /* Line out */
8638 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8639 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8640 spec->out_pins[3] = 0x11; /* Rear surround */
8641 spec->shared_out_nid = 0x2;
8642 spec->unsol_tag_hp = spec->out_pins[1];
8643 spec->unsol_tag_front_hp = spec->out_pins[2];
8645 spec->adcs[0] = 0x07; /* Rear Mic / Line-in */
8646 spec->adcs[1] = 0x08; /* Front Mic, but only if no DSP */
8647 spec->adcs[2] = 0x0a; /* what u hear */
8649 spec->num_inputs = 2;
8650 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8651 spec->input_pins[1] = 0x13; /* What U Hear */
8652 spec->shared_mic_nid = 0x7;
8653 spec->unsol_tag_amic1 = spec->input_pins[0];
8656 spec->dig_out = 0x05;
8657 spec->multiout.dig_out_nid = spec->dig_out;
8660 spec->num_outputs = 2;
8661 spec->out_pins[0] = 0x0b; /* speaker out */
8662 spec->out_pins[1] = 0x10; /* headphone out */
8663 spec->shared_out_nid = 0x2;
8664 spec->unsol_tag_hp = spec->out_pins[1];
8666 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
8667 spec->adcs[1] = 0x8; /* analog mic2 */
8668 spec->adcs[2] = 0xa; /* what u hear */
8670 spec->num_inputs = 3;
8671 spec->input_pins[0] = 0x12;
8672 spec->input_pins[1] = 0x11;
8673 spec->input_pins[2] = 0x13;
8674 spec->shared_mic_nid = 0x7;
8675 spec->unsol_tag_amic1 = spec->input_pins[0];
8678 spec->dig_out = 0x05;
8679 spec->multiout.dig_out_nid = spec->dig_out;
8680 spec->dig_in = 0x09;
8685 static int ca0132_prepare_verbs(struct hda_codec *codec)
8687 /* Verbs + terminator (an empty element) */
8688 #define NUM_SPEC_VERBS 2
8689 struct ca0132_spec *spec = codec->spec;
8691 spec->chip_init_verbs = ca0132_init_verbs0;
8693 * Since desktop cards use pci_mmio, this can be used to determine
8694 * whether or not to use these verbs instead of a separate bool.
8696 if (ca0132_use_pci_mmio(spec))
8697 spec->desktop_init_verbs = ca0132_init_verbs1;
8698 spec->spec_init_verbs = kcalloc(NUM_SPEC_VERBS,
8699 sizeof(struct hda_verb),
8701 if (!spec->spec_init_verbs)
8705 spec->spec_init_verbs[0].nid = 0x0b;
8706 spec->spec_init_verbs[0].param = 0x78D;
8707 spec->spec_init_verbs[0].verb = 0x00;
8709 /* Previously commented configuration */
8711 spec->spec_init_verbs[2].nid = 0x0b;
8712 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
8713 spec->spec_init_verbs[2].verb = 0x02;
8715 spec->spec_init_verbs[3].nid = 0x10;
8716 spec->spec_init_verbs[3].param = 0x78D;
8717 spec->spec_init_verbs[3].verb = 0x02;
8719 spec->spec_init_verbs[4].nid = 0x10;
8720 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
8721 spec->spec_init_verbs[4].verb = 0x02;
8724 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
8729 * The Sound Blaster ZxR shares the same PCI subsystem ID as some regular
8730 * Sound Blaster Z cards. However, they have different HDA codec subsystem
8731 * ID's. So, we check for the ZxR's subsystem ID, as well as the DBPro
8732 * daughter boards ID.
8734 static void sbz_detect_quirk(struct hda_codec *codec)
8736 struct ca0132_spec *spec = codec->spec;
8738 switch (codec->core.subsystem_id) {
8740 spec->quirk = QUIRK_ZXR;
8743 spec->quirk = QUIRK_ZXR_DBPRO;
8746 spec->quirk = QUIRK_SBZ;
8751 static int patch_ca0132(struct hda_codec *codec)
8753 struct ca0132_spec *spec;
8755 const struct snd_pci_quirk *quirk;
8757 codec_dbg(codec, "patch_ca0132\n");
8759 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8763 spec->codec = codec;
8765 /* Detect codec quirk */
8766 quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks);
8768 spec->quirk = quirk->value;
8770 spec->quirk = QUIRK_NONE;
8771 if (ca0132_quirk(spec) == QUIRK_SBZ)
8772 sbz_detect_quirk(codec);
8774 if (ca0132_quirk(spec) == QUIRK_ZXR_DBPRO)
8775 codec->patch_ops = dbpro_patch_ops;
8777 codec->patch_ops = ca0132_patch_ops;
8779 codec->pcm_format_first = 1;
8780 codec->no_sticky_stream = 1;
8783 spec->dsp_state = DSP_DOWNLOAD_INIT;
8784 spec->num_mixers = 1;
8786 /* Set which mixers each quirk uses. */
8787 switch (ca0132_quirk(spec)) {
8789 spec->mixers[0] = desktop_mixer;
8790 snd_hda_codec_set_name(codec, "Sound Blaster Z");
8793 spec->mixers[0] = desktop_mixer;
8794 snd_hda_codec_set_name(codec, "Sound Blaster ZxR");
8796 case QUIRK_ZXR_DBPRO:
8799 spec->mixers[0] = desktop_mixer;
8800 snd_hda_codec_set_name(codec, "Recon3D");
8803 spec->mixers[0] = r3di_mixer;
8804 snd_hda_codec_set_name(codec, "Recon3Di");
8807 spec->mixers[0] = desktop_mixer;
8808 snd_hda_codec_set_name(codec, "Sound BlasterX AE-5");
8811 spec->mixers[0] = ca0132_mixer;
8815 /* Setup whether or not to use alt functions/controls/pci_mmio */
8816 switch (ca0132_quirk(spec)) {
8821 spec->use_alt_controls = true;
8822 spec->use_alt_functions = true;
8823 spec->use_pci_mmio = true;
8826 spec->use_alt_controls = true;
8827 spec->use_alt_functions = true;
8828 spec->use_pci_mmio = false;
8831 spec->use_alt_controls = false;
8832 spec->use_alt_functions = false;
8833 spec->use_pci_mmio = false;
8838 if (spec->use_pci_mmio) {
8839 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
8840 if (spec->mem_base == NULL) {
8841 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
8842 spec->quirk = QUIRK_NONE;
8847 spec->base_init_verbs = ca0132_base_init_verbs;
8848 spec->base_exit_verbs = ca0132_base_exit_verbs;
8850 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
8852 ca0132_init_chip(codec);
8854 ca0132_config(codec);
8856 err = ca0132_prepare_verbs(codec);
8860 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
8874 static const struct hda_device_id snd_hda_id_ca0132[] = {
8875 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132),
8878 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132);
8880 MODULE_LICENSE("GPL");
8881 MODULE_DESCRIPTION("Creative Sound Core3D codec");
8883 static struct hda_codec_driver ca0132_driver = {
8884 .id = snd_hda_id_ca0132,
8887 module_hda_codec_driver(ca0132_driver);