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(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1308 SND_PCI_QUIRK(0x1102, 0x0018, "Recon3D", QUIRK_R3D),
1309 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5),
1310 SND_PCI_QUIRK(0x1102, 0x0191, "Sound Blaster AE-5 Plus", QUIRK_AE5),
1311 SND_PCI_QUIRK(0x1102, 0x0081, "Sound Blaster AE-7", QUIRK_AE7),
1315 /* Output selection quirk info structures. */
1316 #define MAX_QUIRK_MMIO_GPIO_SET_VALS 3
1317 #define MAX_QUIRK_SCP_SET_VALS 2
1318 struct ca0132_alt_out_set_info {
1319 unsigned int dac2port; /* ParamID 0x0d value. */
1325 unsigned int mmio_gpio_count;
1326 char mmio_gpio_pin[MAX_QUIRK_MMIO_GPIO_SET_VALS];
1327 char mmio_gpio_set[MAX_QUIRK_MMIO_GPIO_SET_VALS];
1329 unsigned int scp_cmds_count;
1330 unsigned int scp_cmd_mid[MAX_QUIRK_SCP_SET_VALS];
1331 unsigned int scp_cmd_req[MAX_QUIRK_SCP_SET_VALS];
1332 unsigned int scp_cmd_val[MAX_QUIRK_SCP_SET_VALS];
1334 bool has_chipio_write;
1335 unsigned int chipio_write_addr;
1336 unsigned int chipio_write_data;
1339 struct ca0132_alt_out_set_quirk_data {
1342 bool has_headphone_gain;
1345 struct ca0132_alt_out_set_info out_set_info[NUM_OF_OUTPUTS];
1348 static const struct ca0132_alt_out_set_quirk_data quirk_out_set_data[] = {
1349 { .quirk_id = QUIRK_R3DI,
1350 .has_headphone_gain = false,
1351 .is_ae_series = false,
1355 .has_hda_gpio = true,
1358 .mmio_gpio_count = 0,
1359 .scp_cmds_count = 0,
1360 .has_chipio_write = false,
1364 .has_hda_gpio = true,
1367 .mmio_gpio_count = 0,
1368 .scp_cmds_count = 0,
1369 .has_chipio_write = false,
1372 { .quirk_id = QUIRK_R3D,
1373 .has_headphone_gain = false,
1374 .is_ae_series = false,
1378 .has_hda_gpio = false,
1379 .mmio_gpio_count = 1,
1380 .mmio_gpio_pin = { 1 },
1381 .mmio_gpio_set = { 1 },
1382 .scp_cmds_count = 0,
1383 .has_chipio_write = false,
1387 .has_hda_gpio = false,
1388 .mmio_gpio_count = 1,
1389 .mmio_gpio_pin = { 1 },
1390 .mmio_gpio_set = { 0 },
1391 .scp_cmds_count = 0,
1392 .has_chipio_write = false,
1395 { .quirk_id = QUIRK_SBZ,
1396 .has_headphone_gain = false,
1397 .is_ae_series = false,
1401 .has_hda_gpio = false,
1402 .mmio_gpio_count = 3,
1403 .mmio_gpio_pin = { 7, 4, 1 },
1404 .mmio_gpio_set = { 0, 1, 1 },
1405 .scp_cmds_count = 0,
1406 .has_chipio_write = false, },
1409 .has_hda_gpio = false,
1410 .mmio_gpio_count = 3,
1411 .mmio_gpio_pin = { 7, 4, 1 },
1412 .mmio_gpio_set = { 1, 1, 0 },
1413 .scp_cmds_count = 0,
1414 .has_chipio_write = false,
1417 { .quirk_id = QUIRK_ZXR,
1418 .has_headphone_gain = true,
1419 .is_ae_series = false,
1423 .has_hda_gpio = false,
1424 .mmio_gpio_count = 3,
1425 .mmio_gpio_pin = { 2, 3, 5 },
1426 .mmio_gpio_set = { 1, 1, 0 },
1427 .scp_cmds_count = 0,
1428 .has_chipio_write = false,
1432 .has_hda_gpio = false,
1433 .mmio_gpio_count = 3,
1434 .mmio_gpio_pin = { 2, 3, 5 },
1435 .mmio_gpio_set = { 0, 1, 1 },
1436 .scp_cmds_count = 0,
1437 .has_chipio_write = false,
1440 { .quirk_id = QUIRK_AE5,
1441 .has_headphone_gain = true,
1442 .is_ae_series = true,
1446 .has_hda_gpio = false,
1447 .mmio_gpio_count = 0,
1448 .scp_cmds_count = 2,
1449 .scp_cmd_mid = { 0x96, 0x96 },
1450 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1451 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1452 .scp_cmd_val = { FLOAT_ZERO, FLOAT_ZERO },
1453 .has_chipio_write = true,
1454 .chipio_write_addr = 0x0018b03c,
1455 .chipio_write_data = 0x00000012
1459 .has_hda_gpio = false,
1460 .mmio_gpio_count = 0,
1461 .scp_cmds_count = 2,
1462 .scp_cmd_mid = { 0x96, 0x96 },
1463 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1464 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1465 .scp_cmd_val = { FLOAT_ONE, FLOAT_ONE },
1466 .has_chipio_write = true,
1467 .chipio_write_addr = 0x0018b03c,
1468 .chipio_write_data = 0x00000012
1471 { .quirk_id = QUIRK_AE7,
1472 .has_headphone_gain = true,
1473 .is_ae_series = true,
1477 .has_hda_gpio = false,
1478 .mmio_gpio_count = 1,
1479 .mmio_gpio_pin = { 0 },
1480 .mmio_gpio_set = { 1 },
1481 .scp_cmds_count = 2,
1482 .scp_cmd_mid = { 0x96, 0x96 },
1483 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1484 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1485 .scp_cmd_val = { FLOAT_ZERO, FLOAT_ZERO },
1486 .has_chipio_write = true,
1487 .chipio_write_addr = 0x0018b03c,
1488 .chipio_write_data = 0x00000000
1492 .has_hda_gpio = false,
1493 .mmio_gpio_count = 1,
1494 .mmio_gpio_pin = { 0 },
1495 .mmio_gpio_set = { 1 },
1496 .scp_cmds_count = 2,
1497 .scp_cmd_mid = { 0x96, 0x96 },
1498 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1499 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1500 .scp_cmd_val = { FLOAT_ONE, FLOAT_ONE },
1501 .has_chipio_write = true,
1502 .chipio_write_addr = 0x0018b03c,
1503 .chipio_write_data = 0x00000010
1509 * CA0132 codec access
1511 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1512 unsigned int verb, unsigned int parm, unsigned int *res)
1514 unsigned int response;
1515 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1518 return ((response == -1) ? -1 : 0);
1521 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1522 unsigned short converter_format, unsigned int *res)
1524 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1525 converter_format & 0xffff, res);
1528 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1529 hda_nid_t nid, unsigned char stream,
1530 unsigned char channel, unsigned int *res)
1532 unsigned char converter_stream_channel = 0;
1534 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1535 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1536 converter_stream_channel, res);
1539 /* Chip access helper function */
1540 static int chipio_send(struct hda_codec *codec,
1545 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1547 /* send bits of data specified by reg */
1549 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1551 if (res == VENDOR_STATUS_CHIPIO_OK)
1554 } while (time_before(jiffies, timeout));
1560 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1562 static int chipio_write_address(struct hda_codec *codec,
1563 unsigned int chip_addx)
1565 struct ca0132_spec *spec = codec->spec;
1568 if (spec->curr_chip_addx == chip_addx)
1571 /* send low 16 bits of the address */
1572 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1573 chip_addx & 0xffff);
1576 /* send high 16 bits of the address */
1577 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1581 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1587 * Write data through the vendor widget -- NOT protected by the Mutex!
1589 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1591 struct ca0132_spec *spec = codec->spec;
1594 /* send low 16 bits of the data */
1595 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1598 /* send high 16 bits of the data */
1599 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1603 /*If no error encountered, automatically increment the address
1604 as per chip behaviour*/
1605 spec->curr_chip_addx = (res != -EIO) ?
1606 (spec->curr_chip_addx + 4) : ~0U;
1611 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1613 static int chipio_write_data_multiple(struct hda_codec *codec,
1620 codec_dbg(codec, "chipio_write_data null ptr\n");
1624 while ((count-- != 0) && (status == 0))
1625 status = chipio_write_data(codec, *data++);
1632 * Read data through the vendor widget -- NOT protected by the Mutex!
1634 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1636 struct ca0132_spec *spec = codec->spec;
1640 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1644 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1649 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1650 VENDOR_CHIPIO_HIC_READ_DATA,
1654 /*If no error encountered, automatically increment the address
1655 as per chip behaviour*/
1656 spec->curr_chip_addx = (res != -EIO) ?
1657 (spec->curr_chip_addx + 4) : ~0U;
1662 * Write given value to the given address through the chip I/O widget.
1663 * protected by the Mutex
1665 static int chipio_write(struct hda_codec *codec,
1666 unsigned int chip_addx, const unsigned int data)
1668 struct ca0132_spec *spec = codec->spec;
1671 mutex_lock(&spec->chipio_mutex);
1673 /* write the address, and if successful proceed to write data */
1674 err = chipio_write_address(codec, chip_addx);
1678 err = chipio_write_data(codec, data);
1683 mutex_unlock(&spec->chipio_mutex);
1688 * Write given value to the given address through the chip I/O widget.
1689 * not protected by the Mutex
1691 static int chipio_write_no_mutex(struct hda_codec *codec,
1692 unsigned int chip_addx, const unsigned int data)
1697 /* write the address, and if successful proceed to write data */
1698 err = chipio_write_address(codec, chip_addx);
1702 err = chipio_write_data(codec, data);
1711 * Write multiple values to the given address through the chip I/O widget.
1712 * protected by the Mutex
1714 static int chipio_write_multiple(struct hda_codec *codec,
1719 struct ca0132_spec *spec = codec->spec;
1722 mutex_lock(&spec->chipio_mutex);
1723 status = chipio_write_address(codec, chip_addx);
1727 status = chipio_write_data_multiple(codec, data, count);
1729 mutex_unlock(&spec->chipio_mutex);
1735 * Read the given address through the chip I/O widget
1736 * protected by the Mutex
1738 static int chipio_read(struct hda_codec *codec,
1739 unsigned int chip_addx, unsigned int *data)
1741 struct ca0132_spec *spec = codec->spec;
1744 mutex_lock(&spec->chipio_mutex);
1746 /* write the address, and if successful proceed to write data */
1747 err = chipio_write_address(codec, chip_addx);
1751 err = chipio_read_data(codec, data);
1756 mutex_unlock(&spec->chipio_mutex);
1761 * Set chip control flags through the chip I/O widget.
1763 static void chipio_set_control_flag(struct hda_codec *codec,
1764 enum control_flag_id flag_id,
1768 unsigned int flag_bit;
1770 flag_bit = (flag_state ? 1 : 0);
1771 val = (flag_bit << 7) | (flag_id);
1772 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1773 VENDOR_CHIPIO_FLAG_SET, val);
1777 * Set chip parameters through the chip I/O widget.
1779 static void chipio_set_control_param(struct hda_codec *codec,
1780 enum control_param_id param_id, int param_val)
1782 struct ca0132_spec *spec = codec->spec;
1785 if ((param_id < 32) && (param_val < 8)) {
1786 val = (param_val << 5) | (param_id);
1787 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1788 VENDOR_CHIPIO_PARAM_SET, val);
1790 mutex_lock(&spec->chipio_mutex);
1791 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1792 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1793 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1795 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1796 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1799 mutex_unlock(&spec->chipio_mutex);
1804 * Set chip parameters through the chip I/O widget. NO MUTEX.
1806 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1807 enum control_param_id param_id, int param_val)
1811 if ((param_id < 32) && (param_val < 8)) {
1812 val = (param_val << 5) | (param_id);
1813 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1814 VENDOR_CHIPIO_PARAM_SET, val);
1816 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1817 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1818 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1820 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1821 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1827 * Connect stream to a source point, and then connect
1828 * that source point to a destination point.
1830 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1831 int streamid, int source_point, int dest_point)
1833 chipio_set_control_param_no_mutex(codec,
1834 CONTROL_PARAM_STREAM_ID, streamid);
1835 chipio_set_control_param_no_mutex(codec,
1836 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1837 chipio_set_control_param_no_mutex(codec,
1838 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1842 * Set number of channels in the selected stream.
1844 static void chipio_set_stream_channels(struct hda_codec *codec,
1845 int streamid, unsigned int channels)
1847 chipio_set_control_param_no_mutex(codec,
1848 CONTROL_PARAM_STREAM_ID, streamid);
1849 chipio_set_control_param_no_mutex(codec,
1850 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1854 * Enable/Disable audio stream.
1856 static void chipio_set_stream_control(struct hda_codec *codec,
1857 int streamid, int enable)
1859 chipio_set_control_param_no_mutex(codec,
1860 CONTROL_PARAM_STREAM_ID, streamid);
1861 chipio_set_control_param_no_mutex(codec,
1862 CONTROL_PARAM_STREAM_CONTROL, enable);
1866 * Get ChipIO audio stream's status.
1868 static void chipio_get_stream_control(struct hda_codec *codec,
1869 int streamid, unsigned int *enable)
1871 chipio_set_control_param_no_mutex(codec,
1872 CONTROL_PARAM_STREAM_ID, streamid);
1873 *enable = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1874 VENDOR_CHIPIO_PARAM_GET,
1875 CONTROL_PARAM_STREAM_CONTROL);
1879 * Set sampling rate of the connection point. NO MUTEX.
1881 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1882 int connid, enum ca0132_sample_rate rate)
1884 chipio_set_control_param_no_mutex(codec,
1885 CONTROL_PARAM_CONN_POINT_ID, connid);
1886 chipio_set_control_param_no_mutex(codec,
1887 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1891 * Set sampling rate of the connection point.
1893 static void chipio_set_conn_rate(struct hda_codec *codec,
1894 int connid, enum ca0132_sample_rate rate)
1896 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1897 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1902 * Writes to the 8051's internal address space directly instead of indirectly,
1903 * giving access to the special function registers located at addresses
1906 static void chipio_8051_write_direct(struct hda_codec *codec,
1907 unsigned int addr, unsigned int data)
1911 verb = VENDOR_CHIPIO_8051_WRITE_DIRECT | data;
1912 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1916 * Writes to the 8051's exram, which has 16-bits of address space.
1917 * Data at addresses 0x2000-0x7fff is mirrored to 0x8000-0xdfff.
1918 * Data at 0x8000-0xdfff can also be used as program memory for the 8051 by
1919 * setting the pmem bank selection SFR.
1920 * 0xe000-0xffff is always mapped as program memory, with only 0xf000-0xffff
1923 static void chipio_8051_set_address(struct hda_codec *codec, unsigned int addr)
1929 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1930 VENDOR_CHIPIO_8051_ADDRESS_LOW, tmp);
1933 tmp = (addr >> 8) & 0xff;
1934 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1935 VENDOR_CHIPIO_8051_ADDRESS_HIGH, tmp);
1938 static void chipio_8051_set_data(struct hda_codec *codec, unsigned int data)
1940 /* 8-bits of data. */
1941 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1942 VENDOR_CHIPIO_8051_DATA_WRITE, data & 0xff);
1945 static unsigned int chipio_8051_get_data(struct hda_codec *codec)
1947 return snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1948 VENDOR_CHIPIO_8051_DATA_READ, 0);
1951 /* PLL_PMU writes share the lower address register of the 8051 exram writes. */
1952 static void chipio_8051_set_data_pll(struct hda_codec *codec, unsigned int data)
1954 /* 8-bits of data. */
1955 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1956 VENDOR_CHIPIO_PLL_PMU_WRITE, data & 0xff);
1959 static void chipio_8051_write_exram(struct hda_codec *codec,
1960 unsigned int addr, unsigned int data)
1962 struct ca0132_spec *spec = codec->spec;
1964 mutex_lock(&spec->chipio_mutex);
1966 chipio_8051_set_address(codec, addr);
1967 chipio_8051_set_data(codec, data);
1969 mutex_unlock(&spec->chipio_mutex);
1972 static void chipio_8051_write_exram_no_mutex(struct hda_codec *codec,
1973 unsigned int addr, unsigned int data)
1975 chipio_8051_set_address(codec, addr);
1976 chipio_8051_set_data(codec, data);
1979 /* Readback data from the 8051's exram. No mutex. */
1980 static void chipio_8051_read_exram(struct hda_codec *codec,
1981 unsigned int addr, unsigned int *data)
1983 chipio_8051_set_address(codec, addr);
1984 *data = chipio_8051_get_data(codec);
1987 static void chipio_8051_write_pll_pmu(struct hda_codec *codec,
1988 unsigned int addr, unsigned int data)
1990 struct ca0132_spec *spec = codec->spec;
1992 mutex_lock(&spec->chipio_mutex);
1994 chipio_8051_set_address(codec, addr & 0xff);
1995 chipio_8051_set_data_pll(codec, data);
1997 mutex_unlock(&spec->chipio_mutex);
2000 static void chipio_8051_write_pll_pmu_no_mutex(struct hda_codec *codec,
2001 unsigned int addr, unsigned int data)
2003 chipio_8051_set_address(codec, addr & 0xff);
2004 chipio_8051_set_data_pll(codec, data);
2010 static void chipio_enable_clocks(struct hda_codec *codec)
2012 struct ca0132_spec *spec = codec->spec;
2014 mutex_lock(&spec->chipio_mutex);
2016 chipio_8051_write_pll_pmu_no_mutex(codec, 0x00, 0xff);
2017 chipio_8051_write_pll_pmu_no_mutex(codec, 0x05, 0x0b);
2018 chipio_8051_write_pll_pmu_no_mutex(codec, 0x06, 0xff);
2020 mutex_unlock(&spec->chipio_mutex);
2024 * CA0132 DSP IO stuffs
2026 static int dspio_send(struct hda_codec *codec, unsigned int reg,
2030 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2032 /* send bits of data specified by reg to dsp */
2034 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
2035 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
2038 } while (time_before(jiffies, timeout));
2044 * Wait for DSP to be ready for commands
2046 static void dspio_write_wait(struct hda_codec *codec)
2049 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2052 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2053 VENDOR_DSPIO_STATUS, 0);
2054 if ((status == VENDOR_STATUS_DSPIO_OK) ||
2055 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
2058 } while (time_before(jiffies, timeout));
2062 * Write SCP data to DSP
2064 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
2066 struct ca0132_spec *spec = codec->spec;
2069 dspio_write_wait(codec);
2071 mutex_lock(&spec->chipio_mutex);
2072 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
2077 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
2082 /* OK, now check if the write itself has executed*/
2083 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2084 VENDOR_DSPIO_STATUS, 0);
2086 mutex_unlock(&spec->chipio_mutex);
2088 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
2093 * Write multiple SCP data to DSP
2095 static int dspio_write_multiple(struct hda_codec *codec,
2096 unsigned int *buffer, unsigned int size)
2105 while (count < size) {
2106 status = dspio_write(codec, *buffer++);
2115 static int dspio_read(struct hda_codec *codec, unsigned int *data)
2119 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
2123 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
2124 if (status == -EIO ||
2125 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
2128 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2129 VENDOR_DSPIO_SCP_READ_DATA, 0);
2134 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
2135 unsigned int *buf_size, unsigned int size_count)
2138 unsigned int size = *buf_size;
2140 unsigned int skip_count;
2147 while (count < size && count < size_count) {
2148 status = dspio_read(codec, buffer++);
2156 while (skip_count < size) {
2157 status = dspio_read(codec, &dummy);
2169 * Construct the SCP header using corresponding fields
2171 static inline unsigned int
2172 make_scp_header(unsigned int target_id, unsigned int source_id,
2173 unsigned int get_flag, unsigned int req,
2174 unsigned int device_flag, unsigned int resp_flag,
2175 unsigned int error_flag, unsigned int data_size)
2177 unsigned int header = 0;
2179 header = (data_size & 0x1f) << 27;
2180 header |= (error_flag & 0x01) << 26;
2181 header |= (resp_flag & 0x01) << 25;
2182 header |= (device_flag & 0x01) << 24;
2183 header |= (req & 0x7f) << 17;
2184 header |= (get_flag & 0x01) << 16;
2185 header |= (source_id & 0xff) << 8;
2186 header |= target_id & 0xff;
2192 * Extract corresponding fields from SCP header
2195 extract_scp_header(unsigned int header,
2196 unsigned int *target_id, unsigned int *source_id,
2197 unsigned int *get_flag, unsigned int *req,
2198 unsigned int *device_flag, unsigned int *resp_flag,
2199 unsigned int *error_flag, unsigned int *data_size)
2202 *data_size = (header >> 27) & 0x1f;
2204 *error_flag = (header >> 26) & 0x01;
2206 *resp_flag = (header >> 25) & 0x01;
2208 *device_flag = (header >> 24) & 0x01;
2210 *req = (header >> 17) & 0x7f;
2212 *get_flag = (header >> 16) & 0x01;
2214 *source_id = (header >> 8) & 0xff;
2216 *target_id = header & 0xff;
2219 #define SCP_MAX_DATA_WORDS (16)
2221 /* Structure to contain any SCP message */
2224 unsigned int data[SCP_MAX_DATA_WORDS];
2227 static void dspio_clear_response_queue(struct hda_codec *codec)
2229 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2230 unsigned int dummy = 0;
2233 /* clear all from the response queue */
2235 status = dspio_read(codec, &dummy);
2236 } while (status == 0 && time_before(jiffies, timeout));
2239 static int dspio_get_response_data(struct hda_codec *codec)
2241 struct ca0132_spec *spec = codec->spec;
2242 unsigned int data = 0;
2245 if (dspio_read(codec, &data) < 0)
2248 if ((data & 0x00ffffff) == spec->wait_scp_header) {
2249 spec->scp_resp_header = data;
2250 spec->scp_resp_count = data >> 27;
2251 count = spec->wait_num_data;
2252 dspio_read_multiple(codec, spec->scp_resp_data,
2253 &spec->scp_resp_count, count);
2261 * Send SCP message to DSP
2263 static int dspio_send_scp_message(struct hda_codec *codec,
2264 unsigned char *send_buf,
2265 unsigned int send_buf_size,
2266 unsigned char *return_buf,
2267 unsigned int return_buf_size,
2268 unsigned int *bytes_returned)
2270 struct ca0132_spec *spec = codec->spec;
2272 unsigned int scp_send_size = 0;
2273 unsigned int total_size;
2274 bool waiting_for_resp = false;
2275 unsigned int header;
2276 struct scp_msg *ret_msg;
2277 unsigned int resp_src_id, resp_target_id;
2278 unsigned int data_size, src_id, target_id, get_flag, device_flag;
2281 *bytes_returned = 0;
2283 /* get scp header from buffer */
2284 header = *((unsigned int *)send_buf);
2285 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
2286 &device_flag, NULL, NULL, &data_size);
2287 scp_send_size = data_size + 1;
2288 total_size = (scp_send_size * 4);
2290 if (send_buf_size < total_size)
2293 if (get_flag || device_flag) {
2294 if (!return_buf || return_buf_size < 4 || !bytes_returned)
2297 spec->wait_scp_header = *((unsigned int *)send_buf);
2299 /* swap source id with target id */
2300 resp_target_id = src_id;
2301 resp_src_id = target_id;
2302 spec->wait_scp_header &= 0xffff0000;
2303 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
2304 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
2306 waiting_for_resp = true;
2309 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
2316 if (waiting_for_resp) {
2317 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2318 memset(return_buf, 0, return_buf_size);
2321 } while (spec->wait_scp && time_before(jiffies, timeout));
2322 waiting_for_resp = false;
2323 if (!spec->wait_scp) {
2324 ret_msg = (struct scp_msg *)return_buf;
2325 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
2326 memcpy(&ret_msg->data, spec->scp_resp_data,
2327 spec->wait_num_data);
2328 *bytes_returned = (spec->scp_resp_count + 1) * 4;
2340 * dspio_scp - Prepare and send the SCP message to DSP
2341 * @codec: the HDA codec
2342 * @mod_id: ID of the DSP module to send the command
2343 * @src_id: ID of the source
2344 * @req: ID of request to send to the DSP module
2346 * @data: pointer to the data to send with the request, request specific
2347 * @len: length of the data, in bytes
2348 * @reply: point to the buffer to hold data returned for a reply
2349 * @reply_len: length of the reply buffer returned from GET
2351 * Returns zero or a negative error code.
2353 static int dspio_scp(struct hda_codec *codec,
2354 int mod_id, int src_id, int req, int dir, const void *data,
2355 unsigned int len, void *reply, unsigned int *reply_len)
2358 struct scp_msg scp_send, scp_reply;
2359 unsigned int ret_bytes, send_size, ret_size;
2360 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
2361 unsigned int reply_data_size;
2363 memset(&scp_send, 0, sizeof(scp_send));
2364 memset(&scp_reply, 0, sizeof(scp_reply));
2366 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
2369 if (dir == SCP_GET && reply == NULL) {
2370 codec_dbg(codec, "dspio_scp get but has no buffer\n");
2374 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
2375 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
2379 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
2380 0, 0, 0, len/sizeof(unsigned int));
2381 if (data != NULL && len > 0) {
2382 len = min((unsigned int)(sizeof(scp_send.data)), len);
2383 memcpy(scp_send.data, data, len);
2387 send_size = sizeof(unsigned int) + len;
2388 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
2389 send_size, (unsigned char *)&scp_reply,
2390 sizeof(scp_reply), &ret_bytes);
2393 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
2397 /* extract send and reply headers members */
2398 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
2399 NULL, NULL, NULL, NULL, NULL);
2400 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
2401 &reply_resp_flag, &reply_error_flag,
2407 if (reply_resp_flag && !reply_error_flag) {
2408 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
2409 / sizeof(unsigned int);
2411 if (*reply_len < ret_size*sizeof(unsigned int)) {
2412 codec_dbg(codec, "reply too long for buf\n");
2414 } else if (ret_size != reply_data_size) {
2415 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
2417 } else if (!reply) {
2418 codec_dbg(codec, "NULL reply\n");
2421 *reply_len = ret_size*sizeof(unsigned int);
2422 memcpy(reply, scp_reply.data, *reply_len);
2425 codec_dbg(codec, "reply ill-formed or errflag set\n");
2433 * Set DSP parameters
2435 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2436 int src_id, int req, const void *data, unsigned int len)
2438 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2442 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2443 int req, const unsigned int data)
2445 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2446 sizeof(unsigned int));
2450 * Allocate a DSP DMA channel via an SCP message
2452 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2455 unsigned int size = sizeof(dma_chan);
2457 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2458 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2459 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
2463 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2467 if ((*dma_chan + 1) == 0) {
2468 codec_dbg(codec, "no free dma channels to allocate\n");
2472 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2473 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2479 * Free a DSP DMA via an SCP message
2481 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2484 unsigned int dummy = 0;
2486 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2487 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2489 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2490 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
2491 sizeof(dma_chan), NULL, &dummy);
2494 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2498 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2506 static int dsp_set_run_state(struct hda_codec *codec)
2508 unsigned int dbg_ctrl_reg;
2509 unsigned int halt_state;
2512 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2516 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
2517 DSP_DBGCNTL_STATE_LOBIT;
2519 if (halt_state != 0) {
2520 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
2521 DSP_DBGCNTL_SS_MASK);
2522 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2527 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
2528 DSP_DBGCNTL_EXEC_MASK;
2529 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2541 static int dsp_reset(struct hda_codec *codec)
2546 codec_dbg(codec, "dsp_reset\n");
2548 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2550 } while (res == -EIO && retry);
2553 codec_dbg(codec, "dsp_reset timeout\n");
2561 * Convert chip address to DSP address
2563 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2564 bool *code, bool *yram)
2566 *code = *yram = false;
2568 if (UC_RANGE(chip_addx, 1)) {
2570 return UC_OFF(chip_addx);
2571 } else if (X_RANGE_ALL(chip_addx, 1)) {
2572 return X_OFF(chip_addx);
2573 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2575 return Y_OFF(chip_addx);
2578 return INVALID_CHIP_ADDRESS;
2582 * Check if the DSP DMA is active
2584 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2586 unsigned int dma_chnlstart_reg;
2588 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2590 return ((dma_chnlstart_reg & (1 <<
2591 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2594 static int dsp_dma_setup_common(struct hda_codec *codec,
2595 unsigned int chip_addx,
2596 unsigned int dma_chan,
2597 unsigned int port_map_mask,
2601 unsigned int chnl_prop;
2602 unsigned int dsp_addx;
2603 unsigned int active;
2606 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2608 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2609 codec_dbg(codec, "dma chan num invalid\n");
2613 if (dsp_is_dma_active(codec, dma_chan)) {
2614 codec_dbg(codec, "dma already active\n");
2618 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2620 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2621 codec_dbg(codec, "invalid chip addr\n");
2625 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2628 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2631 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2635 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2638 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2642 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2644 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2646 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2648 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2650 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2653 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2656 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2660 codec_dbg(codec, "read ACTIVE Reg fail\n");
2663 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2666 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2667 DSPDMAC_ACTIVE_AAR_MASK;
2669 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2671 codec_dbg(codec, "write ACTIVE Reg fail\n");
2675 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2677 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2680 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2683 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2685 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2686 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2688 codec_dbg(codec, "write IRQCNT Reg fail\n");
2691 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2694 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2695 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2696 chip_addx, dsp_addx, dma_chan,
2697 port_map_mask, chnl_prop, active);
2699 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2705 * Setup the DSP DMA per-transfer-specific registers
2707 static int dsp_dma_setup(struct hda_codec *codec,
2708 unsigned int chip_addx,
2710 unsigned int dma_chan)
2714 unsigned int dsp_addx;
2715 unsigned int addr_field;
2716 unsigned int incr_field;
2717 unsigned int base_cnt;
2718 unsigned int cur_cnt;
2719 unsigned int dma_cfg = 0;
2720 unsigned int adr_ofs = 0;
2721 unsigned int xfr_cnt = 0;
2722 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2723 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2725 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2727 if (count > max_dma_count) {
2728 codec_dbg(codec, "count too big\n");
2732 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2733 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2734 codec_dbg(codec, "invalid chip addr\n");
2738 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2740 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2746 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2748 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2751 dma_cfg = addr_field + incr_field;
2752 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2755 codec_dbg(codec, "write DMACFG Reg fail\n");
2758 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2760 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2763 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2766 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2769 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2771 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2773 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2775 xfr_cnt = base_cnt | cur_cnt;
2777 status = chipio_write(codec,
2778 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2780 codec_dbg(codec, "write XFRCNT Reg fail\n");
2783 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2786 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2787 "ADROFS=0x%x, XFRCNT=0x%x\n",
2788 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2790 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2798 static int dsp_dma_start(struct hda_codec *codec,
2799 unsigned int dma_chan, bool ovly)
2801 unsigned int reg = 0;
2804 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2807 status = chipio_read(codec,
2808 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2811 codec_dbg(codec, "read CHNLSTART reg fail\n");
2814 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2816 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2817 DSPDMAC_CHNLSTART_DIS_MASK);
2820 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2821 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2823 codec_dbg(codec, "write CHNLSTART reg fail\n");
2826 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2834 static int dsp_dma_stop(struct hda_codec *codec,
2835 unsigned int dma_chan, bool ovly)
2837 unsigned int reg = 0;
2840 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2843 status = chipio_read(codec,
2844 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2847 codec_dbg(codec, "read CHNLSTART reg fail\n");
2850 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2851 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2852 DSPDMAC_CHNLSTART_DIS_MASK);
2855 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2856 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2858 codec_dbg(codec, "write CHNLSTART reg fail\n");
2861 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2867 * dsp_allocate_router_ports - Allocate router ports
2869 * @codec: the HDA codec
2870 * @num_chans: number of channels in the stream
2871 * @ports_per_channel: number of ports per channel
2872 * @start_device: start device
2873 * @port_map: pointer to the port list to hold the allocated ports
2875 * Returns zero or a negative error code.
2877 static int dsp_allocate_router_ports(struct hda_codec *codec,
2878 unsigned int num_chans,
2879 unsigned int ports_per_channel,
2880 unsigned int start_device,
2881 unsigned int *port_map)
2887 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2891 val = start_device << 6;
2892 val |= (ports_per_channel - 1) << 4;
2893 val |= num_chans - 1;
2895 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2896 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2899 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2900 VENDOR_CHIPIO_PORT_ALLOC_SET,
2903 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2907 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2908 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2912 return (res < 0) ? res : 0;
2918 static int dsp_free_router_ports(struct hda_codec *codec)
2922 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2926 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2927 VENDOR_CHIPIO_PORT_FREE_SET,
2930 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2936 * Allocate DSP ports for the download stream
2938 static int dsp_allocate_ports(struct hda_codec *codec,
2939 unsigned int num_chans,
2940 unsigned int rate_multi, unsigned int *port_map)
2944 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2946 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2947 codec_dbg(codec, "bad rate multiple\n");
2951 status = dsp_allocate_router_ports(codec, num_chans,
2952 rate_multi, 0, port_map);
2954 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2959 static int dsp_allocate_ports_format(struct hda_codec *codec,
2960 const unsigned short fmt,
2961 unsigned int *port_map)
2964 unsigned int num_chans;
2966 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2967 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2968 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2970 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2971 codec_dbg(codec, "bad rate multiple\n");
2975 num_chans = get_hdafmt_chs(fmt) + 1;
2977 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2985 static int dsp_free_ports(struct hda_codec *codec)
2989 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2991 status = dsp_free_router_ports(codec);
2993 codec_dbg(codec, "free router ports fail\n");
2996 codec_dbg(codec, " dsp_free_ports() -- complete\n");
3002 * HDA DMA engine stuffs for DSP code download
3005 struct hda_codec *codec;
3006 unsigned short m_converter_format;
3007 struct snd_dma_buffer *dmab;
3008 unsigned int buf_size;
3017 static int dma_convert_to_hda_format(struct hda_codec *codec,
3018 unsigned int sample_rate,
3019 unsigned short channels,
3020 unsigned short *hda_format)
3022 unsigned int format_val;
3024 format_val = snd_hdac_calc_stream_format(sample_rate,
3025 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
3028 *hda_format = (unsigned short)format_val;
3034 * Reset DMA for DSP download
3036 static int dma_reset(struct dma_engine *dma)
3038 struct hda_codec *codec = dma->codec;
3039 struct ca0132_spec *spec = codec->spec;
3042 if (dma->dmab->area)
3043 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
3045 status = snd_hda_codec_load_dsp_prepare(codec,
3046 dma->m_converter_format,
3051 spec->dsp_stream_id = status;
3055 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
3060 case DMA_STATE_STOP:
3070 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
3074 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
3076 return dma->dmab->bytes;
3079 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
3081 return dma->dmab->area;
3084 static int dma_xfer(struct dma_engine *dma,
3085 const unsigned int *data,
3088 memcpy(dma->dmab->area, data, count);
3092 static void dma_get_converter_format(
3093 struct dma_engine *dma,
3094 unsigned short *format)
3097 *format = dma->m_converter_format;
3100 static unsigned int dma_get_stream_id(struct dma_engine *dma)
3102 struct ca0132_spec *spec = dma->codec->spec;
3104 return spec->dsp_stream_id;
3107 struct dsp_image_seg {
3114 static const u32 g_magic_value = 0x4c46584d;
3115 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
3117 static bool is_valid(const struct dsp_image_seg *p)
3119 return p->magic == g_magic_value;
3122 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
3124 return g_chip_addr_magic_value == p->chip_addr;
3127 static bool is_last(const struct dsp_image_seg *p)
3129 return p->count == 0;
3132 static size_t dsp_sizeof(const struct dsp_image_seg *p)
3134 return struct_size(p, data, p->count);
3137 static const struct dsp_image_seg *get_next_seg_ptr(
3138 const struct dsp_image_seg *p)
3140 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
3144 * CA0132 chip DSP transfer stuffs. For DSP download.
3146 #define INVALID_DMA_CHANNEL (~0U)
3149 * Program a list of address/data pairs via the ChipIO widget.
3150 * The segment data is in the format of successive pairs of words.
3151 * These are repeated as indicated by the segment's count field.
3153 static int dspxfr_hci_write(struct hda_codec *codec,
3154 const struct dsp_image_seg *fls)
3160 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
3161 codec_dbg(codec, "hci_write invalid params\n");
3166 data = (u32 *)(fls->data);
3167 while (count >= 2) {
3168 status = chipio_write(codec, data[0], data[1]);
3170 codec_dbg(codec, "hci_write chipio failed\n");
3180 * dspxfr_one_seg - Write a block of data into DSP code or data RAM using pre-allocated DMA engine.
3182 * @codec: the HDA codec
3183 * @fls: pointer to a fast load image
3184 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3186 * @dma_engine: pointer to DMA engine to be used for DSP download
3187 * @dma_chan: The number of DMA channels used for DSP download
3188 * @port_map_mask: port mapping
3189 * @ovly: TRUE if overlay format is required
3191 * Returns zero or a negative error code.
3193 static int dspxfr_one_seg(struct hda_codec *codec,
3194 const struct dsp_image_seg *fls,
3196 struct dma_engine *dma_engine,
3197 unsigned int dma_chan,
3198 unsigned int port_map_mask,
3202 bool comm_dma_setup_done = false;
3203 const unsigned int *data;
3204 unsigned int chip_addx;
3205 unsigned int words_to_write;
3206 unsigned int buffer_size_words;
3207 unsigned char *buffer_addx;
3208 unsigned short hda_format;
3209 unsigned int sample_rate_div;
3210 unsigned int sample_rate_mul;
3211 unsigned int num_chans;
3212 unsigned int hda_frame_size_words;
3213 unsigned int remainder_words;
3214 const u32 *data_remainder;
3215 u32 chip_addx_remainder;
3216 unsigned int run_size_words;
3217 const struct dsp_image_seg *hci_write = NULL;
3218 unsigned long timeout;
3223 if (is_hci_prog_list_seg(fls)) {
3225 fls = get_next_seg_ptr(fls);
3228 if (hci_write && (!fls || is_last(fls))) {
3229 codec_dbg(codec, "hci_write\n");
3230 return dspxfr_hci_write(codec, hci_write);
3233 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
3234 codec_dbg(codec, "Invalid Params\n");
3239 chip_addx = fls->chip_addr;
3240 words_to_write = fls->count;
3242 if (!words_to_write)
3243 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
3245 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
3247 if (!UC_RANGE(chip_addx, words_to_write) &&
3248 !X_RANGE_ALL(chip_addx, words_to_write) &&
3249 !Y_RANGE_ALL(chip_addx, words_to_write)) {
3250 codec_dbg(codec, "Invalid chip_addx Params\n");
3254 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
3257 buffer_addx = dma_get_buffer_addr(dma_engine);
3259 if (buffer_addx == NULL) {
3260 codec_dbg(codec, "dma_engine buffer NULL\n");
3264 dma_get_converter_format(dma_engine, &hda_format);
3265 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
3266 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
3267 num_chans = get_hdafmt_chs(hda_format) + 1;
3269 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
3270 (num_chans * sample_rate_mul / sample_rate_div));
3272 if (hda_frame_size_words == 0) {
3273 codec_dbg(codec, "frmsz zero\n");
3277 buffer_size_words = min(buffer_size_words,
3278 (unsigned int)(UC_RANGE(chip_addx, 1) ?
3280 buffer_size_words -= buffer_size_words % hda_frame_size_words;
3282 "chpadr=0x%08x frmsz=%u nchan=%u "
3283 "rate_mul=%u div=%u bufsz=%u\n",
3284 chip_addx, hda_frame_size_words, num_chans,
3285 sample_rate_mul, sample_rate_div, buffer_size_words);
3287 if (buffer_size_words < hda_frame_size_words) {
3288 codec_dbg(codec, "dspxfr_one_seg:failed\n");
3292 remainder_words = words_to_write % hda_frame_size_words;
3293 data_remainder = data;
3294 chip_addx_remainder = chip_addx;
3296 data += remainder_words;
3297 chip_addx += remainder_words*sizeof(u32);
3298 words_to_write -= remainder_words;
3300 while (words_to_write != 0) {
3301 run_size_words = min(buffer_size_words, words_to_write);
3302 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
3303 words_to_write, run_size_words, remainder_words);
3304 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
3305 if (!comm_dma_setup_done) {
3306 status = dsp_dma_stop(codec, dma_chan, ovly);
3309 status = dsp_dma_setup_common(codec, chip_addx,
3310 dma_chan, port_map_mask, ovly);
3313 comm_dma_setup_done = true;
3316 status = dsp_dma_setup(codec, chip_addx,
3317 run_size_words, dma_chan);
3320 status = dsp_dma_start(codec, dma_chan, ovly);
3323 if (!dsp_is_dma_active(codec, dma_chan)) {
3324 codec_dbg(codec, "dspxfr:DMA did not start\n");
3327 status = dma_set_state(dma_engine, DMA_STATE_RUN);
3330 if (remainder_words != 0) {
3331 status = chipio_write_multiple(codec,
3332 chip_addx_remainder,
3337 remainder_words = 0;
3340 status = dspxfr_hci_write(codec, hci_write);
3346 timeout = jiffies + msecs_to_jiffies(2000);
3348 dma_active = dsp_is_dma_active(codec, dma_chan);
3352 } while (time_before(jiffies, timeout));
3356 codec_dbg(codec, "+++++ DMA complete\n");
3357 dma_set_state(dma_engine, DMA_STATE_STOP);
3358 status = dma_reset(dma_engine);
3363 data += run_size_words;
3364 chip_addx += run_size_words*sizeof(u32);
3365 words_to_write -= run_size_words;
3368 if (remainder_words != 0) {
3369 status = chipio_write_multiple(codec, chip_addx_remainder,
3370 data_remainder, remainder_words);
3377 * dspxfr_image - Write the entire DSP image of a DSP code/data overlay to DSP memories
3379 * @codec: the HDA codec
3380 * @fls_data: pointer to a fast load image
3381 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3383 * @sample_rate: sampling rate of the stream used for DSP download
3384 * @channels: channels of the stream used for DSP download
3385 * @ovly: TRUE if overlay format is required
3387 * Returns zero or a negative error code.
3389 static int dspxfr_image(struct hda_codec *codec,
3390 const struct dsp_image_seg *fls_data,
3392 unsigned int sample_rate,
3393 unsigned short channels,
3396 struct ca0132_spec *spec = codec->spec;
3398 unsigned short hda_format = 0;
3399 unsigned int response;
3400 unsigned char stream_id = 0;
3401 struct dma_engine *dma_engine;
3402 unsigned int dma_chan;
3403 unsigned int port_map_mask;
3405 if (fls_data == NULL)
3408 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
3412 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
3413 if (!dma_engine->dmab) {
3418 dma_engine->codec = codec;
3419 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3420 dma_engine->m_converter_format = hda_format;
3421 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
3422 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
3424 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
3426 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3427 hda_format, &response);
3430 codec_dbg(codec, "set converter format fail\n");
3434 status = snd_hda_codec_load_dsp_prepare(codec,
3435 dma_engine->m_converter_format,
3436 dma_engine->buf_size,
3440 spec->dsp_stream_id = status;
3443 status = dspio_alloc_dma_chan(codec, &dma_chan);
3445 codec_dbg(codec, "alloc dmachan fail\n");
3446 dma_chan = INVALID_DMA_CHANNEL;
3452 status = dsp_allocate_ports_format(codec, hda_format,
3455 codec_dbg(codec, "alloc ports fail\n");
3459 stream_id = dma_get_stream_id(dma_engine);
3460 status = codec_set_converter_stream_channel(codec,
3461 WIDGET_CHIP_CTRL, stream_id, 0, &response);
3463 codec_dbg(codec, "set stream chan fail\n");
3467 while ((fls_data != NULL) && !is_last(fls_data)) {
3468 if (!is_valid(fls_data)) {
3469 codec_dbg(codec, "FLS check fail\n");
3473 status = dspxfr_one_seg(codec, fls_data, reloc,
3474 dma_engine, dma_chan,
3475 port_map_mask, ovly);
3479 if (is_hci_prog_list_seg(fls_data))
3480 fls_data = get_next_seg_ptr(fls_data);
3482 if ((fls_data != NULL) && !is_last(fls_data))
3483 fls_data = get_next_seg_ptr(fls_data);
3486 if (port_map_mask != 0)
3487 status = dsp_free_ports(codec);
3492 status = codec_set_converter_stream_channel(codec,
3493 WIDGET_CHIP_CTRL, 0, 0, &response);
3496 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
3497 dspio_free_dma_chan(codec, dma_chan);
3499 if (dma_engine->dmab->area)
3500 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3501 kfree(dma_engine->dmab);
3508 * CA0132 DSP download stuffs.
3510 static void dspload_post_setup(struct hda_codec *codec)
3512 struct ca0132_spec *spec = codec->spec;
3513 codec_dbg(codec, "---- dspload_post_setup ------\n");
3514 if (!ca0132_use_alt_functions(spec)) {
3515 /*set DSP speaker to 2.0 configuration*/
3516 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3517 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3519 /*update write pointer*/
3520 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3525 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3527 * @codec: the HDA codec
3528 * @fls: pointer to a fast load image
3529 * @ovly: TRUE if overlay format is required
3530 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3532 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3533 * @router_chans: number of audio router channels to be allocated (0 means use
3534 * internal defaults; max is 32)
3536 * Download DSP from a DSP Image Fast Load structure. This structure is a
3537 * linear, non-constant sized element array of structures, each of which
3538 * contain the count of the data to be loaded, the data itself, and the
3539 * corresponding starting chip address of the starting data location.
3540 * Returns zero or a negative error code.
3542 static int dspload_image(struct hda_codec *codec,
3543 const struct dsp_image_seg *fls,
3550 unsigned int sample_rate;
3551 unsigned short channels;
3553 codec_dbg(codec, "---- dspload_image begin ------\n");
3554 if (router_chans == 0) {
3556 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3558 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3561 sample_rate = 48000;
3562 channels = (unsigned short)router_chans;
3564 while (channels > 16) {
3570 codec_dbg(codec, "Ready to program DMA\n");
3572 status = dsp_reset(codec);
3577 codec_dbg(codec, "dsp_reset() complete\n");
3578 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3584 codec_dbg(codec, "dspxfr_image() complete\n");
3585 if (autostart && !ovly) {
3586 dspload_post_setup(codec);
3587 status = dsp_set_run_state(codec);
3590 codec_dbg(codec, "LOAD FINISHED\n");
3596 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3597 static bool dspload_is_loaded(struct hda_codec *codec)
3599 unsigned int data = 0;
3602 status = chipio_read(codec, 0x40004, &data);
3603 if ((status < 0) || (data != 1))
3609 #define dspload_is_loaded(codec) false
3612 static bool dspload_wait_loaded(struct hda_codec *codec)
3614 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3617 if (dspload_is_loaded(codec)) {
3618 codec_info(codec, "ca0132 DSP downloaded and running\n");
3622 } while (time_before(jiffies, timeout));
3624 codec_err(codec, "ca0132 failed to download DSP\n");
3629 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3630 * based cards, and has a second mmio region, region2, that's used for special
3635 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3636 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3637 * The first eight bits are just the number of the pin. So far, I've only seen
3638 * this number go to 7.
3639 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3640 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3641 * then off to send that bit.
3643 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3646 struct ca0132_spec *spec = codec->spec;
3647 unsigned short gpio_data;
3649 gpio_data = gpio_pin & 0xF;
3650 gpio_data |= ((enable << 8) & 0x100);
3652 writew(gpio_data, spec->mem_base + 0x320);
3656 * Special pci region2 commands that are only used by the AE-5. They follow
3657 * a set format, and require reads at certain points to seemingly 'clear'
3658 * the response data. My first tests didn't do these reads, and would cause
3659 * the card to get locked up until the memory was read. These commands
3660 * seem to work with three distinct values that I've taken to calling group,
3661 * target-id, and value.
3663 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3664 unsigned int target, unsigned int value)
3666 struct ca0132_spec *spec = codec->spec;
3667 unsigned int write_val;
3669 writel(0x0000007e, spec->mem_base + 0x210);
3670 readl(spec->mem_base + 0x210);
3671 writel(0x0000005a, spec->mem_base + 0x210);
3672 readl(spec->mem_base + 0x210);
3673 readl(spec->mem_base + 0x210);
3675 writel(0x00800005, spec->mem_base + 0x20c);
3676 writel(group, spec->mem_base + 0x804);
3678 writel(0x00800005, spec->mem_base + 0x20c);
3679 write_val = (target & 0xff);
3680 write_val |= (value << 8);
3683 writel(write_val, spec->mem_base + 0x204);
3685 * Need delay here or else it goes too fast and works inconsistently.
3689 readl(spec->mem_base + 0x860);
3690 readl(spec->mem_base + 0x854);
3691 readl(spec->mem_base + 0x840);
3693 writel(0x00800004, spec->mem_base + 0x20c);
3694 writel(0x00000000, spec->mem_base + 0x210);
3695 readl(spec->mem_base + 0x210);
3696 readl(spec->mem_base + 0x210);
3700 * This second type of command is used for setting the sound filter type.
3702 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3703 unsigned int group, unsigned int target, unsigned int value)
3705 struct ca0132_spec *spec = codec->spec;
3706 unsigned int write_val;
3708 writel(0x0000007e, spec->mem_base + 0x210);
3709 readl(spec->mem_base + 0x210);
3710 writel(0x0000005a, spec->mem_base + 0x210);
3711 readl(spec->mem_base + 0x210);
3712 readl(spec->mem_base + 0x210);
3714 writel(0x00800003, spec->mem_base + 0x20c);
3715 writel(group, spec->mem_base + 0x804);
3717 writel(0x00800005, spec->mem_base + 0x20c);
3718 write_val = (target & 0xff);
3719 write_val |= (value << 8);
3722 writel(write_val, spec->mem_base + 0x204);
3724 readl(spec->mem_base + 0x860);
3725 readl(spec->mem_base + 0x854);
3726 readl(spec->mem_base + 0x840);
3728 writel(0x00800004, spec->mem_base + 0x20c);
3729 writel(0x00000000, spec->mem_base + 0x210);
3730 readl(spec->mem_base + 0x210);
3731 readl(spec->mem_base + 0x210);
3735 * Setup GPIO for the other variants of Core3D.
3739 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3740 * the card shows as having no GPIO pins.
3742 static void ca0132_gpio_init(struct hda_codec *codec)
3744 struct ca0132_spec *spec = codec->spec;
3746 switch (ca0132_quirk(spec)) {
3750 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3751 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3752 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3755 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3756 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3764 /* Sets the GPIO for audio output. */
3765 static void ca0132_gpio_setup(struct hda_codec *codec)
3767 struct ca0132_spec *spec = codec->spec;
3769 switch (ca0132_quirk(spec)) {
3771 snd_hda_codec_write(codec, 0x01, 0,
3772 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3773 snd_hda_codec_write(codec, 0x01, 0,
3774 AC_VERB_SET_GPIO_MASK, 0x07);
3775 snd_hda_codec_write(codec, 0x01, 0,
3776 AC_VERB_SET_GPIO_DATA, 0x04);
3777 snd_hda_codec_write(codec, 0x01, 0,
3778 AC_VERB_SET_GPIO_DATA, 0x06);
3781 snd_hda_codec_write(codec, 0x01, 0,
3782 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3783 snd_hda_codec_write(codec, 0x01, 0,
3784 AC_VERB_SET_GPIO_MASK, 0x1F);
3785 snd_hda_codec_write(codec, 0x01, 0,
3786 AC_VERB_SET_GPIO_DATA, 0x0C);
3794 * GPIO control functions for the Recon3D integrated.
3797 enum r3di_gpio_bit {
3798 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3799 R3DI_MIC_SELECT_BIT = 1,
3800 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3801 R3DI_OUT_SELECT_BIT = 2,
3803 * I dunno what this actually does, but it stays on until the dsp
3806 R3DI_GPIO_DSP_DOWNLOADING = 3,
3808 * Same as above, no clue what it does, but it comes on after the dsp
3811 R3DI_GPIO_DSP_DOWNLOADED = 4
3814 enum r3di_mic_select {
3815 /* Set GPIO bit 1 to 0 for rear mic */
3817 /* Set GPIO bit 1 to 1 for front microphone*/
3821 enum r3di_out_select {
3822 /* Set GPIO bit 2 to 0 for headphone */
3823 R3DI_HEADPHONE_OUT = 0,
3824 /* Set GPIO bit 2 to 1 for speaker */
3827 enum r3di_dsp_status {
3828 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3829 R3DI_DSP_DOWNLOADING = 0,
3830 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3831 R3DI_DSP_DOWNLOADED = 1
3835 static void r3di_gpio_mic_set(struct hda_codec *codec,
3836 enum r3di_mic_select cur_mic)
3838 unsigned int cur_gpio;
3840 /* Get the current GPIO Data setup */
3841 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3845 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3847 case R3DI_FRONT_MIC:
3848 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3851 snd_hda_codec_write(codec, codec->core.afg, 0,
3852 AC_VERB_SET_GPIO_DATA, cur_gpio);
3855 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3856 enum r3di_dsp_status dsp_status)
3858 unsigned int cur_gpio;
3860 /* Get the current GPIO Data setup */
3861 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3863 switch (dsp_status) {
3864 case R3DI_DSP_DOWNLOADING:
3865 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3866 snd_hda_codec_write(codec, codec->core.afg, 0,
3867 AC_VERB_SET_GPIO_DATA, cur_gpio);
3869 case R3DI_DSP_DOWNLOADED:
3870 /* Set DOWNLOADING bit to 0. */
3871 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3873 snd_hda_codec_write(codec, codec->core.afg, 0,
3874 AC_VERB_SET_GPIO_DATA, cur_gpio);
3876 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3880 snd_hda_codec_write(codec, codec->core.afg, 0,
3881 AC_VERB_SET_GPIO_DATA, cur_gpio);
3887 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3888 struct hda_codec *codec,
3889 unsigned int stream_tag,
3890 unsigned int format,
3891 struct snd_pcm_substream *substream)
3893 struct ca0132_spec *spec = codec->spec;
3895 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3900 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3901 struct hda_codec *codec,
3902 struct snd_pcm_substream *substream)
3904 struct ca0132_spec *spec = codec->spec;
3906 if (spec->dsp_state == DSP_DOWNLOADING)
3909 /*If Playback effects are on, allow stream some time to flush
3911 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3914 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3919 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3920 struct hda_codec *codec,
3921 struct snd_pcm_substream *substream)
3923 struct ca0132_spec *spec = codec->spec;
3924 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3925 struct snd_pcm_runtime *runtime = substream->runtime;
3927 if (spec->dsp_state != DSP_DOWNLOADED)
3930 /* Add latency if playback enhancement and either effect is enabled. */
3931 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3932 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3933 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3934 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3937 /* Applying Speaker EQ adds latency as well. */
3938 if (spec->cur_out_type == SPEAKER_OUT)
3939 latency += DSP_SPEAKER_OUT_LATENCY;
3941 return (latency * runtime->rate) / 1000;
3947 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3948 struct hda_codec *codec,
3949 struct snd_pcm_substream *substream)
3951 struct ca0132_spec *spec = codec->spec;
3952 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3955 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3956 struct hda_codec *codec,
3957 unsigned int stream_tag,
3958 unsigned int format,
3959 struct snd_pcm_substream *substream)
3961 struct ca0132_spec *spec = codec->spec;
3962 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3963 stream_tag, format, substream);
3966 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3967 struct hda_codec *codec,
3968 struct snd_pcm_substream *substream)
3970 struct ca0132_spec *spec = codec->spec;
3971 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3974 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3975 struct hda_codec *codec,
3976 struct snd_pcm_substream *substream)
3978 struct ca0132_spec *spec = codec->spec;
3979 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3985 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3986 struct hda_codec *codec,
3987 unsigned int stream_tag,
3988 unsigned int format,
3989 struct snd_pcm_substream *substream)
3991 snd_hda_codec_setup_stream(codec, hinfo->nid,
3992 stream_tag, 0, format);
3997 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3998 struct hda_codec *codec,
3999 struct snd_pcm_substream *substream)
4001 struct ca0132_spec *spec = codec->spec;
4003 if (spec->dsp_state == DSP_DOWNLOADING)
4006 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4010 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
4011 struct hda_codec *codec,
4012 struct snd_pcm_substream *substream)
4014 struct ca0132_spec *spec = codec->spec;
4015 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
4016 struct snd_pcm_runtime *runtime = substream->runtime;
4018 if (spec->dsp_state != DSP_DOWNLOADED)
4021 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
4022 latency += DSP_CRYSTAL_VOICE_LATENCY;
4024 return (latency * runtime->rate) / 1000;
4032 * Mixer controls helpers.
4034 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
4035 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4037 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4038 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
4039 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
4040 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
4041 .info = ca0132_volume_info, \
4042 .get = ca0132_volume_get, \
4043 .put = ca0132_volume_put, \
4044 .tlv = { .c = ca0132_volume_tlv }, \
4045 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4048 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
4049 * volume put, which is used for setting the DSP volume. This was done because
4050 * the ca0132 functions were taking too much time and causing lag.
4052 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
4053 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4055 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4056 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
4057 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
4058 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
4059 .info = snd_hda_mixer_amp_volume_info, \
4060 .get = snd_hda_mixer_amp_volume_get, \
4061 .put = ca0132_alt_volume_put, \
4062 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
4063 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4065 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
4066 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4068 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4069 .info = snd_hda_mixer_amp_switch_info, \
4070 .get = ca0132_switch_get, \
4071 .put = ca0132_switch_put, \
4072 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4075 #define CA0132_CODEC_VOL(xname, nid, dir) \
4076 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
4077 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
4078 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
4079 #define CA0132_CODEC_MUTE(xname, nid, dir) \
4080 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
4084 * Lookup table with decibel values for the DSP. When volume is changed in
4085 * Windows, the DSP is also sent the dB value in floating point. In Windows,
4086 * these values have decimal points, probably because the Windows driver
4087 * actually uses floating point. We can't here, so I made a lookup table of
4088 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
4089 * DAC's, and 9 is the maximum.
4091 static const unsigned int float_vol_db_lookup[] = {
4092 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
4093 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
4094 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
4095 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
4096 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
4097 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
4098 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
4099 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
4100 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
4101 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
4102 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
4103 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
4104 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
4105 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
4106 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
4107 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
4108 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
4112 * This table counts from float 0 to 1 in increments of .01, which is
4113 * useful for a few different sliders.
4115 static const unsigned int float_zero_to_one_lookup[] = {
4116 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
4117 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
4118 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
4119 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
4120 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
4121 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4122 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4123 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4124 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4125 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4126 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4127 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4128 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4129 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4130 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4131 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4132 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4136 * This table counts from float 10 to 1000, which is the range of the x-bass
4137 * crossover slider in Windows.
4139 static const unsigned int float_xbass_xover_lookup[] = {
4140 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
4141 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
4142 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
4143 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
4144 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
4145 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
4146 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
4147 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
4148 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
4149 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
4150 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
4151 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
4152 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
4153 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
4154 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
4155 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
4156 0x44728000, 0x44750000, 0x44778000, 0x447A0000
4159 /* The following are for tuning of products */
4160 #ifdef ENABLE_TUNING_CONTROLS
4162 static const unsigned int voice_focus_vals_lookup[] = {
4163 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
4164 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
4165 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
4166 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
4167 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
4168 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
4169 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
4170 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
4171 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
4172 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
4173 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
4174 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
4175 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
4176 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
4177 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
4178 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
4179 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
4180 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
4181 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
4182 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
4183 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
4184 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
4185 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
4186 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
4187 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
4188 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
4189 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
4192 static const unsigned int mic_svm_vals_lookup[] = {
4193 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
4194 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
4195 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
4196 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
4197 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
4198 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4199 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4200 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4201 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4202 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4203 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4204 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4205 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4206 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4207 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4208 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4209 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4212 static const unsigned int equalizer_vals_lookup[] = {
4213 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
4214 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
4215 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
4216 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
4217 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
4218 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
4219 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
4220 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
4224 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
4225 const unsigned int *lookup, int idx)
4229 for (i = 0; i < TUNING_CTLS_COUNT; i++)
4230 if (nid == ca0132_tuning_ctls[i].nid)
4233 snd_hda_power_up(codec);
4234 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
4235 ca0132_tuning_ctls[i].req,
4236 &(lookup[idx]), sizeof(unsigned int));
4237 snd_hda_power_down(codec);
4242 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
4243 struct snd_ctl_elem_value *ucontrol)
4245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4246 struct ca0132_spec *spec = codec->spec;
4247 hda_nid_t nid = get_amp_nid(kcontrol);
4248 long *valp = ucontrol->value.integer.value;
4249 int idx = nid - TUNING_CTL_START_NID;
4251 *valp = spec->cur_ctl_vals[idx];
4255 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
4256 struct snd_ctl_elem_info *uinfo)
4258 int chs = get_amp_channels(kcontrol);
4259 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4260 uinfo->count = chs == 3 ? 2 : 1;
4261 uinfo->value.integer.min = 20;
4262 uinfo->value.integer.max = 180;
4263 uinfo->value.integer.step = 1;
4268 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
4269 struct snd_ctl_elem_value *ucontrol)
4271 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4272 struct ca0132_spec *spec = codec->spec;
4273 hda_nid_t nid = get_amp_nid(kcontrol);
4274 long *valp = ucontrol->value.integer.value;
4277 idx = nid - TUNING_CTL_START_NID;
4279 if (spec->cur_ctl_vals[idx] == *valp)
4282 spec->cur_ctl_vals[idx] = *valp;
4285 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
4290 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
4291 struct snd_ctl_elem_info *uinfo)
4293 int chs = get_amp_channels(kcontrol);
4294 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4295 uinfo->count = chs == 3 ? 2 : 1;
4296 uinfo->value.integer.min = 0;
4297 uinfo->value.integer.max = 100;
4298 uinfo->value.integer.step = 1;
4303 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
4304 struct snd_ctl_elem_value *ucontrol)
4306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4307 struct ca0132_spec *spec = codec->spec;
4308 hda_nid_t nid = get_amp_nid(kcontrol);
4309 long *valp = ucontrol->value.integer.value;
4312 idx = nid - TUNING_CTL_START_NID;
4314 if (spec->cur_ctl_vals[idx] == *valp)
4317 spec->cur_ctl_vals[idx] = *valp;
4320 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
4325 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
4326 struct snd_ctl_elem_info *uinfo)
4328 int chs = get_amp_channels(kcontrol);
4329 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4330 uinfo->count = chs == 3 ? 2 : 1;
4331 uinfo->value.integer.min = 0;
4332 uinfo->value.integer.max = 48;
4333 uinfo->value.integer.step = 1;
4338 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
4339 struct snd_ctl_elem_value *ucontrol)
4341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4342 struct ca0132_spec *spec = codec->spec;
4343 hda_nid_t nid = get_amp_nid(kcontrol);
4344 long *valp = ucontrol->value.integer.value;
4347 idx = nid - TUNING_CTL_START_NID;
4349 if (spec->cur_ctl_vals[idx] == *valp)
4352 spec->cur_ctl_vals[idx] = *valp;
4355 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
4360 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
4361 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
4363 static int add_tuning_control(struct hda_codec *codec,
4364 hda_nid_t pnid, hda_nid_t nid,
4365 const char *name, int dir)
4367 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
4368 int type = dir ? HDA_INPUT : HDA_OUTPUT;
4369 struct snd_kcontrol_new knew =
4370 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
4372 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
4373 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
4378 knew.info = voice_focus_ctl_info;
4379 knew.get = tuning_ctl_get;
4380 knew.put = voice_focus_ctl_put;
4381 knew.tlv.p = voice_focus_db_scale;
4384 knew.info = mic_svm_ctl_info;
4385 knew.get = tuning_ctl_get;
4386 knew.put = mic_svm_ctl_put;
4389 knew.info = equalizer_ctl_info;
4390 knew.get = tuning_ctl_get;
4391 knew.put = equalizer_ctl_put;
4392 knew.tlv.p = eq_db_scale;
4397 knew.private_value =
4398 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
4399 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
4400 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
4403 static int add_tuning_ctls(struct hda_codec *codec)
4408 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
4409 err = add_tuning_control(codec,
4410 ca0132_tuning_ctls[i].parent_nid,
4411 ca0132_tuning_ctls[i].nid,
4412 ca0132_tuning_ctls[i].name,
4413 ca0132_tuning_ctls[i].direct);
4421 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
4423 struct ca0132_spec *spec = codec->spec;
4426 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
4427 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
4428 /* SVM level defaults to 0.74. */
4429 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
4431 /* EQ defaults to 0dB. */
4432 for (i = 2; i < TUNING_CTLS_COUNT; i++)
4433 spec->cur_ctl_vals[i] = 24;
4435 #endif /*ENABLE_TUNING_CONTROLS*/
4438 * Select the active output.
4439 * If autodetect is enabled, output will be selected based on jack detection.
4440 * If jack inserted, headphone will be selected, else built-in speakers
4441 * If autodetect is disabled, output will be selected based on selection.
4443 static int ca0132_select_out(struct hda_codec *codec)
4445 struct ca0132_spec *spec = codec->spec;
4446 unsigned int pin_ctl;
4452 codec_dbg(codec, "ca0132_select_out\n");
4454 snd_hda_power_up_pm(codec);
4456 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4459 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
4462 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
4465 spec->cur_out_type = HEADPHONE_OUT;
4467 spec->cur_out_type = SPEAKER_OUT;
4469 if (spec->cur_out_type == SPEAKER_OUT) {
4470 codec_dbg(codec, "ca0132_select_out speaker\n");
4471 /*speaker out config*/
4473 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4476 /*enable speaker EQ*/
4478 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4483 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4484 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4485 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4486 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4487 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4488 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4489 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4490 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4492 /* disable headphone node */
4493 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4494 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4495 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4497 /* enable speaker node */
4498 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4499 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4500 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4503 codec_dbg(codec, "ca0132_select_out hp\n");
4504 /*headphone out config*/
4506 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4509 /*disable speaker EQ*/
4511 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4516 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4517 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4518 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4519 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4520 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4521 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4522 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4523 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4525 /* disable speaker*/
4526 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4527 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4528 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4530 /* enable headphone*/
4531 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4532 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4533 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4538 snd_hda_power_down_pm(codec);
4540 return err < 0 ? err : 0;
4543 static int ae5_headphone_gain_set(struct hda_codec *codec, long val);
4544 static int zxr_headphone_gain_set(struct hda_codec *codec, long val);
4545 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4547 static void ae5_mmio_select_out(struct hda_codec *codec)
4549 struct ca0132_spec *spec = codec->spec;
4550 const struct ae_ca0113_output_set *out_cmds;
4553 if (ca0132_quirk(spec) == QUIRK_AE5)
4554 out_cmds = &ae5_ca0113_output_presets;
4556 out_cmds = &ae7_ca0113_output_presets;
4558 for (i = 0; i < AE_CA0113_OUT_SET_COMMANDS; i++)
4559 ca0113_mmio_command_set(codec, out_cmds->group[i],
4560 out_cmds->target[i],
4561 out_cmds->vals[spec->cur_out_type][i]);
4564 static int ca0132_alt_set_full_range_speaker(struct hda_codec *codec)
4566 struct ca0132_spec *spec = codec->spec;
4567 int quirk = ca0132_quirk(spec);
4571 /* 2.0/4.0 setup has no LFE channel, so setting full-range does nothing. */
4572 if (spec->channel_cfg_val == SPEAKER_CHANNELS_4_0
4573 || spec->channel_cfg_val == SPEAKER_CHANNELS_2_0)
4576 /* Set front L/R full range. Zero for full-range, one for redirection. */
4577 tmp = spec->speaker_range_val[0] ? FLOAT_ZERO : FLOAT_ONE;
4578 err = dspio_set_uint_param(codec, 0x96,
4579 SPEAKER_FULL_RANGE_FRONT_L_R, tmp);
4583 /* When setting full-range rear, both rear and center/lfe are set. */
4584 tmp = spec->speaker_range_val[1] ? FLOAT_ZERO : FLOAT_ONE;
4585 err = dspio_set_uint_param(codec, 0x96,
4586 SPEAKER_FULL_RANGE_CENTER_LFE, tmp);
4590 err = dspio_set_uint_param(codec, 0x96,
4591 SPEAKER_FULL_RANGE_REAR_L_R, tmp);
4596 * Only the AE series cards set this value when setting full-range,
4597 * and it's always 1.0f.
4599 if (quirk == QUIRK_AE5 || quirk == QUIRK_AE7) {
4600 err = dspio_set_uint_param(codec, 0x96,
4601 SPEAKER_FULL_RANGE_SURROUND_L_R, FLOAT_ONE);
4609 static int ca0132_alt_surround_set_bass_redirection(struct hda_codec *codec,
4612 struct ca0132_spec *spec = codec->spec;
4616 if (val && spec->channel_cfg_val != SPEAKER_CHANNELS_4_0 &&
4617 spec->channel_cfg_val != SPEAKER_CHANNELS_2_0)
4622 err = dspio_set_uint_param(codec, 0x96, SPEAKER_BASS_REDIRECT, tmp);
4626 /* If it is enabled, make sure to set the crossover frequency. */
4628 tmp = float_xbass_xover_lookup[spec->xbass_xover_freq];
4629 err = dspio_set_uint_param(codec, 0x96,
4630 SPEAKER_BASS_REDIRECT_XOVER_FREQ, tmp);
4639 * These are the commands needed to setup output on each of the different card
4642 static void ca0132_alt_select_out_get_quirk_data(struct hda_codec *codec,
4643 const struct ca0132_alt_out_set_quirk_data **quirk_data)
4645 struct ca0132_spec *spec = codec->spec;
4646 int quirk = ca0132_quirk(spec);
4650 for (i = 0; i < ARRAY_SIZE(quirk_out_set_data); i++) {
4651 if (quirk_out_set_data[i].quirk_id == quirk) {
4652 *quirk_data = &quirk_out_set_data[i];
4658 static int ca0132_alt_select_out_quirk_set(struct hda_codec *codec)
4660 const struct ca0132_alt_out_set_quirk_data *quirk_data;
4661 const struct ca0132_alt_out_set_info *out_info;
4662 struct ca0132_spec *spec = codec->spec;
4663 unsigned int i, gpio_data;
4666 ca0132_alt_select_out_get_quirk_data(codec, &quirk_data);
4670 out_info = &quirk_data->out_set_info[spec->cur_out_type];
4671 if (quirk_data->is_ae_series)
4672 ae5_mmio_select_out(codec);
4674 if (out_info->has_hda_gpio) {
4675 gpio_data = snd_hda_codec_read(codec, codec->core.afg, 0,
4676 AC_VERB_GET_GPIO_DATA, 0);
4678 if (out_info->hda_gpio_set)
4679 gpio_data |= (1 << out_info->hda_gpio_pin);
4681 gpio_data &= ~(1 << out_info->hda_gpio_pin);
4683 snd_hda_codec_write(codec, codec->core.afg, 0,
4684 AC_VERB_SET_GPIO_DATA, gpio_data);
4687 if (out_info->mmio_gpio_count) {
4688 for (i = 0; i < out_info->mmio_gpio_count; i++) {
4689 ca0113_mmio_gpio_set(codec, out_info->mmio_gpio_pin[i],
4690 out_info->mmio_gpio_set[i]);
4694 if (out_info->scp_cmds_count) {
4695 for (i = 0; i < out_info->scp_cmds_count; i++) {
4696 err = dspio_set_uint_param(codec,
4697 out_info->scp_cmd_mid[i],
4698 out_info->scp_cmd_req[i],
4699 out_info->scp_cmd_val[i]);
4705 chipio_set_control_param(codec, 0x0d, out_info->dac2port);
4707 if (out_info->has_chipio_write) {
4708 chipio_write(codec, out_info->chipio_write_addr,
4709 out_info->chipio_write_data);
4712 if (quirk_data->has_headphone_gain) {
4713 if (spec->cur_out_type != HEADPHONE_OUT) {
4714 if (quirk_data->is_ae_series)
4715 ae5_headphone_gain_set(codec, 2);
4717 zxr_headphone_gain_set(codec, 0);
4719 if (quirk_data->is_ae_series)
4720 ae5_headphone_gain_set(codec,
4721 spec->ae5_headphone_gain_val);
4723 zxr_headphone_gain_set(codec,
4724 spec->zxr_gain_set);
4731 static void ca0132_set_out_node_pincfg(struct hda_codec *codec, hda_nid_t nid,
4732 bool out_enable, bool hp_enable)
4734 unsigned int pin_ctl;
4736 pin_ctl = snd_hda_codec_read(codec, nid, 0,
4737 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4739 pin_ctl = hp_enable ? pin_ctl | PIN_HP_AMP : pin_ctl & ~PIN_HP_AMP;
4740 pin_ctl = out_enable ? pin_ctl | PIN_OUT : pin_ctl & ~PIN_OUT;
4741 snd_hda_set_pin_ctl(codec, nid, pin_ctl);
4745 * This function behaves similarly to the ca0132_select_out funciton above,
4746 * except with a few differences. It adds the ability to select the current
4747 * output with an enumerated control "output source" if the auto detect
4748 * mute switch is set to off. If the auto detect mute switch is enabled, it
4749 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
4750 * It also adds the ability to auto-detect the front headphone port.
4752 static int ca0132_alt_select_out(struct hda_codec *codec)
4754 struct ca0132_spec *spec = codec->spec;
4755 unsigned int tmp, outfx_set;
4759 /* Default Headphone is rear headphone */
4760 hda_nid_t headphone_nid = spec->out_pins[1];
4762 codec_dbg(codec, "%s\n", __func__);
4764 snd_hda_power_up_pm(codec);
4766 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4769 * If headphone rear or front is plugged in, set to headphone.
4770 * If neither is plugged in, set to rear line out. Only if
4771 * hp/speaker auto detect is enabled.
4774 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
4775 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
4778 spec->cur_out_type = HEADPHONE_OUT;
4780 spec->cur_out_type = SPEAKER_OUT;
4782 spec->cur_out_type = spec->out_enum_val;
4784 outfx_set = spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID];
4786 /* Begin DSP output switch, mute DSP volume. */
4787 err = dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_MUTE, FLOAT_ONE);
4791 if (ca0132_alt_select_out_quirk_set(codec) < 0)
4794 switch (spec->cur_out_type) {
4796 codec_dbg(codec, "%s speaker\n", __func__);
4799 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4800 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4802 /* Disable headphone node. */
4803 ca0132_set_out_node_pincfg(codec, spec->out_pins[1], 0, 0);
4804 /* Set front L-R to output. */
4805 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 1, 0);
4806 /* Set Center/LFE to output. */
4807 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 1, 0);
4808 /* Set rear surround to output. */
4809 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 1, 0);
4812 * Without PlayEnhancement being enabled, if we've got a 2.0
4813 * setup, set it to floating point eight to disable any DSP
4814 * processing effects.
4816 if (!outfx_set && spec->channel_cfg_val == SPEAKER_CHANNELS_2_0)
4819 tmp = speaker_channel_cfgs[spec->channel_cfg_val].val;
4821 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4827 codec_dbg(codec, "%s hp\n", __func__);
4828 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4829 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4831 /* Disable all speaker nodes. */
4832 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 0, 0);
4833 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 0, 0);
4834 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 0, 0);
4836 /* enable headphone, either front or rear */
4837 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4838 headphone_nid = spec->out_pins[2];
4839 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4840 headphone_nid = spec->out_pins[1];
4842 ca0132_set_out_node_pincfg(codec, headphone_nid, 1, 1);
4845 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4847 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4854 * If output effects are enabled, set the X-Bass effect value again to
4855 * make sure that it's properly enabled/disabled for speaker
4856 * configurations with an LFE channel.
4859 ca0132_effects_set(codec, X_BASS,
4860 spec->effects_switch[X_BASS - EFFECT_START_NID]);
4862 /* Set speaker EQ bypass attenuation to 0. */
4863 err = dspio_set_uint_param(codec, 0x8f, 0x01, FLOAT_ZERO);
4868 * Although unused on all cards but the AE series, this is always set
4869 * to zero when setting the output.
4871 err = dspio_set_uint_param(codec, 0x96,
4872 SPEAKER_TUNING_USE_SPEAKER_EQ, FLOAT_ZERO);
4876 if (spec->cur_out_type == SPEAKER_OUT)
4877 err = ca0132_alt_surround_set_bass_redirection(codec,
4878 spec->bass_redirection_val);
4880 err = ca0132_alt_surround_set_bass_redirection(codec, 0);
4882 /* Unmute DSP now that we're done with output selection. */
4883 err = dspio_set_uint_param(codec, 0x96,
4884 SPEAKER_TUNING_MUTE, FLOAT_ZERO);
4888 if (spec->cur_out_type == SPEAKER_OUT) {
4889 err = ca0132_alt_set_full_range_speaker(codec);
4895 snd_hda_power_down_pm(codec);
4897 return err < 0 ? err : 0;
4900 static void ca0132_unsol_hp_delayed(struct work_struct *work)
4902 struct ca0132_spec *spec = container_of(
4903 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
4904 struct hda_jack_tbl *jack;
4906 if (ca0132_use_alt_functions(spec))
4907 ca0132_alt_select_out(spec->codec);
4909 ca0132_select_out(spec->codec);
4911 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4913 jack->block_report = 0;
4914 snd_hda_jack_report_sync(spec->codec);
4918 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4919 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4920 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4921 static int stop_mic1(struct hda_codec *codec);
4922 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4923 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4926 * Select the active VIP source
4928 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4930 struct ca0132_spec *spec = codec->spec;
4933 if (spec->dsp_state != DSP_DOWNLOADED)
4936 /* if CrystalVoice if off, vipsource should be 0 */
4937 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4939 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4940 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4941 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4942 if (spec->cur_mic_type == DIGITAL_MIC)
4946 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4948 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4950 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4951 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4952 if (spec->cur_mic_type == DIGITAL_MIC)
4956 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4958 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4960 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4966 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4968 struct ca0132_spec *spec = codec->spec;
4971 if (spec->dsp_state != DSP_DOWNLOADED)
4974 codec_dbg(codec, "%s\n", __func__);
4976 chipio_set_stream_control(codec, 0x03, 0);
4977 chipio_set_stream_control(codec, 0x04, 0);
4979 /* if CrystalVoice is off, vipsource should be 0 */
4980 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4981 (val == 0) || spec->in_enum_val == REAR_LINE_IN) {
4982 codec_dbg(codec, "%s: off.", __func__);
4983 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4986 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4988 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4989 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4990 if (ca0132_quirk(spec) == QUIRK_R3DI)
4991 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4994 if (spec->in_enum_val == REAR_LINE_IN)
4997 if (ca0132_quirk(spec) == QUIRK_SBZ)
5003 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5006 codec_dbg(codec, "%s: on.", __func__);
5007 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
5008 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
5009 if (ca0132_quirk(spec) == QUIRK_R3DI)
5010 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
5012 if (spec->effects_switch[VOICE_FOCUS - EFFECT_START_NID])
5016 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5019 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
5022 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
5025 chipio_set_stream_control(codec, 0x03, 1);
5026 chipio_set_stream_control(codec, 0x04, 1);
5032 * Select the active microphone.
5033 * If autodetect is enabled, mic will be selected based on jack detection.
5034 * If jack inserted, ext.mic will be selected, else built-in mic
5035 * If autodetect is disabled, mic will be selected based on selection.
5037 static int ca0132_select_mic(struct hda_codec *codec)
5039 struct ca0132_spec *spec = codec->spec;
5043 codec_dbg(codec, "ca0132_select_mic\n");
5045 snd_hda_power_up_pm(codec);
5047 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5050 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
5053 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
5056 spec->cur_mic_type = LINE_MIC_IN;
5058 spec->cur_mic_type = DIGITAL_MIC;
5060 if (spec->cur_mic_type == DIGITAL_MIC) {
5061 /* enable digital Mic */
5062 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
5063 ca0132_set_dmic(codec, 1);
5064 ca0132_mic_boost_set(codec, 0);
5065 /* set voice focus */
5066 ca0132_effects_set(codec, VOICE_FOCUS,
5067 spec->effects_switch
5068 [VOICE_FOCUS - EFFECT_START_NID]);
5070 /* disable digital Mic */
5071 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
5072 ca0132_set_dmic(codec, 0);
5073 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
5074 /* disable voice focus */
5075 ca0132_effects_set(codec, VOICE_FOCUS, 0);
5078 snd_hda_power_down_pm(codec);
5084 * Select the active input.
5085 * Mic detection isn't used, because it's kind of pointless on the SBZ.
5086 * The front mic has no jack-detection, so the only way to switch to it
5087 * is to do it manually in alsamixer.
5089 static int ca0132_alt_select_in(struct hda_codec *codec)
5091 struct ca0132_spec *spec = codec->spec;
5094 codec_dbg(codec, "%s\n", __func__);
5096 snd_hda_power_up_pm(codec);
5098 chipio_set_stream_control(codec, 0x03, 0);
5099 chipio_set_stream_control(codec, 0x04, 0);
5101 spec->cur_mic_type = spec->in_enum_val;
5103 switch (spec->cur_mic_type) {
5105 switch (ca0132_quirk(spec)) {
5108 ca0113_mmio_gpio_set(codec, 0, false);
5115 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
5119 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5123 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5125 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5127 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5129 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5136 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5137 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5138 if (ca0132_quirk(spec) == QUIRK_R3DI)
5139 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5141 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5143 chipio_set_stream_control(codec, 0x03, 1);
5144 chipio_set_stream_control(codec, 0x04, 1);
5145 switch (ca0132_quirk(spec)) {
5147 chipio_write(codec, 0x18B098, 0x0000000C);
5148 chipio_write(codec, 0x18B09C, 0x0000000C);
5151 chipio_write(codec, 0x18B098, 0x0000000C);
5152 chipio_write(codec, 0x18B09C, 0x000000CC);
5155 chipio_write(codec, 0x18B098, 0x0000000C);
5156 chipio_write(codec, 0x18B09C, 0x0000004C);
5161 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5164 ca0132_mic_boost_set(codec, 0);
5165 switch (ca0132_quirk(spec)) {
5168 ca0113_mmio_gpio_set(codec, 0, false);
5171 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
5174 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5177 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5178 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5180 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5182 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5188 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5189 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5190 if (ca0132_quirk(spec) == QUIRK_R3DI)
5191 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5193 if (ca0132_quirk(spec) == QUIRK_AE7)
5197 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5199 switch (ca0132_quirk(spec)) {
5202 chipio_write(codec, 0x18B098, 0x00000000);
5203 chipio_write(codec, 0x18B09C, 0x00000000);
5208 chipio_set_stream_control(codec, 0x03, 1);
5209 chipio_set_stream_control(codec, 0x04, 1);
5212 switch (ca0132_quirk(spec)) {
5215 ca0113_mmio_gpio_set(codec, 0, true);
5216 ca0113_mmio_gpio_set(codec, 5, false);
5220 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
5224 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5232 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5233 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5234 if (ca0132_quirk(spec) == QUIRK_R3DI)
5235 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5237 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5239 chipio_set_stream_control(codec, 0x03, 1);
5240 chipio_set_stream_control(codec, 0x04, 1);
5242 switch (ca0132_quirk(spec)) {
5244 chipio_write(codec, 0x18B098, 0x0000000C);
5245 chipio_write(codec, 0x18B09C, 0x000000CC);
5248 chipio_write(codec, 0x18B098, 0x0000000C);
5249 chipio_write(codec, 0x18B09C, 0x0000004C);
5254 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5257 ca0132_cvoice_switch_set(codec);
5259 snd_hda_power_down_pm(codec);
5264 * Check if VNODE settings take effect immediately.
5266 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
5268 hda_nid_t *shared_nid)
5270 struct ca0132_spec *spec = codec->spec;
5275 nid = spec->shared_out_nid;
5278 nid = spec->shared_mic_nid;
5291 * The following functions are control change helpers.
5292 * They return 0 if no changed. Return 1 if changed.
5294 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
5296 struct ca0132_spec *spec = codec->spec;
5299 /* based on CrystalVoice state to enable VoiceFX. */
5301 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
5302 FLOAT_ONE : FLOAT_ZERO;
5307 dspio_set_uint_param(codec, ca0132_voicefx.mid,
5308 ca0132_voicefx.reqs[0], tmp);
5314 * Set the effects parameters
5316 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
5318 struct ca0132_spec *spec = codec->spec;
5319 unsigned int on, tmp, channel_cfg;
5320 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
5322 int idx = nid - EFFECT_START_NID;
5324 if ((idx < 0) || (idx >= num_fx))
5325 return 0; /* no changed */
5327 /* for out effect, qualify with PE */
5328 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
5329 /* if PE if off, turn off out effects. */
5330 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
5332 if (spec->cur_out_type == SPEAKER_OUT && nid == X_BASS) {
5333 channel_cfg = spec->channel_cfg_val;
5334 if (channel_cfg != SPEAKER_CHANNELS_2_0 &&
5335 channel_cfg != SPEAKER_CHANNELS_4_0)
5340 /* for in effect, qualify with CrystalVoice */
5341 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
5342 /* if CrystalVoice if off, turn off in effects. */
5343 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
5346 /* Voice Focus applies to 2-ch Mic, Digital Mic */
5347 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
5350 /* If Voice Focus on SBZ, set to two channel. */
5351 if ((nid == VOICE_FOCUS) && ca0132_use_pci_mmio(spec)
5352 && (spec->cur_mic_type != REAR_LINE_IN)) {
5353 if (spec->effects_switch[CRYSTAL_VOICE -
5354 EFFECT_START_NID]) {
5356 if (spec->effects_switch[VOICE_FOCUS -
5357 EFFECT_START_NID]) {
5363 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5367 * For SBZ noise reduction, there's an extra command
5368 * to module ID 0x47. No clue why.
5370 if ((nid == NOISE_REDUCTION) && ca0132_use_pci_mmio(spec)
5371 && (spec->cur_mic_type != REAR_LINE_IN)) {
5372 if (spec->effects_switch[CRYSTAL_VOICE -
5373 EFFECT_START_NID]) {
5374 if (spec->effects_switch[NOISE_REDUCTION -
5382 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
5385 /* If rear line in disable effects. */
5386 if (ca0132_use_alt_functions(spec) &&
5387 spec->in_enum_val == REAR_LINE_IN)
5391 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
5394 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
5395 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5396 ca0132_effects[idx].reqs[0], on);
5399 return 0; /* no changed */
5405 * Turn on/off Playback Enhancements
5407 static int ca0132_pe_switch_set(struct hda_codec *codec)
5409 struct ca0132_spec *spec = codec->spec;
5413 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
5414 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
5416 if (ca0132_use_alt_functions(spec))
5417 ca0132_alt_select_out(codec);
5419 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
5420 nid = OUT_EFFECT_START_NID;
5421 /* PE affects all out effects */
5422 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
5423 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5428 /* Check if Mic1 is streaming, if so, stop streaming */
5429 static int stop_mic1(struct hda_codec *codec)
5431 struct ca0132_spec *spec = codec->spec;
5432 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
5433 AC_VERB_GET_CONV, 0);
5435 snd_hda_codec_write(codec, spec->adcs[0], 0,
5436 AC_VERB_SET_CHANNEL_STREAMID,
5441 /* Resume Mic1 streaming if it was stopped. */
5442 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
5444 struct ca0132_spec *spec = codec->spec;
5445 /* Restore the previous stream and channel */
5447 snd_hda_codec_write(codec, spec->adcs[0], 0,
5448 AC_VERB_SET_CHANNEL_STREAMID,
5453 * Turn on/off CrystalVoice
5455 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
5457 struct ca0132_spec *spec = codec->spec;
5460 unsigned int oldval;
5462 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
5463 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
5465 i = IN_EFFECT_START_NID - EFFECT_START_NID;
5466 nid = IN_EFFECT_START_NID;
5467 /* CrystalVoice affects all in effects */
5468 for (; nid < IN_EFFECT_END_NID; nid++, i++)
5469 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5471 /* including VoiceFX */
5472 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
5474 /* set correct vipsource */
5475 oldval = stop_mic1(codec);
5476 if (ca0132_use_alt_functions(spec))
5477 ret |= ca0132_alt_set_vipsource(codec, 1);
5479 ret |= ca0132_set_vipsource(codec, 1);
5480 resume_mic1(codec, oldval);
5484 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
5486 struct ca0132_spec *spec = codec->spec;
5490 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5491 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
5493 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5494 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
5499 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
5501 struct ca0132_spec *spec = codec->spec;
5504 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5505 HDA_INPUT, 0, HDA_AMP_VOLMASK, val);
5509 static int ae5_headphone_gain_set(struct hda_codec *codec, long val)
5513 for (i = 0; i < 4; i++)
5514 ca0113_mmio_command_set(codec, 0x48, 0x11 + i,
5515 ae5_headphone_gain_presets[val].vals[i]);
5520 * gpio pin 1 is a relay that switches on/off, apparently setting the headphone
5521 * amplifier to handle a 600 ohm load.
5523 static int zxr_headphone_gain_set(struct hda_codec *codec, long val)
5525 ca0113_mmio_gpio_set(codec, 1, val);
5530 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
5531 struct snd_ctl_elem_value *ucontrol)
5533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5534 hda_nid_t nid = get_amp_nid(kcontrol);
5535 hda_nid_t shared_nid = 0;
5538 struct ca0132_spec *spec = codec->spec;
5541 if (nid == VNID_HP_SEL) {
5543 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5545 if (ca0132_use_alt_functions(spec))
5546 ca0132_alt_select_out(codec);
5548 ca0132_select_out(codec);
5553 if (nid == VNID_AMIC1_SEL) {
5555 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5557 ca0132_select_mic(codec);
5561 if (nid == VNID_HP_ASEL) {
5562 if (ca0132_use_alt_functions(spec))
5563 ca0132_alt_select_out(codec);
5565 ca0132_select_out(codec);
5569 if (nid == VNID_AMIC1_ASEL) {
5570 ca0132_select_mic(codec);
5574 /* if effective conditions, then update hw immediately. */
5575 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5577 int dir = get_amp_direction(kcontrol);
5578 int ch = get_amp_channels(kcontrol);
5581 mutex_lock(&codec->control_mutex);
5582 pval = kcontrol->private_value;
5583 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5585 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
5586 kcontrol->private_value = pval;
5587 mutex_unlock(&codec->control_mutex);
5592 /* End of control change helpers. */
5594 static void ca0132_alt_bass_redirection_xover_set(struct hda_codec *codec,
5597 snd_hda_power_up(codec);
5599 dspio_set_param(codec, 0x96, 0x20, SPEAKER_BASS_REDIRECT_XOVER_FREQ,
5600 &(float_xbass_xover_lookup[idx]), sizeof(unsigned int));
5602 snd_hda_power_down(codec);
5606 * Below I've added controls to mess with the effect levels, I've only enabled
5607 * them on the Sound Blaster Z, but they would probably also work on the
5608 * Chromebook. I figured they were probably tuned specifically for it, and left
5612 /* Sets DSP effect level from the sliders above the controls */
5614 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
5615 const unsigned int *lookup, int idx)
5620 * For X_BASS, req 2 is actually crossover freq instead of
5628 snd_hda_power_up(codec);
5629 if (nid == XBASS_XOVER) {
5630 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5631 if (ca0132_effects[i].nid == X_BASS)
5634 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5635 ca0132_effects[i].reqs[1],
5636 &(lookup[idx - 1]), sizeof(unsigned int));
5638 /* Find the actual effect structure */
5639 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5640 if (nid == ca0132_effects[i].nid)
5643 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5644 ca0132_effects[i].reqs[y],
5645 &(lookup[idx]), sizeof(unsigned int));
5648 snd_hda_power_down(codec);
5653 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol *kcontrol,
5654 struct snd_ctl_elem_value *ucontrol)
5656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5657 struct ca0132_spec *spec = codec->spec;
5658 long *valp = ucontrol->value.integer.value;
5659 hda_nid_t nid = get_amp_nid(kcontrol);
5661 if (nid == BASS_REDIRECTION_XOVER)
5662 *valp = spec->bass_redirect_xover_freq;
5664 *valp = spec->xbass_xover_freq;
5669 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol *kcontrol,
5670 struct snd_ctl_elem_value *ucontrol)
5672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5673 struct ca0132_spec *spec = codec->spec;
5674 hda_nid_t nid = get_amp_nid(kcontrol);
5675 long *valp = ucontrol->value.integer.value;
5676 int idx = nid - OUT_EFFECT_START_NID;
5678 *valp = spec->fx_ctl_val[idx];
5683 * The X-bass crossover starts at 10hz, so the min is 1. The
5684 * frequency is set in multiples of 10.
5686 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol *kcontrol,
5687 struct snd_ctl_elem_info *uinfo)
5689 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5691 uinfo->value.integer.min = 1;
5692 uinfo->value.integer.max = 100;
5693 uinfo->value.integer.step = 1;
5698 static int ca0132_alt_effect_slider_info(struct snd_kcontrol *kcontrol,
5699 struct snd_ctl_elem_info *uinfo)
5701 int chs = get_amp_channels(kcontrol);
5703 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5704 uinfo->count = chs == 3 ? 2 : 1;
5705 uinfo->value.integer.min = 0;
5706 uinfo->value.integer.max = 100;
5707 uinfo->value.integer.step = 1;
5712 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol *kcontrol,
5713 struct snd_ctl_elem_value *ucontrol)
5715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5716 struct ca0132_spec *spec = codec->spec;
5717 hda_nid_t nid = get_amp_nid(kcontrol);
5718 long *valp = ucontrol->value.integer.value;
5722 if (nid == BASS_REDIRECTION_XOVER)
5723 cur_val = &spec->bass_redirect_xover_freq;
5725 cur_val = &spec->xbass_xover_freq;
5728 if (*cur_val == *valp)
5734 if (nid == BASS_REDIRECTION_XOVER)
5735 ca0132_alt_bass_redirection_xover_set(codec, *cur_val);
5737 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
5742 static int ca0132_alt_effect_slider_put(struct snd_kcontrol *kcontrol,
5743 struct snd_ctl_elem_value *ucontrol)
5745 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5746 struct ca0132_spec *spec = codec->spec;
5747 hda_nid_t nid = get_amp_nid(kcontrol);
5748 long *valp = ucontrol->value.integer.value;
5751 idx = nid - EFFECT_START_NID;
5753 if (spec->fx_ctl_val[idx] == *valp)
5756 spec->fx_ctl_val[idx] = *valp;
5759 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
5766 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
5767 * only has off or full 30 dB, and didn't like making a volume slider that has
5768 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
5770 #define MIC_BOOST_NUM_OF_STEPS 4
5771 #define MIC_BOOST_ENUM_MAX_STRLEN 10
5773 static int ca0132_alt_mic_boost_info(struct snd_kcontrol *kcontrol,
5774 struct snd_ctl_elem_info *uinfo)
5777 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5779 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5781 uinfo->value.enumerated.items = MIC_BOOST_NUM_OF_STEPS;
5782 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS)
5783 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1;
5784 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx);
5785 strcpy(uinfo->value.enumerated.name, namestr);
5789 static int ca0132_alt_mic_boost_get(struct snd_kcontrol *kcontrol,
5790 struct snd_ctl_elem_value *ucontrol)
5792 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5793 struct ca0132_spec *spec = codec->spec;
5795 ucontrol->value.enumerated.item[0] = spec->mic_boost_enum_val;
5799 static int ca0132_alt_mic_boost_put(struct snd_kcontrol *kcontrol,
5800 struct snd_ctl_elem_value *ucontrol)
5802 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5803 struct ca0132_spec *spec = codec->spec;
5804 int sel = ucontrol->value.enumerated.item[0];
5805 unsigned int items = MIC_BOOST_NUM_OF_STEPS;
5810 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
5813 spec->mic_boost_enum_val = sel;
5815 if (spec->in_enum_val != REAR_LINE_IN)
5816 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5822 * Sound BlasterX AE-5 Headphone Gain Controls.
5824 #define AE5_HEADPHONE_GAIN_MAX 3
5825 static int ae5_headphone_gain_info(struct snd_kcontrol *kcontrol,
5826 struct snd_ctl_elem_info *uinfo)
5828 char *sfx = " Ohms)";
5829 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5831 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5833 uinfo->value.enumerated.items = AE5_HEADPHONE_GAIN_MAX;
5834 if (uinfo->value.enumerated.item >= AE5_HEADPHONE_GAIN_MAX)
5835 uinfo->value.enumerated.item = AE5_HEADPHONE_GAIN_MAX - 1;
5836 sprintf(namestr, "%s %s",
5837 ae5_headphone_gain_presets[uinfo->value.enumerated.item].name,
5839 strcpy(uinfo->value.enumerated.name, namestr);
5843 static int ae5_headphone_gain_get(struct snd_kcontrol *kcontrol,
5844 struct snd_ctl_elem_value *ucontrol)
5846 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5847 struct ca0132_spec *spec = codec->spec;
5849 ucontrol->value.enumerated.item[0] = spec->ae5_headphone_gain_val;
5853 static int ae5_headphone_gain_put(struct snd_kcontrol *kcontrol,
5854 struct snd_ctl_elem_value *ucontrol)
5856 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5857 struct ca0132_spec *spec = codec->spec;
5858 int sel = ucontrol->value.enumerated.item[0];
5859 unsigned int items = AE5_HEADPHONE_GAIN_MAX;
5864 codec_dbg(codec, "ae5_headphone_gain: boost=%d\n",
5867 spec->ae5_headphone_gain_val = sel;
5869 if (spec->out_enum_val == HEADPHONE_OUT)
5870 ae5_headphone_gain_set(codec, spec->ae5_headphone_gain_val);
5876 * Sound BlasterX AE-5 sound filter enumerated control.
5878 #define AE5_SOUND_FILTER_MAX 3
5880 static int ae5_sound_filter_info(struct snd_kcontrol *kcontrol,
5881 struct snd_ctl_elem_info *uinfo)
5883 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5885 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5887 uinfo->value.enumerated.items = AE5_SOUND_FILTER_MAX;
5888 if (uinfo->value.enumerated.item >= AE5_SOUND_FILTER_MAX)
5889 uinfo->value.enumerated.item = AE5_SOUND_FILTER_MAX - 1;
5890 sprintf(namestr, "%s",
5891 ae5_filter_presets[uinfo->value.enumerated.item].name);
5892 strcpy(uinfo->value.enumerated.name, namestr);
5896 static int ae5_sound_filter_get(struct snd_kcontrol *kcontrol,
5897 struct snd_ctl_elem_value *ucontrol)
5899 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5900 struct ca0132_spec *spec = codec->spec;
5902 ucontrol->value.enumerated.item[0] = spec->ae5_filter_val;
5906 static int ae5_sound_filter_put(struct snd_kcontrol *kcontrol,
5907 struct snd_ctl_elem_value *ucontrol)
5909 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5910 struct ca0132_spec *spec = codec->spec;
5911 int sel = ucontrol->value.enumerated.item[0];
5912 unsigned int items = AE5_SOUND_FILTER_MAX;
5917 codec_dbg(codec, "ae5_sound_filter: %s\n",
5918 ae5_filter_presets[sel].name);
5920 spec->ae5_filter_val = sel;
5922 ca0113_mmio_command_set_type2(codec, 0x48, 0x07,
5923 ae5_filter_presets[sel].val);
5929 * Input Select Control for alternative ca0132 codecs. This exists because
5930 * front microphone has no auto-detect, and we need a way to set the rear
5933 static int ca0132_alt_input_source_info(struct snd_kcontrol *kcontrol,
5934 struct snd_ctl_elem_info *uinfo)
5936 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5938 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS;
5939 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS)
5940 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1;
5941 strcpy(uinfo->value.enumerated.name,
5942 in_src_str[uinfo->value.enumerated.item]);
5946 static int ca0132_alt_input_source_get(struct snd_kcontrol *kcontrol,
5947 struct snd_ctl_elem_value *ucontrol)
5949 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5950 struct ca0132_spec *spec = codec->spec;
5952 ucontrol->value.enumerated.item[0] = spec->in_enum_val;
5956 static int ca0132_alt_input_source_put(struct snd_kcontrol *kcontrol,
5957 struct snd_ctl_elem_value *ucontrol)
5959 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5960 struct ca0132_spec *spec = codec->spec;
5961 int sel = ucontrol->value.enumerated.item[0];
5962 unsigned int items = IN_SRC_NUM_OF_INPUTS;
5965 * The AE-7 has no front microphone, so limit items to 2: rear mic and
5968 if (ca0132_quirk(spec) == QUIRK_AE7)
5974 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5975 sel, in_src_str[sel]);
5977 spec->in_enum_val = sel;
5979 ca0132_alt_select_in(codec);
5984 /* Sound Blaster Z Output Select Control */
5985 static int ca0132_alt_output_select_get_info(struct snd_kcontrol *kcontrol,
5986 struct snd_ctl_elem_info *uinfo)
5988 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5990 uinfo->value.enumerated.items = NUM_OF_OUTPUTS;
5991 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS)
5992 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1;
5993 strcpy(uinfo->value.enumerated.name,
5994 out_type_str[uinfo->value.enumerated.item]);
5998 static int ca0132_alt_output_select_get(struct snd_kcontrol *kcontrol,
5999 struct snd_ctl_elem_value *ucontrol)
6001 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6002 struct ca0132_spec *spec = codec->spec;
6004 ucontrol->value.enumerated.item[0] = spec->out_enum_val;
6008 static int ca0132_alt_output_select_put(struct snd_kcontrol *kcontrol,
6009 struct snd_ctl_elem_value *ucontrol)
6011 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6012 struct ca0132_spec *spec = codec->spec;
6013 int sel = ucontrol->value.enumerated.item[0];
6014 unsigned int items = NUM_OF_OUTPUTS;
6015 unsigned int auto_jack;
6020 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
6021 sel, out_type_str[sel]);
6023 spec->out_enum_val = sel;
6025 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
6028 ca0132_alt_select_out(codec);
6033 /* Select surround output type: 2.1, 4.0, 4.1, or 5.1. */
6034 static int ca0132_alt_speaker_channel_cfg_get_info(struct snd_kcontrol *kcontrol,
6035 struct snd_ctl_elem_info *uinfo)
6037 unsigned int items = SPEAKER_CHANNEL_CFG_COUNT;
6039 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6041 uinfo->value.enumerated.items = items;
6042 if (uinfo->value.enumerated.item >= items)
6043 uinfo->value.enumerated.item = items - 1;
6044 strcpy(uinfo->value.enumerated.name,
6045 speaker_channel_cfgs[uinfo->value.enumerated.item].name);
6049 static int ca0132_alt_speaker_channel_cfg_get(struct snd_kcontrol *kcontrol,
6050 struct snd_ctl_elem_value *ucontrol)
6052 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6053 struct ca0132_spec *spec = codec->spec;
6055 ucontrol->value.enumerated.item[0] = spec->channel_cfg_val;
6059 static int ca0132_alt_speaker_channel_cfg_put(struct snd_kcontrol *kcontrol,
6060 struct snd_ctl_elem_value *ucontrol)
6062 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6063 struct ca0132_spec *spec = codec->spec;
6064 int sel = ucontrol->value.enumerated.item[0];
6065 unsigned int items = SPEAKER_CHANNEL_CFG_COUNT;
6070 codec_dbg(codec, "ca0132_alt_speaker_channels: sel=%d, channels=%s\n",
6071 sel, speaker_channel_cfgs[sel].name);
6073 spec->channel_cfg_val = sel;
6075 if (spec->out_enum_val == SPEAKER_OUT)
6076 ca0132_alt_select_out(codec);
6082 * Smart Volume output setting control. Three different settings, Normal,
6083 * which takes the value from the smart volume slider. The two others, loud
6084 * and night, disregard the slider value and have uneditable values.
6086 #define NUM_OF_SVM_SETTINGS 3
6087 static const char *const out_svm_set_enum_str[3] = {"Normal", "Loud", "Night" };
6089 static int ca0132_alt_svm_setting_info(struct snd_kcontrol *kcontrol,
6090 struct snd_ctl_elem_info *uinfo)
6092 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6094 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS;
6095 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS)
6096 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1;
6097 strcpy(uinfo->value.enumerated.name,
6098 out_svm_set_enum_str[uinfo->value.enumerated.item]);
6102 static int ca0132_alt_svm_setting_get(struct snd_kcontrol *kcontrol,
6103 struct snd_ctl_elem_value *ucontrol)
6105 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6106 struct ca0132_spec *spec = codec->spec;
6108 ucontrol->value.enumerated.item[0] = spec->smart_volume_setting;
6112 static int ca0132_alt_svm_setting_put(struct snd_kcontrol *kcontrol,
6113 struct snd_ctl_elem_value *ucontrol)
6115 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6116 struct ca0132_spec *spec = codec->spec;
6117 int sel = ucontrol->value.enumerated.item[0];
6118 unsigned int items = NUM_OF_SVM_SETTINGS;
6119 unsigned int idx = SMART_VOLUME - EFFECT_START_NID;
6125 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
6126 sel, out_svm_set_enum_str[sel]);
6128 spec->smart_volume_setting = sel;
6144 /* Req 2 is the Smart Volume Setting req. */
6145 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
6146 ca0132_effects[idx].reqs[2], tmp);
6150 /* Sound Blaster Z EQ preset controls */
6151 static int ca0132_alt_eq_preset_info(struct snd_kcontrol *kcontrol,
6152 struct snd_ctl_elem_info *uinfo)
6154 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
6156 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6158 uinfo->value.enumerated.items = items;
6159 if (uinfo->value.enumerated.item >= items)
6160 uinfo->value.enumerated.item = items - 1;
6161 strcpy(uinfo->value.enumerated.name,
6162 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name);
6166 static int ca0132_alt_eq_preset_get(struct snd_kcontrol *kcontrol,
6167 struct snd_ctl_elem_value *ucontrol)
6169 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6170 struct ca0132_spec *spec = codec->spec;
6172 ucontrol->value.enumerated.item[0] = spec->eq_preset_val;
6176 static int ca0132_alt_eq_preset_put(struct snd_kcontrol *kcontrol,
6177 struct snd_ctl_elem_value *ucontrol)
6179 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6180 struct ca0132_spec *spec = codec->spec;
6182 int sel = ucontrol->value.enumerated.item[0];
6183 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
6188 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
6189 ca0132_alt_eq_presets[sel].name);
6192 * Default needs to qualify with CrystalVoice state.
6194 for (i = 0; i < EQ_PRESET_MAX_PARAM_COUNT; i++) {
6195 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
6196 ca0132_alt_eq_enum.reqs[i],
6197 ca0132_alt_eq_presets[sel].vals[i]);
6203 spec->eq_preset_val = sel;
6208 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
6209 struct snd_ctl_elem_info *uinfo)
6211 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
6213 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6215 uinfo->value.enumerated.items = items;
6216 if (uinfo->value.enumerated.item >= items)
6217 uinfo->value.enumerated.item = items - 1;
6218 strcpy(uinfo->value.enumerated.name,
6219 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
6223 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
6224 struct snd_ctl_elem_value *ucontrol)
6226 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6227 struct ca0132_spec *spec = codec->spec;
6229 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
6233 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
6234 struct snd_ctl_elem_value *ucontrol)
6236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6237 struct ca0132_spec *spec = codec->spec;
6239 int sel = ucontrol->value.enumerated.item[0];
6241 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
6244 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
6245 sel, ca0132_voicefx_presets[sel].name);
6249 * Default needs to qualify with CrystalVoice state.
6251 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
6252 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
6253 ca0132_voicefx.reqs[i],
6254 ca0132_voicefx_presets[sel].vals[i]);
6260 spec->voicefx_val = sel;
6261 /* enable voice fx */
6262 ca0132_voicefx_set(codec, (sel ? 1 : 0));
6268 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
6269 struct snd_ctl_elem_value *ucontrol)
6271 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6272 struct ca0132_spec *spec = codec->spec;
6273 hda_nid_t nid = get_amp_nid(kcontrol);
6274 int ch = get_amp_channels(kcontrol);
6275 long *valp = ucontrol->value.integer.value;
6278 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
6280 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
6284 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
6290 /* effects, include PE and CrystalVoice */
6291 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
6292 *valp = spec->effects_switch[nid - EFFECT_START_NID];
6297 if (nid == spec->input_pins[0]) {
6298 *valp = spec->cur_mic_boost;
6302 if (nid == ZXR_HEADPHONE_GAIN) {
6303 *valp = spec->zxr_gain_set;
6307 if (nid == SPEAKER_FULL_RANGE_FRONT || nid == SPEAKER_FULL_RANGE_REAR) {
6308 *valp = spec->speaker_range_val[nid - SPEAKER_FULL_RANGE_FRONT];
6312 if (nid == BASS_REDIRECTION) {
6313 *valp = spec->bass_redirection_val;
6320 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
6321 struct snd_ctl_elem_value *ucontrol)
6323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6324 struct ca0132_spec *spec = codec->spec;
6325 hda_nid_t nid = get_amp_nid(kcontrol);
6326 int ch = get_amp_channels(kcontrol);
6327 long *valp = ucontrol->value.integer.value;
6330 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
6333 snd_hda_power_up(codec);
6335 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
6337 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
6341 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
6344 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
6349 if (nid == PLAY_ENHANCEMENT) {
6350 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6351 changed = ca0132_pe_switch_set(codec);
6356 if (nid == CRYSTAL_VOICE) {
6357 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6358 changed = ca0132_cvoice_switch_set(codec);
6362 /* out and in effects */
6363 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
6364 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
6365 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6366 changed = ca0132_effects_set(codec, nid, *valp);
6371 if (nid == spec->input_pins[0]) {
6372 spec->cur_mic_boost = *valp;
6373 if (ca0132_use_alt_functions(spec)) {
6374 if (spec->in_enum_val != REAR_LINE_IN)
6375 changed = ca0132_mic_boost_set(codec, *valp);
6377 /* Mic boost does not apply to Digital Mic */
6378 if (spec->cur_mic_type != DIGITAL_MIC)
6379 changed = ca0132_mic_boost_set(codec, *valp);
6385 if (nid == ZXR_HEADPHONE_GAIN) {
6386 spec->zxr_gain_set = *valp;
6387 if (spec->cur_out_type == HEADPHONE_OUT)
6388 changed = zxr_headphone_gain_set(codec, *valp);
6395 if (nid == SPEAKER_FULL_RANGE_FRONT || nid == SPEAKER_FULL_RANGE_REAR) {
6396 spec->speaker_range_val[nid - SPEAKER_FULL_RANGE_FRONT] = *valp;
6397 if (spec->cur_out_type == SPEAKER_OUT)
6398 ca0132_alt_set_full_range_speaker(codec);
6403 if (nid == BASS_REDIRECTION) {
6404 spec->bass_redirection_val = *valp;
6405 if (spec->cur_out_type == SPEAKER_OUT)
6406 ca0132_alt_surround_set_bass_redirection(codec, *valp);
6412 snd_hda_power_down(codec);
6420 * Sets the internal DSP decibel level to match the DAC for output, and the
6421 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
6422 * all alternative codecs set DSP playback volume.
6424 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
6426 struct ca0132_spec *spec = codec->spec;
6427 unsigned int dsp_dir;
6428 unsigned int lookup_val;
6430 if (nid == VNID_SPK)
6431 dsp_dir = DSP_VOL_OUT;
6433 dsp_dir = DSP_VOL_IN;
6435 lookup_val = spec->vnode_lvol[nid - VNODE_START_NID];
6437 dspio_set_uint_param(codec,
6438 ca0132_alt_vol_ctls[dsp_dir].mid,
6439 ca0132_alt_vol_ctls[dsp_dir].reqs[0],
6440 float_vol_db_lookup[lookup_val]);
6442 lookup_val = spec->vnode_rvol[nid - VNODE_START_NID];
6444 dspio_set_uint_param(codec,
6445 ca0132_alt_vol_ctls[dsp_dir].mid,
6446 ca0132_alt_vol_ctls[dsp_dir].reqs[1],
6447 float_vol_db_lookup[lookup_val]);
6449 dspio_set_uint_param(codec,
6450 ca0132_alt_vol_ctls[dsp_dir].mid,
6451 ca0132_alt_vol_ctls[dsp_dir].reqs[2], FLOAT_ZERO);
6454 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
6455 struct snd_ctl_elem_info *uinfo)
6457 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6458 struct ca0132_spec *spec = codec->spec;
6459 hda_nid_t nid = get_amp_nid(kcontrol);
6460 int ch = get_amp_channels(kcontrol);
6461 int dir = get_amp_direction(kcontrol);
6467 /* follow shared_out info */
6468 nid = spec->shared_out_nid;
6469 mutex_lock(&codec->control_mutex);
6470 pval = kcontrol->private_value;
6471 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6472 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6473 kcontrol->private_value = pval;
6474 mutex_unlock(&codec->control_mutex);
6477 /* follow shared_mic info */
6478 nid = spec->shared_mic_nid;
6479 mutex_lock(&codec->control_mutex);
6480 pval = kcontrol->private_value;
6481 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6482 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6483 kcontrol->private_value = pval;
6484 mutex_unlock(&codec->control_mutex);
6487 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6492 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
6493 struct snd_ctl_elem_value *ucontrol)
6495 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6496 struct ca0132_spec *spec = codec->spec;
6497 hda_nid_t nid = get_amp_nid(kcontrol);
6498 int ch = get_amp_channels(kcontrol);
6499 long *valp = ucontrol->value.integer.value;
6501 /* store the left and right volume */
6503 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
6507 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
6513 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
6514 struct snd_ctl_elem_value *ucontrol)
6516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6517 struct ca0132_spec *spec = codec->spec;
6518 hda_nid_t nid = get_amp_nid(kcontrol);
6519 int ch = get_amp_channels(kcontrol);
6520 long *valp = ucontrol->value.integer.value;
6521 hda_nid_t shared_nid = 0;
6525 /* store the left and right volume */
6527 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
6531 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
6535 /* if effective conditions, then update hw immediately. */
6536 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
6538 int dir = get_amp_direction(kcontrol);
6541 snd_hda_power_up(codec);
6542 mutex_lock(&codec->control_mutex);
6543 pval = kcontrol->private_value;
6544 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
6546 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6547 kcontrol->private_value = pval;
6548 mutex_unlock(&codec->control_mutex);
6549 snd_hda_power_down(codec);
6556 * This function is the same as the one above, because using an if statement
6557 * inside of the above volume control for the DSP volume would cause too much
6558 * lag. This is a lot more smooth.
6560 static int ca0132_alt_volume_put(struct snd_kcontrol *kcontrol,
6561 struct snd_ctl_elem_value *ucontrol)
6563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6564 struct ca0132_spec *spec = codec->spec;
6565 hda_nid_t nid = get_amp_nid(kcontrol);
6566 int ch = get_amp_channels(kcontrol);
6567 long *valp = ucontrol->value.integer.value;
6580 /* store the left and right volume */
6582 spec->vnode_lvol[vnid - VNODE_START_NID] = *valp;
6586 spec->vnode_rvol[vnid - VNODE_START_NID] = *valp;
6590 snd_hda_power_up(codec);
6591 ca0132_alt_dsp_volume_put(codec, vnid);
6592 mutex_lock(&codec->control_mutex);
6593 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6594 mutex_unlock(&codec->control_mutex);
6595 snd_hda_power_down(codec);
6600 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
6601 unsigned int size, unsigned int __user *tlv)
6603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6604 struct ca0132_spec *spec = codec->spec;
6605 hda_nid_t nid = get_amp_nid(kcontrol);
6606 int ch = get_amp_channels(kcontrol);
6607 int dir = get_amp_direction(kcontrol);
6613 /* follow shared_out tlv */
6614 nid = spec->shared_out_nid;
6615 mutex_lock(&codec->control_mutex);
6616 pval = kcontrol->private_value;
6617 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6618 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6619 kcontrol->private_value = pval;
6620 mutex_unlock(&codec->control_mutex);
6623 /* follow shared_mic tlv */
6624 nid = spec->shared_mic_nid;
6625 mutex_lock(&codec->control_mutex);
6626 pval = kcontrol->private_value;
6627 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6628 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6629 kcontrol->private_value = pval;
6630 mutex_unlock(&codec->control_mutex);
6633 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6638 /* Add volume slider control for effect level */
6639 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
6640 const char *pfx, int dir)
6642 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6643 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6644 struct snd_kcontrol_new knew =
6645 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
6647 sprintf(namestr, "FX: %s %s Volume", pfx, dirstr[dir]);
6653 knew.info = ca0132_alt_xbass_xover_slider_info;
6654 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6655 knew.put = ca0132_alt_xbass_xover_slider_put;
6658 knew.info = ca0132_alt_effect_slider_info;
6659 knew.get = ca0132_alt_slider_ctl_get;
6660 knew.put = ca0132_alt_effect_slider_put;
6661 knew.private_value =
6662 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
6666 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6670 * Added FX: prefix for the alternative codecs, because otherwise the surround
6671 * effect would conflict with the Surround sound volume control. Also seems more
6672 * clear as to what the switches do. Left alone for others.
6674 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
6675 const char *pfx, int dir)
6677 struct ca0132_spec *spec = codec->spec;
6678 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6679 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6680 struct snd_kcontrol_new knew =
6681 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
6682 /* If using alt_controls, add FX: prefix. But, don't add FX:
6683 * prefix to OutFX or InFX enable controls.
6685 if (ca0132_use_alt_controls(spec) && (nid <= IN_EFFECT_END_NID))
6686 sprintf(namestr, "FX: %s %s Switch", pfx, dirstr[dir]);
6688 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
6690 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6693 static int add_voicefx(struct hda_codec *codec)
6695 struct snd_kcontrol_new knew =
6696 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
6697 VOICEFX, 1, 0, HDA_INPUT);
6698 knew.info = ca0132_voicefx_info;
6699 knew.get = ca0132_voicefx_get;
6700 knew.put = ca0132_voicefx_put;
6701 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
6704 /* Create the EQ Preset control */
6705 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
6707 struct snd_kcontrol_new knew =
6708 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum.name,
6709 EQ_PRESET_ENUM, 1, 0, HDA_OUTPUT);
6710 knew.info = ca0132_alt_eq_preset_info;
6711 knew.get = ca0132_alt_eq_preset_get;
6712 knew.put = ca0132_alt_eq_preset_put;
6713 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
6714 snd_ctl_new1(&knew, codec));
6718 * Add enumerated control for the three different settings of the smart volume
6719 * output effect. Normal just uses the slider value, and loud and night are
6720 * their own things that ignore that value.
6722 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
6724 struct snd_kcontrol_new knew =
6725 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
6726 SMART_VOLUME_ENUM, 1, 0, HDA_OUTPUT);
6727 knew.info = ca0132_alt_svm_setting_info;
6728 knew.get = ca0132_alt_svm_setting_get;
6729 knew.put = ca0132_alt_svm_setting_put;
6730 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
6731 snd_ctl_new1(&knew, codec));
6736 * Create an Output Select enumerated control for codecs with surround
6739 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
6741 struct snd_kcontrol_new knew =
6742 HDA_CODEC_MUTE_MONO("Output Select",
6743 OUTPUT_SOURCE_ENUM, 1, 0, HDA_OUTPUT);
6744 knew.info = ca0132_alt_output_select_get_info;
6745 knew.get = ca0132_alt_output_select_get;
6746 knew.put = ca0132_alt_output_select_put;
6747 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
6748 snd_ctl_new1(&knew, codec));
6752 * Add a control for selecting channel count on speaker output. Setting this
6753 * allows the DSP to do bass redirection and channel upmixing on surround
6756 static int ca0132_alt_add_speaker_channel_cfg_enum(struct hda_codec *codec)
6758 struct snd_kcontrol_new knew =
6759 HDA_CODEC_MUTE_MONO("Surround Channel Config",
6760 SPEAKER_CHANNEL_CFG_ENUM, 1, 0, HDA_OUTPUT);
6761 knew.info = ca0132_alt_speaker_channel_cfg_get_info;
6762 knew.get = ca0132_alt_speaker_channel_cfg_get;
6763 knew.put = ca0132_alt_speaker_channel_cfg_put;
6764 return snd_hda_ctl_add(codec, SPEAKER_CHANNEL_CFG_ENUM,
6765 snd_ctl_new1(&knew, codec));
6769 * Full range front stereo and rear surround switches. When these are set to
6770 * full range, the lower frequencies from these channels are no longer
6771 * redirected to the LFE channel.
6773 static int ca0132_alt_add_front_full_range_switch(struct hda_codec *codec)
6775 struct snd_kcontrol_new knew =
6776 CA0132_CODEC_MUTE_MONO("Full-Range Front Speakers",
6777 SPEAKER_FULL_RANGE_FRONT, 1, HDA_OUTPUT);
6779 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_FRONT,
6780 snd_ctl_new1(&knew, codec));
6783 static int ca0132_alt_add_rear_full_range_switch(struct hda_codec *codec)
6785 struct snd_kcontrol_new knew =
6786 CA0132_CODEC_MUTE_MONO("Full-Range Rear Speakers",
6787 SPEAKER_FULL_RANGE_REAR, 1, HDA_OUTPUT);
6789 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_REAR,
6790 snd_ctl_new1(&knew, codec));
6794 * Bass redirection redirects audio below the crossover frequency to the LFE
6795 * channel on speakers that are set as not being full-range. On configurations
6796 * without an LFE channel, it does nothing. Bass redirection seems to be the
6797 * replacement for X-Bass on configurations with an LFE channel.
6799 static int ca0132_alt_add_bass_redirection_crossover(struct hda_codec *codec)
6801 const char *namestr = "Bass Redirection Crossover";
6802 struct snd_kcontrol_new knew =
6803 HDA_CODEC_VOLUME_MONO(namestr, BASS_REDIRECTION_XOVER, 1, 0,
6807 knew.info = ca0132_alt_xbass_xover_slider_info;
6808 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6809 knew.put = ca0132_alt_xbass_xover_slider_put;
6811 return snd_hda_ctl_add(codec, BASS_REDIRECTION_XOVER,
6812 snd_ctl_new1(&knew, codec));
6815 static int ca0132_alt_add_bass_redirection_switch(struct hda_codec *codec)
6817 const char *namestr = "Bass Redirection";
6818 struct snd_kcontrol_new knew =
6819 CA0132_CODEC_MUTE_MONO(namestr, BASS_REDIRECTION, 1,
6822 return snd_hda_ctl_add(codec, BASS_REDIRECTION,
6823 snd_ctl_new1(&knew, codec));
6827 * Create an Input Source enumerated control for the alternate ca0132 codecs
6828 * because the front microphone has no auto-detect, and Line-in has to be set
6831 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
6833 struct snd_kcontrol_new knew =
6834 HDA_CODEC_MUTE_MONO("Input Source",
6835 INPUT_SOURCE_ENUM, 1, 0, HDA_INPUT);
6836 knew.info = ca0132_alt_input_source_info;
6837 knew.get = ca0132_alt_input_source_get;
6838 knew.put = ca0132_alt_input_source_put;
6839 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
6840 snd_ctl_new1(&knew, codec));
6844 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
6845 * more control than the original mic boost, which is either full 30dB or off.
6847 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
6849 struct snd_kcontrol_new knew =
6850 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
6851 MIC_BOOST_ENUM, 1, 0, HDA_INPUT);
6852 knew.info = ca0132_alt_mic_boost_info;
6853 knew.get = ca0132_alt_mic_boost_get;
6854 knew.put = ca0132_alt_mic_boost_put;
6855 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
6856 snd_ctl_new1(&knew, codec));
6861 * Add headphone gain enumerated control for the AE-5. This switches between
6862 * three modes, low, medium, and high. When non-headphone outputs are selected,
6863 * it is automatically set to high. This is the same behavior as Windows.
6865 static int ae5_add_headphone_gain_enum(struct hda_codec *codec)
6867 struct snd_kcontrol_new knew =
6868 HDA_CODEC_MUTE_MONO("AE-5: Headphone Gain",
6869 AE5_HEADPHONE_GAIN_ENUM, 1, 0, HDA_OUTPUT);
6870 knew.info = ae5_headphone_gain_info;
6871 knew.get = ae5_headphone_gain_get;
6872 knew.put = ae5_headphone_gain_put;
6873 return snd_hda_ctl_add(codec, AE5_HEADPHONE_GAIN_ENUM,
6874 snd_ctl_new1(&knew, codec));
6878 * Add sound filter enumerated control for the AE-5. This adds three different
6879 * settings: Slow Roll Off, Minimum Phase, and Fast Roll Off. From what I've
6880 * read into it, it changes the DAC's interpolation filter.
6882 static int ae5_add_sound_filter_enum(struct hda_codec *codec)
6884 struct snd_kcontrol_new knew =
6885 HDA_CODEC_MUTE_MONO("AE-5: Sound Filter",
6886 AE5_SOUND_FILTER_ENUM, 1, 0, HDA_OUTPUT);
6887 knew.info = ae5_sound_filter_info;
6888 knew.get = ae5_sound_filter_get;
6889 knew.put = ae5_sound_filter_put;
6890 return snd_hda_ctl_add(codec, AE5_SOUND_FILTER_ENUM,
6891 snd_ctl_new1(&knew, codec));
6894 static int zxr_add_headphone_gain_switch(struct hda_codec *codec)
6896 struct snd_kcontrol_new knew =
6897 CA0132_CODEC_MUTE_MONO("ZxR: 600 Ohm Gain",
6898 ZXR_HEADPHONE_GAIN, 1, HDA_OUTPUT);
6900 return snd_hda_ctl_add(codec, ZXR_HEADPHONE_GAIN,
6901 snd_ctl_new1(&knew, codec));
6905 * Need to create follower controls for the alternate codecs that have surround
6908 static const char * const ca0132_alt_follower_pfxs[] = {
6909 "Front", "Surround", "Center", "LFE", NULL,
6913 * Also need special channel map, because the default one is incorrect.
6914 * I think this has to do with the pin for rear surround being 0x11,
6915 * and the center/lfe being 0x10. Usually the pin order is the opposite.
6917 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps[] = {
6919 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
6921 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6922 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6924 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6925 SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE,
6926 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6930 /* Add the correct chmap for streams with 6 channels. */
6931 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
6934 struct hda_pcm *pcm;
6936 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
6937 struct hda_pcm_stream *hinfo =
6938 &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
6939 struct snd_pcm_chmap *chmap;
6940 const struct snd_pcm_chmap_elem *elem;
6942 elem = ca0132_alt_chmaps;
6943 if (hinfo->channels_max == 6) {
6944 err = snd_pcm_add_chmap_ctls(pcm->pcm,
6945 SNDRV_PCM_STREAM_PLAYBACK,
6946 elem, hinfo->channels_max, 0, &chmap);
6948 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
6954 * When changing Node IDs for Mixer Controls below, make sure to update
6955 * Node IDs in ca0132_config() as well.
6957 static const struct snd_kcontrol_new ca0132_mixer[] = {
6958 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
6959 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
6960 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6961 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6962 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
6963 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
6964 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6965 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6966 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
6967 0x12, 1, HDA_INPUT),
6968 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
6969 VNID_HP_SEL, 1, HDA_OUTPUT),
6970 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
6971 VNID_AMIC1_SEL, 1, HDA_INPUT),
6972 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6973 VNID_HP_ASEL, 1, HDA_OUTPUT),
6974 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
6975 VNID_AMIC1_ASEL, 1, HDA_INPUT),
6980 * Desktop specific control mixer. Removes auto-detect for mic, and adds
6981 * surround controls. Also sets both the Front Playback and Capture Volume
6982 * controls to alt so they set the DSP's decibel level.
6984 static const struct snd_kcontrol_new desktop_mixer[] = {
6985 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6986 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6987 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6988 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6989 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6990 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6991 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6992 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6993 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT),
6994 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6995 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6996 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6997 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6998 VNID_HP_ASEL, 1, HDA_OUTPUT),
7003 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
7004 * because it doesn't set decibel levels for the DSP for capture.
7006 static const struct snd_kcontrol_new r3di_mixer[] = {
7007 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
7008 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
7009 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
7010 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
7011 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
7012 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
7013 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
7014 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
7015 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
7016 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
7017 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
7018 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
7019 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
7020 VNID_HP_ASEL, 1, HDA_OUTPUT),
7024 static int ca0132_build_controls(struct hda_codec *codec)
7026 struct ca0132_spec *spec = codec->spec;
7027 int i, num_fx, num_sliders;
7030 /* Add Mixer controls */
7031 for (i = 0; i < spec->num_mixers; i++) {
7032 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
7036 /* Setup vmaster with surround followers for desktop ca0132 devices */
7037 if (ca0132_use_alt_functions(spec)) {
7038 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
7040 snd_hda_add_vmaster(codec, "Master Playback Volume",
7041 spec->tlv, ca0132_alt_follower_pfxs,
7042 "Playback Volume", 0);
7043 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
7044 NULL, ca0132_alt_follower_pfxs,
7046 true, 0, &spec->vmaster_mute.sw_kctl);
7051 /* Add in and out effects controls.
7052 * VoiceFX, PE and CrystalVoice are added separately.
7054 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
7055 for (i = 0; i < num_fx; i++) {
7056 /* Desktop cards break if Echo Cancellation is used. */
7057 if (ca0132_use_pci_mmio(spec)) {
7058 if (i == (ECHO_CANCELLATION - IN_EFFECT_START_NID +
7063 err = add_fx_switch(codec, ca0132_effects[i].nid,
7064 ca0132_effects[i].name,
7065 ca0132_effects[i].direct);
7070 * If codec has use_alt_controls set to true, add effect level sliders,
7071 * EQ presets, and Smart Volume presets. Also, change names to add FX
7072 * prefix, and change PlayEnhancement and CrystalVoice to match.
7074 if (ca0132_use_alt_controls(spec)) {
7075 err = ca0132_alt_add_svm_enum(codec);
7079 err = add_ca0132_alt_eq_presets(codec);
7083 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
7088 err = add_fx_switch(codec, CRYSTAL_VOICE,
7093 num_sliders = OUT_EFFECTS_COUNT - 1;
7094 for (i = 0; i < num_sliders; i++) {
7095 err = ca0132_alt_add_effect_slider(codec,
7096 ca0132_effects[i].nid,
7097 ca0132_effects[i].name,
7098 ca0132_effects[i].direct);
7103 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
7104 "X-Bass Crossover", EFX_DIR_OUT);
7109 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
7110 "PlayEnhancement", 0);
7114 err = add_fx_switch(codec, CRYSTAL_VOICE,
7119 err = add_voicefx(codec);
7124 * If the codec uses alt_functions, you need the enumerated controls
7125 * to select the new outputs and inputs, plus add the new mic boost
7128 if (ca0132_use_alt_functions(spec)) {
7129 err = ca0132_alt_add_output_enum(codec);
7132 err = ca0132_alt_add_speaker_channel_cfg_enum(codec);
7135 err = ca0132_alt_add_front_full_range_switch(codec);
7138 err = ca0132_alt_add_rear_full_range_switch(codec);
7141 err = ca0132_alt_add_bass_redirection_crossover(codec);
7144 err = ca0132_alt_add_bass_redirection_switch(codec);
7147 err = ca0132_alt_add_mic_boost_enum(codec);
7151 * ZxR only has microphone input, there is no front panel
7152 * header on the card, and aux-in is handled by the DBPro board.
7154 if (ca0132_quirk(spec) != QUIRK_ZXR) {
7155 err = ca0132_alt_add_input_enum(codec);
7161 switch (ca0132_quirk(spec)) {
7164 err = ae5_add_headphone_gain_enum(codec);
7167 err = ae5_add_sound_filter_enum(codec);
7172 err = zxr_add_headphone_gain_switch(codec);
7180 #ifdef ENABLE_TUNING_CONTROLS
7181 add_tuning_ctls(codec);
7184 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
7188 if (spec->dig_out) {
7189 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7193 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
7196 /* spec->multiout.share_spdif = 1; */
7200 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7205 if (ca0132_use_alt_functions(spec))
7206 ca0132_alt_add_chmap_ctls(codec);
7211 static int dbpro_build_controls(struct hda_codec *codec)
7213 struct ca0132_spec *spec = codec->spec;
7216 if (spec->dig_out) {
7217 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7224 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7235 static const struct hda_pcm_stream ca0132_pcm_analog_playback = {
7240 .prepare = ca0132_playback_pcm_prepare,
7241 .cleanup = ca0132_playback_pcm_cleanup,
7242 .get_delay = ca0132_playback_pcm_delay,
7246 static const struct hda_pcm_stream ca0132_pcm_analog_capture = {
7251 .prepare = ca0132_capture_pcm_prepare,
7252 .cleanup = ca0132_capture_pcm_cleanup,
7253 .get_delay = ca0132_capture_pcm_delay,
7257 static const struct hda_pcm_stream ca0132_pcm_digital_playback = {
7262 .open = ca0132_dig_playback_pcm_open,
7263 .close = ca0132_dig_playback_pcm_close,
7264 .prepare = ca0132_dig_playback_pcm_prepare,
7265 .cleanup = ca0132_dig_playback_pcm_cleanup
7269 static const struct hda_pcm_stream ca0132_pcm_digital_capture = {
7275 static int ca0132_build_pcms(struct hda_codec *codec)
7277 struct ca0132_spec *spec = codec->spec;
7278 struct hda_pcm *info;
7280 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
7283 if (ca0132_use_alt_functions(spec)) {
7284 info->own_chmap = true;
7285 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap
7286 = ca0132_alt_chmaps;
7288 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
7289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
7290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
7291 spec->multiout.max_channels;
7292 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7293 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7294 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
7296 /* With the DSP enabled, desktops don't use this ADC. */
7297 if (!ca0132_use_alt_functions(spec)) {
7298 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
7301 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7302 ca0132_pcm_analog_capture;
7303 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7304 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
7307 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
7310 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7311 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
7314 if (!spec->dig_out && !spec->dig_in)
7317 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7320 info->pcm_type = HDA_PCM_TYPE_SPDIF;
7321 if (spec->dig_out) {
7322 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
7323 ca0132_pcm_digital_playback;
7324 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
7327 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7328 ca0132_pcm_digital_capture;
7329 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
7335 static int dbpro_build_pcms(struct hda_codec *codec)
7337 struct ca0132_spec *spec = codec->spec;
7338 struct hda_pcm *info;
7340 info = snd_hda_codec_pcm_new(codec, "CA0132 Alt Analog");
7343 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7344 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7345 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
7348 if (!spec->dig_out && !spec->dig_in)
7351 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7354 info->pcm_type = HDA_PCM_TYPE_SPDIF;
7355 if (spec->dig_out) {
7356 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
7357 ca0132_pcm_digital_playback;
7358 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
7361 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7362 ca0132_pcm_digital_capture;
7363 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
7369 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
7372 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
7373 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
7374 snd_hda_codec_write(codec, pin, 0,
7375 AC_VERB_SET_AMP_GAIN_MUTE,
7378 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
7379 snd_hda_codec_write(codec, dac, 0,
7380 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
7383 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
7386 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
7387 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
7388 snd_hda_codec_write(codec, pin, 0,
7389 AC_VERB_SET_AMP_GAIN_MUTE,
7392 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
7393 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7396 /* init to 0 dB and unmute. */
7397 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7398 HDA_AMP_VOLMASK, 0x5a);
7399 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7404 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
7408 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
7409 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
7410 snd_hda_override_amp_caps(codec, nid, dir, caps);
7414 * Switch between Digital built-in mic and analog mic.
7416 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
7418 struct ca0132_spec *spec = codec->spec;
7421 unsigned int oldval;
7423 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
7425 oldval = stop_mic1(codec);
7426 ca0132_set_vipsource(codec, 0);
7428 /* set DMic input as 2-ch */
7430 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7432 val = spec->dmic_ctl;
7434 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7435 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7437 if (!(spec->dmic_ctl & 0x20))
7438 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
7440 /* set AMic input as mono */
7442 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7444 val = spec->dmic_ctl;
7445 /* clear bit7 and bit5 to disable dmic */
7447 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7448 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7450 if (!(spec->dmic_ctl & 0x20))
7451 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
7453 ca0132_set_vipsource(codec, 1);
7454 resume_mic1(codec, oldval);
7458 * Initialization for Digital Mic.
7460 static void ca0132_init_dmic(struct hda_codec *codec)
7462 struct ca0132_spec *spec = codec->spec;
7465 /* Setup Digital Mic here, but don't enable.
7466 * Enable based on jack detect.
7469 /* MCLK uses MPIO1, set to enable.
7470 * Bit 2-0: MPIO select
7471 * Bit 3: set to disable
7475 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7476 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
7478 /* Data1 uses MPIO3. Data2 not use
7479 * Bit 2-0: Data1 MPIO select
7480 * Bit 3: set disable Data1
7481 * Bit 6-4: Data2 MPIO select
7482 * Bit 7: set disable Data2
7485 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7486 VENDOR_CHIPIO_DMIC_PIN_SET, val);
7488 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
7489 * Bit 3-0: Channel mask
7490 * Bit 4: set for 48KHz, clear for 32KHz
7492 * Bit 6: set to select Data2, clear for Data1
7493 * Bit 7: set to enable DMic, clear for AMic
7495 if (ca0132_quirk(spec) == QUIRK_ALIENWARE_M17XR4)
7499 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
7500 spec->dmic_ctl = val;
7501 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7502 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7506 * Initialization for Analog Mic 2
7508 static void ca0132_init_analog_mic2(struct hda_codec *codec)
7510 struct ca0132_spec *spec = codec->spec;
7512 mutex_lock(&spec->chipio_mutex);
7514 chipio_8051_write_exram_no_mutex(codec, 0x1920, 0x00);
7515 chipio_8051_write_exram_no_mutex(codec, 0x192d, 0x00);
7517 mutex_unlock(&spec->chipio_mutex);
7520 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
7522 struct ca0132_spec *spec = codec->spec;
7525 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
7526 snd_hda_codec_update_widgets(codec);
7528 for (i = 0; i < spec->multiout.num_dacs; i++)
7529 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
7531 for (i = 0; i < spec->num_outputs; i++)
7532 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
7534 for (i = 0; i < spec->num_inputs; i++) {
7535 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
7536 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
7541 /* If there is an active channel for some reason, find it and free it. */
7542 static void ca0132_alt_free_active_dma_channels(struct hda_codec *codec)
7544 unsigned int i, tmp;
7547 /* Read active DSPDMAC channel register. */
7548 status = chipio_read(codec, DSPDMAC_CHNLSTART_MODULE_OFFSET, &tmp);
7550 /* AND against 0xfff to get the active channel bits. */
7553 /* If there are no active channels, nothing to free. */
7557 codec_dbg(codec, "%s: Failed to read active DSP DMA channel register.\n",
7563 * Check each DSP DMA channel for activity, and if the channel is
7566 for (i = 0; i < DSPDMAC_DMA_CFG_CHANNEL_COUNT; i++) {
7567 if (dsp_is_dma_active(codec, i)) {
7568 status = dspio_free_dma_chan(codec, i);
7570 codec_dbg(codec, "%s: Failed to free active DSP DMA channel %d.\n",
7577 * In the case of CT_EXTENSIONS_ENABLE being set to 1, and the DSP being in
7578 * use, audio is no longer routed directly to the DAC/ADC from the HDA stream.
7579 * Instead, audio is now routed through the DSP's DMA controllers, which
7580 * the DSP is tasked with setting up itself. Through debugging, it seems the
7581 * cause of most of the no-audio on startup issues were due to improperly
7582 * configured DSP DMA channels.
7584 * Normally, the DSP configures these the first time an HDA audio stream is
7585 * started post DSP firmware download. That is why creating a 'dummy' stream
7586 * worked in fixing the audio in some cases. This works most of the time, but
7587 * sometimes if a stream is started/stopped before the DSP can setup the DMA
7588 * configuration registers, it ends up in a broken state. Issues can also
7589 * arise if streams are started in an unusual order, i.e the audio output dma
7590 * channel being sandwiched between the mic1 and mic2 dma channels.
7592 * The solution to this is to make sure that the DSP has no DMA channels
7593 * in use post DSP firmware download, and then to manually start each default
7594 * DSP stream that uses the DMA channels. These are 0x0c, the audio output
7595 * stream, 0x03, analog mic 1, and 0x04, analog mic 2.
7597 static void ca0132_alt_start_dsp_audio_streams(struct hda_codec *codec)
7599 static const unsigned int dsp_dma_stream_ids[] = { 0x0c, 0x03, 0x04 };
7600 struct ca0132_spec *spec = codec->spec;
7601 unsigned int i, tmp;
7604 * Check if any of the default streams are active, and if they are,
7607 mutex_lock(&spec->chipio_mutex);
7609 for (i = 0; i < ARRAY_SIZE(dsp_dma_stream_ids); i++) {
7610 chipio_get_stream_control(codec, dsp_dma_stream_ids[i], &tmp);
7613 chipio_set_stream_control(codec,
7614 dsp_dma_stream_ids[i], 0);
7618 mutex_unlock(&spec->chipio_mutex);
7621 * If all DSP streams are inactive, there should be no active DSP DMA
7622 * channels. Check and make sure this is the case, and if it isn't,
7623 * free any active channels.
7625 ca0132_alt_free_active_dma_channels(codec);
7627 mutex_lock(&spec->chipio_mutex);
7629 /* Make sure stream 0x0c is six channels. */
7630 chipio_set_stream_channels(codec, 0x0c, 6);
7632 for (i = 0; i < ARRAY_SIZE(dsp_dma_stream_ids); i++) {
7633 chipio_set_stream_control(codec,
7634 dsp_dma_stream_ids[i], 1);
7636 /* Give the DSP some time to setup the DMA channel. */
7640 mutex_unlock(&spec->chipio_mutex);
7644 * The region of ChipIO memory from 0x190000-0x1903fc is a sort of 'audio
7645 * router', where each entry represents a 48khz audio channel, with a format
7646 * of an 8-bit destination, an 8-bit source, and an unknown 2-bit number
7647 * value. The 2-bit number value is seemingly 0 if inactive, 1 if active,
7648 * and 3 if it's using Sample Rate Converter ports.
7651 * In this case, f8 is the destination, and c0 is the source. The number value
7653 * This region of memory is normally managed internally by the 8051, where
7654 * the region of exram memory from 0x1477-0x1575 has each byte represent an
7655 * entry within the 0x190000 range, and when a range of entries is in use, the
7656 * ending value is overwritten with 0xff.
7657 * 0x1578 in exram is a table of 0x25 entries, corresponding to the ChipIO
7658 * streamID's, where each entry is a starting 0x190000 port offset.
7659 * 0x159d in exram is the same as 0x1578, except it contains the ending port
7660 * offset for the corresponding streamID.
7662 * On certain cards, such as the SBZ/ZxR/AE7, these are originally setup by
7663 * the 8051, then manually overwritten to remap the ports to work with the
7666 * Currently known portID's:
7667 * 0x00-0x1f: HDA audio stream input/output ports.
7668 * 0x80-0xbf: Sample rate converter input/outputs. Only valid ports seem to
7669 * have the lower-nibble set to 0x1, 0x2, and 0x9.
7670 * 0xc0-0xdf: DSP DMA input/output ports. Dynamically assigned.
7671 * 0xe0-0xff: DAC/ADC audio input/output ports.
7673 * Currently known streamID's:
7674 * 0x03: Mic1 ADC to DSP.
7675 * 0x04: Mic2 ADC to DSP.
7676 * 0x05: HDA node 0x02 audio stream to DSP.
7677 * 0x0f: DSP Mic exit to HDA node 0x07.
7678 * 0x0c: DSP processed audio to DACs.
7679 * 0x14: DAC0, front L/R.
7681 * It is possible to route the HDA audio streams directly to the DAC and
7682 * bypass the DSP entirely, with the only downside being that since the DSP
7683 * does volume control, the only volume control you'll get is through PCM on
7684 * the PC side, in the same way volume is handled for optical out. This may be
7685 * useful for debugging.
7687 static void chipio_remap_stream(struct hda_codec *codec,
7688 const struct chipio_stream_remap_data *remap_data)
7690 unsigned int i, stream_offset;
7692 /* Get the starting port for the stream to be remapped. */
7693 chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
7697 * Check if the stream's port value is 0xff, because the 8051 may not
7698 * have gotten around to setting up the stream yet. Wait until it's
7699 * setup to remap it's ports.
7701 if (stream_offset == 0xff) {
7702 for (i = 0; i < 5; i++) {
7705 chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
7708 if (stream_offset != 0xff)
7713 if (stream_offset == 0xff) {
7714 codec_info(codec, "%s: Stream 0x%02x ports aren't allocated, remap failed!\n",
7715 __func__, remap_data->stream_id);
7719 /* Offset isn't in bytes, its in 32-bit words, so multiply it by 4. */
7720 stream_offset *= 0x04;
7721 stream_offset += 0x190000;
7723 for (i = 0; i < remap_data->count; i++) {
7724 chipio_write_no_mutex(codec,
7725 stream_offset + remap_data->offset[i],
7726 remap_data->value[i]);
7729 /* Update stream map configuration. */
7730 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
7734 * Default speaker tuning values setup for alternative codecs.
7736 static const unsigned int sbz_default_delay_values[] = {
7737 /* Non-zero values are floating point 0.000198. */
7738 0x394f9e38, 0x394f9e38, 0x00000000, 0x00000000, 0x00000000, 0x00000000
7741 static const unsigned int zxr_default_delay_values[] = {
7742 /* Non-zero values are floating point 0.000220. */
7743 0x00000000, 0x00000000, 0x3966afcd, 0x3966afcd, 0x3966afcd, 0x3966afcd
7746 static const unsigned int ae5_default_delay_values[] = {
7747 /* Non-zero values are floating point 0.000100. */
7748 0x00000000, 0x00000000, 0x38d1b717, 0x38d1b717, 0x38d1b717, 0x38d1b717
7752 * If we never change these, probably only need them on initialization.
7754 static void ca0132_alt_init_speaker_tuning(struct hda_codec *codec)
7756 struct ca0132_spec *spec = codec->spec;
7757 unsigned int i, tmp, start_req, end_req;
7758 const unsigned int *values;
7760 switch (ca0132_quirk(spec)) {
7762 values = sbz_default_delay_values;
7765 values = zxr_default_delay_values;
7769 values = ae5_default_delay_values;
7772 values = sbz_default_delay_values;
7777 dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_ENABLE_CENTER_EQ, tmp);
7779 start_req = SPEAKER_TUNING_FRONT_LEFT_VOL_LEVEL;
7780 end_req = SPEAKER_TUNING_REAR_RIGHT_VOL_LEVEL;
7781 for (i = start_req; i < end_req + 1; i++)
7782 dspio_set_uint_param(codec, 0x96, i, tmp);
7784 start_req = SPEAKER_TUNING_FRONT_LEFT_INVERT;
7785 end_req = SPEAKER_TUNING_REAR_RIGHT_INVERT;
7786 for (i = start_req; i < end_req + 1; i++)
7787 dspio_set_uint_param(codec, 0x96, i, tmp);
7790 for (i = 0; i < 6; i++)
7791 dspio_set_uint_param(codec, 0x96,
7792 SPEAKER_TUNING_FRONT_LEFT_DELAY + i, values[i]);
7796 * Initialize mic for non-chromebook ca0132 implementations.
7798 static void ca0132_alt_init_analog_mics(struct hda_codec *codec)
7800 struct ca0132_spec *spec = codec->spec;
7804 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7805 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7806 if (ca0132_quirk(spec) == QUIRK_R3DI) {
7807 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7811 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7813 /* Mic 2 setup (not present on desktop cards) */
7814 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
7815 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
7816 if (ca0132_quirk(spec) == QUIRK_R3DI)
7817 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7819 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
7823 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
7824 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
7825 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
7826 * having an updated DAC, which changes the destination to that DAC.
7828 static void sbz_connect_streams(struct hda_codec *codec)
7830 struct ca0132_spec *spec = codec->spec;
7832 mutex_lock(&spec->chipio_mutex);
7834 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
7836 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
7837 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
7839 /* Setup stream 0x14 with it's source and destination points */
7840 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
7841 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
7842 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
7843 chipio_set_stream_channels(codec, 0x14, 2);
7844 chipio_set_stream_control(codec, 0x14, 1);
7846 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
7848 mutex_unlock(&spec->chipio_mutex);
7852 * Write data through ChipIO to setup proper stream destinations.
7853 * Not sure how it exactly works, but it seems to direct data
7854 * to different destinations. Example is f8 to c0, e0 to c0.
7855 * All I know is, if you don't set these, you get no sound.
7857 static void sbz_chipio_startup_data(struct hda_codec *codec)
7859 const struct chipio_stream_remap_data *dsp_out_remap_data;
7860 struct ca0132_spec *spec = codec->spec;
7862 mutex_lock(&spec->chipio_mutex);
7863 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
7865 /* Remap DAC0's output ports. */
7866 chipio_remap_stream(codec, &stream_remap_data[0]);
7868 /* Remap DSP audio output stream ports. */
7869 switch (ca0132_quirk(spec)) {
7871 dsp_out_remap_data = &stream_remap_data[1];
7875 dsp_out_remap_data = &stream_remap_data[2];
7879 dsp_out_remap_data = NULL;
7883 if (dsp_out_remap_data)
7884 chipio_remap_stream(codec, dsp_out_remap_data);
7886 codec_dbg(codec, "Startup Data exited, mutex released.\n");
7887 mutex_unlock(&spec->chipio_mutex);
7890 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec *codec)
7892 struct ca0132_spec *spec = codec->spec;
7895 chipio_set_stream_control(codec, 0x03, 0);
7896 chipio_set_stream_control(codec, 0x04, 0);
7898 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7899 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7902 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7904 chipio_set_stream_control(codec, 0x03, 1);
7905 chipio_set_stream_control(codec, 0x04, 1);
7907 switch (ca0132_quirk(spec)) {
7909 chipio_write(codec, 0x18b098, 0x0000000c);
7910 chipio_write(codec, 0x18b09C, 0x0000000c);
7913 chipio_write(codec, 0x18b098, 0x0000000c);
7914 chipio_write(codec, 0x18b09c, 0x0000004c);
7921 static void ae5_post_dsp_register_set(struct hda_codec *codec)
7923 struct ca0132_spec *spec = codec->spec;
7925 chipio_8051_write_direct(codec, 0x93, 0x10);
7926 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
7928 writeb(0xff, spec->mem_base + 0x304);
7929 writeb(0xff, spec->mem_base + 0x304);
7930 writeb(0xff, spec->mem_base + 0x304);
7931 writeb(0xff, spec->mem_base + 0x304);
7932 writeb(0x00, spec->mem_base + 0x100);
7933 writeb(0xff, spec->mem_base + 0x304);
7934 writeb(0x00, spec->mem_base + 0x100);
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);
7941 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x3f);
7942 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
7943 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7946 static void ae5_post_dsp_param_setup(struct hda_codec *codec)
7949 * Param3 in the 8051's memory is represented by the ascii string 'mch'
7950 * which seems to be 'multichannel'. This is also mentioned in the
7951 * AE-5's registry values in Windows.
7953 chipio_set_control_param(codec, 3, 0);
7955 * I believe ASI is 'audio serial interface' and that it's used to
7956 * change colors on the external LED strip connected to the AE-5.
7958 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
7960 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
7961 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7963 chipio_8051_write_exram(codec, 0xfa92, 0x22);
7966 static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
7968 chipio_8051_write_pll_pmu(codec, 0x41, 0xc8);
7969 chipio_8051_write_pll_pmu(codec, 0x45, 0xcc);
7970 chipio_8051_write_pll_pmu(codec, 0x40, 0xcb);
7971 chipio_8051_write_pll_pmu(codec, 0x43, 0xc7);
7972 chipio_8051_write_pll_pmu(codec, 0x51, 0x8d);
7975 static void ae5_post_dsp_stream_setup(struct hda_codec *codec)
7977 struct ca0132_spec *spec = codec->spec;
7979 mutex_lock(&spec->chipio_mutex);
7981 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7983 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7985 chipio_set_stream_source_dest(codec, 0x5, 0x43, 0x0);
7987 chipio_set_stream_source_dest(codec, 0x18, 0x9, 0xd0);
7988 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7989 chipio_set_stream_channels(codec, 0x18, 6);
7990 chipio_set_stream_control(codec, 0x18, 1);
7992 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7994 chipio_8051_write_pll_pmu_no_mutex(codec, 0x43, 0xc7);
7996 ca0113_mmio_command_set(codec, 0x48, 0x01, 0x80);
7998 mutex_unlock(&spec->chipio_mutex);
8001 static void ae5_post_dsp_startup_data(struct hda_codec *codec)
8003 struct ca0132_spec *spec = codec->spec;
8005 mutex_lock(&spec->chipio_mutex);
8007 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
8008 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
8009 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
8010 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
8012 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
8013 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8014 ca0113_mmio_command_set(codec, 0x48, 0x0b, 0x12);
8015 ca0113_mmio_command_set(codec, 0x48, 0x04, 0x00);
8016 ca0113_mmio_command_set(codec, 0x48, 0x06, 0x48);
8017 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
8018 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8019 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8020 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8021 ca0113_mmio_gpio_set(codec, 0, true);
8022 ca0113_mmio_gpio_set(codec, 1, true);
8023 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x80);
8025 chipio_write_no_mutex(codec, 0x18b03c, 0x00000012);
8027 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8028 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8030 mutex_unlock(&spec->chipio_mutex);
8033 static void ae7_post_dsp_setup_ports(struct hda_codec *codec)
8035 struct ca0132_spec *spec = codec->spec;
8037 mutex_lock(&spec->chipio_mutex);
8039 /* Seems to share the same port remapping as the SBZ. */
8040 chipio_remap_stream(codec, &stream_remap_data[1]);
8042 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8043 ca0113_mmio_command_set(codec, 0x48, 0x0d, 0x40);
8044 ca0113_mmio_command_set(codec, 0x48, 0x17, 0x00);
8045 ca0113_mmio_command_set(codec, 0x48, 0x19, 0x00);
8046 ca0113_mmio_command_set(codec, 0x48, 0x11, 0xff);
8047 ca0113_mmio_command_set(codec, 0x48, 0x12, 0xff);
8048 ca0113_mmio_command_set(codec, 0x48, 0x13, 0xff);
8049 ca0113_mmio_command_set(codec, 0x48, 0x14, 0x7f);
8051 mutex_unlock(&spec->chipio_mutex);
8054 static void ae7_post_dsp_asi_stream_setup(struct hda_codec *codec)
8056 struct ca0132_spec *spec = codec->spec;
8058 mutex_lock(&spec->chipio_mutex);
8060 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
8061 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8063 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
8065 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
8066 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
8068 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
8069 chipio_set_stream_channels(codec, 0x18, 6);
8070 chipio_set_stream_control(codec, 0x18, 1);
8072 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
8074 mutex_unlock(&spec->chipio_mutex);
8077 static void ae7_post_dsp_pll_setup(struct hda_codec *codec)
8079 static const unsigned int addr[] = {
8080 0x41, 0x45, 0x40, 0x43, 0x51
8082 static const unsigned int data[] = {
8083 0xc8, 0xcc, 0xcb, 0xc7, 0x8d
8087 for (i = 0; i < ARRAY_SIZE(addr); i++)
8088 chipio_8051_write_pll_pmu_no_mutex(codec, addr[i], data[i]);
8091 static void ae7_post_dsp_asi_setup_ports(struct hda_codec *codec)
8093 struct ca0132_spec *spec = codec->spec;
8094 static const unsigned int target[] = {
8095 0x0b, 0x04, 0x06, 0x0a, 0x0c, 0x11, 0x12, 0x13, 0x14
8097 static const unsigned int data[] = {
8098 0x12, 0x00, 0x48, 0x05, 0x5f, 0xff, 0xff, 0xff, 0x7f
8102 mutex_lock(&spec->chipio_mutex);
8104 chipio_8051_write_pll_pmu_no_mutex(codec, 0x43, 0xc7);
8106 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
8107 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
8108 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
8109 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
8111 ae7_post_dsp_pll_setup(codec);
8112 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8114 for (i = 0; i < ARRAY_SIZE(target); i++)
8115 ca0113_mmio_command_set(codec, 0x48, target[i], data[i]);
8117 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8118 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8119 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8121 chipio_set_stream_source_dest(codec, 0x21, 0x64, 0x56);
8122 chipio_set_stream_channels(codec, 0x21, 2);
8123 chipio_set_conn_rate_no_mutex(codec, 0x56, SR_8_000);
8125 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_NODE_ID, 0x09);
8127 * In the 8051's memory, this param is referred to as 'n2sid', which I
8128 * believe is 'node to streamID'. It seems to be a way to assign a
8129 * stream to a given HDA node.
8131 chipio_set_control_param_no_mutex(codec, 0x20, 0x21);
8133 chipio_write_no_mutex(codec, 0x18b038, 0x00000088);
8136 * Now, at this point on Windows, an actual stream is setup and
8137 * seemingly sends data to the HDA node 0x09, which is the digital
8138 * audio input node. This is left out here, because obviously I don't
8139 * know what data is being sent. Interestingly, the AE-5 seems to go
8140 * through the motions of getting here and never actually takes this
8141 * step, but the AE-7 does.
8144 ca0113_mmio_gpio_set(codec, 0, 1);
8145 ca0113_mmio_gpio_set(codec, 1, 1);
8147 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8148 chipio_write_no_mutex(codec, 0x18b03c, 0x00000000);
8149 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8150 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8152 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
8153 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
8155 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
8156 chipio_set_stream_channels(codec, 0x18, 6);
8159 * Runs again, this has been repeated a few times, but I'm just
8160 * following what the Windows driver does.
8162 ae7_post_dsp_pll_setup(codec);
8163 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8165 mutex_unlock(&spec->chipio_mutex);
8169 * The Windows driver has commands that seem to setup ASI, which I believe to
8170 * be some sort of audio serial interface. My current speculation is that it's
8171 * related to communicating with the new DAC.
8173 static void ae7_post_dsp_asi_setup(struct hda_codec *codec)
8175 chipio_8051_write_direct(codec, 0x93, 0x10);
8177 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
8179 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8180 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8182 chipio_set_control_param(codec, 3, 3);
8183 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
8185 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
8186 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8187 snd_hda_codec_write(codec, 0x17, 0, 0x794, 0x00);
8189 chipio_8051_write_exram(codec, 0xfa92, 0x22);
8191 ae7_post_dsp_pll_setup(codec);
8192 ae7_post_dsp_asi_stream_setup(codec);
8194 chipio_8051_write_pll_pmu(codec, 0x43, 0xc7);
8196 ae7_post_dsp_asi_setup_ports(codec);
8200 * Setup default parameters for DSP
8202 static void ca0132_setup_defaults(struct hda_codec *codec)
8204 struct ca0132_spec *spec = codec->spec;
8209 if (spec->dsp_state != DSP_DOWNLOADED)
8212 /* out, in effects + voicefx */
8213 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8214 for (idx = 0; idx < num_fx; idx++) {
8215 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8216 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
8217 ca0132_effects[idx].reqs[i],
8218 ca0132_effects[idx].def_vals[i]);
8222 /*remove DSP headroom*/
8224 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8226 /*set speaker EQ bypass attenuation*/
8227 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
8229 /* set AMic1 and AMic2 as mono mic */
8231 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
8232 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
8234 /* set AMic1 as CrystalVoice input */
8236 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
8238 /* set WUH source */
8240 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8244 * Setup default parameters for Recon3D/Recon3Di DSP.
8247 static void r3d_setup_defaults(struct hda_codec *codec)
8249 struct ca0132_spec *spec = codec->spec;
8254 if (spec->dsp_state != DSP_DOWNLOADED)
8257 ca0132_alt_init_analog_mics(codec);
8258 ca0132_alt_start_dsp_audio_streams(codec);
8260 /*remove DSP headroom*/
8262 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8264 /* set WUH source */
8266 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8267 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8269 /* Set speaker source? */
8270 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8272 if (ca0132_quirk(spec) == QUIRK_R3DI)
8273 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
8275 /* Disable mute on Center/LFE. */
8276 if (ca0132_quirk(spec) == QUIRK_R3D) {
8277 ca0113_mmio_gpio_set(codec, 2, false);
8278 ca0113_mmio_gpio_set(codec, 4, true);
8281 /* Setup effect defaults */
8282 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8283 for (idx = 0; idx < num_fx; idx++) {
8284 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8285 dspio_set_uint_param(codec,
8286 ca0132_effects[idx].mid,
8287 ca0132_effects[idx].reqs[i],
8288 ca0132_effects[idx].def_vals[i]);
8294 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
8295 * than the Chromebook setup.
8297 static void sbz_setup_defaults(struct hda_codec *codec)
8299 struct ca0132_spec *spec = codec->spec;
8304 if (spec->dsp_state != DSP_DOWNLOADED)
8307 ca0132_alt_init_analog_mics(codec);
8308 ca0132_alt_start_dsp_audio_streams(codec);
8309 sbz_connect_streams(codec);
8310 sbz_chipio_startup_data(codec);
8313 * Sets internal input loopback to off, used to have a switch to
8314 * enable input loopback, but turned out to be way too buggy.
8317 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8318 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8320 /*remove DSP headroom*/
8322 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8324 /* set WUH source */
8326 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8327 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8329 /* Set speaker source? */
8330 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8332 ca0132_alt_dsp_initial_mic_setup(codec);
8334 /* out, in effects + voicefx */
8335 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8336 for (idx = 0; idx < num_fx; idx++) {
8337 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8338 dspio_set_uint_param(codec,
8339 ca0132_effects[idx].mid,
8340 ca0132_effects[idx].reqs[i],
8341 ca0132_effects[idx].def_vals[i]);
8345 ca0132_alt_init_speaker_tuning(codec);
8349 * Setup default parameters for the Sound BlasterX AE-5 DSP.
8351 static void ae5_setup_defaults(struct hda_codec *codec)
8353 struct ca0132_spec *spec = codec->spec;
8358 if (spec->dsp_state != DSP_DOWNLOADED)
8361 ca0132_alt_init_analog_mics(codec);
8362 ca0132_alt_start_dsp_audio_streams(codec);
8364 /* New, unknown SCP req's */
8366 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
8367 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
8368 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8369 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8371 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8372 ca0113_mmio_gpio_set(codec, 0, false);
8373 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8375 /* Internal loopback off */
8377 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8378 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8380 /*remove DSP headroom*/
8382 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8384 /* set WUH source */
8386 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8387 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8389 /* Set speaker source? */
8390 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8392 ca0132_alt_dsp_initial_mic_setup(codec);
8393 ae5_post_dsp_register_set(codec);
8394 ae5_post_dsp_param_setup(codec);
8395 ae5_post_dsp_pll_setup(codec);
8396 ae5_post_dsp_stream_setup(codec);
8397 ae5_post_dsp_startup_data(codec);
8399 /* out, in effects + voicefx */
8400 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8401 for (idx = 0; idx < num_fx; idx++) {
8402 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8403 dspio_set_uint_param(codec,
8404 ca0132_effects[idx].mid,
8405 ca0132_effects[idx].reqs[i],
8406 ca0132_effects[idx].def_vals[i]);
8410 ca0132_alt_init_speaker_tuning(codec);
8414 * Setup default parameters for the Sound Blaster AE-7 DSP.
8416 static void ae7_setup_defaults(struct hda_codec *codec)
8418 struct ca0132_spec *spec = codec->spec;
8423 if (spec->dsp_state != DSP_DOWNLOADED)
8426 ca0132_alt_init_analog_mics(codec);
8427 ca0132_alt_start_dsp_audio_streams(codec);
8428 ae7_post_dsp_setup_ports(codec);
8431 dspio_set_uint_param(codec, 0x96,
8432 SPEAKER_TUNING_FRONT_LEFT_INVERT, tmp);
8433 dspio_set_uint_param(codec, 0x96,
8434 SPEAKER_TUNING_FRONT_RIGHT_INVERT, tmp);
8436 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8438 /* New, unknown SCP req's */
8439 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8440 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8442 ca0113_mmio_gpio_set(codec, 0, false);
8444 /* Internal loopback off */
8446 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8447 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8449 /*remove DSP headroom*/
8451 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8453 /* set WUH source */
8455 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8456 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8458 /* Set speaker source? */
8459 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8460 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8463 * This is the second time we've called this, but this is seemingly
8464 * what Windows does.
8466 ca0132_alt_init_analog_mics(codec);
8468 ae7_post_dsp_asi_setup(codec);
8471 * Not sure why, but these are both set to 1. They're only set to 0
8474 ca0113_mmio_gpio_set(codec, 0, true);
8475 ca0113_mmio_gpio_set(codec, 1, true);
8477 /* Volume control related. */
8478 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x04);
8479 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x04);
8480 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x80);
8482 /* out, in effects + voicefx */
8483 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8484 for (idx = 0; idx < num_fx; idx++) {
8485 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8486 dspio_set_uint_param(codec,
8487 ca0132_effects[idx].mid,
8488 ca0132_effects[idx].reqs[i],
8489 ca0132_effects[idx].def_vals[i]);
8493 ca0132_alt_init_speaker_tuning(codec);
8497 * Initialization of flags in chip
8499 static void ca0132_init_flags(struct hda_codec *codec)
8501 struct ca0132_spec *spec = codec->spec;
8503 if (ca0132_use_alt_functions(spec)) {
8504 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
8505 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
8506 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
8507 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
8508 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
8509 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8510 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
8511 chipio_set_control_flag(codec,
8512 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
8513 chipio_set_control_flag(codec,
8514 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 1);
8516 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8517 chipio_set_control_flag(codec,
8518 CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
8519 chipio_set_control_flag(codec,
8520 CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
8521 chipio_set_control_flag(codec,
8522 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
8523 chipio_set_control_flag(codec,
8524 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
8525 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
8530 * Initialization of parameters in chip
8532 static void ca0132_init_params(struct hda_codec *codec)
8534 struct ca0132_spec *spec = codec->spec;
8536 if (ca0132_use_alt_functions(spec)) {
8537 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8538 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
8539 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
8540 chipio_set_control_param(codec, 0, 0);
8541 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
8544 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
8545 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
8548 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
8550 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
8551 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
8552 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
8553 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
8554 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
8555 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
8557 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
8558 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
8559 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8562 static bool ca0132_download_dsp_images(struct hda_codec *codec)
8564 bool dsp_loaded = false;
8565 struct ca0132_spec *spec = codec->spec;
8566 const struct dsp_image_seg *dsp_os_image;
8567 const struct firmware *fw_entry = NULL;
8569 * Alternate firmwares for different variants. The Recon3Di apparently
8570 * can use the default firmware, but I'll leave the option in case
8571 * it needs it again.
8573 switch (ca0132_quirk(spec)) {
8577 if (reject_firmware(&fw_entry, DESKTOP_EFX_FILE,
8578 codec->card->dev) != 0)
8579 codec_dbg(codec, "Desktop firmware not found.");
8581 codec_dbg(codec, "Desktop firmware selected.");
8584 if (reject_firmware(&fw_entry, R3DI_EFX_FILE,
8585 codec->card->dev) != 0)
8586 codec_dbg(codec, "Recon3Di alt firmware not detected.");
8588 codec_dbg(codec, "Recon3Di firmware selected.");
8595 codec_dbg(codec, "Default firmware selected.");
8596 if (reject_firmware(&fw_entry, EFX_FILE,
8597 codec->card->dev) != 0)
8601 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
8602 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
8603 codec_err(codec, "ca0132 DSP load image failed\n");
8607 dsp_loaded = dspload_wait_loaded(codec);
8610 release_firmware(fw_entry);
8615 static void ca0132_download_dsp(struct hda_codec *codec)
8617 struct ca0132_spec *spec = codec->spec;
8619 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
8623 if (spec->dsp_state == DSP_DOWNLOAD_FAILED)
8624 return; /* don't retry failures */
8626 chipio_enable_clocks(codec);
8627 if (spec->dsp_state != DSP_DOWNLOADED) {
8628 spec->dsp_state = DSP_DOWNLOADING;
8630 if (!ca0132_download_dsp_images(codec))
8631 spec->dsp_state = DSP_DOWNLOAD_FAILED;
8633 spec->dsp_state = DSP_DOWNLOADED;
8636 /* For codecs using alt functions, this is already done earlier */
8637 if (spec->dsp_state == DSP_DOWNLOADED && !ca0132_use_alt_functions(spec))
8638 ca0132_set_dsp_msr(codec, true);
8641 static void ca0132_process_dsp_response(struct hda_codec *codec,
8642 struct hda_jack_callback *callback)
8644 struct ca0132_spec *spec = codec->spec;
8646 codec_dbg(codec, "ca0132_process_dsp_response\n");
8647 snd_hda_power_up_pm(codec);
8648 if (spec->wait_scp) {
8649 if (dspio_get_response_data(codec) >= 0)
8653 dspio_clear_response_queue(codec);
8654 snd_hda_power_down_pm(codec);
8657 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8659 struct ca0132_spec *spec = codec->spec;
8660 struct hda_jack_tbl *tbl;
8662 /* Delay enabling the HP amp, to let the mic-detection
8663 * state machine run.
8665 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
8667 tbl->block_report = 1;
8668 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
8671 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8673 struct ca0132_spec *spec = codec->spec;
8675 if (ca0132_use_alt_functions(spec))
8676 ca0132_alt_select_in(codec);
8678 ca0132_select_mic(codec);
8681 static void ca0132_setup_unsol(struct hda_codec *codec)
8683 struct ca0132_spec *spec = codec->spec;
8684 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
8685 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
8687 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
8688 ca0132_process_dsp_response);
8689 /* Front headphone jack detection */
8690 if (ca0132_use_alt_functions(spec))
8691 snd_hda_jack_detect_enable_callback(codec,
8692 spec->unsol_tag_front_hp, hp_callback);
8699 /* Sends before DSP download. */
8700 static const struct hda_verb ca0132_base_init_verbs[] = {
8701 /*enable ct extension*/
8702 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
8707 static const struct hda_verb ca0132_base_exit_verbs[] = {
8709 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
8710 /*disable ct extension*/
8711 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
8715 /* Other verbs tables. Sends after DSP download. */
8717 static const struct hda_verb ca0132_init_verbs0[] = {
8718 /* chip init verbs */
8719 {0x15, 0x70D, 0xF0},
8720 {0x15, 0x70E, 0xFE},
8721 {0x15, 0x707, 0x75},
8722 {0x15, 0x707, 0xD3},
8723 {0x15, 0x707, 0x09},
8724 {0x15, 0x707, 0x53},
8725 {0x15, 0x707, 0xD4},
8726 {0x15, 0x707, 0xEF},
8727 {0x15, 0x707, 0x75},
8728 {0x15, 0x707, 0xD3},
8729 {0x15, 0x707, 0x09},
8730 {0x15, 0x707, 0x02},
8731 {0x15, 0x707, 0x37},
8732 {0x15, 0x707, 0x78},
8733 {0x15, 0x53C, 0xCE},
8734 {0x15, 0x575, 0xC9},
8735 {0x15, 0x53D, 0xCE},
8736 {0x15, 0x5B7, 0xC9},
8737 {0x15, 0x70D, 0xE8},
8738 {0x15, 0x70E, 0xFE},
8739 {0x15, 0x707, 0x02},
8740 {0x15, 0x707, 0x68},
8741 {0x15, 0x707, 0x62},
8742 {0x15, 0x53A, 0xCE},
8743 {0x15, 0x546, 0xC9},
8744 {0x15, 0x53B, 0xCE},
8745 {0x15, 0x5E8, 0xC9},
8749 /* Extra init verbs for desktop cards. */
8750 static const struct hda_verb ca0132_init_verbs1[] = {
8751 {0x15, 0x70D, 0x20},
8752 {0x15, 0x70E, 0x19},
8753 {0x15, 0x707, 0x00},
8754 {0x15, 0x539, 0xCE},
8755 {0x15, 0x546, 0xC9},
8756 {0x15, 0x70D, 0xB7},
8757 {0x15, 0x70E, 0x09},
8758 {0x15, 0x707, 0x10},
8759 {0x15, 0x70D, 0xAF},
8760 {0x15, 0x70E, 0x09},
8761 {0x15, 0x707, 0x01},
8762 {0x15, 0x707, 0x05},
8763 {0x15, 0x70D, 0x73},
8764 {0x15, 0x70E, 0x09},
8765 {0x15, 0x707, 0x14},
8766 {0x15, 0x6FF, 0xC4},
8770 static void ca0132_init_chip(struct hda_codec *codec)
8772 struct ca0132_spec *spec = codec->spec;
8777 mutex_init(&spec->chipio_mutex);
8780 * The Windows driver always does this upon startup, which seems to
8781 * clear out any previous configuration. This should help issues where
8782 * a boot into Windows prior to a boot into Linux breaks things. Also,
8783 * Windows always sends the reset twice.
8785 if (ca0132_use_alt_functions(spec)) {
8786 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8787 chipio_write_no_mutex(codec, 0x18b0a4, 0x000000c2);
8789 snd_hda_codec_write(codec, codec->core.afg, 0,
8790 AC_VERB_SET_CODEC_RESET, 0);
8791 snd_hda_codec_write(codec, codec->core.afg, 0,
8792 AC_VERB_SET_CODEC_RESET, 0);
8795 spec->cur_out_type = SPEAKER_OUT;
8796 if (!ca0132_use_alt_functions(spec))
8797 spec->cur_mic_type = DIGITAL_MIC;
8799 spec->cur_mic_type = REAR_MIC;
8801 spec->cur_mic_boost = 0;
8803 for (i = 0; i < VNODES_COUNT; i++) {
8804 spec->vnode_lvol[i] = 0x5a;
8805 spec->vnode_rvol[i] = 0x5a;
8806 spec->vnode_lswitch[i] = 0;
8807 spec->vnode_rswitch[i] = 0;
8811 * Default states for effects are in ca0132_effects[].
8813 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
8814 for (i = 0; i < num_fx; i++) {
8815 on = (unsigned int)ca0132_effects[i].reqs[0];
8816 spec->effects_switch[i] = on ? 1 : 0;
8819 * Sets defaults for the effect slider controls, only for alternative
8820 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
8822 if (ca0132_use_alt_controls(spec)) {
8823 /* Set speakers to default to full range. */
8824 spec->speaker_range_val[0] = 1;
8825 spec->speaker_range_val[1] = 1;
8827 spec->xbass_xover_freq = 8;
8828 for (i = 0; i < EFFECT_LEVEL_SLIDERS; i++)
8829 spec->fx_ctl_val[i] = effect_slider_defaults[i];
8831 spec->bass_redirect_xover_freq = 8;
8834 spec->voicefx_val = 0;
8835 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
8836 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
8839 * The ZxR doesn't have a front panel header, and it's line-in is on
8840 * the daughter board. So, there is no input enum control, and we need
8841 * to make sure that spec->in_enum_val is set properly.
8843 if (ca0132_quirk(spec) == QUIRK_ZXR)
8844 spec->in_enum_val = REAR_MIC;
8846 #ifdef ENABLE_TUNING_CONTROLS
8847 ca0132_init_tuning_defaults(codec);
8852 * Recon3Di exit specific commands.
8854 /* prevents popping noise on shutdown */
8855 static void r3di_gpio_shutdown(struct hda_codec *codec)
8857 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
8861 * Sound Blaster Z exit specific commands.
8863 static void sbz_region2_exit(struct hda_codec *codec)
8865 struct ca0132_spec *spec = codec->spec;
8868 for (i = 0; i < 4; i++)
8869 writeb(0x0, spec->mem_base + 0x100);
8870 for (i = 0; i < 8; i++)
8871 writeb(0xb3, spec->mem_base + 0x304);
8873 ca0113_mmio_gpio_set(codec, 0, false);
8874 ca0113_mmio_gpio_set(codec, 1, false);
8875 ca0113_mmio_gpio_set(codec, 4, true);
8876 ca0113_mmio_gpio_set(codec, 5, false);
8877 ca0113_mmio_gpio_set(codec, 7, false);
8880 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
8882 static const hda_nid_t pins[] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
8885 snd_hda_codec_write(codec, 0x11, 0,
8886 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40);
8888 for (i = 0; i < ARRAY_SIZE(pins); i++)
8889 snd_hda_codec_write(codec, pins[i], 0,
8890 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00);
8893 static void ca0132_clear_unsolicited(struct hda_codec *codec)
8895 static const hda_nid_t pins[] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
8898 for (i = 0; i < ARRAY_SIZE(pins); i++) {
8899 snd_hda_codec_write(codec, pins[i], 0,
8900 AC_VERB_SET_UNSOLICITED_ENABLE, 0x00);
8904 /* On shutdown, sends commands in sets of three */
8905 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
8909 snd_hda_codec_write(codec, 0x01, 0,
8910 AC_VERB_SET_GPIO_DIRECTION, dir);
8912 snd_hda_codec_write(codec, 0x01, 0,
8913 AC_VERB_SET_GPIO_MASK, mask);
8916 snd_hda_codec_write(codec, 0x01, 0,
8917 AC_VERB_SET_GPIO_DATA, data);
8920 static void zxr_dbpro_power_state_shutdown(struct hda_codec *codec)
8922 static const hda_nid_t pins[] = {0x05, 0x0c, 0x09, 0x0e, 0x08, 0x11, 0x01};
8925 for (i = 0; i < ARRAY_SIZE(pins); i++)
8926 snd_hda_codec_write(codec, pins[i], 0,
8927 AC_VERB_SET_POWER_STATE, 0x03);
8930 static void sbz_exit_chip(struct hda_codec *codec)
8932 chipio_set_stream_control(codec, 0x03, 0);
8933 chipio_set_stream_control(codec, 0x04, 0);
8935 /* Mess with GPIO */
8936 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
8937 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
8938 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
8940 chipio_set_stream_control(codec, 0x14, 0);
8941 chipio_set_stream_control(codec, 0x0C, 0);
8943 chipio_set_conn_rate(codec, 0x41, SR_192_000);
8944 chipio_set_conn_rate(codec, 0x91, SR_192_000);
8946 chipio_write(codec, 0x18a020, 0x00000083);
8948 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
8949 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
8950 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
8952 chipio_set_stream_control(codec, 0x0C, 0);
8954 chipio_set_control_param(codec, 0x0D, 0x24);
8956 ca0132_clear_unsolicited(codec);
8957 sbz_set_pin_ctl_default(codec);
8959 snd_hda_codec_write(codec, 0x0B, 0,
8960 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
8962 sbz_region2_exit(codec);
8965 static void r3d_exit_chip(struct hda_codec *codec)
8967 ca0132_clear_unsolicited(codec);
8968 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8969 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
8972 static void ae5_exit_chip(struct hda_codec *codec)
8974 chipio_set_stream_control(codec, 0x03, 0);
8975 chipio_set_stream_control(codec, 0x04, 0);
8977 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8978 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8979 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8980 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8981 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8982 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x00);
8983 ca0113_mmio_gpio_set(codec, 0, false);
8984 ca0113_mmio_gpio_set(codec, 1, false);
8986 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8987 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8989 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8991 chipio_set_stream_control(codec, 0x18, 0);
8992 chipio_set_stream_control(codec, 0x0c, 0);
8994 snd_hda_codec_write(codec, 0x01, 0, 0x724, 0x83);
8997 static void ae7_exit_chip(struct hda_codec *codec)
8999 chipio_set_stream_control(codec, 0x18, 0);
9000 chipio_set_stream_source_dest(codec, 0x21, 0xc8, 0xc8);
9001 chipio_set_stream_channels(codec, 0x21, 0);
9002 chipio_set_control_param(codec, CONTROL_PARAM_NODE_ID, 0x09);
9003 chipio_set_control_param(codec, 0x20, 0x01);
9005 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
9007 chipio_set_stream_control(codec, 0x18, 0);
9008 chipio_set_stream_control(codec, 0x0c, 0);
9010 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
9011 snd_hda_codec_write(codec, 0x15, 0, 0x724, 0x83);
9012 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
9013 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
9014 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x00);
9015 ca0113_mmio_gpio_set(codec, 0, false);
9016 ca0113_mmio_gpio_set(codec, 1, false);
9017 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9019 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
9020 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
9023 static void zxr_exit_chip(struct hda_codec *codec)
9025 chipio_set_stream_control(codec, 0x03, 0);
9026 chipio_set_stream_control(codec, 0x04, 0);
9027 chipio_set_stream_control(codec, 0x14, 0);
9028 chipio_set_stream_control(codec, 0x0C, 0);
9030 chipio_set_conn_rate(codec, 0x41, SR_192_000);
9031 chipio_set_conn_rate(codec, 0x91, SR_192_000);
9033 chipio_write(codec, 0x18a020, 0x00000083);
9035 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
9036 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
9038 ca0132_clear_unsolicited(codec);
9039 sbz_set_pin_ctl_default(codec);
9040 snd_hda_codec_write(codec, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x00);
9042 ca0113_mmio_gpio_set(codec, 5, false);
9043 ca0113_mmio_gpio_set(codec, 2, false);
9044 ca0113_mmio_gpio_set(codec, 3, false);
9045 ca0113_mmio_gpio_set(codec, 0, false);
9046 ca0113_mmio_gpio_set(codec, 4, true);
9047 ca0113_mmio_gpio_set(codec, 0, true);
9048 ca0113_mmio_gpio_set(codec, 5, true);
9049 ca0113_mmio_gpio_set(codec, 2, false);
9050 ca0113_mmio_gpio_set(codec, 3, false);
9053 static void ca0132_exit_chip(struct hda_codec *codec)
9055 /* put any chip cleanup stuffs here. */
9057 if (dspload_is_loaded(codec))
9062 * This fixes a problem that was hard to reproduce. Very rarely, I would
9063 * boot up, and there would be no sound, but the DSP indicated it had loaded
9064 * properly. I did a few memory dumps to see if anything was different, and
9065 * there were a few areas of memory uninitialized with a1a2a3a4. This function
9066 * checks if those areas are uninitialized, and if they are, it'll attempt to
9067 * reload the card 3 times. Usually it fixes by the second.
9069 static void sbz_dsp_startup_check(struct hda_codec *codec)
9071 struct ca0132_spec *spec = codec->spec;
9072 unsigned int dsp_data_check[4];
9073 unsigned int cur_address = 0x390;
9075 unsigned int failure = 0;
9076 unsigned int reload = 3;
9078 if (spec->startup_check_entered)
9081 spec->startup_check_entered = true;
9083 for (i = 0; i < 4; i++) {
9084 chipio_read(codec, cur_address, &dsp_data_check[i]);
9087 for (i = 0; i < 4; i++) {
9088 if (dsp_data_check[i] == 0xa1a2a3a4)
9092 codec_dbg(codec, "Startup Check: %d ", failure);
9094 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
9096 * While the failure condition is true, and we haven't reached our
9097 * three reload limit, continue trying to reload the driver and
9100 while (failure && (reload != 0)) {
9101 codec_info(codec, "Reloading... Tries left: %d", reload);
9102 sbz_exit_chip(codec);
9103 spec->dsp_state = DSP_DOWNLOAD_INIT;
9104 codec->patch_ops.init(codec);
9106 for (i = 0; i < 4; i++) {
9107 chipio_read(codec, cur_address, &dsp_data_check[i]);
9110 for (i = 0; i < 4; i++) {
9111 if (dsp_data_check[i] == 0xa1a2a3a4)
9117 if (!failure && reload < 3)
9118 codec_info(codec, "DSP fixed.");
9123 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
9127 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
9128 * extra precision for decibel values. If you had the dB value in floating point
9129 * you would take the value after the decimal point, multiply by 64, and divide
9130 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
9131 * implement fixed point or floating point dB volumes. For now, I'll set them
9132 * to 0 just incase a value has lingered from a boot into Windows.
9134 static void ca0132_alt_vol_setup(struct hda_codec *codec)
9136 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
9137 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
9138 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
9139 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
9140 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
9141 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
9142 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
9143 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
9147 * Extra commands that don't really fit anywhere else.
9149 static void sbz_pre_dsp_setup(struct hda_codec *codec)
9151 struct ca0132_spec *spec = codec->spec;
9153 writel(0x00820680, spec->mem_base + 0x01C);
9154 writel(0x00820680, spec->mem_base + 0x01C);
9156 chipio_write(codec, 0x18b0a4, 0x000000c2);
9158 snd_hda_codec_write(codec, 0x11, 0,
9159 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
9162 static void r3d_pre_dsp_setup(struct hda_codec *codec)
9164 chipio_write(codec, 0x18b0a4, 0x000000c2);
9166 chipio_8051_write_exram(codec, 0x1c1e, 0x5b);
9168 snd_hda_codec_write(codec, 0x11, 0,
9169 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
9172 static void r3di_pre_dsp_setup(struct hda_codec *codec)
9174 chipio_write(codec, 0x18b0a4, 0x000000c2);
9176 chipio_8051_write_exram(codec, 0x1c1e, 0x5b);
9177 chipio_8051_write_exram(codec, 0x1920, 0x00);
9178 chipio_8051_write_exram(codec, 0x1921, 0x40);
9180 snd_hda_codec_write(codec, 0x11, 0,
9181 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
9185 * The ZxR seems to use alternative DAC's for the surround channels, which
9186 * require PLL PMU setup for the clock rate, I'm guessing. Without setting
9187 * this up, we get no audio out of the surround jacks.
9189 static void zxr_pre_dsp_setup(struct hda_codec *codec)
9191 static const unsigned int addr[] = { 0x43, 0x40, 0x41, 0x42, 0x45 };
9192 static const unsigned int data[] = { 0x08, 0x0c, 0x0b, 0x07, 0x0d };
9195 chipio_write(codec, 0x189000, 0x0001f100);
9197 chipio_write(codec, 0x18900c, 0x0001f100);
9201 * This writes a RET instruction at the entry point of the function at
9202 * 0xfa92 in exram. This function seems to have something to do with
9203 * ASI. Might be some way to prevent the card from reconfiguring the
9206 chipio_8051_write_exram(codec, 0xfa92, 0x22);
9208 chipio_8051_write_pll_pmu(codec, 0x51, 0x98);
9210 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x82);
9211 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 3);
9213 chipio_write(codec, 0x18902c, 0x00000000);
9215 chipio_write(codec, 0x18902c, 0x00000003);
9218 for (i = 0; i < ARRAY_SIZE(addr); i++)
9219 chipio_8051_write_pll_pmu(codec, addr[i], data[i]);
9223 * These are sent before the DSP is downloaded. Not sure
9224 * what they do, or if they're necessary. Could possibly
9225 * be removed. Figure they're better to leave in.
9227 static const unsigned int ca0113_mmio_init_address_sbz[] = {
9228 0x400, 0x408, 0x40c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c,
9229 0xc0c, 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04
9232 static const unsigned int ca0113_mmio_init_data_sbz[] = {
9233 0x00000030, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9234 0x00000003, 0x000000c1, 0x000000f1, 0x00000001, 0x000000c7,
9235 0x000000c1, 0x00000080
9238 static const unsigned int ca0113_mmio_init_data_zxr[] = {
9239 0x00000030, 0x00000000, 0x00000000, 0x00000003, 0x00000003,
9240 0x00000003, 0x00000001, 0x000000f1, 0x00000001, 0x000000c7,
9241 0x000000c1, 0x00000080
9244 static const unsigned int ca0113_mmio_init_address_ae5[] = {
9245 0x400, 0x42c, 0x46c, 0x4ac, 0x4ec, 0x43c, 0x47c, 0x4bc, 0x4fc, 0x408,
9246 0x100, 0x410, 0x40c, 0x100, 0x100, 0x830, 0x86c, 0x800, 0x86c, 0x800,
9247 0x804, 0x20c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c, 0xc0c,
9248 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04, 0x01c
9251 static const unsigned int ca0113_mmio_init_data_ae5[] = {
9252 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
9253 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
9254 0x00000600, 0x00000014, 0x00000001, 0x0000060f, 0x0000070f,
9255 0x00000aff, 0x00000000, 0x0000006b, 0x00000001, 0x0000006b,
9256 0x00000057, 0x00800000, 0x00880680, 0x00000080, 0x00000030,
9257 0x00000000, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9258 0x00000001, 0x000000f1, 0x00000001, 0x000000c7, 0x000000c1,
9259 0x00000080, 0x00880680
9262 static void ca0132_mmio_init_sbz(struct hda_codec *codec)
9264 struct ca0132_spec *spec = codec->spec;
9265 unsigned int tmp[2], i, count, cur_addr;
9266 const unsigned int *addr, *data;
9268 addr = ca0113_mmio_init_address_sbz;
9269 for (i = 0; i < 3; i++)
9270 writel(0x00000000, spec->mem_base + addr[i]);
9273 switch (ca0132_quirk(spec)) {
9275 tmp[0] = 0x00880480;
9276 tmp[1] = 0x00000080;
9279 tmp[0] = 0x00820680;
9280 tmp[1] = 0x00000083;
9283 tmp[0] = 0x00880680;
9284 tmp[1] = 0x00000083;
9287 tmp[0] = 0x00000000;
9288 tmp[1] = 0x00000000;
9292 for (i = 0; i < 2; i++)
9293 writel(tmp[i], spec->mem_base + addr[cur_addr + i]);
9297 switch (ca0132_quirk(spec)) {
9299 count = ARRAY_SIZE(ca0113_mmio_init_data_zxr);
9300 data = ca0113_mmio_init_data_zxr;
9303 count = ARRAY_SIZE(ca0113_mmio_init_data_sbz);
9304 data = ca0113_mmio_init_data_sbz;
9308 for (i = 0; i < count; i++)
9309 writel(data[i], spec->mem_base + addr[cur_addr + i]);
9312 static void ca0132_mmio_init_ae5(struct hda_codec *codec)
9314 struct ca0132_spec *spec = codec->spec;
9315 const unsigned int *addr, *data;
9316 unsigned int i, count;
9318 addr = ca0113_mmio_init_address_ae5;
9319 data = ca0113_mmio_init_data_ae5;
9320 count = ARRAY_SIZE(ca0113_mmio_init_data_ae5);
9322 if (ca0132_quirk(spec) == QUIRK_AE7) {
9323 writel(0x00000680, spec->mem_base + 0x1c);
9324 writel(0x00880680, spec->mem_base + 0x1c);
9327 for (i = 0; i < count; i++) {
9329 * AE-7 shares all writes with the AE-5, except that it writes
9330 * a different value to 0x20c.
9332 if (i == 21 && ca0132_quirk(spec) == QUIRK_AE7) {
9333 writel(0x00800001, spec->mem_base + addr[i]);
9337 writel(data[i], spec->mem_base + addr[i]);
9340 if (ca0132_quirk(spec) == QUIRK_AE5)
9341 writel(0x00880680, spec->mem_base + 0x1c);
9344 static void ca0132_mmio_init(struct hda_codec *codec)
9346 struct ca0132_spec *spec = codec->spec;
9348 switch (ca0132_quirk(spec)) {
9352 ca0132_mmio_init_sbz(codec);
9355 ca0132_mmio_init_ae5(codec);
9362 static const unsigned int ca0132_ae5_register_set_addresses[] = {
9363 0x304, 0x304, 0x304, 0x304, 0x100, 0x304, 0x100, 0x304, 0x100, 0x304,
9364 0x100, 0x304, 0x86c, 0x800, 0x86c, 0x800, 0x804
9367 static const unsigned char ca0132_ae5_register_set_data[] = {
9368 0x0f, 0x0e, 0x1f, 0x0c, 0x3f, 0x08, 0x7f, 0x00, 0xff, 0x00, 0x6b,
9373 * This function writes to some SFR's, does some region2 writes, and then
9374 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
9377 static void ae5_register_set(struct hda_codec *codec)
9379 struct ca0132_spec *spec = codec->spec;
9380 unsigned int count = ARRAY_SIZE(ca0132_ae5_register_set_addresses);
9381 const unsigned int *addr = ca0132_ae5_register_set_addresses;
9382 const unsigned char *data = ca0132_ae5_register_set_data;
9383 unsigned int i, cur_addr;
9384 unsigned char tmp[3];
9386 if (ca0132_quirk(spec) == QUIRK_AE7)
9387 chipio_8051_write_pll_pmu(codec, 0x41, 0xc8);
9389 chipio_8051_write_direct(codec, 0x93, 0x10);
9390 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
9392 if (ca0132_quirk(spec) == QUIRK_AE7) {
9402 for (i = cur_addr = 0; i < 3; i++, cur_addr++)
9403 writeb(tmp[i], spec->mem_base + addr[cur_addr]);
9406 * First writes are in single bytes, final are in 4 bytes. So, we use
9407 * writeb, then writel.
9409 for (i = 0; cur_addr < 12; i++, cur_addr++)
9410 writeb(data[i], spec->mem_base + addr[cur_addr]);
9412 for (; cur_addr < count; i++, cur_addr++)
9413 writel(data[i], spec->mem_base + addr[cur_addr]);
9415 writel(0x00800001, spec->mem_base + 0x20c);
9417 if (ca0132_quirk(spec) == QUIRK_AE7) {
9418 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
9419 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
9421 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
9424 chipio_8051_write_direct(codec, 0x90, 0x00);
9425 chipio_8051_write_direct(codec, 0x90, 0x10);
9427 if (ca0132_quirk(spec) == QUIRK_AE5)
9428 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
9432 * Extra init functions for alternative ca0132 codecs. Done
9433 * here so they don't clutter up the main ca0132_init function
9434 * anymore than they have to.
9436 static void ca0132_alt_init(struct hda_codec *codec)
9438 struct ca0132_spec *spec = codec->spec;
9440 ca0132_alt_vol_setup(codec);
9442 switch (ca0132_quirk(spec)) {
9444 codec_dbg(codec, "SBZ alt_init");
9445 ca0132_gpio_init(codec);
9446 sbz_pre_dsp_setup(codec);
9447 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9448 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9451 codec_dbg(codec, "R3DI alt_init");
9452 ca0132_gpio_init(codec);
9453 ca0132_gpio_setup(codec);
9454 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
9455 r3di_pre_dsp_setup(codec);
9456 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9457 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
9460 r3d_pre_dsp_setup(codec);
9461 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9462 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9465 ca0132_gpio_init(codec);
9466 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9467 chipio_write(codec, 0x18b030, 0x00000020);
9468 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9469 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9470 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9473 ca0132_gpio_init(codec);
9474 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9475 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9476 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9477 chipio_write(codec, 0x18b008, 0x000000f8);
9478 chipio_write(codec, 0x18b008, 0x000000f0);
9479 chipio_write(codec, 0x18b030, 0x00000020);
9480 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9483 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9484 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9485 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9486 zxr_pre_dsp_setup(codec);
9493 static int ca0132_init(struct hda_codec *codec)
9495 struct ca0132_spec *spec = codec->spec;
9496 struct auto_pin_cfg *cfg = &spec->autocfg;
9501 * If the DSP is already downloaded, and init has been entered again,
9502 * there's only two reasons for it. One, the codec has awaken from a
9503 * suspended state, and in that case dspload_is_loaded will return
9504 * false, and the init will be ran again. The other reason it gets
9505 * re entered is on startup for some reason it triggers a suspend and
9506 * resume state. In this case, it will check if the DSP is downloaded,
9507 * and not run the init function again. For codecs using alt_functions,
9508 * it will check if the DSP is loaded properly.
9510 if (spec->dsp_state == DSP_DOWNLOADED) {
9511 dsp_loaded = dspload_is_loaded(codec);
9513 spec->dsp_reload = true;
9514 spec->dsp_state = DSP_DOWNLOAD_INIT;
9516 if (ca0132_quirk(spec) == QUIRK_SBZ)
9517 sbz_dsp_startup_check(codec);
9522 if (spec->dsp_state != DSP_DOWNLOAD_FAILED)
9523 spec->dsp_state = DSP_DOWNLOAD_INIT;
9524 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
9526 if (ca0132_use_pci_mmio(spec))
9527 ca0132_mmio_init(codec);
9529 snd_hda_power_up_pm(codec);
9531 if (ca0132_quirk(spec) == QUIRK_AE5 || ca0132_quirk(spec) == QUIRK_AE7)
9532 ae5_register_set(codec);
9534 ca0132_init_params(codec);
9535 ca0132_init_flags(codec);
9537 snd_hda_sequence_write(codec, spec->base_init_verbs);
9539 if (ca0132_use_alt_functions(spec))
9540 ca0132_alt_init(codec);
9542 ca0132_download_dsp(codec);
9544 ca0132_refresh_widget_caps(codec);
9546 switch (ca0132_quirk(spec)) {
9549 r3d_setup_defaults(codec);
9553 sbz_setup_defaults(codec);
9556 ae5_setup_defaults(codec);
9559 ae7_setup_defaults(codec);
9562 ca0132_setup_defaults(codec);
9563 ca0132_init_analog_mic2(codec);
9564 ca0132_init_dmic(codec);
9568 for (i = 0; i < spec->num_outputs; i++)
9569 init_output(codec, spec->out_pins[i], spec->dacs[0]);
9571 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9573 for (i = 0; i < spec->num_inputs; i++)
9574 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9576 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9578 if (!ca0132_use_alt_functions(spec)) {
9579 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9580 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9581 VENDOR_CHIPIO_PARAM_EX_ID_SET, 0x0D);
9582 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9583 VENDOR_CHIPIO_PARAM_EX_VALUE_SET, 0x20);
9586 if (ca0132_quirk(spec) == QUIRK_SBZ)
9587 ca0132_gpio_setup(codec);
9589 snd_hda_sequence_write(codec, spec->spec_init_verbs);
9590 if (ca0132_use_alt_functions(spec)) {
9591 ca0132_alt_select_out(codec);
9592 ca0132_alt_select_in(codec);
9594 ca0132_select_out(codec);
9595 ca0132_select_mic(codec);
9598 snd_hda_jack_report_sync(codec);
9601 * Re set the PlayEnhancement switch on a resume event, because the
9602 * controls will not be reloaded.
9604 if (spec->dsp_reload) {
9605 spec->dsp_reload = false;
9606 ca0132_pe_switch_set(codec);
9609 snd_hda_power_down_pm(codec);
9614 static int dbpro_init(struct hda_codec *codec)
9616 struct ca0132_spec *spec = codec->spec;
9617 struct auto_pin_cfg *cfg = &spec->autocfg;
9620 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9621 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9623 for (i = 0; i < spec->num_inputs; i++)
9624 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9629 static void ca0132_free(struct hda_codec *codec)
9631 struct ca0132_spec *spec = codec->spec;
9633 cancel_delayed_work_sync(&spec->unsol_hp_work);
9634 snd_hda_power_up(codec);
9635 switch (ca0132_quirk(spec)) {
9637 sbz_exit_chip(codec);
9640 zxr_exit_chip(codec);
9643 r3d_exit_chip(codec);
9646 ae5_exit_chip(codec);
9649 ae7_exit_chip(codec);
9652 r3di_gpio_shutdown(codec);
9658 snd_hda_sequence_write(codec, spec->base_exit_verbs);
9659 ca0132_exit_chip(codec);
9661 snd_hda_power_down(codec);
9664 pci_iounmap(codec->bus->pci, spec->mem_base);
9666 kfree(spec->spec_init_verbs);
9670 static void dbpro_free(struct hda_codec *codec)
9672 struct ca0132_spec *spec = codec->spec;
9674 zxr_dbpro_power_state_shutdown(codec);
9676 kfree(spec->spec_init_verbs);
9681 static int ca0132_suspend(struct hda_codec *codec)
9683 struct ca0132_spec *spec = codec->spec;
9685 cancel_delayed_work_sync(&spec->unsol_hp_work);
9690 static const struct hda_codec_ops ca0132_patch_ops = {
9691 .build_controls = ca0132_build_controls,
9692 .build_pcms = ca0132_build_pcms,
9693 .init = ca0132_init,
9694 .free = ca0132_free,
9695 .unsol_event = snd_hda_jack_unsol_event,
9697 .suspend = ca0132_suspend,
9701 static const struct hda_codec_ops dbpro_patch_ops = {
9702 .build_controls = dbpro_build_controls,
9703 .build_pcms = dbpro_build_pcms,
9708 static void ca0132_config(struct hda_codec *codec)
9710 struct ca0132_spec *spec = codec->spec;
9712 spec->dacs[0] = 0x2;
9713 spec->dacs[1] = 0x3;
9714 spec->dacs[2] = 0x4;
9716 spec->multiout.dac_nids = spec->dacs;
9717 spec->multiout.num_dacs = 3;
9719 if (!ca0132_use_alt_functions(spec))
9720 spec->multiout.max_channels = 2;
9722 spec->multiout.max_channels = 6;
9724 switch (ca0132_quirk(spec)) {
9725 case QUIRK_ALIENWARE:
9726 codec_dbg(codec, "%s: QUIRK_ALIENWARE applied.\n", __func__);
9727 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
9730 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
9731 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
9734 codec_dbg(codec, "%s: QUIRK_ZXR applied.\n", __func__);
9735 snd_hda_apply_pincfgs(codec, zxr_pincfgs);
9738 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
9739 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
9742 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
9743 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
9746 codec_dbg(codec, "%s: QUIRK_AE5 applied.\n", __func__);
9747 snd_hda_apply_pincfgs(codec, ae5_pincfgs);
9750 codec_dbg(codec, "%s: QUIRK_AE7 applied.\n", __func__);
9751 snd_hda_apply_pincfgs(codec, ae7_pincfgs);
9757 switch (ca0132_quirk(spec)) {
9758 case QUIRK_ALIENWARE:
9759 spec->num_outputs = 2;
9760 spec->out_pins[0] = 0x0b; /* speaker out */
9761 spec->out_pins[1] = 0x0f;
9762 spec->shared_out_nid = 0x2;
9763 spec->unsol_tag_hp = 0x0f;
9765 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
9766 spec->adcs[1] = 0x8; /* analog mic2 */
9767 spec->adcs[2] = 0xa; /* what u hear */
9769 spec->num_inputs = 3;
9770 spec->input_pins[0] = 0x12;
9771 spec->input_pins[1] = 0x11;
9772 spec->input_pins[2] = 0x13;
9773 spec->shared_mic_nid = 0x7;
9774 spec->unsol_tag_amic1 = 0x11;
9778 spec->num_outputs = 2;
9779 spec->out_pins[0] = 0x0B; /* Line out */
9780 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9781 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9782 spec->out_pins[3] = 0x11; /* Rear surround */
9783 spec->shared_out_nid = 0x2;
9784 spec->unsol_tag_hp = spec->out_pins[1];
9785 spec->unsol_tag_front_hp = spec->out_pins[2];
9787 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9788 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
9789 spec->adcs[2] = 0xa; /* what u hear */
9791 spec->num_inputs = 2;
9792 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9793 spec->input_pins[1] = 0x13; /* What U Hear */
9794 spec->shared_mic_nid = 0x7;
9795 spec->unsol_tag_amic1 = spec->input_pins[0];
9798 spec->dig_out = 0x05;
9799 spec->multiout.dig_out_nid = spec->dig_out;
9800 spec->dig_in = 0x09;
9803 spec->num_outputs = 2;
9804 spec->out_pins[0] = 0x0B; /* Line out */
9805 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9806 spec->out_pins[2] = 0x10; /* Center/LFE */
9807 spec->out_pins[3] = 0x11; /* Rear surround */
9808 spec->shared_out_nid = 0x2;
9809 spec->unsol_tag_hp = spec->out_pins[1];
9810 spec->unsol_tag_front_hp = spec->out_pins[2];
9812 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9813 spec->adcs[1] = 0x8; /* Not connected, no front mic */
9814 spec->adcs[2] = 0xa; /* what u hear */
9816 spec->num_inputs = 2;
9817 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9818 spec->input_pins[1] = 0x13; /* What U Hear */
9819 spec->shared_mic_nid = 0x7;
9820 spec->unsol_tag_amic1 = spec->input_pins[0];
9822 case QUIRK_ZXR_DBPRO:
9823 spec->adcs[0] = 0x8; /* ZxR DBPro Aux In */
9825 spec->num_inputs = 1;
9826 spec->input_pins[0] = 0x11; /* RCA Line-in */
9828 spec->dig_out = 0x05;
9829 spec->multiout.dig_out_nid = spec->dig_out;
9831 spec->dig_in = 0x09;
9835 spec->num_outputs = 2;
9836 spec->out_pins[0] = 0x0B; /* Line out */
9837 spec->out_pins[1] = 0x11; /* Rear headphone out */
9838 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9839 spec->out_pins[3] = 0x0F; /* Rear surround */
9840 spec->shared_out_nid = 0x2;
9841 spec->unsol_tag_hp = spec->out_pins[1];
9842 spec->unsol_tag_front_hp = spec->out_pins[2];
9844 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9845 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
9846 spec->adcs[2] = 0xa; /* what u hear */
9848 spec->num_inputs = 2;
9849 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9850 spec->input_pins[1] = 0x13; /* What U Hear */
9851 spec->shared_mic_nid = 0x7;
9852 spec->unsol_tag_amic1 = spec->input_pins[0];
9855 spec->dig_out = 0x05;
9856 spec->multiout.dig_out_nid = spec->dig_out;
9859 spec->num_outputs = 2;
9860 spec->out_pins[0] = 0x0B; /* Line out */
9861 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9862 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9863 spec->out_pins[3] = 0x11; /* Rear surround */
9864 spec->shared_out_nid = 0x2;
9865 spec->unsol_tag_hp = spec->out_pins[1];
9866 spec->unsol_tag_front_hp = spec->out_pins[2];
9868 spec->adcs[0] = 0x07; /* Rear Mic / Line-in */
9869 spec->adcs[1] = 0x08; /* Front Mic, but only if no DSP */
9870 spec->adcs[2] = 0x0a; /* what u hear */
9872 spec->num_inputs = 2;
9873 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9874 spec->input_pins[1] = 0x13; /* What U Hear */
9875 spec->shared_mic_nid = 0x7;
9876 spec->unsol_tag_amic1 = spec->input_pins[0];
9879 spec->dig_out = 0x05;
9880 spec->multiout.dig_out_nid = spec->dig_out;
9883 spec->num_outputs = 2;
9884 spec->out_pins[0] = 0x0b; /* speaker out */
9885 spec->out_pins[1] = 0x10; /* headphone out */
9886 spec->shared_out_nid = 0x2;
9887 spec->unsol_tag_hp = spec->out_pins[1];
9889 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
9890 spec->adcs[1] = 0x8; /* analog mic2 */
9891 spec->adcs[2] = 0xa; /* what u hear */
9893 spec->num_inputs = 3;
9894 spec->input_pins[0] = 0x12;
9895 spec->input_pins[1] = 0x11;
9896 spec->input_pins[2] = 0x13;
9897 spec->shared_mic_nid = 0x7;
9898 spec->unsol_tag_amic1 = spec->input_pins[0];
9901 spec->dig_out = 0x05;
9902 spec->multiout.dig_out_nid = spec->dig_out;
9903 spec->dig_in = 0x09;
9908 static int ca0132_prepare_verbs(struct hda_codec *codec)
9910 /* Verbs + terminator (an empty element) */
9911 #define NUM_SPEC_VERBS 2
9912 struct ca0132_spec *spec = codec->spec;
9914 spec->chip_init_verbs = ca0132_init_verbs0;
9916 * Since desktop cards use pci_mmio, this can be used to determine
9917 * whether or not to use these verbs instead of a separate bool.
9919 if (ca0132_use_pci_mmio(spec))
9920 spec->desktop_init_verbs = ca0132_init_verbs1;
9921 spec->spec_init_verbs = kcalloc(NUM_SPEC_VERBS,
9922 sizeof(struct hda_verb),
9924 if (!spec->spec_init_verbs)
9928 spec->spec_init_verbs[0].nid = 0x0b;
9929 spec->spec_init_verbs[0].param = 0x78D;
9930 spec->spec_init_verbs[0].verb = 0x00;
9932 /* Previously commented configuration */
9934 spec->spec_init_verbs[2].nid = 0x0b;
9935 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
9936 spec->spec_init_verbs[2].verb = 0x02;
9938 spec->spec_init_verbs[3].nid = 0x10;
9939 spec->spec_init_verbs[3].param = 0x78D;
9940 spec->spec_init_verbs[3].verb = 0x02;
9942 spec->spec_init_verbs[4].nid = 0x10;
9943 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
9944 spec->spec_init_verbs[4].verb = 0x02;
9947 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
9952 * The Sound Blaster ZxR shares the same PCI subsystem ID as some regular
9953 * Sound Blaster Z cards. However, they have different HDA codec subsystem
9954 * ID's. So, we check for the ZxR's subsystem ID, as well as the DBPro
9955 * daughter boards ID.
9957 static void sbz_detect_quirk(struct hda_codec *codec)
9959 struct ca0132_spec *spec = codec->spec;
9961 switch (codec->core.subsystem_id) {
9963 spec->quirk = QUIRK_ZXR;
9966 spec->quirk = QUIRK_ZXR_DBPRO;
9969 spec->quirk = QUIRK_SBZ;
9974 static int patch_ca0132(struct hda_codec *codec)
9976 struct ca0132_spec *spec;
9978 const struct snd_pci_quirk *quirk;
9980 codec_dbg(codec, "patch_ca0132\n");
9982 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9986 spec->codec = codec;
9988 /* Detect codec quirk */
9989 quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks);
9991 spec->quirk = quirk->value;
9993 spec->quirk = QUIRK_NONE;
9994 if (ca0132_quirk(spec) == QUIRK_SBZ)
9995 sbz_detect_quirk(codec);
9997 if (ca0132_quirk(spec) == QUIRK_ZXR_DBPRO)
9998 codec->patch_ops = dbpro_patch_ops;
10000 codec->patch_ops = ca0132_patch_ops;
10002 codec->pcm_format_first = 1;
10003 codec->no_sticky_stream = 1;
10006 spec->dsp_state = DSP_DOWNLOAD_INIT;
10007 spec->num_mixers = 1;
10009 /* Set which mixers each quirk uses. */
10010 switch (ca0132_quirk(spec)) {
10012 spec->mixers[0] = desktop_mixer;
10013 snd_hda_codec_set_name(codec, "Sound Blaster Z");
10016 spec->mixers[0] = desktop_mixer;
10017 snd_hda_codec_set_name(codec, "Sound Blaster ZxR");
10019 case QUIRK_ZXR_DBPRO:
10022 spec->mixers[0] = desktop_mixer;
10023 snd_hda_codec_set_name(codec, "Recon3D");
10026 spec->mixers[0] = r3di_mixer;
10027 snd_hda_codec_set_name(codec, "Recon3Di");
10030 spec->mixers[0] = desktop_mixer;
10031 snd_hda_codec_set_name(codec, "Sound BlasterX AE-5");
10034 spec->mixers[0] = desktop_mixer;
10035 snd_hda_codec_set_name(codec, "Sound Blaster AE-7");
10038 spec->mixers[0] = ca0132_mixer;
10042 /* Setup whether or not to use alt functions/controls/pci_mmio */
10043 switch (ca0132_quirk(spec)) {
10049 spec->use_alt_controls = true;
10050 spec->use_alt_functions = true;
10051 spec->use_pci_mmio = true;
10054 spec->use_alt_controls = true;
10055 spec->use_alt_functions = true;
10056 spec->use_pci_mmio = false;
10059 spec->use_alt_controls = false;
10060 spec->use_alt_functions = false;
10061 spec->use_pci_mmio = false;
10066 if (spec->use_pci_mmio) {
10067 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
10068 if (spec->mem_base == NULL) {
10069 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
10070 spec->quirk = QUIRK_NONE;
10075 spec->base_init_verbs = ca0132_base_init_verbs;
10076 spec->base_exit_verbs = ca0132_base_exit_verbs;
10078 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
10080 ca0132_init_chip(codec);
10082 ca0132_config(codec);
10084 err = ca0132_prepare_verbs(codec);
10088 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
10092 ca0132_setup_unsol(codec);
10097 ca0132_free(codec);
10104 static const struct hda_device_id snd_hda_id_ca0132[] = {
10105 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132),
10106 {} /* terminator */
10108 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132);
10110 MODULE_LICENSE("GPL");
10111 MODULE_DESCRIPTION("Creative Sound Core3D codec");
10113 static struct hda_codec_driver ca0132_driver = {
10114 .id = snd_hda_id_ca0132,
10117 module_hda_codec_driver(ca0132_driver);