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_FIVE 0x40a00000
42 #define FLOAT_SIX 0x40c00000
43 #define FLOAT_EIGHT 0x41000000
44 #define FLOAT_MINUS_5 0xc0a00000
46 #define UNSOL_TAG_DSP 0x16
48 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
49 #define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
51 #define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
52 #define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
53 #define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
55 #define MASTERCONTROL 0x80
56 #define MASTERCONTROL_ALLOC_DMA_CHAN 10
57 #define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
59 #define WIDGET_CHIP_CTRL 0x15
60 #define WIDGET_DSP_CTRL 0x16
62 #define MEM_CONNID_MICIN1 3
63 #define MEM_CONNID_MICIN2 5
64 #define MEM_CONNID_MICOUT1 12
65 #define MEM_CONNID_MICOUT2 14
66 #define MEM_CONNID_WUH 10
67 #define MEM_CONNID_DSP 16
68 #define MEM_CONNID_DMIC 100
73 #define EFX_FILE "/*(DEBLOBBED)*/"
74 #define DESKTOP_EFX_FILE "/*(DEBLOBBED)*/"
75 #define R3DI_EFX_FILE "/*(DEBLOBBED)*/"
77 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
81 static const char *const dirstr[2] = { "Playback", "Capture" };
83 #define NUM_OF_OUTPUTS 2
84 static const char *const out_type_str[2] = { "Speakers", "Headphone" };
95 /* Strings for Input Source Enum Control */
96 static const char *const in_src_str[3] = { "Microphone", "Line In", "Front Microphone" };
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 SPEAKER_CHANNEL_CFG_ENUM,
148 SPEAKER_FULL_RANGE_FRONT,
149 SPEAKER_FULL_RANGE_REAR,
151 BASS_REDIRECTION_XOVER,
152 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
155 /* Effects values size*/
156 #define EFFECT_VALS_MAX_COUNT 12
159 * Default values for the effect slider controls, they are in order of their
160 * effect NID's. Surround, Crystalizer, Dialog Plus, Smart Volume, and then
163 static const unsigned int effect_slider_defaults[] = {67, 65, 50, 74, 50};
164 /* Amount of effect level sliders for ca0132_alt controls. */
165 #define EFFECT_LEVEL_SLIDERS 5
167 /* Latency introduced by DSP blocks in milliseconds. */
168 #define DSP_CAPTURE_INIT_LATENCY 0
169 #define DSP_CRYSTAL_VOICE_LATENCY 124
170 #define DSP_PLAYBACK_INIT_LATENCY 13
171 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
172 #define DSP_SPEAKER_OUT_LATENCY 7
175 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
177 int mid; /*effect module ID*/
178 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
179 int direct; /* 0:output; 1:input*/
180 int params; /* number of default non-on/off params */
181 /*effect default values, 1st is on/off. */
182 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
185 #define EFX_DIR_OUT 0
188 static const struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
189 { .name = "Surround",
193 .direct = EFX_DIR_OUT,
195 .def_vals = {0x3F800000, 0x3F2B851F}
197 { .name = "Crystalizer",
201 .direct = EFX_DIR_OUT,
203 .def_vals = {0x3F800000, 0x3F266666}
205 { .name = "Dialog Plus",
209 .direct = EFX_DIR_OUT,
211 .def_vals = {0x00000000, 0x3F000000}
213 { .name = "Smart Volume",
217 .direct = EFX_DIR_OUT,
219 .def_vals = {0x3F800000, 0x3F3D70A4, 0x00000000}
224 .reqs = {24, 23, 25},
225 .direct = EFX_DIR_OUT,
227 .def_vals = {0x3F800000, 0x42A00000, 0x3F000000}
229 { .name = "Equalizer",
232 .reqs = {9, 10, 11, 12, 13, 14,
233 15, 16, 17, 18, 19, 20},
234 .direct = EFX_DIR_OUT,
236 .def_vals = {0x00000000, 0x00000000, 0x00000000, 0x00000000,
237 0x00000000, 0x00000000, 0x00000000, 0x00000000,
238 0x00000000, 0x00000000, 0x00000000, 0x00000000}
240 { .name = "Echo Cancellation",
241 .nid = ECHO_CANCELLATION,
243 .reqs = {0, 1, 2, 3},
244 .direct = EFX_DIR_IN,
246 .def_vals = {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
248 { .name = "Voice Focus",
251 .reqs = {6, 7, 8, 9},
252 .direct = EFX_DIR_IN,
254 .def_vals = {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
260 .direct = EFX_DIR_IN,
262 .def_vals = {0x00000000, 0x3F3D70A4}
264 { .name = "Noise Reduction",
265 .nid = NOISE_REDUCTION,
268 .direct = EFX_DIR_IN,
270 .def_vals = {0x3F800000, 0x3F000000}
275 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18},
276 .direct = EFX_DIR_IN,
278 .def_vals = {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
279 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
284 /* Tuning controls */
285 #ifdef ENABLE_TUNING_CONTROLS
288 #define TUNING_CTL_START_NID 0xC0
289 WEDGE_ANGLE = TUNING_CTL_START_NID,
302 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
305 struct ct_tuning_ctl {
306 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
307 hda_nid_t parent_nid;
309 int mid; /*effect module ID*/
310 int req; /*effect module request*/
311 int direct; /* 0:output; 1:input*/
312 unsigned int def_val;/*effect default values*/
315 static const struct ct_tuning_ctl ca0132_tuning_ctls[] = {
316 { .name = "Wedge Angle",
317 .parent_nid = VOICE_FOCUS,
321 .direct = EFX_DIR_IN,
322 .def_val = 0x41F00000
324 { .name = "SVM Level",
325 .parent_nid = MIC_SVM,
329 .direct = EFX_DIR_IN,
330 .def_val = 0x3F3D70A4
332 { .name = "EQ Band0",
333 .parent_nid = EQUALIZER,
334 .nid = EQUALIZER_BAND_0,
337 .direct = EFX_DIR_OUT,
338 .def_val = 0x00000000
340 { .name = "EQ Band1",
341 .parent_nid = EQUALIZER,
342 .nid = EQUALIZER_BAND_1,
345 .direct = EFX_DIR_OUT,
346 .def_val = 0x00000000
348 { .name = "EQ Band2",
349 .parent_nid = EQUALIZER,
350 .nid = EQUALIZER_BAND_2,
353 .direct = EFX_DIR_OUT,
354 .def_val = 0x00000000
356 { .name = "EQ Band3",
357 .parent_nid = EQUALIZER,
358 .nid = EQUALIZER_BAND_3,
361 .direct = EFX_DIR_OUT,
362 .def_val = 0x00000000
364 { .name = "EQ Band4",
365 .parent_nid = EQUALIZER,
366 .nid = EQUALIZER_BAND_4,
369 .direct = EFX_DIR_OUT,
370 .def_val = 0x00000000
372 { .name = "EQ Band5",
373 .parent_nid = EQUALIZER,
374 .nid = EQUALIZER_BAND_5,
377 .direct = EFX_DIR_OUT,
378 .def_val = 0x00000000
380 { .name = "EQ Band6",
381 .parent_nid = EQUALIZER,
382 .nid = EQUALIZER_BAND_6,
385 .direct = EFX_DIR_OUT,
386 .def_val = 0x00000000
388 { .name = "EQ Band7",
389 .parent_nid = EQUALIZER,
390 .nid = EQUALIZER_BAND_7,
393 .direct = EFX_DIR_OUT,
394 .def_val = 0x00000000
396 { .name = "EQ Band8",
397 .parent_nid = EQUALIZER,
398 .nid = EQUALIZER_BAND_8,
401 .direct = EFX_DIR_OUT,
402 .def_val = 0x00000000
404 { .name = "EQ Band9",
405 .parent_nid = EQUALIZER,
406 .nid = EQUALIZER_BAND_9,
409 .direct = EFX_DIR_OUT,
410 .def_val = 0x00000000
415 /* Voice FX Presets */
416 #define VOICEFX_MAX_PARAM_COUNT 9
422 int reqs[VOICEFX_MAX_PARAM_COUNT]; /*effect module request*/
425 struct ct_voicefx_preset {
426 char *name; /*preset name*/
427 unsigned int vals[VOICEFX_MAX_PARAM_COUNT];
430 static const struct ct_voicefx ca0132_voicefx = {
431 .name = "VoiceFX Capture Switch",
434 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18}
437 static const struct ct_voicefx_preset ca0132_voicefx_presets[] = {
439 .vals = { 0x00000000, 0x43C80000, 0x44AF0000,
440 0x44FA0000, 0x3F800000, 0x3F800000,
441 0x3F800000, 0x00000000, 0x00000000 }
443 { .name = "Female2Male",
444 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
445 0x44FA0000, 0x3F19999A, 0x3F866666,
446 0x3F800000, 0x00000000, 0x00000000 }
448 { .name = "Male2Female",
449 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
450 0x450AC000, 0x4017AE14, 0x3F6B851F,
451 0x3F800000, 0x00000000, 0x00000000 }
453 { .name = "ScrappyKid",
454 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
455 0x44FA0000, 0x40400000, 0x3F28F5C3,
456 0x3F800000, 0x00000000, 0x00000000 }
459 .vals = { 0x3F800000, 0x44324000, 0x44BB8000,
460 0x44E10000, 0x3FB33333, 0x3FB9999A,
461 0x3F800000, 0x3E3A2E43, 0x00000000 }
464 .vals = { 0x3F800000, 0x43EA0000, 0x44A52000,
465 0x45098000, 0x3F266666, 0x3FC00000,
466 0x3F800000, 0x00000000, 0x00000000 }
469 .vals = { 0x3F800000, 0x43C70000, 0x44AE6000,
470 0x45193000, 0x3F8E147B, 0x3F75C28F,
471 0x3F800000, 0x00000000, 0x00000000 }
474 .vals = { 0x3F800000, 0x43930000, 0x44BEE000,
475 0x45007000, 0x3F451EB8, 0x3F7851EC,
476 0x3F800000, 0x00000000, 0x00000000 }
478 { .name = "AlienBrute",
479 .vals = { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
480 0x451F6000, 0x3F266666, 0x3FA7D945,
481 0x3F800000, 0x3CF5C28F, 0x00000000 }
484 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
485 0x44FA0000, 0x3FB2718B, 0x3F800000,
486 0xBC07010E, 0x00000000, 0x00000000 }
489 .vals = { 0x3F800000, 0x43C20000, 0x44906000,
490 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
491 0x3F0A3D71, 0x00000000, 0x00000000 }
494 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
495 0x44FA0000, 0x3F800000, 0x3F800000,
496 0x3E4CCCCD, 0x00000000, 0x00000000 }
498 { .name = "DeepVoice",
499 .vals = { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
500 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
501 0x3F800000, 0x00000000, 0x00000000 }
503 { .name = "Munchkin",
504 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
505 0x44FA0000, 0x3F800000, 0x3F1A043C,
506 0x3F800000, 0x00000000, 0x00000000 }
510 /* ca0132 EQ presets, taken from Windows Sound Blaster Z Driver */
512 #define EQ_PRESET_MAX_PARAM_COUNT 11
518 int reqs[EQ_PRESET_MAX_PARAM_COUNT]; /*effect module request*/
521 struct ct_eq_preset {
522 char *name; /*preset name*/
523 unsigned int vals[EQ_PRESET_MAX_PARAM_COUNT];
526 static const struct ct_eq ca0132_alt_eq_enum = {
527 .name = "FX: Equalizer Preset Switch",
528 .nid = EQ_PRESET_ENUM,
530 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
534 static const struct ct_eq_preset ca0132_alt_eq_presets[] = {
536 .vals = { 0x00000000, 0x00000000, 0x00000000,
537 0x00000000, 0x00000000, 0x00000000,
538 0x00000000, 0x00000000, 0x00000000,
539 0x00000000, 0x00000000 }
541 { .name = "Acoustic",
542 .vals = { 0x00000000, 0x00000000, 0x3F8CCCCD,
543 0x40000000, 0x00000000, 0x00000000,
544 0x00000000, 0x00000000, 0x40000000,
545 0x40000000, 0x40000000 }
547 { .name = "Classical",
548 .vals = { 0x00000000, 0x00000000, 0x40C00000,
549 0x40C00000, 0x40466666, 0x00000000,
550 0x00000000, 0x00000000, 0x00000000,
551 0x40466666, 0x40466666 }
554 .vals = { 0x00000000, 0xBF99999A, 0x00000000,
555 0x3FA66666, 0x3FA66666, 0x3F8CCCCD,
556 0x00000000, 0x00000000, 0x40000000,
557 0x40466666, 0x40800000 }
560 .vals = { 0x00000000, 0xBF99999A, 0x40000000,
561 0x40466666, 0x40866666, 0xBF99999A,
562 0xBF99999A, 0x00000000, 0x00000000,
563 0x40800000, 0x40800000 }
566 .vals = { 0x00000000, 0x00000000, 0x00000000,
567 0x3F8CCCCD, 0x40800000, 0x40800000,
568 0x40800000, 0x00000000, 0x3F8CCCCD,
569 0x40466666, 0x40466666 }
572 .vals = { 0x00000000, 0x00000000, 0x40000000,
573 0x40000000, 0x00000000, 0x00000000,
574 0x00000000, 0x3F8CCCCD, 0x40000000,
575 0x40000000, 0x40000000 }
578 .vals = { 0x00000000, 0xBFCCCCCD, 0x00000000,
579 0x40000000, 0x40000000, 0x00000000,
580 0xBF99999A, 0xBF99999A, 0x00000000,
581 0x40466666, 0x40C00000 }
584 .vals = { 0x00000000, 0xBF99999A, 0xBF99999A,
585 0x3F8CCCCD, 0x40000000, 0xBF99999A,
586 0xBF99999A, 0x00000000, 0x00000000,
587 0x40800000, 0x40800000 }
590 .vals = { 0x00000000, 0xC0000000, 0xBF99999A,
591 0xBF99999A, 0x00000000, 0x40466666,
592 0x40800000, 0x40466666, 0x00000000,
593 0x00000000, 0x3F8CCCCD }
598 * DSP reqs for handling full-range speakers/bass redirection. If a speaker is
599 * set as not being full range, and bass redirection is enabled, all
600 * frequencies below the crossover frequency are redirected to the LFE
601 * channel. If the surround configuration has no LFE channel, this can't be
602 * enabled. X-Bass must be disabled when using these.
604 enum speaker_range_reqs {
605 SPEAKER_BASS_REDIRECT = 0x15,
606 SPEAKER_BASS_REDIRECT_XOVER_FREQ = 0x16,
607 /* Between 0x16-0x1a are the X-Bass reqs. */
608 SPEAKER_FULL_RANGE_FRONT_L_R = 0x1a,
609 SPEAKER_FULL_RANGE_CENTER_LFE = 0x1b,
610 SPEAKER_FULL_RANGE_REAR_L_R = 0x1c,
611 SPEAKER_FULL_RANGE_SURROUND_L_R = 0x1d,
612 SPEAKER_BASS_REDIRECT_SUB_GAIN = 0x1e,
616 * Definitions for the DSP req's to handle speaker tuning. These all belong to
617 * module ID 0x96, the output effects module.
619 enum speaker_tuning_reqs {
621 * Currently, this value is always set to 0.0f. However, on Windows,
622 * when selecting certain headphone profiles on the new Sound Blaster
623 * connect software, the QUERY_SPEAKER_EQ_ADDRESS req on mid 0x80 is
624 * sent. This gets the speaker EQ address area, which is then used to
625 * send over (presumably) an equalizer profile for the specific
626 * headphone setup. It is sent using the same method the DSP
627 * firmware is uploaded with, which I believe is why the 'ctspeq.bin'
628 * file exists in linux firmware tree but goes unused. It would also
629 * explain why the QUERY_SPEAKER_EQ_ADDRESS req is defined but unused.
630 * Once this profile is sent over, SPEAKER_TUNING_USE_SPEAKER_EQ is
633 SPEAKER_TUNING_USE_SPEAKER_EQ = 0x1f,
634 SPEAKER_TUNING_ENABLE_CENTER_EQ = 0x20,
635 SPEAKER_TUNING_FRONT_LEFT_VOL_LEVEL = 0x21,
636 SPEAKER_TUNING_FRONT_RIGHT_VOL_LEVEL = 0x22,
637 SPEAKER_TUNING_CENTER_VOL_LEVEL = 0x23,
638 SPEAKER_TUNING_LFE_VOL_LEVEL = 0x24,
639 SPEAKER_TUNING_REAR_LEFT_VOL_LEVEL = 0x25,
640 SPEAKER_TUNING_REAR_RIGHT_VOL_LEVEL = 0x26,
641 SPEAKER_TUNING_SURROUND_LEFT_VOL_LEVEL = 0x27,
642 SPEAKER_TUNING_SURROUND_RIGHT_VOL_LEVEL = 0x28,
644 * Inversion is used when setting headphone virtualization to line
645 * out. Not sure why this is, but it's the only place it's ever used.
647 SPEAKER_TUNING_FRONT_LEFT_INVERT = 0x29,
648 SPEAKER_TUNING_FRONT_RIGHT_INVERT = 0x2a,
649 SPEAKER_TUNING_CENTER_INVERT = 0x2b,
650 SPEAKER_TUNING_LFE_INVERT = 0x2c,
651 SPEAKER_TUNING_REAR_LEFT_INVERT = 0x2d,
652 SPEAKER_TUNING_REAR_RIGHT_INVERT = 0x2e,
653 SPEAKER_TUNING_SURROUND_LEFT_INVERT = 0x2f,
654 SPEAKER_TUNING_SURROUND_RIGHT_INVERT = 0x30,
655 /* Delay is used when setting surround speaker distance in Windows. */
656 SPEAKER_TUNING_FRONT_LEFT_DELAY = 0x31,
657 SPEAKER_TUNING_FRONT_RIGHT_DELAY = 0x32,
658 SPEAKER_TUNING_CENTER_DELAY = 0x33,
659 SPEAKER_TUNING_LFE_DELAY = 0x34,
660 SPEAKER_TUNING_REAR_LEFT_DELAY = 0x35,
661 SPEAKER_TUNING_REAR_RIGHT_DELAY = 0x36,
662 SPEAKER_TUNING_SURROUND_LEFT_DELAY = 0x37,
663 SPEAKER_TUNING_SURROUND_RIGHT_DELAY = 0x38,
664 /* Of these two, only mute seems to ever be used. */
665 SPEAKER_TUNING_MAIN_VOLUME = 0x39,
666 SPEAKER_TUNING_MUTE = 0x3a,
669 /* Surround output channel count configuration structures. */
670 #define SPEAKER_CHANNEL_CFG_COUNT 5
672 SPEAKER_CHANNELS_2_0,
673 SPEAKER_CHANNELS_2_1,
674 SPEAKER_CHANNELS_4_0,
675 SPEAKER_CHANNELS_4_1,
676 SPEAKER_CHANNELS_5_1,
679 struct ca0132_alt_speaker_channel_cfg {
684 static const struct ca0132_alt_speaker_channel_cfg speaker_channel_cfgs[] = {
703 * DSP volume setting structs. Req 1 is left volume, req 2 is right volume,
704 * and I don't know what the third req is, but it's always zero. I assume it's
705 * some sort of update or set command to tell the DSP there's new volume info.
707 #define DSP_VOL_OUT 0
710 struct ct_dsp_volume_ctl {
712 int mid; /* module ID*/
713 unsigned int reqs[3]; /* scp req ID */
716 static const struct ct_dsp_volume_ctl ca0132_alt_vol_ctls[] = {
727 /* Values for ca0113_mmio_command_set for selecting output. */
728 #define AE_CA0113_OUT_SET_COMMANDS 6
729 struct ae_ca0113_output_set {
730 unsigned int group[AE_CA0113_OUT_SET_COMMANDS];
731 unsigned int target[AE_CA0113_OUT_SET_COMMANDS];
732 unsigned int vals[NUM_OF_OUTPUTS][AE_CA0113_OUT_SET_COMMANDS];
735 static const struct ae_ca0113_output_set ae5_ca0113_output_presets = {
736 .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
737 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
739 .vals = { { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f },
741 { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 } },
744 static const struct ae_ca0113_output_set ae7_ca0113_output_presets = {
745 .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
746 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
748 .vals = { { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f },
750 { 0x3f, 0x3f, 0x00, 0x00, 0x02, 0x00 } },
753 /* ae5 ca0113 command sequences to set headphone gain levels. */
754 #define AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS 4
755 struct ae5_headphone_gain_set {
757 unsigned int vals[AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS];
760 static const struct ae5_headphone_gain_set ae5_headphone_gain_presets[] = {
761 { .name = "Low (16-31",
762 .vals = { 0xff, 0x2c, 0xf5, 0x32 }
764 { .name = "Medium (32-149",
765 .vals = { 0x38, 0xa8, 0x3e, 0x4c }
767 { .name = "High (150-600",
768 .vals = { 0xff, 0xff, 0xff, 0x7f }
772 struct ae5_filter_set {
777 static const struct ae5_filter_set ae5_filter_presets[] = {
778 { .name = "Slow Roll Off",
781 { .name = "Minimum Phase",
784 { .name = "Fast Roll Off",
790 * Data structures for storing audio router remapping data. These are used to
791 * remap a currently active streams ports.
793 struct chipio_stream_remap_data {
794 unsigned int stream_id;
797 unsigned int offset[16];
798 unsigned int value[16];
801 static const struct chipio_stream_remap_data stream_remap_data[] = {
804 .offset = { 0x00, 0x04, 0x08, 0x0c },
805 .value = { 0x0001f8c0, 0x0001f9c1, 0x0001fac6, 0x0001fbc7 },
809 .offset = { 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c,
810 0x20, 0x24, 0x28, 0x2c },
811 .value = { 0x0001e0c0, 0x0001e1c1, 0x0001e4c2, 0x0001e5c3,
812 0x0001e2c4, 0x0001e3c5, 0x0001e8c6, 0x0001e9c7,
813 0x0001ecc8, 0x0001edc9, 0x0001eaca, 0x0001ebcb },
817 .offset = { 0x08, 0x0c, 0x10, 0x14, 0x20, 0x24, 0x28, 0x2c },
818 .value = { 0x000140c2, 0x000141c3, 0x000150c4, 0x000151c5,
819 0x000142c8, 0x000143c9, 0x000152ca, 0x000153cb },
823 enum hda_cmd_vendor_io {
825 VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000,
826 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100,
828 VENDOR_DSPIO_STATUS = 0xF01,
829 VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702,
830 VENDOR_DSPIO_SCP_READ_DATA = 0xF02,
831 VENDOR_DSPIO_DSP_INIT = 0x703,
832 VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704,
833 VENDOR_DSPIO_SCP_READ_COUNT = 0xF04,
835 /* for ChipIO node */
836 VENDOR_CHIPIO_ADDRESS_LOW = 0x000,
837 VENDOR_CHIPIO_ADDRESS_HIGH = 0x100,
838 VENDOR_CHIPIO_STREAM_FORMAT = 0x200,
839 VENDOR_CHIPIO_DATA_LOW = 0x300,
840 VENDOR_CHIPIO_DATA_HIGH = 0x400,
842 VENDOR_CHIPIO_8051_WRITE_DIRECT = 0x500,
843 VENDOR_CHIPIO_8051_READ_DIRECT = 0xD00,
845 VENDOR_CHIPIO_GET_PARAMETER = 0xF00,
846 VENDOR_CHIPIO_STATUS = 0xF01,
847 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
848 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
850 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
851 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
852 VENDOR_CHIPIO_8051_PMEM_READ = 0xF08,
853 VENDOR_CHIPIO_8051_IRAM_WRITE = 0x709,
854 VENDOR_CHIPIO_8051_IRAM_READ = 0xF09,
856 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
857 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
859 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
860 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
861 VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D,
862 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
863 VENDOR_CHIPIO_FLAG_SET = 0x70F,
864 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
865 VENDOR_CHIPIO_PARAM_SET = 0x710,
866 VENDOR_CHIPIO_PARAM_GET = 0xF10,
868 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
869 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
870 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
871 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
873 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
874 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
875 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
876 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
878 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
879 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
880 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
881 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
882 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
883 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
885 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
891 enum control_flag_id {
892 /* Connection manager stream setup is bypassed/enabled */
893 CONTROL_FLAG_C_MGR = 0,
894 /* DSP DMA is bypassed/enabled */
895 CONTROL_FLAG_DMA = 1,
896 /* 8051 'idle' mode is disabled/enabled */
897 CONTROL_FLAG_IDLE_ENABLE = 2,
898 /* Tracker for the SPDIF-in path is bypassed/enabled */
899 CONTROL_FLAG_TRACKER = 3,
900 /* DigitalOut to Spdif2Out connection is disabled/enabled */
901 CONTROL_FLAG_SPDIF2OUT = 4,
902 /* Digital Microphone is disabled/enabled */
903 CONTROL_FLAG_DMIC = 5,
904 /* ADC_B rate is 48 kHz/96 kHz */
905 CONTROL_FLAG_ADC_B_96KHZ = 6,
906 /* ADC_C rate is 48 kHz/96 kHz */
907 CONTROL_FLAG_ADC_C_96KHZ = 7,
908 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
909 CONTROL_FLAG_DAC_96KHZ = 8,
910 /* DSP rate is 48 kHz/96 kHz */
911 CONTROL_FLAG_DSP_96KHZ = 9,
912 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
913 CONTROL_FLAG_SRC_CLOCK_196MHZ = 10,
914 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
915 CONTROL_FLAG_SRC_RATE_96KHZ = 11,
916 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
917 CONTROL_FLAG_DECODE_LOOP = 12,
918 /* De-emphasis filter on DAC-1 disabled/enabled */
919 CONTROL_FLAG_DAC1_DEEMPHASIS = 13,
920 /* De-emphasis filter on DAC-2 disabled/enabled */
921 CONTROL_FLAG_DAC2_DEEMPHASIS = 14,
922 /* De-emphasis filter on DAC-3 disabled/enabled */
923 CONTROL_FLAG_DAC3_DEEMPHASIS = 15,
924 /* High-pass filter on ADC_B disabled/enabled */
925 CONTROL_FLAG_ADC_B_HIGH_PASS = 16,
926 /* High-pass filter on ADC_C disabled/enabled */
927 CONTROL_FLAG_ADC_C_HIGH_PASS = 17,
928 /* Common mode on Port_A disabled/enabled */
929 CONTROL_FLAG_PORT_A_COMMON_MODE = 18,
930 /* Common mode on Port_D disabled/enabled */
931 CONTROL_FLAG_PORT_D_COMMON_MODE = 19,
932 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
933 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
934 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
935 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
936 /* ASI rate is 48kHz/96kHz */
937 CONTROL_FLAG_ASI_96KHZ = 22,
938 /* DAC power settings able to control attached ports no/yes */
939 CONTROL_FLAG_DACS_CONTROL_PORTS = 23,
940 /* Clock Stop OK reporting is disabled/enabled */
941 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24,
942 /* Number of control flags */
943 CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1)
947 * Control parameter IDs
949 enum control_param_id {
950 /* 0: None, 1: Mic1In*/
951 CONTROL_PARAM_VIP_SOURCE = 1,
952 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
953 CONTROL_PARAM_SPDIF1_SOURCE = 2,
954 /* Port A output stage gain setting to use when 16 Ohm output
955 * impedance is selected*/
956 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
957 /* Port D output stage gain setting to use when 16 Ohm output
958 * impedance is selected*/
959 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
962 * This control param name was found in the 8051 memory, and makes
963 * sense given the fact the AE-5 uses it and has the ASI flag set.
965 CONTROL_PARAM_ASI = 23,
969 /* Select stream with the given ID */
970 CONTROL_PARAM_STREAM_ID = 24,
971 /* Source connection point for the selected stream */
972 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25,
973 /* Destination connection point for the selected stream */
974 CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26,
975 /* Number of audio channels in the selected stream */
976 CONTROL_PARAM_STREAMS_CHANNELS = 27,
977 /*Enable control for the selected stream */
978 CONTROL_PARAM_STREAM_CONTROL = 28,
980 /* Connection Point Control */
982 /* Select connection point with the given ID */
983 CONTROL_PARAM_CONN_POINT_ID = 29,
984 /* Connection point sample rate */
985 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30,
989 /* Select HDA node with the given ID */
990 CONTROL_PARAM_NODE_ID = 31
994 * Dsp Io Status codes
996 enum hda_vendor_status_dspio {
998 VENDOR_STATUS_DSPIO_OK = 0x00,
999 /* Busy, unable to accept new command, the host must retry */
1000 VENDOR_STATUS_DSPIO_BUSY = 0x01,
1001 /* SCP command queue is full */
1002 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02,
1003 /* SCP response queue is empty */
1004 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03
1008 * Chip Io Status codes
1010 enum hda_vendor_status_chipio {
1012 VENDOR_STATUS_CHIPIO_OK = 0x00,
1013 /* Busy, unable to accept new command, the host must retry */
1014 VENDOR_STATUS_CHIPIO_BUSY = 0x01
1018 * CA0132 sample rate
1020 enum ca0132_sample_rate {
1040 SR_RATE_UNKNOWN = 0x1F
1043 enum dsp_download_state {
1044 DSP_DOWNLOAD_FAILED = -1,
1045 DSP_DOWNLOAD_INIT = 0,
1046 DSP_DOWNLOADING = 1,
1050 /* retrieve parameters from hda format */
1051 #define get_hdafmt_chs(fmt) (fmt & 0xf)
1052 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
1053 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
1054 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
1060 struct ca0132_spec {
1061 const struct snd_kcontrol_new *mixers[5];
1062 unsigned int num_mixers;
1063 const struct hda_verb *base_init_verbs;
1064 const struct hda_verb *base_exit_verbs;
1065 const struct hda_verb *chip_init_verbs;
1066 const struct hda_verb *desktop_init_verbs;
1067 struct hda_verb *spec_init_verbs;
1068 struct auto_pin_cfg autocfg;
1070 /* Nodes configurations */
1071 struct hda_multi_out multiout;
1072 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
1073 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
1074 unsigned int num_outputs;
1075 hda_nid_t input_pins[AUTO_PIN_LAST];
1076 hda_nid_t adcs[AUTO_PIN_LAST];
1079 unsigned int num_inputs;
1080 hda_nid_t shared_mic_nid;
1081 hda_nid_t shared_out_nid;
1082 hda_nid_t unsol_tag_hp;
1083 hda_nid_t unsol_tag_front_hp; /* for desktop ca0132 codecs */
1084 hda_nid_t unsol_tag_amic1;
1087 struct mutex chipio_mutex; /* chip access mutex */
1090 /* DSP download related */
1091 enum dsp_download_state dsp_state;
1092 unsigned int dsp_stream_id;
1093 unsigned int wait_scp;
1094 unsigned int wait_scp_header;
1095 unsigned int wait_num_data;
1096 unsigned int scp_resp_header;
1097 unsigned int scp_resp_data[4];
1098 unsigned int scp_resp_count;
1099 bool startup_check_entered;
1102 /* mixer and effects related */
1103 unsigned char dmic_ctl;
1106 long vnode_lvol[VNODES_COUNT];
1107 long vnode_rvol[VNODES_COUNT];
1108 long vnode_lswitch[VNODES_COUNT];
1109 long vnode_rswitch[VNODES_COUNT];
1110 long effects_switch[EFFECTS_COUNT];
1113 /* ca0132_alt control related values */
1114 unsigned char in_enum_val;
1115 unsigned char out_enum_val;
1116 unsigned char channel_cfg_val;
1117 unsigned char speaker_range_val[2];
1118 unsigned char mic_boost_enum_val;
1119 unsigned char smart_volume_setting;
1120 unsigned char bass_redirection_val;
1121 long bass_redirect_xover_freq;
1122 long fx_ctl_val[EFFECT_LEVEL_SLIDERS];
1123 long xbass_xover_freq;
1125 unsigned int tlv[4];
1126 struct hda_vmaster_mute_hook vmaster_mute;
1127 /* AE-5 Control values */
1128 unsigned char ae5_headphone_gain_val;
1129 unsigned char ae5_filter_val;
1130 /* ZxR Control Values */
1131 unsigned char zxr_gain_set;
1133 struct hda_codec *codec;
1134 struct delayed_work unsol_hp_work;
1137 #ifdef ENABLE_TUNING_CONTROLS
1138 long cur_ctl_vals[TUNING_CTLS_COUNT];
1141 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
1142 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
1146 void __iomem *mem_base;
1149 * Whether or not to use the alt functions like alt_select_out,
1150 * alt_select_in, etc. Only used on desktop codecs for now, because of
1151 * surround sound support.
1153 bool use_alt_functions;
1156 * Whether or not to use alt controls: volume effect sliders, EQ
1157 * presets, smart volume presets, and new control names with FX prefix.
1158 * Renames PlayEnhancement and CrystalVoice too.
1160 bool use_alt_controls;
1164 * CA0132 quirks table
1169 QUIRK_ALIENWARE_M17XR4,
1180 #define ca0132_quirk(spec) ((spec)->quirk)
1181 #define ca0132_use_pci_mmio(spec) ((spec)->use_pci_mmio)
1182 #define ca0132_use_alt_functions(spec) ((spec)->use_alt_functions)
1183 #define ca0132_use_alt_controls(spec) ((spec)->use_alt_controls)
1185 #define ca0132_quirk(spec) ({ (void)(spec); QUIRK_NONE; })
1186 #define ca0132_use_alt_functions(spec) ({ (void)(spec); false; })
1187 #define ca0132_use_pci_mmio(spec) ({ (void)(spec); false; })
1188 #define ca0132_use_alt_controls(spec) ({ (void)(spec); false; })
1191 static const struct hda_pintbl alienware_pincfgs[] = {
1192 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1193 { 0x0c, 0x411111f0 }, /* N/A */
1194 { 0x0d, 0x411111f0 }, /* N/A */
1195 { 0x0e, 0x411111f0 }, /* N/A */
1196 { 0x0f, 0x0321101f }, /* HP */
1197 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1198 { 0x11, 0x03a11021 }, /* Mic */
1199 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1200 { 0x13, 0x411111f0 }, /* N/A */
1201 { 0x18, 0x411111f0 }, /* N/A */
1205 /* Sound Blaster Z pin configs taken from Windows Driver */
1206 static const struct hda_pintbl sbz_pincfgs[] = {
1207 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1208 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1209 { 0x0d, 0x014510f0 }, /* Digital Out */
1210 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1211 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1212 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1213 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1214 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1215 { 0x13, 0x908700f0 }, /* What U Hear In*/
1216 { 0x18, 0x50d000f0 }, /* N/A */
1220 /* Sound Blaster ZxR pin configs taken from Windows Driver */
1221 static const struct hda_pintbl zxr_pincfgs[] = {
1222 { 0x0b, 0x01047110 }, /* Port G -- Lineout FRONT L/R */
1223 { 0x0c, 0x414510f0 }, /* SPDIF Out 1 - Disabled*/
1224 { 0x0d, 0x014510f0 }, /* Digital Out */
1225 { 0x0e, 0x41c520f0 }, /* SPDIF In - Disabled*/
1226 { 0x0f, 0x0122711f }, /* Port A -- BackPanel HP */
1227 { 0x10, 0x01017111 }, /* Port D -- Center/LFE */
1228 { 0x11, 0x01017114 }, /* Port B -- LineMicIn2 / Rear L/R */
1229 { 0x12, 0x01a271f0 }, /* Port C -- LineIn1 */
1230 { 0x13, 0x908700f0 }, /* What U Hear In*/
1231 { 0x18, 0x50d000f0 }, /* N/A */
1235 /* Recon3D pin configs taken from Windows Driver */
1236 static const struct hda_pintbl r3d_pincfgs[] = {
1237 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1238 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1239 { 0x0d, 0x014510f0 }, /* Digital Out */
1240 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1241 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1242 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1243 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1244 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1245 { 0x13, 0x908700f0 }, /* What U Hear In*/
1246 { 0x18, 0x50d000f0 }, /* N/A */
1250 /* Sound Blaster AE-5 pin configs taken from Windows Driver */
1251 static const struct hda_pintbl ae5_pincfgs[] = {
1252 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1253 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1254 { 0x0d, 0x014510f0 }, /* Digital Out */
1255 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1256 { 0x0f, 0x01017114 }, /* Port A -- Rear L/R. */
1257 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1258 { 0x11, 0x012170ff }, /* Port B -- LineMicIn2 / Rear Headphone */
1259 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1260 { 0x13, 0x908700f0 }, /* What U Hear In*/
1261 { 0x18, 0x50d000f0 }, /* N/A */
1265 /* Recon3D integrated pin configs taken from Windows Driver */
1266 static const struct hda_pintbl r3di_pincfgs[] = {
1267 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1268 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1269 { 0x0d, 0x014510f0 }, /* Digital Out */
1270 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1271 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1272 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1273 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1274 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1275 { 0x13, 0x908700f0 }, /* What U Hear In*/
1276 { 0x18, 0x500000f0 }, /* N/A */
1280 static const struct hda_pintbl ae7_pincfgs[] = {
1281 { 0x0b, 0x01017010 },
1282 { 0x0c, 0x014510f0 },
1283 { 0x0d, 0x414510f0 },
1284 { 0x0e, 0x01c520f0 },
1285 { 0x0f, 0x01017114 },
1286 { 0x10, 0x01017011 },
1287 { 0x11, 0x018170ff },
1288 { 0x12, 0x01a170f0 },
1289 { 0x13, 0x908700f0 },
1290 { 0x18, 0x500000f0 },
1294 static const struct snd_pci_quirk ca0132_quirks[] = {
1295 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4),
1296 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE),
1297 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE),
1298 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE),
1299 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ),
1300 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ),
1301 SND_PCI_QUIRK(0x1102, 0x0027, "Sound Blaster Z", QUIRK_SBZ),
1302 SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ),
1303 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
1304 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
1305 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
1306 SND_PCI_QUIRK(0x3842, 0x1038, "EVGA X99 Classified", QUIRK_R3DI),
1307 SND_PCI_QUIRK(0x3842, 0x104b, "EVGA X299 Dark", QUIRK_R3DI),
1308 SND_PCI_QUIRK(0x3842, 0x1055, "EVGA Z390 DARK", QUIRK_R3DI),
1309 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1310 SND_PCI_QUIRK(0x1102, 0x0018, "Recon3D", QUIRK_R3D),
1311 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5),
1312 SND_PCI_QUIRK(0x1102, 0x0191, "Sound Blaster AE-5 Plus", QUIRK_AE5),
1313 SND_PCI_QUIRK(0x1102, 0x0081, "Sound Blaster AE-7", QUIRK_AE7),
1317 /* Output selection quirk info structures. */
1318 #define MAX_QUIRK_MMIO_GPIO_SET_VALS 3
1319 #define MAX_QUIRK_SCP_SET_VALS 2
1320 struct ca0132_alt_out_set_info {
1321 unsigned int dac2port; /* ParamID 0x0d value. */
1327 unsigned int mmio_gpio_count;
1328 char mmio_gpio_pin[MAX_QUIRK_MMIO_GPIO_SET_VALS];
1329 char mmio_gpio_set[MAX_QUIRK_MMIO_GPIO_SET_VALS];
1331 unsigned int scp_cmds_count;
1332 unsigned int scp_cmd_mid[MAX_QUIRK_SCP_SET_VALS];
1333 unsigned int scp_cmd_req[MAX_QUIRK_SCP_SET_VALS];
1334 unsigned int scp_cmd_val[MAX_QUIRK_SCP_SET_VALS];
1336 bool has_chipio_write;
1337 unsigned int chipio_write_addr;
1338 unsigned int chipio_write_data;
1341 struct ca0132_alt_out_set_quirk_data {
1344 bool has_headphone_gain;
1347 struct ca0132_alt_out_set_info out_set_info[NUM_OF_OUTPUTS];
1350 static const struct ca0132_alt_out_set_quirk_data quirk_out_set_data[] = {
1351 { .quirk_id = QUIRK_R3DI,
1352 .has_headphone_gain = false,
1353 .is_ae_series = false,
1357 .has_hda_gpio = true,
1360 .mmio_gpio_count = 0,
1361 .scp_cmds_count = 0,
1362 .has_chipio_write = false,
1366 .has_hda_gpio = true,
1369 .mmio_gpio_count = 0,
1370 .scp_cmds_count = 0,
1371 .has_chipio_write = false,
1374 { .quirk_id = QUIRK_R3D,
1375 .has_headphone_gain = false,
1376 .is_ae_series = false,
1380 .has_hda_gpio = false,
1381 .mmio_gpio_count = 1,
1382 .mmio_gpio_pin = { 1 },
1383 .mmio_gpio_set = { 1 },
1384 .scp_cmds_count = 0,
1385 .has_chipio_write = false,
1389 .has_hda_gpio = false,
1390 .mmio_gpio_count = 1,
1391 .mmio_gpio_pin = { 1 },
1392 .mmio_gpio_set = { 0 },
1393 .scp_cmds_count = 0,
1394 .has_chipio_write = false,
1397 { .quirk_id = QUIRK_SBZ,
1398 .has_headphone_gain = false,
1399 .is_ae_series = false,
1403 .has_hda_gpio = false,
1404 .mmio_gpio_count = 3,
1405 .mmio_gpio_pin = { 7, 4, 1 },
1406 .mmio_gpio_set = { 0, 1, 1 },
1407 .scp_cmds_count = 0,
1408 .has_chipio_write = false, },
1411 .has_hda_gpio = false,
1412 .mmio_gpio_count = 3,
1413 .mmio_gpio_pin = { 7, 4, 1 },
1414 .mmio_gpio_set = { 1, 1, 0 },
1415 .scp_cmds_count = 0,
1416 .has_chipio_write = false,
1419 { .quirk_id = QUIRK_ZXR,
1420 .has_headphone_gain = true,
1421 .is_ae_series = false,
1425 .has_hda_gpio = false,
1426 .mmio_gpio_count = 3,
1427 .mmio_gpio_pin = { 2, 3, 5 },
1428 .mmio_gpio_set = { 1, 1, 0 },
1429 .scp_cmds_count = 0,
1430 .has_chipio_write = false,
1434 .has_hda_gpio = false,
1435 .mmio_gpio_count = 3,
1436 .mmio_gpio_pin = { 2, 3, 5 },
1437 .mmio_gpio_set = { 0, 1, 1 },
1438 .scp_cmds_count = 0,
1439 .has_chipio_write = false,
1442 { .quirk_id = QUIRK_AE5,
1443 .has_headphone_gain = true,
1444 .is_ae_series = true,
1448 .has_hda_gpio = false,
1449 .mmio_gpio_count = 0,
1450 .scp_cmds_count = 2,
1451 .scp_cmd_mid = { 0x96, 0x96 },
1452 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1453 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1454 .scp_cmd_val = { FLOAT_ZERO, FLOAT_ZERO },
1455 .has_chipio_write = true,
1456 .chipio_write_addr = 0x0018b03c,
1457 .chipio_write_data = 0x00000012
1461 .has_hda_gpio = false,
1462 .mmio_gpio_count = 0,
1463 .scp_cmds_count = 2,
1464 .scp_cmd_mid = { 0x96, 0x96 },
1465 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1466 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1467 .scp_cmd_val = { FLOAT_ONE, FLOAT_ONE },
1468 .has_chipio_write = true,
1469 .chipio_write_addr = 0x0018b03c,
1470 .chipio_write_data = 0x00000012
1473 { .quirk_id = QUIRK_AE7,
1474 .has_headphone_gain = true,
1475 .is_ae_series = true,
1479 .has_hda_gpio = false,
1480 .mmio_gpio_count = 1,
1481 .mmio_gpio_pin = { 0 },
1482 .mmio_gpio_set = { 1 },
1483 .scp_cmds_count = 2,
1484 .scp_cmd_mid = { 0x96, 0x96 },
1485 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1486 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1487 .scp_cmd_val = { FLOAT_ZERO, FLOAT_ZERO },
1488 .has_chipio_write = true,
1489 .chipio_write_addr = 0x0018b03c,
1490 .chipio_write_data = 0x00000000
1494 .has_hda_gpio = false,
1495 .mmio_gpio_count = 1,
1496 .mmio_gpio_pin = { 0 },
1497 .mmio_gpio_set = { 1 },
1498 .scp_cmds_count = 2,
1499 .scp_cmd_mid = { 0x96, 0x96 },
1500 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1501 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1502 .scp_cmd_val = { FLOAT_ONE, FLOAT_ONE },
1503 .has_chipio_write = true,
1504 .chipio_write_addr = 0x0018b03c,
1505 .chipio_write_data = 0x00000010
1511 * CA0132 codec access
1513 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1514 unsigned int verb, unsigned int parm, unsigned int *res)
1516 unsigned int response;
1517 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1520 return ((response == -1) ? -1 : 0);
1523 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1524 unsigned short converter_format, unsigned int *res)
1526 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1527 converter_format & 0xffff, res);
1530 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1531 hda_nid_t nid, unsigned char stream,
1532 unsigned char channel, unsigned int *res)
1534 unsigned char converter_stream_channel = 0;
1536 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1537 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1538 converter_stream_channel, res);
1541 /* Chip access helper function */
1542 static int chipio_send(struct hda_codec *codec,
1547 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1549 /* send bits of data specified by reg */
1551 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1553 if (res == VENDOR_STATUS_CHIPIO_OK)
1556 } while (time_before(jiffies, timeout));
1562 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1564 static int chipio_write_address(struct hda_codec *codec,
1565 unsigned int chip_addx)
1567 struct ca0132_spec *spec = codec->spec;
1570 if (spec->curr_chip_addx == chip_addx)
1573 /* send low 16 bits of the address */
1574 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1575 chip_addx & 0xffff);
1578 /* send high 16 bits of the address */
1579 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1583 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1589 * Write data through the vendor widget -- NOT protected by the Mutex!
1591 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1593 struct ca0132_spec *spec = codec->spec;
1596 /* send low 16 bits of the data */
1597 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1600 /* send high 16 bits of the data */
1601 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1605 /*If no error encountered, automatically increment the address
1606 as per chip behaviour*/
1607 spec->curr_chip_addx = (res != -EIO) ?
1608 (spec->curr_chip_addx + 4) : ~0U;
1613 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1615 static int chipio_write_data_multiple(struct hda_codec *codec,
1622 codec_dbg(codec, "chipio_write_data null ptr\n");
1626 while ((count-- != 0) && (status == 0))
1627 status = chipio_write_data(codec, *data++);
1634 * Read data through the vendor widget -- NOT protected by the Mutex!
1636 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1638 struct ca0132_spec *spec = codec->spec;
1642 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1646 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1651 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1652 VENDOR_CHIPIO_HIC_READ_DATA,
1656 /*If no error encountered, automatically increment the address
1657 as per chip behaviour*/
1658 spec->curr_chip_addx = (res != -EIO) ?
1659 (spec->curr_chip_addx + 4) : ~0U;
1664 * Write given value to the given address through the chip I/O widget.
1665 * protected by the Mutex
1667 static int chipio_write(struct hda_codec *codec,
1668 unsigned int chip_addx, const unsigned int data)
1670 struct ca0132_spec *spec = codec->spec;
1673 mutex_lock(&spec->chipio_mutex);
1675 /* write the address, and if successful proceed to write data */
1676 err = chipio_write_address(codec, chip_addx);
1680 err = chipio_write_data(codec, data);
1685 mutex_unlock(&spec->chipio_mutex);
1690 * Write given value to the given address through the chip I/O widget.
1691 * not protected by the Mutex
1693 static int chipio_write_no_mutex(struct hda_codec *codec,
1694 unsigned int chip_addx, const unsigned int data)
1699 /* write the address, and if successful proceed to write data */
1700 err = chipio_write_address(codec, chip_addx);
1704 err = chipio_write_data(codec, data);
1713 * Write multiple values to the given address through the chip I/O widget.
1714 * protected by the Mutex
1716 static int chipio_write_multiple(struct hda_codec *codec,
1721 struct ca0132_spec *spec = codec->spec;
1724 mutex_lock(&spec->chipio_mutex);
1725 status = chipio_write_address(codec, chip_addx);
1729 status = chipio_write_data_multiple(codec, data, count);
1731 mutex_unlock(&spec->chipio_mutex);
1737 * Read the given address through the chip I/O widget
1738 * protected by the Mutex
1740 static int chipio_read(struct hda_codec *codec,
1741 unsigned int chip_addx, unsigned int *data)
1743 struct ca0132_spec *spec = codec->spec;
1746 mutex_lock(&spec->chipio_mutex);
1748 /* write the address, and if successful proceed to write data */
1749 err = chipio_write_address(codec, chip_addx);
1753 err = chipio_read_data(codec, data);
1758 mutex_unlock(&spec->chipio_mutex);
1763 * Set chip control flags through the chip I/O widget.
1765 static void chipio_set_control_flag(struct hda_codec *codec,
1766 enum control_flag_id flag_id,
1770 unsigned int flag_bit;
1772 flag_bit = (flag_state ? 1 : 0);
1773 val = (flag_bit << 7) | (flag_id);
1774 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1775 VENDOR_CHIPIO_FLAG_SET, val);
1779 * Set chip parameters through the chip I/O widget.
1781 static void chipio_set_control_param(struct hda_codec *codec,
1782 enum control_param_id param_id, int param_val)
1784 struct ca0132_spec *spec = codec->spec;
1787 if ((param_id < 32) && (param_val < 8)) {
1788 val = (param_val << 5) | (param_id);
1789 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1790 VENDOR_CHIPIO_PARAM_SET, val);
1792 mutex_lock(&spec->chipio_mutex);
1793 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1794 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1795 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1797 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1798 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1801 mutex_unlock(&spec->chipio_mutex);
1806 * Set chip parameters through the chip I/O widget. NO MUTEX.
1808 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1809 enum control_param_id param_id, int param_val)
1813 if ((param_id < 32) && (param_val < 8)) {
1814 val = (param_val << 5) | (param_id);
1815 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1816 VENDOR_CHIPIO_PARAM_SET, val);
1818 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1819 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1820 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1822 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1823 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1829 * Connect stream to a source point, and then connect
1830 * that source point to a destination point.
1832 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1833 int streamid, int source_point, int dest_point)
1835 chipio_set_control_param_no_mutex(codec,
1836 CONTROL_PARAM_STREAM_ID, streamid);
1837 chipio_set_control_param_no_mutex(codec,
1838 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1839 chipio_set_control_param_no_mutex(codec,
1840 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1844 * Set number of channels in the selected stream.
1846 static void chipio_set_stream_channels(struct hda_codec *codec,
1847 int streamid, unsigned int channels)
1849 chipio_set_control_param_no_mutex(codec,
1850 CONTROL_PARAM_STREAM_ID, streamid);
1851 chipio_set_control_param_no_mutex(codec,
1852 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1856 * Enable/Disable audio stream.
1858 static void chipio_set_stream_control(struct hda_codec *codec,
1859 int streamid, int enable)
1861 chipio_set_control_param_no_mutex(codec,
1862 CONTROL_PARAM_STREAM_ID, streamid);
1863 chipio_set_control_param_no_mutex(codec,
1864 CONTROL_PARAM_STREAM_CONTROL, enable);
1868 * Get ChipIO audio stream's status.
1870 static void chipio_get_stream_control(struct hda_codec *codec,
1871 int streamid, unsigned int *enable)
1873 chipio_set_control_param_no_mutex(codec,
1874 CONTROL_PARAM_STREAM_ID, streamid);
1875 *enable = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1876 VENDOR_CHIPIO_PARAM_GET,
1877 CONTROL_PARAM_STREAM_CONTROL);
1881 * Set sampling rate of the connection point. NO MUTEX.
1883 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1884 int connid, enum ca0132_sample_rate rate)
1886 chipio_set_control_param_no_mutex(codec,
1887 CONTROL_PARAM_CONN_POINT_ID, connid);
1888 chipio_set_control_param_no_mutex(codec,
1889 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1893 * Set sampling rate of the connection point.
1895 static void chipio_set_conn_rate(struct hda_codec *codec,
1896 int connid, enum ca0132_sample_rate rate)
1898 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1899 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1904 * Writes to the 8051's internal address space directly instead of indirectly,
1905 * giving access to the special function registers located at addresses
1908 static void chipio_8051_write_direct(struct hda_codec *codec,
1909 unsigned int addr, unsigned int data)
1913 verb = VENDOR_CHIPIO_8051_WRITE_DIRECT | data;
1914 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1918 * Writes to the 8051's exram, which has 16-bits of address space.
1919 * Data at addresses 0x2000-0x7fff is mirrored to 0x8000-0xdfff.
1920 * Data at 0x8000-0xdfff can also be used as program memory for the 8051 by
1921 * setting the pmem bank selection SFR.
1922 * 0xe000-0xffff is always mapped as program memory, with only 0xf000-0xffff
1925 static void chipio_8051_set_address(struct hda_codec *codec, unsigned int addr)
1931 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1932 VENDOR_CHIPIO_8051_ADDRESS_LOW, tmp);
1935 tmp = (addr >> 8) & 0xff;
1936 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1937 VENDOR_CHIPIO_8051_ADDRESS_HIGH, tmp);
1940 static void chipio_8051_set_data(struct hda_codec *codec, unsigned int data)
1942 /* 8-bits of data. */
1943 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1944 VENDOR_CHIPIO_8051_DATA_WRITE, data & 0xff);
1947 static unsigned int chipio_8051_get_data(struct hda_codec *codec)
1949 return snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1950 VENDOR_CHIPIO_8051_DATA_READ, 0);
1953 /* PLL_PMU writes share the lower address register of the 8051 exram writes. */
1954 static void chipio_8051_set_data_pll(struct hda_codec *codec, unsigned int data)
1956 /* 8-bits of data. */
1957 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1958 VENDOR_CHIPIO_PLL_PMU_WRITE, data & 0xff);
1961 static void chipio_8051_write_exram(struct hda_codec *codec,
1962 unsigned int addr, unsigned int data)
1964 struct ca0132_spec *spec = codec->spec;
1966 mutex_lock(&spec->chipio_mutex);
1968 chipio_8051_set_address(codec, addr);
1969 chipio_8051_set_data(codec, data);
1971 mutex_unlock(&spec->chipio_mutex);
1974 static void chipio_8051_write_exram_no_mutex(struct hda_codec *codec,
1975 unsigned int addr, unsigned int data)
1977 chipio_8051_set_address(codec, addr);
1978 chipio_8051_set_data(codec, data);
1981 /* Readback data from the 8051's exram. No mutex. */
1982 static void chipio_8051_read_exram(struct hda_codec *codec,
1983 unsigned int addr, unsigned int *data)
1985 chipio_8051_set_address(codec, addr);
1986 *data = chipio_8051_get_data(codec);
1989 static void chipio_8051_write_pll_pmu(struct hda_codec *codec,
1990 unsigned int addr, unsigned int data)
1992 struct ca0132_spec *spec = codec->spec;
1994 mutex_lock(&spec->chipio_mutex);
1996 chipio_8051_set_address(codec, addr & 0xff);
1997 chipio_8051_set_data_pll(codec, data);
1999 mutex_unlock(&spec->chipio_mutex);
2002 static void chipio_8051_write_pll_pmu_no_mutex(struct hda_codec *codec,
2003 unsigned int addr, unsigned int data)
2005 chipio_8051_set_address(codec, addr & 0xff);
2006 chipio_8051_set_data_pll(codec, data);
2012 static void chipio_enable_clocks(struct hda_codec *codec)
2014 struct ca0132_spec *spec = codec->spec;
2016 mutex_lock(&spec->chipio_mutex);
2018 chipio_8051_write_pll_pmu_no_mutex(codec, 0x00, 0xff);
2019 chipio_8051_write_pll_pmu_no_mutex(codec, 0x05, 0x0b);
2020 chipio_8051_write_pll_pmu_no_mutex(codec, 0x06, 0xff);
2022 mutex_unlock(&spec->chipio_mutex);
2026 * CA0132 DSP IO stuffs
2028 static int dspio_send(struct hda_codec *codec, unsigned int reg,
2032 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2034 /* send bits of data specified by reg to dsp */
2036 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
2037 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
2040 } while (time_before(jiffies, timeout));
2046 * Wait for DSP to be ready for commands
2048 static void dspio_write_wait(struct hda_codec *codec)
2051 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2054 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2055 VENDOR_DSPIO_STATUS, 0);
2056 if ((status == VENDOR_STATUS_DSPIO_OK) ||
2057 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
2060 } while (time_before(jiffies, timeout));
2064 * Write SCP data to DSP
2066 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
2068 struct ca0132_spec *spec = codec->spec;
2071 dspio_write_wait(codec);
2073 mutex_lock(&spec->chipio_mutex);
2074 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
2079 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
2084 /* OK, now check if the write itself has executed*/
2085 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2086 VENDOR_DSPIO_STATUS, 0);
2088 mutex_unlock(&spec->chipio_mutex);
2090 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
2095 * Write multiple SCP data to DSP
2097 static int dspio_write_multiple(struct hda_codec *codec,
2098 unsigned int *buffer, unsigned int size)
2107 while (count < size) {
2108 status = dspio_write(codec, *buffer++);
2117 static int dspio_read(struct hda_codec *codec, unsigned int *data)
2121 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
2125 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
2126 if (status == -EIO ||
2127 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
2130 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2131 VENDOR_DSPIO_SCP_READ_DATA, 0);
2136 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
2137 unsigned int *buf_size, unsigned int size_count)
2140 unsigned int size = *buf_size;
2142 unsigned int skip_count;
2149 while (count < size && count < size_count) {
2150 status = dspio_read(codec, buffer++);
2158 while (skip_count < size) {
2159 status = dspio_read(codec, &dummy);
2171 * Construct the SCP header using corresponding fields
2173 static inline unsigned int
2174 make_scp_header(unsigned int target_id, unsigned int source_id,
2175 unsigned int get_flag, unsigned int req,
2176 unsigned int device_flag, unsigned int resp_flag,
2177 unsigned int error_flag, unsigned int data_size)
2179 unsigned int header = 0;
2181 header = (data_size & 0x1f) << 27;
2182 header |= (error_flag & 0x01) << 26;
2183 header |= (resp_flag & 0x01) << 25;
2184 header |= (device_flag & 0x01) << 24;
2185 header |= (req & 0x7f) << 17;
2186 header |= (get_flag & 0x01) << 16;
2187 header |= (source_id & 0xff) << 8;
2188 header |= target_id & 0xff;
2194 * Extract corresponding fields from SCP header
2197 extract_scp_header(unsigned int header,
2198 unsigned int *target_id, unsigned int *source_id,
2199 unsigned int *get_flag, unsigned int *req,
2200 unsigned int *device_flag, unsigned int *resp_flag,
2201 unsigned int *error_flag, unsigned int *data_size)
2204 *data_size = (header >> 27) & 0x1f;
2206 *error_flag = (header >> 26) & 0x01;
2208 *resp_flag = (header >> 25) & 0x01;
2210 *device_flag = (header >> 24) & 0x01;
2212 *req = (header >> 17) & 0x7f;
2214 *get_flag = (header >> 16) & 0x01;
2216 *source_id = (header >> 8) & 0xff;
2218 *target_id = header & 0xff;
2221 #define SCP_MAX_DATA_WORDS (16)
2223 /* Structure to contain any SCP message */
2226 unsigned int data[SCP_MAX_DATA_WORDS];
2229 static void dspio_clear_response_queue(struct hda_codec *codec)
2231 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2232 unsigned int dummy = 0;
2235 /* clear all from the response queue */
2237 status = dspio_read(codec, &dummy);
2238 } while (status == 0 && time_before(jiffies, timeout));
2241 static int dspio_get_response_data(struct hda_codec *codec)
2243 struct ca0132_spec *spec = codec->spec;
2244 unsigned int data = 0;
2247 if (dspio_read(codec, &data) < 0)
2250 if ((data & 0x00ffffff) == spec->wait_scp_header) {
2251 spec->scp_resp_header = data;
2252 spec->scp_resp_count = data >> 27;
2253 count = spec->wait_num_data;
2254 dspio_read_multiple(codec, spec->scp_resp_data,
2255 &spec->scp_resp_count, count);
2263 * Send SCP message to DSP
2265 static int dspio_send_scp_message(struct hda_codec *codec,
2266 unsigned char *send_buf,
2267 unsigned int send_buf_size,
2268 unsigned char *return_buf,
2269 unsigned int return_buf_size,
2270 unsigned int *bytes_returned)
2272 struct ca0132_spec *spec = codec->spec;
2274 unsigned int scp_send_size = 0;
2275 unsigned int total_size;
2276 bool waiting_for_resp = false;
2277 unsigned int header;
2278 struct scp_msg *ret_msg;
2279 unsigned int resp_src_id, resp_target_id;
2280 unsigned int data_size, src_id, target_id, get_flag, device_flag;
2283 *bytes_returned = 0;
2285 /* get scp header from buffer */
2286 header = *((unsigned int *)send_buf);
2287 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
2288 &device_flag, NULL, NULL, &data_size);
2289 scp_send_size = data_size + 1;
2290 total_size = (scp_send_size * 4);
2292 if (send_buf_size < total_size)
2295 if (get_flag || device_flag) {
2296 if (!return_buf || return_buf_size < 4 || !bytes_returned)
2299 spec->wait_scp_header = *((unsigned int *)send_buf);
2301 /* swap source id with target id */
2302 resp_target_id = src_id;
2303 resp_src_id = target_id;
2304 spec->wait_scp_header &= 0xffff0000;
2305 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
2306 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
2308 waiting_for_resp = true;
2311 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
2318 if (waiting_for_resp) {
2319 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2320 memset(return_buf, 0, return_buf_size);
2323 } while (spec->wait_scp && time_before(jiffies, timeout));
2324 waiting_for_resp = false;
2325 if (!spec->wait_scp) {
2326 ret_msg = (struct scp_msg *)return_buf;
2327 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
2328 memcpy(&ret_msg->data, spec->scp_resp_data,
2329 spec->wait_num_data);
2330 *bytes_returned = (spec->scp_resp_count + 1) * 4;
2342 * dspio_scp - Prepare and send the SCP message to DSP
2343 * @codec: the HDA codec
2344 * @mod_id: ID of the DSP module to send the command
2345 * @src_id: ID of the source
2346 * @req: ID of request to send to the DSP module
2348 * @data: pointer to the data to send with the request, request specific
2349 * @len: length of the data, in bytes
2350 * @reply: point to the buffer to hold data returned for a reply
2351 * @reply_len: length of the reply buffer returned from GET
2353 * Returns zero or a negative error code.
2355 static int dspio_scp(struct hda_codec *codec,
2356 int mod_id, int src_id, int req, int dir, const void *data,
2357 unsigned int len, void *reply, unsigned int *reply_len)
2360 struct scp_msg scp_send, scp_reply;
2361 unsigned int ret_bytes, send_size, ret_size;
2362 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
2363 unsigned int reply_data_size;
2365 memset(&scp_send, 0, sizeof(scp_send));
2366 memset(&scp_reply, 0, sizeof(scp_reply));
2368 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
2371 if (dir == SCP_GET && reply == NULL) {
2372 codec_dbg(codec, "dspio_scp get but has no buffer\n");
2376 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
2377 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
2381 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
2382 0, 0, 0, len/sizeof(unsigned int));
2383 if (data != NULL && len > 0) {
2384 len = min((unsigned int)(sizeof(scp_send.data)), len);
2385 memcpy(scp_send.data, data, len);
2389 send_size = sizeof(unsigned int) + len;
2390 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
2391 send_size, (unsigned char *)&scp_reply,
2392 sizeof(scp_reply), &ret_bytes);
2395 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
2399 /* extract send and reply headers members */
2400 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
2401 NULL, NULL, NULL, NULL, NULL);
2402 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
2403 &reply_resp_flag, &reply_error_flag,
2409 if (reply_resp_flag && !reply_error_flag) {
2410 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
2411 / sizeof(unsigned int);
2413 if (*reply_len < ret_size*sizeof(unsigned int)) {
2414 codec_dbg(codec, "reply too long for buf\n");
2416 } else if (ret_size != reply_data_size) {
2417 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
2419 } else if (!reply) {
2420 codec_dbg(codec, "NULL reply\n");
2423 *reply_len = ret_size*sizeof(unsigned int);
2424 memcpy(reply, scp_reply.data, *reply_len);
2427 codec_dbg(codec, "reply ill-formed or errflag set\n");
2435 * Set DSP parameters
2437 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2438 int src_id, int req, const void *data, unsigned int len)
2440 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2444 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2445 int req, const unsigned int data)
2447 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2448 sizeof(unsigned int));
2452 * Allocate a DSP DMA channel via an SCP message
2454 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2457 unsigned int size = sizeof(*dma_chan);
2459 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2460 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2461 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
2465 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2469 if ((*dma_chan + 1) == 0) {
2470 codec_dbg(codec, "no free dma channels to allocate\n");
2474 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2475 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2481 * Free a DSP DMA via an SCP message
2483 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2486 unsigned int dummy = 0;
2488 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2489 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2491 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2492 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
2493 sizeof(dma_chan), NULL, &dummy);
2496 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2500 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2508 static int dsp_set_run_state(struct hda_codec *codec)
2510 unsigned int dbg_ctrl_reg;
2511 unsigned int halt_state;
2514 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2518 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
2519 DSP_DBGCNTL_STATE_LOBIT;
2521 if (halt_state != 0) {
2522 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
2523 DSP_DBGCNTL_SS_MASK);
2524 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2529 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
2530 DSP_DBGCNTL_EXEC_MASK;
2531 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2543 static int dsp_reset(struct hda_codec *codec)
2548 codec_dbg(codec, "dsp_reset\n");
2550 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2552 } while (res == -EIO && retry);
2555 codec_dbg(codec, "dsp_reset timeout\n");
2563 * Convert chip address to DSP address
2565 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2566 bool *code, bool *yram)
2568 *code = *yram = false;
2570 if (UC_RANGE(chip_addx, 1)) {
2572 return UC_OFF(chip_addx);
2573 } else if (X_RANGE_ALL(chip_addx, 1)) {
2574 return X_OFF(chip_addx);
2575 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2577 return Y_OFF(chip_addx);
2580 return INVALID_CHIP_ADDRESS;
2584 * Check if the DSP DMA is active
2586 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2588 unsigned int dma_chnlstart_reg;
2590 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2592 return ((dma_chnlstart_reg & (1 <<
2593 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2596 static int dsp_dma_setup_common(struct hda_codec *codec,
2597 unsigned int chip_addx,
2598 unsigned int dma_chan,
2599 unsigned int port_map_mask,
2603 unsigned int chnl_prop;
2604 unsigned int dsp_addx;
2605 unsigned int active;
2608 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2610 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2611 codec_dbg(codec, "dma chan num invalid\n");
2615 if (dsp_is_dma_active(codec, dma_chan)) {
2616 codec_dbg(codec, "dma already active\n");
2620 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2622 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2623 codec_dbg(codec, "invalid chip addr\n");
2627 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2630 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2633 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2637 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2640 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2644 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2646 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2648 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2650 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2652 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2655 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2658 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2662 codec_dbg(codec, "read ACTIVE Reg fail\n");
2665 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2668 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2669 DSPDMAC_ACTIVE_AAR_MASK;
2671 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2673 codec_dbg(codec, "write ACTIVE Reg fail\n");
2677 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2679 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2682 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2685 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2687 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2688 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2690 codec_dbg(codec, "write IRQCNT Reg fail\n");
2693 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2696 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2697 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2698 chip_addx, dsp_addx, dma_chan,
2699 port_map_mask, chnl_prop, active);
2701 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2707 * Setup the DSP DMA per-transfer-specific registers
2709 static int dsp_dma_setup(struct hda_codec *codec,
2710 unsigned int chip_addx,
2712 unsigned int dma_chan)
2716 unsigned int dsp_addx;
2717 unsigned int addr_field;
2718 unsigned int incr_field;
2719 unsigned int base_cnt;
2720 unsigned int cur_cnt;
2721 unsigned int dma_cfg = 0;
2722 unsigned int adr_ofs = 0;
2723 unsigned int xfr_cnt = 0;
2724 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2725 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2727 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2729 if (count > max_dma_count) {
2730 codec_dbg(codec, "count too big\n");
2734 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2735 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2736 codec_dbg(codec, "invalid chip addr\n");
2740 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2742 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2748 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2750 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2753 dma_cfg = addr_field + incr_field;
2754 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2757 codec_dbg(codec, "write DMACFG Reg fail\n");
2760 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2762 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2765 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2768 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2771 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2773 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2775 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2777 xfr_cnt = base_cnt | cur_cnt;
2779 status = chipio_write(codec,
2780 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2782 codec_dbg(codec, "write XFRCNT Reg fail\n");
2785 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2788 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2789 "ADROFS=0x%x, XFRCNT=0x%x\n",
2790 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2792 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2800 static int dsp_dma_start(struct hda_codec *codec,
2801 unsigned int dma_chan, bool ovly)
2803 unsigned int reg = 0;
2806 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2809 status = chipio_read(codec,
2810 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2813 codec_dbg(codec, "read CHNLSTART reg fail\n");
2816 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2818 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2819 DSPDMAC_CHNLSTART_DIS_MASK);
2822 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2823 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2825 codec_dbg(codec, "write CHNLSTART reg fail\n");
2828 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2836 static int dsp_dma_stop(struct hda_codec *codec,
2837 unsigned int dma_chan, bool ovly)
2839 unsigned int reg = 0;
2842 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2845 status = chipio_read(codec,
2846 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2849 codec_dbg(codec, "read CHNLSTART reg fail\n");
2852 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2853 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2854 DSPDMAC_CHNLSTART_DIS_MASK);
2857 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2858 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2860 codec_dbg(codec, "write CHNLSTART reg fail\n");
2863 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2869 * dsp_allocate_router_ports - Allocate router ports
2871 * @codec: the HDA codec
2872 * @num_chans: number of channels in the stream
2873 * @ports_per_channel: number of ports per channel
2874 * @start_device: start device
2875 * @port_map: pointer to the port list to hold the allocated ports
2877 * Returns zero or a negative error code.
2879 static int dsp_allocate_router_ports(struct hda_codec *codec,
2880 unsigned int num_chans,
2881 unsigned int ports_per_channel,
2882 unsigned int start_device,
2883 unsigned int *port_map)
2889 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2893 val = start_device << 6;
2894 val |= (ports_per_channel - 1) << 4;
2895 val |= num_chans - 1;
2897 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2898 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2901 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2902 VENDOR_CHIPIO_PORT_ALLOC_SET,
2905 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2909 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2910 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2914 return (res < 0) ? res : 0;
2920 static int dsp_free_router_ports(struct hda_codec *codec)
2924 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2928 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2929 VENDOR_CHIPIO_PORT_FREE_SET,
2932 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2938 * Allocate DSP ports for the download stream
2940 static int dsp_allocate_ports(struct hda_codec *codec,
2941 unsigned int num_chans,
2942 unsigned int rate_multi, unsigned int *port_map)
2946 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2948 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2949 codec_dbg(codec, "bad rate multiple\n");
2953 status = dsp_allocate_router_ports(codec, num_chans,
2954 rate_multi, 0, port_map);
2956 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2961 static int dsp_allocate_ports_format(struct hda_codec *codec,
2962 const unsigned short fmt,
2963 unsigned int *port_map)
2966 unsigned int num_chans;
2968 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2969 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2970 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2972 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2973 codec_dbg(codec, "bad rate multiple\n");
2977 num_chans = get_hdafmt_chs(fmt) + 1;
2979 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2987 static int dsp_free_ports(struct hda_codec *codec)
2991 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2993 status = dsp_free_router_ports(codec);
2995 codec_dbg(codec, "free router ports fail\n");
2998 codec_dbg(codec, " dsp_free_ports() -- complete\n");
3004 * HDA DMA engine stuffs for DSP code download
3007 struct hda_codec *codec;
3008 unsigned short m_converter_format;
3009 struct snd_dma_buffer *dmab;
3010 unsigned int buf_size;
3019 static int dma_convert_to_hda_format(struct hda_codec *codec,
3020 unsigned int sample_rate,
3021 unsigned short channels,
3022 unsigned short *hda_format)
3024 unsigned int format_val;
3026 format_val = snd_hdac_calc_stream_format(sample_rate,
3027 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
3030 *hda_format = (unsigned short)format_val;
3036 * Reset DMA for DSP download
3038 static int dma_reset(struct dma_engine *dma)
3040 struct hda_codec *codec = dma->codec;
3041 struct ca0132_spec *spec = codec->spec;
3044 if (dma->dmab->area)
3045 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
3047 status = snd_hda_codec_load_dsp_prepare(codec,
3048 dma->m_converter_format,
3053 spec->dsp_stream_id = status;
3057 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
3062 case DMA_STATE_STOP:
3072 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
3076 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
3078 return dma->dmab->bytes;
3081 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
3083 return dma->dmab->area;
3086 static int dma_xfer(struct dma_engine *dma,
3087 const unsigned int *data,
3090 memcpy(dma->dmab->area, data, count);
3094 static void dma_get_converter_format(
3095 struct dma_engine *dma,
3096 unsigned short *format)
3099 *format = dma->m_converter_format;
3102 static unsigned int dma_get_stream_id(struct dma_engine *dma)
3104 struct ca0132_spec *spec = dma->codec->spec;
3106 return spec->dsp_stream_id;
3109 struct dsp_image_seg {
3116 static const u32 g_magic_value = 0x4c46584d;
3117 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
3119 static bool is_valid(const struct dsp_image_seg *p)
3121 return p->magic == g_magic_value;
3124 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
3126 return g_chip_addr_magic_value == p->chip_addr;
3129 static bool is_last(const struct dsp_image_seg *p)
3131 return p->count == 0;
3134 static size_t dsp_sizeof(const struct dsp_image_seg *p)
3136 return struct_size(p, data, p->count);
3139 static const struct dsp_image_seg *get_next_seg_ptr(
3140 const struct dsp_image_seg *p)
3142 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
3146 * CA0132 chip DSP transfer stuffs. For DSP download.
3148 #define INVALID_DMA_CHANNEL (~0U)
3151 * Program a list of address/data pairs via the ChipIO widget.
3152 * The segment data is in the format of successive pairs of words.
3153 * These are repeated as indicated by the segment's count field.
3155 static int dspxfr_hci_write(struct hda_codec *codec,
3156 const struct dsp_image_seg *fls)
3162 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
3163 codec_dbg(codec, "hci_write invalid params\n");
3168 data = (u32 *)(fls->data);
3169 while (count >= 2) {
3170 status = chipio_write(codec, data[0], data[1]);
3172 codec_dbg(codec, "hci_write chipio failed\n");
3182 * dspxfr_one_seg - Write a block of data into DSP code or data RAM using pre-allocated DMA engine.
3184 * @codec: the HDA codec
3185 * @fls: pointer to a fast load image
3186 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3188 * @dma_engine: pointer to DMA engine to be used for DSP download
3189 * @dma_chan: The number of DMA channels used for DSP download
3190 * @port_map_mask: port mapping
3191 * @ovly: TRUE if overlay format is required
3193 * Returns zero or a negative error code.
3195 static int dspxfr_one_seg(struct hda_codec *codec,
3196 const struct dsp_image_seg *fls,
3198 struct dma_engine *dma_engine,
3199 unsigned int dma_chan,
3200 unsigned int port_map_mask,
3204 bool comm_dma_setup_done = false;
3205 const unsigned int *data;
3206 unsigned int chip_addx;
3207 unsigned int words_to_write;
3208 unsigned int buffer_size_words;
3209 unsigned char *buffer_addx;
3210 unsigned short hda_format;
3211 unsigned int sample_rate_div;
3212 unsigned int sample_rate_mul;
3213 unsigned int num_chans;
3214 unsigned int hda_frame_size_words;
3215 unsigned int remainder_words;
3216 const u32 *data_remainder;
3217 u32 chip_addx_remainder;
3218 unsigned int run_size_words;
3219 const struct dsp_image_seg *hci_write = NULL;
3220 unsigned long timeout;
3225 if (is_hci_prog_list_seg(fls)) {
3227 fls = get_next_seg_ptr(fls);
3230 if (hci_write && (!fls || is_last(fls))) {
3231 codec_dbg(codec, "hci_write\n");
3232 return dspxfr_hci_write(codec, hci_write);
3235 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
3236 codec_dbg(codec, "Invalid Params\n");
3241 chip_addx = fls->chip_addr;
3242 words_to_write = fls->count;
3244 if (!words_to_write)
3245 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
3247 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
3249 if (!UC_RANGE(chip_addx, words_to_write) &&
3250 !X_RANGE_ALL(chip_addx, words_to_write) &&
3251 !Y_RANGE_ALL(chip_addx, words_to_write)) {
3252 codec_dbg(codec, "Invalid chip_addx Params\n");
3256 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
3259 buffer_addx = dma_get_buffer_addr(dma_engine);
3261 if (buffer_addx == NULL) {
3262 codec_dbg(codec, "dma_engine buffer NULL\n");
3266 dma_get_converter_format(dma_engine, &hda_format);
3267 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
3268 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
3269 num_chans = get_hdafmt_chs(hda_format) + 1;
3271 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
3272 (num_chans * sample_rate_mul / sample_rate_div));
3274 if (hda_frame_size_words == 0) {
3275 codec_dbg(codec, "frmsz zero\n");
3279 buffer_size_words = min(buffer_size_words,
3280 (unsigned int)(UC_RANGE(chip_addx, 1) ?
3282 buffer_size_words -= buffer_size_words % hda_frame_size_words;
3284 "chpadr=0x%08x frmsz=%u nchan=%u "
3285 "rate_mul=%u div=%u bufsz=%u\n",
3286 chip_addx, hda_frame_size_words, num_chans,
3287 sample_rate_mul, sample_rate_div, buffer_size_words);
3289 if (buffer_size_words < hda_frame_size_words) {
3290 codec_dbg(codec, "dspxfr_one_seg:failed\n");
3294 remainder_words = words_to_write % hda_frame_size_words;
3295 data_remainder = data;
3296 chip_addx_remainder = chip_addx;
3298 data += remainder_words;
3299 chip_addx += remainder_words*sizeof(u32);
3300 words_to_write -= remainder_words;
3302 while (words_to_write != 0) {
3303 run_size_words = min(buffer_size_words, words_to_write);
3304 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
3305 words_to_write, run_size_words, remainder_words);
3306 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
3307 if (!comm_dma_setup_done) {
3308 status = dsp_dma_stop(codec, dma_chan, ovly);
3311 status = dsp_dma_setup_common(codec, chip_addx,
3312 dma_chan, port_map_mask, ovly);
3315 comm_dma_setup_done = true;
3318 status = dsp_dma_setup(codec, chip_addx,
3319 run_size_words, dma_chan);
3322 status = dsp_dma_start(codec, dma_chan, ovly);
3325 if (!dsp_is_dma_active(codec, dma_chan)) {
3326 codec_dbg(codec, "dspxfr:DMA did not start\n");
3329 status = dma_set_state(dma_engine, DMA_STATE_RUN);
3332 if (remainder_words != 0) {
3333 status = chipio_write_multiple(codec,
3334 chip_addx_remainder,
3339 remainder_words = 0;
3342 status = dspxfr_hci_write(codec, hci_write);
3348 timeout = jiffies + msecs_to_jiffies(2000);
3350 dma_active = dsp_is_dma_active(codec, dma_chan);
3354 } while (time_before(jiffies, timeout));
3358 codec_dbg(codec, "+++++ DMA complete\n");
3359 dma_set_state(dma_engine, DMA_STATE_STOP);
3360 status = dma_reset(dma_engine);
3365 data += run_size_words;
3366 chip_addx += run_size_words*sizeof(u32);
3367 words_to_write -= run_size_words;
3370 if (remainder_words != 0) {
3371 status = chipio_write_multiple(codec, chip_addx_remainder,
3372 data_remainder, remainder_words);
3379 * dspxfr_image - Write the entire DSP image of a DSP code/data overlay to DSP memories
3381 * @codec: the HDA codec
3382 * @fls_data: pointer to a fast load image
3383 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3385 * @sample_rate: sampling rate of the stream used for DSP download
3386 * @channels: channels of the stream used for DSP download
3387 * @ovly: TRUE if overlay format is required
3389 * Returns zero or a negative error code.
3391 static int dspxfr_image(struct hda_codec *codec,
3392 const struct dsp_image_seg *fls_data,
3394 unsigned int sample_rate,
3395 unsigned short channels,
3398 struct ca0132_spec *spec = codec->spec;
3400 unsigned short hda_format = 0;
3401 unsigned int response;
3402 unsigned char stream_id = 0;
3403 struct dma_engine *dma_engine;
3404 unsigned int dma_chan;
3405 unsigned int port_map_mask;
3407 if (fls_data == NULL)
3410 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
3414 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
3415 if (!dma_engine->dmab) {
3420 dma_engine->codec = codec;
3421 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3422 dma_engine->m_converter_format = hda_format;
3423 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
3424 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
3426 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
3428 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3429 hda_format, &response);
3432 codec_dbg(codec, "set converter format fail\n");
3436 status = snd_hda_codec_load_dsp_prepare(codec,
3437 dma_engine->m_converter_format,
3438 dma_engine->buf_size,
3442 spec->dsp_stream_id = status;
3445 status = dspio_alloc_dma_chan(codec, &dma_chan);
3447 codec_dbg(codec, "alloc dmachan fail\n");
3448 dma_chan = INVALID_DMA_CHANNEL;
3454 status = dsp_allocate_ports_format(codec, hda_format,
3457 codec_dbg(codec, "alloc ports fail\n");
3461 stream_id = dma_get_stream_id(dma_engine);
3462 status = codec_set_converter_stream_channel(codec,
3463 WIDGET_CHIP_CTRL, stream_id, 0, &response);
3465 codec_dbg(codec, "set stream chan fail\n");
3469 while ((fls_data != NULL) && !is_last(fls_data)) {
3470 if (!is_valid(fls_data)) {
3471 codec_dbg(codec, "FLS check fail\n");
3475 status = dspxfr_one_seg(codec, fls_data, reloc,
3476 dma_engine, dma_chan,
3477 port_map_mask, ovly);
3481 if (is_hci_prog_list_seg(fls_data))
3482 fls_data = get_next_seg_ptr(fls_data);
3484 if ((fls_data != NULL) && !is_last(fls_data))
3485 fls_data = get_next_seg_ptr(fls_data);
3488 if (port_map_mask != 0)
3489 status = dsp_free_ports(codec);
3494 status = codec_set_converter_stream_channel(codec,
3495 WIDGET_CHIP_CTRL, 0, 0, &response);
3498 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
3499 dspio_free_dma_chan(codec, dma_chan);
3501 if (dma_engine->dmab->area)
3502 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3503 kfree(dma_engine->dmab);
3510 * CA0132 DSP download stuffs.
3512 static void dspload_post_setup(struct hda_codec *codec)
3514 struct ca0132_spec *spec = codec->spec;
3515 codec_dbg(codec, "---- dspload_post_setup ------\n");
3516 if (!ca0132_use_alt_functions(spec)) {
3517 /*set DSP speaker to 2.0 configuration*/
3518 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3519 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3521 /*update write pointer*/
3522 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3527 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3529 * @codec: the HDA codec
3530 * @fls: pointer to a fast load image
3531 * @ovly: TRUE if overlay format is required
3532 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3534 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3535 * @router_chans: number of audio router channels to be allocated (0 means use
3536 * internal defaults; max is 32)
3538 * Download DSP from a DSP Image Fast Load structure. This structure is a
3539 * linear, non-constant sized element array of structures, each of which
3540 * contain the count of the data to be loaded, the data itself, and the
3541 * corresponding starting chip address of the starting data location.
3542 * Returns zero or a negative error code.
3544 static int dspload_image(struct hda_codec *codec,
3545 const struct dsp_image_seg *fls,
3552 unsigned int sample_rate;
3553 unsigned short channels;
3555 codec_dbg(codec, "---- dspload_image begin ------\n");
3556 if (router_chans == 0) {
3558 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3560 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3563 sample_rate = 48000;
3564 channels = (unsigned short)router_chans;
3566 while (channels > 16) {
3572 codec_dbg(codec, "Ready to program DMA\n");
3574 status = dsp_reset(codec);
3579 codec_dbg(codec, "dsp_reset() complete\n");
3580 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3586 codec_dbg(codec, "dspxfr_image() complete\n");
3587 if (autostart && !ovly) {
3588 dspload_post_setup(codec);
3589 status = dsp_set_run_state(codec);
3592 codec_dbg(codec, "LOAD FINISHED\n");
3598 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3599 static bool dspload_is_loaded(struct hda_codec *codec)
3601 unsigned int data = 0;
3604 status = chipio_read(codec, 0x40004, &data);
3605 if ((status < 0) || (data != 1))
3611 #define dspload_is_loaded(codec) false
3614 static bool dspload_wait_loaded(struct hda_codec *codec)
3616 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3619 if (dspload_is_loaded(codec)) {
3620 codec_info(codec, "ca0132 DSP downloaded and running\n");
3624 } while (time_before(jiffies, timeout));
3626 codec_err(codec, "ca0132 failed to download DSP\n");
3631 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3632 * based cards, and has a second mmio region, region2, that's used for special
3637 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3638 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3639 * The first eight bits are just the number of the pin. So far, I've only seen
3640 * this number go to 7.
3641 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3642 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3643 * then off to send that bit.
3645 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3648 struct ca0132_spec *spec = codec->spec;
3649 unsigned short gpio_data;
3651 gpio_data = gpio_pin & 0xF;
3652 gpio_data |= ((enable << 8) & 0x100);
3654 writew(gpio_data, spec->mem_base + 0x320);
3658 * Special pci region2 commands that are only used by the AE-5. They follow
3659 * a set format, and require reads at certain points to seemingly 'clear'
3660 * the response data. My first tests didn't do these reads, and would cause
3661 * the card to get locked up until the memory was read. These commands
3662 * seem to work with three distinct values that I've taken to calling group,
3663 * target-id, and value.
3665 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3666 unsigned int target, unsigned int value)
3668 struct ca0132_spec *spec = codec->spec;
3669 unsigned int write_val;
3671 writel(0x0000007e, spec->mem_base + 0x210);
3672 readl(spec->mem_base + 0x210);
3673 writel(0x0000005a, spec->mem_base + 0x210);
3674 readl(spec->mem_base + 0x210);
3675 readl(spec->mem_base + 0x210);
3677 writel(0x00800005, spec->mem_base + 0x20c);
3678 writel(group, spec->mem_base + 0x804);
3680 writel(0x00800005, spec->mem_base + 0x20c);
3681 write_val = (target & 0xff);
3682 write_val |= (value << 8);
3685 writel(write_val, spec->mem_base + 0x204);
3687 * Need delay here or else it goes too fast and works inconsistently.
3691 readl(spec->mem_base + 0x860);
3692 readl(spec->mem_base + 0x854);
3693 readl(spec->mem_base + 0x840);
3695 writel(0x00800004, spec->mem_base + 0x20c);
3696 writel(0x00000000, spec->mem_base + 0x210);
3697 readl(spec->mem_base + 0x210);
3698 readl(spec->mem_base + 0x210);
3702 * This second type of command is used for setting the sound filter type.
3704 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3705 unsigned int group, unsigned int target, unsigned int value)
3707 struct ca0132_spec *spec = codec->spec;
3708 unsigned int write_val;
3710 writel(0x0000007e, spec->mem_base + 0x210);
3711 readl(spec->mem_base + 0x210);
3712 writel(0x0000005a, spec->mem_base + 0x210);
3713 readl(spec->mem_base + 0x210);
3714 readl(spec->mem_base + 0x210);
3716 writel(0x00800003, spec->mem_base + 0x20c);
3717 writel(group, spec->mem_base + 0x804);
3719 writel(0x00800005, spec->mem_base + 0x20c);
3720 write_val = (target & 0xff);
3721 write_val |= (value << 8);
3724 writel(write_val, spec->mem_base + 0x204);
3726 readl(spec->mem_base + 0x860);
3727 readl(spec->mem_base + 0x854);
3728 readl(spec->mem_base + 0x840);
3730 writel(0x00800004, spec->mem_base + 0x20c);
3731 writel(0x00000000, spec->mem_base + 0x210);
3732 readl(spec->mem_base + 0x210);
3733 readl(spec->mem_base + 0x210);
3737 * Setup GPIO for the other variants of Core3D.
3741 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3742 * the card shows as having no GPIO pins.
3744 static void ca0132_gpio_init(struct hda_codec *codec)
3746 struct ca0132_spec *spec = codec->spec;
3748 switch (ca0132_quirk(spec)) {
3752 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3753 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3754 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3757 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3758 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3766 /* Sets the GPIO for audio output. */
3767 static void ca0132_gpio_setup(struct hda_codec *codec)
3769 struct ca0132_spec *spec = codec->spec;
3771 switch (ca0132_quirk(spec)) {
3773 snd_hda_codec_write(codec, 0x01, 0,
3774 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3775 snd_hda_codec_write(codec, 0x01, 0,
3776 AC_VERB_SET_GPIO_MASK, 0x07);
3777 snd_hda_codec_write(codec, 0x01, 0,
3778 AC_VERB_SET_GPIO_DATA, 0x04);
3779 snd_hda_codec_write(codec, 0x01, 0,
3780 AC_VERB_SET_GPIO_DATA, 0x06);
3783 snd_hda_codec_write(codec, 0x01, 0,
3784 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3785 snd_hda_codec_write(codec, 0x01, 0,
3786 AC_VERB_SET_GPIO_MASK, 0x1F);
3787 snd_hda_codec_write(codec, 0x01, 0,
3788 AC_VERB_SET_GPIO_DATA, 0x0C);
3796 * GPIO control functions for the Recon3D integrated.
3799 enum r3di_gpio_bit {
3800 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3801 R3DI_MIC_SELECT_BIT = 1,
3802 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3803 R3DI_OUT_SELECT_BIT = 2,
3805 * I dunno what this actually does, but it stays on until the dsp
3808 R3DI_GPIO_DSP_DOWNLOADING = 3,
3810 * Same as above, no clue what it does, but it comes on after the dsp
3813 R3DI_GPIO_DSP_DOWNLOADED = 4
3816 enum r3di_mic_select {
3817 /* Set GPIO bit 1 to 0 for rear mic */
3819 /* Set GPIO bit 1 to 1 for front microphone*/
3823 enum r3di_out_select {
3824 /* Set GPIO bit 2 to 0 for headphone */
3825 R3DI_HEADPHONE_OUT = 0,
3826 /* Set GPIO bit 2 to 1 for speaker */
3829 enum r3di_dsp_status {
3830 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3831 R3DI_DSP_DOWNLOADING = 0,
3832 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3833 R3DI_DSP_DOWNLOADED = 1
3837 static void r3di_gpio_mic_set(struct hda_codec *codec,
3838 enum r3di_mic_select cur_mic)
3840 unsigned int cur_gpio;
3842 /* Get the current GPIO Data setup */
3843 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3847 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3849 case R3DI_FRONT_MIC:
3850 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3853 snd_hda_codec_write(codec, codec->core.afg, 0,
3854 AC_VERB_SET_GPIO_DATA, cur_gpio);
3857 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3858 enum r3di_dsp_status dsp_status)
3860 unsigned int cur_gpio;
3862 /* Get the current GPIO Data setup */
3863 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3865 switch (dsp_status) {
3866 case R3DI_DSP_DOWNLOADING:
3867 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3868 snd_hda_codec_write(codec, codec->core.afg, 0,
3869 AC_VERB_SET_GPIO_DATA, cur_gpio);
3871 case R3DI_DSP_DOWNLOADED:
3872 /* Set DOWNLOADING bit to 0. */
3873 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3875 snd_hda_codec_write(codec, codec->core.afg, 0,
3876 AC_VERB_SET_GPIO_DATA, cur_gpio);
3878 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3882 snd_hda_codec_write(codec, codec->core.afg, 0,
3883 AC_VERB_SET_GPIO_DATA, cur_gpio);
3889 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3890 struct hda_codec *codec,
3891 unsigned int stream_tag,
3892 unsigned int format,
3893 struct snd_pcm_substream *substream)
3895 struct ca0132_spec *spec = codec->spec;
3897 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3902 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3903 struct hda_codec *codec,
3904 struct snd_pcm_substream *substream)
3906 struct ca0132_spec *spec = codec->spec;
3908 if (spec->dsp_state == DSP_DOWNLOADING)
3911 /*If Playback effects are on, allow stream some time to flush
3913 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3916 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3921 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3922 struct hda_codec *codec,
3923 struct snd_pcm_substream *substream)
3925 struct ca0132_spec *spec = codec->spec;
3926 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3927 struct snd_pcm_runtime *runtime = substream->runtime;
3929 if (spec->dsp_state != DSP_DOWNLOADED)
3932 /* Add latency if playback enhancement and either effect is enabled. */
3933 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3934 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3935 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3936 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3939 /* Applying Speaker EQ adds latency as well. */
3940 if (spec->cur_out_type == SPEAKER_OUT)
3941 latency += DSP_SPEAKER_OUT_LATENCY;
3943 return (latency * runtime->rate) / 1000;
3949 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3950 struct hda_codec *codec,
3951 struct snd_pcm_substream *substream)
3953 struct ca0132_spec *spec = codec->spec;
3954 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3957 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3958 struct hda_codec *codec,
3959 unsigned int stream_tag,
3960 unsigned int format,
3961 struct snd_pcm_substream *substream)
3963 struct ca0132_spec *spec = codec->spec;
3964 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3965 stream_tag, format, substream);
3968 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3969 struct hda_codec *codec,
3970 struct snd_pcm_substream *substream)
3972 struct ca0132_spec *spec = codec->spec;
3973 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3976 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3977 struct hda_codec *codec,
3978 struct snd_pcm_substream *substream)
3980 struct ca0132_spec *spec = codec->spec;
3981 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3987 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3988 struct hda_codec *codec,
3989 unsigned int stream_tag,
3990 unsigned int format,
3991 struct snd_pcm_substream *substream)
3993 snd_hda_codec_setup_stream(codec, hinfo->nid,
3994 stream_tag, 0, format);
3999 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4000 struct hda_codec *codec,
4001 struct snd_pcm_substream *substream)
4003 struct ca0132_spec *spec = codec->spec;
4005 if (spec->dsp_state == DSP_DOWNLOADING)
4008 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4012 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
4013 struct hda_codec *codec,
4014 struct snd_pcm_substream *substream)
4016 struct ca0132_spec *spec = codec->spec;
4017 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
4018 struct snd_pcm_runtime *runtime = substream->runtime;
4020 if (spec->dsp_state != DSP_DOWNLOADED)
4023 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
4024 latency += DSP_CRYSTAL_VOICE_LATENCY;
4026 return (latency * runtime->rate) / 1000;
4034 * Mixer controls helpers.
4036 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
4037 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4039 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4040 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
4041 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
4042 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
4043 .info = ca0132_volume_info, \
4044 .get = ca0132_volume_get, \
4045 .put = ca0132_volume_put, \
4046 .tlv = { .c = ca0132_volume_tlv }, \
4047 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4050 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
4051 * volume put, which is used for setting the DSP volume. This was done because
4052 * the ca0132 functions were taking too much time and causing lag.
4054 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
4055 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4057 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4058 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
4059 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
4060 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
4061 .info = snd_hda_mixer_amp_volume_info, \
4062 .get = snd_hda_mixer_amp_volume_get, \
4063 .put = ca0132_alt_volume_put, \
4064 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
4065 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4067 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
4068 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4070 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4071 .info = snd_hda_mixer_amp_switch_info, \
4072 .get = ca0132_switch_get, \
4073 .put = ca0132_switch_put, \
4074 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4077 #define CA0132_CODEC_VOL(xname, nid, dir) \
4078 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
4079 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
4080 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
4081 #define CA0132_CODEC_MUTE(xname, nid, dir) \
4082 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
4086 * Lookup table with decibel values for the DSP. When volume is changed in
4087 * Windows, the DSP is also sent the dB value in floating point. In Windows,
4088 * these values have decimal points, probably because the Windows driver
4089 * actually uses floating point. We can't here, so I made a lookup table of
4090 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
4091 * DAC's, and 9 is the maximum.
4093 static const unsigned int float_vol_db_lookup[] = {
4094 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
4095 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
4096 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
4097 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
4098 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
4099 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
4100 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
4101 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
4102 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
4103 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
4104 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
4105 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
4106 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
4107 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
4108 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
4109 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
4110 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
4114 * This table counts from float 0 to 1 in increments of .01, which is
4115 * useful for a few different sliders.
4117 static const unsigned int float_zero_to_one_lookup[] = {
4118 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
4119 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
4120 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
4121 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
4122 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
4123 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4124 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4125 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4126 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4127 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4128 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4129 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4130 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4131 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4132 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4133 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4134 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4138 * This table counts from float 10 to 1000, which is the range of the x-bass
4139 * crossover slider in Windows.
4141 static const unsigned int float_xbass_xover_lookup[] = {
4142 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
4143 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
4144 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
4145 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
4146 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
4147 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
4148 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
4149 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
4150 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
4151 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
4152 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
4153 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
4154 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
4155 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
4156 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
4157 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
4158 0x44728000, 0x44750000, 0x44778000, 0x447A0000
4161 /* The following are for tuning of products */
4162 #ifdef ENABLE_TUNING_CONTROLS
4164 static const unsigned int voice_focus_vals_lookup[] = {
4165 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
4166 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
4167 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
4168 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
4169 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
4170 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
4171 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
4172 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
4173 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
4174 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
4175 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
4176 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
4177 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
4178 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
4179 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
4180 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
4181 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
4182 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
4183 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
4184 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
4185 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
4186 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
4187 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
4188 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
4189 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
4190 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
4191 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
4194 static const unsigned int mic_svm_vals_lookup[] = {
4195 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
4196 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
4197 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
4198 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
4199 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
4200 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4201 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4202 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4203 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4204 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4205 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4206 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4207 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4208 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4209 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4210 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4211 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4214 static const unsigned int equalizer_vals_lookup[] = {
4215 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
4216 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
4217 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
4218 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
4219 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
4220 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
4221 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
4222 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
4226 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
4227 const unsigned int *lookup, int idx)
4231 for (i = 0; i < TUNING_CTLS_COUNT; i++)
4232 if (nid == ca0132_tuning_ctls[i].nid)
4237 snd_hda_power_up(codec);
4238 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
4239 ca0132_tuning_ctls[i].req,
4240 &(lookup[idx]), sizeof(unsigned int));
4241 snd_hda_power_down(codec);
4246 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
4247 struct snd_ctl_elem_value *ucontrol)
4249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4250 struct ca0132_spec *spec = codec->spec;
4251 hda_nid_t nid = get_amp_nid(kcontrol);
4252 long *valp = ucontrol->value.integer.value;
4253 int idx = nid - TUNING_CTL_START_NID;
4255 *valp = spec->cur_ctl_vals[idx];
4259 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
4260 struct snd_ctl_elem_info *uinfo)
4262 int chs = get_amp_channels(kcontrol);
4263 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4264 uinfo->count = chs == 3 ? 2 : 1;
4265 uinfo->value.integer.min = 20;
4266 uinfo->value.integer.max = 180;
4267 uinfo->value.integer.step = 1;
4272 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
4273 struct snd_ctl_elem_value *ucontrol)
4275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4276 struct ca0132_spec *spec = codec->spec;
4277 hda_nid_t nid = get_amp_nid(kcontrol);
4278 long *valp = ucontrol->value.integer.value;
4281 idx = nid - TUNING_CTL_START_NID;
4283 if (spec->cur_ctl_vals[idx] == *valp)
4286 spec->cur_ctl_vals[idx] = *valp;
4289 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
4294 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
4295 struct snd_ctl_elem_info *uinfo)
4297 int chs = get_amp_channels(kcontrol);
4298 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4299 uinfo->count = chs == 3 ? 2 : 1;
4300 uinfo->value.integer.min = 0;
4301 uinfo->value.integer.max = 100;
4302 uinfo->value.integer.step = 1;
4307 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
4308 struct snd_ctl_elem_value *ucontrol)
4310 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4311 struct ca0132_spec *spec = codec->spec;
4312 hda_nid_t nid = get_amp_nid(kcontrol);
4313 long *valp = ucontrol->value.integer.value;
4316 idx = nid - TUNING_CTL_START_NID;
4318 if (spec->cur_ctl_vals[idx] == *valp)
4321 spec->cur_ctl_vals[idx] = *valp;
4324 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
4329 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
4330 struct snd_ctl_elem_info *uinfo)
4332 int chs = get_amp_channels(kcontrol);
4333 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4334 uinfo->count = chs == 3 ? 2 : 1;
4335 uinfo->value.integer.min = 0;
4336 uinfo->value.integer.max = 48;
4337 uinfo->value.integer.step = 1;
4342 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
4343 struct snd_ctl_elem_value *ucontrol)
4345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4346 struct ca0132_spec *spec = codec->spec;
4347 hda_nid_t nid = get_amp_nid(kcontrol);
4348 long *valp = ucontrol->value.integer.value;
4351 idx = nid - TUNING_CTL_START_NID;
4353 if (spec->cur_ctl_vals[idx] == *valp)
4356 spec->cur_ctl_vals[idx] = *valp;
4359 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
4364 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
4365 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
4367 static int add_tuning_control(struct hda_codec *codec,
4368 hda_nid_t pnid, hda_nid_t nid,
4369 const char *name, int dir)
4371 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
4372 int type = dir ? HDA_INPUT : HDA_OUTPUT;
4373 struct snd_kcontrol_new knew =
4374 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
4376 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
4377 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
4382 knew.info = voice_focus_ctl_info;
4383 knew.get = tuning_ctl_get;
4384 knew.put = voice_focus_ctl_put;
4385 knew.tlv.p = voice_focus_db_scale;
4388 knew.info = mic_svm_ctl_info;
4389 knew.get = tuning_ctl_get;
4390 knew.put = mic_svm_ctl_put;
4393 knew.info = equalizer_ctl_info;
4394 knew.get = tuning_ctl_get;
4395 knew.put = equalizer_ctl_put;
4396 knew.tlv.p = eq_db_scale;
4401 knew.private_value =
4402 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
4403 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
4404 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
4407 static int add_tuning_ctls(struct hda_codec *codec)
4412 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
4413 err = add_tuning_control(codec,
4414 ca0132_tuning_ctls[i].parent_nid,
4415 ca0132_tuning_ctls[i].nid,
4416 ca0132_tuning_ctls[i].name,
4417 ca0132_tuning_ctls[i].direct);
4425 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
4427 struct ca0132_spec *spec = codec->spec;
4430 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
4431 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
4432 /* SVM level defaults to 0.74. */
4433 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
4435 /* EQ defaults to 0dB. */
4436 for (i = 2; i < TUNING_CTLS_COUNT; i++)
4437 spec->cur_ctl_vals[i] = 24;
4439 #endif /*ENABLE_TUNING_CONTROLS*/
4442 * Select the active output.
4443 * If autodetect is enabled, output will be selected based on jack detection.
4444 * If jack inserted, headphone will be selected, else built-in speakers
4445 * If autodetect is disabled, output will be selected based on selection.
4447 static int ca0132_select_out(struct hda_codec *codec)
4449 struct ca0132_spec *spec = codec->spec;
4450 unsigned int pin_ctl;
4456 codec_dbg(codec, "ca0132_select_out\n");
4458 snd_hda_power_up_pm(codec);
4460 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4463 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
4466 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
4469 spec->cur_out_type = HEADPHONE_OUT;
4471 spec->cur_out_type = SPEAKER_OUT;
4473 if (spec->cur_out_type == SPEAKER_OUT) {
4474 codec_dbg(codec, "ca0132_select_out speaker\n");
4475 /*speaker out config*/
4477 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4480 /*enable speaker EQ*/
4482 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4487 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4488 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4489 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4490 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4491 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4492 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4493 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4494 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4496 /* disable headphone node */
4497 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4498 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4499 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4501 /* enable speaker node */
4502 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4503 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4504 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4507 codec_dbg(codec, "ca0132_select_out hp\n");
4508 /*headphone out config*/
4510 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4513 /*disable speaker EQ*/
4515 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4520 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4521 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4522 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4523 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4524 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4525 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4526 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4527 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4529 /* disable speaker*/
4530 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4531 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4532 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4534 /* enable headphone*/
4535 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4536 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4537 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4542 snd_hda_power_down_pm(codec);
4544 return err < 0 ? err : 0;
4547 static int ae5_headphone_gain_set(struct hda_codec *codec, long val);
4548 static int zxr_headphone_gain_set(struct hda_codec *codec, long val);
4549 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4551 static void ae5_mmio_select_out(struct hda_codec *codec)
4553 struct ca0132_spec *spec = codec->spec;
4554 const struct ae_ca0113_output_set *out_cmds;
4557 if (ca0132_quirk(spec) == QUIRK_AE5)
4558 out_cmds = &ae5_ca0113_output_presets;
4560 out_cmds = &ae7_ca0113_output_presets;
4562 for (i = 0; i < AE_CA0113_OUT_SET_COMMANDS; i++)
4563 ca0113_mmio_command_set(codec, out_cmds->group[i],
4564 out_cmds->target[i],
4565 out_cmds->vals[spec->cur_out_type][i]);
4568 static int ca0132_alt_set_full_range_speaker(struct hda_codec *codec)
4570 struct ca0132_spec *spec = codec->spec;
4571 int quirk = ca0132_quirk(spec);
4575 /* 2.0/4.0 setup has no LFE channel, so setting full-range does nothing. */
4576 if (spec->channel_cfg_val == SPEAKER_CHANNELS_4_0
4577 || spec->channel_cfg_val == SPEAKER_CHANNELS_2_0)
4580 /* Set front L/R full range. Zero for full-range, one for redirection. */
4581 tmp = spec->speaker_range_val[0] ? FLOAT_ZERO : FLOAT_ONE;
4582 err = dspio_set_uint_param(codec, 0x96,
4583 SPEAKER_FULL_RANGE_FRONT_L_R, tmp);
4587 /* When setting full-range rear, both rear and center/lfe are set. */
4588 tmp = spec->speaker_range_val[1] ? FLOAT_ZERO : FLOAT_ONE;
4589 err = dspio_set_uint_param(codec, 0x96,
4590 SPEAKER_FULL_RANGE_CENTER_LFE, tmp);
4594 err = dspio_set_uint_param(codec, 0x96,
4595 SPEAKER_FULL_RANGE_REAR_L_R, tmp);
4600 * Only the AE series cards set this value when setting full-range,
4601 * and it's always 1.0f.
4603 if (quirk == QUIRK_AE5 || quirk == QUIRK_AE7) {
4604 err = dspio_set_uint_param(codec, 0x96,
4605 SPEAKER_FULL_RANGE_SURROUND_L_R, FLOAT_ONE);
4613 static int ca0132_alt_surround_set_bass_redirection(struct hda_codec *codec,
4616 struct ca0132_spec *spec = codec->spec;
4620 if (val && spec->channel_cfg_val != SPEAKER_CHANNELS_4_0 &&
4621 spec->channel_cfg_val != SPEAKER_CHANNELS_2_0)
4626 err = dspio_set_uint_param(codec, 0x96, SPEAKER_BASS_REDIRECT, tmp);
4630 /* If it is enabled, make sure to set the crossover frequency. */
4632 tmp = float_xbass_xover_lookup[spec->xbass_xover_freq];
4633 err = dspio_set_uint_param(codec, 0x96,
4634 SPEAKER_BASS_REDIRECT_XOVER_FREQ, tmp);
4643 * These are the commands needed to setup output on each of the different card
4646 static void ca0132_alt_select_out_get_quirk_data(struct hda_codec *codec,
4647 const struct ca0132_alt_out_set_quirk_data **quirk_data)
4649 struct ca0132_spec *spec = codec->spec;
4650 int quirk = ca0132_quirk(spec);
4654 for (i = 0; i < ARRAY_SIZE(quirk_out_set_data); i++) {
4655 if (quirk_out_set_data[i].quirk_id == quirk) {
4656 *quirk_data = &quirk_out_set_data[i];
4662 static int ca0132_alt_select_out_quirk_set(struct hda_codec *codec)
4664 const struct ca0132_alt_out_set_quirk_data *quirk_data;
4665 const struct ca0132_alt_out_set_info *out_info;
4666 struct ca0132_spec *spec = codec->spec;
4667 unsigned int i, gpio_data;
4670 ca0132_alt_select_out_get_quirk_data(codec, &quirk_data);
4674 out_info = &quirk_data->out_set_info[spec->cur_out_type];
4675 if (quirk_data->is_ae_series)
4676 ae5_mmio_select_out(codec);
4678 if (out_info->has_hda_gpio) {
4679 gpio_data = snd_hda_codec_read(codec, codec->core.afg, 0,
4680 AC_VERB_GET_GPIO_DATA, 0);
4682 if (out_info->hda_gpio_set)
4683 gpio_data |= (1 << out_info->hda_gpio_pin);
4685 gpio_data &= ~(1 << out_info->hda_gpio_pin);
4687 snd_hda_codec_write(codec, codec->core.afg, 0,
4688 AC_VERB_SET_GPIO_DATA, gpio_data);
4691 if (out_info->mmio_gpio_count) {
4692 for (i = 0; i < out_info->mmio_gpio_count; i++) {
4693 ca0113_mmio_gpio_set(codec, out_info->mmio_gpio_pin[i],
4694 out_info->mmio_gpio_set[i]);
4698 if (out_info->scp_cmds_count) {
4699 for (i = 0; i < out_info->scp_cmds_count; i++) {
4700 err = dspio_set_uint_param(codec,
4701 out_info->scp_cmd_mid[i],
4702 out_info->scp_cmd_req[i],
4703 out_info->scp_cmd_val[i]);
4709 chipio_set_control_param(codec, 0x0d, out_info->dac2port);
4711 if (out_info->has_chipio_write) {
4712 chipio_write(codec, out_info->chipio_write_addr,
4713 out_info->chipio_write_data);
4716 if (quirk_data->has_headphone_gain) {
4717 if (spec->cur_out_type != HEADPHONE_OUT) {
4718 if (quirk_data->is_ae_series)
4719 ae5_headphone_gain_set(codec, 2);
4721 zxr_headphone_gain_set(codec, 0);
4723 if (quirk_data->is_ae_series)
4724 ae5_headphone_gain_set(codec,
4725 spec->ae5_headphone_gain_val);
4727 zxr_headphone_gain_set(codec,
4728 spec->zxr_gain_set);
4735 static void ca0132_set_out_node_pincfg(struct hda_codec *codec, hda_nid_t nid,
4736 bool out_enable, bool hp_enable)
4738 unsigned int pin_ctl;
4740 pin_ctl = snd_hda_codec_read(codec, nid, 0,
4741 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4743 pin_ctl = hp_enable ? pin_ctl | PIN_HP_AMP : pin_ctl & ~PIN_HP_AMP;
4744 pin_ctl = out_enable ? pin_ctl | PIN_OUT : pin_ctl & ~PIN_OUT;
4745 snd_hda_set_pin_ctl(codec, nid, pin_ctl);
4749 * This function behaves similarly to the ca0132_select_out funciton above,
4750 * except with a few differences. It adds the ability to select the current
4751 * output with an enumerated control "output source" if the auto detect
4752 * mute switch is set to off. If the auto detect mute switch is enabled, it
4753 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
4754 * It also adds the ability to auto-detect the front headphone port.
4756 static int ca0132_alt_select_out(struct hda_codec *codec)
4758 struct ca0132_spec *spec = codec->spec;
4759 unsigned int tmp, outfx_set;
4763 /* Default Headphone is rear headphone */
4764 hda_nid_t headphone_nid = spec->out_pins[1];
4766 codec_dbg(codec, "%s\n", __func__);
4768 snd_hda_power_up_pm(codec);
4770 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4773 * If headphone rear or front is plugged in, set to headphone.
4774 * If neither is plugged in, set to rear line out. Only if
4775 * hp/speaker auto detect is enabled.
4778 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
4779 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
4782 spec->cur_out_type = HEADPHONE_OUT;
4784 spec->cur_out_type = SPEAKER_OUT;
4786 spec->cur_out_type = spec->out_enum_val;
4788 outfx_set = spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID];
4790 /* Begin DSP output switch, mute DSP volume. */
4791 err = dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_MUTE, FLOAT_ONE);
4795 if (ca0132_alt_select_out_quirk_set(codec) < 0)
4798 switch (spec->cur_out_type) {
4800 codec_dbg(codec, "%s speaker\n", __func__);
4803 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4804 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4806 /* Disable headphone node. */
4807 ca0132_set_out_node_pincfg(codec, spec->out_pins[1], 0, 0);
4808 /* Set front L-R to output. */
4809 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 1, 0);
4810 /* Set Center/LFE to output. */
4811 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 1, 0);
4812 /* Set rear surround to output. */
4813 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 1, 0);
4816 * Without PlayEnhancement being enabled, if we've got a 2.0
4817 * setup, set it to floating point eight to disable any DSP
4818 * processing effects.
4820 if (!outfx_set && spec->channel_cfg_val == SPEAKER_CHANNELS_2_0)
4823 tmp = speaker_channel_cfgs[spec->channel_cfg_val].val;
4825 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4831 codec_dbg(codec, "%s hp\n", __func__);
4832 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4833 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4835 /* Disable all speaker nodes. */
4836 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 0, 0);
4837 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 0, 0);
4838 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 0, 0);
4840 /* enable headphone, either front or rear */
4841 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4842 headphone_nid = spec->out_pins[2];
4843 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4844 headphone_nid = spec->out_pins[1];
4846 ca0132_set_out_node_pincfg(codec, headphone_nid, 1, 1);
4849 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4851 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4858 * If output effects are enabled, set the X-Bass effect value again to
4859 * make sure that it's properly enabled/disabled for speaker
4860 * configurations with an LFE channel.
4863 ca0132_effects_set(codec, X_BASS,
4864 spec->effects_switch[X_BASS - EFFECT_START_NID]);
4866 /* Set speaker EQ bypass attenuation to 0. */
4867 err = dspio_set_uint_param(codec, 0x8f, 0x01, FLOAT_ZERO);
4872 * Although unused on all cards but the AE series, this is always set
4873 * to zero when setting the output.
4875 err = dspio_set_uint_param(codec, 0x96,
4876 SPEAKER_TUNING_USE_SPEAKER_EQ, FLOAT_ZERO);
4880 if (spec->cur_out_type == SPEAKER_OUT)
4881 err = ca0132_alt_surround_set_bass_redirection(codec,
4882 spec->bass_redirection_val);
4884 err = ca0132_alt_surround_set_bass_redirection(codec, 0);
4886 /* Unmute DSP now that we're done with output selection. */
4887 err = dspio_set_uint_param(codec, 0x96,
4888 SPEAKER_TUNING_MUTE, FLOAT_ZERO);
4892 if (spec->cur_out_type == SPEAKER_OUT) {
4893 err = ca0132_alt_set_full_range_speaker(codec);
4899 snd_hda_power_down_pm(codec);
4901 return err < 0 ? err : 0;
4904 static void ca0132_unsol_hp_delayed(struct work_struct *work)
4906 struct ca0132_spec *spec = container_of(
4907 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
4908 struct hda_jack_tbl *jack;
4910 if (ca0132_use_alt_functions(spec))
4911 ca0132_alt_select_out(spec->codec);
4913 ca0132_select_out(spec->codec);
4915 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4917 jack->block_report = 0;
4918 snd_hda_jack_report_sync(spec->codec);
4922 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4923 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4924 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4925 static int stop_mic1(struct hda_codec *codec);
4926 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4927 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4930 * Select the active VIP source
4932 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4934 struct ca0132_spec *spec = codec->spec;
4937 if (spec->dsp_state != DSP_DOWNLOADED)
4940 /* if CrystalVoice if off, vipsource should be 0 */
4941 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4943 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4944 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4945 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4946 if (spec->cur_mic_type == DIGITAL_MIC)
4950 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4952 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4954 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4955 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4956 if (spec->cur_mic_type == DIGITAL_MIC)
4960 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4962 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4964 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4970 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4972 struct ca0132_spec *spec = codec->spec;
4975 if (spec->dsp_state != DSP_DOWNLOADED)
4978 codec_dbg(codec, "%s\n", __func__);
4980 chipio_set_stream_control(codec, 0x03, 0);
4981 chipio_set_stream_control(codec, 0x04, 0);
4983 /* if CrystalVoice is off, vipsource should be 0 */
4984 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4985 (val == 0) || spec->in_enum_val == REAR_LINE_IN) {
4986 codec_dbg(codec, "%s: off.", __func__);
4987 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4990 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4992 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4993 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4994 if (ca0132_quirk(spec) == QUIRK_R3DI)
4995 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4998 if (spec->in_enum_val == REAR_LINE_IN)
5001 if (ca0132_quirk(spec) == QUIRK_SBZ)
5007 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5010 codec_dbg(codec, "%s: on.", __func__);
5011 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
5012 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
5013 if (ca0132_quirk(spec) == QUIRK_R3DI)
5014 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
5016 if (spec->effects_switch[VOICE_FOCUS - EFFECT_START_NID])
5020 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5023 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
5026 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
5029 chipio_set_stream_control(codec, 0x03, 1);
5030 chipio_set_stream_control(codec, 0x04, 1);
5036 * Select the active microphone.
5037 * If autodetect is enabled, mic will be selected based on jack detection.
5038 * If jack inserted, ext.mic will be selected, else built-in mic
5039 * If autodetect is disabled, mic will be selected based on selection.
5041 static int ca0132_select_mic(struct hda_codec *codec)
5043 struct ca0132_spec *spec = codec->spec;
5047 codec_dbg(codec, "ca0132_select_mic\n");
5049 snd_hda_power_up_pm(codec);
5051 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5054 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
5057 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
5060 spec->cur_mic_type = LINE_MIC_IN;
5062 spec->cur_mic_type = DIGITAL_MIC;
5064 if (spec->cur_mic_type == DIGITAL_MIC) {
5065 /* enable digital Mic */
5066 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
5067 ca0132_set_dmic(codec, 1);
5068 ca0132_mic_boost_set(codec, 0);
5069 /* set voice focus */
5070 ca0132_effects_set(codec, VOICE_FOCUS,
5071 spec->effects_switch
5072 [VOICE_FOCUS - EFFECT_START_NID]);
5074 /* disable digital Mic */
5075 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
5076 ca0132_set_dmic(codec, 0);
5077 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
5078 /* disable voice focus */
5079 ca0132_effects_set(codec, VOICE_FOCUS, 0);
5082 snd_hda_power_down_pm(codec);
5088 * Select the active input.
5089 * Mic detection isn't used, because it's kind of pointless on the SBZ.
5090 * The front mic has no jack-detection, so the only way to switch to it
5091 * is to do it manually in alsamixer.
5093 static int ca0132_alt_select_in(struct hda_codec *codec)
5095 struct ca0132_spec *spec = codec->spec;
5098 codec_dbg(codec, "%s\n", __func__);
5100 snd_hda_power_up_pm(codec);
5102 chipio_set_stream_control(codec, 0x03, 0);
5103 chipio_set_stream_control(codec, 0x04, 0);
5105 spec->cur_mic_type = spec->in_enum_val;
5107 switch (spec->cur_mic_type) {
5109 switch (ca0132_quirk(spec)) {
5112 ca0113_mmio_gpio_set(codec, 0, false);
5119 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
5123 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5127 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5129 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5131 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5133 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5140 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5141 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5142 if (ca0132_quirk(spec) == QUIRK_R3DI)
5143 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5145 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5147 chipio_set_stream_control(codec, 0x03, 1);
5148 chipio_set_stream_control(codec, 0x04, 1);
5149 switch (ca0132_quirk(spec)) {
5151 chipio_write(codec, 0x18B098, 0x0000000C);
5152 chipio_write(codec, 0x18B09C, 0x0000000C);
5155 chipio_write(codec, 0x18B098, 0x0000000C);
5156 chipio_write(codec, 0x18B09C, 0x000000CC);
5159 chipio_write(codec, 0x18B098, 0x0000000C);
5160 chipio_write(codec, 0x18B09C, 0x0000004C);
5165 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5168 ca0132_mic_boost_set(codec, 0);
5169 switch (ca0132_quirk(spec)) {
5172 ca0113_mmio_gpio_set(codec, 0, false);
5175 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
5178 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5181 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5182 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5184 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5186 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5192 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5193 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5194 if (ca0132_quirk(spec) == QUIRK_R3DI)
5195 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5197 if (ca0132_quirk(spec) == QUIRK_AE7)
5201 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5203 switch (ca0132_quirk(spec)) {
5206 chipio_write(codec, 0x18B098, 0x00000000);
5207 chipio_write(codec, 0x18B09C, 0x00000000);
5212 chipio_set_stream_control(codec, 0x03, 1);
5213 chipio_set_stream_control(codec, 0x04, 1);
5216 switch (ca0132_quirk(spec)) {
5219 ca0113_mmio_gpio_set(codec, 0, true);
5220 ca0113_mmio_gpio_set(codec, 5, false);
5224 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
5228 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5236 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5237 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5238 if (ca0132_quirk(spec) == QUIRK_R3DI)
5239 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5241 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5243 chipio_set_stream_control(codec, 0x03, 1);
5244 chipio_set_stream_control(codec, 0x04, 1);
5246 switch (ca0132_quirk(spec)) {
5248 chipio_write(codec, 0x18B098, 0x0000000C);
5249 chipio_write(codec, 0x18B09C, 0x000000CC);
5252 chipio_write(codec, 0x18B098, 0x0000000C);
5253 chipio_write(codec, 0x18B09C, 0x0000004C);
5258 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5261 ca0132_cvoice_switch_set(codec);
5263 snd_hda_power_down_pm(codec);
5268 * Check if VNODE settings take effect immediately.
5270 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
5272 hda_nid_t *shared_nid)
5274 struct ca0132_spec *spec = codec->spec;
5279 nid = spec->shared_out_nid;
5282 nid = spec->shared_mic_nid;
5295 * The following functions are control change helpers.
5296 * They return 0 if no changed. Return 1 if changed.
5298 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
5300 struct ca0132_spec *spec = codec->spec;
5303 /* based on CrystalVoice state to enable VoiceFX. */
5305 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
5306 FLOAT_ONE : FLOAT_ZERO;
5311 dspio_set_uint_param(codec, ca0132_voicefx.mid,
5312 ca0132_voicefx.reqs[0], tmp);
5318 * Set the effects parameters
5320 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
5322 struct ca0132_spec *spec = codec->spec;
5323 unsigned int on, tmp, channel_cfg;
5324 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
5326 int idx = nid - EFFECT_START_NID;
5328 if ((idx < 0) || (idx >= num_fx))
5329 return 0; /* no changed */
5331 /* for out effect, qualify with PE */
5332 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
5333 /* if PE if off, turn off out effects. */
5334 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
5336 if (spec->cur_out_type == SPEAKER_OUT && nid == X_BASS) {
5337 channel_cfg = spec->channel_cfg_val;
5338 if (channel_cfg != SPEAKER_CHANNELS_2_0 &&
5339 channel_cfg != SPEAKER_CHANNELS_4_0)
5344 /* for in effect, qualify with CrystalVoice */
5345 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
5346 /* if CrystalVoice if off, turn off in effects. */
5347 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
5350 /* Voice Focus applies to 2-ch Mic, Digital Mic */
5351 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
5354 /* If Voice Focus on SBZ, set to two channel. */
5355 if ((nid == VOICE_FOCUS) && ca0132_use_pci_mmio(spec)
5356 && (spec->cur_mic_type != REAR_LINE_IN)) {
5357 if (spec->effects_switch[CRYSTAL_VOICE -
5358 EFFECT_START_NID]) {
5360 if (spec->effects_switch[VOICE_FOCUS -
5361 EFFECT_START_NID]) {
5367 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5371 * For SBZ noise reduction, there's an extra command
5372 * to module ID 0x47. No clue why.
5374 if ((nid == NOISE_REDUCTION) && ca0132_use_pci_mmio(spec)
5375 && (spec->cur_mic_type != REAR_LINE_IN)) {
5376 if (spec->effects_switch[CRYSTAL_VOICE -
5377 EFFECT_START_NID]) {
5378 if (spec->effects_switch[NOISE_REDUCTION -
5386 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
5389 /* If rear line in disable effects. */
5390 if (ca0132_use_alt_functions(spec) &&
5391 spec->in_enum_val == REAR_LINE_IN)
5395 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
5398 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
5399 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5400 ca0132_effects[idx].reqs[0], on);
5403 return 0; /* no changed */
5409 * Turn on/off Playback Enhancements
5411 static int ca0132_pe_switch_set(struct hda_codec *codec)
5413 struct ca0132_spec *spec = codec->spec;
5417 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
5418 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
5420 if (ca0132_use_alt_functions(spec))
5421 ca0132_alt_select_out(codec);
5423 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
5424 nid = OUT_EFFECT_START_NID;
5425 /* PE affects all out effects */
5426 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
5427 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5432 /* Check if Mic1 is streaming, if so, stop streaming */
5433 static int stop_mic1(struct hda_codec *codec)
5435 struct ca0132_spec *spec = codec->spec;
5436 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
5437 AC_VERB_GET_CONV, 0);
5439 snd_hda_codec_write(codec, spec->adcs[0], 0,
5440 AC_VERB_SET_CHANNEL_STREAMID,
5445 /* Resume Mic1 streaming if it was stopped. */
5446 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
5448 struct ca0132_spec *spec = codec->spec;
5449 /* Restore the previous stream and channel */
5451 snd_hda_codec_write(codec, spec->adcs[0], 0,
5452 AC_VERB_SET_CHANNEL_STREAMID,
5457 * Turn on/off CrystalVoice
5459 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
5461 struct ca0132_spec *spec = codec->spec;
5464 unsigned int oldval;
5466 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
5467 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
5469 i = IN_EFFECT_START_NID - EFFECT_START_NID;
5470 nid = IN_EFFECT_START_NID;
5471 /* CrystalVoice affects all in effects */
5472 for (; nid < IN_EFFECT_END_NID; nid++, i++)
5473 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5475 /* including VoiceFX */
5476 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
5478 /* set correct vipsource */
5479 oldval = stop_mic1(codec);
5480 if (ca0132_use_alt_functions(spec))
5481 ret |= ca0132_alt_set_vipsource(codec, 1);
5483 ret |= ca0132_set_vipsource(codec, 1);
5484 resume_mic1(codec, oldval);
5488 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
5490 struct ca0132_spec *spec = codec->spec;
5494 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5495 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
5497 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5498 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
5503 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
5505 struct ca0132_spec *spec = codec->spec;
5508 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5509 HDA_INPUT, 0, HDA_AMP_VOLMASK, val);
5513 static int ae5_headphone_gain_set(struct hda_codec *codec, long val)
5517 for (i = 0; i < 4; i++)
5518 ca0113_mmio_command_set(codec, 0x48, 0x11 + i,
5519 ae5_headphone_gain_presets[val].vals[i]);
5524 * gpio pin 1 is a relay that switches on/off, apparently setting the headphone
5525 * amplifier to handle a 600 ohm load.
5527 static int zxr_headphone_gain_set(struct hda_codec *codec, long val)
5529 ca0113_mmio_gpio_set(codec, 1, val);
5534 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
5535 struct snd_ctl_elem_value *ucontrol)
5537 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5538 hda_nid_t nid = get_amp_nid(kcontrol);
5539 hda_nid_t shared_nid = 0;
5542 struct ca0132_spec *spec = codec->spec;
5545 if (nid == VNID_HP_SEL) {
5547 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5549 if (ca0132_use_alt_functions(spec))
5550 ca0132_alt_select_out(codec);
5552 ca0132_select_out(codec);
5557 if (nid == VNID_AMIC1_SEL) {
5559 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5561 ca0132_select_mic(codec);
5565 if (nid == VNID_HP_ASEL) {
5566 if (ca0132_use_alt_functions(spec))
5567 ca0132_alt_select_out(codec);
5569 ca0132_select_out(codec);
5573 if (nid == VNID_AMIC1_ASEL) {
5574 ca0132_select_mic(codec);
5578 /* if effective conditions, then update hw immediately. */
5579 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5581 int dir = get_amp_direction(kcontrol);
5582 int ch = get_amp_channels(kcontrol);
5585 mutex_lock(&codec->control_mutex);
5586 pval = kcontrol->private_value;
5587 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5589 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
5590 kcontrol->private_value = pval;
5591 mutex_unlock(&codec->control_mutex);
5596 /* End of control change helpers. */
5598 static void ca0132_alt_bass_redirection_xover_set(struct hda_codec *codec,
5601 snd_hda_power_up(codec);
5603 dspio_set_param(codec, 0x96, 0x20, SPEAKER_BASS_REDIRECT_XOVER_FREQ,
5604 &(float_xbass_xover_lookup[idx]), sizeof(unsigned int));
5606 snd_hda_power_down(codec);
5610 * Below I've added controls to mess with the effect levels, I've only enabled
5611 * them on the Sound Blaster Z, but they would probably also work on the
5612 * Chromebook. I figured they were probably tuned specifically for it, and left
5616 /* Sets DSP effect level from the sliders above the controls */
5618 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
5619 const unsigned int *lookup, int idx)
5624 * For X_BASS, req 2 is actually crossover freq instead of
5632 snd_hda_power_up(codec);
5633 if (nid == XBASS_XOVER) {
5634 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5635 if (ca0132_effects[i].nid == X_BASS)
5638 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5639 ca0132_effects[i].reqs[1],
5640 &(lookup[idx - 1]), sizeof(unsigned int));
5642 /* Find the actual effect structure */
5643 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5644 if (nid == ca0132_effects[i].nid)
5647 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5648 ca0132_effects[i].reqs[y],
5649 &(lookup[idx]), sizeof(unsigned int));
5652 snd_hda_power_down(codec);
5657 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol *kcontrol,
5658 struct snd_ctl_elem_value *ucontrol)
5660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5661 struct ca0132_spec *spec = codec->spec;
5662 long *valp = ucontrol->value.integer.value;
5663 hda_nid_t nid = get_amp_nid(kcontrol);
5665 if (nid == BASS_REDIRECTION_XOVER)
5666 *valp = spec->bass_redirect_xover_freq;
5668 *valp = spec->xbass_xover_freq;
5673 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol *kcontrol,
5674 struct snd_ctl_elem_value *ucontrol)
5676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5677 struct ca0132_spec *spec = codec->spec;
5678 hda_nid_t nid = get_amp_nid(kcontrol);
5679 long *valp = ucontrol->value.integer.value;
5680 int idx = nid - OUT_EFFECT_START_NID;
5682 *valp = spec->fx_ctl_val[idx];
5687 * The X-bass crossover starts at 10hz, so the min is 1. The
5688 * frequency is set in multiples of 10.
5690 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol *kcontrol,
5691 struct snd_ctl_elem_info *uinfo)
5693 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5695 uinfo->value.integer.min = 1;
5696 uinfo->value.integer.max = 100;
5697 uinfo->value.integer.step = 1;
5702 static int ca0132_alt_effect_slider_info(struct snd_kcontrol *kcontrol,
5703 struct snd_ctl_elem_info *uinfo)
5705 int chs = get_amp_channels(kcontrol);
5707 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5708 uinfo->count = chs == 3 ? 2 : 1;
5709 uinfo->value.integer.min = 0;
5710 uinfo->value.integer.max = 100;
5711 uinfo->value.integer.step = 1;
5716 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol *kcontrol,
5717 struct snd_ctl_elem_value *ucontrol)
5719 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5720 struct ca0132_spec *spec = codec->spec;
5721 hda_nid_t nid = get_amp_nid(kcontrol);
5722 long *valp = ucontrol->value.integer.value;
5726 if (nid == BASS_REDIRECTION_XOVER)
5727 cur_val = &spec->bass_redirect_xover_freq;
5729 cur_val = &spec->xbass_xover_freq;
5732 if (*cur_val == *valp)
5738 if (nid == BASS_REDIRECTION_XOVER)
5739 ca0132_alt_bass_redirection_xover_set(codec, *cur_val);
5741 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
5746 static int ca0132_alt_effect_slider_put(struct snd_kcontrol *kcontrol,
5747 struct snd_ctl_elem_value *ucontrol)
5749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5750 struct ca0132_spec *spec = codec->spec;
5751 hda_nid_t nid = get_amp_nid(kcontrol);
5752 long *valp = ucontrol->value.integer.value;
5755 idx = nid - EFFECT_START_NID;
5757 if (spec->fx_ctl_val[idx] == *valp)
5760 spec->fx_ctl_val[idx] = *valp;
5763 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
5770 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
5771 * only has off or full 30 dB, and didn't like making a volume slider that has
5772 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
5774 #define MIC_BOOST_NUM_OF_STEPS 4
5775 #define MIC_BOOST_ENUM_MAX_STRLEN 10
5777 static int ca0132_alt_mic_boost_info(struct snd_kcontrol *kcontrol,
5778 struct snd_ctl_elem_info *uinfo)
5781 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5783 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5785 uinfo->value.enumerated.items = MIC_BOOST_NUM_OF_STEPS;
5786 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS)
5787 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1;
5788 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx);
5789 strcpy(uinfo->value.enumerated.name, namestr);
5793 static int ca0132_alt_mic_boost_get(struct snd_kcontrol *kcontrol,
5794 struct snd_ctl_elem_value *ucontrol)
5796 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5797 struct ca0132_spec *spec = codec->spec;
5799 ucontrol->value.enumerated.item[0] = spec->mic_boost_enum_val;
5803 static int ca0132_alt_mic_boost_put(struct snd_kcontrol *kcontrol,
5804 struct snd_ctl_elem_value *ucontrol)
5806 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5807 struct ca0132_spec *spec = codec->spec;
5808 int sel = ucontrol->value.enumerated.item[0];
5809 unsigned int items = MIC_BOOST_NUM_OF_STEPS;
5814 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
5817 spec->mic_boost_enum_val = sel;
5819 if (spec->in_enum_val != REAR_LINE_IN)
5820 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5826 * Sound BlasterX AE-5 Headphone Gain Controls.
5828 #define AE5_HEADPHONE_GAIN_MAX 3
5829 static int ae5_headphone_gain_info(struct snd_kcontrol *kcontrol,
5830 struct snd_ctl_elem_info *uinfo)
5832 char *sfx = " Ohms)";
5833 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5835 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5837 uinfo->value.enumerated.items = AE5_HEADPHONE_GAIN_MAX;
5838 if (uinfo->value.enumerated.item >= AE5_HEADPHONE_GAIN_MAX)
5839 uinfo->value.enumerated.item = AE5_HEADPHONE_GAIN_MAX - 1;
5840 sprintf(namestr, "%s %s",
5841 ae5_headphone_gain_presets[uinfo->value.enumerated.item].name,
5843 strcpy(uinfo->value.enumerated.name, namestr);
5847 static int ae5_headphone_gain_get(struct snd_kcontrol *kcontrol,
5848 struct snd_ctl_elem_value *ucontrol)
5850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5851 struct ca0132_spec *spec = codec->spec;
5853 ucontrol->value.enumerated.item[0] = spec->ae5_headphone_gain_val;
5857 static int ae5_headphone_gain_put(struct snd_kcontrol *kcontrol,
5858 struct snd_ctl_elem_value *ucontrol)
5860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5861 struct ca0132_spec *spec = codec->spec;
5862 int sel = ucontrol->value.enumerated.item[0];
5863 unsigned int items = AE5_HEADPHONE_GAIN_MAX;
5868 codec_dbg(codec, "ae5_headphone_gain: boost=%d\n",
5871 spec->ae5_headphone_gain_val = sel;
5873 if (spec->out_enum_val == HEADPHONE_OUT)
5874 ae5_headphone_gain_set(codec, spec->ae5_headphone_gain_val);
5880 * Sound BlasterX AE-5 sound filter enumerated control.
5882 #define AE5_SOUND_FILTER_MAX 3
5884 static int ae5_sound_filter_info(struct snd_kcontrol *kcontrol,
5885 struct snd_ctl_elem_info *uinfo)
5887 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5889 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5891 uinfo->value.enumerated.items = AE5_SOUND_FILTER_MAX;
5892 if (uinfo->value.enumerated.item >= AE5_SOUND_FILTER_MAX)
5893 uinfo->value.enumerated.item = AE5_SOUND_FILTER_MAX - 1;
5894 sprintf(namestr, "%s",
5895 ae5_filter_presets[uinfo->value.enumerated.item].name);
5896 strcpy(uinfo->value.enumerated.name, namestr);
5900 static int ae5_sound_filter_get(struct snd_kcontrol *kcontrol,
5901 struct snd_ctl_elem_value *ucontrol)
5903 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5904 struct ca0132_spec *spec = codec->spec;
5906 ucontrol->value.enumerated.item[0] = spec->ae5_filter_val;
5910 static int ae5_sound_filter_put(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 int sel = ucontrol->value.enumerated.item[0];
5916 unsigned int items = AE5_SOUND_FILTER_MAX;
5921 codec_dbg(codec, "ae5_sound_filter: %s\n",
5922 ae5_filter_presets[sel].name);
5924 spec->ae5_filter_val = sel;
5926 ca0113_mmio_command_set_type2(codec, 0x48, 0x07,
5927 ae5_filter_presets[sel].val);
5933 * Input Select Control for alternative ca0132 codecs. This exists because
5934 * front microphone has no auto-detect, and we need a way to set the rear
5937 static int ca0132_alt_input_source_info(struct snd_kcontrol *kcontrol,
5938 struct snd_ctl_elem_info *uinfo)
5940 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5942 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS;
5943 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS)
5944 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1;
5945 strcpy(uinfo->value.enumerated.name,
5946 in_src_str[uinfo->value.enumerated.item]);
5950 static int ca0132_alt_input_source_get(struct snd_kcontrol *kcontrol,
5951 struct snd_ctl_elem_value *ucontrol)
5953 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5954 struct ca0132_spec *spec = codec->spec;
5956 ucontrol->value.enumerated.item[0] = spec->in_enum_val;
5960 static int ca0132_alt_input_source_put(struct snd_kcontrol *kcontrol,
5961 struct snd_ctl_elem_value *ucontrol)
5963 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5964 struct ca0132_spec *spec = codec->spec;
5965 int sel = ucontrol->value.enumerated.item[0];
5966 unsigned int items = IN_SRC_NUM_OF_INPUTS;
5969 * The AE-7 has no front microphone, so limit items to 2: rear mic and
5972 if (ca0132_quirk(spec) == QUIRK_AE7)
5978 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5979 sel, in_src_str[sel]);
5981 spec->in_enum_val = sel;
5983 ca0132_alt_select_in(codec);
5988 /* Sound Blaster Z Output Select Control */
5989 static int ca0132_alt_output_select_get_info(struct snd_kcontrol *kcontrol,
5990 struct snd_ctl_elem_info *uinfo)
5992 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5994 uinfo->value.enumerated.items = NUM_OF_OUTPUTS;
5995 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS)
5996 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1;
5997 strcpy(uinfo->value.enumerated.name,
5998 out_type_str[uinfo->value.enumerated.item]);
6002 static int ca0132_alt_output_select_get(struct snd_kcontrol *kcontrol,
6003 struct snd_ctl_elem_value *ucontrol)
6005 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6006 struct ca0132_spec *spec = codec->spec;
6008 ucontrol->value.enumerated.item[0] = spec->out_enum_val;
6012 static int ca0132_alt_output_select_put(struct snd_kcontrol *kcontrol,
6013 struct snd_ctl_elem_value *ucontrol)
6015 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6016 struct ca0132_spec *spec = codec->spec;
6017 int sel = ucontrol->value.enumerated.item[0];
6018 unsigned int items = NUM_OF_OUTPUTS;
6019 unsigned int auto_jack;
6024 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
6025 sel, out_type_str[sel]);
6027 spec->out_enum_val = sel;
6029 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
6032 ca0132_alt_select_out(codec);
6037 /* Select surround output type: 2.1, 4.0, 4.1, or 5.1. */
6038 static int ca0132_alt_speaker_channel_cfg_get_info(struct snd_kcontrol *kcontrol,
6039 struct snd_ctl_elem_info *uinfo)
6041 unsigned int items = SPEAKER_CHANNEL_CFG_COUNT;
6043 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6045 uinfo->value.enumerated.items = items;
6046 if (uinfo->value.enumerated.item >= items)
6047 uinfo->value.enumerated.item = items - 1;
6048 strcpy(uinfo->value.enumerated.name,
6049 speaker_channel_cfgs[uinfo->value.enumerated.item].name);
6053 static int ca0132_alt_speaker_channel_cfg_get(struct snd_kcontrol *kcontrol,
6054 struct snd_ctl_elem_value *ucontrol)
6056 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6057 struct ca0132_spec *spec = codec->spec;
6059 ucontrol->value.enumerated.item[0] = spec->channel_cfg_val;
6063 static int ca0132_alt_speaker_channel_cfg_put(struct snd_kcontrol *kcontrol,
6064 struct snd_ctl_elem_value *ucontrol)
6066 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6067 struct ca0132_spec *spec = codec->spec;
6068 int sel = ucontrol->value.enumerated.item[0];
6069 unsigned int items = SPEAKER_CHANNEL_CFG_COUNT;
6074 codec_dbg(codec, "ca0132_alt_speaker_channels: sel=%d, channels=%s\n",
6075 sel, speaker_channel_cfgs[sel].name);
6077 spec->channel_cfg_val = sel;
6079 if (spec->out_enum_val == SPEAKER_OUT)
6080 ca0132_alt_select_out(codec);
6086 * Smart Volume output setting control. Three different settings, Normal,
6087 * which takes the value from the smart volume slider. The two others, loud
6088 * and night, disregard the slider value and have uneditable values.
6090 #define NUM_OF_SVM_SETTINGS 3
6091 static const char *const out_svm_set_enum_str[3] = {"Normal", "Loud", "Night" };
6093 static int ca0132_alt_svm_setting_info(struct snd_kcontrol *kcontrol,
6094 struct snd_ctl_elem_info *uinfo)
6096 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6098 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS;
6099 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS)
6100 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1;
6101 strcpy(uinfo->value.enumerated.name,
6102 out_svm_set_enum_str[uinfo->value.enumerated.item]);
6106 static int ca0132_alt_svm_setting_get(struct snd_kcontrol *kcontrol,
6107 struct snd_ctl_elem_value *ucontrol)
6109 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6110 struct ca0132_spec *spec = codec->spec;
6112 ucontrol->value.enumerated.item[0] = spec->smart_volume_setting;
6116 static int ca0132_alt_svm_setting_put(struct snd_kcontrol *kcontrol,
6117 struct snd_ctl_elem_value *ucontrol)
6119 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6120 struct ca0132_spec *spec = codec->spec;
6121 int sel = ucontrol->value.enumerated.item[0];
6122 unsigned int items = NUM_OF_SVM_SETTINGS;
6123 unsigned int idx = SMART_VOLUME - EFFECT_START_NID;
6129 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
6130 sel, out_svm_set_enum_str[sel]);
6132 spec->smart_volume_setting = sel;
6148 /* Req 2 is the Smart Volume Setting req. */
6149 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
6150 ca0132_effects[idx].reqs[2], tmp);
6154 /* Sound Blaster Z EQ preset controls */
6155 static int ca0132_alt_eq_preset_info(struct snd_kcontrol *kcontrol,
6156 struct snd_ctl_elem_info *uinfo)
6158 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
6160 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6162 uinfo->value.enumerated.items = items;
6163 if (uinfo->value.enumerated.item >= items)
6164 uinfo->value.enumerated.item = items - 1;
6165 strcpy(uinfo->value.enumerated.name,
6166 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name);
6170 static int ca0132_alt_eq_preset_get(struct snd_kcontrol *kcontrol,
6171 struct snd_ctl_elem_value *ucontrol)
6173 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6174 struct ca0132_spec *spec = codec->spec;
6176 ucontrol->value.enumerated.item[0] = spec->eq_preset_val;
6180 static int ca0132_alt_eq_preset_put(struct snd_kcontrol *kcontrol,
6181 struct snd_ctl_elem_value *ucontrol)
6183 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6184 struct ca0132_spec *spec = codec->spec;
6186 int sel = ucontrol->value.enumerated.item[0];
6187 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
6192 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
6193 ca0132_alt_eq_presets[sel].name);
6196 * Default needs to qualify with CrystalVoice state.
6198 for (i = 0; i < EQ_PRESET_MAX_PARAM_COUNT; i++) {
6199 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
6200 ca0132_alt_eq_enum.reqs[i],
6201 ca0132_alt_eq_presets[sel].vals[i]);
6207 spec->eq_preset_val = sel;
6212 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
6213 struct snd_ctl_elem_info *uinfo)
6215 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
6217 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6219 uinfo->value.enumerated.items = items;
6220 if (uinfo->value.enumerated.item >= items)
6221 uinfo->value.enumerated.item = items - 1;
6222 strcpy(uinfo->value.enumerated.name,
6223 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
6227 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
6228 struct snd_ctl_elem_value *ucontrol)
6230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6231 struct ca0132_spec *spec = codec->spec;
6233 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
6237 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
6238 struct snd_ctl_elem_value *ucontrol)
6240 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6241 struct ca0132_spec *spec = codec->spec;
6243 int sel = ucontrol->value.enumerated.item[0];
6245 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
6248 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
6249 sel, ca0132_voicefx_presets[sel].name);
6253 * Default needs to qualify with CrystalVoice state.
6255 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
6256 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
6257 ca0132_voicefx.reqs[i],
6258 ca0132_voicefx_presets[sel].vals[i]);
6264 spec->voicefx_val = sel;
6265 /* enable voice fx */
6266 ca0132_voicefx_set(codec, (sel ? 1 : 0));
6272 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
6273 struct snd_ctl_elem_value *ucontrol)
6275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6276 struct ca0132_spec *spec = codec->spec;
6277 hda_nid_t nid = get_amp_nid(kcontrol);
6278 int ch = get_amp_channels(kcontrol);
6279 long *valp = ucontrol->value.integer.value;
6282 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
6284 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
6288 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
6294 /* effects, include PE and CrystalVoice */
6295 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
6296 *valp = spec->effects_switch[nid - EFFECT_START_NID];
6301 if (nid == spec->input_pins[0]) {
6302 *valp = spec->cur_mic_boost;
6306 if (nid == ZXR_HEADPHONE_GAIN) {
6307 *valp = spec->zxr_gain_set;
6311 if (nid == SPEAKER_FULL_RANGE_FRONT || nid == SPEAKER_FULL_RANGE_REAR) {
6312 *valp = spec->speaker_range_val[nid - SPEAKER_FULL_RANGE_FRONT];
6316 if (nid == BASS_REDIRECTION) {
6317 *valp = spec->bass_redirection_val;
6324 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
6325 struct snd_ctl_elem_value *ucontrol)
6327 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6328 struct ca0132_spec *spec = codec->spec;
6329 hda_nid_t nid = get_amp_nid(kcontrol);
6330 int ch = get_amp_channels(kcontrol);
6331 long *valp = ucontrol->value.integer.value;
6334 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
6337 snd_hda_power_up(codec);
6339 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
6341 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
6345 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
6348 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
6353 if (nid == PLAY_ENHANCEMENT) {
6354 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6355 changed = ca0132_pe_switch_set(codec);
6360 if (nid == CRYSTAL_VOICE) {
6361 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6362 changed = ca0132_cvoice_switch_set(codec);
6366 /* out and in effects */
6367 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
6368 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
6369 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6370 changed = ca0132_effects_set(codec, nid, *valp);
6375 if (nid == spec->input_pins[0]) {
6376 spec->cur_mic_boost = *valp;
6377 if (ca0132_use_alt_functions(spec)) {
6378 if (spec->in_enum_val != REAR_LINE_IN)
6379 changed = ca0132_mic_boost_set(codec, *valp);
6381 /* Mic boost does not apply to Digital Mic */
6382 if (spec->cur_mic_type != DIGITAL_MIC)
6383 changed = ca0132_mic_boost_set(codec, *valp);
6389 if (nid == ZXR_HEADPHONE_GAIN) {
6390 spec->zxr_gain_set = *valp;
6391 if (spec->cur_out_type == HEADPHONE_OUT)
6392 changed = zxr_headphone_gain_set(codec, *valp);
6399 if (nid == SPEAKER_FULL_RANGE_FRONT || nid == SPEAKER_FULL_RANGE_REAR) {
6400 spec->speaker_range_val[nid - SPEAKER_FULL_RANGE_FRONT] = *valp;
6401 if (spec->cur_out_type == SPEAKER_OUT)
6402 ca0132_alt_set_full_range_speaker(codec);
6407 if (nid == BASS_REDIRECTION) {
6408 spec->bass_redirection_val = *valp;
6409 if (spec->cur_out_type == SPEAKER_OUT)
6410 ca0132_alt_surround_set_bass_redirection(codec, *valp);
6416 snd_hda_power_down(codec);
6424 * Sets the internal DSP decibel level to match the DAC for output, and the
6425 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
6426 * all alternative codecs set DSP playback volume.
6428 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
6430 struct ca0132_spec *spec = codec->spec;
6431 unsigned int dsp_dir;
6432 unsigned int lookup_val;
6434 if (nid == VNID_SPK)
6435 dsp_dir = DSP_VOL_OUT;
6437 dsp_dir = DSP_VOL_IN;
6439 lookup_val = spec->vnode_lvol[nid - VNODE_START_NID];
6441 dspio_set_uint_param(codec,
6442 ca0132_alt_vol_ctls[dsp_dir].mid,
6443 ca0132_alt_vol_ctls[dsp_dir].reqs[0],
6444 float_vol_db_lookup[lookup_val]);
6446 lookup_val = spec->vnode_rvol[nid - VNODE_START_NID];
6448 dspio_set_uint_param(codec,
6449 ca0132_alt_vol_ctls[dsp_dir].mid,
6450 ca0132_alt_vol_ctls[dsp_dir].reqs[1],
6451 float_vol_db_lookup[lookup_val]);
6453 dspio_set_uint_param(codec,
6454 ca0132_alt_vol_ctls[dsp_dir].mid,
6455 ca0132_alt_vol_ctls[dsp_dir].reqs[2], FLOAT_ZERO);
6458 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
6459 struct snd_ctl_elem_info *uinfo)
6461 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6462 struct ca0132_spec *spec = codec->spec;
6463 hda_nid_t nid = get_amp_nid(kcontrol);
6464 int ch = get_amp_channels(kcontrol);
6465 int dir = get_amp_direction(kcontrol);
6471 /* follow shared_out info */
6472 nid = spec->shared_out_nid;
6473 mutex_lock(&codec->control_mutex);
6474 pval = kcontrol->private_value;
6475 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6476 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6477 kcontrol->private_value = pval;
6478 mutex_unlock(&codec->control_mutex);
6481 /* follow shared_mic info */
6482 nid = spec->shared_mic_nid;
6483 mutex_lock(&codec->control_mutex);
6484 pval = kcontrol->private_value;
6485 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6486 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6487 kcontrol->private_value = pval;
6488 mutex_unlock(&codec->control_mutex);
6491 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6496 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
6497 struct snd_ctl_elem_value *ucontrol)
6499 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6500 struct ca0132_spec *spec = codec->spec;
6501 hda_nid_t nid = get_amp_nid(kcontrol);
6502 int ch = get_amp_channels(kcontrol);
6503 long *valp = ucontrol->value.integer.value;
6505 /* store the left and right volume */
6507 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
6511 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
6517 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
6518 struct snd_ctl_elem_value *ucontrol)
6520 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6521 struct ca0132_spec *spec = codec->spec;
6522 hda_nid_t nid = get_amp_nid(kcontrol);
6523 int ch = get_amp_channels(kcontrol);
6524 long *valp = ucontrol->value.integer.value;
6525 hda_nid_t shared_nid = 0;
6529 /* store the left and right volume */
6531 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
6535 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
6539 /* if effective conditions, then update hw immediately. */
6540 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
6542 int dir = get_amp_direction(kcontrol);
6545 snd_hda_power_up(codec);
6546 mutex_lock(&codec->control_mutex);
6547 pval = kcontrol->private_value;
6548 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
6550 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6551 kcontrol->private_value = pval;
6552 mutex_unlock(&codec->control_mutex);
6553 snd_hda_power_down(codec);
6560 * This function is the same as the one above, because using an if statement
6561 * inside of the above volume control for the DSP volume would cause too much
6562 * lag. This is a lot more smooth.
6564 static int ca0132_alt_volume_put(struct snd_kcontrol *kcontrol,
6565 struct snd_ctl_elem_value *ucontrol)
6567 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6568 struct ca0132_spec *spec = codec->spec;
6569 hda_nid_t nid = get_amp_nid(kcontrol);
6570 int ch = get_amp_channels(kcontrol);
6571 long *valp = ucontrol->value.integer.value;
6584 /* store the left and right volume */
6586 spec->vnode_lvol[vnid - VNODE_START_NID] = *valp;
6590 spec->vnode_rvol[vnid - VNODE_START_NID] = *valp;
6594 snd_hda_power_up(codec);
6595 ca0132_alt_dsp_volume_put(codec, vnid);
6596 mutex_lock(&codec->control_mutex);
6597 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6598 mutex_unlock(&codec->control_mutex);
6599 snd_hda_power_down(codec);
6604 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
6605 unsigned int size, unsigned int __user *tlv)
6607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6608 struct ca0132_spec *spec = codec->spec;
6609 hda_nid_t nid = get_amp_nid(kcontrol);
6610 int ch = get_amp_channels(kcontrol);
6611 int dir = get_amp_direction(kcontrol);
6617 /* follow shared_out tlv */
6618 nid = spec->shared_out_nid;
6619 mutex_lock(&codec->control_mutex);
6620 pval = kcontrol->private_value;
6621 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6622 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6623 kcontrol->private_value = pval;
6624 mutex_unlock(&codec->control_mutex);
6627 /* follow shared_mic tlv */
6628 nid = spec->shared_mic_nid;
6629 mutex_lock(&codec->control_mutex);
6630 pval = kcontrol->private_value;
6631 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6632 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6633 kcontrol->private_value = pval;
6634 mutex_unlock(&codec->control_mutex);
6637 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6642 /* Add volume slider control for effect level */
6643 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
6644 const char *pfx, int dir)
6646 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6647 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6648 struct snd_kcontrol_new knew =
6649 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
6651 sprintf(namestr, "FX: %s %s Volume", pfx, dirstr[dir]);
6657 knew.info = ca0132_alt_xbass_xover_slider_info;
6658 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6659 knew.put = ca0132_alt_xbass_xover_slider_put;
6662 knew.info = ca0132_alt_effect_slider_info;
6663 knew.get = ca0132_alt_slider_ctl_get;
6664 knew.put = ca0132_alt_effect_slider_put;
6665 knew.private_value =
6666 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
6670 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6674 * Added FX: prefix for the alternative codecs, because otherwise the surround
6675 * effect would conflict with the Surround sound volume control. Also seems more
6676 * clear as to what the switches do. Left alone for others.
6678 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
6679 const char *pfx, int dir)
6681 struct ca0132_spec *spec = codec->spec;
6682 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6683 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6684 struct snd_kcontrol_new knew =
6685 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
6686 /* If using alt_controls, add FX: prefix. But, don't add FX:
6687 * prefix to OutFX or InFX enable controls.
6689 if (ca0132_use_alt_controls(spec) && (nid <= IN_EFFECT_END_NID))
6690 sprintf(namestr, "FX: %s %s Switch", pfx, dirstr[dir]);
6692 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
6694 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6697 static int add_voicefx(struct hda_codec *codec)
6699 struct snd_kcontrol_new knew =
6700 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
6701 VOICEFX, 1, 0, HDA_INPUT);
6702 knew.info = ca0132_voicefx_info;
6703 knew.get = ca0132_voicefx_get;
6704 knew.put = ca0132_voicefx_put;
6705 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
6708 /* Create the EQ Preset control */
6709 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
6711 struct snd_kcontrol_new knew =
6712 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum.name,
6713 EQ_PRESET_ENUM, 1, 0, HDA_OUTPUT);
6714 knew.info = ca0132_alt_eq_preset_info;
6715 knew.get = ca0132_alt_eq_preset_get;
6716 knew.put = ca0132_alt_eq_preset_put;
6717 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
6718 snd_ctl_new1(&knew, codec));
6722 * Add enumerated control for the three different settings of the smart volume
6723 * output effect. Normal just uses the slider value, and loud and night are
6724 * their own things that ignore that value.
6726 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
6728 struct snd_kcontrol_new knew =
6729 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
6730 SMART_VOLUME_ENUM, 1, 0, HDA_OUTPUT);
6731 knew.info = ca0132_alt_svm_setting_info;
6732 knew.get = ca0132_alt_svm_setting_get;
6733 knew.put = ca0132_alt_svm_setting_put;
6734 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
6735 snd_ctl_new1(&knew, codec));
6740 * Create an Output Select enumerated control for codecs with surround
6743 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
6745 struct snd_kcontrol_new knew =
6746 HDA_CODEC_MUTE_MONO("Output Select",
6747 OUTPUT_SOURCE_ENUM, 1, 0, HDA_OUTPUT);
6748 knew.info = ca0132_alt_output_select_get_info;
6749 knew.get = ca0132_alt_output_select_get;
6750 knew.put = ca0132_alt_output_select_put;
6751 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
6752 snd_ctl_new1(&knew, codec));
6756 * Add a control for selecting channel count on speaker output. Setting this
6757 * allows the DSP to do bass redirection and channel upmixing on surround
6760 static int ca0132_alt_add_speaker_channel_cfg_enum(struct hda_codec *codec)
6762 struct snd_kcontrol_new knew =
6763 HDA_CODEC_MUTE_MONO("Surround Channel Config",
6764 SPEAKER_CHANNEL_CFG_ENUM, 1, 0, HDA_OUTPUT);
6765 knew.info = ca0132_alt_speaker_channel_cfg_get_info;
6766 knew.get = ca0132_alt_speaker_channel_cfg_get;
6767 knew.put = ca0132_alt_speaker_channel_cfg_put;
6768 return snd_hda_ctl_add(codec, SPEAKER_CHANNEL_CFG_ENUM,
6769 snd_ctl_new1(&knew, codec));
6773 * Full range front stereo and rear surround switches. When these are set to
6774 * full range, the lower frequencies from these channels are no longer
6775 * redirected to the LFE channel.
6777 static int ca0132_alt_add_front_full_range_switch(struct hda_codec *codec)
6779 struct snd_kcontrol_new knew =
6780 CA0132_CODEC_MUTE_MONO("Full-Range Front Speakers",
6781 SPEAKER_FULL_RANGE_FRONT, 1, HDA_OUTPUT);
6783 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_FRONT,
6784 snd_ctl_new1(&knew, codec));
6787 static int ca0132_alt_add_rear_full_range_switch(struct hda_codec *codec)
6789 struct snd_kcontrol_new knew =
6790 CA0132_CODEC_MUTE_MONO("Full-Range Rear Speakers",
6791 SPEAKER_FULL_RANGE_REAR, 1, HDA_OUTPUT);
6793 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_REAR,
6794 snd_ctl_new1(&knew, codec));
6798 * Bass redirection redirects audio below the crossover frequency to the LFE
6799 * channel on speakers that are set as not being full-range. On configurations
6800 * without an LFE channel, it does nothing. Bass redirection seems to be the
6801 * replacement for X-Bass on configurations with an LFE channel.
6803 static int ca0132_alt_add_bass_redirection_crossover(struct hda_codec *codec)
6805 const char *namestr = "Bass Redirection Crossover";
6806 struct snd_kcontrol_new knew =
6807 HDA_CODEC_VOLUME_MONO(namestr, BASS_REDIRECTION_XOVER, 1, 0,
6811 knew.info = ca0132_alt_xbass_xover_slider_info;
6812 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6813 knew.put = ca0132_alt_xbass_xover_slider_put;
6815 return snd_hda_ctl_add(codec, BASS_REDIRECTION_XOVER,
6816 snd_ctl_new1(&knew, codec));
6819 static int ca0132_alt_add_bass_redirection_switch(struct hda_codec *codec)
6821 const char *namestr = "Bass Redirection";
6822 struct snd_kcontrol_new knew =
6823 CA0132_CODEC_MUTE_MONO(namestr, BASS_REDIRECTION, 1,
6826 return snd_hda_ctl_add(codec, BASS_REDIRECTION,
6827 snd_ctl_new1(&knew, codec));
6831 * Create an Input Source enumerated control for the alternate ca0132 codecs
6832 * because the front microphone has no auto-detect, and Line-in has to be set
6835 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
6837 struct snd_kcontrol_new knew =
6838 HDA_CODEC_MUTE_MONO("Input Source",
6839 INPUT_SOURCE_ENUM, 1, 0, HDA_INPUT);
6840 knew.info = ca0132_alt_input_source_info;
6841 knew.get = ca0132_alt_input_source_get;
6842 knew.put = ca0132_alt_input_source_put;
6843 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
6844 snd_ctl_new1(&knew, codec));
6848 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
6849 * more control than the original mic boost, which is either full 30dB or off.
6851 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
6853 struct snd_kcontrol_new knew =
6854 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
6855 MIC_BOOST_ENUM, 1, 0, HDA_INPUT);
6856 knew.info = ca0132_alt_mic_boost_info;
6857 knew.get = ca0132_alt_mic_boost_get;
6858 knew.put = ca0132_alt_mic_boost_put;
6859 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
6860 snd_ctl_new1(&knew, codec));
6865 * Add headphone gain enumerated control for the AE-5. This switches between
6866 * three modes, low, medium, and high. When non-headphone outputs are selected,
6867 * it is automatically set to high. This is the same behavior as Windows.
6869 static int ae5_add_headphone_gain_enum(struct hda_codec *codec)
6871 struct snd_kcontrol_new knew =
6872 HDA_CODEC_MUTE_MONO("AE-5: Headphone Gain",
6873 AE5_HEADPHONE_GAIN_ENUM, 1, 0, HDA_OUTPUT);
6874 knew.info = ae5_headphone_gain_info;
6875 knew.get = ae5_headphone_gain_get;
6876 knew.put = ae5_headphone_gain_put;
6877 return snd_hda_ctl_add(codec, AE5_HEADPHONE_GAIN_ENUM,
6878 snd_ctl_new1(&knew, codec));
6882 * Add sound filter enumerated control for the AE-5. This adds three different
6883 * settings: Slow Roll Off, Minimum Phase, and Fast Roll Off. From what I've
6884 * read into it, it changes the DAC's interpolation filter.
6886 static int ae5_add_sound_filter_enum(struct hda_codec *codec)
6888 struct snd_kcontrol_new knew =
6889 HDA_CODEC_MUTE_MONO("AE-5: Sound Filter",
6890 AE5_SOUND_FILTER_ENUM, 1, 0, HDA_OUTPUT);
6891 knew.info = ae5_sound_filter_info;
6892 knew.get = ae5_sound_filter_get;
6893 knew.put = ae5_sound_filter_put;
6894 return snd_hda_ctl_add(codec, AE5_SOUND_FILTER_ENUM,
6895 snd_ctl_new1(&knew, codec));
6898 static int zxr_add_headphone_gain_switch(struct hda_codec *codec)
6900 struct snd_kcontrol_new knew =
6901 CA0132_CODEC_MUTE_MONO("ZxR: 600 Ohm Gain",
6902 ZXR_HEADPHONE_GAIN, 1, HDA_OUTPUT);
6904 return snd_hda_ctl_add(codec, ZXR_HEADPHONE_GAIN,
6905 snd_ctl_new1(&knew, codec));
6909 * Need to create follower controls for the alternate codecs that have surround
6912 static const char * const ca0132_alt_follower_pfxs[] = {
6913 "Front", "Surround", "Center", "LFE", NULL,
6917 * Also need special channel map, because the default one is incorrect.
6918 * I think this has to do with the pin for rear surround being 0x11,
6919 * and the center/lfe being 0x10. Usually the pin order is the opposite.
6921 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps[] = {
6923 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
6925 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6926 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6928 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6929 SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE,
6930 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6934 /* Add the correct chmap for streams with 6 channels. */
6935 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
6938 struct hda_pcm *pcm;
6940 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
6941 struct hda_pcm_stream *hinfo =
6942 &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
6943 struct snd_pcm_chmap *chmap;
6944 const struct snd_pcm_chmap_elem *elem;
6946 elem = ca0132_alt_chmaps;
6947 if (hinfo->channels_max == 6) {
6948 err = snd_pcm_add_chmap_ctls(pcm->pcm,
6949 SNDRV_PCM_STREAM_PLAYBACK,
6950 elem, hinfo->channels_max, 0, &chmap);
6952 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
6958 * When changing Node IDs for Mixer Controls below, make sure to update
6959 * Node IDs in ca0132_config() as well.
6961 static const struct snd_kcontrol_new ca0132_mixer[] = {
6962 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
6963 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
6964 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6965 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6966 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
6967 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
6968 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6969 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6970 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
6971 0x12, 1, HDA_INPUT),
6972 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
6973 VNID_HP_SEL, 1, HDA_OUTPUT),
6974 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
6975 VNID_AMIC1_SEL, 1, HDA_INPUT),
6976 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6977 VNID_HP_ASEL, 1, HDA_OUTPUT),
6978 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
6979 VNID_AMIC1_ASEL, 1, HDA_INPUT),
6984 * Desktop specific control mixer. Removes auto-detect for mic, and adds
6985 * surround controls. Also sets both the Front Playback and Capture Volume
6986 * controls to alt so they set the DSP's decibel level.
6988 static const struct snd_kcontrol_new desktop_mixer[] = {
6989 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6990 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6991 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6992 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6993 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6994 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6995 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6996 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6997 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT),
6998 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6999 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
7000 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
7001 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
7002 VNID_HP_ASEL, 1, HDA_OUTPUT),
7007 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
7008 * because it doesn't set decibel levels for the DSP for capture.
7010 static const struct snd_kcontrol_new r3di_mixer[] = {
7011 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
7012 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
7013 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
7014 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
7015 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
7016 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
7017 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
7018 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
7019 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
7020 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
7021 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
7022 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
7023 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
7024 VNID_HP_ASEL, 1, HDA_OUTPUT),
7028 static int ca0132_build_controls(struct hda_codec *codec)
7030 struct ca0132_spec *spec = codec->spec;
7031 int i, num_fx, num_sliders;
7034 /* Add Mixer controls */
7035 for (i = 0; i < spec->num_mixers; i++) {
7036 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
7040 /* Setup vmaster with surround followers for desktop ca0132 devices */
7041 if (ca0132_use_alt_functions(spec)) {
7042 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
7044 snd_hda_add_vmaster(codec, "Master Playback Volume",
7045 spec->tlv, ca0132_alt_follower_pfxs,
7046 "Playback Volume", 0);
7047 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
7048 NULL, ca0132_alt_follower_pfxs,
7050 true, 0, &spec->vmaster_mute.sw_kctl);
7055 /* Add in and out effects controls.
7056 * VoiceFX, PE and CrystalVoice are added separately.
7058 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
7059 for (i = 0; i < num_fx; i++) {
7060 /* Desktop cards break if Echo Cancellation is used. */
7061 if (ca0132_use_pci_mmio(spec)) {
7062 if (i == (ECHO_CANCELLATION - IN_EFFECT_START_NID +
7067 err = add_fx_switch(codec, ca0132_effects[i].nid,
7068 ca0132_effects[i].name,
7069 ca0132_effects[i].direct);
7074 * If codec has use_alt_controls set to true, add effect level sliders,
7075 * EQ presets, and Smart Volume presets. Also, change names to add FX
7076 * prefix, and change PlayEnhancement and CrystalVoice to match.
7078 if (ca0132_use_alt_controls(spec)) {
7079 err = ca0132_alt_add_svm_enum(codec);
7083 err = add_ca0132_alt_eq_presets(codec);
7087 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
7092 err = add_fx_switch(codec, CRYSTAL_VOICE,
7097 num_sliders = OUT_EFFECTS_COUNT - 1;
7098 for (i = 0; i < num_sliders; i++) {
7099 err = ca0132_alt_add_effect_slider(codec,
7100 ca0132_effects[i].nid,
7101 ca0132_effects[i].name,
7102 ca0132_effects[i].direct);
7107 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
7108 "X-Bass Crossover", EFX_DIR_OUT);
7113 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
7114 "PlayEnhancement", 0);
7118 err = add_fx_switch(codec, CRYSTAL_VOICE,
7123 err = add_voicefx(codec);
7128 * If the codec uses alt_functions, you need the enumerated controls
7129 * to select the new outputs and inputs, plus add the new mic boost
7132 if (ca0132_use_alt_functions(spec)) {
7133 err = ca0132_alt_add_output_enum(codec);
7136 err = ca0132_alt_add_speaker_channel_cfg_enum(codec);
7139 err = ca0132_alt_add_front_full_range_switch(codec);
7142 err = ca0132_alt_add_rear_full_range_switch(codec);
7145 err = ca0132_alt_add_bass_redirection_crossover(codec);
7148 err = ca0132_alt_add_bass_redirection_switch(codec);
7151 err = ca0132_alt_add_mic_boost_enum(codec);
7155 * ZxR only has microphone input, there is no front panel
7156 * header on the card, and aux-in is handled by the DBPro board.
7158 if (ca0132_quirk(spec) != QUIRK_ZXR) {
7159 err = ca0132_alt_add_input_enum(codec);
7165 switch (ca0132_quirk(spec)) {
7168 err = ae5_add_headphone_gain_enum(codec);
7171 err = ae5_add_sound_filter_enum(codec);
7176 err = zxr_add_headphone_gain_switch(codec);
7184 #ifdef ENABLE_TUNING_CONTROLS
7185 add_tuning_ctls(codec);
7188 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
7192 if (spec->dig_out) {
7193 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7197 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
7200 /* spec->multiout.share_spdif = 1; */
7204 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7209 if (ca0132_use_alt_functions(spec))
7210 ca0132_alt_add_chmap_ctls(codec);
7215 static int dbpro_build_controls(struct hda_codec *codec)
7217 struct ca0132_spec *spec = codec->spec;
7220 if (spec->dig_out) {
7221 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7228 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7239 static const struct hda_pcm_stream ca0132_pcm_analog_playback = {
7244 .prepare = ca0132_playback_pcm_prepare,
7245 .cleanup = ca0132_playback_pcm_cleanup,
7246 .get_delay = ca0132_playback_pcm_delay,
7250 static const struct hda_pcm_stream ca0132_pcm_analog_capture = {
7255 .prepare = ca0132_capture_pcm_prepare,
7256 .cleanup = ca0132_capture_pcm_cleanup,
7257 .get_delay = ca0132_capture_pcm_delay,
7261 static const struct hda_pcm_stream ca0132_pcm_digital_playback = {
7266 .open = ca0132_dig_playback_pcm_open,
7267 .close = ca0132_dig_playback_pcm_close,
7268 .prepare = ca0132_dig_playback_pcm_prepare,
7269 .cleanup = ca0132_dig_playback_pcm_cleanup
7273 static const struct hda_pcm_stream ca0132_pcm_digital_capture = {
7279 static int ca0132_build_pcms(struct hda_codec *codec)
7281 struct ca0132_spec *spec = codec->spec;
7282 struct hda_pcm *info;
7284 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
7287 if (ca0132_use_alt_functions(spec)) {
7288 info->own_chmap = true;
7289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap
7290 = ca0132_alt_chmaps;
7292 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
7293 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
7294 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
7295 spec->multiout.max_channels;
7296 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7297 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7298 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
7300 /* With the DSP enabled, desktops don't use this ADC. */
7301 if (!ca0132_use_alt_functions(spec)) {
7302 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
7305 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7306 ca0132_pcm_analog_capture;
7307 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7308 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
7311 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
7314 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7315 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7316 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
7318 if (!spec->dig_out && !spec->dig_in)
7321 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7324 info->pcm_type = HDA_PCM_TYPE_SPDIF;
7325 if (spec->dig_out) {
7326 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
7327 ca0132_pcm_digital_playback;
7328 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
7331 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7332 ca0132_pcm_digital_capture;
7333 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
7339 static int dbpro_build_pcms(struct hda_codec *codec)
7341 struct ca0132_spec *spec = codec->spec;
7342 struct hda_pcm *info;
7344 info = snd_hda_codec_pcm_new(codec, "CA0132 Alt Analog");
7347 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7348 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
7352 if (!spec->dig_out && !spec->dig_in)
7355 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7358 info->pcm_type = HDA_PCM_TYPE_SPDIF;
7359 if (spec->dig_out) {
7360 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
7361 ca0132_pcm_digital_playback;
7362 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
7365 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7366 ca0132_pcm_digital_capture;
7367 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
7373 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
7376 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
7377 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
7378 snd_hda_codec_write(codec, pin, 0,
7379 AC_VERB_SET_AMP_GAIN_MUTE,
7382 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
7383 snd_hda_codec_write(codec, dac, 0,
7384 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
7387 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
7390 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
7391 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
7392 snd_hda_codec_write(codec, pin, 0,
7393 AC_VERB_SET_AMP_GAIN_MUTE,
7396 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
7397 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7400 /* init to 0 dB and unmute. */
7401 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7402 HDA_AMP_VOLMASK, 0x5a);
7403 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7408 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
7412 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
7413 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
7414 snd_hda_override_amp_caps(codec, nid, dir, caps);
7418 * Switch between Digital built-in mic and analog mic.
7420 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
7422 struct ca0132_spec *spec = codec->spec;
7425 unsigned int oldval;
7427 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
7429 oldval = stop_mic1(codec);
7430 ca0132_set_vipsource(codec, 0);
7432 /* set DMic input as 2-ch */
7434 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7436 val = spec->dmic_ctl;
7438 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7439 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7441 if (!(spec->dmic_ctl & 0x20))
7442 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
7444 /* set AMic input as mono */
7446 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7448 val = spec->dmic_ctl;
7449 /* clear bit7 and bit5 to disable dmic */
7451 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7452 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7454 if (!(spec->dmic_ctl & 0x20))
7455 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
7457 ca0132_set_vipsource(codec, 1);
7458 resume_mic1(codec, oldval);
7462 * Initialization for Digital Mic.
7464 static void ca0132_init_dmic(struct hda_codec *codec)
7466 struct ca0132_spec *spec = codec->spec;
7469 /* Setup Digital Mic here, but don't enable.
7470 * Enable based on jack detect.
7473 /* MCLK uses MPIO1, set to enable.
7474 * Bit 2-0: MPIO select
7475 * Bit 3: set to disable
7479 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7480 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
7482 /* Data1 uses MPIO3. Data2 not use
7483 * Bit 2-0: Data1 MPIO select
7484 * Bit 3: set disable Data1
7485 * Bit 6-4: Data2 MPIO select
7486 * Bit 7: set disable Data2
7489 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7490 VENDOR_CHIPIO_DMIC_PIN_SET, val);
7492 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
7493 * Bit 3-0: Channel mask
7494 * Bit 4: set for 48KHz, clear for 32KHz
7496 * Bit 6: set to select Data2, clear for Data1
7497 * Bit 7: set to enable DMic, clear for AMic
7499 if (ca0132_quirk(spec) == QUIRK_ALIENWARE_M17XR4)
7503 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
7504 spec->dmic_ctl = val;
7505 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7506 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7510 * Initialization for Analog Mic 2
7512 static void ca0132_init_analog_mic2(struct hda_codec *codec)
7514 struct ca0132_spec *spec = codec->spec;
7516 mutex_lock(&spec->chipio_mutex);
7518 chipio_8051_write_exram_no_mutex(codec, 0x1920, 0x00);
7519 chipio_8051_write_exram_no_mutex(codec, 0x192d, 0x00);
7521 mutex_unlock(&spec->chipio_mutex);
7524 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
7526 struct ca0132_spec *spec = codec->spec;
7529 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
7530 snd_hda_codec_update_widgets(codec);
7532 for (i = 0; i < spec->multiout.num_dacs; i++)
7533 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
7535 for (i = 0; i < spec->num_outputs; i++)
7536 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
7538 for (i = 0; i < spec->num_inputs; i++) {
7539 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
7540 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
7545 /* If there is an active channel for some reason, find it and free it. */
7546 static void ca0132_alt_free_active_dma_channels(struct hda_codec *codec)
7548 unsigned int i, tmp;
7551 /* Read active DSPDMAC channel register. */
7552 status = chipio_read(codec, DSPDMAC_CHNLSTART_MODULE_OFFSET, &tmp);
7554 /* AND against 0xfff to get the active channel bits. */
7557 /* If there are no active channels, nothing to free. */
7561 codec_dbg(codec, "%s: Failed to read active DSP DMA channel register.\n",
7567 * Check each DSP DMA channel for activity, and if the channel is
7570 for (i = 0; i < DSPDMAC_DMA_CFG_CHANNEL_COUNT; i++) {
7571 if (dsp_is_dma_active(codec, i)) {
7572 status = dspio_free_dma_chan(codec, i);
7574 codec_dbg(codec, "%s: Failed to free active DSP DMA channel %d.\n",
7581 * In the case of CT_EXTENSIONS_ENABLE being set to 1, and the DSP being in
7582 * use, audio is no longer routed directly to the DAC/ADC from the HDA stream.
7583 * Instead, audio is now routed through the DSP's DMA controllers, which
7584 * the DSP is tasked with setting up itself. Through debugging, it seems the
7585 * cause of most of the no-audio on startup issues were due to improperly
7586 * configured DSP DMA channels.
7588 * Normally, the DSP configures these the first time an HDA audio stream is
7589 * started post DSP firmware download. That is why creating a 'dummy' stream
7590 * worked in fixing the audio in some cases. This works most of the time, but
7591 * sometimes if a stream is started/stopped before the DSP can setup the DMA
7592 * configuration registers, it ends up in a broken state. Issues can also
7593 * arise if streams are started in an unusual order, i.e the audio output dma
7594 * channel being sandwiched between the mic1 and mic2 dma channels.
7596 * The solution to this is to make sure that the DSP has no DMA channels
7597 * in use post DSP firmware download, and then to manually start each default
7598 * DSP stream that uses the DMA channels. These are 0x0c, the audio output
7599 * stream, 0x03, analog mic 1, and 0x04, analog mic 2.
7601 static void ca0132_alt_start_dsp_audio_streams(struct hda_codec *codec)
7603 static const unsigned int dsp_dma_stream_ids[] = { 0x0c, 0x03, 0x04 };
7604 struct ca0132_spec *spec = codec->spec;
7605 unsigned int i, tmp;
7608 * Check if any of the default streams are active, and if they are,
7611 mutex_lock(&spec->chipio_mutex);
7613 for (i = 0; i < ARRAY_SIZE(dsp_dma_stream_ids); i++) {
7614 chipio_get_stream_control(codec, dsp_dma_stream_ids[i], &tmp);
7617 chipio_set_stream_control(codec,
7618 dsp_dma_stream_ids[i], 0);
7622 mutex_unlock(&spec->chipio_mutex);
7625 * If all DSP streams are inactive, there should be no active DSP DMA
7626 * channels. Check and make sure this is the case, and if it isn't,
7627 * free any active channels.
7629 ca0132_alt_free_active_dma_channels(codec);
7631 mutex_lock(&spec->chipio_mutex);
7633 /* Make sure stream 0x0c is six channels. */
7634 chipio_set_stream_channels(codec, 0x0c, 6);
7636 for (i = 0; i < ARRAY_SIZE(dsp_dma_stream_ids); i++) {
7637 chipio_set_stream_control(codec,
7638 dsp_dma_stream_ids[i], 1);
7640 /* Give the DSP some time to setup the DMA channel. */
7644 mutex_unlock(&spec->chipio_mutex);
7648 * The region of ChipIO memory from 0x190000-0x1903fc is a sort of 'audio
7649 * router', where each entry represents a 48khz audio channel, with a format
7650 * of an 8-bit destination, an 8-bit source, and an unknown 2-bit number
7651 * value. The 2-bit number value is seemingly 0 if inactive, 1 if active,
7652 * and 3 if it's using Sample Rate Converter ports.
7655 * In this case, f8 is the destination, and c0 is the source. The number value
7657 * This region of memory is normally managed internally by the 8051, where
7658 * the region of exram memory from 0x1477-0x1575 has each byte represent an
7659 * entry within the 0x190000 range, and when a range of entries is in use, the
7660 * ending value is overwritten with 0xff.
7661 * 0x1578 in exram is a table of 0x25 entries, corresponding to the ChipIO
7662 * streamID's, where each entry is a starting 0x190000 port offset.
7663 * 0x159d in exram is the same as 0x1578, except it contains the ending port
7664 * offset for the corresponding streamID.
7666 * On certain cards, such as the SBZ/ZxR/AE7, these are originally setup by
7667 * the 8051, then manually overwritten to remap the ports to work with the
7670 * Currently known portID's:
7671 * 0x00-0x1f: HDA audio stream input/output ports.
7672 * 0x80-0xbf: Sample rate converter input/outputs. Only valid ports seem to
7673 * have the lower-nibble set to 0x1, 0x2, and 0x9.
7674 * 0xc0-0xdf: DSP DMA input/output ports. Dynamically assigned.
7675 * 0xe0-0xff: DAC/ADC audio input/output ports.
7677 * Currently known streamID's:
7678 * 0x03: Mic1 ADC to DSP.
7679 * 0x04: Mic2 ADC to DSP.
7680 * 0x05: HDA node 0x02 audio stream to DSP.
7681 * 0x0f: DSP Mic exit to HDA node 0x07.
7682 * 0x0c: DSP processed audio to DACs.
7683 * 0x14: DAC0, front L/R.
7685 * It is possible to route the HDA audio streams directly to the DAC and
7686 * bypass the DSP entirely, with the only downside being that since the DSP
7687 * does volume control, the only volume control you'll get is through PCM on
7688 * the PC side, in the same way volume is handled for optical out. This may be
7689 * useful for debugging.
7691 static void chipio_remap_stream(struct hda_codec *codec,
7692 const struct chipio_stream_remap_data *remap_data)
7694 unsigned int i, stream_offset;
7696 /* Get the starting port for the stream to be remapped. */
7697 chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
7701 * Check if the stream's port value is 0xff, because the 8051 may not
7702 * have gotten around to setting up the stream yet. Wait until it's
7703 * setup to remap it's ports.
7705 if (stream_offset == 0xff) {
7706 for (i = 0; i < 5; i++) {
7709 chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
7712 if (stream_offset != 0xff)
7717 if (stream_offset == 0xff) {
7718 codec_info(codec, "%s: Stream 0x%02x ports aren't allocated, remap failed!\n",
7719 __func__, remap_data->stream_id);
7723 /* Offset isn't in bytes, its in 32-bit words, so multiply it by 4. */
7724 stream_offset *= 0x04;
7725 stream_offset += 0x190000;
7727 for (i = 0; i < remap_data->count; i++) {
7728 chipio_write_no_mutex(codec,
7729 stream_offset + remap_data->offset[i],
7730 remap_data->value[i]);
7733 /* Update stream map configuration. */
7734 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
7738 * Default speaker tuning values setup for alternative codecs.
7740 static const unsigned int sbz_default_delay_values[] = {
7741 /* Non-zero values are floating point 0.000198. */
7742 0x394f9e38, 0x394f9e38, 0x00000000, 0x00000000, 0x00000000, 0x00000000
7745 static const unsigned int zxr_default_delay_values[] = {
7746 /* Non-zero values are floating point 0.000220. */
7747 0x00000000, 0x00000000, 0x3966afcd, 0x3966afcd, 0x3966afcd, 0x3966afcd
7750 static const unsigned int ae5_default_delay_values[] = {
7751 /* Non-zero values are floating point 0.000100. */
7752 0x00000000, 0x00000000, 0x38d1b717, 0x38d1b717, 0x38d1b717, 0x38d1b717
7756 * If we never change these, probably only need them on initialization.
7758 static void ca0132_alt_init_speaker_tuning(struct hda_codec *codec)
7760 struct ca0132_spec *spec = codec->spec;
7761 unsigned int i, tmp, start_req, end_req;
7762 const unsigned int *values;
7764 switch (ca0132_quirk(spec)) {
7766 values = sbz_default_delay_values;
7769 values = zxr_default_delay_values;
7773 values = ae5_default_delay_values;
7776 values = sbz_default_delay_values;
7781 dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_ENABLE_CENTER_EQ, tmp);
7783 start_req = SPEAKER_TUNING_FRONT_LEFT_VOL_LEVEL;
7784 end_req = SPEAKER_TUNING_REAR_RIGHT_VOL_LEVEL;
7785 for (i = start_req; i < end_req + 1; i++)
7786 dspio_set_uint_param(codec, 0x96, i, tmp);
7788 start_req = SPEAKER_TUNING_FRONT_LEFT_INVERT;
7789 end_req = SPEAKER_TUNING_REAR_RIGHT_INVERT;
7790 for (i = start_req; i < end_req + 1; i++)
7791 dspio_set_uint_param(codec, 0x96, i, tmp);
7794 for (i = 0; i < 6; i++)
7795 dspio_set_uint_param(codec, 0x96,
7796 SPEAKER_TUNING_FRONT_LEFT_DELAY + i, values[i]);
7800 * Initialize mic for non-chromebook ca0132 implementations.
7802 static void ca0132_alt_init_analog_mics(struct hda_codec *codec)
7804 struct ca0132_spec *spec = codec->spec;
7808 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7809 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7810 if (ca0132_quirk(spec) == QUIRK_R3DI) {
7811 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7815 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7817 /* Mic 2 setup (not present on desktop cards) */
7818 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
7819 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
7820 if (ca0132_quirk(spec) == QUIRK_R3DI)
7821 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7823 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
7827 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
7828 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
7829 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
7830 * having an updated DAC, which changes the destination to that DAC.
7832 static void sbz_connect_streams(struct hda_codec *codec)
7834 struct ca0132_spec *spec = codec->spec;
7836 mutex_lock(&spec->chipio_mutex);
7838 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
7840 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
7841 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
7843 /* Setup stream 0x14 with it's source and destination points */
7844 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
7845 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
7846 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
7847 chipio_set_stream_channels(codec, 0x14, 2);
7848 chipio_set_stream_control(codec, 0x14, 1);
7850 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
7852 mutex_unlock(&spec->chipio_mutex);
7856 * Write data through ChipIO to setup proper stream destinations.
7857 * Not sure how it exactly works, but it seems to direct data
7858 * to different destinations. Example is f8 to c0, e0 to c0.
7859 * All I know is, if you don't set these, you get no sound.
7861 static void sbz_chipio_startup_data(struct hda_codec *codec)
7863 const struct chipio_stream_remap_data *dsp_out_remap_data;
7864 struct ca0132_spec *spec = codec->spec;
7866 mutex_lock(&spec->chipio_mutex);
7867 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
7869 /* Remap DAC0's output ports. */
7870 chipio_remap_stream(codec, &stream_remap_data[0]);
7872 /* Remap DSP audio output stream ports. */
7873 switch (ca0132_quirk(spec)) {
7875 dsp_out_remap_data = &stream_remap_data[1];
7879 dsp_out_remap_data = &stream_remap_data[2];
7883 dsp_out_remap_data = NULL;
7887 if (dsp_out_remap_data)
7888 chipio_remap_stream(codec, dsp_out_remap_data);
7890 codec_dbg(codec, "Startup Data exited, mutex released.\n");
7891 mutex_unlock(&spec->chipio_mutex);
7894 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec *codec)
7896 struct ca0132_spec *spec = codec->spec;
7899 chipio_set_stream_control(codec, 0x03, 0);
7900 chipio_set_stream_control(codec, 0x04, 0);
7902 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7903 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7906 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7908 chipio_set_stream_control(codec, 0x03, 1);
7909 chipio_set_stream_control(codec, 0x04, 1);
7911 switch (ca0132_quirk(spec)) {
7913 chipio_write(codec, 0x18b098, 0x0000000c);
7914 chipio_write(codec, 0x18b09C, 0x0000000c);
7917 chipio_write(codec, 0x18b098, 0x0000000c);
7918 chipio_write(codec, 0x18b09c, 0x0000004c);
7925 static void ae5_post_dsp_register_set(struct hda_codec *codec)
7927 struct ca0132_spec *spec = codec->spec;
7929 chipio_8051_write_direct(codec, 0x93, 0x10);
7930 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
7932 writeb(0xff, spec->mem_base + 0x304);
7933 writeb(0xff, spec->mem_base + 0x304);
7934 writeb(0xff, spec->mem_base + 0x304);
7935 writeb(0xff, spec->mem_base + 0x304);
7936 writeb(0x00, spec->mem_base + 0x100);
7937 writeb(0xff, spec->mem_base + 0x304);
7938 writeb(0x00, spec->mem_base + 0x100);
7939 writeb(0xff, spec->mem_base + 0x304);
7940 writeb(0x00, spec->mem_base + 0x100);
7941 writeb(0xff, spec->mem_base + 0x304);
7942 writeb(0x00, spec->mem_base + 0x100);
7943 writeb(0xff, spec->mem_base + 0x304);
7945 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x3f);
7946 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
7947 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7950 static void ae5_post_dsp_param_setup(struct hda_codec *codec)
7953 * Param3 in the 8051's memory is represented by the ascii string 'mch'
7954 * which seems to be 'multichannel'. This is also mentioned in the
7955 * AE-5's registry values in Windows.
7957 chipio_set_control_param(codec, 3, 0);
7959 * I believe ASI is 'audio serial interface' and that it's used to
7960 * change colors on the external LED strip connected to the AE-5.
7962 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
7964 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
7965 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7967 chipio_8051_write_exram(codec, 0xfa92, 0x22);
7970 static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
7972 chipio_8051_write_pll_pmu(codec, 0x41, 0xc8);
7973 chipio_8051_write_pll_pmu(codec, 0x45, 0xcc);
7974 chipio_8051_write_pll_pmu(codec, 0x40, 0xcb);
7975 chipio_8051_write_pll_pmu(codec, 0x43, 0xc7);
7976 chipio_8051_write_pll_pmu(codec, 0x51, 0x8d);
7979 static void ae5_post_dsp_stream_setup(struct hda_codec *codec)
7981 struct ca0132_spec *spec = codec->spec;
7983 mutex_lock(&spec->chipio_mutex);
7985 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7987 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7989 chipio_set_stream_source_dest(codec, 0x5, 0x43, 0x0);
7991 chipio_set_stream_source_dest(codec, 0x18, 0x9, 0xd0);
7992 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7993 chipio_set_stream_channels(codec, 0x18, 6);
7994 chipio_set_stream_control(codec, 0x18, 1);
7996 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7998 chipio_8051_write_pll_pmu_no_mutex(codec, 0x43, 0xc7);
8000 ca0113_mmio_command_set(codec, 0x48, 0x01, 0x80);
8002 mutex_unlock(&spec->chipio_mutex);
8005 static void ae5_post_dsp_startup_data(struct hda_codec *codec)
8007 struct ca0132_spec *spec = codec->spec;
8009 mutex_lock(&spec->chipio_mutex);
8011 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
8012 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
8013 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
8014 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
8016 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
8017 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8018 ca0113_mmio_command_set(codec, 0x48, 0x0b, 0x12);
8019 ca0113_mmio_command_set(codec, 0x48, 0x04, 0x00);
8020 ca0113_mmio_command_set(codec, 0x48, 0x06, 0x48);
8021 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
8022 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8023 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8024 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8025 ca0113_mmio_gpio_set(codec, 0, true);
8026 ca0113_mmio_gpio_set(codec, 1, true);
8027 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x80);
8029 chipio_write_no_mutex(codec, 0x18b03c, 0x00000012);
8031 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8032 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8034 mutex_unlock(&spec->chipio_mutex);
8037 static void ae7_post_dsp_setup_ports(struct hda_codec *codec)
8039 struct ca0132_spec *spec = codec->spec;
8041 mutex_lock(&spec->chipio_mutex);
8043 /* Seems to share the same port remapping as the SBZ. */
8044 chipio_remap_stream(codec, &stream_remap_data[1]);
8046 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8047 ca0113_mmio_command_set(codec, 0x48, 0x0d, 0x40);
8048 ca0113_mmio_command_set(codec, 0x48, 0x17, 0x00);
8049 ca0113_mmio_command_set(codec, 0x48, 0x19, 0x00);
8050 ca0113_mmio_command_set(codec, 0x48, 0x11, 0xff);
8051 ca0113_mmio_command_set(codec, 0x48, 0x12, 0xff);
8052 ca0113_mmio_command_set(codec, 0x48, 0x13, 0xff);
8053 ca0113_mmio_command_set(codec, 0x48, 0x14, 0x7f);
8055 mutex_unlock(&spec->chipio_mutex);
8058 static void ae7_post_dsp_asi_stream_setup(struct hda_codec *codec)
8060 struct ca0132_spec *spec = codec->spec;
8062 mutex_lock(&spec->chipio_mutex);
8064 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
8065 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8067 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
8069 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
8070 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
8072 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
8073 chipio_set_stream_channels(codec, 0x18, 6);
8074 chipio_set_stream_control(codec, 0x18, 1);
8076 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
8078 mutex_unlock(&spec->chipio_mutex);
8081 static void ae7_post_dsp_pll_setup(struct hda_codec *codec)
8083 static const unsigned int addr[] = {
8084 0x41, 0x45, 0x40, 0x43, 0x51
8086 static const unsigned int data[] = {
8087 0xc8, 0xcc, 0xcb, 0xc7, 0x8d
8091 for (i = 0; i < ARRAY_SIZE(addr); i++)
8092 chipio_8051_write_pll_pmu_no_mutex(codec, addr[i], data[i]);
8095 static void ae7_post_dsp_asi_setup_ports(struct hda_codec *codec)
8097 struct ca0132_spec *spec = codec->spec;
8098 static const unsigned int target[] = {
8099 0x0b, 0x04, 0x06, 0x0a, 0x0c, 0x11, 0x12, 0x13, 0x14
8101 static const unsigned int data[] = {
8102 0x12, 0x00, 0x48, 0x05, 0x5f, 0xff, 0xff, 0xff, 0x7f
8106 mutex_lock(&spec->chipio_mutex);
8108 chipio_8051_write_pll_pmu_no_mutex(codec, 0x43, 0xc7);
8110 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
8111 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
8112 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
8113 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
8115 ae7_post_dsp_pll_setup(codec);
8116 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8118 for (i = 0; i < ARRAY_SIZE(target); i++)
8119 ca0113_mmio_command_set(codec, 0x48, target[i], data[i]);
8121 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8122 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8123 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8125 chipio_set_stream_source_dest(codec, 0x21, 0x64, 0x56);
8126 chipio_set_stream_channels(codec, 0x21, 2);
8127 chipio_set_conn_rate_no_mutex(codec, 0x56, SR_8_000);
8129 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_NODE_ID, 0x09);
8131 * In the 8051's memory, this param is referred to as 'n2sid', which I
8132 * believe is 'node to streamID'. It seems to be a way to assign a
8133 * stream to a given HDA node.
8135 chipio_set_control_param_no_mutex(codec, 0x20, 0x21);
8137 chipio_write_no_mutex(codec, 0x18b038, 0x00000088);
8140 * Now, at this point on Windows, an actual stream is setup and
8141 * seemingly sends data to the HDA node 0x09, which is the digital
8142 * audio input node. This is left out here, because obviously I don't
8143 * know what data is being sent. Interestingly, the AE-5 seems to go
8144 * through the motions of getting here and never actually takes this
8145 * step, but the AE-7 does.
8148 ca0113_mmio_gpio_set(codec, 0, 1);
8149 ca0113_mmio_gpio_set(codec, 1, 1);
8151 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8152 chipio_write_no_mutex(codec, 0x18b03c, 0x00000000);
8153 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8154 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8156 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
8157 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
8159 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
8160 chipio_set_stream_channels(codec, 0x18, 6);
8163 * Runs again, this has been repeated a few times, but I'm just
8164 * following what the Windows driver does.
8166 ae7_post_dsp_pll_setup(codec);
8167 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8169 mutex_unlock(&spec->chipio_mutex);
8173 * The Windows driver has commands that seem to setup ASI, which I believe to
8174 * be some sort of audio serial interface. My current speculation is that it's
8175 * related to communicating with the new DAC.
8177 static void ae7_post_dsp_asi_setup(struct hda_codec *codec)
8179 chipio_8051_write_direct(codec, 0x93, 0x10);
8181 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
8183 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8184 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8186 chipio_set_control_param(codec, 3, 3);
8187 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
8189 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
8190 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8191 snd_hda_codec_write(codec, 0x17, 0, 0x794, 0x00);
8193 chipio_8051_write_exram(codec, 0xfa92, 0x22);
8195 ae7_post_dsp_pll_setup(codec);
8196 ae7_post_dsp_asi_stream_setup(codec);
8198 chipio_8051_write_pll_pmu(codec, 0x43, 0xc7);
8200 ae7_post_dsp_asi_setup_ports(codec);
8204 * Setup default parameters for DSP
8206 static void ca0132_setup_defaults(struct hda_codec *codec)
8208 struct ca0132_spec *spec = codec->spec;
8213 if (spec->dsp_state != DSP_DOWNLOADED)
8216 /* out, in effects + voicefx */
8217 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8218 for (idx = 0; idx < num_fx; idx++) {
8219 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8220 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
8221 ca0132_effects[idx].reqs[i],
8222 ca0132_effects[idx].def_vals[i]);
8226 /*remove DSP headroom*/
8228 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8230 /*set speaker EQ bypass attenuation*/
8231 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
8233 /* set AMic1 and AMic2 as mono mic */
8235 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
8236 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
8238 /* set AMic1 as CrystalVoice input */
8240 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
8242 /* set WUH source */
8244 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8248 * Setup default parameters for Recon3D/Recon3Di DSP.
8251 static void r3d_setup_defaults(struct hda_codec *codec)
8253 struct ca0132_spec *spec = codec->spec;
8258 if (spec->dsp_state != DSP_DOWNLOADED)
8261 ca0132_alt_init_analog_mics(codec);
8262 ca0132_alt_start_dsp_audio_streams(codec);
8264 /*remove DSP headroom*/
8266 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8268 /* set WUH source */
8270 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8271 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8273 /* Set speaker source? */
8274 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8276 if (ca0132_quirk(spec) == QUIRK_R3DI)
8277 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
8279 /* Disable mute on Center/LFE. */
8280 if (ca0132_quirk(spec) == QUIRK_R3D) {
8281 ca0113_mmio_gpio_set(codec, 2, false);
8282 ca0113_mmio_gpio_set(codec, 4, true);
8285 /* Setup effect defaults */
8286 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8287 for (idx = 0; idx < num_fx; idx++) {
8288 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8289 dspio_set_uint_param(codec,
8290 ca0132_effects[idx].mid,
8291 ca0132_effects[idx].reqs[i],
8292 ca0132_effects[idx].def_vals[i]);
8298 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
8299 * than the Chromebook setup.
8301 static void sbz_setup_defaults(struct hda_codec *codec)
8303 struct ca0132_spec *spec = codec->spec;
8308 if (spec->dsp_state != DSP_DOWNLOADED)
8311 ca0132_alt_init_analog_mics(codec);
8312 ca0132_alt_start_dsp_audio_streams(codec);
8313 sbz_connect_streams(codec);
8314 sbz_chipio_startup_data(codec);
8317 * Sets internal input loopback to off, used to have a switch to
8318 * enable input loopback, but turned out to be way too buggy.
8321 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8322 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8324 /*remove DSP headroom*/
8326 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8328 /* set WUH source */
8330 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8331 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8333 /* Set speaker source? */
8334 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8336 ca0132_alt_dsp_initial_mic_setup(codec);
8338 /* out, in effects + voicefx */
8339 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8340 for (idx = 0; idx < num_fx; idx++) {
8341 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8342 dspio_set_uint_param(codec,
8343 ca0132_effects[idx].mid,
8344 ca0132_effects[idx].reqs[i],
8345 ca0132_effects[idx].def_vals[i]);
8349 ca0132_alt_init_speaker_tuning(codec);
8353 * Setup default parameters for the Sound BlasterX AE-5 DSP.
8355 static void ae5_setup_defaults(struct hda_codec *codec)
8357 struct ca0132_spec *spec = codec->spec;
8362 if (spec->dsp_state != DSP_DOWNLOADED)
8365 ca0132_alt_init_analog_mics(codec);
8366 ca0132_alt_start_dsp_audio_streams(codec);
8368 /* New, unknown SCP req's */
8370 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
8371 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
8372 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8373 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8375 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8376 ca0113_mmio_gpio_set(codec, 0, false);
8377 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8379 /* Internal loopback off */
8381 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8382 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8384 /*remove DSP headroom*/
8386 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8388 /* set WUH source */
8390 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8391 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8393 /* Set speaker source? */
8394 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8396 ca0132_alt_dsp_initial_mic_setup(codec);
8397 ae5_post_dsp_register_set(codec);
8398 ae5_post_dsp_param_setup(codec);
8399 ae5_post_dsp_pll_setup(codec);
8400 ae5_post_dsp_stream_setup(codec);
8401 ae5_post_dsp_startup_data(codec);
8403 /* out, in effects + voicefx */
8404 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8405 for (idx = 0; idx < num_fx; idx++) {
8406 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8407 dspio_set_uint_param(codec,
8408 ca0132_effects[idx].mid,
8409 ca0132_effects[idx].reqs[i],
8410 ca0132_effects[idx].def_vals[i]);
8414 ca0132_alt_init_speaker_tuning(codec);
8418 * Setup default parameters for the Sound Blaster AE-7 DSP.
8420 static void ae7_setup_defaults(struct hda_codec *codec)
8422 struct ca0132_spec *spec = codec->spec;
8427 if (spec->dsp_state != DSP_DOWNLOADED)
8430 ca0132_alt_init_analog_mics(codec);
8431 ca0132_alt_start_dsp_audio_streams(codec);
8432 ae7_post_dsp_setup_ports(codec);
8435 dspio_set_uint_param(codec, 0x96,
8436 SPEAKER_TUNING_FRONT_LEFT_INVERT, tmp);
8437 dspio_set_uint_param(codec, 0x96,
8438 SPEAKER_TUNING_FRONT_RIGHT_INVERT, tmp);
8440 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8442 /* New, unknown SCP req's */
8443 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8444 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8446 ca0113_mmio_gpio_set(codec, 0, false);
8448 /* Internal loopback off */
8450 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8451 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8453 /*remove DSP headroom*/
8455 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8457 /* set WUH source */
8459 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8460 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8462 /* Set speaker source? */
8463 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8464 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8467 * This is the second time we've called this, but this is seemingly
8468 * what Windows does.
8470 ca0132_alt_init_analog_mics(codec);
8472 ae7_post_dsp_asi_setup(codec);
8475 * Not sure why, but these are both set to 1. They're only set to 0
8478 ca0113_mmio_gpio_set(codec, 0, true);
8479 ca0113_mmio_gpio_set(codec, 1, true);
8481 /* Volume control related. */
8482 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x04);
8483 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x04);
8484 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x80);
8486 /* out, in effects + voicefx */
8487 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8488 for (idx = 0; idx < num_fx; idx++) {
8489 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8490 dspio_set_uint_param(codec,
8491 ca0132_effects[idx].mid,
8492 ca0132_effects[idx].reqs[i],
8493 ca0132_effects[idx].def_vals[i]);
8497 ca0132_alt_init_speaker_tuning(codec);
8501 * Initialization of flags in chip
8503 static void ca0132_init_flags(struct hda_codec *codec)
8505 struct ca0132_spec *spec = codec->spec;
8507 if (ca0132_use_alt_functions(spec)) {
8508 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
8509 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
8510 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
8511 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
8512 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
8513 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8514 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
8515 chipio_set_control_flag(codec,
8516 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
8517 chipio_set_control_flag(codec,
8518 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 1);
8520 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8521 chipio_set_control_flag(codec,
8522 CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
8523 chipio_set_control_flag(codec,
8524 CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
8525 chipio_set_control_flag(codec,
8526 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
8527 chipio_set_control_flag(codec,
8528 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
8529 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
8534 * Initialization of parameters in chip
8536 static void ca0132_init_params(struct hda_codec *codec)
8538 struct ca0132_spec *spec = codec->spec;
8540 if (ca0132_use_alt_functions(spec)) {
8541 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8542 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
8543 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
8544 chipio_set_control_param(codec, 0, 0);
8545 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
8548 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
8549 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
8552 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
8554 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
8555 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
8556 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
8557 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
8558 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
8559 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
8561 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
8562 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
8563 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8566 static bool ca0132_download_dsp_images(struct hda_codec *codec)
8568 bool dsp_loaded = false;
8569 struct ca0132_spec *spec = codec->spec;
8570 const struct dsp_image_seg *dsp_os_image;
8571 const struct firmware *fw_entry = NULL;
8573 * Alternate firmwares for different variants. The Recon3Di apparently
8574 * can use the default firmware, but I'll leave the option in case
8575 * it needs it again.
8577 switch (ca0132_quirk(spec)) {
8581 if (reject_firmware(&fw_entry, DESKTOP_EFX_FILE,
8582 codec->card->dev) != 0)
8583 codec_dbg(codec, "Desktop firmware not found.");
8585 codec_dbg(codec, "Desktop firmware selected.");
8588 if (reject_firmware(&fw_entry, R3DI_EFX_FILE,
8589 codec->card->dev) != 0)
8590 codec_dbg(codec, "Recon3Di alt firmware not detected.");
8592 codec_dbg(codec, "Recon3Di firmware selected.");
8599 codec_dbg(codec, "Default firmware selected.");
8600 if (reject_firmware(&fw_entry, EFX_FILE,
8601 codec->card->dev) != 0)
8605 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
8606 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
8607 codec_err(codec, "ca0132 DSP load image failed\n");
8611 dsp_loaded = dspload_wait_loaded(codec);
8614 release_firmware(fw_entry);
8619 static void ca0132_download_dsp(struct hda_codec *codec)
8621 struct ca0132_spec *spec = codec->spec;
8623 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
8627 if (spec->dsp_state == DSP_DOWNLOAD_FAILED)
8628 return; /* don't retry failures */
8630 chipio_enable_clocks(codec);
8631 if (spec->dsp_state != DSP_DOWNLOADED) {
8632 spec->dsp_state = DSP_DOWNLOADING;
8634 if (!ca0132_download_dsp_images(codec))
8635 spec->dsp_state = DSP_DOWNLOAD_FAILED;
8637 spec->dsp_state = DSP_DOWNLOADED;
8640 /* For codecs using alt functions, this is already done earlier */
8641 if (spec->dsp_state == DSP_DOWNLOADED && !ca0132_use_alt_functions(spec))
8642 ca0132_set_dsp_msr(codec, true);
8645 static void ca0132_process_dsp_response(struct hda_codec *codec,
8646 struct hda_jack_callback *callback)
8648 struct ca0132_spec *spec = codec->spec;
8650 codec_dbg(codec, "ca0132_process_dsp_response\n");
8651 snd_hda_power_up_pm(codec);
8652 if (spec->wait_scp) {
8653 if (dspio_get_response_data(codec) >= 0)
8657 dspio_clear_response_queue(codec);
8658 snd_hda_power_down_pm(codec);
8661 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8663 struct ca0132_spec *spec = codec->spec;
8664 struct hda_jack_tbl *tbl;
8666 /* Delay enabling the HP amp, to let the mic-detection
8667 * state machine run.
8669 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
8671 tbl->block_report = 1;
8672 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
8675 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8677 struct ca0132_spec *spec = codec->spec;
8679 if (ca0132_use_alt_functions(spec))
8680 ca0132_alt_select_in(codec);
8682 ca0132_select_mic(codec);
8685 static void ca0132_setup_unsol(struct hda_codec *codec)
8687 struct ca0132_spec *spec = codec->spec;
8688 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
8689 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
8691 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
8692 ca0132_process_dsp_response);
8693 /* Front headphone jack detection */
8694 if (ca0132_use_alt_functions(spec))
8695 snd_hda_jack_detect_enable_callback(codec,
8696 spec->unsol_tag_front_hp, hp_callback);
8703 /* Sends before DSP download. */
8704 static const struct hda_verb ca0132_base_init_verbs[] = {
8705 /*enable ct extension*/
8706 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
8711 static const struct hda_verb ca0132_base_exit_verbs[] = {
8713 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
8714 /*disable ct extension*/
8715 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
8719 /* Other verbs tables. Sends after DSP download. */
8721 static const struct hda_verb ca0132_init_verbs0[] = {
8722 /* chip init verbs */
8723 {0x15, 0x70D, 0xF0},
8724 {0x15, 0x70E, 0xFE},
8725 {0x15, 0x707, 0x75},
8726 {0x15, 0x707, 0xD3},
8727 {0x15, 0x707, 0x09},
8728 {0x15, 0x707, 0x53},
8729 {0x15, 0x707, 0xD4},
8730 {0x15, 0x707, 0xEF},
8731 {0x15, 0x707, 0x75},
8732 {0x15, 0x707, 0xD3},
8733 {0x15, 0x707, 0x09},
8734 {0x15, 0x707, 0x02},
8735 {0x15, 0x707, 0x37},
8736 {0x15, 0x707, 0x78},
8737 {0x15, 0x53C, 0xCE},
8738 {0x15, 0x575, 0xC9},
8739 {0x15, 0x53D, 0xCE},
8740 {0x15, 0x5B7, 0xC9},
8741 {0x15, 0x70D, 0xE8},
8742 {0x15, 0x70E, 0xFE},
8743 {0x15, 0x707, 0x02},
8744 {0x15, 0x707, 0x68},
8745 {0x15, 0x707, 0x62},
8746 {0x15, 0x53A, 0xCE},
8747 {0x15, 0x546, 0xC9},
8748 {0x15, 0x53B, 0xCE},
8749 {0x15, 0x5E8, 0xC9},
8753 /* Extra init verbs for desktop cards. */
8754 static const struct hda_verb ca0132_init_verbs1[] = {
8755 {0x15, 0x70D, 0x20},
8756 {0x15, 0x70E, 0x19},
8757 {0x15, 0x707, 0x00},
8758 {0x15, 0x539, 0xCE},
8759 {0x15, 0x546, 0xC9},
8760 {0x15, 0x70D, 0xB7},
8761 {0x15, 0x70E, 0x09},
8762 {0x15, 0x707, 0x10},
8763 {0x15, 0x70D, 0xAF},
8764 {0x15, 0x70E, 0x09},
8765 {0x15, 0x707, 0x01},
8766 {0x15, 0x707, 0x05},
8767 {0x15, 0x70D, 0x73},
8768 {0x15, 0x70E, 0x09},
8769 {0x15, 0x707, 0x14},
8770 {0x15, 0x6FF, 0xC4},
8774 static void ca0132_init_chip(struct hda_codec *codec)
8776 struct ca0132_spec *spec = codec->spec;
8781 mutex_init(&spec->chipio_mutex);
8784 * The Windows driver always does this upon startup, which seems to
8785 * clear out any previous configuration. This should help issues where
8786 * a boot into Windows prior to a boot into Linux breaks things. Also,
8787 * Windows always sends the reset twice.
8789 if (ca0132_use_alt_functions(spec)) {
8790 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8791 chipio_write_no_mutex(codec, 0x18b0a4, 0x000000c2);
8793 snd_hda_codec_write(codec, codec->core.afg, 0,
8794 AC_VERB_SET_CODEC_RESET, 0);
8795 snd_hda_codec_write(codec, codec->core.afg, 0,
8796 AC_VERB_SET_CODEC_RESET, 0);
8799 spec->cur_out_type = SPEAKER_OUT;
8800 if (!ca0132_use_alt_functions(spec))
8801 spec->cur_mic_type = DIGITAL_MIC;
8803 spec->cur_mic_type = REAR_MIC;
8805 spec->cur_mic_boost = 0;
8807 for (i = 0; i < VNODES_COUNT; i++) {
8808 spec->vnode_lvol[i] = 0x5a;
8809 spec->vnode_rvol[i] = 0x5a;
8810 spec->vnode_lswitch[i] = 0;
8811 spec->vnode_rswitch[i] = 0;
8815 * Default states for effects are in ca0132_effects[].
8817 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
8818 for (i = 0; i < num_fx; i++) {
8819 on = (unsigned int)ca0132_effects[i].reqs[0];
8820 spec->effects_switch[i] = on ? 1 : 0;
8823 * Sets defaults for the effect slider controls, only for alternative
8824 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
8826 if (ca0132_use_alt_controls(spec)) {
8827 /* Set speakers to default to full range. */
8828 spec->speaker_range_val[0] = 1;
8829 spec->speaker_range_val[1] = 1;
8831 spec->xbass_xover_freq = 8;
8832 for (i = 0; i < EFFECT_LEVEL_SLIDERS; i++)
8833 spec->fx_ctl_val[i] = effect_slider_defaults[i];
8835 spec->bass_redirect_xover_freq = 8;
8838 spec->voicefx_val = 0;
8839 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
8840 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
8843 * The ZxR doesn't have a front panel header, and it's line-in is on
8844 * the daughter board. So, there is no input enum control, and we need
8845 * to make sure that spec->in_enum_val is set properly.
8847 if (ca0132_quirk(spec) == QUIRK_ZXR)
8848 spec->in_enum_val = REAR_MIC;
8850 #ifdef ENABLE_TUNING_CONTROLS
8851 ca0132_init_tuning_defaults(codec);
8856 * Recon3Di exit specific commands.
8858 /* prevents popping noise on shutdown */
8859 static void r3di_gpio_shutdown(struct hda_codec *codec)
8861 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
8865 * Sound Blaster Z exit specific commands.
8867 static void sbz_region2_exit(struct hda_codec *codec)
8869 struct ca0132_spec *spec = codec->spec;
8872 for (i = 0; i < 4; i++)
8873 writeb(0x0, spec->mem_base + 0x100);
8874 for (i = 0; i < 8; i++)
8875 writeb(0xb3, spec->mem_base + 0x304);
8877 ca0113_mmio_gpio_set(codec, 0, false);
8878 ca0113_mmio_gpio_set(codec, 1, false);
8879 ca0113_mmio_gpio_set(codec, 4, true);
8880 ca0113_mmio_gpio_set(codec, 5, false);
8881 ca0113_mmio_gpio_set(codec, 7, false);
8884 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
8886 static const hda_nid_t pins[] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
8889 snd_hda_codec_write(codec, 0x11, 0,
8890 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40);
8892 for (i = 0; i < ARRAY_SIZE(pins); i++)
8893 snd_hda_codec_write(codec, pins[i], 0,
8894 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00);
8897 static void ca0132_clear_unsolicited(struct hda_codec *codec)
8899 static const hda_nid_t pins[] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
8902 for (i = 0; i < ARRAY_SIZE(pins); i++) {
8903 snd_hda_codec_write(codec, pins[i], 0,
8904 AC_VERB_SET_UNSOLICITED_ENABLE, 0x00);
8908 /* On shutdown, sends commands in sets of three */
8909 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
8913 snd_hda_codec_write(codec, 0x01, 0,
8914 AC_VERB_SET_GPIO_DIRECTION, dir);
8916 snd_hda_codec_write(codec, 0x01, 0,
8917 AC_VERB_SET_GPIO_MASK, mask);
8920 snd_hda_codec_write(codec, 0x01, 0,
8921 AC_VERB_SET_GPIO_DATA, data);
8924 static void zxr_dbpro_power_state_shutdown(struct hda_codec *codec)
8926 static const hda_nid_t pins[] = {0x05, 0x0c, 0x09, 0x0e, 0x08, 0x11, 0x01};
8929 for (i = 0; i < ARRAY_SIZE(pins); i++)
8930 snd_hda_codec_write(codec, pins[i], 0,
8931 AC_VERB_SET_POWER_STATE, 0x03);
8934 static void sbz_exit_chip(struct hda_codec *codec)
8936 chipio_set_stream_control(codec, 0x03, 0);
8937 chipio_set_stream_control(codec, 0x04, 0);
8939 /* Mess with GPIO */
8940 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
8941 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
8942 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
8944 chipio_set_stream_control(codec, 0x14, 0);
8945 chipio_set_stream_control(codec, 0x0C, 0);
8947 chipio_set_conn_rate(codec, 0x41, SR_192_000);
8948 chipio_set_conn_rate(codec, 0x91, SR_192_000);
8950 chipio_write(codec, 0x18a020, 0x00000083);
8952 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
8953 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
8954 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
8956 chipio_set_stream_control(codec, 0x0C, 0);
8958 chipio_set_control_param(codec, 0x0D, 0x24);
8960 ca0132_clear_unsolicited(codec);
8961 sbz_set_pin_ctl_default(codec);
8963 snd_hda_codec_write(codec, 0x0B, 0,
8964 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
8966 sbz_region2_exit(codec);
8969 static void r3d_exit_chip(struct hda_codec *codec)
8971 ca0132_clear_unsolicited(codec);
8972 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8973 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
8976 static void ae5_exit_chip(struct hda_codec *codec)
8978 chipio_set_stream_control(codec, 0x03, 0);
8979 chipio_set_stream_control(codec, 0x04, 0);
8981 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8982 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8983 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8984 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8985 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8986 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x00);
8987 ca0113_mmio_gpio_set(codec, 0, false);
8988 ca0113_mmio_gpio_set(codec, 1, false);
8990 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8991 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8993 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8995 chipio_set_stream_control(codec, 0x18, 0);
8996 chipio_set_stream_control(codec, 0x0c, 0);
8998 snd_hda_codec_write(codec, 0x01, 0, 0x724, 0x83);
9001 static void ae7_exit_chip(struct hda_codec *codec)
9003 chipio_set_stream_control(codec, 0x18, 0);
9004 chipio_set_stream_source_dest(codec, 0x21, 0xc8, 0xc8);
9005 chipio_set_stream_channels(codec, 0x21, 0);
9006 chipio_set_control_param(codec, CONTROL_PARAM_NODE_ID, 0x09);
9007 chipio_set_control_param(codec, 0x20, 0x01);
9009 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
9011 chipio_set_stream_control(codec, 0x18, 0);
9012 chipio_set_stream_control(codec, 0x0c, 0);
9014 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
9015 snd_hda_codec_write(codec, 0x15, 0, 0x724, 0x83);
9016 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
9017 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
9018 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x00);
9019 ca0113_mmio_gpio_set(codec, 0, false);
9020 ca0113_mmio_gpio_set(codec, 1, false);
9021 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9023 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
9024 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
9027 static void zxr_exit_chip(struct hda_codec *codec)
9029 chipio_set_stream_control(codec, 0x03, 0);
9030 chipio_set_stream_control(codec, 0x04, 0);
9031 chipio_set_stream_control(codec, 0x14, 0);
9032 chipio_set_stream_control(codec, 0x0C, 0);
9034 chipio_set_conn_rate(codec, 0x41, SR_192_000);
9035 chipio_set_conn_rate(codec, 0x91, SR_192_000);
9037 chipio_write(codec, 0x18a020, 0x00000083);
9039 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
9040 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
9042 ca0132_clear_unsolicited(codec);
9043 sbz_set_pin_ctl_default(codec);
9044 snd_hda_codec_write(codec, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x00);
9046 ca0113_mmio_gpio_set(codec, 5, false);
9047 ca0113_mmio_gpio_set(codec, 2, false);
9048 ca0113_mmio_gpio_set(codec, 3, false);
9049 ca0113_mmio_gpio_set(codec, 0, false);
9050 ca0113_mmio_gpio_set(codec, 4, true);
9051 ca0113_mmio_gpio_set(codec, 0, true);
9052 ca0113_mmio_gpio_set(codec, 5, true);
9053 ca0113_mmio_gpio_set(codec, 2, false);
9054 ca0113_mmio_gpio_set(codec, 3, false);
9057 static void ca0132_exit_chip(struct hda_codec *codec)
9059 /* put any chip cleanup stuffs here. */
9061 if (dspload_is_loaded(codec))
9066 * This fixes a problem that was hard to reproduce. Very rarely, I would
9067 * boot up, and there would be no sound, but the DSP indicated it had loaded
9068 * properly. I did a few memory dumps to see if anything was different, and
9069 * there were a few areas of memory uninitialized with a1a2a3a4. This function
9070 * checks if those areas are uninitialized, and if they are, it'll attempt to
9071 * reload the card 3 times. Usually it fixes by the second.
9073 static void sbz_dsp_startup_check(struct hda_codec *codec)
9075 struct ca0132_spec *spec = codec->spec;
9076 unsigned int dsp_data_check[4];
9077 unsigned int cur_address = 0x390;
9079 unsigned int failure = 0;
9080 unsigned int reload = 3;
9082 if (spec->startup_check_entered)
9085 spec->startup_check_entered = true;
9087 for (i = 0; i < 4; i++) {
9088 chipio_read(codec, cur_address, &dsp_data_check[i]);
9091 for (i = 0; i < 4; i++) {
9092 if (dsp_data_check[i] == 0xa1a2a3a4)
9096 codec_dbg(codec, "Startup Check: %d ", failure);
9098 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
9100 * While the failure condition is true, and we haven't reached our
9101 * three reload limit, continue trying to reload the driver and
9104 while (failure && (reload != 0)) {
9105 codec_info(codec, "Reloading... Tries left: %d", reload);
9106 sbz_exit_chip(codec);
9107 spec->dsp_state = DSP_DOWNLOAD_INIT;
9108 codec->patch_ops.init(codec);
9110 for (i = 0; i < 4; i++) {
9111 chipio_read(codec, cur_address, &dsp_data_check[i]);
9114 for (i = 0; i < 4; i++) {
9115 if (dsp_data_check[i] == 0xa1a2a3a4)
9121 if (!failure && reload < 3)
9122 codec_info(codec, "DSP fixed.");
9127 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
9131 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
9132 * extra precision for decibel values. If you had the dB value in floating point
9133 * you would take the value after the decimal point, multiply by 64, and divide
9134 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
9135 * implement fixed point or floating point dB volumes. For now, I'll set them
9136 * to 0 just incase a value has lingered from a boot into Windows.
9138 static void ca0132_alt_vol_setup(struct hda_codec *codec)
9140 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
9141 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
9142 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
9143 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
9144 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
9145 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
9146 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
9147 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
9151 * Extra commands that don't really fit anywhere else.
9153 static void sbz_pre_dsp_setup(struct hda_codec *codec)
9155 struct ca0132_spec *spec = codec->spec;
9157 writel(0x00820680, spec->mem_base + 0x01C);
9158 writel(0x00820680, spec->mem_base + 0x01C);
9160 chipio_write(codec, 0x18b0a4, 0x000000c2);
9162 snd_hda_codec_write(codec, 0x11, 0,
9163 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
9166 static void r3d_pre_dsp_setup(struct hda_codec *codec)
9168 chipio_write(codec, 0x18b0a4, 0x000000c2);
9170 chipio_8051_write_exram(codec, 0x1c1e, 0x5b);
9172 snd_hda_codec_write(codec, 0x11, 0,
9173 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
9176 static void r3di_pre_dsp_setup(struct hda_codec *codec)
9178 chipio_write(codec, 0x18b0a4, 0x000000c2);
9180 chipio_8051_write_exram(codec, 0x1c1e, 0x5b);
9181 chipio_8051_write_exram(codec, 0x1920, 0x00);
9182 chipio_8051_write_exram(codec, 0x1921, 0x40);
9184 snd_hda_codec_write(codec, 0x11, 0,
9185 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
9189 * The ZxR seems to use alternative DAC's for the surround channels, which
9190 * require PLL PMU setup for the clock rate, I'm guessing. Without setting
9191 * this up, we get no audio out of the surround jacks.
9193 static void zxr_pre_dsp_setup(struct hda_codec *codec)
9195 static const unsigned int addr[] = { 0x43, 0x40, 0x41, 0x42, 0x45 };
9196 static const unsigned int data[] = { 0x08, 0x0c, 0x0b, 0x07, 0x0d };
9199 chipio_write(codec, 0x189000, 0x0001f100);
9201 chipio_write(codec, 0x18900c, 0x0001f100);
9205 * This writes a RET instruction at the entry point of the function at
9206 * 0xfa92 in exram. This function seems to have something to do with
9207 * ASI. Might be some way to prevent the card from reconfiguring the
9210 chipio_8051_write_exram(codec, 0xfa92, 0x22);
9212 chipio_8051_write_pll_pmu(codec, 0x51, 0x98);
9214 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x82);
9215 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 3);
9217 chipio_write(codec, 0x18902c, 0x00000000);
9219 chipio_write(codec, 0x18902c, 0x00000003);
9222 for (i = 0; i < ARRAY_SIZE(addr); i++)
9223 chipio_8051_write_pll_pmu(codec, addr[i], data[i]);
9227 * These are sent before the DSP is downloaded. Not sure
9228 * what they do, or if they're necessary. Could possibly
9229 * be removed. Figure they're better to leave in.
9231 static const unsigned int ca0113_mmio_init_address_sbz[] = {
9232 0x400, 0x408, 0x40c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c,
9233 0xc0c, 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04
9236 static const unsigned int ca0113_mmio_init_data_sbz[] = {
9237 0x00000030, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9238 0x00000003, 0x000000c1, 0x000000f1, 0x00000001, 0x000000c7,
9239 0x000000c1, 0x00000080
9242 static const unsigned int ca0113_mmio_init_data_zxr[] = {
9243 0x00000030, 0x00000000, 0x00000000, 0x00000003, 0x00000003,
9244 0x00000003, 0x00000001, 0x000000f1, 0x00000001, 0x000000c7,
9245 0x000000c1, 0x00000080
9248 static const unsigned int ca0113_mmio_init_address_ae5[] = {
9249 0x400, 0x42c, 0x46c, 0x4ac, 0x4ec, 0x43c, 0x47c, 0x4bc, 0x4fc, 0x408,
9250 0x100, 0x410, 0x40c, 0x100, 0x100, 0x830, 0x86c, 0x800, 0x86c, 0x800,
9251 0x804, 0x20c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c, 0xc0c,
9252 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04, 0x01c
9255 static const unsigned int ca0113_mmio_init_data_ae5[] = {
9256 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
9257 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
9258 0x00000600, 0x00000014, 0x00000001, 0x0000060f, 0x0000070f,
9259 0x00000aff, 0x00000000, 0x0000006b, 0x00000001, 0x0000006b,
9260 0x00000057, 0x00800000, 0x00880680, 0x00000080, 0x00000030,
9261 0x00000000, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9262 0x00000001, 0x000000f1, 0x00000001, 0x000000c7, 0x000000c1,
9263 0x00000080, 0x00880680
9266 static void ca0132_mmio_init_sbz(struct hda_codec *codec)
9268 struct ca0132_spec *spec = codec->spec;
9269 unsigned int tmp[2], i, count, cur_addr;
9270 const unsigned int *addr, *data;
9272 addr = ca0113_mmio_init_address_sbz;
9273 for (i = 0; i < 3; i++)
9274 writel(0x00000000, spec->mem_base + addr[i]);
9277 switch (ca0132_quirk(spec)) {
9279 tmp[0] = 0x00880480;
9280 tmp[1] = 0x00000080;
9283 tmp[0] = 0x00820680;
9284 tmp[1] = 0x00000083;
9287 tmp[0] = 0x00880680;
9288 tmp[1] = 0x00000083;
9291 tmp[0] = 0x00000000;
9292 tmp[1] = 0x00000000;
9296 for (i = 0; i < 2; i++)
9297 writel(tmp[i], spec->mem_base + addr[cur_addr + i]);
9301 switch (ca0132_quirk(spec)) {
9303 count = ARRAY_SIZE(ca0113_mmio_init_data_zxr);
9304 data = ca0113_mmio_init_data_zxr;
9307 count = ARRAY_SIZE(ca0113_mmio_init_data_sbz);
9308 data = ca0113_mmio_init_data_sbz;
9312 for (i = 0; i < count; i++)
9313 writel(data[i], spec->mem_base + addr[cur_addr + i]);
9316 static void ca0132_mmio_init_ae5(struct hda_codec *codec)
9318 struct ca0132_spec *spec = codec->spec;
9319 const unsigned int *addr, *data;
9320 unsigned int i, count;
9322 addr = ca0113_mmio_init_address_ae5;
9323 data = ca0113_mmio_init_data_ae5;
9324 count = ARRAY_SIZE(ca0113_mmio_init_data_ae5);
9326 if (ca0132_quirk(spec) == QUIRK_AE7) {
9327 writel(0x00000680, spec->mem_base + 0x1c);
9328 writel(0x00880680, spec->mem_base + 0x1c);
9331 for (i = 0; i < count; i++) {
9333 * AE-7 shares all writes with the AE-5, except that it writes
9334 * a different value to 0x20c.
9336 if (i == 21 && ca0132_quirk(spec) == QUIRK_AE7) {
9337 writel(0x00800001, spec->mem_base + addr[i]);
9341 writel(data[i], spec->mem_base + addr[i]);
9344 if (ca0132_quirk(spec) == QUIRK_AE5)
9345 writel(0x00880680, spec->mem_base + 0x1c);
9348 static void ca0132_mmio_init(struct hda_codec *codec)
9350 struct ca0132_spec *spec = codec->spec;
9352 switch (ca0132_quirk(spec)) {
9356 ca0132_mmio_init_sbz(codec);
9359 ca0132_mmio_init_ae5(codec);
9366 static const unsigned int ca0132_ae5_register_set_addresses[] = {
9367 0x304, 0x304, 0x304, 0x304, 0x100, 0x304, 0x100, 0x304, 0x100, 0x304,
9368 0x100, 0x304, 0x86c, 0x800, 0x86c, 0x800, 0x804
9371 static const unsigned char ca0132_ae5_register_set_data[] = {
9372 0x0f, 0x0e, 0x1f, 0x0c, 0x3f, 0x08, 0x7f, 0x00, 0xff, 0x00, 0x6b,
9377 * This function writes to some SFR's, does some region2 writes, and then
9378 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
9381 static void ae5_register_set(struct hda_codec *codec)
9383 struct ca0132_spec *spec = codec->spec;
9384 unsigned int count = ARRAY_SIZE(ca0132_ae5_register_set_addresses);
9385 const unsigned int *addr = ca0132_ae5_register_set_addresses;
9386 const unsigned char *data = ca0132_ae5_register_set_data;
9387 unsigned int i, cur_addr;
9388 unsigned char tmp[3];
9390 if (ca0132_quirk(spec) == QUIRK_AE7)
9391 chipio_8051_write_pll_pmu(codec, 0x41, 0xc8);
9393 chipio_8051_write_direct(codec, 0x93, 0x10);
9394 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
9396 if (ca0132_quirk(spec) == QUIRK_AE7) {
9406 for (i = cur_addr = 0; i < 3; i++, cur_addr++)
9407 writeb(tmp[i], spec->mem_base + addr[cur_addr]);
9410 * First writes are in single bytes, final are in 4 bytes. So, we use
9411 * writeb, then writel.
9413 for (i = 0; cur_addr < 12; i++, cur_addr++)
9414 writeb(data[i], spec->mem_base + addr[cur_addr]);
9416 for (; cur_addr < count; i++, cur_addr++)
9417 writel(data[i], spec->mem_base + addr[cur_addr]);
9419 writel(0x00800001, spec->mem_base + 0x20c);
9421 if (ca0132_quirk(spec) == QUIRK_AE7) {
9422 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
9423 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
9425 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
9428 chipio_8051_write_direct(codec, 0x90, 0x00);
9429 chipio_8051_write_direct(codec, 0x90, 0x10);
9431 if (ca0132_quirk(spec) == QUIRK_AE5)
9432 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
9436 * Extra init functions for alternative ca0132 codecs. Done
9437 * here so they don't clutter up the main ca0132_init function
9438 * anymore than they have to.
9440 static void ca0132_alt_init(struct hda_codec *codec)
9442 struct ca0132_spec *spec = codec->spec;
9444 ca0132_alt_vol_setup(codec);
9446 switch (ca0132_quirk(spec)) {
9448 codec_dbg(codec, "SBZ alt_init");
9449 ca0132_gpio_init(codec);
9450 sbz_pre_dsp_setup(codec);
9451 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9452 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9455 codec_dbg(codec, "R3DI alt_init");
9456 ca0132_gpio_init(codec);
9457 ca0132_gpio_setup(codec);
9458 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
9459 r3di_pre_dsp_setup(codec);
9460 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9461 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
9464 r3d_pre_dsp_setup(codec);
9465 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9466 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9469 ca0132_gpio_init(codec);
9470 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9471 chipio_write(codec, 0x18b030, 0x00000020);
9472 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9473 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9474 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9477 ca0132_gpio_init(codec);
9478 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9479 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9480 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9481 chipio_write(codec, 0x18b008, 0x000000f8);
9482 chipio_write(codec, 0x18b008, 0x000000f0);
9483 chipio_write(codec, 0x18b030, 0x00000020);
9484 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9487 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9488 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9489 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9490 zxr_pre_dsp_setup(codec);
9497 static int ca0132_init(struct hda_codec *codec)
9499 struct ca0132_spec *spec = codec->spec;
9500 struct auto_pin_cfg *cfg = &spec->autocfg;
9505 * If the DSP is already downloaded, and init has been entered again,
9506 * there's only two reasons for it. One, the codec has awaken from a
9507 * suspended state, and in that case dspload_is_loaded will return
9508 * false, and the init will be ran again. The other reason it gets
9509 * re entered is on startup for some reason it triggers a suspend and
9510 * resume state. In this case, it will check if the DSP is downloaded,
9511 * and not run the init function again. For codecs using alt_functions,
9512 * it will check if the DSP is loaded properly.
9514 if (spec->dsp_state == DSP_DOWNLOADED) {
9515 dsp_loaded = dspload_is_loaded(codec);
9517 spec->dsp_reload = true;
9518 spec->dsp_state = DSP_DOWNLOAD_INIT;
9520 if (ca0132_quirk(spec) == QUIRK_SBZ)
9521 sbz_dsp_startup_check(codec);
9526 if (spec->dsp_state != DSP_DOWNLOAD_FAILED)
9527 spec->dsp_state = DSP_DOWNLOAD_INIT;
9528 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
9530 if (ca0132_use_pci_mmio(spec))
9531 ca0132_mmio_init(codec);
9533 snd_hda_power_up_pm(codec);
9535 if (ca0132_quirk(spec) == QUIRK_AE5 || ca0132_quirk(spec) == QUIRK_AE7)
9536 ae5_register_set(codec);
9538 ca0132_init_params(codec);
9539 ca0132_init_flags(codec);
9541 snd_hda_sequence_write(codec, spec->base_init_verbs);
9543 if (ca0132_use_alt_functions(spec))
9544 ca0132_alt_init(codec);
9546 ca0132_download_dsp(codec);
9548 ca0132_refresh_widget_caps(codec);
9550 switch (ca0132_quirk(spec)) {
9553 r3d_setup_defaults(codec);
9557 sbz_setup_defaults(codec);
9560 ae5_setup_defaults(codec);
9563 ae7_setup_defaults(codec);
9566 ca0132_setup_defaults(codec);
9567 ca0132_init_analog_mic2(codec);
9568 ca0132_init_dmic(codec);
9572 for (i = 0; i < spec->num_outputs; i++)
9573 init_output(codec, spec->out_pins[i], spec->dacs[0]);
9575 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9577 for (i = 0; i < spec->num_inputs; i++)
9578 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9580 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9582 if (!ca0132_use_alt_functions(spec)) {
9583 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9584 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9585 VENDOR_CHIPIO_PARAM_EX_ID_SET, 0x0D);
9586 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9587 VENDOR_CHIPIO_PARAM_EX_VALUE_SET, 0x20);
9590 if (ca0132_quirk(spec) == QUIRK_SBZ)
9591 ca0132_gpio_setup(codec);
9593 snd_hda_sequence_write(codec, spec->spec_init_verbs);
9594 if (ca0132_use_alt_functions(spec)) {
9595 ca0132_alt_select_out(codec);
9596 ca0132_alt_select_in(codec);
9598 ca0132_select_out(codec);
9599 ca0132_select_mic(codec);
9602 snd_hda_jack_report_sync(codec);
9605 * Re set the PlayEnhancement switch on a resume event, because the
9606 * controls will not be reloaded.
9608 if (spec->dsp_reload) {
9609 spec->dsp_reload = false;
9610 ca0132_pe_switch_set(codec);
9613 snd_hda_power_down_pm(codec);
9618 static int dbpro_init(struct hda_codec *codec)
9620 struct ca0132_spec *spec = codec->spec;
9621 struct auto_pin_cfg *cfg = &spec->autocfg;
9624 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9625 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9627 for (i = 0; i < spec->num_inputs; i++)
9628 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9633 static void ca0132_free(struct hda_codec *codec)
9635 struct ca0132_spec *spec = codec->spec;
9637 cancel_delayed_work_sync(&spec->unsol_hp_work);
9638 snd_hda_power_up(codec);
9639 switch (ca0132_quirk(spec)) {
9641 sbz_exit_chip(codec);
9644 zxr_exit_chip(codec);
9647 r3d_exit_chip(codec);
9650 ae5_exit_chip(codec);
9653 ae7_exit_chip(codec);
9656 r3di_gpio_shutdown(codec);
9662 snd_hda_sequence_write(codec, spec->base_exit_verbs);
9663 ca0132_exit_chip(codec);
9665 snd_hda_power_down(codec);
9668 pci_iounmap(codec->bus->pci, spec->mem_base);
9670 kfree(spec->spec_init_verbs);
9674 static void dbpro_free(struct hda_codec *codec)
9676 struct ca0132_spec *spec = codec->spec;
9678 zxr_dbpro_power_state_shutdown(codec);
9680 kfree(spec->spec_init_verbs);
9685 static int ca0132_suspend(struct hda_codec *codec)
9687 struct ca0132_spec *spec = codec->spec;
9689 cancel_delayed_work_sync(&spec->unsol_hp_work);
9694 static const struct hda_codec_ops ca0132_patch_ops = {
9695 .build_controls = ca0132_build_controls,
9696 .build_pcms = ca0132_build_pcms,
9697 .init = ca0132_init,
9698 .free = ca0132_free,
9699 .unsol_event = snd_hda_jack_unsol_event,
9701 .suspend = ca0132_suspend,
9705 static const struct hda_codec_ops dbpro_patch_ops = {
9706 .build_controls = dbpro_build_controls,
9707 .build_pcms = dbpro_build_pcms,
9712 static void ca0132_config(struct hda_codec *codec)
9714 struct ca0132_spec *spec = codec->spec;
9716 spec->dacs[0] = 0x2;
9717 spec->dacs[1] = 0x3;
9718 spec->dacs[2] = 0x4;
9720 spec->multiout.dac_nids = spec->dacs;
9721 spec->multiout.num_dacs = 3;
9723 if (!ca0132_use_alt_functions(spec))
9724 spec->multiout.max_channels = 2;
9726 spec->multiout.max_channels = 6;
9728 switch (ca0132_quirk(spec)) {
9729 case QUIRK_ALIENWARE:
9730 codec_dbg(codec, "%s: QUIRK_ALIENWARE applied.\n", __func__);
9731 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
9734 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
9735 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
9738 codec_dbg(codec, "%s: QUIRK_ZXR applied.\n", __func__);
9739 snd_hda_apply_pincfgs(codec, zxr_pincfgs);
9742 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
9743 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
9746 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
9747 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
9750 codec_dbg(codec, "%s: QUIRK_AE5 applied.\n", __func__);
9751 snd_hda_apply_pincfgs(codec, ae5_pincfgs);
9754 codec_dbg(codec, "%s: QUIRK_AE7 applied.\n", __func__);
9755 snd_hda_apply_pincfgs(codec, ae7_pincfgs);
9761 switch (ca0132_quirk(spec)) {
9762 case QUIRK_ALIENWARE:
9763 spec->num_outputs = 2;
9764 spec->out_pins[0] = 0x0b; /* speaker out */
9765 spec->out_pins[1] = 0x0f;
9766 spec->shared_out_nid = 0x2;
9767 spec->unsol_tag_hp = 0x0f;
9769 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
9770 spec->adcs[1] = 0x8; /* analog mic2 */
9771 spec->adcs[2] = 0xa; /* what u hear */
9773 spec->num_inputs = 3;
9774 spec->input_pins[0] = 0x12;
9775 spec->input_pins[1] = 0x11;
9776 spec->input_pins[2] = 0x13;
9777 spec->shared_mic_nid = 0x7;
9778 spec->unsol_tag_amic1 = 0x11;
9782 spec->num_outputs = 2;
9783 spec->out_pins[0] = 0x0B; /* Line out */
9784 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9785 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9786 spec->out_pins[3] = 0x11; /* Rear surround */
9787 spec->shared_out_nid = 0x2;
9788 spec->unsol_tag_hp = spec->out_pins[1];
9789 spec->unsol_tag_front_hp = spec->out_pins[2];
9791 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9792 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
9793 spec->adcs[2] = 0xa; /* what u hear */
9795 spec->num_inputs = 2;
9796 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9797 spec->input_pins[1] = 0x13; /* What U Hear */
9798 spec->shared_mic_nid = 0x7;
9799 spec->unsol_tag_amic1 = spec->input_pins[0];
9802 spec->dig_out = 0x05;
9803 spec->multiout.dig_out_nid = spec->dig_out;
9804 spec->dig_in = 0x09;
9807 spec->num_outputs = 2;
9808 spec->out_pins[0] = 0x0B; /* Line out */
9809 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9810 spec->out_pins[2] = 0x10; /* Center/LFE */
9811 spec->out_pins[3] = 0x11; /* Rear surround */
9812 spec->shared_out_nid = 0x2;
9813 spec->unsol_tag_hp = spec->out_pins[1];
9814 spec->unsol_tag_front_hp = spec->out_pins[2];
9816 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9817 spec->adcs[1] = 0x8; /* Not connected, no front mic */
9818 spec->adcs[2] = 0xa; /* what u hear */
9820 spec->num_inputs = 2;
9821 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9822 spec->input_pins[1] = 0x13; /* What U Hear */
9823 spec->shared_mic_nid = 0x7;
9824 spec->unsol_tag_amic1 = spec->input_pins[0];
9826 case QUIRK_ZXR_DBPRO:
9827 spec->adcs[0] = 0x8; /* ZxR DBPro Aux In */
9829 spec->num_inputs = 1;
9830 spec->input_pins[0] = 0x11; /* RCA Line-in */
9832 spec->dig_out = 0x05;
9833 spec->multiout.dig_out_nid = spec->dig_out;
9835 spec->dig_in = 0x09;
9839 spec->num_outputs = 2;
9840 spec->out_pins[0] = 0x0B; /* Line out */
9841 spec->out_pins[1] = 0x11; /* Rear headphone out */
9842 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9843 spec->out_pins[3] = 0x0F; /* Rear surround */
9844 spec->shared_out_nid = 0x2;
9845 spec->unsol_tag_hp = spec->out_pins[1];
9846 spec->unsol_tag_front_hp = spec->out_pins[2];
9848 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9849 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
9850 spec->adcs[2] = 0xa; /* what u hear */
9852 spec->num_inputs = 2;
9853 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9854 spec->input_pins[1] = 0x13; /* What U Hear */
9855 spec->shared_mic_nid = 0x7;
9856 spec->unsol_tag_amic1 = spec->input_pins[0];
9859 spec->dig_out = 0x05;
9860 spec->multiout.dig_out_nid = spec->dig_out;
9863 spec->num_outputs = 2;
9864 spec->out_pins[0] = 0x0B; /* Line out */
9865 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9866 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9867 spec->out_pins[3] = 0x11; /* Rear surround */
9868 spec->shared_out_nid = 0x2;
9869 spec->unsol_tag_hp = spec->out_pins[1];
9870 spec->unsol_tag_front_hp = spec->out_pins[2];
9872 spec->adcs[0] = 0x07; /* Rear Mic / Line-in */
9873 spec->adcs[1] = 0x08; /* Front Mic, but only if no DSP */
9874 spec->adcs[2] = 0x0a; /* what u hear */
9876 spec->num_inputs = 2;
9877 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9878 spec->input_pins[1] = 0x13; /* What U Hear */
9879 spec->shared_mic_nid = 0x7;
9880 spec->unsol_tag_amic1 = spec->input_pins[0];
9883 spec->dig_out = 0x05;
9884 spec->multiout.dig_out_nid = spec->dig_out;
9887 spec->num_outputs = 2;
9888 spec->out_pins[0] = 0x0b; /* speaker out */
9889 spec->out_pins[1] = 0x10; /* headphone out */
9890 spec->shared_out_nid = 0x2;
9891 spec->unsol_tag_hp = spec->out_pins[1];
9893 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
9894 spec->adcs[1] = 0x8; /* analog mic2 */
9895 spec->adcs[2] = 0xa; /* what u hear */
9897 spec->num_inputs = 3;
9898 spec->input_pins[0] = 0x12;
9899 spec->input_pins[1] = 0x11;
9900 spec->input_pins[2] = 0x13;
9901 spec->shared_mic_nid = 0x7;
9902 spec->unsol_tag_amic1 = spec->input_pins[0];
9905 spec->dig_out = 0x05;
9906 spec->multiout.dig_out_nid = spec->dig_out;
9907 spec->dig_in = 0x09;
9912 static int ca0132_prepare_verbs(struct hda_codec *codec)
9914 /* Verbs + terminator (an empty element) */
9915 #define NUM_SPEC_VERBS 2
9916 struct ca0132_spec *spec = codec->spec;
9918 spec->chip_init_verbs = ca0132_init_verbs0;
9920 * Since desktop cards use pci_mmio, this can be used to determine
9921 * whether or not to use these verbs instead of a separate bool.
9923 if (ca0132_use_pci_mmio(spec))
9924 spec->desktop_init_verbs = ca0132_init_verbs1;
9925 spec->spec_init_verbs = kcalloc(NUM_SPEC_VERBS,
9926 sizeof(struct hda_verb),
9928 if (!spec->spec_init_verbs)
9932 spec->spec_init_verbs[0].nid = 0x0b;
9933 spec->spec_init_verbs[0].param = 0x78D;
9934 spec->spec_init_verbs[0].verb = 0x00;
9936 /* Previously commented configuration */
9938 spec->spec_init_verbs[2].nid = 0x0b;
9939 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
9940 spec->spec_init_verbs[2].verb = 0x02;
9942 spec->spec_init_verbs[3].nid = 0x10;
9943 spec->spec_init_verbs[3].param = 0x78D;
9944 spec->spec_init_verbs[3].verb = 0x02;
9946 spec->spec_init_verbs[4].nid = 0x10;
9947 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
9948 spec->spec_init_verbs[4].verb = 0x02;
9951 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
9956 * The Sound Blaster ZxR shares the same PCI subsystem ID as some regular
9957 * Sound Blaster Z cards. However, they have different HDA codec subsystem
9958 * ID's. So, we check for the ZxR's subsystem ID, as well as the DBPro
9959 * daughter boards ID.
9961 static void sbz_detect_quirk(struct hda_codec *codec)
9963 struct ca0132_spec *spec = codec->spec;
9965 switch (codec->core.subsystem_id) {
9967 spec->quirk = QUIRK_ZXR;
9970 spec->quirk = QUIRK_ZXR_DBPRO;
9973 spec->quirk = QUIRK_SBZ;
9978 static int patch_ca0132(struct hda_codec *codec)
9980 struct ca0132_spec *spec;
9982 const struct snd_pci_quirk *quirk;
9984 codec_dbg(codec, "patch_ca0132\n");
9986 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9990 spec->codec = codec;
9992 /* Detect codec quirk */
9993 quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks);
9995 spec->quirk = quirk->value;
9997 spec->quirk = QUIRK_NONE;
9998 if (ca0132_quirk(spec) == QUIRK_SBZ)
9999 sbz_detect_quirk(codec);
10001 if (ca0132_quirk(spec) == QUIRK_ZXR_DBPRO)
10002 codec->patch_ops = dbpro_patch_ops;
10004 codec->patch_ops = ca0132_patch_ops;
10006 codec->pcm_format_first = 1;
10007 codec->no_sticky_stream = 1;
10010 spec->dsp_state = DSP_DOWNLOAD_INIT;
10011 spec->num_mixers = 1;
10013 /* Set which mixers each quirk uses. */
10014 switch (ca0132_quirk(spec)) {
10016 spec->mixers[0] = desktop_mixer;
10017 snd_hda_codec_set_name(codec, "Sound Blaster Z");
10020 spec->mixers[0] = desktop_mixer;
10021 snd_hda_codec_set_name(codec, "Sound Blaster ZxR");
10023 case QUIRK_ZXR_DBPRO:
10026 spec->mixers[0] = desktop_mixer;
10027 snd_hda_codec_set_name(codec, "Recon3D");
10030 spec->mixers[0] = r3di_mixer;
10031 snd_hda_codec_set_name(codec, "Recon3Di");
10034 spec->mixers[0] = desktop_mixer;
10035 snd_hda_codec_set_name(codec, "Sound BlasterX AE-5");
10038 spec->mixers[0] = desktop_mixer;
10039 snd_hda_codec_set_name(codec, "Sound Blaster AE-7");
10042 spec->mixers[0] = ca0132_mixer;
10046 /* Setup whether or not to use alt functions/controls/pci_mmio */
10047 switch (ca0132_quirk(spec)) {
10053 spec->use_alt_controls = true;
10054 spec->use_alt_functions = true;
10055 spec->use_pci_mmio = true;
10058 spec->use_alt_controls = true;
10059 spec->use_alt_functions = true;
10060 spec->use_pci_mmio = false;
10063 spec->use_alt_controls = false;
10064 spec->use_alt_functions = false;
10065 spec->use_pci_mmio = false;
10070 if (spec->use_pci_mmio) {
10071 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
10072 if (spec->mem_base == NULL) {
10073 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
10074 spec->quirk = QUIRK_NONE;
10079 spec->base_init_verbs = ca0132_base_init_verbs;
10080 spec->base_exit_verbs = ca0132_base_exit_verbs;
10082 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
10084 ca0132_init_chip(codec);
10086 ca0132_config(codec);
10088 err = ca0132_prepare_verbs(codec);
10092 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
10096 ca0132_setup_unsol(codec);
10101 ca0132_free(codec);
10108 static const struct hda_device_id snd_hda_id_ca0132[] = {
10109 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132),
10110 {} /* terminator */
10112 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132);
10114 MODULE_LICENSE("GPL");
10115 MODULE_DESCRIPTION("Creative Sound Core3D codec");
10117 static struct hda_codec_driver ca0132_driver = {
10118 .id = snd_hda_id_ca0132,
10121 module_hda_codec_driver(ca0132_driver);