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 "ctefx.bin"
74 #define DESKTOP_EFX_FILE "ctefx-desktop.bin"
75 #define R3DI_EFX_FILE "ctefx-r3di.bin"
77 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
78 MODULE_FIRMWARE(EFX_FILE);
79 MODULE_FIRMWARE(DESKTOP_EFX_FILE);
80 MODULE_FIRMWARE(R3DI_EFX_FILE);
83 static const char *const dirstr[2] = { "Playback", "Capture" };
85 #define NUM_OF_OUTPUTS 2
86 static const char *const out_type_str[2] = { "Speakers", "Headphone" };
97 /* Strings for Input Source Enum Control */
98 static const char *const in_src_str[3] = {"Rear Mic", "Line", "Front Mic" };
99 #define IN_SRC_NUM_OF_INPUTS 3
107 #define VNODE_START_NID 0x80
108 VNID_SPK = VNODE_START_NID, /* Speaker vnid */
115 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
117 #define EFFECT_START_NID 0x90
118 #define OUT_EFFECT_START_NID EFFECT_START_NID
119 SURROUND = OUT_EFFECT_START_NID,
126 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
128 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
129 ECHO_CANCELLATION = IN_EFFECT_START_NID,
134 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
136 VOICEFX = IN_EFFECT_END_NID,
146 AE5_HEADPHONE_GAIN_ENUM,
147 AE5_SOUND_FILTER_ENUM,
149 SPEAKER_CHANNEL_CFG_ENUM,
150 SPEAKER_FULL_RANGE_FRONT,
151 SPEAKER_FULL_RANGE_REAR,
153 BASS_REDIRECTION_XOVER,
154 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
157 /* Effects values size*/
158 #define EFFECT_VALS_MAX_COUNT 12
161 * Default values for the effect slider controls, they are in order of their
162 * effect NID's. Surround, Crystalizer, Dialog Plus, Smart Volume, and then
165 static const unsigned int effect_slider_defaults[] = {67, 65, 50, 74, 50};
166 /* Amount of effect level sliders for ca0132_alt controls. */
167 #define EFFECT_LEVEL_SLIDERS 5
169 /* Latency introduced by DSP blocks in milliseconds. */
170 #define DSP_CAPTURE_INIT_LATENCY 0
171 #define DSP_CRYSTAL_VOICE_LATENCY 124
172 #define DSP_PLAYBACK_INIT_LATENCY 13
173 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
174 #define DSP_SPEAKER_OUT_LATENCY 7
177 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
179 int mid; /*effect module ID*/
180 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
181 int direct; /* 0:output; 1:input*/
182 int params; /* number of default non-on/off params */
183 /*effect default values, 1st is on/off. */
184 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
187 #define EFX_DIR_OUT 0
190 static const struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
191 { .name = "Surround",
195 .direct = EFX_DIR_OUT,
197 .def_vals = {0x3F800000, 0x3F2B851F}
199 { .name = "Crystalizer",
203 .direct = EFX_DIR_OUT,
205 .def_vals = {0x3F800000, 0x3F266666}
207 { .name = "Dialog Plus",
211 .direct = EFX_DIR_OUT,
213 .def_vals = {0x00000000, 0x3F000000}
215 { .name = "Smart Volume",
219 .direct = EFX_DIR_OUT,
221 .def_vals = {0x3F800000, 0x3F3D70A4, 0x00000000}
226 .reqs = {24, 23, 25},
227 .direct = EFX_DIR_OUT,
229 .def_vals = {0x3F800000, 0x42A00000, 0x3F000000}
231 { .name = "Equalizer",
234 .reqs = {9, 10, 11, 12, 13, 14,
235 15, 16, 17, 18, 19, 20},
236 .direct = EFX_DIR_OUT,
238 .def_vals = {0x00000000, 0x00000000, 0x00000000, 0x00000000,
239 0x00000000, 0x00000000, 0x00000000, 0x00000000,
240 0x00000000, 0x00000000, 0x00000000, 0x00000000}
242 { .name = "Echo Cancellation",
243 .nid = ECHO_CANCELLATION,
245 .reqs = {0, 1, 2, 3},
246 .direct = EFX_DIR_IN,
248 .def_vals = {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
250 { .name = "Voice Focus",
253 .reqs = {6, 7, 8, 9},
254 .direct = EFX_DIR_IN,
256 .def_vals = {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
262 .direct = EFX_DIR_IN,
264 .def_vals = {0x00000000, 0x3F3D70A4}
266 { .name = "Noise Reduction",
267 .nid = NOISE_REDUCTION,
270 .direct = EFX_DIR_IN,
272 .def_vals = {0x3F800000, 0x3F000000}
277 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18},
278 .direct = EFX_DIR_IN,
280 .def_vals = {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
281 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
286 /* Tuning controls */
287 #ifdef ENABLE_TUNING_CONTROLS
290 #define TUNING_CTL_START_NID 0xC0
291 WEDGE_ANGLE = TUNING_CTL_START_NID,
304 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
307 struct ct_tuning_ctl {
308 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
309 hda_nid_t parent_nid;
311 int mid; /*effect module ID*/
312 int req; /*effect module request*/
313 int direct; /* 0:output; 1:input*/
314 unsigned int def_val;/*effect default values*/
317 static const struct ct_tuning_ctl ca0132_tuning_ctls[] = {
318 { .name = "Wedge Angle",
319 .parent_nid = VOICE_FOCUS,
323 .direct = EFX_DIR_IN,
324 .def_val = 0x41F00000
326 { .name = "SVM Level",
327 .parent_nid = MIC_SVM,
331 .direct = EFX_DIR_IN,
332 .def_val = 0x3F3D70A4
334 { .name = "EQ Band0",
335 .parent_nid = EQUALIZER,
336 .nid = EQUALIZER_BAND_0,
339 .direct = EFX_DIR_OUT,
340 .def_val = 0x00000000
342 { .name = "EQ Band1",
343 .parent_nid = EQUALIZER,
344 .nid = EQUALIZER_BAND_1,
347 .direct = EFX_DIR_OUT,
348 .def_val = 0x00000000
350 { .name = "EQ Band2",
351 .parent_nid = EQUALIZER,
352 .nid = EQUALIZER_BAND_2,
355 .direct = EFX_DIR_OUT,
356 .def_val = 0x00000000
358 { .name = "EQ Band3",
359 .parent_nid = EQUALIZER,
360 .nid = EQUALIZER_BAND_3,
363 .direct = EFX_DIR_OUT,
364 .def_val = 0x00000000
366 { .name = "EQ Band4",
367 .parent_nid = EQUALIZER,
368 .nid = EQUALIZER_BAND_4,
371 .direct = EFX_DIR_OUT,
372 .def_val = 0x00000000
374 { .name = "EQ Band5",
375 .parent_nid = EQUALIZER,
376 .nid = EQUALIZER_BAND_5,
379 .direct = EFX_DIR_OUT,
380 .def_val = 0x00000000
382 { .name = "EQ Band6",
383 .parent_nid = EQUALIZER,
384 .nid = EQUALIZER_BAND_6,
387 .direct = EFX_DIR_OUT,
388 .def_val = 0x00000000
390 { .name = "EQ Band7",
391 .parent_nid = EQUALIZER,
392 .nid = EQUALIZER_BAND_7,
395 .direct = EFX_DIR_OUT,
396 .def_val = 0x00000000
398 { .name = "EQ Band8",
399 .parent_nid = EQUALIZER,
400 .nid = EQUALIZER_BAND_8,
403 .direct = EFX_DIR_OUT,
404 .def_val = 0x00000000
406 { .name = "EQ Band9",
407 .parent_nid = EQUALIZER,
408 .nid = EQUALIZER_BAND_9,
411 .direct = EFX_DIR_OUT,
412 .def_val = 0x00000000
417 /* Voice FX Presets */
418 #define VOICEFX_MAX_PARAM_COUNT 9
424 int reqs[VOICEFX_MAX_PARAM_COUNT]; /*effect module request*/
427 struct ct_voicefx_preset {
428 char *name; /*preset name*/
429 unsigned int vals[VOICEFX_MAX_PARAM_COUNT];
432 static const struct ct_voicefx ca0132_voicefx = {
433 .name = "VoiceFX Capture Switch",
436 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18}
439 static const struct ct_voicefx_preset ca0132_voicefx_presets[] = {
441 .vals = { 0x00000000, 0x43C80000, 0x44AF0000,
442 0x44FA0000, 0x3F800000, 0x3F800000,
443 0x3F800000, 0x00000000, 0x00000000 }
445 { .name = "Female2Male",
446 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
447 0x44FA0000, 0x3F19999A, 0x3F866666,
448 0x3F800000, 0x00000000, 0x00000000 }
450 { .name = "Male2Female",
451 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
452 0x450AC000, 0x4017AE14, 0x3F6B851F,
453 0x3F800000, 0x00000000, 0x00000000 }
455 { .name = "ScrappyKid",
456 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
457 0x44FA0000, 0x40400000, 0x3F28F5C3,
458 0x3F800000, 0x00000000, 0x00000000 }
461 .vals = { 0x3F800000, 0x44324000, 0x44BB8000,
462 0x44E10000, 0x3FB33333, 0x3FB9999A,
463 0x3F800000, 0x3E3A2E43, 0x00000000 }
466 .vals = { 0x3F800000, 0x43EA0000, 0x44A52000,
467 0x45098000, 0x3F266666, 0x3FC00000,
468 0x3F800000, 0x00000000, 0x00000000 }
471 .vals = { 0x3F800000, 0x43C70000, 0x44AE6000,
472 0x45193000, 0x3F8E147B, 0x3F75C28F,
473 0x3F800000, 0x00000000, 0x00000000 }
476 .vals = { 0x3F800000, 0x43930000, 0x44BEE000,
477 0x45007000, 0x3F451EB8, 0x3F7851EC,
478 0x3F800000, 0x00000000, 0x00000000 }
480 { .name = "AlienBrute",
481 .vals = { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
482 0x451F6000, 0x3F266666, 0x3FA7D945,
483 0x3F800000, 0x3CF5C28F, 0x00000000 }
486 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
487 0x44FA0000, 0x3FB2718B, 0x3F800000,
488 0xBC07010E, 0x00000000, 0x00000000 }
491 .vals = { 0x3F800000, 0x43C20000, 0x44906000,
492 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
493 0x3F0A3D71, 0x00000000, 0x00000000 }
496 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
497 0x44FA0000, 0x3F800000, 0x3F800000,
498 0x3E4CCCCD, 0x00000000, 0x00000000 }
500 { .name = "DeepVoice",
501 .vals = { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
502 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
503 0x3F800000, 0x00000000, 0x00000000 }
505 { .name = "Munchkin",
506 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
507 0x44FA0000, 0x3F800000, 0x3F1A043C,
508 0x3F800000, 0x00000000, 0x00000000 }
512 /* ca0132 EQ presets, taken from Windows Sound Blaster Z Driver */
514 #define EQ_PRESET_MAX_PARAM_COUNT 11
520 int reqs[EQ_PRESET_MAX_PARAM_COUNT]; /*effect module request*/
523 struct ct_eq_preset {
524 char *name; /*preset name*/
525 unsigned int vals[EQ_PRESET_MAX_PARAM_COUNT];
528 static const struct ct_eq ca0132_alt_eq_enum = {
529 .name = "FX: Equalizer Preset Switch",
530 .nid = EQ_PRESET_ENUM,
532 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
536 static const struct ct_eq_preset ca0132_alt_eq_presets[] = {
538 .vals = { 0x00000000, 0x00000000, 0x00000000,
539 0x00000000, 0x00000000, 0x00000000,
540 0x00000000, 0x00000000, 0x00000000,
541 0x00000000, 0x00000000 }
543 { .name = "Acoustic",
544 .vals = { 0x00000000, 0x00000000, 0x3F8CCCCD,
545 0x40000000, 0x00000000, 0x00000000,
546 0x00000000, 0x00000000, 0x40000000,
547 0x40000000, 0x40000000 }
549 { .name = "Classical",
550 .vals = { 0x00000000, 0x00000000, 0x40C00000,
551 0x40C00000, 0x40466666, 0x00000000,
552 0x00000000, 0x00000000, 0x00000000,
553 0x40466666, 0x40466666 }
556 .vals = { 0x00000000, 0xBF99999A, 0x00000000,
557 0x3FA66666, 0x3FA66666, 0x3F8CCCCD,
558 0x00000000, 0x00000000, 0x40000000,
559 0x40466666, 0x40800000 }
562 .vals = { 0x00000000, 0xBF99999A, 0x40000000,
563 0x40466666, 0x40866666, 0xBF99999A,
564 0xBF99999A, 0x00000000, 0x00000000,
565 0x40800000, 0x40800000 }
568 .vals = { 0x00000000, 0x00000000, 0x00000000,
569 0x3F8CCCCD, 0x40800000, 0x40800000,
570 0x40800000, 0x00000000, 0x3F8CCCCD,
571 0x40466666, 0x40466666 }
574 .vals = { 0x00000000, 0x00000000, 0x40000000,
575 0x40000000, 0x00000000, 0x00000000,
576 0x00000000, 0x3F8CCCCD, 0x40000000,
577 0x40000000, 0x40000000 }
580 .vals = { 0x00000000, 0xBFCCCCCD, 0x00000000,
581 0x40000000, 0x40000000, 0x00000000,
582 0xBF99999A, 0xBF99999A, 0x00000000,
583 0x40466666, 0x40C00000 }
586 .vals = { 0x00000000, 0xBF99999A, 0xBF99999A,
587 0x3F8CCCCD, 0x40000000, 0xBF99999A,
588 0xBF99999A, 0x00000000, 0x00000000,
589 0x40800000, 0x40800000 }
592 .vals = { 0x00000000, 0xC0000000, 0xBF99999A,
593 0xBF99999A, 0x00000000, 0x40466666,
594 0x40800000, 0x40466666, 0x00000000,
595 0x00000000, 0x3F8CCCCD }
600 * DSP reqs for handling full-range speakers/bass redirection. If a speaker is
601 * set as not being full range, and bass redirection is enabled, all
602 * frequencies below the crossover frequency are redirected to the LFE
603 * channel. If the surround configuration has no LFE channel, this can't be
604 * enabled. X-Bass must be disabled when using these.
606 enum speaker_range_reqs {
607 SPEAKER_BASS_REDIRECT = 0x15,
608 SPEAKER_BASS_REDIRECT_XOVER_FREQ = 0x16,
609 /* Between 0x16-0x1a are the X-Bass reqs. */
610 SPEAKER_FULL_RANGE_FRONT_L_R = 0x1a,
611 SPEAKER_FULL_RANGE_CENTER_LFE = 0x1b,
612 SPEAKER_FULL_RANGE_REAR_L_R = 0x1c,
613 SPEAKER_FULL_RANGE_SURROUND_L_R = 0x1d,
614 SPEAKER_BASS_REDIRECT_SUB_GAIN = 0x1e,
618 * Definitions for the DSP req's to handle speaker tuning. These all belong to
619 * module ID 0x96, the output effects module.
621 enum speaker_tuning_reqs {
623 * Currently, this value is always set to 0.0f. However, on Windows,
624 * when selecting certain headphone profiles on the new Sound Blaster
625 * connect software, the QUERY_SPEAKER_EQ_ADDRESS req on mid 0x80 is
626 * sent. This gets the speaker EQ address area, which is then used to
627 * send over (presumably) an equalizer profile for the specific
628 * headphone setup. It is sent using the same method the DSP
629 * firmware is uploaded with, which I believe is why the 'ctspeq.bin'
630 * file exists in linux firmware tree but goes unused. It would also
631 * explain why the QUERY_SPEAKER_EQ_ADDRESS req is defined but unused.
632 * Once this profile is sent over, SPEAKER_TUNING_USE_SPEAKER_EQ is
635 SPEAKER_TUNING_USE_SPEAKER_EQ = 0x1f,
636 SPEAKER_TUNING_ENABLE_CENTER_EQ = 0x20,
637 SPEAKER_TUNING_FRONT_LEFT_VOL_LEVEL = 0x21,
638 SPEAKER_TUNING_FRONT_RIGHT_VOL_LEVEL = 0x22,
639 SPEAKER_TUNING_CENTER_VOL_LEVEL = 0x23,
640 SPEAKER_TUNING_LFE_VOL_LEVEL = 0x24,
641 SPEAKER_TUNING_REAR_LEFT_VOL_LEVEL = 0x25,
642 SPEAKER_TUNING_REAR_RIGHT_VOL_LEVEL = 0x26,
643 SPEAKER_TUNING_SURROUND_LEFT_VOL_LEVEL = 0x27,
644 SPEAKER_TUNING_SURROUND_RIGHT_VOL_LEVEL = 0x28,
646 * Inversion is used when setting headphone virtualization to line
647 * out. Not sure why this is, but it's the only place it's ever used.
649 SPEAKER_TUNING_FRONT_LEFT_INVERT = 0x29,
650 SPEAKER_TUNING_FRONT_RIGHT_INVERT = 0x2a,
651 SPEAKER_TUNING_CENTER_INVERT = 0x2b,
652 SPEAKER_TUNING_LFE_INVERT = 0x2c,
653 SPEAKER_TUNING_REAR_LEFT_INVERT = 0x2d,
654 SPEAKER_TUNING_REAR_RIGHT_INVERT = 0x2e,
655 SPEAKER_TUNING_SURROUND_LEFT_INVERT = 0x2f,
656 SPEAKER_TUNING_SURROUND_RIGHT_INVERT = 0x30,
657 /* Delay is used when setting surround speaker distance in Windows. */
658 SPEAKER_TUNING_FRONT_LEFT_DELAY = 0x31,
659 SPEAKER_TUNING_FRONT_RIGHT_DELAY = 0x32,
660 SPEAKER_TUNING_CENTER_DELAY = 0x33,
661 SPEAKER_TUNING_LFE_DELAY = 0x34,
662 SPEAKER_TUNING_REAR_LEFT_DELAY = 0x35,
663 SPEAKER_TUNING_REAR_RIGHT_DELAY = 0x36,
664 SPEAKER_TUNING_SURROUND_LEFT_DELAY = 0x37,
665 SPEAKER_TUNING_SURROUND_RIGHT_DELAY = 0x38,
666 /* Of these two, only mute seems to ever be used. */
667 SPEAKER_TUNING_MAIN_VOLUME = 0x39,
668 SPEAKER_TUNING_MUTE = 0x3a,
671 /* Surround output channel count configuration structures. */
672 #define SPEAKER_CHANNEL_CFG_COUNT 5
674 SPEAKER_CHANNELS_2_0,
675 SPEAKER_CHANNELS_2_1,
676 SPEAKER_CHANNELS_4_0,
677 SPEAKER_CHANNELS_4_1,
678 SPEAKER_CHANNELS_5_1,
681 struct ca0132_alt_speaker_channel_cfg {
686 static const struct ca0132_alt_speaker_channel_cfg speaker_channel_cfgs[] = {
705 * DSP volume setting structs. Req 1 is left volume, req 2 is right volume,
706 * and I don't know what the third req is, but it's always zero. I assume it's
707 * some sort of update or set command to tell the DSP there's new volume info.
709 #define DSP_VOL_OUT 0
712 struct ct_dsp_volume_ctl {
714 int mid; /* module ID*/
715 unsigned int reqs[3]; /* scp req ID */
718 static const struct ct_dsp_volume_ctl ca0132_alt_vol_ctls[] = {
729 /* Values for ca0113_mmio_command_set for selecting output. */
730 #define AE_CA0113_OUT_SET_COMMANDS 6
731 struct ae_ca0113_output_set {
732 unsigned int group[AE_CA0113_OUT_SET_COMMANDS];
733 unsigned int target[AE_CA0113_OUT_SET_COMMANDS];
734 unsigned int vals[NUM_OF_OUTPUTS][AE_CA0113_OUT_SET_COMMANDS];
737 static const struct ae_ca0113_output_set ae5_ca0113_output_presets = {
738 .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
739 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
741 .vals = { { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f },
743 { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 } },
746 static const struct ae_ca0113_output_set ae7_ca0113_output_presets = {
747 .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
748 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
750 .vals = { { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f },
752 { 0x3f, 0x3f, 0x00, 0x00, 0x02, 0x00 } },
755 /* ae5 ca0113 command sequences to set headphone gain levels. */
756 #define AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS 4
757 struct ae5_headphone_gain_set {
759 unsigned int vals[AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS];
762 static const struct ae5_headphone_gain_set ae5_headphone_gain_presets[] = {
763 { .name = "Low (16-31",
764 .vals = { 0xff, 0x2c, 0xf5, 0x32 }
766 { .name = "Medium (32-149",
767 .vals = { 0x38, 0xa8, 0x3e, 0x4c }
769 { .name = "High (150-600",
770 .vals = { 0xff, 0xff, 0xff, 0x7f }
774 struct ae5_filter_set {
779 static const struct ae5_filter_set ae5_filter_presets[] = {
780 { .name = "Slow Roll Off",
783 { .name = "Minimum Phase",
786 { .name = "Fast Roll Off",
791 enum hda_cmd_vendor_io {
793 VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000,
794 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100,
796 VENDOR_DSPIO_STATUS = 0xF01,
797 VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702,
798 VENDOR_DSPIO_SCP_READ_DATA = 0xF02,
799 VENDOR_DSPIO_DSP_INIT = 0x703,
800 VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704,
801 VENDOR_DSPIO_SCP_READ_COUNT = 0xF04,
803 /* for ChipIO node */
804 VENDOR_CHIPIO_ADDRESS_LOW = 0x000,
805 VENDOR_CHIPIO_ADDRESS_HIGH = 0x100,
806 VENDOR_CHIPIO_STREAM_FORMAT = 0x200,
807 VENDOR_CHIPIO_DATA_LOW = 0x300,
808 VENDOR_CHIPIO_DATA_HIGH = 0x400,
810 VENDOR_CHIPIO_8051_WRITE_DIRECT = 0x500,
811 VENDOR_CHIPIO_8051_READ_DIRECT = 0xD00,
813 VENDOR_CHIPIO_GET_PARAMETER = 0xF00,
814 VENDOR_CHIPIO_STATUS = 0xF01,
815 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
816 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
818 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
819 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
820 VENDOR_CHIPIO_8051_PMEM_READ = 0xF08,
821 VENDOR_CHIPIO_8051_IRAM_WRITE = 0x709,
822 VENDOR_CHIPIO_8051_IRAM_READ = 0xF09,
824 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
825 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
827 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
828 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
829 VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D,
830 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
831 VENDOR_CHIPIO_FLAG_SET = 0x70F,
832 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
833 VENDOR_CHIPIO_PARAM_SET = 0x710,
834 VENDOR_CHIPIO_PARAM_GET = 0xF10,
836 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
837 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
838 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
839 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
841 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
842 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
843 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
844 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
846 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
847 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
848 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
849 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
850 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
851 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
853 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
859 enum control_flag_id {
860 /* Connection manager stream setup is bypassed/enabled */
861 CONTROL_FLAG_C_MGR = 0,
862 /* DSP DMA is bypassed/enabled */
863 CONTROL_FLAG_DMA = 1,
864 /* 8051 'idle' mode is disabled/enabled */
865 CONTROL_FLAG_IDLE_ENABLE = 2,
866 /* Tracker for the SPDIF-in path is bypassed/enabled */
867 CONTROL_FLAG_TRACKER = 3,
868 /* DigitalOut to Spdif2Out connection is disabled/enabled */
869 CONTROL_FLAG_SPDIF2OUT = 4,
870 /* Digital Microphone is disabled/enabled */
871 CONTROL_FLAG_DMIC = 5,
872 /* ADC_B rate is 48 kHz/96 kHz */
873 CONTROL_FLAG_ADC_B_96KHZ = 6,
874 /* ADC_C rate is 48 kHz/96 kHz */
875 CONTROL_FLAG_ADC_C_96KHZ = 7,
876 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
877 CONTROL_FLAG_DAC_96KHZ = 8,
878 /* DSP rate is 48 kHz/96 kHz */
879 CONTROL_FLAG_DSP_96KHZ = 9,
880 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
881 CONTROL_FLAG_SRC_CLOCK_196MHZ = 10,
882 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
883 CONTROL_FLAG_SRC_RATE_96KHZ = 11,
884 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
885 CONTROL_FLAG_DECODE_LOOP = 12,
886 /* De-emphasis filter on DAC-1 disabled/enabled */
887 CONTROL_FLAG_DAC1_DEEMPHASIS = 13,
888 /* De-emphasis filter on DAC-2 disabled/enabled */
889 CONTROL_FLAG_DAC2_DEEMPHASIS = 14,
890 /* De-emphasis filter on DAC-3 disabled/enabled */
891 CONTROL_FLAG_DAC3_DEEMPHASIS = 15,
892 /* High-pass filter on ADC_B disabled/enabled */
893 CONTROL_FLAG_ADC_B_HIGH_PASS = 16,
894 /* High-pass filter on ADC_C disabled/enabled */
895 CONTROL_FLAG_ADC_C_HIGH_PASS = 17,
896 /* Common mode on Port_A disabled/enabled */
897 CONTROL_FLAG_PORT_A_COMMON_MODE = 18,
898 /* Common mode on Port_D disabled/enabled */
899 CONTROL_FLAG_PORT_D_COMMON_MODE = 19,
900 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
901 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
902 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
903 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
904 /* ASI rate is 48kHz/96kHz */
905 CONTROL_FLAG_ASI_96KHZ = 22,
906 /* DAC power settings able to control attached ports no/yes */
907 CONTROL_FLAG_DACS_CONTROL_PORTS = 23,
908 /* Clock Stop OK reporting is disabled/enabled */
909 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24,
910 /* Number of control flags */
911 CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1)
915 * Control parameter IDs
917 enum control_param_id {
918 /* 0: None, 1: Mic1In*/
919 CONTROL_PARAM_VIP_SOURCE = 1,
920 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
921 CONTROL_PARAM_SPDIF1_SOURCE = 2,
922 /* Port A output stage gain setting to use when 16 Ohm output
923 * impedance is selected*/
924 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
925 /* Port D output stage gain setting to use when 16 Ohm output
926 * impedance is selected*/
927 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
930 * This control param name was found in the 8051 memory, and makes
931 * sense given the fact the AE-5 uses it and has the ASI flag set.
933 CONTROL_PARAM_ASI = 23,
937 /* Select stream with the given ID */
938 CONTROL_PARAM_STREAM_ID = 24,
939 /* Source connection point for the selected stream */
940 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25,
941 /* Destination connection point for the selected stream */
942 CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26,
943 /* Number of audio channels in the selected stream */
944 CONTROL_PARAM_STREAMS_CHANNELS = 27,
945 /*Enable control for the selected stream */
946 CONTROL_PARAM_STREAM_CONTROL = 28,
948 /* Connection Point Control */
950 /* Select connection point with the given ID */
951 CONTROL_PARAM_CONN_POINT_ID = 29,
952 /* Connection point sample rate */
953 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30,
957 /* Select HDA node with the given ID */
958 CONTROL_PARAM_NODE_ID = 31
962 * Dsp Io Status codes
964 enum hda_vendor_status_dspio {
966 VENDOR_STATUS_DSPIO_OK = 0x00,
967 /* Busy, unable to accept new command, the host must retry */
968 VENDOR_STATUS_DSPIO_BUSY = 0x01,
969 /* SCP command queue is full */
970 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02,
971 /* SCP response queue is empty */
972 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03
976 * Chip Io Status codes
978 enum hda_vendor_status_chipio {
980 VENDOR_STATUS_CHIPIO_OK = 0x00,
981 /* Busy, unable to accept new command, the host must retry */
982 VENDOR_STATUS_CHIPIO_BUSY = 0x01
988 enum ca0132_sample_rate {
1008 SR_RATE_UNKNOWN = 0x1F
1011 enum dsp_download_state {
1012 DSP_DOWNLOAD_FAILED = -1,
1013 DSP_DOWNLOAD_INIT = 0,
1014 DSP_DOWNLOADING = 1,
1018 /* retrieve parameters from hda format */
1019 #define get_hdafmt_chs(fmt) (fmt & 0xf)
1020 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
1021 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
1022 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
1028 struct ca0132_spec {
1029 const struct snd_kcontrol_new *mixers[5];
1030 unsigned int num_mixers;
1031 const struct hda_verb *base_init_verbs;
1032 const struct hda_verb *base_exit_verbs;
1033 const struct hda_verb *chip_init_verbs;
1034 const struct hda_verb *desktop_init_verbs;
1035 struct hda_verb *spec_init_verbs;
1036 struct auto_pin_cfg autocfg;
1038 /* Nodes configurations */
1039 struct hda_multi_out multiout;
1040 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
1041 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
1042 unsigned int num_outputs;
1043 hda_nid_t input_pins[AUTO_PIN_LAST];
1044 hda_nid_t adcs[AUTO_PIN_LAST];
1047 unsigned int num_inputs;
1048 hda_nid_t shared_mic_nid;
1049 hda_nid_t shared_out_nid;
1050 hda_nid_t unsol_tag_hp;
1051 hda_nid_t unsol_tag_front_hp; /* for desktop ca0132 codecs */
1052 hda_nid_t unsol_tag_amic1;
1055 struct mutex chipio_mutex; /* chip access mutex */
1058 /* DSP download related */
1059 enum dsp_download_state dsp_state;
1060 unsigned int dsp_stream_id;
1061 unsigned int wait_scp;
1062 unsigned int wait_scp_header;
1063 unsigned int wait_num_data;
1064 unsigned int scp_resp_header;
1065 unsigned int scp_resp_data[4];
1066 unsigned int scp_resp_count;
1067 bool startup_check_entered;
1070 /* mixer and effects related */
1071 unsigned char dmic_ctl;
1074 long vnode_lvol[VNODES_COUNT];
1075 long vnode_rvol[VNODES_COUNT];
1076 long vnode_lswitch[VNODES_COUNT];
1077 long vnode_rswitch[VNODES_COUNT];
1078 long effects_switch[EFFECTS_COUNT];
1081 /* ca0132_alt control related values */
1082 unsigned char in_enum_val;
1083 unsigned char out_enum_val;
1084 unsigned char channel_cfg_val;
1085 unsigned char speaker_range_val[2];
1086 unsigned char mic_boost_enum_val;
1087 unsigned char smart_volume_setting;
1088 unsigned char bass_redirection_val;
1089 long bass_redirect_xover_freq;
1090 long fx_ctl_val[EFFECT_LEVEL_SLIDERS];
1091 long xbass_xover_freq;
1093 unsigned int tlv[4];
1094 struct hda_vmaster_mute_hook vmaster_mute;
1095 /* AE-5 Control values */
1096 unsigned char ae5_headphone_gain_val;
1097 unsigned char ae5_filter_val;
1098 /* ZxR Control Values */
1099 unsigned char zxr_gain_set;
1101 struct hda_codec *codec;
1102 struct delayed_work unsol_hp_work;
1105 #ifdef ENABLE_TUNING_CONTROLS
1106 long cur_ctl_vals[TUNING_CTLS_COUNT];
1109 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
1110 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
1114 void __iomem *mem_base;
1117 * Whether or not to use the alt functions like alt_select_out,
1118 * alt_select_in, etc. Only used on desktop codecs for now, because of
1119 * surround sound support.
1121 bool use_alt_functions;
1124 * Whether or not to use alt controls: volume effect sliders, EQ
1125 * presets, smart volume presets, and new control names with FX prefix.
1126 * Renames PlayEnhancement and CrystalVoice too.
1128 bool use_alt_controls;
1132 * CA0132 quirks table
1137 QUIRK_ALIENWARE_M17XR4,
1148 #define ca0132_quirk(spec) ((spec)->quirk)
1149 #define ca0132_use_pci_mmio(spec) ((spec)->use_pci_mmio)
1150 #define ca0132_use_alt_functions(spec) ((spec)->use_alt_functions)
1151 #define ca0132_use_alt_controls(spec) ((spec)->use_alt_controls)
1153 #define ca0132_quirk(spec) ({ (void)(spec); QUIRK_NONE; })
1154 #define ca0132_use_alt_functions(spec) ({ (void)(spec); false; })
1155 #define ca0132_use_pci_mmio(spec) ({ (void)(spec); false; })
1156 #define ca0132_use_alt_controls(spec) ({ (void)(spec); false; })
1159 static const struct hda_pintbl alienware_pincfgs[] = {
1160 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1161 { 0x0c, 0x411111f0 }, /* N/A */
1162 { 0x0d, 0x411111f0 }, /* N/A */
1163 { 0x0e, 0x411111f0 }, /* N/A */
1164 { 0x0f, 0x0321101f }, /* HP */
1165 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1166 { 0x11, 0x03a11021 }, /* Mic */
1167 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1168 { 0x13, 0x411111f0 }, /* N/A */
1169 { 0x18, 0x411111f0 }, /* N/A */
1173 /* Sound Blaster Z pin configs taken from Windows Driver */
1174 static const struct hda_pintbl sbz_pincfgs[] = {
1175 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1176 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1177 { 0x0d, 0x014510f0 }, /* Digital Out */
1178 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1179 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1180 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1181 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1182 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1183 { 0x13, 0x908700f0 }, /* What U Hear In*/
1184 { 0x18, 0x50d000f0 }, /* N/A */
1188 /* Sound Blaster ZxR pin configs taken from Windows Driver */
1189 static const struct hda_pintbl zxr_pincfgs[] = {
1190 { 0x0b, 0x01047110 }, /* Port G -- Lineout FRONT L/R */
1191 { 0x0c, 0x414510f0 }, /* SPDIF Out 1 - Disabled*/
1192 { 0x0d, 0x014510f0 }, /* Digital Out */
1193 { 0x0e, 0x41c520f0 }, /* SPDIF In - Disabled*/
1194 { 0x0f, 0x0122711f }, /* Port A -- BackPanel HP */
1195 { 0x10, 0x01017111 }, /* Port D -- Center/LFE */
1196 { 0x11, 0x01017114 }, /* Port B -- LineMicIn2 / Rear L/R */
1197 { 0x12, 0x01a271f0 }, /* Port C -- LineIn1 */
1198 { 0x13, 0x908700f0 }, /* What U Hear In*/
1199 { 0x18, 0x50d000f0 }, /* N/A */
1203 /* Recon3D pin configs taken from Windows Driver */
1204 static const struct hda_pintbl r3d_pincfgs[] = {
1205 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1206 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1207 { 0x0d, 0x014510f0 }, /* Digital Out */
1208 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1209 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1210 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1211 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1212 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1213 { 0x13, 0x908700f0 }, /* What U Hear In*/
1214 { 0x18, 0x50d000f0 }, /* N/A */
1218 /* Sound Blaster AE-5 pin configs taken from Windows Driver */
1219 static const struct hda_pintbl ae5_pincfgs[] = {
1220 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1221 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1222 { 0x0d, 0x014510f0 }, /* Digital Out */
1223 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1224 { 0x0f, 0x01017114 }, /* Port A -- Rear L/R. */
1225 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1226 { 0x11, 0x01a170ff }, /* Port B -- LineMicIn2 / Rear Headphone */
1227 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1228 { 0x13, 0x908700f0 }, /* What U Hear In*/
1229 { 0x18, 0x50d000f0 }, /* N/A */
1233 /* Recon3D integrated pin configs taken from Windows Driver */
1234 static const struct hda_pintbl r3di_pincfgs[] = {
1235 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1236 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1237 { 0x0d, 0x014510f0 }, /* Digital Out */
1238 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1239 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1240 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1241 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1242 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1243 { 0x13, 0x908700f0 }, /* What U Hear In*/
1244 { 0x18, 0x500000f0 }, /* N/A */
1248 static const struct hda_pintbl ae7_pincfgs[] = {
1249 { 0x0b, 0x01017010 },
1250 { 0x0c, 0x014510f0 },
1251 { 0x0d, 0x414510f0 },
1252 { 0x0e, 0x01c520f0 },
1253 { 0x0f, 0x01017114 },
1254 { 0x10, 0x01017011 },
1255 { 0x11, 0x018170ff },
1256 { 0x12, 0x01a170f0 },
1257 { 0x13, 0x908700f0 },
1258 { 0x18, 0x500000f0 },
1262 static const struct snd_pci_quirk ca0132_quirks[] = {
1263 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4),
1264 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE),
1265 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE),
1266 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE),
1267 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ),
1268 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ),
1269 SND_PCI_QUIRK(0x1102, 0x0027, "Sound Blaster Z", QUIRK_SBZ),
1270 SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ),
1271 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
1272 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
1273 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
1274 SND_PCI_QUIRK(0x3842, 0x1038, "EVGA X99 Classified", QUIRK_R3DI),
1275 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1276 SND_PCI_QUIRK(0x1102, 0x0018, "Recon3D", QUIRK_R3D),
1277 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5),
1278 SND_PCI_QUIRK(0x1102, 0x0081, "Sound Blaster AE-7", QUIRK_AE7),
1282 /* Output selection quirk info structures. */
1283 #define MAX_QUIRK_MMIO_GPIO_SET_VALS 3
1284 #define MAX_QUIRK_SCP_SET_VALS 2
1285 struct ca0132_alt_out_set_info {
1286 unsigned int dac2port; /* ParamID 0x0d value. */
1292 unsigned int mmio_gpio_count;
1293 char mmio_gpio_pin[MAX_QUIRK_MMIO_GPIO_SET_VALS];
1294 char mmio_gpio_set[MAX_QUIRK_MMIO_GPIO_SET_VALS];
1296 unsigned int scp_cmds_count;
1297 unsigned int scp_cmd_mid[MAX_QUIRK_SCP_SET_VALS];
1298 unsigned int scp_cmd_req[MAX_QUIRK_SCP_SET_VALS];
1299 unsigned int scp_cmd_val[MAX_QUIRK_SCP_SET_VALS];
1301 bool has_chipio_write;
1302 unsigned int chipio_write_addr;
1303 unsigned int chipio_write_data;
1306 struct ca0132_alt_out_set_quirk_data {
1309 bool has_headphone_gain;
1312 struct ca0132_alt_out_set_info out_set_info[NUM_OF_OUTPUTS];
1315 static const struct ca0132_alt_out_set_quirk_data quirk_out_set_data[] = {
1316 { .quirk_id = QUIRK_R3DI,
1317 .has_headphone_gain = false,
1318 .is_ae_series = false,
1322 .has_hda_gpio = true,
1325 .mmio_gpio_count = 0,
1326 .scp_cmds_count = 0,
1327 .has_chipio_write = false,
1331 .has_hda_gpio = true,
1334 .mmio_gpio_count = 0,
1335 .scp_cmds_count = 0,
1336 .has_chipio_write = false,
1339 { .quirk_id = QUIRK_R3D,
1340 .has_headphone_gain = false,
1341 .is_ae_series = false,
1345 .has_hda_gpio = false,
1346 .mmio_gpio_count = 1,
1347 .mmio_gpio_pin = { 1 },
1348 .mmio_gpio_set = { 1 },
1349 .scp_cmds_count = 0,
1350 .has_chipio_write = false,
1354 .has_hda_gpio = false,
1355 .mmio_gpio_count = 1,
1356 .mmio_gpio_pin = { 1 },
1357 .mmio_gpio_set = { 0 },
1358 .scp_cmds_count = 0,
1359 .has_chipio_write = false,
1362 { .quirk_id = QUIRK_SBZ,
1363 .has_headphone_gain = false,
1364 .is_ae_series = false,
1368 .has_hda_gpio = false,
1369 .mmio_gpio_count = 3,
1370 .mmio_gpio_pin = { 7, 4, 1 },
1371 .mmio_gpio_set = { 0, 1, 1 },
1372 .scp_cmds_count = 0,
1373 .has_chipio_write = false, },
1376 .has_hda_gpio = false,
1377 .mmio_gpio_count = 3,
1378 .mmio_gpio_pin = { 7, 4, 1 },
1379 .mmio_gpio_set = { 1, 1, 0 },
1380 .scp_cmds_count = 0,
1381 .has_chipio_write = false,
1384 { .quirk_id = QUIRK_ZXR,
1385 .has_headphone_gain = true,
1386 .is_ae_series = false,
1390 .has_hda_gpio = false,
1391 .mmio_gpio_count = 3,
1392 .mmio_gpio_pin = { 2, 3, 5 },
1393 .mmio_gpio_set = { 1, 1, 0 },
1394 .scp_cmds_count = 0,
1395 .has_chipio_write = false,
1399 .has_hda_gpio = false,
1400 .mmio_gpio_count = 3,
1401 .mmio_gpio_pin = { 2, 3, 5 },
1402 .mmio_gpio_set = { 0, 1, 1 },
1403 .scp_cmds_count = 0,
1404 .has_chipio_write = false,
1407 { .quirk_id = QUIRK_AE5,
1408 .has_headphone_gain = true,
1409 .is_ae_series = true,
1413 .has_hda_gpio = false,
1414 .mmio_gpio_count = 0,
1415 .scp_cmds_count = 2,
1416 .scp_cmd_mid = { 0x96, 0x96 },
1417 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1418 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1419 .scp_cmd_val = { FLOAT_ZERO, FLOAT_ZERO },
1420 .has_chipio_write = true,
1421 .chipio_write_addr = 0x0018b03c,
1422 .chipio_write_data = 0x00000012
1426 .has_hda_gpio = false,
1427 .mmio_gpio_count = 0,
1428 .scp_cmds_count = 2,
1429 .scp_cmd_mid = { 0x96, 0x96 },
1430 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1431 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1432 .scp_cmd_val = { FLOAT_ONE, FLOAT_ONE },
1433 .has_chipio_write = true,
1434 .chipio_write_addr = 0x0018b03c,
1435 .chipio_write_data = 0x00000012
1438 { .quirk_id = QUIRK_AE7,
1439 .has_headphone_gain = true,
1440 .is_ae_series = true,
1444 .has_hda_gpio = false,
1445 .mmio_gpio_count = 1,
1446 .mmio_gpio_pin = { 0 },
1447 .mmio_gpio_set = { 1 },
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 = 0x00000000
1459 .has_hda_gpio = false,
1460 .mmio_gpio_count = 1,
1461 .mmio_gpio_pin = { 0 },
1462 .mmio_gpio_set = { 1 },
1463 .scp_cmds_count = 2,
1464 .scp_cmd_mid = { 0x96, 0x96 },
1465 .scp_cmd_req = { SPEAKER_TUNING_FRONT_LEFT_INVERT,
1466 SPEAKER_TUNING_FRONT_RIGHT_INVERT },
1467 .scp_cmd_val = { FLOAT_ONE, FLOAT_ONE },
1468 .has_chipio_write = true,
1469 .chipio_write_addr = 0x0018b03c,
1470 .chipio_write_data = 0x00000010
1476 * CA0132 codec access
1478 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1479 unsigned int verb, unsigned int parm, unsigned int *res)
1481 unsigned int response;
1482 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1485 return ((response == -1) ? -1 : 0);
1488 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1489 unsigned short converter_format, unsigned int *res)
1491 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1492 converter_format & 0xffff, res);
1495 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1496 hda_nid_t nid, unsigned char stream,
1497 unsigned char channel, unsigned int *res)
1499 unsigned char converter_stream_channel = 0;
1501 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1502 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1503 converter_stream_channel, res);
1506 /* Chip access helper function */
1507 static int chipio_send(struct hda_codec *codec,
1512 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1514 /* send bits of data specified by reg */
1516 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1518 if (res == VENDOR_STATUS_CHIPIO_OK)
1521 } while (time_before(jiffies, timeout));
1527 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1529 static int chipio_write_address(struct hda_codec *codec,
1530 unsigned int chip_addx)
1532 struct ca0132_spec *spec = codec->spec;
1535 if (spec->curr_chip_addx == chip_addx)
1538 /* send low 16 bits of the address */
1539 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1540 chip_addx & 0xffff);
1543 /* send high 16 bits of the address */
1544 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1548 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1554 * Write data through the vendor widget -- NOT protected by the Mutex!
1556 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1558 struct ca0132_spec *spec = codec->spec;
1561 /* send low 16 bits of the data */
1562 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1565 /* send high 16 bits of the data */
1566 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1570 /*If no error encountered, automatically increment the address
1571 as per chip behaviour*/
1572 spec->curr_chip_addx = (res != -EIO) ?
1573 (spec->curr_chip_addx + 4) : ~0U;
1578 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1580 static int chipio_write_data_multiple(struct hda_codec *codec,
1587 codec_dbg(codec, "chipio_write_data null ptr\n");
1591 while ((count-- != 0) && (status == 0))
1592 status = chipio_write_data(codec, *data++);
1599 * Read data through the vendor widget -- NOT protected by the Mutex!
1601 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1603 struct ca0132_spec *spec = codec->spec;
1607 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1611 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1616 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1617 VENDOR_CHIPIO_HIC_READ_DATA,
1621 /*If no error encountered, automatically increment the address
1622 as per chip behaviour*/
1623 spec->curr_chip_addx = (res != -EIO) ?
1624 (spec->curr_chip_addx + 4) : ~0U;
1629 * Write given value to the given address through the chip I/O widget.
1630 * protected by the Mutex
1632 static int chipio_write(struct hda_codec *codec,
1633 unsigned int chip_addx, const unsigned int data)
1635 struct ca0132_spec *spec = codec->spec;
1638 mutex_lock(&spec->chipio_mutex);
1640 /* write the address, and if successful proceed to write data */
1641 err = chipio_write_address(codec, chip_addx);
1645 err = chipio_write_data(codec, data);
1650 mutex_unlock(&spec->chipio_mutex);
1655 * Write given value to the given address through the chip I/O widget.
1656 * not protected by the Mutex
1658 static int chipio_write_no_mutex(struct hda_codec *codec,
1659 unsigned int chip_addx, const unsigned int data)
1664 /* write the address, and if successful proceed to write data */
1665 err = chipio_write_address(codec, chip_addx);
1669 err = chipio_write_data(codec, data);
1678 * Write multiple values to the given address through the chip I/O widget.
1679 * protected by the Mutex
1681 static int chipio_write_multiple(struct hda_codec *codec,
1686 struct ca0132_spec *spec = codec->spec;
1689 mutex_lock(&spec->chipio_mutex);
1690 status = chipio_write_address(codec, chip_addx);
1694 status = chipio_write_data_multiple(codec, data, count);
1696 mutex_unlock(&spec->chipio_mutex);
1702 * Read the given address through the chip I/O widget
1703 * protected by the Mutex
1705 static int chipio_read(struct hda_codec *codec,
1706 unsigned int chip_addx, unsigned int *data)
1708 struct ca0132_spec *spec = codec->spec;
1711 mutex_lock(&spec->chipio_mutex);
1713 /* write the address, and if successful proceed to write data */
1714 err = chipio_write_address(codec, chip_addx);
1718 err = chipio_read_data(codec, data);
1723 mutex_unlock(&spec->chipio_mutex);
1728 * Set chip control flags through the chip I/O widget.
1730 static void chipio_set_control_flag(struct hda_codec *codec,
1731 enum control_flag_id flag_id,
1735 unsigned int flag_bit;
1737 flag_bit = (flag_state ? 1 : 0);
1738 val = (flag_bit << 7) | (flag_id);
1739 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1740 VENDOR_CHIPIO_FLAG_SET, val);
1744 * Set chip parameters through the chip I/O widget.
1746 static void chipio_set_control_param(struct hda_codec *codec,
1747 enum control_param_id param_id, int param_val)
1749 struct ca0132_spec *spec = codec->spec;
1752 if ((param_id < 32) && (param_val < 8)) {
1753 val = (param_val << 5) | (param_id);
1754 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1755 VENDOR_CHIPIO_PARAM_SET, val);
1757 mutex_lock(&spec->chipio_mutex);
1758 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1759 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1760 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1762 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1763 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1766 mutex_unlock(&spec->chipio_mutex);
1771 * Set chip parameters through the chip I/O widget. NO MUTEX.
1773 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1774 enum control_param_id param_id, int param_val)
1778 if ((param_id < 32) && (param_val < 8)) {
1779 val = (param_val << 5) | (param_id);
1780 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1781 VENDOR_CHIPIO_PARAM_SET, val);
1783 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1784 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1785 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1787 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1788 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1794 * Connect stream to a source point, and then connect
1795 * that source point to a destination point.
1797 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1798 int streamid, int source_point, int dest_point)
1800 chipio_set_control_param_no_mutex(codec,
1801 CONTROL_PARAM_STREAM_ID, streamid);
1802 chipio_set_control_param_no_mutex(codec,
1803 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1804 chipio_set_control_param_no_mutex(codec,
1805 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1809 * Set number of channels in the selected stream.
1811 static void chipio_set_stream_channels(struct hda_codec *codec,
1812 int streamid, unsigned int channels)
1814 chipio_set_control_param_no_mutex(codec,
1815 CONTROL_PARAM_STREAM_ID, streamid);
1816 chipio_set_control_param_no_mutex(codec,
1817 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1821 * Enable/Disable audio stream.
1823 static void chipio_set_stream_control(struct hda_codec *codec,
1824 int streamid, int enable)
1826 chipio_set_control_param_no_mutex(codec,
1827 CONTROL_PARAM_STREAM_ID, streamid);
1828 chipio_set_control_param_no_mutex(codec,
1829 CONTROL_PARAM_STREAM_CONTROL, enable);
1834 * Set sampling rate of the connection point. NO MUTEX.
1836 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1837 int connid, enum ca0132_sample_rate rate)
1839 chipio_set_control_param_no_mutex(codec,
1840 CONTROL_PARAM_CONN_POINT_ID, connid);
1841 chipio_set_control_param_no_mutex(codec,
1842 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1846 * Set sampling rate of the connection point.
1848 static void chipio_set_conn_rate(struct hda_codec *codec,
1849 int connid, enum ca0132_sample_rate rate)
1851 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1852 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1857 * Writes to the 8051's internal address space directly instead of indirectly,
1858 * giving access to the special function registers located at addresses
1861 static void chipio_8051_write_direct(struct hda_codec *codec,
1862 unsigned int addr, unsigned int data)
1866 verb = VENDOR_CHIPIO_8051_WRITE_DIRECT | data;
1867 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1873 static void chipio_enable_clocks(struct hda_codec *codec)
1875 struct ca0132_spec *spec = codec->spec;
1877 mutex_lock(&spec->chipio_mutex);
1878 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1879 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1880 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1881 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1882 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1883 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1884 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1885 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1886 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1887 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1888 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1889 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1890 mutex_unlock(&spec->chipio_mutex);
1894 * CA0132 DSP IO stuffs
1896 static int dspio_send(struct hda_codec *codec, unsigned int reg,
1900 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1902 /* send bits of data specified by reg to dsp */
1904 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1905 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1908 } while (time_before(jiffies, timeout));
1914 * Wait for DSP to be ready for commands
1916 static void dspio_write_wait(struct hda_codec *codec)
1919 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1922 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1923 VENDOR_DSPIO_STATUS, 0);
1924 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1925 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1928 } while (time_before(jiffies, timeout));
1932 * Write SCP data to DSP
1934 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1936 struct ca0132_spec *spec = codec->spec;
1939 dspio_write_wait(codec);
1941 mutex_lock(&spec->chipio_mutex);
1942 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1947 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1952 /* OK, now check if the write itself has executed*/
1953 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1954 VENDOR_DSPIO_STATUS, 0);
1956 mutex_unlock(&spec->chipio_mutex);
1958 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1963 * Write multiple SCP data to DSP
1965 static int dspio_write_multiple(struct hda_codec *codec,
1966 unsigned int *buffer, unsigned int size)
1975 while (count < size) {
1976 status = dspio_write(codec, *buffer++);
1985 static int dspio_read(struct hda_codec *codec, unsigned int *data)
1989 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1993 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1994 if (status == -EIO ||
1995 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
1998 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1999 VENDOR_DSPIO_SCP_READ_DATA, 0);
2004 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
2005 unsigned int *buf_size, unsigned int size_count)
2008 unsigned int size = *buf_size;
2010 unsigned int skip_count;
2017 while (count < size && count < size_count) {
2018 status = dspio_read(codec, buffer++);
2026 while (skip_count < size) {
2027 status = dspio_read(codec, &dummy);
2039 * Construct the SCP header using corresponding fields
2041 static inline unsigned int
2042 make_scp_header(unsigned int target_id, unsigned int source_id,
2043 unsigned int get_flag, unsigned int req,
2044 unsigned int device_flag, unsigned int resp_flag,
2045 unsigned int error_flag, unsigned int data_size)
2047 unsigned int header = 0;
2049 header = (data_size & 0x1f) << 27;
2050 header |= (error_flag & 0x01) << 26;
2051 header |= (resp_flag & 0x01) << 25;
2052 header |= (device_flag & 0x01) << 24;
2053 header |= (req & 0x7f) << 17;
2054 header |= (get_flag & 0x01) << 16;
2055 header |= (source_id & 0xff) << 8;
2056 header |= target_id & 0xff;
2062 * Extract corresponding fields from SCP header
2065 extract_scp_header(unsigned int header,
2066 unsigned int *target_id, unsigned int *source_id,
2067 unsigned int *get_flag, unsigned int *req,
2068 unsigned int *device_flag, unsigned int *resp_flag,
2069 unsigned int *error_flag, unsigned int *data_size)
2072 *data_size = (header >> 27) & 0x1f;
2074 *error_flag = (header >> 26) & 0x01;
2076 *resp_flag = (header >> 25) & 0x01;
2078 *device_flag = (header >> 24) & 0x01;
2080 *req = (header >> 17) & 0x7f;
2082 *get_flag = (header >> 16) & 0x01;
2084 *source_id = (header >> 8) & 0xff;
2086 *target_id = header & 0xff;
2089 #define SCP_MAX_DATA_WORDS (16)
2091 /* Structure to contain any SCP message */
2094 unsigned int data[SCP_MAX_DATA_WORDS];
2097 static void dspio_clear_response_queue(struct hda_codec *codec)
2099 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2100 unsigned int dummy = 0;
2103 /* clear all from the response queue */
2105 status = dspio_read(codec, &dummy);
2106 } while (status == 0 && time_before(jiffies, timeout));
2109 static int dspio_get_response_data(struct hda_codec *codec)
2111 struct ca0132_spec *spec = codec->spec;
2112 unsigned int data = 0;
2115 if (dspio_read(codec, &data) < 0)
2118 if ((data & 0x00ffffff) == spec->wait_scp_header) {
2119 spec->scp_resp_header = data;
2120 spec->scp_resp_count = data >> 27;
2121 count = spec->wait_num_data;
2122 dspio_read_multiple(codec, spec->scp_resp_data,
2123 &spec->scp_resp_count, count);
2131 * Send SCP message to DSP
2133 static int dspio_send_scp_message(struct hda_codec *codec,
2134 unsigned char *send_buf,
2135 unsigned int send_buf_size,
2136 unsigned char *return_buf,
2137 unsigned int return_buf_size,
2138 unsigned int *bytes_returned)
2140 struct ca0132_spec *spec = codec->spec;
2142 unsigned int scp_send_size = 0;
2143 unsigned int total_size;
2144 bool waiting_for_resp = false;
2145 unsigned int header;
2146 struct scp_msg *ret_msg;
2147 unsigned int resp_src_id, resp_target_id;
2148 unsigned int data_size, src_id, target_id, get_flag, device_flag;
2151 *bytes_returned = 0;
2153 /* get scp header from buffer */
2154 header = *((unsigned int *)send_buf);
2155 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
2156 &device_flag, NULL, NULL, &data_size);
2157 scp_send_size = data_size + 1;
2158 total_size = (scp_send_size * 4);
2160 if (send_buf_size < total_size)
2163 if (get_flag || device_flag) {
2164 if (!return_buf || return_buf_size < 4 || !bytes_returned)
2167 spec->wait_scp_header = *((unsigned int *)send_buf);
2169 /* swap source id with target id */
2170 resp_target_id = src_id;
2171 resp_src_id = target_id;
2172 spec->wait_scp_header &= 0xffff0000;
2173 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
2174 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
2176 waiting_for_resp = true;
2179 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
2186 if (waiting_for_resp) {
2187 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
2188 memset(return_buf, 0, return_buf_size);
2191 } while (spec->wait_scp && time_before(jiffies, timeout));
2192 waiting_for_resp = false;
2193 if (!spec->wait_scp) {
2194 ret_msg = (struct scp_msg *)return_buf;
2195 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
2196 memcpy(&ret_msg->data, spec->scp_resp_data,
2197 spec->wait_num_data);
2198 *bytes_returned = (spec->scp_resp_count + 1) * 4;
2210 * Prepare and send the SCP message to DSP
2211 * @codec: the HDA codec
2212 * @mod_id: ID of the DSP module to send the command
2213 * @src_id: ID of the source
2214 * @req: ID of request to send to the DSP module
2216 * @data: pointer to the data to send with the request, request specific
2217 * @len: length of the data, in bytes
2218 * @reply: point to the buffer to hold data returned for a reply
2219 * @reply_len: length of the reply buffer returned from GET
2221 * Returns zero or a negative error code.
2223 static int dspio_scp(struct hda_codec *codec,
2224 int mod_id, int src_id, int req, int dir, const void *data,
2225 unsigned int len, void *reply, unsigned int *reply_len)
2228 struct scp_msg scp_send, scp_reply;
2229 unsigned int ret_bytes, send_size, ret_size;
2230 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
2231 unsigned int reply_data_size;
2233 memset(&scp_send, 0, sizeof(scp_send));
2234 memset(&scp_reply, 0, sizeof(scp_reply));
2236 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
2239 if (dir == SCP_GET && reply == NULL) {
2240 codec_dbg(codec, "dspio_scp get but has no buffer\n");
2244 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
2245 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
2249 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
2250 0, 0, 0, len/sizeof(unsigned int));
2251 if (data != NULL && len > 0) {
2252 len = min((unsigned int)(sizeof(scp_send.data)), len);
2253 memcpy(scp_send.data, data, len);
2257 send_size = sizeof(unsigned int) + len;
2258 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
2259 send_size, (unsigned char *)&scp_reply,
2260 sizeof(scp_reply), &ret_bytes);
2263 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
2267 /* extract send and reply headers members */
2268 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
2269 NULL, NULL, NULL, NULL, NULL);
2270 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
2271 &reply_resp_flag, &reply_error_flag,
2277 if (reply_resp_flag && !reply_error_flag) {
2278 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
2279 / sizeof(unsigned int);
2281 if (*reply_len < ret_size*sizeof(unsigned int)) {
2282 codec_dbg(codec, "reply too long for buf\n");
2284 } else if (ret_size != reply_data_size) {
2285 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
2287 } else if (!reply) {
2288 codec_dbg(codec, "NULL reply\n");
2291 *reply_len = ret_size*sizeof(unsigned int);
2292 memcpy(reply, scp_reply.data, *reply_len);
2295 codec_dbg(codec, "reply ill-formed or errflag set\n");
2303 * Set DSP parameters
2305 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2306 int src_id, int req, const void *data, unsigned int len)
2308 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2312 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2313 int req, const unsigned int data)
2315 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2316 sizeof(unsigned int));
2319 static int dspio_set_uint_param_no_source(struct hda_codec *codec, int mod_id,
2320 int req, const unsigned int data)
2322 return dspio_set_param(codec, mod_id, 0x00, req, &data,
2323 sizeof(unsigned int));
2327 * Allocate a DSP DMA channel via an SCP message
2329 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2332 unsigned int size = sizeof(dma_chan);
2334 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2335 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2336 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
2340 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2344 if ((*dma_chan + 1) == 0) {
2345 codec_dbg(codec, "no free dma channels to allocate\n");
2349 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2350 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2356 * Free a DSP DMA via an SCP message
2358 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2361 unsigned int dummy = 0;
2363 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2364 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2366 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2367 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
2368 sizeof(dma_chan), NULL, &dummy);
2371 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2375 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2383 static int dsp_set_run_state(struct hda_codec *codec)
2385 unsigned int dbg_ctrl_reg;
2386 unsigned int halt_state;
2389 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2393 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
2394 DSP_DBGCNTL_STATE_LOBIT;
2396 if (halt_state != 0) {
2397 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
2398 DSP_DBGCNTL_SS_MASK);
2399 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2404 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
2405 DSP_DBGCNTL_EXEC_MASK;
2406 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2418 static int dsp_reset(struct hda_codec *codec)
2423 codec_dbg(codec, "dsp_reset\n");
2425 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2427 } while (res == -EIO && retry);
2430 codec_dbg(codec, "dsp_reset timeout\n");
2438 * Convert chip address to DSP address
2440 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2441 bool *code, bool *yram)
2443 *code = *yram = false;
2445 if (UC_RANGE(chip_addx, 1)) {
2447 return UC_OFF(chip_addx);
2448 } else if (X_RANGE_ALL(chip_addx, 1)) {
2449 return X_OFF(chip_addx);
2450 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2452 return Y_OFF(chip_addx);
2455 return INVALID_CHIP_ADDRESS;
2459 * Check if the DSP DMA is active
2461 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2463 unsigned int dma_chnlstart_reg;
2465 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2467 return ((dma_chnlstart_reg & (1 <<
2468 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2471 static int dsp_dma_setup_common(struct hda_codec *codec,
2472 unsigned int chip_addx,
2473 unsigned int dma_chan,
2474 unsigned int port_map_mask,
2478 unsigned int chnl_prop;
2479 unsigned int dsp_addx;
2480 unsigned int active;
2483 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2485 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2486 codec_dbg(codec, "dma chan num invalid\n");
2490 if (dsp_is_dma_active(codec, dma_chan)) {
2491 codec_dbg(codec, "dma already active\n");
2495 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2497 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2498 codec_dbg(codec, "invalid chip addr\n");
2502 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2505 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2508 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2512 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2515 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2519 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2521 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2523 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2525 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2527 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2530 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2533 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2537 codec_dbg(codec, "read ACTIVE Reg fail\n");
2540 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2543 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2544 DSPDMAC_ACTIVE_AAR_MASK;
2546 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2548 codec_dbg(codec, "write ACTIVE Reg fail\n");
2552 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2554 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2557 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2560 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2562 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2563 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2565 codec_dbg(codec, "write IRQCNT Reg fail\n");
2568 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2571 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2572 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2573 chip_addx, dsp_addx, dma_chan,
2574 port_map_mask, chnl_prop, active);
2576 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2582 * Setup the DSP DMA per-transfer-specific registers
2584 static int dsp_dma_setup(struct hda_codec *codec,
2585 unsigned int chip_addx,
2587 unsigned int dma_chan)
2591 unsigned int dsp_addx;
2592 unsigned int addr_field;
2593 unsigned int incr_field;
2594 unsigned int base_cnt;
2595 unsigned int cur_cnt;
2596 unsigned int dma_cfg = 0;
2597 unsigned int adr_ofs = 0;
2598 unsigned int xfr_cnt = 0;
2599 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2600 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2602 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2604 if (count > max_dma_count) {
2605 codec_dbg(codec, "count too big\n");
2609 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2610 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2611 codec_dbg(codec, "invalid chip addr\n");
2615 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2617 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2623 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2625 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2628 dma_cfg = addr_field + incr_field;
2629 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2632 codec_dbg(codec, "write DMACFG Reg fail\n");
2635 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2637 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2640 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2643 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2646 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2648 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2650 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2652 xfr_cnt = base_cnt | cur_cnt;
2654 status = chipio_write(codec,
2655 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2657 codec_dbg(codec, "write XFRCNT Reg fail\n");
2660 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2663 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2664 "ADROFS=0x%x, XFRCNT=0x%x\n",
2665 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2667 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2675 static int dsp_dma_start(struct hda_codec *codec,
2676 unsigned int dma_chan, bool ovly)
2678 unsigned int reg = 0;
2681 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2684 status = chipio_read(codec,
2685 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2688 codec_dbg(codec, "read CHNLSTART reg fail\n");
2691 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2693 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2694 DSPDMAC_CHNLSTART_DIS_MASK);
2697 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2698 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2700 codec_dbg(codec, "write CHNLSTART reg fail\n");
2703 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2711 static int dsp_dma_stop(struct hda_codec *codec,
2712 unsigned int dma_chan, bool ovly)
2714 unsigned int reg = 0;
2717 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2720 status = chipio_read(codec,
2721 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2724 codec_dbg(codec, "read CHNLSTART reg fail\n");
2727 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2728 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2729 DSPDMAC_CHNLSTART_DIS_MASK);
2732 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2733 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2735 codec_dbg(codec, "write CHNLSTART reg fail\n");
2738 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2744 * Allocate router ports
2746 * @codec: the HDA codec
2747 * @num_chans: number of channels in the stream
2748 * @ports_per_channel: number of ports per channel
2749 * @start_device: start device
2750 * @port_map: pointer to the port list to hold the allocated ports
2752 * Returns zero or a negative error code.
2754 static int dsp_allocate_router_ports(struct hda_codec *codec,
2755 unsigned int num_chans,
2756 unsigned int ports_per_channel,
2757 unsigned int start_device,
2758 unsigned int *port_map)
2764 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2768 val = start_device << 6;
2769 val |= (ports_per_channel - 1) << 4;
2770 val |= num_chans - 1;
2772 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2773 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2776 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2777 VENDOR_CHIPIO_PORT_ALLOC_SET,
2780 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2784 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2785 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2789 return (res < 0) ? res : 0;
2795 static int dsp_free_router_ports(struct hda_codec *codec)
2799 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2803 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2804 VENDOR_CHIPIO_PORT_FREE_SET,
2807 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2813 * Allocate DSP ports for the download stream
2815 static int dsp_allocate_ports(struct hda_codec *codec,
2816 unsigned int num_chans,
2817 unsigned int rate_multi, unsigned int *port_map)
2821 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2823 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2824 codec_dbg(codec, "bad rate multiple\n");
2828 status = dsp_allocate_router_ports(codec, num_chans,
2829 rate_multi, 0, port_map);
2831 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2836 static int dsp_allocate_ports_format(struct hda_codec *codec,
2837 const unsigned short fmt,
2838 unsigned int *port_map)
2841 unsigned int num_chans;
2843 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2844 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2845 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2847 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2848 codec_dbg(codec, "bad rate multiple\n");
2852 num_chans = get_hdafmt_chs(fmt) + 1;
2854 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2862 static int dsp_free_ports(struct hda_codec *codec)
2866 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2868 status = dsp_free_router_ports(codec);
2870 codec_dbg(codec, "free router ports fail\n");
2873 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2879 * HDA DMA engine stuffs for DSP code download
2882 struct hda_codec *codec;
2883 unsigned short m_converter_format;
2884 struct snd_dma_buffer *dmab;
2885 unsigned int buf_size;
2894 static int dma_convert_to_hda_format(struct hda_codec *codec,
2895 unsigned int sample_rate,
2896 unsigned short channels,
2897 unsigned short *hda_format)
2899 unsigned int format_val;
2901 format_val = snd_hdac_calc_stream_format(sample_rate,
2902 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
2905 *hda_format = (unsigned short)format_val;
2911 * Reset DMA for DSP download
2913 static int dma_reset(struct dma_engine *dma)
2915 struct hda_codec *codec = dma->codec;
2916 struct ca0132_spec *spec = codec->spec;
2919 if (dma->dmab->area)
2920 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2922 status = snd_hda_codec_load_dsp_prepare(codec,
2923 dma->m_converter_format,
2928 spec->dsp_stream_id = status;
2932 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2937 case DMA_STATE_STOP:
2947 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2951 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2953 return dma->dmab->bytes;
2956 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2958 return dma->dmab->area;
2961 static int dma_xfer(struct dma_engine *dma,
2962 const unsigned int *data,
2965 memcpy(dma->dmab->area, data, count);
2969 static void dma_get_converter_format(
2970 struct dma_engine *dma,
2971 unsigned short *format)
2974 *format = dma->m_converter_format;
2977 static unsigned int dma_get_stream_id(struct dma_engine *dma)
2979 struct ca0132_spec *spec = dma->codec->spec;
2981 return spec->dsp_stream_id;
2984 struct dsp_image_seg {
2991 static const u32 g_magic_value = 0x4c46584d;
2992 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2994 static bool is_valid(const struct dsp_image_seg *p)
2996 return p->magic == g_magic_value;
2999 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
3001 return g_chip_addr_magic_value == p->chip_addr;
3004 static bool is_last(const struct dsp_image_seg *p)
3006 return p->count == 0;
3009 static size_t dsp_sizeof(const struct dsp_image_seg *p)
3011 return struct_size(p, data, p->count);
3014 static const struct dsp_image_seg *get_next_seg_ptr(
3015 const struct dsp_image_seg *p)
3017 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
3021 * CA0132 chip DSP transfer stuffs. For DSP download.
3023 #define INVALID_DMA_CHANNEL (~0U)
3026 * Program a list of address/data pairs via the ChipIO widget.
3027 * The segment data is in the format of successive pairs of words.
3028 * These are repeated as indicated by the segment's count field.
3030 static int dspxfr_hci_write(struct hda_codec *codec,
3031 const struct dsp_image_seg *fls)
3037 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
3038 codec_dbg(codec, "hci_write invalid params\n");
3043 data = (u32 *)(fls->data);
3044 while (count >= 2) {
3045 status = chipio_write(codec, data[0], data[1]);
3047 codec_dbg(codec, "hci_write chipio failed\n");
3057 * Write a block of data into DSP code or data RAM using pre-allocated
3060 * @codec: the HDA codec
3061 * @fls: pointer to a fast load image
3062 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3064 * @dma_engine: pointer to DMA engine to be used for DSP download
3065 * @dma_chan: The number of DMA channels used for DSP download
3066 * @port_map_mask: port mapping
3067 * @ovly: TRUE if overlay format is required
3069 * Returns zero or a negative error code.
3071 static int dspxfr_one_seg(struct hda_codec *codec,
3072 const struct dsp_image_seg *fls,
3074 struct dma_engine *dma_engine,
3075 unsigned int dma_chan,
3076 unsigned int port_map_mask,
3080 bool comm_dma_setup_done = false;
3081 const unsigned int *data;
3082 unsigned int chip_addx;
3083 unsigned int words_to_write;
3084 unsigned int buffer_size_words;
3085 unsigned char *buffer_addx;
3086 unsigned short hda_format;
3087 unsigned int sample_rate_div;
3088 unsigned int sample_rate_mul;
3089 unsigned int num_chans;
3090 unsigned int hda_frame_size_words;
3091 unsigned int remainder_words;
3092 const u32 *data_remainder;
3093 u32 chip_addx_remainder;
3094 unsigned int run_size_words;
3095 const struct dsp_image_seg *hci_write = NULL;
3096 unsigned long timeout;
3101 if (is_hci_prog_list_seg(fls)) {
3103 fls = get_next_seg_ptr(fls);
3106 if (hci_write && (!fls || is_last(fls))) {
3107 codec_dbg(codec, "hci_write\n");
3108 return dspxfr_hci_write(codec, hci_write);
3111 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
3112 codec_dbg(codec, "Invalid Params\n");
3117 chip_addx = fls->chip_addr;
3118 words_to_write = fls->count;
3120 if (!words_to_write)
3121 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
3123 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
3125 if (!UC_RANGE(chip_addx, words_to_write) &&
3126 !X_RANGE_ALL(chip_addx, words_to_write) &&
3127 !Y_RANGE_ALL(chip_addx, words_to_write)) {
3128 codec_dbg(codec, "Invalid chip_addx Params\n");
3132 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
3135 buffer_addx = dma_get_buffer_addr(dma_engine);
3137 if (buffer_addx == NULL) {
3138 codec_dbg(codec, "dma_engine buffer NULL\n");
3142 dma_get_converter_format(dma_engine, &hda_format);
3143 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
3144 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
3145 num_chans = get_hdafmt_chs(hda_format) + 1;
3147 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
3148 (num_chans * sample_rate_mul / sample_rate_div));
3150 if (hda_frame_size_words == 0) {
3151 codec_dbg(codec, "frmsz zero\n");
3155 buffer_size_words = min(buffer_size_words,
3156 (unsigned int)(UC_RANGE(chip_addx, 1) ?
3158 buffer_size_words -= buffer_size_words % hda_frame_size_words;
3160 "chpadr=0x%08x frmsz=%u nchan=%u "
3161 "rate_mul=%u div=%u bufsz=%u\n",
3162 chip_addx, hda_frame_size_words, num_chans,
3163 sample_rate_mul, sample_rate_div, buffer_size_words);
3165 if (buffer_size_words < hda_frame_size_words) {
3166 codec_dbg(codec, "dspxfr_one_seg:failed\n");
3170 remainder_words = words_to_write % hda_frame_size_words;
3171 data_remainder = data;
3172 chip_addx_remainder = chip_addx;
3174 data += remainder_words;
3175 chip_addx += remainder_words*sizeof(u32);
3176 words_to_write -= remainder_words;
3178 while (words_to_write != 0) {
3179 run_size_words = min(buffer_size_words, words_to_write);
3180 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
3181 words_to_write, run_size_words, remainder_words);
3182 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
3183 if (!comm_dma_setup_done) {
3184 status = dsp_dma_stop(codec, dma_chan, ovly);
3187 status = dsp_dma_setup_common(codec, chip_addx,
3188 dma_chan, port_map_mask, ovly);
3191 comm_dma_setup_done = true;
3194 status = dsp_dma_setup(codec, chip_addx,
3195 run_size_words, dma_chan);
3198 status = dsp_dma_start(codec, dma_chan, ovly);
3201 if (!dsp_is_dma_active(codec, dma_chan)) {
3202 codec_dbg(codec, "dspxfr:DMA did not start\n");
3205 status = dma_set_state(dma_engine, DMA_STATE_RUN);
3208 if (remainder_words != 0) {
3209 status = chipio_write_multiple(codec,
3210 chip_addx_remainder,
3215 remainder_words = 0;
3218 status = dspxfr_hci_write(codec, hci_write);
3224 timeout = jiffies + msecs_to_jiffies(2000);
3226 dma_active = dsp_is_dma_active(codec, dma_chan);
3230 } while (time_before(jiffies, timeout));
3234 codec_dbg(codec, "+++++ DMA complete\n");
3235 dma_set_state(dma_engine, DMA_STATE_STOP);
3236 status = dma_reset(dma_engine);
3241 data += run_size_words;
3242 chip_addx += run_size_words*sizeof(u32);
3243 words_to_write -= run_size_words;
3246 if (remainder_words != 0) {
3247 status = chipio_write_multiple(codec, chip_addx_remainder,
3248 data_remainder, remainder_words);
3255 * Write the entire DSP image of a DSP code/data overlay to DSP memories
3257 * @codec: the HDA codec
3258 * @fls_data: pointer to a fast load image
3259 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3261 * @sample_rate: sampling rate of the stream used for DSP download
3262 * @channels: channels of the stream used for DSP download
3263 * @ovly: TRUE if overlay format is required
3265 * Returns zero or a negative error code.
3267 static int dspxfr_image(struct hda_codec *codec,
3268 const struct dsp_image_seg *fls_data,
3270 unsigned int sample_rate,
3271 unsigned short channels,
3274 struct ca0132_spec *spec = codec->spec;
3276 unsigned short hda_format = 0;
3277 unsigned int response;
3278 unsigned char stream_id = 0;
3279 struct dma_engine *dma_engine;
3280 unsigned int dma_chan;
3281 unsigned int port_map_mask;
3283 if (fls_data == NULL)
3286 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
3290 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
3291 if (!dma_engine->dmab) {
3296 dma_engine->codec = codec;
3297 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3298 dma_engine->m_converter_format = hda_format;
3299 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
3300 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
3302 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
3304 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3305 hda_format, &response);
3308 codec_dbg(codec, "set converter format fail\n");
3312 status = snd_hda_codec_load_dsp_prepare(codec,
3313 dma_engine->m_converter_format,
3314 dma_engine->buf_size,
3318 spec->dsp_stream_id = status;
3321 status = dspio_alloc_dma_chan(codec, &dma_chan);
3323 codec_dbg(codec, "alloc dmachan fail\n");
3324 dma_chan = INVALID_DMA_CHANNEL;
3330 status = dsp_allocate_ports_format(codec, hda_format,
3333 codec_dbg(codec, "alloc ports fail\n");
3337 stream_id = dma_get_stream_id(dma_engine);
3338 status = codec_set_converter_stream_channel(codec,
3339 WIDGET_CHIP_CTRL, stream_id, 0, &response);
3341 codec_dbg(codec, "set stream chan fail\n");
3345 while ((fls_data != NULL) && !is_last(fls_data)) {
3346 if (!is_valid(fls_data)) {
3347 codec_dbg(codec, "FLS check fail\n");
3351 status = dspxfr_one_seg(codec, fls_data, reloc,
3352 dma_engine, dma_chan,
3353 port_map_mask, ovly);
3357 if (is_hci_prog_list_seg(fls_data))
3358 fls_data = get_next_seg_ptr(fls_data);
3360 if ((fls_data != NULL) && !is_last(fls_data))
3361 fls_data = get_next_seg_ptr(fls_data);
3364 if (port_map_mask != 0)
3365 status = dsp_free_ports(codec);
3370 status = codec_set_converter_stream_channel(codec,
3371 WIDGET_CHIP_CTRL, 0, 0, &response);
3374 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
3375 dspio_free_dma_chan(codec, dma_chan);
3377 if (dma_engine->dmab->area)
3378 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3379 kfree(dma_engine->dmab);
3386 * CA0132 DSP download stuffs.
3388 static void dspload_post_setup(struct hda_codec *codec)
3390 struct ca0132_spec *spec = codec->spec;
3391 codec_dbg(codec, "---- dspload_post_setup ------\n");
3392 if (!ca0132_use_alt_functions(spec)) {
3393 /*set DSP speaker to 2.0 configuration*/
3394 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3395 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3397 /*update write pointer*/
3398 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3403 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3405 * @codec: the HDA codec
3406 * @fls: pointer to a fast load image
3407 * @ovly: TRUE if overlay format is required
3408 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3410 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3411 * @router_chans: number of audio router channels to be allocated (0 means use
3412 * internal defaults; max is 32)
3414 * Download DSP from a DSP Image Fast Load structure. This structure is a
3415 * linear, non-constant sized element array of structures, each of which
3416 * contain the count of the data to be loaded, the data itself, and the
3417 * corresponding starting chip address of the starting data location.
3418 * Returns zero or a negative error code.
3420 static int dspload_image(struct hda_codec *codec,
3421 const struct dsp_image_seg *fls,
3428 unsigned int sample_rate;
3429 unsigned short channels;
3431 codec_dbg(codec, "---- dspload_image begin ------\n");
3432 if (router_chans == 0) {
3434 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3436 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3439 sample_rate = 48000;
3440 channels = (unsigned short)router_chans;
3442 while (channels > 16) {
3448 codec_dbg(codec, "Ready to program DMA\n");
3450 status = dsp_reset(codec);
3455 codec_dbg(codec, "dsp_reset() complete\n");
3456 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3462 codec_dbg(codec, "dspxfr_image() complete\n");
3463 if (autostart && !ovly) {
3464 dspload_post_setup(codec);
3465 status = dsp_set_run_state(codec);
3468 codec_dbg(codec, "LOAD FINISHED\n");
3474 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3475 static bool dspload_is_loaded(struct hda_codec *codec)
3477 unsigned int data = 0;
3480 status = chipio_read(codec, 0x40004, &data);
3481 if ((status < 0) || (data != 1))
3487 #define dspload_is_loaded(codec) false
3490 static bool dspload_wait_loaded(struct hda_codec *codec)
3492 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3495 if (dspload_is_loaded(codec)) {
3496 codec_info(codec, "ca0132 DSP downloaded and running\n");
3500 } while (time_before(jiffies, timeout));
3502 codec_err(codec, "ca0132 failed to download DSP\n");
3507 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3508 * based cards, and has a second mmio region, region2, that's used for special
3513 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3514 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3515 * The first eight bits are just the number of the pin. So far, I've only seen
3516 * this number go to 7.
3517 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3518 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3519 * then off to send that bit.
3521 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3524 struct ca0132_spec *spec = codec->spec;
3525 unsigned short gpio_data;
3527 gpio_data = gpio_pin & 0xF;
3528 gpio_data |= ((enable << 8) & 0x100);
3530 writew(gpio_data, spec->mem_base + 0x320);
3534 * Special pci region2 commands that are only used by the AE-5. They follow
3535 * a set format, and require reads at certain points to seemingly 'clear'
3536 * the response data. My first tests didn't do these reads, and would cause
3537 * the card to get locked up until the memory was read. These commands
3538 * seem to work with three distinct values that I've taken to calling group,
3539 * target-id, and value.
3541 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3542 unsigned int target, unsigned int value)
3544 struct ca0132_spec *spec = codec->spec;
3545 unsigned int write_val;
3547 writel(0x0000007e, spec->mem_base + 0x210);
3548 readl(spec->mem_base + 0x210);
3549 writel(0x0000005a, spec->mem_base + 0x210);
3550 readl(spec->mem_base + 0x210);
3551 readl(spec->mem_base + 0x210);
3553 writel(0x00800005, spec->mem_base + 0x20c);
3554 writel(group, spec->mem_base + 0x804);
3556 writel(0x00800005, spec->mem_base + 0x20c);
3557 write_val = (target & 0xff);
3558 write_val |= (value << 8);
3561 writel(write_val, spec->mem_base + 0x204);
3563 * Need delay here or else it goes too fast and works inconsistently.
3567 readl(spec->mem_base + 0x860);
3568 readl(spec->mem_base + 0x854);
3569 readl(spec->mem_base + 0x840);
3571 writel(0x00800004, spec->mem_base + 0x20c);
3572 writel(0x00000000, spec->mem_base + 0x210);
3573 readl(spec->mem_base + 0x210);
3574 readl(spec->mem_base + 0x210);
3578 * This second type of command is used for setting the sound filter type.
3580 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3581 unsigned int group, unsigned int target, unsigned int value)
3583 struct ca0132_spec *spec = codec->spec;
3584 unsigned int write_val;
3586 writel(0x0000007e, spec->mem_base + 0x210);
3587 readl(spec->mem_base + 0x210);
3588 writel(0x0000005a, spec->mem_base + 0x210);
3589 readl(spec->mem_base + 0x210);
3590 readl(spec->mem_base + 0x210);
3592 writel(0x00800003, spec->mem_base + 0x20c);
3593 writel(group, spec->mem_base + 0x804);
3595 writel(0x00800005, spec->mem_base + 0x20c);
3596 write_val = (target & 0xff);
3597 write_val |= (value << 8);
3600 writel(write_val, spec->mem_base + 0x204);
3602 readl(spec->mem_base + 0x860);
3603 readl(spec->mem_base + 0x854);
3604 readl(spec->mem_base + 0x840);
3606 writel(0x00800004, spec->mem_base + 0x20c);
3607 writel(0x00000000, spec->mem_base + 0x210);
3608 readl(spec->mem_base + 0x210);
3609 readl(spec->mem_base + 0x210);
3613 * Setup GPIO for the other variants of Core3D.
3617 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3618 * the card shows as having no GPIO pins.
3620 static void ca0132_gpio_init(struct hda_codec *codec)
3622 struct ca0132_spec *spec = codec->spec;
3624 switch (ca0132_quirk(spec)) {
3628 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3629 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3630 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3633 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3634 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3642 /* Sets the GPIO for audio output. */
3643 static void ca0132_gpio_setup(struct hda_codec *codec)
3645 struct ca0132_spec *spec = codec->spec;
3647 switch (ca0132_quirk(spec)) {
3649 snd_hda_codec_write(codec, 0x01, 0,
3650 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3651 snd_hda_codec_write(codec, 0x01, 0,
3652 AC_VERB_SET_GPIO_MASK, 0x07);
3653 snd_hda_codec_write(codec, 0x01, 0,
3654 AC_VERB_SET_GPIO_DATA, 0x04);
3655 snd_hda_codec_write(codec, 0x01, 0,
3656 AC_VERB_SET_GPIO_DATA, 0x06);
3659 snd_hda_codec_write(codec, 0x01, 0,
3660 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3661 snd_hda_codec_write(codec, 0x01, 0,
3662 AC_VERB_SET_GPIO_MASK, 0x1F);
3663 snd_hda_codec_write(codec, 0x01, 0,
3664 AC_VERB_SET_GPIO_DATA, 0x0C);
3672 * GPIO control functions for the Recon3D integrated.
3675 enum r3di_gpio_bit {
3676 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3677 R3DI_MIC_SELECT_BIT = 1,
3678 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3679 R3DI_OUT_SELECT_BIT = 2,
3681 * I dunno what this actually does, but it stays on until the dsp
3684 R3DI_GPIO_DSP_DOWNLOADING = 3,
3686 * Same as above, no clue what it does, but it comes on after the dsp
3689 R3DI_GPIO_DSP_DOWNLOADED = 4
3692 enum r3di_mic_select {
3693 /* Set GPIO bit 1 to 0 for rear mic */
3695 /* Set GPIO bit 1 to 1 for front microphone*/
3699 enum r3di_out_select {
3700 /* Set GPIO bit 2 to 0 for headphone */
3701 R3DI_HEADPHONE_OUT = 0,
3702 /* Set GPIO bit 2 to 1 for speaker */
3705 enum r3di_dsp_status {
3706 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3707 R3DI_DSP_DOWNLOADING = 0,
3708 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3709 R3DI_DSP_DOWNLOADED = 1
3713 static void r3di_gpio_mic_set(struct hda_codec *codec,
3714 enum r3di_mic_select cur_mic)
3716 unsigned int cur_gpio;
3718 /* Get the current GPIO Data setup */
3719 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3723 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3725 case R3DI_FRONT_MIC:
3726 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3729 snd_hda_codec_write(codec, codec->core.afg, 0,
3730 AC_VERB_SET_GPIO_DATA, cur_gpio);
3733 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3734 enum r3di_dsp_status dsp_status)
3736 unsigned int cur_gpio;
3738 /* Get the current GPIO Data setup */
3739 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3741 switch (dsp_status) {
3742 case R3DI_DSP_DOWNLOADING:
3743 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3744 snd_hda_codec_write(codec, codec->core.afg, 0,
3745 AC_VERB_SET_GPIO_DATA, cur_gpio);
3747 case R3DI_DSP_DOWNLOADED:
3748 /* Set DOWNLOADING bit to 0. */
3749 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3751 snd_hda_codec_write(codec, codec->core.afg, 0,
3752 AC_VERB_SET_GPIO_DATA, cur_gpio);
3754 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3758 snd_hda_codec_write(codec, codec->core.afg, 0,
3759 AC_VERB_SET_GPIO_DATA, cur_gpio);
3765 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3766 struct hda_codec *codec,
3767 unsigned int stream_tag,
3768 unsigned int format,
3769 struct snd_pcm_substream *substream)
3771 struct ca0132_spec *spec = codec->spec;
3773 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3778 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3779 struct hda_codec *codec,
3780 struct snd_pcm_substream *substream)
3782 struct ca0132_spec *spec = codec->spec;
3784 if (spec->dsp_state == DSP_DOWNLOADING)
3787 /*If Playback effects are on, allow stream some time to flush
3789 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3792 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3797 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3798 struct hda_codec *codec,
3799 struct snd_pcm_substream *substream)
3801 struct ca0132_spec *spec = codec->spec;
3802 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3803 struct snd_pcm_runtime *runtime = substream->runtime;
3805 if (spec->dsp_state != DSP_DOWNLOADED)
3808 /* Add latency if playback enhancement and either effect is enabled. */
3809 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3810 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3811 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3812 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3815 /* Applying Speaker EQ adds latency as well. */
3816 if (spec->cur_out_type == SPEAKER_OUT)
3817 latency += DSP_SPEAKER_OUT_LATENCY;
3819 return (latency * runtime->rate) / 1000;
3825 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3826 struct hda_codec *codec,
3827 struct snd_pcm_substream *substream)
3829 struct ca0132_spec *spec = codec->spec;
3830 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3833 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3834 struct hda_codec *codec,
3835 unsigned int stream_tag,
3836 unsigned int format,
3837 struct snd_pcm_substream *substream)
3839 struct ca0132_spec *spec = codec->spec;
3840 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3841 stream_tag, format, substream);
3844 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3845 struct hda_codec *codec,
3846 struct snd_pcm_substream *substream)
3848 struct ca0132_spec *spec = codec->spec;
3849 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3852 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3853 struct hda_codec *codec,
3854 struct snd_pcm_substream *substream)
3856 struct ca0132_spec *spec = codec->spec;
3857 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3863 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3864 struct hda_codec *codec,
3865 unsigned int stream_tag,
3866 unsigned int format,
3867 struct snd_pcm_substream *substream)
3869 snd_hda_codec_setup_stream(codec, hinfo->nid,
3870 stream_tag, 0, format);
3875 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3876 struct hda_codec *codec,
3877 struct snd_pcm_substream *substream)
3879 struct ca0132_spec *spec = codec->spec;
3881 if (spec->dsp_state == DSP_DOWNLOADING)
3884 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3888 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
3889 struct hda_codec *codec,
3890 struct snd_pcm_substream *substream)
3892 struct ca0132_spec *spec = codec->spec;
3893 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
3894 struct snd_pcm_runtime *runtime = substream->runtime;
3896 if (spec->dsp_state != DSP_DOWNLOADED)
3899 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3900 latency += DSP_CRYSTAL_VOICE_LATENCY;
3902 return (latency * runtime->rate) / 1000;
3910 * Mixer controls helpers.
3912 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
3913 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3915 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3916 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3917 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3918 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3919 .info = ca0132_volume_info, \
3920 .get = ca0132_volume_get, \
3921 .put = ca0132_volume_put, \
3922 .tlv = { .c = ca0132_volume_tlv }, \
3923 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3926 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
3927 * volume put, which is used for setting the DSP volume. This was done because
3928 * the ca0132 functions were taking too much time and causing lag.
3930 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
3931 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3933 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3934 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3935 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3936 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3937 .info = snd_hda_mixer_amp_volume_info, \
3938 .get = snd_hda_mixer_amp_volume_get, \
3939 .put = ca0132_alt_volume_put, \
3940 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
3941 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3943 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
3944 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3946 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3947 .info = snd_hda_mixer_amp_switch_info, \
3948 .get = ca0132_switch_get, \
3949 .put = ca0132_switch_put, \
3950 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3953 #define CA0132_CODEC_VOL(xname, nid, dir) \
3954 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
3955 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
3956 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
3957 #define CA0132_CODEC_MUTE(xname, nid, dir) \
3958 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
3962 * Lookup table with decibel values for the DSP. When volume is changed in
3963 * Windows, the DSP is also sent the dB value in floating point. In Windows,
3964 * these values have decimal points, probably because the Windows driver
3965 * actually uses floating point. We can't here, so I made a lookup table of
3966 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
3967 * DAC's, and 9 is the maximum.
3969 static const unsigned int float_vol_db_lookup[] = {
3970 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
3971 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
3972 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
3973 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
3974 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
3975 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
3976 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
3977 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
3978 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
3979 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
3980 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
3981 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3982 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3983 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3984 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3985 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3986 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
3990 * This table counts from float 0 to 1 in increments of .01, which is
3991 * useful for a few different sliders.
3993 static const unsigned int float_zero_to_one_lookup[] = {
3994 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3995 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3996 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3997 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3998 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3999 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4000 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4001 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4002 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4003 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4004 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4005 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4006 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4007 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4008 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4009 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4010 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4014 * This table counts from float 10 to 1000, which is the range of the x-bass
4015 * crossover slider in Windows.
4017 static const unsigned int float_xbass_xover_lookup[] = {
4018 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
4019 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
4020 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
4021 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
4022 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
4023 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
4024 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
4025 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
4026 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
4027 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
4028 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
4029 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
4030 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
4031 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
4032 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
4033 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
4034 0x44728000, 0x44750000, 0x44778000, 0x447A0000
4037 /* The following are for tuning of products */
4038 #ifdef ENABLE_TUNING_CONTROLS
4040 static const unsigned int voice_focus_vals_lookup[] = {
4041 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
4042 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
4043 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
4044 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
4045 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
4046 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
4047 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
4048 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
4049 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
4050 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
4051 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
4052 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
4053 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
4054 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
4055 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
4056 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
4057 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
4058 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
4059 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
4060 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
4061 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
4062 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
4063 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
4064 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
4065 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
4066 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
4067 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
4070 static const unsigned int mic_svm_vals_lookup[] = {
4071 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
4072 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
4073 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
4074 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
4075 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
4076 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4077 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4078 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4079 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4080 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4081 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4082 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4083 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4084 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4085 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4086 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4087 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4090 static const unsigned int equalizer_vals_lookup[] = {
4091 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
4092 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
4093 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
4094 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
4095 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
4096 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
4097 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
4098 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
4102 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
4103 const unsigned int *lookup, int idx)
4107 for (i = 0; i < TUNING_CTLS_COUNT; i++)
4108 if (nid == ca0132_tuning_ctls[i].nid)
4111 snd_hda_power_up(codec);
4112 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
4113 ca0132_tuning_ctls[i].req,
4114 &(lookup[idx]), sizeof(unsigned int));
4115 snd_hda_power_down(codec);
4120 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
4121 struct snd_ctl_elem_value *ucontrol)
4123 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4124 struct ca0132_spec *spec = codec->spec;
4125 hda_nid_t nid = get_amp_nid(kcontrol);
4126 long *valp = ucontrol->value.integer.value;
4127 int idx = nid - TUNING_CTL_START_NID;
4129 *valp = spec->cur_ctl_vals[idx];
4133 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
4134 struct snd_ctl_elem_info *uinfo)
4136 int chs = get_amp_channels(kcontrol);
4137 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4138 uinfo->count = chs == 3 ? 2 : 1;
4139 uinfo->value.integer.min = 20;
4140 uinfo->value.integer.max = 180;
4141 uinfo->value.integer.step = 1;
4146 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
4147 struct snd_ctl_elem_value *ucontrol)
4149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4150 struct ca0132_spec *spec = codec->spec;
4151 hda_nid_t nid = get_amp_nid(kcontrol);
4152 long *valp = ucontrol->value.integer.value;
4155 idx = nid - TUNING_CTL_START_NID;
4157 if (spec->cur_ctl_vals[idx] == *valp)
4160 spec->cur_ctl_vals[idx] = *valp;
4163 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
4168 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
4169 struct snd_ctl_elem_info *uinfo)
4171 int chs = get_amp_channels(kcontrol);
4172 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4173 uinfo->count = chs == 3 ? 2 : 1;
4174 uinfo->value.integer.min = 0;
4175 uinfo->value.integer.max = 100;
4176 uinfo->value.integer.step = 1;
4181 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
4182 struct snd_ctl_elem_value *ucontrol)
4184 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4185 struct ca0132_spec *spec = codec->spec;
4186 hda_nid_t nid = get_amp_nid(kcontrol);
4187 long *valp = ucontrol->value.integer.value;
4190 idx = nid - TUNING_CTL_START_NID;
4192 if (spec->cur_ctl_vals[idx] == *valp)
4195 spec->cur_ctl_vals[idx] = *valp;
4198 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
4203 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
4204 struct snd_ctl_elem_info *uinfo)
4206 int chs = get_amp_channels(kcontrol);
4207 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4208 uinfo->count = chs == 3 ? 2 : 1;
4209 uinfo->value.integer.min = 0;
4210 uinfo->value.integer.max = 48;
4211 uinfo->value.integer.step = 1;
4216 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
4217 struct snd_ctl_elem_value *ucontrol)
4219 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4220 struct ca0132_spec *spec = codec->spec;
4221 hda_nid_t nid = get_amp_nid(kcontrol);
4222 long *valp = ucontrol->value.integer.value;
4225 idx = nid - TUNING_CTL_START_NID;
4227 if (spec->cur_ctl_vals[idx] == *valp)
4230 spec->cur_ctl_vals[idx] = *valp;
4233 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
4238 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
4239 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
4241 static int add_tuning_control(struct hda_codec *codec,
4242 hda_nid_t pnid, hda_nid_t nid,
4243 const char *name, int dir)
4245 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
4246 int type = dir ? HDA_INPUT : HDA_OUTPUT;
4247 struct snd_kcontrol_new knew =
4248 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
4250 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
4251 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
4256 knew.info = voice_focus_ctl_info;
4257 knew.get = tuning_ctl_get;
4258 knew.put = voice_focus_ctl_put;
4259 knew.tlv.p = voice_focus_db_scale;
4262 knew.info = mic_svm_ctl_info;
4263 knew.get = tuning_ctl_get;
4264 knew.put = mic_svm_ctl_put;
4267 knew.info = equalizer_ctl_info;
4268 knew.get = tuning_ctl_get;
4269 knew.put = equalizer_ctl_put;
4270 knew.tlv.p = eq_db_scale;
4275 knew.private_value =
4276 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
4277 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
4278 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
4281 static int add_tuning_ctls(struct hda_codec *codec)
4286 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
4287 err = add_tuning_control(codec,
4288 ca0132_tuning_ctls[i].parent_nid,
4289 ca0132_tuning_ctls[i].nid,
4290 ca0132_tuning_ctls[i].name,
4291 ca0132_tuning_ctls[i].direct);
4299 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
4301 struct ca0132_spec *spec = codec->spec;
4304 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
4305 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
4306 /* SVM level defaults to 0.74. */
4307 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
4309 /* EQ defaults to 0dB. */
4310 for (i = 2; i < TUNING_CTLS_COUNT; i++)
4311 spec->cur_ctl_vals[i] = 24;
4313 #endif /*ENABLE_TUNING_CONTROLS*/
4316 * Select the active output.
4317 * If autodetect is enabled, output will be selected based on jack detection.
4318 * If jack inserted, headphone will be selected, else built-in speakers
4319 * If autodetect is disabled, output will be selected based on selection.
4321 static int ca0132_select_out(struct hda_codec *codec)
4323 struct ca0132_spec *spec = codec->spec;
4324 unsigned int pin_ctl;
4330 codec_dbg(codec, "ca0132_select_out\n");
4332 snd_hda_power_up_pm(codec);
4334 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4337 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
4340 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
4343 spec->cur_out_type = HEADPHONE_OUT;
4345 spec->cur_out_type = SPEAKER_OUT;
4347 if (spec->cur_out_type == SPEAKER_OUT) {
4348 codec_dbg(codec, "ca0132_select_out speaker\n");
4349 /*speaker out config*/
4351 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4354 /*enable speaker EQ*/
4356 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4361 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4362 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4363 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4364 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4365 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4366 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4367 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4368 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4370 /* disable headphone node */
4371 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4372 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4373 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4375 /* enable speaker node */
4376 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4377 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4378 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4381 codec_dbg(codec, "ca0132_select_out hp\n");
4382 /*headphone out config*/
4384 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4387 /*disable speaker EQ*/
4389 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4394 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4395 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4396 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4397 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4398 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4399 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4400 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4401 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4403 /* disable speaker*/
4404 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4405 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4406 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4408 /* enable headphone*/
4409 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4410 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4411 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4416 snd_hda_power_down_pm(codec);
4418 return err < 0 ? err : 0;
4421 static int ae5_headphone_gain_set(struct hda_codec *codec, long val);
4422 static int zxr_headphone_gain_set(struct hda_codec *codec, long val);
4423 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4425 static void ae5_mmio_select_out(struct hda_codec *codec)
4427 struct ca0132_spec *spec = codec->spec;
4428 const struct ae_ca0113_output_set *out_cmds;
4431 if (ca0132_quirk(spec) == QUIRK_AE5)
4432 out_cmds = &ae5_ca0113_output_presets;
4434 out_cmds = &ae7_ca0113_output_presets;
4436 for (i = 0; i < AE_CA0113_OUT_SET_COMMANDS; i++)
4437 ca0113_mmio_command_set(codec, out_cmds->group[i],
4438 out_cmds->target[i],
4439 out_cmds->vals[spec->cur_out_type][i]);
4442 static int ca0132_alt_set_full_range_speaker(struct hda_codec *codec)
4444 struct ca0132_spec *spec = codec->spec;
4445 int quirk = ca0132_quirk(spec);
4449 /* 2.0/4.0 setup has no LFE channel, so setting full-range does nothing. */
4450 if (spec->channel_cfg_val == SPEAKER_CHANNELS_4_0
4451 || spec->channel_cfg_val == SPEAKER_CHANNELS_2_0)
4454 /* Set front L/R full range. Zero for full-range, one for redirection. */
4455 tmp = spec->speaker_range_val[0] ? FLOAT_ZERO : FLOAT_ONE;
4456 err = dspio_set_uint_param(codec, 0x96,
4457 SPEAKER_FULL_RANGE_FRONT_L_R, tmp);
4461 /* When setting full-range rear, both rear and center/lfe are set. */
4462 tmp = spec->speaker_range_val[1] ? FLOAT_ZERO : FLOAT_ONE;
4463 err = dspio_set_uint_param(codec, 0x96,
4464 SPEAKER_FULL_RANGE_CENTER_LFE, tmp);
4468 err = dspio_set_uint_param(codec, 0x96,
4469 SPEAKER_FULL_RANGE_REAR_L_R, tmp);
4474 * Only the AE series cards set this value when setting full-range,
4475 * and it's always 1.0f.
4477 if (quirk == QUIRK_AE5 || quirk == QUIRK_AE7) {
4478 err = dspio_set_uint_param(codec, 0x96,
4479 SPEAKER_FULL_RANGE_SURROUND_L_R, FLOAT_ONE);
4487 static int ca0132_alt_surround_set_bass_redirection(struct hda_codec *codec,
4490 struct ca0132_spec *spec = codec->spec;
4494 if (val && spec->channel_cfg_val != SPEAKER_CHANNELS_4_0 &&
4495 spec->channel_cfg_val != SPEAKER_CHANNELS_2_0)
4500 err = dspio_set_uint_param(codec, 0x96, SPEAKER_BASS_REDIRECT, tmp);
4504 /* If it is enabled, make sure to set the crossover frequency. */
4506 tmp = float_xbass_xover_lookup[spec->xbass_xover_freq];
4507 err = dspio_set_uint_param(codec, 0x96,
4508 SPEAKER_BASS_REDIRECT_XOVER_FREQ, tmp);
4517 * These are the commands needed to setup output on each of the different card
4520 static void ca0132_alt_select_out_get_quirk_data(struct hda_codec *codec,
4521 const struct ca0132_alt_out_set_quirk_data **quirk_data)
4523 struct ca0132_spec *spec = codec->spec;
4524 int quirk = ca0132_quirk(spec);
4528 for (i = 0; i < ARRAY_SIZE(quirk_out_set_data); i++) {
4529 if (quirk_out_set_data[i].quirk_id == quirk) {
4530 *quirk_data = &quirk_out_set_data[i];
4536 static int ca0132_alt_select_out_quirk_set(struct hda_codec *codec)
4538 const struct ca0132_alt_out_set_quirk_data *quirk_data;
4539 const struct ca0132_alt_out_set_info *out_info;
4540 struct ca0132_spec *spec = codec->spec;
4541 unsigned int i, gpio_data;
4544 ca0132_alt_select_out_get_quirk_data(codec, &quirk_data);
4548 out_info = &quirk_data->out_set_info[spec->cur_out_type];
4549 if (quirk_data->is_ae_series)
4550 ae5_mmio_select_out(codec);
4552 if (out_info->has_hda_gpio) {
4553 gpio_data = snd_hda_codec_read(codec, codec->core.afg, 0,
4554 AC_VERB_GET_GPIO_DATA, 0);
4556 if (out_info->hda_gpio_set)
4557 gpio_data |= (1 << out_info->hda_gpio_pin);
4559 gpio_data &= ~(1 << out_info->hda_gpio_pin);
4561 snd_hda_codec_write(codec, codec->core.afg, 0,
4562 AC_VERB_SET_GPIO_DATA, gpio_data);
4565 if (out_info->mmio_gpio_count) {
4566 for (i = 0; i < out_info->mmio_gpio_count; i++) {
4567 ca0113_mmio_gpio_set(codec, out_info->mmio_gpio_pin[i],
4568 out_info->mmio_gpio_set[i]);
4572 if (out_info->scp_cmds_count) {
4573 for (i = 0; i < out_info->scp_cmds_count; i++) {
4574 err = dspio_set_uint_param(codec,
4575 out_info->scp_cmd_mid[i],
4576 out_info->scp_cmd_req[i],
4577 out_info->scp_cmd_val[i]);
4583 chipio_set_control_param(codec, 0x0d, out_info->dac2port);
4585 if (out_info->has_chipio_write) {
4586 chipio_write(codec, out_info->chipio_write_addr,
4587 out_info->chipio_write_data);
4590 if (quirk_data->has_headphone_gain) {
4591 if (spec->cur_out_type != HEADPHONE_OUT) {
4592 if (quirk_data->is_ae_series)
4593 ae5_headphone_gain_set(codec, 2);
4595 zxr_headphone_gain_set(codec, 0);
4597 if (quirk_data->is_ae_series)
4598 ae5_headphone_gain_set(codec,
4599 spec->ae5_headphone_gain_val);
4601 zxr_headphone_gain_set(codec,
4602 spec->zxr_gain_set);
4609 static void ca0132_set_out_node_pincfg(struct hda_codec *codec, hda_nid_t nid,
4610 bool out_enable, bool hp_enable)
4612 unsigned int pin_ctl;
4614 pin_ctl = snd_hda_codec_read(codec, nid, 0,
4615 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4617 pin_ctl = hp_enable ? pin_ctl | PIN_HP_AMP : pin_ctl & ~PIN_HP_AMP;
4618 pin_ctl = out_enable ? pin_ctl | PIN_OUT : pin_ctl & ~PIN_OUT;
4619 snd_hda_set_pin_ctl(codec, nid, pin_ctl);
4623 * This function behaves similarly to the ca0132_select_out funciton above,
4624 * except with a few differences. It adds the ability to select the current
4625 * output with an enumerated control "output source" if the auto detect
4626 * mute switch is set to off. If the auto detect mute switch is enabled, it
4627 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
4628 * It also adds the ability to auto-detect the front headphone port.
4630 static int ca0132_alt_select_out(struct hda_codec *codec)
4632 struct ca0132_spec *spec = codec->spec;
4633 unsigned int tmp, outfx_set;
4637 /* Default Headphone is rear headphone */
4638 hda_nid_t headphone_nid = spec->out_pins[1];
4640 codec_dbg(codec, "%s\n", __func__);
4642 snd_hda_power_up_pm(codec);
4644 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4647 * If headphone rear or front is plugged in, set to headphone.
4648 * If neither is plugged in, set to rear line out. Only if
4649 * hp/speaker auto detect is enabled.
4652 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
4653 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
4656 spec->cur_out_type = HEADPHONE_OUT;
4658 spec->cur_out_type = SPEAKER_OUT;
4660 spec->cur_out_type = spec->out_enum_val;
4662 outfx_set = spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID];
4664 /* Begin DSP output switch, mute DSP volume. */
4665 err = dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_MUTE, FLOAT_ONE);
4669 if (ca0132_alt_select_out_quirk_set(codec) < 0)
4672 switch (spec->cur_out_type) {
4674 codec_dbg(codec, "%s speaker\n", __func__);
4677 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4678 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4680 /* Disable headphone node. */
4681 ca0132_set_out_node_pincfg(codec, spec->out_pins[1], 0, 0);
4682 /* Set front L-R to output. */
4683 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 1, 0);
4684 /* Set Center/LFE to output. */
4685 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 1, 0);
4686 /* Set rear surround to output. */
4687 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 1, 0);
4690 * Without PlayEnhancement being enabled, if we've got a 2.0
4691 * setup, set it to floating point eight to disable any DSP
4692 * processing effects.
4694 if (!outfx_set && spec->channel_cfg_val == SPEAKER_CHANNELS_2_0)
4697 tmp = speaker_channel_cfgs[spec->channel_cfg_val].val;
4699 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4705 codec_dbg(codec, "%s hp\n", __func__);
4706 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4707 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4709 /* Disable all speaker nodes. */
4710 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 0, 0);
4711 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 0, 0);
4712 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 0, 0);
4714 /* enable headphone, either front or rear */
4715 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4716 headphone_nid = spec->out_pins[2];
4717 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4718 headphone_nid = spec->out_pins[1];
4720 ca0132_set_out_node_pincfg(codec, headphone_nid, 1, 1);
4723 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4725 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4732 * If output effects are enabled, set the X-Bass effect value again to
4733 * make sure that it's properly enabled/disabled for speaker
4734 * configurations with an LFE channel.
4737 ca0132_effects_set(codec, X_BASS,
4738 spec->effects_switch[X_BASS - EFFECT_START_NID]);
4740 /* Set speaker EQ bypass attenuation to 0. */
4741 err = dspio_set_uint_param(codec, 0x8f, 0x01, FLOAT_ZERO);
4746 * Although unused on all cards but the AE series, this is always set
4747 * to zero when setting the output.
4749 err = dspio_set_uint_param(codec, 0x96,
4750 SPEAKER_TUNING_USE_SPEAKER_EQ, FLOAT_ZERO);
4754 if (spec->cur_out_type == SPEAKER_OUT)
4755 err = ca0132_alt_surround_set_bass_redirection(codec,
4756 spec->bass_redirection_val);
4758 err = ca0132_alt_surround_set_bass_redirection(codec, 0);
4760 /* Unmute DSP now that we're done with output selection. */
4761 err = dspio_set_uint_param(codec, 0x96,
4762 SPEAKER_TUNING_MUTE, FLOAT_ZERO);
4766 if (spec->cur_out_type == SPEAKER_OUT) {
4767 err = ca0132_alt_set_full_range_speaker(codec);
4773 snd_hda_power_down_pm(codec);
4775 return err < 0 ? err : 0;
4778 static void ca0132_unsol_hp_delayed(struct work_struct *work)
4780 struct ca0132_spec *spec = container_of(
4781 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
4782 struct hda_jack_tbl *jack;
4784 if (ca0132_use_alt_functions(spec))
4785 ca0132_alt_select_out(spec->codec);
4787 ca0132_select_out(spec->codec);
4789 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4791 jack->block_report = 0;
4792 snd_hda_jack_report_sync(spec->codec);
4796 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4797 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4798 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4799 static int stop_mic1(struct hda_codec *codec);
4800 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4801 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4804 * Select the active VIP source
4806 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4808 struct ca0132_spec *spec = codec->spec;
4811 if (spec->dsp_state != DSP_DOWNLOADED)
4814 /* if CrystalVoice if off, vipsource should be 0 */
4815 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4817 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4818 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4819 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4820 if (spec->cur_mic_type == DIGITAL_MIC)
4824 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4826 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4828 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4829 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4830 if (spec->cur_mic_type == DIGITAL_MIC)
4834 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4836 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4838 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4844 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4846 struct ca0132_spec *spec = codec->spec;
4849 if (spec->dsp_state != DSP_DOWNLOADED)
4852 codec_dbg(codec, "%s\n", __func__);
4854 chipio_set_stream_control(codec, 0x03, 0);
4855 chipio_set_stream_control(codec, 0x04, 0);
4857 /* if CrystalVoice is off, vipsource should be 0 */
4858 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4859 (val == 0) || spec->in_enum_val == REAR_LINE_IN) {
4860 codec_dbg(codec, "%s: off.", __func__);
4861 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4864 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4866 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4867 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4868 if (ca0132_quirk(spec) == QUIRK_R3DI)
4869 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4872 if (spec->in_enum_val == REAR_LINE_IN)
4875 if (ca0132_quirk(spec) == QUIRK_SBZ)
4881 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4884 codec_dbg(codec, "%s: on.", __func__);
4885 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4886 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4887 if (ca0132_quirk(spec) == QUIRK_R3DI)
4888 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
4890 if (spec->effects_switch[VOICE_FOCUS - EFFECT_START_NID])
4894 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4897 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4900 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4903 chipio_set_stream_control(codec, 0x03, 1);
4904 chipio_set_stream_control(codec, 0x04, 1);
4910 * Select the active microphone.
4911 * If autodetect is enabled, mic will be selected based on jack detection.
4912 * If jack inserted, ext.mic will be selected, else built-in mic
4913 * If autodetect is disabled, mic will be selected based on selection.
4915 static int ca0132_select_mic(struct hda_codec *codec)
4917 struct ca0132_spec *spec = codec->spec;
4921 codec_dbg(codec, "ca0132_select_mic\n");
4923 snd_hda_power_up_pm(codec);
4925 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
4928 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
4931 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
4934 spec->cur_mic_type = LINE_MIC_IN;
4936 spec->cur_mic_type = DIGITAL_MIC;
4938 if (spec->cur_mic_type == DIGITAL_MIC) {
4939 /* enable digital Mic */
4940 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
4941 ca0132_set_dmic(codec, 1);
4942 ca0132_mic_boost_set(codec, 0);
4943 /* set voice focus */
4944 ca0132_effects_set(codec, VOICE_FOCUS,
4945 spec->effects_switch
4946 [VOICE_FOCUS - EFFECT_START_NID]);
4948 /* disable digital Mic */
4949 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
4950 ca0132_set_dmic(codec, 0);
4951 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
4952 /* disable voice focus */
4953 ca0132_effects_set(codec, VOICE_FOCUS, 0);
4956 snd_hda_power_down_pm(codec);
4962 * Select the active input.
4963 * Mic detection isn't used, because it's kind of pointless on the SBZ.
4964 * The front mic has no jack-detection, so the only way to switch to it
4965 * is to do it manually in alsamixer.
4967 static int ca0132_alt_select_in(struct hda_codec *codec)
4969 struct ca0132_spec *spec = codec->spec;
4972 codec_dbg(codec, "%s\n", __func__);
4974 snd_hda_power_up_pm(codec);
4976 chipio_set_stream_control(codec, 0x03, 0);
4977 chipio_set_stream_control(codec, 0x04, 0);
4979 spec->cur_mic_type = spec->in_enum_val;
4981 switch (spec->cur_mic_type) {
4983 switch (ca0132_quirk(spec)) {
4986 ca0113_mmio_gpio_set(codec, 0, false);
4993 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4997 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5001 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5003 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5005 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5007 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5014 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5015 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5016 if (ca0132_quirk(spec) == QUIRK_R3DI)
5017 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5019 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5021 chipio_set_stream_control(codec, 0x03, 1);
5022 chipio_set_stream_control(codec, 0x04, 1);
5023 switch (ca0132_quirk(spec)) {
5025 chipio_write(codec, 0x18B098, 0x0000000C);
5026 chipio_write(codec, 0x18B09C, 0x0000000C);
5029 chipio_write(codec, 0x18B098, 0x0000000C);
5030 chipio_write(codec, 0x18B09C, 0x000000CC);
5033 chipio_write(codec, 0x18B098, 0x0000000C);
5034 chipio_write(codec, 0x18B09C, 0x0000004C);
5039 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5042 ca0132_mic_boost_set(codec, 0);
5043 switch (ca0132_quirk(spec)) {
5046 ca0113_mmio_gpio_set(codec, 0, false);
5049 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
5052 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5055 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5056 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5058 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5060 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5066 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5067 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5068 if (ca0132_quirk(spec) == QUIRK_R3DI)
5069 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5071 if (ca0132_quirk(spec) == QUIRK_AE7)
5075 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5077 switch (ca0132_quirk(spec)) {
5080 chipio_write(codec, 0x18B098, 0x00000000);
5081 chipio_write(codec, 0x18B09C, 0x00000000);
5086 chipio_set_stream_control(codec, 0x03, 1);
5087 chipio_set_stream_control(codec, 0x04, 1);
5090 switch (ca0132_quirk(spec)) {
5093 ca0113_mmio_gpio_set(codec, 0, true);
5094 ca0113_mmio_gpio_set(codec, 5, false);
5098 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
5102 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5110 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5111 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5112 if (ca0132_quirk(spec) == QUIRK_R3DI)
5113 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5115 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5117 chipio_set_stream_control(codec, 0x03, 1);
5118 chipio_set_stream_control(codec, 0x04, 1);
5120 switch (ca0132_quirk(spec)) {
5122 chipio_write(codec, 0x18B098, 0x0000000C);
5123 chipio_write(codec, 0x18B09C, 0x000000CC);
5126 chipio_write(codec, 0x18B098, 0x0000000C);
5127 chipio_write(codec, 0x18B09C, 0x0000004C);
5132 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5135 ca0132_cvoice_switch_set(codec);
5137 snd_hda_power_down_pm(codec);
5142 * Check if VNODE settings take effect immediately.
5144 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
5146 hda_nid_t *shared_nid)
5148 struct ca0132_spec *spec = codec->spec;
5153 nid = spec->shared_out_nid;
5156 nid = spec->shared_mic_nid;
5169 * The following functions are control change helpers.
5170 * They return 0 if no changed. Return 1 if changed.
5172 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
5174 struct ca0132_spec *spec = codec->spec;
5177 /* based on CrystalVoice state to enable VoiceFX. */
5179 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
5180 FLOAT_ONE : FLOAT_ZERO;
5185 dspio_set_uint_param(codec, ca0132_voicefx.mid,
5186 ca0132_voicefx.reqs[0], tmp);
5192 * Set the effects parameters
5194 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
5196 struct ca0132_spec *spec = codec->spec;
5197 unsigned int on, tmp, channel_cfg;
5198 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
5200 int idx = nid - EFFECT_START_NID;
5202 if ((idx < 0) || (idx >= num_fx))
5203 return 0; /* no changed */
5205 /* for out effect, qualify with PE */
5206 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
5207 /* if PE if off, turn off out effects. */
5208 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
5210 if (spec->cur_out_type == SPEAKER_OUT && nid == X_BASS) {
5211 channel_cfg = spec->channel_cfg_val;
5212 if (channel_cfg != SPEAKER_CHANNELS_2_0 &&
5213 channel_cfg != SPEAKER_CHANNELS_4_0)
5218 /* for in effect, qualify with CrystalVoice */
5219 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
5220 /* if CrystalVoice if off, turn off in effects. */
5221 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
5224 /* Voice Focus applies to 2-ch Mic, Digital Mic */
5225 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
5228 /* If Voice Focus on SBZ, set to two channel. */
5229 if ((nid == VOICE_FOCUS) && ca0132_use_pci_mmio(spec)
5230 && (spec->cur_mic_type != REAR_LINE_IN)) {
5231 if (spec->effects_switch[CRYSTAL_VOICE -
5232 EFFECT_START_NID]) {
5234 if (spec->effects_switch[VOICE_FOCUS -
5235 EFFECT_START_NID]) {
5241 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5245 * For SBZ noise reduction, there's an extra command
5246 * to module ID 0x47. No clue why.
5248 if ((nid == NOISE_REDUCTION) && ca0132_use_pci_mmio(spec)
5249 && (spec->cur_mic_type != REAR_LINE_IN)) {
5250 if (spec->effects_switch[CRYSTAL_VOICE -
5251 EFFECT_START_NID]) {
5252 if (spec->effects_switch[NOISE_REDUCTION -
5260 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
5263 /* If rear line in disable effects. */
5264 if (ca0132_use_alt_functions(spec) &&
5265 spec->in_enum_val == REAR_LINE_IN)
5269 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
5272 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
5273 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5274 ca0132_effects[idx].reqs[0], on);
5277 return 0; /* no changed */
5283 * Turn on/off Playback Enhancements
5285 static int ca0132_pe_switch_set(struct hda_codec *codec)
5287 struct ca0132_spec *spec = codec->spec;
5291 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
5292 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
5294 if (ca0132_use_alt_functions(spec))
5295 ca0132_alt_select_out(codec);
5297 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
5298 nid = OUT_EFFECT_START_NID;
5299 /* PE affects all out effects */
5300 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
5301 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5306 /* Check if Mic1 is streaming, if so, stop streaming */
5307 static int stop_mic1(struct hda_codec *codec)
5309 struct ca0132_spec *spec = codec->spec;
5310 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
5311 AC_VERB_GET_CONV, 0);
5313 snd_hda_codec_write(codec, spec->adcs[0], 0,
5314 AC_VERB_SET_CHANNEL_STREAMID,
5319 /* Resume Mic1 streaming if it was stopped. */
5320 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
5322 struct ca0132_spec *spec = codec->spec;
5323 /* Restore the previous stream and channel */
5325 snd_hda_codec_write(codec, spec->adcs[0], 0,
5326 AC_VERB_SET_CHANNEL_STREAMID,
5331 * Turn on/off CrystalVoice
5333 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
5335 struct ca0132_spec *spec = codec->spec;
5338 unsigned int oldval;
5340 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
5341 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
5343 i = IN_EFFECT_START_NID - EFFECT_START_NID;
5344 nid = IN_EFFECT_START_NID;
5345 /* CrystalVoice affects all in effects */
5346 for (; nid < IN_EFFECT_END_NID; nid++, i++)
5347 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5349 /* including VoiceFX */
5350 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
5352 /* set correct vipsource */
5353 oldval = stop_mic1(codec);
5354 if (ca0132_use_alt_functions(spec))
5355 ret |= ca0132_alt_set_vipsource(codec, 1);
5357 ret |= ca0132_set_vipsource(codec, 1);
5358 resume_mic1(codec, oldval);
5362 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
5364 struct ca0132_spec *spec = codec->spec;
5368 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5369 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
5371 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5372 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
5377 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
5379 struct ca0132_spec *spec = codec->spec;
5382 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5383 HDA_INPUT, 0, HDA_AMP_VOLMASK, val);
5387 static int ae5_headphone_gain_set(struct hda_codec *codec, long val)
5391 for (i = 0; i < 4; i++)
5392 ca0113_mmio_command_set(codec, 0x48, 0x11 + i,
5393 ae5_headphone_gain_presets[val].vals[i]);
5398 * gpio pin 1 is a relay that switches on/off, apparently setting the headphone
5399 * amplifier to handle a 600 ohm load.
5401 static int zxr_headphone_gain_set(struct hda_codec *codec, long val)
5403 ca0113_mmio_gpio_set(codec, 1, val);
5408 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
5409 struct snd_ctl_elem_value *ucontrol)
5411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5412 hda_nid_t nid = get_amp_nid(kcontrol);
5413 hda_nid_t shared_nid = 0;
5416 struct ca0132_spec *spec = codec->spec;
5419 if (nid == VNID_HP_SEL) {
5421 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5423 if (ca0132_use_alt_functions(spec))
5424 ca0132_alt_select_out(codec);
5426 ca0132_select_out(codec);
5431 if (nid == VNID_AMIC1_SEL) {
5433 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5435 ca0132_select_mic(codec);
5439 if (nid == VNID_HP_ASEL) {
5440 if (ca0132_use_alt_functions(spec))
5441 ca0132_alt_select_out(codec);
5443 ca0132_select_out(codec);
5447 if (nid == VNID_AMIC1_ASEL) {
5448 ca0132_select_mic(codec);
5452 /* if effective conditions, then update hw immediately. */
5453 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5455 int dir = get_amp_direction(kcontrol);
5456 int ch = get_amp_channels(kcontrol);
5459 mutex_lock(&codec->control_mutex);
5460 pval = kcontrol->private_value;
5461 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5463 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
5464 kcontrol->private_value = pval;
5465 mutex_unlock(&codec->control_mutex);
5470 /* End of control change helpers. */
5472 static void ca0132_alt_bass_redirection_xover_set(struct hda_codec *codec,
5475 snd_hda_power_up(codec);
5477 dspio_set_param(codec, 0x96, 0x20, SPEAKER_BASS_REDIRECT_XOVER_FREQ,
5478 &(float_xbass_xover_lookup[idx]), sizeof(unsigned int));
5480 snd_hda_power_down(codec);
5484 * Below I've added controls to mess with the effect levels, I've only enabled
5485 * them on the Sound Blaster Z, but they would probably also work on the
5486 * Chromebook. I figured they were probably tuned specifically for it, and left
5490 /* Sets DSP effect level from the sliders above the controls */
5492 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
5493 const unsigned int *lookup, int idx)
5498 * For X_BASS, req 2 is actually crossover freq instead of
5506 snd_hda_power_up(codec);
5507 if (nid == XBASS_XOVER) {
5508 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5509 if (ca0132_effects[i].nid == X_BASS)
5512 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5513 ca0132_effects[i].reqs[1],
5514 &(lookup[idx - 1]), sizeof(unsigned int));
5516 /* Find the actual effect structure */
5517 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5518 if (nid == ca0132_effects[i].nid)
5521 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5522 ca0132_effects[i].reqs[y],
5523 &(lookup[idx]), sizeof(unsigned int));
5526 snd_hda_power_down(codec);
5531 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol *kcontrol,
5532 struct snd_ctl_elem_value *ucontrol)
5534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5535 struct ca0132_spec *spec = codec->spec;
5536 long *valp = ucontrol->value.integer.value;
5537 hda_nid_t nid = get_amp_nid(kcontrol);
5539 if (nid == BASS_REDIRECTION_XOVER)
5540 *valp = spec->bass_redirect_xover_freq;
5542 *valp = spec->xbass_xover_freq;
5547 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol *kcontrol,
5548 struct snd_ctl_elem_value *ucontrol)
5550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5551 struct ca0132_spec *spec = codec->spec;
5552 hda_nid_t nid = get_amp_nid(kcontrol);
5553 long *valp = ucontrol->value.integer.value;
5554 int idx = nid - OUT_EFFECT_START_NID;
5556 *valp = spec->fx_ctl_val[idx];
5561 * The X-bass crossover starts at 10hz, so the min is 1. The
5562 * frequency is set in multiples of 10.
5564 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol *kcontrol,
5565 struct snd_ctl_elem_info *uinfo)
5567 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5569 uinfo->value.integer.min = 1;
5570 uinfo->value.integer.max = 100;
5571 uinfo->value.integer.step = 1;
5576 static int ca0132_alt_effect_slider_info(struct snd_kcontrol *kcontrol,
5577 struct snd_ctl_elem_info *uinfo)
5579 int chs = get_amp_channels(kcontrol);
5581 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5582 uinfo->count = chs == 3 ? 2 : 1;
5583 uinfo->value.integer.min = 0;
5584 uinfo->value.integer.max = 100;
5585 uinfo->value.integer.step = 1;
5590 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol *kcontrol,
5591 struct snd_ctl_elem_value *ucontrol)
5593 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5594 struct ca0132_spec *spec = codec->spec;
5595 hda_nid_t nid = get_amp_nid(kcontrol);
5596 long *valp = ucontrol->value.integer.value;
5600 if (nid == BASS_REDIRECTION_XOVER)
5601 cur_val = &spec->bass_redirect_xover_freq;
5603 cur_val = &spec->xbass_xover_freq;
5606 if (*cur_val == *valp)
5612 if (nid == BASS_REDIRECTION_XOVER)
5613 ca0132_alt_bass_redirection_xover_set(codec, *cur_val);
5615 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
5620 static int ca0132_alt_effect_slider_put(struct snd_kcontrol *kcontrol,
5621 struct snd_ctl_elem_value *ucontrol)
5623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5624 struct ca0132_spec *spec = codec->spec;
5625 hda_nid_t nid = get_amp_nid(kcontrol);
5626 long *valp = ucontrol->value.integer.value;
5629 idx = nid - EFFECT_START_NID;
5631 if (spec->fx_ctl_val[idx] == *valp)
5634 spec->fx_ctl_val[idx] = *valp;
5637 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
5644 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
5645 * only has off or full 30 dB, and didn't like making a volume slider that has
5646 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
5648 #define MIC_BOOST_NUM_OF_STEPS 4
5649 #define MIC_BOOST_ENUM_MAX_STRLEN 10
5651 static int ca0132_alt_mic_boost_info(struct snd_kcontrol *kcontrol,
5652 struct snd_ctl_elem_info *uinfo)
5655 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5657 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5659 uinfo->value.enumerated.items = MIC_BOOST_NUM_OF_STEPS;
5660 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS)
5661 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1;
5662 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx);
5663 strcpy(uinfo->value.enumerated.name, namestr);
5667 static int ca0132_alt_mic_boost_get(struct snd_kcontrol *kcontrol,
5668 struct snd_ctl_elem_value *ucontrol)
5670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5671 struct ca0132_spec *spec = codec->spec;
5673 ucontrol->value.enumerated.item[0] = spec->mic_boost_enum_val;
5677 static int ca0132_alt_mic_boost_put(struct snd_kcontrol *kcontrol,
5678 struct snd_ctl_elem_value *ucontrol)
5680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5681 struct ca0132_spec *spec = codec->spec;
5682 int sel = ucontrol->value.enumerated.item[0];
5683 unsigned int items = MIC_BOOST_NUM_OF_STEPS;
5688 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
5691 spec->mic_boost_enum_val = sel;
5693 if (spec->in_enum_val != REAR_LINE_IN)
5694 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5700 * Sound BlasterX AE-5 Headphone Gain Controls.
5702 #define AE5_HEADPHONE_GAIN_MAX 3
5703 static int ae5_headphone_gain_info(struct snd_kcontrol *kcontrol,
5704 struct snd_ctl_elem_info *uinfo)
5706 char *sfx = " Ohms)";
5707 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5709 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5711 uinfo->value.enumerated.items = AE5_HEADPHONE_GAIN_MAX;
5712 if (uinfo->value.enumerated.item >= AE5_HEADPHONE_GAIN_MAX)
5713 uinfo->value.enumerated.item = AE5_HEADPHONE_GAIN_MAX - 1;
5714 sprintf(namestr, "%s %s",
5715 ae5_headphone_gain_presets[uinfo->value.enumerated.item].name,
5717 strcpy(uinfo->value.enumerated.name, namestr);
5721 static int ae5_headphone_gain_get(struct snd_kcontrol *kcontrol,
5722 struct snd_ctl_elem_value *ucontrol)
5724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5725 struct ca0132_spec *spec = codec->spec;
5727 ucontrol->value.enumerated.item[0] = spec->ae5_headphone_gain_val;
5731 static int ae5_headphone_gain_put(struct snd_kcontrol *kcontrol,
5732 struct snd_ctl_elem_value *ucontrol)
5734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5735 struct ca0132_spec *spec = codec->spec;
5736 int sel = ucontrol->value.enumerated.item[0];
5737 unsigned int items = AE5_HEADPHONE_GAIN_MAX;
5742 codec_dbg(codec, "ae5_headphone_gain: boost=%d\n",
5745 spec->ae5_headphone_gain_val = sel;
5747 if (spec->out_enum_val == HEADPHONE_OUT)
5748 ae5_headphone_gain_set(codec, spec->ae5_headphone_gain_val);
5754 * Sound BlasterX AE-5 sound filter enumerated control.
5756 #define AE5_SOUND_FILTER_MAX 3
5758 static int ae5_sound_filter_info(struct snd_kcontrol *kcontrol,
5759 struct snd_ctl_elem_info *uinfo)
5761 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5763 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5765 uinfo->value.enumerated.items = AE5_SOUND_FILTER_MAX;
5766 if (uinfo->value.enumerated.item >= AE5_SOUND_FILTER_MAX)
5767 uinfo->value.enumerated.item = AE5_SOUND_FILTER_MAX - 1;
5768 sprintf(namestr, "%s",
5769 ae5_filter_presets[uinfo->value.enumerated.item].name);
5770 strcpy(uinfo->value.enumerated.name, namestr);
5774 static int ae5_sound_filter_get(struct snd_kcontrol *kcontrol,
5775 struct snd_ctl_elem_value *ucontrol)
5777 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5778 struct ca0132_spec *spec = codec->spec;
5780 ucontrol->value.enumerated.item[0] = spec->ae5_filter_val;
5784 static int ae5_sound_filter_put(struct snd_kcontrol *kcontrol,
5785 struct snd_ctl_elem_value *ucontrol)
5787 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5788 struct ca0132_spec *spec = codec->spec;
5789 int sel = ucontrol->value.enumerated.item[0];
5790 unsigned int items = AE5_SOUND_FILTER_MAX;
5795 codec_dbg(codec, "ae5_sound_filter: %s\n",
5796 ae5_filter_presets[sel].name);
5798 spec->ae5_filter_val = sel;
5800 ca0113_mmio_command_set_type2(codec, 0x48, 0x07,
5801 ae5_filter_presets[sel].val);
5807 * Input Select Control for alternative ca0132 codecs. This exists because
5808 * front microphone has no auto-detect, and we need a way to set the rear
5811 static int ca0132_alt_input_source_info(struct snd_kcontrol *kcontrol,
5812 struct snd_ctl_elem_info *uinfo)
5814 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5816 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS;
5817 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS)
5818 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1;
5819 strcpy(uinfo->value.enumerated.name,
5820 in_src_str[uinfo->value.enumerated.item]);
5824 static int ca0132_alt_input_source_get(struct snd_kcontrol *kcontrol,
5825 struct snd_ctl_elem_value *ucontrol)
5827 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5828 struct ca0132_spec *spec = codec->spec;
5830 ucontrol->value.enumerated.item[0] = spec->in_enum_val;
5834 static int ca0132_alt_input_source_put(struct snd_kcontrol *kcontrol,
5835 struct snd_ctl_elem_value *ucontrol)
5837 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5838 struct ca0132_spec *spec = codec->spec;
5839 int sel = ucontrol->value.enumerated.item[0];
5840 unsigned int items = IN_SRC_NUM_OF_INPUTS;
5843 * The AE-7 has no front microphone, so limit items to 2: rear mic and
5846 if (ca0132_quirk(spec) == QUIRK_AE7)
5852 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5853 sel, in_src_str[sel]);
5855 spec->in_enum_val = sel;
5857 ca0132_alt_select_in(codec);
5862 /* Sound Blaster Z Output Select Control */
5863 static int ca0132_alt_output_select_get_info(struct snd_kcontrol *kcontrol,
5864 struct snd_ctl_elem_info *uinfo)
5866 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5868 uinfo->value.enumerated.items = NUM_OF_OUTPUTS;
5869 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS)
5870 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1;
5871 strcpy(uinfo->value.enumerated.name,
5872 out_type_str[uinfo->value.enumerated.item]);
5876 static int ca0132_alt_output_select_get(struct snd_kcontrol *kcontrol,
5877 struct snd_ctl_elem_value *ucontrol)
5879 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5880 struct ca0132_spec *spec = codec->spec;
5882 ucontrol->value.enumerated.item[0] = spec->out_enum_val;
5886 static int ca0132_alt_output_select_put(struct snd_kcontrol *kcontrol,
5887 struct snd_ctl_elem_value *ucontrol)
5889 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5890 struct ca0132_spec *spec = codec->spec;
5891 int sel = ucontrol->value.enumerated.item[0];
5892 unsigned int items = NUM_OF_OUTPUTS;
5893 unsigned int auto_jack;
5898 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
5899 sel, out_type_str[sel]);
5901 spec->out_enum_val = sel;
5903 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5906 ca0132_alt_select_out(codec);
5911 /* Select surround output type: 2.1, 4.0, 4.1, or 5.1. */
5912 static int ca0132_alt_speaker_channel_cfg_get_info(struct snd_kcontrol *kcontrol,
5913 struct snd_ctl_elem_info *uinfo)
5915 unsigned int items = SPEAKER_CHANNEL_CFG_COUNT;
5917 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5919 uinfo->value.enumerated.items = items;
5920 if (uinfo->value.enumerated.item >= items)
5921 uinfo->value.enumerated.item = items - 1;
5922 strcpy(uinfo->value.enumerated.name,
5923 speaker_channel_cfgs[uinfo->value.enumerated.item].name);
5927 static int ca0132_alt_speaker_channel_cfg_get(struct snd_kcontrol *kcontrol,
5928 struct snd_ctl_elem_value *ucontrol)
5930 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5931 struct ca0132_spec *spec = codec->spec;
5933 ucontrol->value.enumerated.item[0] = spec->channel_cfg_val;
5937 static int ca0132_alt_speaker_channel_cfg_put(struct snd_kcontrol *kcontrol,
5938 struct snd_ctl_elem_value *ucontrol)
5940 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5941 struct ca0132_spec *spec = codec->spec;
5942 int sel = ucontrol->value.enumerated.item[0];
5943 unsigned int items = SPEAKER_CHANNEL_CFG_COUNT;
5948 codec_dbg(codec, "ca0132_alt_speaker_channels: sel=%d, channels=%s\n",
5949 sel, speaker_channel_cfgs[sel].name);
5951 spec->channel_cfg_val = sel;
5953 if (spec->out_enum_val == SPEAKER_OUT)
5954 ca0132_alt_select_out(codec);
5960 * Smart Volume output setting control. Three different settings, Normal,
5961 * which takes the value from the smart volume slider. The two others, loud
5962 * and night, disregard the slider value and have uneditable values.
5964 #define NUM_OF_SVM_SETTINGS 3
5965 static const char *const out_svm_set_enum_str[3] = {"Normal", "Loud", "Night" };
5967 static int ca0132_alt_svm_setting_info(struct snd_kcontrol *kcontrol,
5968 struct snd_ctl_elem_info *uinfo)
5970 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5972 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS;
5973 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS)
5974 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1;
5975 strcpy(uinfo->value.enumerated.name,
5976 out_svm_set_enum_str[uinfo->value.enumerated.item]);
5980 static int ca0132_alt_svm_setting_get(struct snd_kcontrol *kcontrol,
5981 struct snd_ctl_elem_value *ucontrol)
5983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5984 struct ca0132_spec *spec = codec->spec;
5986 ucontrol->value.enumerated.item[0] = spec->smart_volume_setting;
5990 static int ca0132_alt_svm_setting_put(struct snd_kcontrol *kcontrol,
5991 struct snd_ctl_elem_value *ucontrol)
5993 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5994 struct ca0132_spec *spec = codec->spec;
5995 int sel = ucontrol->value.enumerated.item[0];
5996 unsigned int items = NUM_OF_SVM_SETTINGS;
5997 unsigned int idx = SMART_VOLUME - EFFECT_START_NID;
6003 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
6004 sel, out_svm_set_enum_str[sel]);
6006 spec->smart_volume_setting = sel;
6022 /* Req 2 is the Smart Volume Setting req. */
6023 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
6024 ca0132_effects[idx].reqs[2], tmp);
6028 /* Sound Blaster Z EQ preset controls */
6029 static int ca0132_alt_eq_preset_info(struct snd_kcontrol *kcontrol,
6030 struct snd_ctl_elem_info *uinfo)
6032 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
6034 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6036 uinfo->value.enumerated.items = items;
6037 if (uinfo->value.enumerated.item >= items)
6038 uinfo->value.enumerated.item = items - 1;
6039 strcpy(uinfo->value.enumerated.name,
6040 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name);
6044 static int ca0132_alt_eq_preset_get(struct snd_kcontrol *kcontrol,
6045 struct snd_ctl_elem_value *ucontrol)
6047 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6048 struct ca0132_spec *spec = codec->spec;
6050 ucontrol->value.enumerated.item[0] = spec->eq_preset_val;
6054 static int ca0132_alt_eq_preset_put(struct snd_kcontrol *kcontrol,
6055 struct snd_ctl_elem_value *ucontrol)
6057 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6058 struct ca0132_spec *spec = codec->spec;
6060 int sel = ucontrol->value.enumerated.item[0];
6061 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
6066 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
6067 ca0132_alt_eq_presets[sel].name);
6070 * Default needs to qualify with CrystalVoice state.
6072 for (i = 0; i < EQ_PRESET_MAX_PARAM_COUNT; i++) {
6073 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
6074 ca0132_alt_eq_enum.reqs[i],
6075 ca0132_alt_eq_presets[sel].vals[i]);
6081 spec->eq_preset_val = sel;
6086 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
6087 struct snd_ctl_elem_info *uinfo)
6089 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
6091 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
6093 uinfo->value.enumerated.items = items;
6094 if (uinfo->value.enumerated.item >= items)
6095 uinfo->value.enumerated.item = items - 1;
6096 strcpy(uinfo->value.enumerated.name,
6097 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
6101 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
6102 struct snd_ctl_elem_value *ucontrol)
6104 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6105 struct ca0132_spec *spec = codec->spec;
6107 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
6111 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
6112 struct snd_ctl_elem_value *ucontrol)
6114 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6115 struct ca0132_spec *spec = codec->spec;
6117 int sel = ucontrol->value.enumerated.item[0];
6119 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
6122 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
6123 sel, ca0132_voicefx_presets[sel].name);
6127 * Default needs to qualify with CrystalVoice state.
6129 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
6130 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
6131 ca0132_voicefx.reqs[i],
6132 ca0132_voicefx_presets[sel].vals[i]);
6138 spec->voicefx_val = sel;
6139 /* enable voice fx */
6140 ca0132_voicefx_set(codec, (sel ? 1 : 0));
6146 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
6147 struct snd_ctl_elem_value *ucontrol)
6149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6150 struct ca0132_spec *spec = codec->spec;
6151 hda_nid_t nid = get_amp_nid(kcontrol);
6152 int ch = get_amp_channels(kcontrol);
6153 long *valp = ucontrol->value.integer.value;
6156 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
6158 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
6162 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
6168 /* effects, include PE and CrystalVoice */
6169 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
6170 *valp = spec->effects_switch[nid - EFFECT_START_NID];
6175 if (nid == spec->input_pins[0]) {
6176 *valp = spec->cur_mic_boost;
6180 if (nid == ZXR_HEADPHONE_GAIN) {
6181 *valp = spec->zxr_gain_set;
6185 if (nid == SPEAKER_FULL_RANGE_FRONT || nid == SPEAKER_FULL_RANGE_REAR) {
6186 *valp = spec->speaker_range_val[nid - SPEAKER_FULL_RANGE_FRONT];
6190 if (nid == BASS_REDIRECTION) {
6191 *valp = spec->bass_redirection_val;
6198 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
6199 struct snd_ctl_elem_value *ucontrol)
6201 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6202 struct ca0132_spec *spec = codec->spec;
6203 hda_nid_t nid = get_amp_nid(kcontrol);
6204 int ch = get_amp_channels(kcontrol);
6205 long *valp = ucontrol->value.integer.value;
6208 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
6211 snd_hda_power_up(codec);
6213 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
6215 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
6219 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
6222 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
6227 if (nid == PLAY_ENHANCEMENT) {
6228 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6229 changed = ca0132_pe_switch_set(codec);
6234 if (nid == CRYSTAL_VOICE) {
6235 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6236 changed = ca0132_cvoice_switch_set(codec);
6240 /* out and in effects */
6241 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
6242 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
6243 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
6244 changed = ca0132_effects_set(codec, nid, *valp);
6249 if (nid == spec->input_pins[0]) {
6250 spec->cur_mic_boost = *valp;
6251 if (ca0132_use_alt_functions(spec)) {
6252 if (spec->in_enum_val != REAR_LINE_IN)
6253 changed = ca0132_mic_boost_set(codec, *valp);
6255 /* Mic boost does not apply to Digital Mic */
6256 if (spec->cur_mic_type != DIGITAL_MIC)
6257 changed = ca0132_mic_boost_set(codec, *valp);
6263 if (nid == ZXR_HEADPHONE_GAIN) {
6264 spec->zxr_gain_set = *valp;
6265 if (spec->cur_out_type == HEADPHONE_OUT)
6266 changed = zxr_headphone_gain_set(codec, *valp);
6273 if (nid == SPEAKER_FULL_RANGE_FRONT || nid == SPEAKER_FULL_RANGE_REAR) {
6274 spec->speaker_range_val[nid - SPEAKER_FULL_RANGE_FRONT] = *valp;
6275 if (spec->cur_out_type == SPEAKER_OUT)
6276 ca0132_alt_set_full_range_speaker(codec);
6281 if (nid == BASS_REDIRECTION) {
6282 spec->bass_redirection_val = *valp;
6283 if (spec->cur_out_type == SPEAKER_OUT)
6284 ca0132_alt_surround_set_bass_redirection(codec, *valp);
6290 snd_hda_power_down(codec);
6298 * Sets the internal DSP decibel level to match the DAC for output, and the
6299 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
6300 * all alternative codecs set DSP playback volume.
6302 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
6304 struct ca0132_spec *spec = codec->spec;
6305 unsigned int dsp_dir;
6306 unsigned int lookup_val;
6308 if (nid == VNID_SPK)
6309 dsp_dir = DSP_VOL_OUT;
6311 dsp_dir = DSP_VOL_IN;
6313 lookup_val = spec->vnode_lvol[nid - VNODE_START_NID];
6315 dspio_set_uint_param(codec,
6316 ca0132_alt_vol_ctls[dsp_dir].mid,
6317 ca0132_alt_vol_ctls[dsp_dir].reqs[0],
6318 float_vol_db_lookup[lookup_val]);
6320 lookup_val = spec->vnode_rvol[nid - VNODE_START_NID];
6322 dspio_set_uint_param(codec,
6323 ca0132_alt_vol_ctls[dsp_dir].mid,
6324 ca0132_alt_vol_ctls[dsp_dir].reqs[1],
6325 float_vol_db_lookup[lookup_val]);
6327 dspio_set_uint_param(codec,
6328 ca0132_alt_vol_ctls[dsp_dir].mid,
6329 ca0132_alt_vol_ctls[dsp_dir].reqs[2], FLOAT_ZERO);
6332 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
6333 struct snd_ctl_elem_info *uinfo)
6335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6336 struct ca0132_spec *spec = codec->spec;
6337 hda_nid_t nid = get_amp_nid(kcontrol);
6338 int ch = get_amp_channels(kcontrol);
6339 int dir = get_amp_direction(kcontrol);
6345 /* follow shared_out info */
6346 nid = spec->shared_out_nid;
6347 mutex_lock(&codec->control_mutex);
6348 pval = kcontrol->private_value;
6349 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6350 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6351 kcontrol->private_value = pval;
6352 mutex_unlock(&codec->control_mutex);
6355 /* follow shared_mic info */
6356 nid = spec->shared_mic_nid;
6357 mutex_lock(&codec->control_mutex);
6358 pval = kcontrol->private_value;
6359 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6360 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6361 kcontrol->private_value = pval;
6362 mutex_unlock(&codec->control_mutex);
6365 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
6370 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
6371 struct snd_ctl_elem_value *ucontrol)
6373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6374 struct ca0132_spec *spec = codec->spec;
6375 hda_nid_t nid = get_amp_nid(kcontrol);
6376 int ch = get_amp_channels(kcontrol);
6377 long *valp = ucontrol->value.integer.value;
6379 /* store the left and right volume */
6381 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
6385 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
6391 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
6392 struct snd_ctl_elem_value *ucontrol)
6394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6395 struct ca0132_spec *spec = codec->spec;
6396 hda_nid_t nid = get_amp_nid(kcontrol);
6397 int ch = get_amp_channels(kcontrol);
6398 long *valp = ucontrol->value.integer.value;
6399 hda_nid_t shared_nid = 0;
6403 /* store the left and right volume */
6405 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
6409 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
6413 /* if effective conditions, then update hw immediately. */
6414 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
6416 int dir = get_amp_direction(kcontrol);
6419 snd_hda_power_up(codec);
6420 mutex_lock(&codec->control_mutex);
6421 pval = kcontrol->private_value;
6422 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
6424 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6425 kcontrol->private_value = pval;
6426 mutex_unlock(&codec->control_mutex);
6427 snd_hda_power_down(codec);
6434 * This function is the same as the one above, because using an if statement
6435 * inside of the above volume control for the DSP volume would cause too much
6436 * lag. This is a lot more smooth.
6438 static int ca0132_alt_volume_put(struct snd_kcontrol *kcontrol,
6439 struct snd_ctl_elem_value *ucontrol)
6441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6442 struct ca0132_spec *spec = codec->spec;
6443 hda_nid_t nid = get_amp_nid(kcontrol);
6444 int ch = get_amp_channels(kcontrol);
6445 long *valp = ucontrol->value.integer.value;
6458 /* store the left and right volume */
6460 spec->vnode_lvol[vnid - VNODE_START_NID] = *valp;
6464 spec->vnode_rvol[vnid - VNODE_START_NID] = *valp;
6468 snd_hda_power_up(codec);
6469 ca0132_alt_dsp_volume_put(codec, vnid);
6470 mutex_lock(&codec->control_mutex);
6471 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6472 mutex_unlock(&codec->control_mutex);
6473 snd_hda_power_down(codec);
6478 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
6479 unsigned int size, unsigned int __user *tlv)
6481 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6482 struct ca0132_spec *spec = codec->spec;
6483 hda_nid_t nid = get_amp_nid(kcontrol);
6484 int ch = get_amp_channels(kcontrol);
6485 int dir = get_amp_direction(kcontrol);
6491 /* follow shared_out tlv */
6492 nid = spec->shared_out_nid;
6493 mutex_lock(&codec->control_mutex);
6494 pval = kcontrol->private_value;
6495 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6496 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6497 kcontrol->private_value = pval;
6498 mutex_unlock(&codec->control_mutex);
6501 /* follow shared_mic tlv */
6502 nid = spec->shared_mic_nid;
6503 mutex_lock(&codec->control_mutex);
6504 pval = kcontrol->private_value;
6505 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6506 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6507 kcontrol->private_value = pval;
6508 mutex_unlock(&codec->control_mutex);
6511 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6516 /* Add volume slider control for effect level */
6517 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
6518 const char *pfx, int dir)
6520 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6521 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6522 struct snd_kcontrol_new knew =
6523 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
6525 sprintf(namestr, "FX: %s %s Volume", pfx, dirstr[dir]);
6531 knew.info = ca0132_alt_xbass_xover_slider_info;
6532 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6533 knew.put = ca0132_alt_xbass_xover_slider_put;
6536 knew.info = ca0132_alt_effect_slider_info;
6537 knew.get = ca0132_alt_slider_ctl_get;
6538 knew.put = ca0132_alt_effect_slider_put;
6539 knew.private_value =
6540 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
6544 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6548 * Added FX: prefix for the alternative codecs, because otherwise the surround
6549 * effect would conflict with the Surround sound volume control. Also seems more
6550 * clear as to what the switches do. Left alone for others.
6552 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
6553 const char *pfx, int dir)
6555 struct ca0132_spec *spec = codec->spec;
6556 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6557 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6558 struct snd_kcontrol_new knew =
6559 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
6560 /* If using alt_controls, add FX: prefix. But, don't add FX:
6561 * prefix to OutFX or InFX enable controls.
6563 if (ca0132_use_alt_controls(spec) && (nid <= IN_EFFECT_END_NID))
6564 sprintf(namestr, "FX: %s %s Switch", pfx, dirstr[dir]);
6566 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
6568 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6571 static int add_voicefx(struct hda_codec *codec)
6573 struct snd_kcontrol_new knew =
6574 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
6575 VOICEFX, 1, 0, HDA_INPUT);
6576 knew.info = ca0132_voicefx_info;
6577 knew.get = ca0132_voicefx_get;
6578 knew.put = ca0132_voicefx_put;
6579 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
6582 /* Create the EQ Preset control */
6583 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
6585 struct snd_kcontrol_new knew =
6586 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum.name,
6587 EQ_PRESET_ENUM, 1, 0, HDA_OUTPUT);
6588 knew.info = ca0132_alt_eq_preset_info;
6589 knew.get = ca0132_alt_eq_preset_get;
6590 knew.put = ca0132_alt_eq_preset_put;
6591 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
6592 snd_ctl_new1(&knew, codec));
6596 * Add enumerated control for the three different settings of the smart volume
6597 * output effect. Normal just uses the slider value, and loud and night are
6598 * their own things that ignore that value.
6600 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
6602 struct snd_kcontrol_new knew =
6603 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
6604 SMART_VOLUME_ENUM, 1, 0, HDA_OUTPUT);
6605 knew.info = ca0132_alt_svm_setting_info;
6606 knew.get = ca0132_alt_svm_setting_get;
6607 knew.put = ca0132_alt_svm_setting_put;
6608 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
6609 snd_ctl_new1(&knew, codec));
6614 * Create an Output Select enumerated control for codecs with surround
6617 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
6619 struct snd_kcontrol_new knew =
6620 HDA_CODEC_MUTE_MONO("Output Select",
6621 OUTPUT_SOURCE_ENUM, 1, 0, HDA_OUTPUT);
6622 knew.info = ca0132_alt_output_select_get_info;
6623 knew.get = ca0132_alt_output_select_get;
6624 knew.put = ca0132_alt_output_select_put;
6625 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
6626 snd_ctl_new1(&knew, codec));
6630 * Add a control for selecting channel count on speaker output. Setting this
6631 * allows the DSP to do bass redirection and channel upmixing on surround
6634 static int ca0132_alt_add_speaker_channel_cfg_enum(struct hda_codec *codec)
6636 struct snd_kcontrol_new knew =
6637 HDA_CODEC_MUTE_MONO("Surround Channel Config",
6638 SPEAKER_CHANNEL_CFG_ENUM, 1, 0, HDA_OUTPUT);
6639 knew.info = ca0132_alt_speaker_channel_cfg_get_info;
6640 knew.get = ca0132_alt_speaker_channel_cfg_get;
6641 knew.put = ca0132_alt_speaker_channel_cfg_put;
6642 return snd_hda_ctl_add(codec, SPEAKER_CHANNEL_CFG_ENUM,
6643 snd_ctl_new1(&knew, codec));
6647 * Full range front stereo and rear surround switches. When these are set to
6648 * full range, the lower frequencies from these channels are no longer
6649 * redirected to the LFE channel.
6651 static int ca0132_alt_add_front_full_range_switch(struct hda_codec *codec)
6653 struct snd_kcontrol_new knew =
6654 CA0132_CODEC_MUTE_MONO("Full-Range Front Speakers",
6655 SPEAKER_FULL_RANGE_FRONT, 1, HDA_OUTPUT);
6657 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_FRONT,
6658 snd_ctl_new1(&knew, codec));
6661 static int ca0132_alt_add_rear_full_range_switch(struct hda_codec *codec)
6663 struct snd_kcontrol_new knew =
6664 CA0132_CODEC_MUTE_MONO("Full-Range Rear Speakers",
6665 SPEAKER_FULL_RANGE_REAR, 1, HDA_OUTPUT);
6667 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_REAR,
6668 snd_ctl_new1(&knew, codec));
6672 * Bass redirection redirects audio below the crossover frequency to the LFE
6673 * channel on speakers that are set as not being full-range. On configurations
6674 * without an LFE channel, it does nothing. Bass redirection seems to be the
6675 * replacement for X-Bass on configurations with an LFE channel.
6677 static int ca0132_alt_add_bass_redirection_crossover(struct hda_codec *codec)
6679 const char *namestr = "Bass Redirection Crossover";
6680 struct snd_kcontrol_new knew =
6681 HDA_CODEC_VOLUME_MONO(namestr, BASS_REDIRECTION_XOVER, 1, 0,
6685 knew.info = ca0132_alt_xbass_xover_slider_info;
6686 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6687 knew.put = ca0132_alt_xbass_xover_slider_put;
6689 return snd_hda_ctl_add(codec, BASS_REDIRECTION_XOVER,
6690 snd_ctl_new1(&knew, codec));
6693 static int ca0132_alt_add_bass_redirection_switch(struct hda_codec *codec)
6695 const char *namestr = "Bass Redirection";
6696 struct snd_kcontrol_new knew =
6697 CA0132_CODEC_MUTE_MONO(namestr, BASS_REDIRECTION, 1,
6700 return snd_hda_ctl_add(codec, BASS_REDIRECTION,
6701 snd_ctl_new1(&knew, codec));
6705 * Create an Input Source enumerated control for the alternate ca0132 codecs
6706 * because the front microphone has no auto-detect, and Line-in has to be set
6709 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
6711 struct snd_kcontrol_new knew =
6712 HDA_CODEC_MUTE_MONO("Input Source",
6713 INPUT_SOURCE_ENUM, 1, 0, HDA_INPUT);
6714 knew.info = ca0132_alt_input_source_info;
6715 knew.get = ca0132_alt_input_source_get;
6716 knew.put = ca0132_alt_input_source_put;
6717 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
6718 snd_ctl_new1(&knew, codec));
6722 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
6723 * more control than the original mic boost, which is either full 30dB or off.
6725 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
6727 struct snd_kcontrol_new knew =
6728 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
6729 MIC_BOOST_ENUM, 1, 0, HDA_INPUT);
6730 knew.info = ca0132_alt_mic_boost_info;
6731 knew.get = ca0132_alt_mic_boost_get;
6732 knew.put = ca0132_alt_mic_boost_put;
6733 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
6734 snd_ctl_new1(&knew, codec));
6739 * Add headphone gain enumerated control for the AE-5. This switches between
6740 * three modes, low, medium, and high. When non-headphone outputs are selected,
6741 * it is automatically set to high. This is the same behavior as Windows.
6743 static int ae5_add_headphone_gain_enum(struct hda_codec *codec)
6745 struct snd_kcontrol_new knew =
6746 HDA_CODEC_MUTE_MONO("AE-5: Headphone Gain",
6747 AE5_HEADPHONE_GAIN_ENUM, 1, 0, HDA_OUTPUT);
6748 knew.info = ae5_headphone_gain_info;
6749 knew.get = ae5_headphone_gain_get;
6750 knew.put = ae5_headphone_gain_put;
6751 return snd_hda_ctl_add(codec, AE5_HEADPHONE_GAIN_ENUM,
6752 snd_ctl_new1(&knew, codec));
6756 * Add sound filter enumerated control for the AE-5. This adds three different
6757 * settings: Slow Roll Off, Minimum Phase, and Fast Roll Off. From what I've
6758 * read into it, it changes the DAC's interpolation filter.
6760 static int ae5_add_sound_filter_enum(struct hda_codec *codec)
6762 struct snd_kcontrol_new knew =
6763 HDA_CODEC_MUTE_MONO("AE-5: Sound Filter",
6764 AE5_SOUND_FILTER_ENUM, 1, 0, HDA_OUTPUT);
6765 knew.info = ae5_sound_filter_info;
6766 knew.get = ae5_sound_filter_get;
6767 knew.put = ae5_sound_filter_put;
6768 return snd_hda_ctl_add(codec, AE5_SOUND_FILTER_ENUM,
6769 snd_ctl_new1(&knew, codec));
6772 static int zxr_add_headphone_gain_switch(struct hda_codec *codec)
6774 struct snd_kcontrol_new knew =
6775 CA0132_CODEC_MUTE_MONO("ZxR: 600 Ohm Gain",
6776 ZXR_HEADPHONE_GAIN, 1, HDA_OUTPUT);
6778 return snd_hda_ctl_add(codec, ZXR_HEADPHONE_GAIN,
6779 snd_ctl_new1(&knew, codec));
6783 * Need to create follower controls for the alternate codecs that have surround
6786 static const char * const ca0132_alt_follower_pfxs[] = {
6787 "Front", "Surround", "Center", "LFE", NULL,
6791 * Also need special channel map, because the default one is incorrect.
6792 * I think this has to do with the pin for rear surround being 0x11,
6793 * and the center/lfe being 0x10. Usually the pin order is the opposite.
6795 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps[] = {
6797 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
6799 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6800 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6802 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6803 SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE,
6804 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6808 /* Add the correct chmap for streams with 6 channels. */
6809 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
6812 struct hda_pcm *pcm;
6814 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
6815 struct hda_pcm_stream *hinfo =
6816 &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
6817 struct snd_pcm_chmap *chmap;
6818 const struct snd_pcm_chmap_elem *elem;
6820 elem = ca0132_alt_chmaps;
6821 if (hinfo->channels_max == 6) {
6822 err = snd_pcm_add_chmap_ctls(pcm->pcm,
6823 SNDRV_PCM_STREAM_PLAYBACK,
6824 elem, hinfo->channels_max, 0, &chmap);
6826 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
6832 * When changing Node IDs for Mixer Controls below, make sure to update
6833 * Node IDs in ca0132_config() as well.
6835 static const struct snd_kcontrol_new ca0132_mixer[] = {
6836 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
6837 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
6838 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6839 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6840 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
6841 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
6842 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6843 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6844 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
6845 0x12, 1, HDA_INPUT),
6846 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
6847 VNID_HP_SEL, 1, HDA_OUTPUT),
6848 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
6849 VNID_AMIC1_SEL, 1, HDA_INPUT),
6850 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6851 VNID_HP_ASEL, 1, HDA_OUTPUT),
6852 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
6853 VNID_AMIC1_ASEL, 1, HDA_INPUT),
6858 * Desktop specific control mixer. Removes auto-detect for mic, and adds
6859 * surround controls. Also sets both the Front Playback and Capture Volume
6860 * controls to alt so they set the DSP's decibel level.
6862 static const struct snd_kcontrol_new desktop_mixer[] = {
6863 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6864 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6865 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6866 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6867 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6868 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6869 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6870 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6871 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT),
6872 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6873 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6874 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6875 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6876 VNID_HP_ASEL, 1, HDA_OUTPUT),
6881 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
6882 * because it doesn't set decibel levels for the DSP for capture.
6884 static const struct snd_kcontrol_new r3di_mixer[] = {
6885 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6886 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6887 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6888 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6889 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6890 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6891 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6892 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6893 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6894 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6895 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6896 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6897 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6898 VNID_HP_ASEL, 1, HDA_OUTPUT),
6902 static int ca0132_build_controls(struct hda_codec *codec)
6904 struct ca0132_spec *spec = codec->spec;
6905 int i, num_fx, num_sliders;
6908 /* Add Mixer controls */
6909 for (i = 0; i < spec->num_mixers; i++) {
6910 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
6914 /* Setup vmaster with surround followers for desktop ca0132 devices */
6915 if (ca0132_use_alt_functions(spec)) {
6916 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
6918 snd_hda_add_vmaster(codec, "Master Playback Volume",
6919 spec->tlv, ca0132_alt_follower_pfxs,
6921 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
6922 NULL, ca0132_alt_follower_pfxs,
6924 true, &spec->vmaster_mute.sw_kctl);
6929 /* Add in and out effects controls.
6930 * VoiceFX, PE and CrystalVoice are added separately.
6932 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
6933 for (i = 0; i < num_fx; i++) {
6934 /* Desktop cards break if Echo Cancellation is used. */
6935 if (ca0132_use_pci_mmio(spec)) {
6936 if (i == (ECHO_CANCELLATION - IN_EFFECT_START_NID +
6941 err = add_fx_switch(codec, ca0132_effects[i].nid,
6942 ca0132_effects[i].name,
6943 ca0132_effects[i].direct);
6948 * If codec has use_alt_controls set to true, add effect level sliders,
6949 * EQ presets, and Smart Volume presets. Also, change names to add FX
6950 * prefix, and change PlayEnhancement and CrystalVoice to match.
6952 if (ca0132_use_alt_controls(spec)) {
6953 err = ca0132_alt_add_svm_enum(codec);
6957 err = add_ca0132_alt_eq_presets(codec);
6961 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6966 err = add_fx_switch(codec, CRYSTAL_VOICE,
6971 num_sliders = OUT_EFFECTS_COUNT - 1;
6972 for (i = 0; i < num_sliders; i++) {
6973 err = ca0132_alt_add_effect_slider(codec,
6974 ca0132_effects[i].nid,
6975 ca0132_effects[i].name,
6976 ca0132_effects[i].direct);
6981 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
6982 "X-Bass Crossover", EFX_DIR_OUT);
6987 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6988 "PlayEnhancement", 0);
6992 err = add_fx_switch(codec, CRYSTAL_VOICE,
6997 err = add_voicefx(codec);
7002 * If the codec uses alt_functions, you need the enumerated controls
7003 * to select the new outputs and inputs, plus add the new mic boost
7006 if (ca0132_use_alt_functions(spec)) {
7007 err = ca0132_alt_add_output_enum(codec);
7010 err = ca0132_alt_add_speaker_channel_cfg_enum(codec);
7013 err = ca0132_alt_add_front_full_range_switch(codec);
7016 err = ca0132_alt_add_rear_full_range_switch(codec);
7019 err = ca0132_alt_add_bass_redirection_crossover(codec);
7022 err = ca0132_alt_add_bass_redirection_switch(codec);
7025 err = ca0132_alt_add_mic_boost_enum(codec);
7029 * ZxR only has microphone input, there is no front panel
7030 * header on the card, and aux-in is handled by the DBPro board.
7032 if (ca0132_quirk(spec) != QUIRK_ZXR) {
7033 err = ca0132_alt_add_input_enum(codec);
7039 switch (ca0132_quirk(spec)) {
7042 err = ae5_add_headphone_gain_enum(codec);
7045 err = ae5_add_sound_filter_enum(codec);
7050 err = zxr_add_headphone_gain_switch(codec);
7058 #ifdef ENABLE_TUNING_CONTROLS
7059 add_tuning_ctls(codec);
7062 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
7066 if (spec->dig_out) {
7067 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7071 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
7074 /* spec->multiout.share_spdif = 1; */
7078 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7083 if (ca0132_use_alt_functions(spec))
7084 ca0132_alt_add_chmap_ctls(codec);
7089 static int dbpro_build_controls(struct hda_codec *codec)
7091 struct ca0132_spec *spec = codec->spec;
7094 if (spec->dig_out) {
7095 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7102 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7113 static const struct hda_pcm_stream ca0132_pcm_analog_playback = {
7118 .prepare = ca0132_playback_pcm_prepare,
7119 .cleanup = ca0132_playback_pcm_cleanup,
7120 .get_delay = ca0132_playback_pcm_delay,
7124 static const struct hda_pcm_stream ca0132_pcm_analog_capture = {
7129 .prepare = ca0132_capture_pcm_prepare,
7130 .cleanup = ca0132_capture_pcm_cleanup,
7131 .get_delay = ca0132_capture_pcm_delay,
7135 static const struct hda_pcm_stream ca0132_pcm_digital_playback = {
7140 .open = ca0132_dig_playback_pcm_open,
7141 .close = ca0132_dig_playback_pcm_close,
7142 .prepare = ca0132_dig_playback_pcm_prepare,
7143 .cleanup = ca0132_dig_playback_pcm_cleanup
7147 static const struct hda_pcm_stream ca0132_pcm_digital_capture = {
7153 static int ca0132_build_pcms(struct hda_codec *codec)
7155 struct ca0132_spec *spec = codec->spec;
7156 struct hda_pcm *info;
7158 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
7161 if (ca0132_use_alt_functions(spec)) {
7162 info->own_chmap = true;
7163 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap
7164 = ca0132_alt_chmaps;
7166 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
7167 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
7168 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
7169 spec->multiout.max_channels;
7170 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7171 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7172 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
7174 /* With the DSP enabled, desktops don't use this ADC. */
7175 if (!ca0132_use_alt_functions(spec)) {
7176 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
7179 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7180 ca0132_pcm_analog_capture;
7181 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7182 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
7185 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
7188 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7189 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7190 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
7192 if (!spec->dig_out && !spec->dig_in)
7195 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7198 info->pcm_type = HDA_PCM_TYPE_SPDIF;
7199 if (spec->dig_out) {
7200 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
7201 ca0132_pcm_digital_playback;
7202 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
7205 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7206 ca0132_pcm_digital_capture;
7207 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
7213 static int dbpro_build_pcms(struct hda_codec *codec)
7215 struct ca0132_spec *spec = codec->spec;
7216 struct hda_pcm *info;
7218 info = snd_hda_codec_pcm_new(codec, "CA0132 Alt Analog");
7221 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
7222 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
7223 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
7226 if (!spec->dig_out && !spec->dig_in)
7229 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7232 info->pcm_type = HDA_PCM_TYPE_SPDIF;
7233 if (spec->dig_out) {
7234 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
7235 ca0132_pcm_digital_playback;
7236 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
7239 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
7240 ca0132_pcm_digital_capture;
7241 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
7247 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
7250 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
7251 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
7252 snd_hda_codec_write(codec, pin, 0,
7253 AC_VERB_SET_AMP_GAIN_MUTE,
7256 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
7257 snd_hda_codec_write(codec, dac, 0,
7258 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
7261 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
7264 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
7265 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
7266 snd_hda_codec_write(codec, pin, 0,
7267 AC_VERB_SET_AMP_GAIN_MUTE,
7270 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
7271 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7274 /* init to 0 dB and unmute. */
7275 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7276 HDA_AMP_VOLMASK, 0x5a);
7277 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7282 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
7286 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
7287 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
7288 snd_hda_override_amp_caps(codec, nid, dir, caps);
7292 * Switch between Digital built-in mic and analog mic.
7294 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
7296 struct ca0132_spec *spec = codec->spec;
7299 unsigned int oldval;
7301 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
7303 oldval = stop_mic1(codec);
7304 ca0132_set_vipsource(codec, 0);
7306 /* set DMic input as 2-ch */
7308 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7310 val = spec->dmic_ctl;
7312 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7313 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7315 if (!(spec->dmic_ctl & 0x20))
7316 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
7318 /* set AMic input as mono */
7320 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7322 val = spec->dmic_ctl;
7323 /* clear bit7 and bit5 to disable dmic */
7325 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7326 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7328 if (!(spec->dmic_ctl & 0x20))
7329 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
7331 ca0132_set_vipsource(codec, 1);
7332 resume_mic1(codec, oldval);
7336 * Initialization for Digital Mic.
7338 static void ca0132_init_dmic(struct hda_codec *codec)
7340 struct ca0132_spec *spec = codec->spec;
7343 /* Setup Digital Mic here, but don't enable.
7344 * Enable based on jack detect.
7347 /* MCLK uses MPIO1, set to enable.
7348 * Bit 2-0: MPIO select
7349 * Bit 3: set to disable
7353 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7354 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
7356 /* Data1 uses MPIO3. Data2 not use
7357 * Bit 2-0: Data1 MPIO select
7358 * Bit 3: set disable Data1
7359 * Bit 6-4: Data2 MPIO select
7360 * Bit 7: set disable Data2
7363 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7364 VENDOR_CHIPIO_DMIC_PIN_SET, val);
7366 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
7367 * Bit 3-0: Channel mask
7368 * Bit 4: set for 48KHz, clear for 32KHz
7370 * Bit 6: set to select Data2, clear for Data1
7371 * Bit 7: set to enable DMic, clear for AMic
7373 if (ca0132_quirk(spec) == QUIRK_ALIENWARE_M17XR4)
7377 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
7378 spec->dmic_ctl = val;
7379 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7380 VENDOR_CHIPIO_DMIC_CTL_SET, val);
7384 * Initialization for Analog Mic 2
7386 static void ca0132_init_analog_mic2(struct hda_codec *codec)
7388 struct ca0132_spec *spec = codec->spec;
7390 mutex_lock(&spec->chipio_mutex);
7391 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7392 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
7393 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7394 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
7395 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7396 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
7397 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7398 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
7399 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7400 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
7401 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7402 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
7403 mutex_unlock(&spec->chipio_mutex);
7406 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
7408 struct ca0132_spec *spec = codec->spec;
7411 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
7412 snd_hda_codec_update_widgets(codec);
7414 for (i = 0; i < spec->multiout.num_dacs; i++)
7415 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
7417 for (i = 0; i < spec->num_outputs; i++)
7418 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
7420 for (i = 0; i < spec->num_inputs; i++) {
7421 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
7422 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
7427 * Default speaker tuning values setup for alternative codecs.
7429 static const unsigned int sbz_default_delay_values[] = {
7430 /* Non-zero values are floating point 0.000198. */
7431 0x394f9e38, 0x394f9e38, 0x00000000, 0x00000000, 0x00000000, 0x00000000
7434 static const unsigned int zxr_default_delay_values[] = {
7435 /* Non-zero values are floating point 0.000220. */
7436 0x00000000, 0x00000000, 0x3966afcd, 0x3966afcd, 0x3966afcd, 0x3966afcd
7439 static const unsigned int ae5_default_delay_values[] = {
7440 /* Non-zero values are floating point 0.000100. */
7441 0x00000000, 0x00000000, 0x38d1b717, 0x38d1b717, 0x38d1b717, 0x38d1b717
7445 * If we never change these, probably only need them on initialization.
7447 static void ca0132_alt_init_speaker_tuning(struct hda_codec *codec)
7449 struct ca0132_spec *spec = codec->spec;
7450 unsigned int i, tmp, start_req, end_req;
7451 const unsigned int *values;
7453 switch (ca0132_quirk(spec)) {
7455 values = sbz_default_delay_values;
7458 values = zxr_default_delay_values;
7462 values = ae5_default_delay_values;
7465 values = sbz_default_delay_values;
7470 dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_ENABLE_CENTER_EQ, tmp);
7472 start_req = SPEAKER_TUNING_FRONT_LEFT_VOL_LEVEL;
7473 end_req = SPEAKER_TUNING_REAR_RIGHT_VOL_LEVEL;
7474 for (i = start_req; i < end_req + 1; i++)
7475 dspio_set_uint_param(codec, 0x96, i, tmp);
7477 start_req = SPEAKER_TUNING_FRONT_LEFT_INVERT;
7478 end_req = SPEAKER_TUNING_REAR_RIGHT_INVERT;
7479 for (i = start_req; i < end_req + 1; i++)
7480 dspio_set_uint_param(codec, 0x96, i, tmp);
7483 for (i = 0; i < 6; i++)
7484 dspio_set_uint_param(codec, 0x96,
7485 SPEAKER_TUNING_FRONT_LEFT_DELAY + i, values[i]);
7489 * Creates a dummy stream to bind the output to. This seems to have to be done
7490 * after changing the main outputs source and destination streams.
7492 static void ca0132_alt_create_dummy_stream(struct hda_codec *codec)
7494 struct ca0132_spec *spec = codec->spec;
7495 unsigned int stream_format;
7497 stream_format = snd_hdac_calc_stream_format(48000, 2,
7498 SNDRV_PCM_FORMAT_S32_LE, 32, 0);
7500 snd_hda_codec_setup_stream(codec, spec->dacs[0], spec->dsp_stream_id,
7503 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
7507 * Initialize mic for non-chromebook ca0132 implementations.
7509 static void ca0132_alt_init_analog_mics(struct hda_codec *codec)
7511 struct ca0132_spec *spec = codec->spec;
7515 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7516 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7517 if (ca0132_quirk(spec) == QUIRK_R3DI) {
7518 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7522 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7524 /* Mic 2 setup (not present on desktop cards) */
7525 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
7526 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
7527 if (ca0132_quirk(spec) == QUIRK_R3DI)
7528 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7530 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
7534 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
7535 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
7536 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
7537 * having an updated DAC, which changes the destination to that DAC.
7539 static void sbz_connect_streams(struct hda_codec *codec)
7541 struct ca0132_spec *spec = codec->spec;
7543 mutex_lock(&spec->chipio_mutex);
7545 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
7547 chipio_set_stream_channels(codec, 0x0C, 6);
7548 chipio_set_stream_control(codec, 0x0C, 1);
7550 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
7551 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
7553 /* Setup stream 0x14 with it's source and destination points */
7554 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
7555 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
7556 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
7557 chipio_set_stream_channels(codec, 0x14, 2);
7558 chipio_set_stream_control(codec, 0x14, 1);
7560 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
7562 mutex_unlock(&spec->chipio_mutex);
7566 * Write data through ChipIO to setup proper stream destinations.
7567 * Not sure how it exactly works, but it seems to direct data
7568 * to different destinations. Example is f8 to c0, e0 to c0.
7569 * All I know is, if you don't set these, you get no sound.
7571 static void sbz_chipio_startup_data(struct hda_codec *codec)
7573 struct ca0132_spec *spec = codec->spec;
7575 mutex_lock(&spec->chipio_mutex);
7576 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
7578 /* These control audio output */
7579 chipio_write_no_mutex(codec, 0x190060, 0x0001f8c0);
7580 chipio_write_no_mutex(codec, 0x190064, 0x0001f9c1);
7581 chipio_write_no_mutex(codec, 0x190068, 0x0001fac6);
7582 chipio_write_no_mutex(codec, 0x19006c, 0x0001fbc7);
7583 /* Signal to update I think */
7584 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
7586 chipio_set_stream_channels(codec, 0x0C, 6);
7587 chipio_set_stream_control(codec, 0x0C, 1);
7588 /* No clue what these control */
7589 if (ca0132_quirk(spec) == QUIRK_SBZ) {
7590 chipio_write_no_mutex(codec, 0x190030, 0x0001e0c0);
7591 chipio_write_no_mutex(codec, 0x190034, 0x0001e1c1);
7592 chipio_write_no_mutex(codec, 0x190038, 0x0001e4c2);
7593 chipio_write_no_mutex(codec, 0x19003c, 0x0001e5c3);
7594 chipio_write_no_mutex(codec, 0x190040, 0x0001e2c4);
7595 chipio_write_no_mutex(codec, 0x190044, 0x0001e3c5);
7596 chipio_write_no_mutex(codec, 0x190048, 0x0001e8c6);
7597 chipio_write_no_mutex(codec, 0x19004c, 0x0001e9c7);
7598 chipio_write_no_mutex(codec, 0x190050, 0x0001ecc8);
7599 chipio_write_no_mutex(codec, 0x190054, 0x0001edc9);
7600 chipio_write_no_mutex(codec, 0x190058, 0x0001eaca);
7601 chipio_write_no_mutex(codec, 0x19005c, 0x0001ebcb);
7602 } else if (ca0132_quirk(spec) == QUIRK_ZXR) {
7603 chipio_write_no_mutex(codec, 0x190038, 0x000140c2);
7604 chipio_write_no_mutex(codec, 0x19003c, 0x000141c3);
7605 chipio_write_no_mutex(codec, 0x190040, 0x000150c4);
7606 chipio_write_no_mutex(codec, 0x190044, 0x000151c5);
7607 chipio_write_no_mutex(codec, 0x190050, 0x000142c8);
7608 chipio_write_no_mutex(codec, 0x190054, 0x000143c9);
7609 chipio_write_no_mutex(codec, 0x190058, 0x000152ca);
7610 chipio_write_no_mutex(codec, 0x19005c, 0x000153cb);
7612 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
7614 codec_dbg(codec, "Startup Data exited, mutex released.\n");
7615 mutex_unlock(&spec->chipio_mutex);
7619 * Custom DSP SCP commands where the src value is 0x00 instead of 0x20. This is
7620 * done after the DSP is loaded.
7622 static void ca0132_alt_dsp_scp_startup(struct hda_codec *codec)
7624 struct ca0132_spec *spec = codec->spec;
7625 unsigned int tmp, i;
7628 * Gotta run these twice, or else mic works inconsistently. Not clear
7629 * why this is, but multiple tests have confirmed it.
7631 for (i = 0; i < 2; i++) {
7632 switch (ca0132_quirk(spec)) {
7637 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7639 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7641 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7643 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7645 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7647 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7652 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7654 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7656 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7658 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7660 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7669 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec *codec)
7671 struct ca0132_spec *spec = codec->spec;
7674 chipio_set_stream_control(codec, 0x03, 0);
7675 chipio_set_stream_control(codec, 0x04, 0);
7677 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7678 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7681 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7683 chipio_set_stream_control(codec, 0x03, 1);
7684 chipio_set_stream_control(codec, 0x04, 1);
7686 switch (ca0132_quirk(spec)) {
7688 chipio_write(codec, 0x18b098, 0x0000000c);
7689 chipio_write(codec, 0x18b09C, 0x0000000c);
7692 chipio_write(codec, 0x18b098, 0x0000000c);
7693 chipio_write(codec, 0x18b09c, 0x0000004c);
7700 static void ae5_post_dsp_register_set(struct hda_codec *codec)
7702 struct ca0132_spec *spec = codec->spec;
7704 chipio_8051_write_direct(codec, 0x93, 0x10);
7705 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7706 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
7707 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7708 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
7710 writeb(0xff, spec->mem_base + 0x304);
7711 writeb(0xff, spec->mem_base + 0x304);
7712 writeb(0xff, spec->mem_base + 0x304);
7713 writeb(0xff, spec->mem_base + 0x304);
7714 writeb(0x00, spec->mem_base + 0x100);
7715 writeb(0xff, spec->mem_base + 0x304);
7716 writeb(0x00, spec->mem_base + 0x100);
7717 writeb(0xff, spec->mem_base + 0x304);
7718 writeb(0x00, spec->mem_base + 0x100);
7719 writeb(0xff, spec->mem_base + 0x304);
7720 writeb(0x00, spec->mem_base + 0x100);
7721 writeb(0xff, spec->mem_base + 0x304);
7723 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x3f);
7724 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
7725 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7728 static void ae5_post_dsp_param_setup(struct hda_codec *codec)
7731 * Param3 in the 8051's memory is represented by the ascii string 'mch'
7732 * which seems to be 'multichannel'. This is also mentioned in the
7733 * AE-5's registry values in Windows.
7735 chipio_set_control_param(codec, 3, 0);
7737 * I believe ASI is 'audio serial interface' and that it's used to
7738 * change colors on the external LED strip connected to the AE-5.
7740 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
7742 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
7743 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7745 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7746 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x92);
7747 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7748 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0xfa);
7749 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7750 VENDOR_CHIPIO_8051_DATA_WRITE, 0x22);
7753 static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
7755 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7756 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x41);
7757 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7758 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc8);
7760 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7761 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x45);
7762 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7763 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcc);
7765 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7766 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x40);
7767 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7768 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcb);
7770 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7771 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7772 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7773 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7775 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7776 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x51);
7777 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7778 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x8d);
7781 static void ae5_post_dsp_stream_setup(struct hda_codec *codec)
7783 struct ca0132_spec *spec = codec->spec;
7785 mutex_lock(&spec->chipio_mutex);
7787 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7789 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7791 chipio_set_stream_channels(codec, 0x0C, 6);
7792 chipio_set_stream_control(codec, 0x0C, 1);
7794 chipio_set_stream_source_dest(codec, 0x5, 0x43, 0x0);
7796 chipio_set_stream_source_dest(codec, 0x18, 0x9, 0xd0);
7797 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7798 chipio_set_stream_channels(codec, 0x18, 6);
7799 chipio_set_stream_control(codec, 0x18, 1);
7801 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7803 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7804 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7805 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7806 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7808 ca0113_mmio_command_set(codec, 0x48, 0x01, 0x80);
7810 mutex_unlock(&spec->chipio_mutex);
7813 static void ae5_post_dsp_startup_data(struct hda_codec *codec)
7815 struct ca0132_spec *spec = codec->spec;
7817 mutex_lock(&spec->chipio_mutex);
7819 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
7820 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
7821 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
7822 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
7824 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7825 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
7826 ca0113_mmio_command_set(codec, 0x48, 0x0b, 0x12);
7827 ca0113_mmio_command_set(codec, 0x48, 0x04, 0x00);
7828 ca0113_mmio_command_set(codec, 0x48, 0x06, 0x48);
7829 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7830 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7831 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7832 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7833 ca0113_mmio_gpio_set(codec, 0, true);
7834 ca0113_mmio_gpio_set(codec, 1, true);
7835 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x80);
7837 chipio_write_no_mutex(codec, 0x18b03c, 0x00000012);
7839 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7840 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7842 mutex_unlock(&spec->chipio_mutex);
7845 static const unsigned int ae7_port_set_data[] = {
7846 0x0001e0c0, 0x0001e1c1, 0x0001e4c2, 0x0001e5c3, 0x0001e2c4, 0x0001e3c5,
7847 0x0001e8c6, 0x0001e9c7, 0x0001ecc8, 0x0001edc9, 0x0001eaca, 0x0001ebcb
7850 static void ae7_post_dsp_setup_ports(struct hda_codec *codec)
7852 struct ca0132_spec *spec = codec->spec;
7853 unsigned int i, count, addr;
7855 mutex_lock(&spec->chipio_mutex);
7857 chipio_set_stream_channels(codec, 0x0c, 6);
7858 chipio_set_stream_control(codec, 0x0c, 1);
7860 count = ARRAY_SIZE(ae7_port_set_data);
7862 for (i = 0; i < count; i++) {
7863 chipio_write_no_mutex(codec, addr, ae7_port_set_data[i]);
7865 /* Addresses are incremented by 4-bytes. */
7870 * Port setting always ends with a write of 0x1 to address 0x19042c.
7872 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
7874 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
7875 ca0113_mmio_command_set(codec, 0x48, 0x0d, 0x40);
7876 ca0113_mmio_command_set(codec, 0x48, 0x17, 0x00);
7877 ca0113_mmio_command_set(codec, 0x48, 0x19, 0x00);
7878 ca0113_mmio_command_set(codec, 0x48, 0x11, 0xff);
7879 ca0113_mmio_command_set(codec, 0x48, 0x12, 0xff);
7880 ca0113_mmio_command_set(codec, 0x48, 0x13, 0xff);
7881 ca0113_mmio_command_set(codec, 0x48, 0x14, 0x7f);
7883 mutex_unlock(&spec->chipio_mutex);
7886 static void ae7_post_dsp_asi_stream_setup(struct hda_codec *codec)
7888 struct ca0132_spec *spec = codec->spec;
7890 mutex_lock(&spec->chipio_mutex);
7892 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7893 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
7895 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7896 chipio_set_stream_channels(codec, 0x0c, 6);
7897 chipio_set_stream_control(codec, 0x0c, 1);
7899 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
7900 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
7902 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7903 chipio_set_stream_channels(codec, 0x18, 6);
7904 chipio_set_stream_control(codec, 0x18, 1);
7906 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7908 mutex_unlock(&spec->chipio_mutex);
7911 static void ae7_post_dsp_pll_setup(struct hda_codec *codec)
7913 static const unsigned int addr[] = {
7914 0x41, 0x45, 0x40, 0x43, 0x51
7916 static const unsigned int data[] = {
7917 0xc8, 0xcc, 0xcb, 0xc7, 0x8d
7921 for (i = 0; i < ARRAY_SIZE(addr); i++) {
7922 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7923 VENDOR_CHIPIO_8051_ADDRESS_LOW, addr[i]);
7924 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7925 VENDOR_CHIPIO_PLL_PMU_WRITE, data[i]);
7929 static void ae7_post_dsp_asi_setup_ports(struct hda_codec *codec)
7931 struct ca0132_spec *spec = codec->spec;
7932 static const unsigned int target[] = {
7933 0x0b, 0x04, 0x06, 0x0a, 0x0c, 0x11, 0x12, 0x13, 0x14
7935 static const unsigned int data[] = {
7936 0x12, 0x00, 0x48, 0x05, 0x5f, 0xff, 0xff, 0xff, 0x7f
7940 mutex_lock(&spec->chipio_mutex);
7942 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7943 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7944 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7945 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7947 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
7948 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
7949 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
7950 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
7952 ae7_post_dsp_pll_setup(codec);
7953 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
7955 for (i = 0; i < ARRAY_SIZE(target); i++)
7956 ca0113_mmio_command_set(codec, 0x48, target[i], data[i]);
7958 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
7959 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7960 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7962 chipio_set_stream_source_dest(codec, 0x21, 0x64, 0x56);
7963 chipio_set_stream_channels(codec, 0x21, 2);
7964 chipio_set_conn_rate_no_mutex(codec, 0x56, SR_8_000);
7966 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_NODE_ID, 0x09);
7968 * In the 8051's memory, this param is referred to as 'n2sid', which I
7969 * believe is 'node to streamID'. It seems to be a way to assign a
7970 * stream to a given HDA node.
7972 chipio_set_control_param_no_mutex(codec, 0x20, 0x21);
7974 chipio_write_no_mutex(codec, 0x18b038, 0x00000088);
7977 * Now, at this point on Windows, an actual stream is setup and
7978 * seemingly sends data to the HDA node 0x09, which is the digital
7979 * audio input node. This is left out here, because obviously I don't
7980 * know what data is being sent. Interestingly, the AE-5 seems to go
7981 * through the motions of getting here and never actually takes this
7982 * step, but the AE-7 does.
7985 ca0113_mmio_gpio_set(codec, 0, 1);
7986 ca0113_mmio_gpio_set(codec, 1, 1);
7988 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
7989 chipio_write_no_mutex(codec, 0x18b03c, 0x00000000);
7990 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7991 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7993 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
7994 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
7996 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7997 chipio_set_stream_channels(codec, 0x18, 6);
8000 * Runs again, this has been repeated a few times, but I'm just
8001 * following what the Windows driver does.
8003 ae7_post_dsp_pll_setup(codec);
8004 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8006 mutex_unlock(&spec->chipio_mutex);
8010 * The Windows driver has commands that seem to setup ASI, which I believe to
8011 * be some sort of audio serial interface. My current speculation is that it's
8012 * related to communicating with the new DAC.
8014 static void ae7_post_dsp_asi_setup(struct hda_codec *codec)
8016 chipio_8051_write_direct(codec, 0x93, 0x10);
8018 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8019 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
8020 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8021 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
8023 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8024 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8026 chipio_set_control_param(codec, 3, 3);
8027 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
8029 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
8030 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8031 snd_hda_codec_write(codec, 0x17, 0, 0x794, 0x00);
8033 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8034 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x92);
8035 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8036 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0xfa);
8037 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8038 VENDOR_CHIPIO_8051_DATA_WRITE, 0x22);
8040 ae7_post_dsp_pll_setup(codec);
8041 ae7_post_dsp_asi_stream_setup(codec);
8043 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8044 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
8045 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8046 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
8048 ae7_post_dsp_asi_setup_ports(codec);
8052 * Setup default parameters for DSP
8054 static void ca0132_setup_defaults(struct hda_codec *codec)
8056 struct ca0132_spec *spec = codec->spec;
8061 if (spec->dsp_state != DSP_DOWNLOADED)
8064 /* out, in effects + voicefx */
8065 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8066 for (idx = 0; idx < num_fx; idx++) {
8067 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8068 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
8069 ca0132_effects[idx].reqs[i],
8070 ca0132_effects[idx].def_vals[i]);
8074 /*remove DSP headroom*/
8076 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8078 /*set speaker EQ bypass attenuation*/
8079 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
8081 /* set AMic1 and AMic2 as mono mic */
8083 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
8084 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
8086 /* set AMic1 as CrystalVoice input */
8088 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
8090 /* set WUH source */
8092 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8096 * Setup default parameters for Recon3D/Recon3Di DSP.
8099 static void r3d_setup_defaults(struct hda_codec *codec)
8101 struct ca0132_spec *spec = codec->spec;
8106 if (spec->dsp_state != DSP_DOWNLOADED)
8109 ca0132_alt_dsp_scp_startup(codec);
8110 ca0132_alt_init_analog_mics(codec);
8112 /*remove DSP headroom*/
8114 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8116 /* set WUH source */
8118 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8119 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8121 /* Set speaker source? */
8122 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8124 if (ca0132_quirk(spec) == QUIRK_R3DI)
8125 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
8127 /* Disable mute on Center/LFE. */
8128 if (ca0132_quirk(spec) == QUIRK_R3D) {
8129 ca0113_mmio_gpio_set(codec, 2, false);
8130 ca0113_mmio_gpio_set(codec, 4, true);
8133 /* Setup effect defaults */
8134 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8135 for (idx = 0; idx < num_fx; idx++) {
8136 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8137 dspio_set_uint_param(codec,
8138 ca0132_effects[idx].mid,
8139 ca0132_effects[idx].reqs[i],
8140 ca0132_effects[idx].def_vals[i]);
8146 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
8147 * than the Chromebook setup.
8149 static void sbz_setup_defaults(struct hda_codec *codec)
8151 struct ca0132_spec *spec = codec->spec;
8156 if (spec->dsp_state != DSP_DOWNLOADED)
8159 ca0132_alt_dsp_scp_startup(codec);
8160 ca0132_alt_init_analog_mics(codec);
8161 sbz_connect_streams(codec);
8162 sbz_chipio_startup_data(codec);
8164 chipio_set_stream_control(codec, 0x03, 1);
8165 chipio_set_stream_control(codec, 0x04, 1);
8168 * Sets internal input loopback to off, used to have a switch to
8169 * enable input loopback, but turned out to be way too buggy.
8172 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8173 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8175 /*remove DSP headroom*/
8177 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8179 /* set WUH source */
8181 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8182 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8184 /* Set speaker source? */
8185 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8187 ca0132_alt_dsp_initial_mic_setup(codec);
8189 /* out, in effects + voicefx */
8190 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8191 for (idx = 0; idx < num_fx; idx++) {
8192 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8193 dspio_set_uint_param(codec,
8194 ca0132_effects[idx].mid,
8195 ca0132_effects[idx].reqs[i],
8196 ca0132_effects[idx].def_vals[i]);
8200 ca0132_alt_init_speaker_tuning(codec);
8202 ca0132_alt_create_dummy_stream(codec);
8206 * Setup default parameters for the Sound BlasterX AE-5 DSP.
8208 static void ae5_setup_defaults(struct hda_codec *codec)
8210 struct ca0132_spec *spec = codec->spec;
8215 if (spec->dsp_state != DSP_DOWNLOADED)
8218 ca0132_alt_dsp_scp_startup(codec);
8219 ca0132_alt_init_analog_mics(codec);
8220 chipio_set_stream_control(codec, 0x03, 1);
8221 chipio_set_stream_control(codec, 0x04, 1);
8223 /* New, unknown SCP req's */
8225 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
8226 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
8227 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8228 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8230 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8231 ca0113_mmio_gpio_set(codec, 0, false);
8232 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8234 /* Internal loopback off */
8236 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8237 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8239 /*remove DSP headroom*/
8241 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8243 /* set WUH source */
8245 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8246 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8248 /* Set speaker source? */
8249 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8251 ca0132_alt_dsp_initial_mic_setup(codec);
8252 ae5_post_dsp_register_set(codec);
8253 ae5_post_dsp_param_setup(codec);
8254 ae5_post_dsp_pll_setup(codec);
8255 ae5_post_dsp_stream_setup(codec);
8256 ae5_post_dsp_startup_data(codec);
8258 /* out, in effects + voicefx */
8259 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8260 for (idx = 0; idx < num_fx; idx++) {
8261 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8262 dspio_set_uint_param(codec,
8263 ca0132_effects[idx].mid,
8264 ca0132_effects[idx].reqs[i],
8265 ca0132_effects[idx].def_vals[i]);
8269 ca0132_alt_init_speaker_tuning(codec);
8271 ca0132_alt_create_dummy_stream(codec);
8275 * Setup default parameters for the Sound Blaster AE-7 DSP.
8277 static void ae7_setup_defaults(struct hda_codec *codec)
8279 struct ca0132_spec *spec = codec->spec;
8284 if (spec->dsp_state != DSP_DOWNLOADED)
8287 ca0132_alt_dsp_scp_startup(codec);
8288 ca0132_alt_init_analog_mics(codec);
8289 ae7_post_dsp_setup_ports(codec);
8292 dspio_set_uint_param(codec, 0x96,
8293 SPEAKER_TUNING_FRONT_LEFT_INVERT, tmp);
8294 dspio_set_uint_param(codec, 0x96,
8295 SPEAKER_TUNING_FRONT_RIGHT_INVERT, tmp);
8297 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8299 /* New, unknown SCP req's */
8300 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8301 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8303 ca0113_mmio_gpio_set(codec, 0, false);
8305 /* Internal loopback off */
8307 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8308 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8310 /*remove DSP headroom*/
8312 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8314 /* set WUH source */
8316 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8317 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8319 /* Set speaker source? */
8320 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8321 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8324 * This is the second time we've called this, but this is seemingly
8325 * what Windows does.
8327 ca0132_alt_init_analog_mics(codec);
8329 ae7_post_dsp_asi_setup(codec);
8332 * Not sure why, but these are both set to 1. They're only set to 0
8335 ca0113_mmio_gpio_set(codec, 0, true);
8336 ca0113_mmio_gpio_set(codec, 1, true);
8338 /* Volume control related. */
8339 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x04);
8340 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x04);
8341 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x80);
8343 /* out, in effects + voicefx */
8344 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
8345 for (idx = 0; idx < num_fx; idx++) {
8346 for (i = 0; i <= ca0132_effects[idx].params; i++) {
8347 dspio_set_uint_param(codec,
8348 ca0132_effects[idx].mid,
8349 ca0132_effects[idx].reqs[i],
8350 ca0132_effects[idx].def_vals[i]);
8354 ca0132_alt_init_speaker_tuning(codec);
8356 ca0132_alt_create_dummy_stream(codec);
8360 * Initialization of flags in chip
8362 static void ca0132_init_flags(struct hda_codec *codec)
8364 struct ca0132_spec *spec = codec->spec;
8366 if (ca0132_use_alt_functions(spec)) {
8367 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
8368 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
8369 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
8370 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
8371 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
8372 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8373 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
8374 chipio_set_control_flag(codec,
8375 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
8376 chipio_set_control_flag(codec,
8377 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 1);
8379 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8380 chipio_set_control_flag(codec,
8381 CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
8382 chipio_set_control_flag(codec,
8383 CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
8384 chipio_set_control_flag(codec,
8385 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
8386 chipio_set_control_flag(codec,
8387 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
8388 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
8393 * Initialization of parameters in chip
8395 static void ca0132_init_params(struct hda_codec *codec)
8397 struct ca0132_spec *spec = codec->spec;
8399 if (ca0132_use_alt_functions(spec)) {
8400 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8401 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
8402 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
8403 chipio_set_control_param(codec, 0, 0);
8404 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
8407 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
8408 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
8411 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
8413 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
8414 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
8415 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
8416 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
8417 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
8418 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
8420 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
8421 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
8422 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8425 static bool ca0132_download_dsp_images(struct hda_codec *codec)
8427 bool dsp_loaded = false;
8428 struct ca0132_spec *spec = codec->spec;
8429 const struct dsp_image_seg *dsp_os_image;
8430 const struct firmware *fw_entry = NULL;
8432 * Alternate firmwares for different variants. The Recon3Di apparently
8433 * can use the default firmware, but I'll leave the option in case
8434 * it needs it again.
8436 switch (ca0132_quirk(spec)) {
8440 if (request_firmware(&fw_entry, DESKTOP_EFX_FILE,
8441 codec->card->dev) != 0)
8442 codec_dbg(codec, "Desktop firmware not found.");
8444 codec_dbg(codec, "Desktop firmware selected.");
8447 if (request_firmware(&fw_entry, R3DI_EFX_FILE,
8448 codec->card->dev) != 0)
8449 codec_dbg(codec, "Recon3Di alt firmware not detected.");
8451 codec_dbg(codec, "Recon3Di firmware selected.");
8457 * Use default ctefx.bin if no alt firmware is detected, or if none
8458 * exists for your particular codec.
8461 codec_dbg(codec, "Default firmware selected.");
8462 if (request_firmware(&fw_entry, EFX_FILE,
8463 codec->card->dev) != 0)
8467 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
8468 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
8469 codec_err(codec, "ca0132 DSP load image failed\n");
8473 dsp_loaded = dspload_wait_loaded(codec);
8476 release_firmware(fw_entry);
8481 static void ca0132_download_dsp(struct hda_codec *codec)
8483 struct ca0132_spec *spec = codec->spec;
8485 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
8489 if (spec->dsp_state == DSP_DOWNLOAD_FAILED)
8490 return; /* don't retry failures */
8492 chipio_enable_clocks(codec);
8493 if (spec->dsp_state != DSP_DOWNLOADED) {
8494 spec->dsp_state = DSP_DOWNLOADING;
8496 if (!ca0132_download_dsp_images(codec))
8497 spec->dsp_state = DSP_DOWNLOAD_FAILED;
8499 spec->dsp_state = DSP_DOWNLOADED;
8502 /* For codecs using alt functions, this is already done earlier */
8503 if (spec->dsp_state == DSP_DOWNLOADED && !ca0132_use_alt_functions(spec))
8504 ca0132_set_dsp_msr(codec, true);
8507 static void ca0132_process_dsp_response(struct hda_codec *codec,
8508 struct hda_jack_callback *callback)
8510 struct ca0132_spec *spec = codec->spec;
8512 codec_dbg(codec, "ca0132_process_dsp_response\n");
8513 snd_hda_power_up_pm(codec);
8514 if (spec->wait_scp) {
8515 if (dspio_get_response_data(codec) >= 0)
8519 dspio_clear_response_queue(codec);
8520 snd_hda_power_down_pm(codec);
8523 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8525 struct ca0132_spec *spec = codec->spec;
8526 struct hda_jack_tbl *tbl;
8528 /* Delay enabling the HP amp, to let the mic-detection
8529 * state machine run.
8531 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
8533 tbl->block_report = 1;
8534 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
8537 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8539 struct ca0132_spec *spec = codec->spec;
8541 if (ca0132_use_alt_functions(spec))
8542 ca0132_alt_select_in(codec);
8544 ca0132_select_mic(codec);
8547 static void ca0132_init_unsol(struct hda_codec *codec)
8549 struct ca0132_spec *spec = codec->spec;
8550 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
8551 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
8553 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
8554 ca0132_process_dsp_response);
8555 /* Front headphone jack detection */
8556 if (ca0132_use_alt_functions(spec))
8557 snd_hda_jack_detect_enable_callback(codec,
8558 spec->unsol_tag_front_hp, hp_callback);
8565 /* Sends before DSP download. */
8566 static const struct hda_verb ca0132_base_init_verbs[] = {
8567 /*enable ct extension*/
8568 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
8573 static const struct hda_verb ca0132_base_exit_verbs[] = {
8575 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
8576 /*disable ct extension*/
8577 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
8581 /* Other verbs tables. Sends after DSP download. */
8583 static const struct hda_verb ca0132_init_verbs0[] = {
8584 /* chip init verbs */
8585 {0x15, 0x70D, 0xF0},
8586 {0x15, 0x70E, 0xFE},
8587 {0x15, 0x707, 0x75},
8588 {0x15, 0x707, 0xD3},
8589 {0x15, 0x707, 0x09},
8590 {0x15, 0x707, 0x53},
8591 {0x15, 0x707, 0xD4},
8592 {0x15, 0x707, 0xEF},
8593 {0x15, 0x707, 0x75},
8594 {0x15, 0x707, 0xD3},
8595 {0x15, 0x707, 0x09},
8596 {0x15, 0x707, 0x02},
8597 {0x15, 0x707, 0x37},
8598 {0x15, 0x707, 0x78},
8599 {0x15, 0x53C, 0xCE},
8600 {0x15, 0x575, 0xC9},
8601 {0x15, 0x53D, 0xCE},
8602 {0x15, 0x5B7, 0xC9},
8603 {0x15, 0x70D, 0xE8},
8604 {0x15, 0x70E, 0xFE},
8605 {0x15, 0x707, 0x02},
8606 {0x15, 0x707, 0x68},
8607 {0x15, 0x707, 0x62},
8608 {0x15, 0x53A, 0xCE},
8609 {0x15, 0x546, 0xC9},
8610 {0x15, 0x53B, 0xCE},
8611 {0x15, 0x5E8, 0xC9},
8615 /* Extra init verbs for desktop cards. */
8616 static const struct hda_verb ca0132_init_verbs1[] = {
8617 {0x15, 0x70D, 0x20},
8618 {0x15, 0x70E, 0x19},
8619 {0x15, 0x707, 0x00},
8620 {0x15, 0x539, 0xCE},
8621 {0x15, 0x546, 0xC9},
8622 {0x15, 0x70D, 0xB7},
8623 {0x15, 0x70E, 0x09},
8624 {0x15, 0x707, 0x10},
8625 {0x15, 0x70D, 0xAF},
8626 {0x15, 0x70E, 0x09},
8627 {0x15, 0x707, 0x01},
8628 {0x15, 0x707, 0x05},
8629 {0x15, 0x70D, 0x73},
8630 {0x15, 0x70E, 0x09},
8631 {0x15, 0x707, 0x14},
8632 {0x15, 0x6FF, 0xC4},
8636 static void ca0132_init_chip(struct hda_codec *codec)
8638 struct ca0132_spec *spec = codec->spec;
8643 mutex_init(&spec->chipio_mutex);
8645 spec->cur_out_type = SPEAKER_OUT;
8646 if (!ca0132_use_alt_functions(spec))
8647 spec->cur_mic_type = DIGITAL_MIC;
8649 spec->cur_mic_type = REAR_MIC;
8651 spec->cur_mic_boost = 0;
8653 for (i = 0; i < VNODES_COUNT; i++) {
8654 spec->vnode_lvol[i] = 0x5a;
8655 spec->vnode_rvol[i] = 0x5a;
8656 spec->vnode_lswitch[i] = 0;
8657 spec->vnode_rswitch[i] = 0;
8661 * Default states for effects are in ca0132_effects[].
8663 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
8664 for (i = 0; i < num_fx; i++) {
8665 on = (unsigned int)ca0132_effects[i].reqs[0];
8666 spec->effects_switch[i] = on ? 1 : 0;
8669 * Sets defaults for the effect slider controls, only for alternative
8670 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
8672 if (ca0132_use_alt_controls(spec)) {
8673 /* Set speakers to default to full range. */
8674 spec->speaker_range_val[0] = 1;
8675 spec->speaker_range_val[1] = 1;
8677 spec->xbass_xover_freq = 8;
8678 for (i = 0; i < EFFECT_LEVEL_SLIDERS; i++)
8679 spec->fx_ctl_val[i] = effect_slider_defaults[i];
8681 spec->bass_redirect_xover_freq = 8;
8684 spec->voicefx_val = 0;
8685 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
8686 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
8689 * The ZxR doesn't have a front panel header, and it's line-in is on
8690 * the daughter board. So, there is no input enum control, and we need
8691 * to make sure that spec->in_enum_val is set properly.
8693 if (ca0132_quirk(spec) == QUIRK_ZXR)
8694 spec->in_enum_val = REAR_MIC;
8696 #ifdef ENABLE_TUNING_CONTROLS
8697 ca0132_init_tuning_defaults(codec);
8702 * Recon3Di exit specific commands.
8704 /* prevents popping noise on shutdown */
8705 static void r3di_gpio_shutdown(struct hda_codec *codec)
8707 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
8711 * Sound Blaster Z exit specific commands.
8713 static void sbz_region2_exit(struct hda_codec *codec)
8715 struct ca0132_spec *spec = codec->spec;
8718 for (i = 0; i < 4; i++)
8719 writeb(0x0, spec->mem_base + 0x100);
8720 for (i = 0; i < 8; i++)
8721 writeb(0xb3, spec->mem_base + 0x304);
8723 ca0113_mmio_gpio_set(codec, 0, false);
8724 ca0113_mmio_gpio_set(codec, 1, false);
8725 ca0113_mmio_gpio_set(codec, 4, true);
8726 ca0113_mmio_gpio_set(codec, 5, false);
8727 ca0113_mmio_gpio_set(codec, 7, false);
8730 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
8732 static const hda_nid_t pins[] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
8735 snd_hda_codec_write(codec, 0x11, 0,
8736 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40);
8738 for (i = 0; i < ARRAY_SIZE(pins); i++)
8739 snd_hda_codec_write(codec, pins[i], 0,
8740 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00);
8743 static void ca0132_clear_unsolicited(struct hda_codec *codec)
8745 static const hda_nid_t pins[] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
8748 for (i = 0; i < ARRAY_SIZE(pins); i++) {
8749 snd_hda_codec_write(codec, pins[i], 0,
8750 AC_VERB_SET_UNSOLICITED_ENABLE, 0x00);
8754 /* On shutdown, sends commands in sets of three */
8755 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
8759 snd_hda_codec_write(codec, 0x01, 0,
8760 AC_VERB_SET_GPIO_DIRECTION, dir);
8762 snd_hda_codec_write(codec, 0x01, 0,
8763 AC_VERB_SET_GPIO_MASK, mask);
8766 snd_hda_codec_write(codec, 0x01, 0,
8767 AC_VERB_SET_GPIO_DATA, data);
8770 static void zxr_dbpro_power_state_shutdown(struct hda_codec *codec)
8772 static const hda_nid_t pins[] = {0x05, 0x0c, 0x09, 0x0e, 0x08, 0x11, 0x01};
8775 for (i = 0; i < ARRAY_SIZE(pins); i++)
8776 snd_hda_codec_write(codec, pins[i], 0,
8777 AC_VERB_SET_POWER_STATE, 0x03);
8780 static void sbz_exit_chip(struct hda_codec *codec)
8782 chipio_set_stream_control(codec, 0x03, 0);
8783 chipio_set_stream_control(codec, 0x04, 0);
8785 /* Mess with GPIO */
8786 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
8787 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
8788 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
8790 chipio_set_stream_control(codec, 0x14, 0);
8791 chipio_set_stream_control(codec, 0x0C, 0);
8793 chipio_set_conn_rate(codec, 0x41, SR_192_000);
8794 chipio_set_conn_rate(codec, 0x91, SR_192_000);
8796 chipio_write(codec, 0x18a020, 0x00000083);
8798 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
8799 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
8800 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
8802 chipio_set_stream_control(codec, 0x0C, 0);
8804 chipio_set_control_param(codec, 0x0D, 0x24);
8806 ca0132_clear_unsolicited(codec);
8807 sbz_set_pin_ctl_default(codec);
8809 snd_hda_codec_write(codec, 0x0B, 0,
8810 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
8812 sbz_region2_exit(codec);
8815 static void r3d_exit_chip(struct hda_codec *codec)
8817 ca0132_clear_unsolicited(codec);
8818 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8819 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
8822 static void ae5_exit_chip(struct hda_codec *codec)
8824 chipio_set_stream_control(codec, 0x03, 0);
8825 chipio_set_stream_control(codec, 0x04, 0);
8827 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8828 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8829 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8830 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8831 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8832 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x00);
8833 ca0113_mmio_gpio_set(codec, 0, false);
8834 ca0113_mmio_gpio_set(codec, 1, false);
8836 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8837 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8839 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8841 chipio_set_stream_control(codec, 0x18, 0);
8842 chipio_set_stream_control(codec, 0x0c, 0);
8844 snd_hda_codec_write(codec, 0x01, 0, 0x724, 0x83);
8847 static void ae7_exit_chip(struct hda_codec *codec)
8849 chipio_set_stream_control(codec, 0x18, 0);
8850 chipio_set_stream_source_dest(codec, 0x21, 0xc8, 0xc8);
8851 chipio_set_stream_channels(codec, 0x21, 0);
8852 chipio_set_control_param(codec, CONTROL_PARAM_NODE_ID, 0x09);
8853 chipio_set_control_param(codec, 0x20, 0x01);
8855 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8857 chipio_set_stream_control(codec, 0x18, 0);
8858 chipio_set_stream_control(codec, 0x0c, 0);
8860 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8861 snd_hda_codec_write(codec, 0x15, 0, 0x724, 0x83);
8862 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8863 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8864 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x00);
8865 ca0113_mmio_gpio_set(codec, 0, false);
8866 ca0113_mmio_gpio_set(codec, 1, false);
8867 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8869 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8870 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8873 static void zxr_exit_chip(struct hda_codec *codec)
8875 chipio_set_stream_control(codec, 0x03, 0);
8876 chipio_set_stream_control(codec, 0x04, 0);
8877 chipio_set_stream_control(codec, 0x14, 0);
8878 chipio_set_stream_control(codec, 0x0C, 0);
8880 chipio_set_conn_rate(codec, 0x41, SR_192_000);
8881 chipio_set_conn_rate(codec, 0x91, SR_192_000);
8883 chipio_write(codec, 0x18a020, 0x00000083);
8885 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8886 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8888 ca0132_clear_unsolicited(codec);
8889 sbz_set_pin_ctl_default(codec);
8890 snd_hda_codec_write(codec, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x00);
8892 ca0113_mmio_gpio_set(codec, 5, false);
8893 ca0113_mmio_gpio_set(codec, 2, false);
8894 ca0113_mmio_gpio_set(codec, 3, false);
8895 ca0113_mmio_gpio_set(codec, 0, false);
8896 ca0113_mmio_gpio_set(codec, 4, true);
8897 ca0113_mmio_gpio_set(codec, 0, true);
8898 ca0113_mmio_gpio_set(codec, 5, true);
8899 ca0113_mmio_gpio_set(codec, 2, false);
8900 ca0113_mmio_gpio_set(codec, 3, false);
8903 static void ca0132_exit_chip(struct hda_codec *codec)
8905 /* put any chip cleanup stuffs here. */
8907 if (dspload_is_loaded(codec))
8912 * This fixes a problem that was hard to reproduce. Very rarely, I would
8913 * boot up, and there would be no sound, but the DSP indicated it had loaded
8914 * properly. I did a few memory dumps to see if anything was different, and
8915 * there were a few areas of memory uninitialized with a1a2a3a4. This function
8916 * checks if those areas are uninitialized, and if they are, it'll attempt to
8917 * reload the card 3 times. Usually it fixes by the second.
8919 static void sbz_dsp_startup_check(struct hda_codec *codec)
8921 struct ca0132_spec *spec = codec->spec;
8922 unsigned int dsp_data_check[4];
8923 unsigned int cur_address = 0x390;
8925 unsigned int failure = 0;
8926 unsigned int reload = 3;
8928 if (spec->startup_check_entered)
8931 spec->startup_check_entered = true;
8933 for (i = 0; i < 4; i++) {
8934 chipio_read(codec, cur_address, &dsp_data_check[i]);
8937 for (i = 0; i < 4; i++) {
8938 if (dsp_data_check[i] == 0xa1a2a3a4)
8942 codec_dbg(codec, "Startup Check: %d ", failure);
8944 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
8946 * While the failure condition is true, and we haven't reached our
8947 * three reload limit, continue trying to reload the driver and
8950 while (failure && (reload != 0)) {
8951 codec_info(codec, "Reloading... Tries left: %d", reload);
8952 sbz_exit_chip(codec);
8953 spec->dsp_state = DSP_DOWNLOAD_INIT;
8954 codec->patch_ops.init(codec);
8956 for (i = 0; i < 4; i++) {
8957 chipio_read(codec, cur_address, &dsp_data_check[i]);
8960 for (i = 0; i < 4; i++) {
8961 if (dsp_data_check[i] == 0xa1a2a3a4)
8967 if (!failure && reload < 3)
8968 codec_info(codec, "DSP fixed.");
8973 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
8977 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
8978 * extra precision for decibel values. If you had the dB value in floating point
8979 * you would take the value after the decimal point, multiply by 64, and divide
8980 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
8981 * implement fixed point or floating point dB volumes. For now, I'll set them
8982 * to 0 just incase a value has lingered from a boot into Windows.
8984 static void ca0132_alt_vol_setup(struct hda_codec *codec)
8986 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
8987 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
8988 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
8989 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
8990 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
8991 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
8992 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
8993 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
8997 * Extra commands that don't really fit anywhere else.
8999 static void sbz_pre_dsp_setup(struct hda_codec *codec)
9001 struct ca0132_spec *spec = codec->spec;
9003 writel(0x00820680, spec->mem_base + 0x01C);
9004 writel(0x00820680, spec->mem_base + 0x01C);
9006 chipio_write(codec, 0x18b0a4, 0x000000c2);
9008 snd_hda_codec_write(codec, 0x11, 0,
9009 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
9012 static void r3d_pre_dsp_setup(struct hda_codec *codec)
9014 chipio_write(codec, 0x18b0a4, 0x000000c2);
9016 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9017 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
9018 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9019 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
9020 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9021 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
9023 snd_hda_codec_write(codec, 0x11, 0,
9024 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
9027 static void r3di_pre_dsp_setup(struct hda_codec *codec)
9029 chipio_write(codec, 0x18b0a4, 0x000000c2);
9031 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9032 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
9033 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9034 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
9035 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9036 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
9038 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9039 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
9040 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9041 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
9042 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9043 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
9044 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9045 VENDOR_CHIPIO_8051_DATA_WRITE, 0x40);
9047 snd_hda_codec_write(codec, 0x11, 0,
9048 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
9052 * These are sent before the DSP is downloaded. Not sure
9053 * what they do, or if they're necessary. Could possibly
9054 * be removed. Figure they're better to leave in.
9056 static const unsigned int ca0113_mmio_init_address_sbz[] = {
9057 0x400, 0x408, 0x40c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c,
9058 0xc0c, 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04
9061 static const unsigned int ca0113_mmio_init_data_sbz[] = {
9062 0x00000030, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9063 0x00000003, 0x000000c1, 0x000000f1, 0x00000001, 0x000000c7,
9064 0x000000c1, 0x00000080
9067 static const unsigned int ca0113_mmio_init_data_zxr[] = {
9068 0x00000030, 0x00000000, 0x00000000, 0x00000003, 0x00000003,
9069 0x00000003, 0x00000001, 0x000000f1, 0x00000001, 0x000000c7,
9070 0x000000c1, 0x00000080
9073 static const unsigned int ca0113_mmio_init_address_ae5[] = {
9074 0x400, 0x42c, 0x46c, 0x4ac, 0x4ec, 0x43c, 0x47c, 0x4bc, 0x4fc, 0x408,
9075 0x100, 0x410, 0x40c, 0x100, 0x100, 0x830, 0x86c, 0x800, 0x86c, 0x800,
9076 0x804, 0x20c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c, 0xc0c,
9077 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04, 0x01c
9080 static const unsigned int ca0113_mmio_init_data_ae5[] = {
9081 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
9082 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
9083 0x00000600, 0x00000014, 0x00000001, 0x0000060f, 0x0000070f,
9084 0x00000aff, 0x00000000, 0x0000006b, 0x00000001, 0x0000006b,
9085 0x00000057, 0x00800000, 0x00880680, 0x00000080, 0x00000030,
9086 0x00000000, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9087 0x00000001, 0x000000f1, 0x00000001, 0x000000c7, 0x000000c1,
9088 0x00000080, 0x00880680
9091 static void ca0132_mmio_init_sbz(struct hda_codec *codec)
9093 struct ca0132_spec *spec = codec->spec;
9094 unsigned int tmp[2], i, count, cur_addr;
9095 const unsigned int *addr, *data;
9097 addr = ca0113_mmio_init_address_sbz;
9098 for (i = 0; i < 3; i++)
9099 writel(0x00000000, spec->mem_base + addr[i]);
9102 switch (ca0132_quirk(spec)) {
9104 tmp[0] = 0x00880480;
9105 tmp[1] = 0x00000080;
9108 tmp[0] = 0x00820680;
9109 tmp[1] = 0x00000083;
9112 tmp[0] = 0x00880680;
9113 tmp[1] = 0x00000083;
9116 tmp[0] = 0x00000000;
9117 tmp[1] = 0x00000000;
9121 for (i = 0; i < 2; i++)
9122 writel(tmp[i], spec->mem_base + addr[cur_addr + i]);
9126 switch (ca0132_quirk(spec)) {
9128 count = ARRAY_SIZE(ca0113_mmio_init_data_zxr);
9129 data = ca0113_mmio_init_data_zxr;
9132 count = ARRAY_SIZE(ca0113_mmio_init_data_sbz);
9133 data = ca0113_mmio_init_data_sbz;
9137 for (i = 0; i < count; i++)
9138 writel(data[i], spec->mem_base + addr[cur_addr + i]);
9141 static void ca0132_mmio_init_ae5(struct hda_codec *codec)
9143 struct ca0132_spec *spec = codec->spec;
9144 const unsigned int *addr, *data;
9145 unsigned int i, count;
9147 addr = ca0113_mmio_init_address_ae5;
9148 data = ca0113_mmio_init_data_ae5;
9149 count = ARRAY_SIZE(ca0113_mmio_init_data_ae5);
9151 if (ca0132_quirk(spec) == QUIRK_AE7) {
9152 writel(0x00000680, spec->mem_base + 0x1c);
9153 writel(0x00880680, spec->mem_base + 0x1c);
9156 for (i = 0; i < count; i++) {
9158 * AE-7 shares all writes with the AE-5, except that it writes
9159 * a different value to 0x20c.
9161 if (i == 21 && ca0132_quirk(spec) == QUIRK_AE7) {
9162 writel(0x00800001, spec->mem_base + addr[i]);
9166 writel(data[i], spec->mem_base + addr[i]);
9169 if (ca0132_quirk(spec) == QUIRK_AE5)
9170 writel(0x00880680, spec->mem_base + 0x1c);
9173 static void ca0132_mmio_init(struct hda_codec *codec)
9175 struct ca0132_spec *spec = codec->spec;
9177 switch (ca0132_quirk(spec)) {
9181 ca0132_mmio_init_sbz(codec);
9184 ca0132_mmio_init_ae5(codec);
9191 static const unsigned int ca0132_ae5_register_set_addresses[] = {
9192 0x304, 0x304, 0x304, 0x304, 0x100, 0x304, 0x100, 0x304, 0x100, 0x304,
9193 0x100, 0x304, 0x86c, 0x800, 0x86c, 0x800, 0x804
9196 static const unsigned char ca0132_ae5_register_set_data[] = {
9197 0x0f, 0x0e, 0x1f, 0x0c, 0x3f, 0x08, 0x7f, 0x00, 0xff, 0x00, 0x6b,
9202 * This function writes to some SFR's, does some region2 writes, and then
9203 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
9206 static void ae5_register_set(struct hda_codec *codec)
9208 struct ca0132_spec *spec = codec->spec;
9209 unsigned int count = ARRAY_SIZE(ca0132_ae5_register_set_addresses);
9210 const unsigned int *addr = ca0132_ae5_register_set_addresses;
9211 const unsigned char *data = ca0132_ae5_register_set_data;
9212 unsigned int i, cur_addr;
9213 unsigned char tmp[3];
9215 if (ca0132_quirk(spec) == QUIRK_AE7) {
9216 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9217 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x41);
9218 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9219 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc8);
9222 chipio_8051_write_direct(codec, 0x93, 0x10);
9223 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9224 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
9225 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9226 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
9228 if (ca0132_quirk(spec) == QUIRK_AE7) {
9238 for (i = cur_addr = 0; i < 3; i++, cur_addr++)
9239 writeb(tmp[i], spec->mem_base + addr[cur_addr]);
9242 * First writes are in single bytes, final are in 4 bytes. So, we use
9243 * writeb, then writel.
9245 for (i = 0; cur_addr < 12; i++, cur_addr++)
9246 writeb(data[i], spec->mem_base + addr[cur_addr]);
9248 for (; cur_addr < count; i++, cur_addr++)
9249 writel(data[i], spec->mem_base + addr[cur_addr]);
9251 writel(0x00800001, spec->mem_base + 0x20c);
9253 if (ca0132_quirk(spec) == QUIRK_AE7) {
9254 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
9255 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
9257 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
9260 chipio_8051_write_direct(codec, 0x90, 0x00);
9261 chipio_8051_write_direct(codec, 0x90, 0x10);
9263 if (ca0132_quirk(spec) == QUIRK_AE5)
9264 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
9266 chipio_write(codec, 0x18b0a4, 0x000000c2);
9268 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
9269 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
9273 * Extra init functions for alternative ca0132 codecs. Done
9274 * here so they don't clutter up the main ca0132_init function
9275 * anymore than they have to.
9277 static void ca0132_alt_init(struct hda_codec *codec)
9279 struct ca0132_spec *spec = codec->spec;
9281 ca0132_alt_vol_setup(codec);
9283 switch (ca0132_quirk(spec)) {
9285 codec_dbg(codec, "SBZ alt_init");
9286 ca0132_gpio_init(codec);
9287 sbz_pre_dsp_setup(codec);
9288 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9289 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9292 codec_dbg(codec, "R3DI alt_init");
9293 ca0132_gpio_init(codec);
9294 ca0132_gpio_setup(codec);
9295 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
9296 r3di_pre_dsp_setup(codec);
9297 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9298 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
9301 r3d_pre_dsp_setup(codec);
9302 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9303 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9306 ca0132_gpio_init(codec);
9307 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9308 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x49);
9309 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9310 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x88);
9311 chipio_write(codec, 0x18b030, 0x00000020);
9312 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9313 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9314 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9317 ca0132_gpio_init(codec);
9318 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9319 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x49);
9320 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9321 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x88);
9322 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9323 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9324 chipio_write(codec, 0x18b008, 0x000000f8);
9325 chipio_write(codec, 0x18b008, 0x000000f0);
9326 chipio_write(codec, 0x18b030, 0x00000020);
9327 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9330 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9331 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9338 static int ca0132_init(struct hda_codec *codec)
9340 struct ca0132_spec *spec = codec->spec;
9341 struct auto_pin_cfg *cfg = &spec->autocfg;
9346 * If the DSP is already downloaded, and init has been entered again,
9347 * there's only two reasons for it. One, the codec has awaken from a
9348 * suspended state, and in that case dspload_is_loaded will return
9349 * false, and the init will be ran again. The other reason it gets
9350 * re entered is on startup for some reason it triggers a suspend and
9351 * resume state. In this case, it will check if the DSP is downloaded,
9352 * and not run the init function again. For codecs using alt_functions,
9353 * it will check if the DSP is loaded properly.
9355 if (spec->dsp_state == DSP_DOWNLOADED) {
9356 dsp_loaded = dspload_is_loaded(codec);
9358 spec->dsp_reload = true;
9359 spec->dsp_state = DSP_DOWNLOAD_INIT;
9361 if (ca0132_quirk(spec) == QUIRK_SBZ)
9362 sbz_dsp_startup_check(codec);
9367 if (spec->dsp_state != DSP_DOWNLOAD_FAILED)
9368 spec->dsp_state = DSP_DOWNLOAD_INIT;
9369 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
9371 if (ca0132_use_pci_mmio(spec))
9372 ca0132_mmio_init(codec);
9374 snd_hda_power_up_pm(codec);
9376 if (ca0132_quirk(spec) == QUIRK_AE5 || ca0132_quirk(spec) == QUIRK_AE7)
9377 ae5_register_set(codec);
9379 ca0132_init_unsol(codec);
9380 ca0132_init_params(codec);
9381 ca0132_init_flags(codec);
9383 snd_hda_sequence_write(codec, spec->base_init_verbs);
9385 if (ca0132_use_alt_functions(spec))
9386 ca0132_alt_init(codec);
9388 ca0132_download_dsp(codec);
9390 ca0132_refresh_widget_caps(codec);
9392 switch (ca0132_quirk(spec)) {
9395 r3d_setup_defaults(codec);
9399 sbz_setup_defaults(codec);
9402 ae5_setup_defaults(codec);
9405 ae7_setup_defaults(codec);
9408 ca0132_setup_defaults(codec);
9409 ca0132_init_analog_mic2(codec);
9410 ca0132_init_dmic(codec);
9414 for (i = 0; i < spec->num_outputs; i++)
9415 init_output(codec, spec->out_pins[i], spec->dacs[0]);
9417 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9419 for (i = 0; i < spec->num_inputs; i++)
9420 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9422 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9424 if (!ca0132_use_alt_functions(spec)) {
9425 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9426 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9427 VENDOR_CHIPIO_PARAM_EX_ID_SET, 0x0D);
9428 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9429 VENDOR_CHIPIO_PARAM_EX_VALUE_SET, 0x20);
9432 if (ca0132_quirk(spec) == QUIRK_SBZ)
9433 ca0132_gpio_setup(codec);
9435 snd_hda_sequence_write(codec, spec->spec_init_verbs);
9436 if (ca0132_use_alt_functions(spec)) {
9437 ca0132_alt_select_out(codec);
9438 ca0132_alt_select_in(codec);
9440 ca0132_select_out(codec);
9441 ca0132_select_mic(codec);
9444 snd_hda_jack_report_sync(codec);
9447 * Re set the PlayEnhancement switch on a resume event, because the
9448 * controls will not be reloaded.
9450 if (spec->dsp_reload) {
9451 spec->dsp_reload = false;
9452 ca0132_pe_switch_set(codec);
9455 snd_hda_power_down_pm(codec);
9460 static int dbpro_init(struct hda_codec *codec)
9462 struct ca0132_spec *spec = codec->spec;
9463 struct auto_pin_cfg *cfg = &spec->autocfg;
9466 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9467 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9469 for (i = 0; i < spec->num_inputs; i++)
9470 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9475 static void ca0132_free(struct hda_codec *codec)
9477 struct ca0132_spec *spec = codec->spec;
9479 cancel_delayed_work_sync(&spec->unsol_hp_work);
9480 snd_hda_power_up(codec);
9481 switch (ca0132_quirk(spec)) {
9483 sbz_exit_chip(codec);
9486 zxr_exit_chip(codec);
9489 r3d_exit_chip(codec);
9492 ae5_exit_chip(codec);
9495 ae7_exit_chip(codec);
9498 r3di_gpio_shutdown(codec);
9504 snd_hda_sequence_write(codec, spec->base_exit_verbs);
9505 ca0132_exit_chip(codec);
9507 snd_hda_power_down(codec);
9510 pci_iounmap(codec->bus->pci, spec->mem_base);
9512 kfree(spec->spec_init_verbs);
9516 static void dbpro_free(struct hda_codec *codec)
9518 struct ca0132_spec *spec = codec->spec;
9520 zxr_dbpro_power_state_shutdown(codec);
9522 kfree(spec->spec_init_verbs);
9526 static void ca0132_reboot_notify(struct hda_codec *codec)
9528 codec->patch_ops.free(codec);
9532 static int ca0132_suspend(struct hda_codec *codec)
9534 struct ca0132_spec *spec = codec->spec;
9536 cancel_delayed_work_sync(&spec->unsol_hp_work);
9541 static const struct hda_codec_ops ca0132_patch_ops = {
9542 .build_controls = ca0132_build_controls,
9543 .build_pcms = ca0132_build_pcms,
9544 .init = ca0132_init,
9545 .free = ca0132_free,
9546 .unsol_event = snd_hda_jack_unsol_event,
9548 .suspend = ca0132_suspend,
9550 .reboot_notify = ca0132_reboot_notify,
9553 static const struct hda_codec_ops dbpro_patch_ops = {
9554 .build_controls = dbpro_build_controls,
9555 .build_pcms = dbpro_build_pcms,
9560 static void ca0132_config(struct hda_codec *codec)
9562 struct ca0132_spec *spec = codec->spec;
9564 spec->dacs[0] = 0x2;
9565 spec->dacs[1] = 0x3;
9566 spec->dacs[2] = 0x4;
9568 spec->multiout.dac_nids = spec->dacs;
9569 spec->multiout.num_dacs = 3;
9571 if (!ca0132_use_alt_functions(spec))
9572 spec->multiout.max_channels = 2;
9574 spec->multiout.max_channels = 6;
9576 switch (ca0132_quirk(spec)) {
9577 case QUIRK_ALIENWARE:
9578 codec_dbg(codec, "%s: QUIRK_ALIENWARE applied.\n", __func__);
9579 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
9582 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
9583 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
9586 codec_dbg(codec, "%s: QUIRK_ZXR applied.\n", __func__);
9587 snd_hda_apply_pincfgs(codec, zxr_pincfgs);
9590 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
9591 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
9594 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
9595 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
9598 codec_dbg(codec, "%s: QUIRK_AE5 applied.\n", __func__);
9599 snd_hda_apply_pincfgs(codec, ae5_pincfgs);
9602 codec_dbg(codec, "%s: QUIRK_AE7 applied.\n", __func__);
9603 snd_hda_apply_pincfgs(codec, ae7_pincfgs);
9609 switch (ca0132_quirk(spec)) {
9610 case QUIRK_ALIENWARE:
9611 spec->num_outputs = 2;
9612 spec->out_pins[0] = 0x0b; /* speaker out */
9613 spec->out_pins[1] = 0x0f;
9614 spec->shared_out_nid = 0x2;
9615 spec->unsol_tag_hp = 0x0f;
9617 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
9618 spec->adcs[1] = 0x8; /* analog mic2 */
9619 spec->adcs[2] = 0xa; /* what u hear */
9621 spec->num_inputs = 3;
9622 spec->input_pins[0] = 0x12;
9623 spec->input_pins[1] = 0x11;
9624 spec->input_pins[2] = 0x13;
9625 spec->shared_mic_nid = 0x7;
9626 spec->unsol_tag_amic1 = 0x11;
9630 spec->num_outputs = 2;
9631 spec->out_pins[0] = 0x0B; /* Line out */
9632 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9633 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9634 spec->out_pins[3] = 0x11; /* Rear surround */
9635 spec->shared_out_nid = 0x2;
9636 spec->unsol_tag_hp = spec->out_pins[1];
9637 spec->unsol_tag_front_hp = spec->out_pins[2];
9639 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9640 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
9641 spec->adcs[2] = 0xa; /* what u hear */
9643 spec->num_inputs = 2;
9644 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9645 spec->input_pins[1] = 0x13; /* What U Hear */
9646 spec->shared_mic_nid = 0x7;
9647 spec->unsol_tag_amic1 = spec->input_pins[0];
9650 spec->dig_out = 0x05;
9651 spec->multiout.dig_out_nid = spec->dig_out;
9652 spec->dig_in = 0x09;
9655 spec->num_outputs = 2;
9656 spec->out_pins[0] = 0x0B; /* Line out */
9657 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9658 spec->out_pins[2] = 0x10; /* Center/LFE */
9659 spec->out_pins[3] = 0x11; /* Rear surround */
9660 spec->shared_out_nid = 0x2;
9661 spec->unsol_tag_hp = spec->out_pins[1];
9662 spec->unsol_tag_front_hp = spec->out_pins[2];
9664 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9665 spec->adcs[1] = 0x8; /* Not connected, no front mic */
9666 spec->adcs[2] = 0xa; /* what u hear */
9668 spec->num_inputs = 2;
9669 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9670 spec->input_pins[1] = 0x13; /* What U Hear */
9671 spec->shared_mic_nid = 0x7;
9672 spec->unsol_tag_amic1 = spec->input_pins[0];
9674 case QUIRK_ZXR_DBPRO:
9675 spec->adcs[0] = 0x8; /* ZxR DBPro Aux In */
9677 spec->num_inputs = 1;
9678 spec->input_pins[0] = 0x11; /* RCA Line-in */
9680 spec->dig_out = 0x05;
9681 spec->multiout.dig_out_nid = spec->dig_out;
9683 spec->dig_in = 0x09;
9687 spec->num_outputs = 2;
9688 spec->out_pins[0] = 0x0B; /* Line out */
9689 spec->out_pins[1] = 0x11; /* Rear headphone out */
9690 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9691 spec->out_pins[3] = 0x0F; /* Rear surround */
9692 spec->shared_out_nid = 0x2;
9693 spec->unsol_tag_hp = spec->out_pins[1];
9694 spec->unsol_tag_front_hp = spec->out_pins[2];
9696 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
9697 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
9698 spec->adcs[2] = 0xa; /* what u hear */
9700 spec->num_inputs = 2;
9701 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9702 spec->input_pins[1] = 0x13; /* What U Hear */
9703 spec->shared_mic_nid = 0x7;
9704 spec->unsol_tag_amic1 = spec->input_pins[0];
9707 spec->dig_out = 0x05;
9708 spec->multiout.dig_out_nid = spec->dig_out;
9711 spec->num_outputs = 2;
9712 spec->out_pins[0] = 0x0B; /* Line out */
9713 spec->out_pins[1] = 0x0F; /* Rear headphone out */
9714 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
9715 spec->out_pins[3] = 0x11; /* Rear surround */
9716 spec->shared_out_nid = 0x2;
9717 spec->unsol_tag_hp = spec->out_pins[1];
9718 spec->unsol_tag_front_hp = spec->out_pins[2];
9720 spec->adcs[0] = 0x07; /* Rear Mic / Line-in */
9721 spec->adcs[1] = 0x08; /* Front Mic, but only if no DSP */
9722 spec->adcs[2] = 0x0a; /* what u hear */
9724 spec->num_inputs = 2;
9725 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
9726 spec->input_pins[1] = 0x13; /* What U Hear */
9727 spec->shared_mic_nid = 0x7;
9728 spec->unsol_tag_amic1 = spec->input_pins[0];
9731 spec->dig_out = 0x05;
9732 spec->multiout.dig_out_nid = spec->dig_out;
9735 spec->num_outputs = 2;
9736 spec->out_pins[0] = 0x0b; /* speaker out */
9737 spec->out_pins[1] = 0x10; /* headphone out */
9738 spec->shared_out_nid = 0x2;
9739 spec->unsol_tag_hp = spec->out_pins[1];
9741 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
9742 spec->adcs[1] = 0x8; /* analog mic2 */
9743 spec->adcs[2] = 0xa; /* what u hear */
9745 spec->num_inputs = 3;
9746 spec->input_pins[0] = 0x12;
9747 spec->input_pins[1] = 0x11;
9748 spec->input_pins[2] = 0x13;
9749 spec->shared_mic_nid = 0x7;
9750 spec->unsol_tag_amic1 = spec->input_pins[0];
9753 spec->dig_out = 0x05;
9754 spec->multiout.dig_out_nid = spec->dig_out;
9755 spec->dig_in = 0x09;
9760 static int ca0132_prepare_verbs(struct hda_codec *codec)
9762 /* Verbs + terminator (an empty element) */
9763 #define NUM_SPEC_VERBS 2
9764 struct ca0132_spec *spec = codec->spec;
9766 spec->chip_init_verbs = ca0132_init_verbs0;
9768 * Since desktop cards use pci_mmio, this can be used to determine
9769 * whether or not to use these verbs instead of a separate bool.
9771 if (ca0132_use_pci_mmio(spec))
9772 spec->desktop_init_verbs = ca0132_init_verbs1;
9773 spec->spec_init_verbs = kcalloc(NUM_SPEC_VERBS,
9774 sizeof(struct hda_verb),
9776 if (!spec->spec_init_verbs)
9780 spec->spec_init_verbs[0].nid = 0x0b;
9781 spec->spec_init_verbs[0].param = 0x78D;
9782 spec->spec_init_verbs[0].verb = 0x00;
9784 /* Previously commented configuration */
9786 spec->spec_init_verbs[2].nid = 0x0b;
9787 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
9788 spec->spec_init_verbs[2].verb = 0x02;
9790 spec->spec_init_verbs[3].nid = 0x10;
9791 spec->spec_init_verbs[3].param = 0x78D;
9792 spec->spec_init_verbs[3].verb = 0x02;
9794 spec->spec_init_verbs[4].nid = 0x10;
9795 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
9796 spec->spec_init_verbs[4].verb = 0x02;
9799 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
9804 * The Sound Blaster ZxR shares the same PCI subsystem ID as some regular
9805 * Sound Blaster Z cards. However, they have different HDA codec subsystem
9806 * ID's. So, we check for the ZxR's subsystem ID, as well as the DBPro
9807 * daughter boards ID.
9809 static void sbz_detect_quirk(struct hda_codec *codec)
9811 struct ca0132_spec *spec = codec->spec;
9813 switch (codec->core.subsystem_id) {
9815 spec->quirk = QUIRK_ZXR;
9818 spec->quirk = QUIRK_ZXR_DBPRO;
9821 spec->quirk = QUIRK_SBZ;
9826 static int patch_ca0132(struct hda_codec *codec)
9828 struct ca0132_spec *spec;
9830 const struct snd_pci_quirk *quirk;
9832 codec_dbg(codec, "patch_ca0132\n");
9834 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9838 spec->codec = codec;
9840 /* Detect codec quirk */
9841 quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks);
9843 spec->quirk = quirk->value;
9845 spec->quirk = QUIRK_NONE;
9846 if (ca0132_quirk(spec) == QUIRK_SBZ)
9847 sbz_detect_quirk(codec);
9849 if (ca0132_quirk(spec) == QUIRK_ZXR_DBPRO)
9850 codec->patch_ops = dbpro_patch_ops;
9852 codec->patch_ops = ca0132_patch_ops;
9854 codec->pcm_format_first = 1;
9855 codec->no_sticky_stream = 1;
9858 spec->dsp_state = DSP_DOWNLOAD_INIT;
9859 spec->num_mixers = 1;
9861 /* Set which mixers each quirk uses. */
9862 switch (ca0132_quirk(spec)) {
9864 spec->mixers[0] = desktop_mixer;
9865 snd_hda_codec_set_name(codec, "Sound Blaster Z");
9868 spec->mixers[0] = desktop_mixer;
9869 snd_hda_codec_set_name(codec, "Sound Blaster ZxR");
9871 case QUIRK_ZXR_DBPRO:
9874 spec->mixers[0] = desktop_mixer;
9875 snd_hda_codec_set_name(codec, "Recon3D");
9878 spec->mixers[0] = r3di_mixer;
9879 snd_hda_codec_set_name(codec, "Recon3Di");
9882 spec->mixers[0] = desktop_mixer;
9883 snd_hda_codec_set_name(codec, "Sound BlasterX AE-5");
9886 spec->mixers[0] = desktop_mixer;
9887 snd_hda_codec_set_name(codec, "Sound Blaster AE-7");
9890 spec->mixers[0] = ca0132_mixer;
9894 /* Setup whether or not to use alt functions/controls/pci_mmio */
9895 switch (ca0132_quirk(spec)) {
9901 spec->use_alt_controls = true;
9902 spec->use_alt_functions = true;
9903 spec->use_pci_mmio = true;
9906 spec->use_alt_controls = true;
9907 spec->use_alt_functions = true;
9908 spec->use_pci_mmio = false;
9911 spec->use_alt_controls = false;
9912 spec->use_alt_functions = false;
9913 spec->use_pci_mmio = false;
9918 if (spec->use_pci_mmio) {
9919 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
9920 if (spec->mem_base == NULL) {
9921 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
9922 spec->quirk = QUIRK_NONE;
9927 spec->base_init_verbs = ca0132_base_init_verbs;
9928 spec->base_exit_verbs = ca0132_base_exit_verbs;
9930 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
9932 ca0132_init_chip(codec);
9934 ca0132_config(codec);
9936 err = ca0132_prepare_verbs(codec);
9940 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
9954 static const struct hda_device_id snd_hda_id_ca0132[] = {
9955 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132),
9958 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132);
9960 MODULE_LICENSE("GPL");
9961 MODULE_DESCRIPTION("Creative Sound Core3D codec");
9963 static struct hda_codec_driver ca0132_driver = {
9964 .id = snd_hda_id_ca0132,
9967 module_hda_codec_driver(ca0132_driver);