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] = { "Microphone", "Line In", "Front Microphone" };
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",
792 * Data structures for storing audio router remapping data. These are used to
793 * remap a currently active streams ports.
795 struct chipio_stream_remap_data
{
796 unsigned int stream_id
;
799 unsigned int offset
[16];
800 unsigned int value
[16];
803 static const struct chipio_stream_remap_data stream_remap_data
[] = {
806 .offset
= { 0x00, 0x04, 0x08, 0x0c },
807 .value
= { 0x0001f8c0, 0x0001f9c1, 0x0001fac6, 0x0001fbc7 },
811 .offset
= { 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c,
812 0x20, 0x24, 0x28, 0x2c },
813 .value
= { 0x0001e0c0, 0x0001e1c1, 0x0001e4c2, 0x0001e5c3,
814 0x0001e2c4, 0x0001e3c5, 0x0001e8c6, 0x0001e9c7,
815 0x0001ecc8, 0x0001edc9, 0x0001eaca, 0x0001ebcb },
819 .offset
= { 0x08, 0x0c, 0x10, 0x14, 0x20, 0x24, 0x28, 0x2c },
820 .value
= { 0x000140c2, 0x000141c3, 0x000150c4, 0x000151c5,
821 0x000142c8, 0x000143c9, 0x000152ca, 0x000153cb },
825 enum hda_cmd_vendor_io
{
827 VENDOR_DSPIO_SCP_WRITE_DATA_LOW
= 0x000,
828 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH
= 0x100,
830 VENDOR_DSPIO_STATUS
= 0xF01,
831 VENDOR_DSPIO_SCP_POST_READ_DATA
= 0x702,
832 VENDOR_DSPIO_SCP_READ_DATA
= 0xF02,
833 VENDOR_DSPIO_DSP_INIT
= 0x703,
834 VENDOR_DSPIO_SCP_POST_COUNT_QUERY
= 0x704,
835 VENDOR_DSPIO_SCP_READ_COUNT
= 0xF04,
837 /* for ChipIO node */
838 VENDOR_CHIPIO_ADDRESS_LOW
= 0x000,
839 VENDOR_CHIPIO_ADDRESS_HIGH
= 0x100,
840 VENDOR_CHIPIO_STREAM_FORMAT
= 0x200,
841 VENDOR_CHIPIO_DATA_LOW
= 0x300,
842 VENDOR_CHIPIO_DATA_HIGH
= 0x400,
844 VENDOR_CHIPIO_8051_WRITE_DIRECT
= 0x500,
845 VENDOR_CHIPIO_8051_READ_DIRECT
= 0xD00,
847 VENDOR_CHIPIO_GET_PARAMETER
= 0xF00,
848 VENDOR_CHIPIO_STATUS
= 0xF01,
849 VENDOR_CHIPIO_HIC_POST_READ
= 0x702,
850 VENDOR_CHIPIO_HIC_READ_DATA
= 0xF03,
852 VENDOR_CHIPIO_8051_DATA_WRITE
= 0x707,
853 VENDOR_CHIPIO_8051_DATA_READ
= 0xF07,
854 VENDOR_CHIPIO_8051_PMEM_READ
= 0xF08,
855 VENDOR_CHIPIO_8051_IRAM_WRITE
= 0x709,
856 VENDOR_CHIPIO_8051_IRAM_READ
= 0xF09,
858 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
= 0x70A,
859 VENDOR_CHIPIO_CT_EXTENSIONS_GET
= 0xF0A,
861 VENDOR_CHIPIO_PLL_PMU_WRITE
= 0x70C,
862 VENDOR_CHIPIO_PLL_PMU_READ
= 0xF0C,
863 VENDOR_CHIPIO_8051_ADDRESS_LOW
= 0x70D,
864 VENDOR_CHIPIO_8051_ADDRESS_HIGH
= 0x70E,
865 VENDOR_CHIPIO_FLAG_SET
= 0x70F,
866 VENDOR_CHIPIO_FLAGS_GET
= 0xF0F,
867 VENDOR_CHIPIO_PARAM_SET
= 0x710,
868 VENDOR_CHIPIO_PARAM_GET
= 0xF10,
870 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET
= 0x711,
871 VENDOR_CHIPIO_PORT_ALLOC_SET
= 0x712,
872 VENDOR_CHIPIO_PORT_ALLOC_GET
= 0xF12,
873 VENDOR_CHIPIO_PORT_FREE_SET
= 0x713,
875 VENDOR_CHIPIO_PARAM_EX_ID_GET
= 0xF17,
876 VENDOR_CHIPIO_PARAM_EX_ID_SET
= 0x717,
877 VENDOR_CHIPIO_PARAM_EX_VALUE_GET
= 0xF18,
878 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
= 0x718,
880 VENDOR_CHIPIO_DMIC_CTL_SET
= 0x788,
881 VENDOR_CHIPIO_DMIC_CTL_GET
= 0xF88,
882 VENDOR_CHIPIO_DMIC_PIN_SET
= 0x789,
883 VENDOR_CHIPIO_DMIC_PIN_GET
= 0xF89,
884 VENDOR_CHIPIO_DMIC_MCLK_SET
= 0x78A,
885 VENDOR_CHIPIO_DMIC_MCLK_GET
= 0xF8A,
887 VENDOR_CHIPIO_EAPD_SEL_SET
= 0x78D
893 enum control_flag_id
{
894 /* Connection manager stream setup is bypassed/enabled */
895 CONTROL_FLAG_C_MGR
= 0,
896 /* DSP DMA is bypassed/enabled */
897 CONTROL_FLAG_DMA
= 1,
898 /* 8051 'idle' mode is disabled/enabled */
899 CONTROL_FLAG_IDLE_ENABLE
= 2,
900 /* Tracker for the SPDIF-in path is bypassed/enabled */
901 CONTROL_FLAG_TRACKER
= 3,
902 /* DigitalOut to Spdif2Out connection is disabled/enabled */
903 CONTROL_FLAG_SPDIF2OUT
= 4,
904 /* Digital Microphone is disabled/enabled */
905 CONTROL_FLAG_DMIC
= 5,
906 /* ADC_B rate is 48 kHz/96 kHz */
907 CONTROL_FLAG_ADC_B_96KHZ
= 6,
908 /* ADC_C rate is 48 kHz/96 kHz */
909 CONTROL_FLAG_ADC_C_96KHZ
= 7,
910 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
911 CONTROL_FLAG_DAC_96KHZ
= 8,
912 /* DSP rate is 48 kHz/96 kHz */
913 CONTROL_FLAG_DSP_96KHZ
= 9,
914 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
915 CONTROL_FLAG_SRC_CLOCK_196MHZ
= 10,
916 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
917 CONTROL_FLAG_SRC_RATE_96KHZ
= 11,
918 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
919 CONTROL_FLAG_DECODE_LOOP
= 12,
920 /* De-emphasis filter on DAC-1 disabled/enabled */
921 CONTROL_FLAG_DAC1_DEEMPHASIS
= 13,
922 /* De-emphasis filter on DAC-2 disabled/enabled */
923 CONTROL_FLAG_DAC2_DEEMPHASIS
= 14,
924 /* De-emphasis filter on DAC-3 disabled/enabled */
925 CONTROL_FLAG_DAC3_DEEMPHASIS
= 15,
926 /* High-pass filter on ADC_B disabled/enabled */
927 CONTROL_FLAG_ADC_B_HIGH_PASS
= 16,
928 /* High-pass filter on ADC_C disabled/enabled */
929 CONTROL_FLAG_ADC_C_HIGH_PASS
= 17,
930 /* Common mode on Port_A disabled/enabled */
931 CONTROL_FLAG_PORT_A_COMMON_MODE
= 18,
932 /* Common mode on Port_D disabled/enabled */
933 CONTROL_FLAG_PORT_D_COMMON_MODE
= 19,
934 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
935 CONTROL_FLAG_PORT_A_10KOHM_LOAD
= 20,
936 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
937 CONTROL_FLAG_PORT_D_10KOHM_LOAD
= 21,
938 /* ASI rate is 48kHz/96kHz */
939 CONTROL_FLAG_ASI_96KHZ
= 22,
940 /* DAC power settings able to control attached ports no/yes */
941 CONTROL_FLAG_DACS_CONTROL_PORTS
= 23,
942 /* Clock Stop OK reporting is disabled/enabled */
943 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
= 24,
944 /* Number of control flags */
945 CONTROL_FLAGS_MAX
= (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
+1)
949 * Control parameter IDs
951 enum control_param_id
{
952 /* 0: None, 1: Mic1In*/
953 CONTROL_PARAM_VIP_SOURCE
= 1,
954 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
955 CONTROL_PARAM_SPDIF1_SOURCE
= 2,
956 /* Port A output stage gain setting to use when 16 Ohm output
957 * impedance is selected*/
958 CONTROL_PARAM_PORTA_160OHM_GAIN
= 8,
959 /* Port D output stage gain setting to use when 16 Ohm output
960 * impedance is selected*/
961 CONTROL_PARAM_PORTD_160OHM_GAIN
= 10,
964 * This control param name was found in the 8051 memory, and makes
965 * sense given the fact the AE-5 uses it and has the ASI flag set.
967 CONTROL_PARAM_ASI
= 23,
971 /* Select stream with the given ID */
972 CONTROL_PARAM_STREAM_ID
= 24,
973 /* Source connection point for the selected stream */
974 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT
= 25,
975 /* Destination connection point for the selected stream */
976 CONTROL_PARAM_STREAM_DEST_CONN_POINT
= 26,
977 /* Number of audio channels in the selected stream */
978 CONTROL_PARAM_STREAMS_CHANNELS
= 27,
979 /*Enable control for the selected stream */
980 CONTROL_PARAM_STREAM_CONTROL
= 28,
982 /* Connection Point Control */
984 /* Select connection point with the given ID */
985 CONTROL_PARAM_CONN_POINT_ID
= 29,
986 /* Connection point sample rate */
987 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
= 30,
991 /* Select HDA node with the given ID */
992 CONTROL_PARAM_NODE_ID
= 31
996 * Dsp Io Status codes
998 enum hda_vendor_status_dspio
{
1000 VENDOR_STATUS_DSPIO_OK
= 0x00,
1001 /* Busy, unable to accept new command, the host must retry */
1002 VENDOR_STATUS_DSPIO_BUSY
= 0x01,
1003 /* SCP command queue is full */
1004 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL
= 0x02,
1005 /* SCP response queue is empty */
1006 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
= 0x03
1010 * Chip Io Status codes
1012 enum hda_vendor_status_chipio
{
1014 VENDOR_STATUS_CHIPIO_OK
= 0x00,
1015 /* Busy, unable to accept new command, the host must retry */
1016 VENDOR_STATUS_CHIPIO_BUSY
= 0x01
1020 * CA0132 sample rate
1022 enum ca0132_sample_rate
{
1042 SR_RATE_UNKNOWN
= 0x1F
1045 enum dsp_download_state
{
1046 DSP_DOWNLOAD_FAILED
= -1,
1047 DSP_DOWNLOAD_INIT
= 0,
1048 DSP_DOWNLOADING
= 1,
1052 /* retrieve parameters from hda format */
1053 #define get_hdafmt_chs(fmt) (fmt & 0xf)
1054 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
1055 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
1056 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
1062 struct ca0132_spec
{
1063 const struct snd_kcontrol_new
*mixers
[5];
1064 unsigned int num_mixers
;
1065 const struct hda_verb
*base_init_verbs
;
1066 const struct hda_verb
*base_exit_verbs
;
1067 const struct hda_verb
*chip_init_verbs
;
1068 const struct hda_verb
*desktop_init_verbs
;
1069 struct hda_verb
*spec_init_verbs
;
1070 struct auto_pin_cfg autocfg
;
1072 /* Nodes configurations */
1073 struct hda_multi_out multiout
;
1074 hda_nid_t out_pins
[AUTO_CFG_MAX_OUTS
];
1075 hda_nid_t dacs
[AUTO_CFG_MAX_OUTS
];
1076 unsigned int num_outputs
;
1077 hda_nid_t input_pins
[AUTO_PIN_LAST
];
1078 hda_nid_t adcs
[AUTO_PIN_LAST
];
1081 unsigned int num_inputs
;
1082 hda_nid_t shared_mic_nid
;
1083 hda_nid_t shared_out_nid
;
1084 hda_nid_t unsol_tag_hp
;
1085 hda_nid_t unsol_tag_front_hp
; /* for desktop ca0132 codecs */
1086 hda_nid_t unsol_tag_amic1
;
1089 struct mutex chipio_mutex
; /* chip access mutex */
1092 /* DSP download related */
1093 enum dsp_download_state dsp_state
;
1094 unsigned int dsp_stream_id
;
1095 unsigned int wait_scp
;
1096 unsigned int wait_scp_header
;
1097 unsigned int wait_num_data
;
1098 unsigned int scp_resp_header
;
1099 unsigned int scp_resp_data
[4];
1100 unsigned int scp_resp_count
;
1101 bool startup_check_entered
;
1104 /* mixer and effects related */
1105 unsigned char dmic_ctl
;
1108 long vnode_lvol
[VNODES_COUNT
];
1109 long vnode_rvol
[VNODES_COUNT
];
1110 long vnode_lswitch
[VNODES_COUNT
];
1111 long vnode_rswitch
[VNODES_COUNT
];
1112 long effects_switch
[EFFECTS_COUNT
];
1115 /* ca0132_alt control related values */
1116 unsigned char in_enum_val
;
1117 unsigned char out_enum_val
;
1118 unsigned char channel_cfg_val
;
1119 unsigned char speaker_range_val
[2];
1120 unsigned char mic_boost_enum_val
;
1121 unsigned char smart_volume_setting
;
1122 unsigned char bass_redirection_val
;
1123 long bass_redirect_xover_freq
;
1124 long fx_ctl_val
[EFFECT_LEVEL_SLIDERS
];
1125 long xbass_xover_freq
;
1127 unsigned int tlv
[4];
1128 struct hda_vmaster_mute_hook vmaster_mute
;
1129 /* AE-5 Control values */
1130 unsigned char ae5_headphone_gain_val
;
1131 unsigned char ae5_filter_val
;
1132 /* ZxR Control Values */
1133 unsigned char zxr_gain_set
;
1135 struct hda_codec
*codec
;
1136 struct delayed_work unsol_hp_work
;
1139 #ifdef ENABLE_TUNING_CONTROLS
1140 long cur_ctl_vals
[TUNING_CTLS_COUNT
];
1143 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
1144 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
1148 void __iomem
*mem_base
;
1151 * Whether or not to use the alt functions like alt_select_out,
1152 * alt_select_in, etc. Only used on desktop codecs for now, because of
1153 * surround sound support.
1155 bool use_alt_functions
;
1158 * Whether or not to use alt controls: volume effect sliders, EQ
1159 * presets, smart volume presets, and new control names with FX prefix.
1160 * Renames PlayEnhancement and CrystalVoice too.
1162 bool use_alt_controls
;
1166 * CA0132 quirks table
1171 QUIRK_ALIENWARE_M17XR4
,
1182 #define ca0132_quirk(spec) ((spec)->quirk)
1183 #define ca0132_use_pci_mmio(spec) ((spec)->use_pci_mmio)
1184 #define ca0132_use_alt_functions(spec) ((spec)->use_alt_functions)
1185 #define ca0132_use_alt_controls(spec) ((spec)->use_alt_controls)
1187 #define ca0132_quirk(spec) ({ (void)(spec); QUIRK_NONE; })
1188 #define ca0132_use_alt_functions(spec) ({ (void)(spec); false; })
1189 #define ca0132_use_pci_mmio(spec) ({ (void)(spec); false; })
1190 #define ca0132_use_alt_controls(spec) ({ (void)(spec); false; })
1193 static const struct hda_pintbl alienware_pincfgs
[] = {
1194 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1195 { 0x0c, 0x411111f0 }, /* N/A */
1196 { 0x0d, 0x411111f0 }, /* N/A */
1197 { 0x0e, 0x411111f0 }, /* N/A */
1198 { 0x0f, 0x0321101f }, /* HP */
1199 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1200 { 0x11, 0x03a11021 }, /* Mic */
1201 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1202 { 0x13, 0x411111f0 }, /* N/A */
1203 { 0x18, 0x411111f0 }, /* N/A */
1207 /* Sound Blaster Z pin configs taken from Windows Driver */
1208 static const struct hda_pintbl sbz_pincfgs
[] = {
1209 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1210 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1211 { 0x0d, 0x014510f0 }, /* Digital Out */
1212 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1213 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1214 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1215 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1216 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1217 { 0x13, 0x908700f0 }, /* What U Hear In*/
1218 { 0x18, 0x50d000f0 }, /* N/A */
1222 /* Sound Blaster ZxR pin configs taken from Windows Driver */
1223 static const struct hda_pintbl zxr_pincfgs
[] = {
1224 { 0x0b, 0x01047110 }, /* Port G -- Lineout FRONT L/R */
1225 { 0x0c, 0x414510f0 }, /* SPDIF Out 1 - Disabled*/
1226 { 0x0d, 0x014510f0 }, /* Digital Out */
1227 { 0x0e, 0x41c520f0 }, /* SPDIF In - Disabled*/
1228 { 0x0f, 0x0122711f }, /* Port A -- BackPanel HP */
1229 { 0x10, 0x01017111 }, /* Port D -- Center/LFE */
1230 { 0x11, 0x01017114 }, /* Port B -- LineMicIn2 / Rear L/R */
1231 { 0x12, 0x01a271f0 }, /* Port C -- LineIn1 */
1232 { 0x13, 0x908700f0 }, /* What U Hear In*/
1233 { 0x18, 0x50d000f0 }, /* N/A */
1237 /* Recon3D pin configs taken from Windows Driver */
1238 static const struct hda_pintbl r3d_pincfgs
[] = {
1239 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1240 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1241 { 0x0d, 0x014510f0 }, /* Digital Out */
1242 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1243 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1244 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1245 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1246 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1247 { 0x13, 0x908700f0 }, /* What U Hear In*/
1248 { 0x18, 0x50d000f0 }, /* N/A */
1252 /* Sound Blaster AE-5 pin configs taken from Windows Driver */
1253 static const struct hda_pintbl ae5_pincfgs
[] = {
1254 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1255 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1256 { 0x0d, 0x014510f0 }, /* Digital Out */
1257 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1258 { 0x0f, 0x01017114 }, /* Port A -- Rear L/R. */
1259 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1260 { 0x11, 0x012170ff }, /* Port B -- LineMicIn2 / Rear Headphone */
1261 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1262 { 0x13, 0x908700f0 }, /* What U Hear In*/
1263 { 0x18, 0x50d000f0 }, /* N/A */
1267 /* Recon3D integrated pin configs taken from Windows Driver */
1268 static const struct hda_pintbl r3di_pincfgs
[] = {
1269 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1270 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1271 { 0x0d, 0x014510f0 }, /* Digital Out */
1272 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1273 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1274 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1275 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1276 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1277 { 0x13, 0x908700f0 }, /* What U Hear In*/
1278 { 0x18, 0x500000f0 }, /* N/A */
1282 static const struct hda_pintbl ae7_pincfgs
[] = {
1283 { 0x0b, 0x01017010 },
1284 { 0x0c, 0x014510f0 },
1285 { 0x0d, 0x414510f0 },
1286 { 0x0e, 0x01c520f0 },
1287 { 0x0f, 0x01017114 },
1288 { 0x10, 0x01017011 },
1289 { 0x11, 0x018170ff },
1290 { 0x12, 0x01a170f0 },
1291 { 0x13, 0x908700f0 },
1292 { 0x18, 0x500000f0 },
1296 static const struct snd_pci_quirk ca0132_quirks
[] = {
1297 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4
),
1298 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE
),
1299 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE
),
1300 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE
),
1301 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ
),
1302 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ
),
1303 SND_PCI_QUIRK(0x1102, 0x0027, "Sound Blaster Z", QUIRK_SBZ
),
1304 SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ
),
1305 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI
),
1306 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI
),
1307 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI
),
1308 SND_PCI_QUIRK(0x3842, 0x1038, "EVGA X99 Classified", QUIRK_R3DI
),
1309 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D
),
1310 SND_PCI_QUIRK(0x1102, 0x0018, "Recon3D", QUIRK_R3D
),
1311 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5
),
1312 SND_PCI_QUIRK(0x1102, 0x0081, "Sound Blaster AE-7", QUIRK_AE7
),
1316 /* Output selection quirk info structures. */
1317 #define MAX_QUIRK_MMIO_GPIO_SET_VALS 3
1318 #define MAX_QUIRK_SCP_SET_VALS 2
1319 struct ca0132_alt_out_set_info
{
1320 unsigned int dac2port
; /* ParamID 0x0d value. */
1326 unsigned int mmio_gpio_count
;
1327 char mmio_gpio_pin
[MAX_QUIRK_MMIO_GPIO_SET_VALS
];
1328 char mmio_gpio_set
[MAX_QUIRK_MMIO_GPIO_SET_VALS
];
1330 unsigned int scp_cmds_count
;
1331 unsigned int scp_cmd_mid
[MAX_QUIRK_SCP_SET_VALS
];
1332 unsigned int scp_cmd_req
[MAX_QUIRK_SCP_SET_VALS
];
1333 unsigned int scp_cmd_val
[MAX_QUIRK_SCP_SET_VALS
];
1335 bool has_chipio_write
;
1336 unsigned int chipio_write_addr
;
1337 unsigned int chipio_write_data
;
1340 struct ca0132_alt_out_set_quirk_data
{
1343 bool has_headphone_gain
;
1346 struct ca0132_alt_out_set_info out_set_info
[NUM_OF_OUTPUTS
];
1349 static const struct ca0132_alt_out_set_quirk_data quirk_out_set_data
[] = {
1350 { .quirk_id
= QUIRK_R3DI
,
1351 .has_headphone_gain
= false,
1352 .is_ae_series
= false,
1356 .has_hda_gpio
= true,
1359 .mmio_gpio_count
= 0,
1360 .scp_cmds_count
= 0,
1361 .has_chipio_write
= false,
1365 .has_hda_gpio
= true,
1368 .mmio_gpio_count
= 0,
1369 .scp_cmds_count
= 0,
1370 .has_chipio_write
= false,
1373 { .quirk_id
= QUIRK_R3D
,
1374 .has_headphone_gain
= false,
1375 .is_ae_series
= false,
1379 .has_hda_gpio
= false,
1380 .mmio_gpio_count
= 1,
1381 .mmio_gpio_pin
= { 1 },
1382 .mmio_gpio_set
= { 1 },
1383 .scp_cmds_count
= 0,
1384 .has_chipio_write
= false,
1388 .has_hda_gpio
= false,
1389 .mmio_gpio_count
= 1,
1390 .mmio_gpio_pin
= { 1 },
1391 .mmio_gpio_set
= { 0 },
1392 .scp_cmds_count
= 0,
1393 .has_chipio_write
= false,
1396 { .quirk_id
= QUIRK_SBZ
,
1397 .has_headphone_gain
= false,
1398 .is_ae_series
= false,
1402 .has_hda_gpio
= false,
1403 .mmio_gpio_count
= 3,
1404 .mmio_gpio_pin
= { 7, 4, 1 },
1405 .mmio_gpio_set
= { 0, 1, 1 },
1406 .scp_cmds_count
= 0,
1407 .has_chipio_write
= false, },
1410 .has_hda_gpio
= false,
1411 .mmio_gpio_count
= 3,
1412 .mmio_gpio_pin
= { 7, 4, 1 },
1413 .mmio_gpio_set
= { 1, 1, 0 },
1414 .scp_cmds_count
= 0,
1415 .has_chipio_write
= false,
1418 { .quirk_id
= QUIRK_ZXR
,
1419 .has_headphone_gain
= true,
1420 .is_ae_series
= false,
1424 .has_hda_gpio
= false,
1425 .mmio_gpio_count
= 3,
1426 .mmio_gpio_pin
= { 2, 3, 5 },
1427 .mmio_gpio_set
= { 1, 1, 0 },
1428 .scp_cmds_count
= 0,
1429 .has_chipio_write
= false,
1433 .has_hda_gpio
= false,
1434 .mmio_gpio_count
= 3,
1435 .mmio_gpio_pin
= { 2, 3, 5 },
1436 .mmio_gpio_set
= { 0, 1, 1 },
1437 .scp_cmds_count
= 0,
1438 .has_chipio_write
= false,
1441 { .quirk_id
= QUIRK_AE5
,
1442 .has_headphone_gain
= true,
1443 .is_ae_series
= true,
1447 .has_hda_gpio
= false,
1448 .mmio_gpio_count
= 0,
1449 .scp_cmds_count
= 2,
1450 .scp_cmd_mid
= { 0x96, 0x96 },
1451 .scp_cmd_req
= { SPEAKER_TUNING_FRONT_LEFT_INVERT
,
1452 SPEAKER_TUNING_FRONT_RIGHT_INVERT
},
1453 .scp_cmd_val
= { FLOAT_ZERO
, FLOAT_ZERO
},
1454 .has_chipio_write
= true,
1455 .chipio_write_addr
= 0x0018b03c,
1456 .chipio_write_data
= 0x00000012
1460 .has_hda_gpio
= false,
1461 .mmio_gpio_count
= 0,
1462 .scp_cmds_count
= 2,
1463 .scp_cmd_mid
= { 0x96, 0x96 },
1464 .scp_cmd_req
= { SPEAKER_TUNING_FRONT_LEFT_INVERT
,
1465 SPEAKER_TUNING_FRONT_RIGHT_INVERT
},
1466 .scp_cmd_val
= { FLOAT_ONE
, FLOAT_ONE
},
1467 .has_chipio_write
= true,
1468 .chipio_write_addr
= 0x0018b03c,
1469 .chipio_write_data
= 0x00000012
1472 { .quirk_id
= QUIRK_AE7
,
1473 .has_headphone_gain
= true,
1474 .is_ae_series
= true,
1478 .has_hda_gpio
= false,
1479 .mmio_gpio_count
= 1,
1480 .mmio_gpio_pin
= { 0 },
1481 .mmio_gpio_set
= { 1 },
1482 .scp_cmds_count
= 2,
1483 .scp_cmd_mid
= { 0x96, 0x96 },
1484 .scp_cmd_req
= { SPEAKER_TUNING_FRONT_LEFT_INVERT
,
1485 SPEAKER_TUNING_FRONT_RIGHT_INVERT
},
1486 .scp_cmd_val
= { FLOAT_ZERO
, FLOAT_ZERO
},
1487 .has_chipio_write
= true,
1488 .chipio_write_addr
= 0x0018b03c,
1489 .chipio_write_data
= 0x00000000
1493 .has_hda_gpio
= false,
1494 .mmio_gpio_count
= 1,
1495 .mmio_gpio_pin
= { 0 },
1496 .mmio_gpio_set
= { 1 },
1497 .scp_cmds_count
= 2,
1498 .scp_cmd_mid
= { 0x96, 0x96 },
1499 .scp_cmd_req
= { SPEAKER_TUNING_FRONT_LEFT_INVERT
,
1500 SPEAKER_TUNING_FRONT_RIGHT_INVERT
},
1501 .scp_cmd_val
= { FLOAT_ONE
, FLOAT_ONE
},
1502 .has_chipio_write
= true,
1503 .chipio_write_addr
= 0x0018b03c,
1504 .chipio_write_data
= 0x00000010
1510 * CA0132 codec access
1512 static unsigned int codec_send_command(struct hda_codec
*codec
, hda_nid_t nid
,
1513 unsigned int verb
, unsigned int parm
, unsigned int *res
)
1515 unsigned int response
;
1516 response
= snd_hda_codec_read(codec
, nid
, 0, verb
, parm
);
1519 return ((response
== -1) ? -1 : 0);
1522 static int codec_set_converter_format(struct hda_codec
*codec
, hda_nid_t nid
,
1523 unsigned short converter_format
, unsigned int *res
)
1525 return codec_send_command(codec
, nid
, VENDOR_CHIPIO_STREAM_FORMAT
,
1526 converter_format
& 0xffff, res
);
1529 static int codec_set_converter_stream_channel(struct hda_codec
*codec
,
1530 hda_nid_t nid
, unsigned char stream
,
1531 unsigned char channel
, unsigned int *res
)
1533 unsigned char converter_stream_channel
= 0;
1535 converter_stream_channel
= (stream
<< 4) | (channel
& 0x0f);
1536 return codec_send_command(codec
, nid
, AC_VERB_SET_CHANNEL_STREAMID
,
1537 converter_stream_channel
, res
);
1540 /* Chip access helper function */
1541 static int chipio_send(struct hda_codec
*codec
,
1546 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1548 /* send bits of data specified by reg */
1550 res
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
1552 if (res
== VENDOR_STATUS_CHIPIO_OK
)
1555 } while (time_before(jiffies
, timeout
));
1561 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1563 static int chipio_write_address(struct hda_codec
*codec
,
1564 unsigned int chip_addx
)
1566 struct ca0132_spec
*spec
= codec
->spec
;
1569 if (spec
->curr_chip_addx
== chip_addx
)
1572 /* send low 16 bits of the address */
1573 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_LOW
,
1574 chip_addx
& 0xffff);
1577 /* send high 16 bits of the address */
1578 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_HIGH
,
1582 spec
->curr_chip_addx
= (res
< 0) ? ~0U : chip_addx
;
1588 * Write data through the vendor widget -- NOT protected by the Mutex!
1590 static int chipio_write_data(struct hda_codec
*codec
, unsigned int data
)
1592 struct ca0132_spec
*spec
= codec
->spec
;
1595 /* send low 16 bits of the data */
1596 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_LOW
, data
& 0xffff);
1599 /* send high 16 bits of the data */
1600 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_HIGH
,
1604 /*If no error encountered, automatically increment the address
1605 as per chip behaviour*/
1606 spec
->curr_chip_addx
= (res
!= -EIO
) ?
1607 (spec
->curr_chip_addx
+ 4) : ~0U;
1612 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1614 static int chipio_write_data_multiple(struct hda_codec
*codec
,
1621 codec_dbg(codec
, "chipio_write_data null ptr\n");
1625 while ((count
-- != 0) && (status
== 0))
1626 status
= chipio_write_data(codec
, *data
++);
1633 * Read data through the vendor widget -- NOT protected by the Mutex!
1635 static int chipio_read_data(struct hda_codec
*codec
, unsigned int *data
)
1637 struct ca0132_spec
*spec
= codec
->spec
;
1641 res
= chipio_send(codec
, VENDOR_CHIPIO_HIC_POST_READ
, 0);
1645 res
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
1650 *data
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
1651 VENDOR_CHIPIO_HIC_READ_DATA
,
1655 /*If no error encountered, automatically increment the address
1656 as per chip behaviour*/
1657 spec
->curr_chip_addx
= (res
!= -EIO
) ?
1658 (spec
->curr_chip_addx
+ 4) : ~0U;
1663 * Write given value to the given address through the chip I/O widget.
1664 * protected by the Mutex
1666 static int chipio_write(struct hda_codec
*codec
,
1667 unsigned int chip_addx
, const unsigned int data
)
1669 struct ca0132_spec
*spec
= codec
->spec
;
1672 mutex_lock(&spec
->chipio_mutex
);
1674 /* write the address, and if successful proceed to write data */
1675 err
= chipio_write_address(codec
, chip_addx
);
1679 err
= chipio_write_data(codec
, data
);
1684 mutex_unlock(&spec
->chipio_mutex
);
1689 * Write given value to the given address through the chip I/O widget.
1690 * not protected by the Mutex
1692 static int chipio_write_no_mutex(struct hda_codec
*codec
,
1693 unsigned int chip_addx
, const unsigned int data
)
1698 /* write the address, and if successful proceed to write data */
1699 err
= chipio_write_address(codec
, chip_addx
);
1703 err
= chipio_write_data(codec
, data
);
1712 * Write multiple values to the given address through the chip I/O widget.
1713 * protected by the Mutex
1715 static int chipio_write_multiple(struct hda_codec
*codec
,
1720 struct ca0132_spec
*spec
= codec
->spec
;
1723 mutex_lock(&spec
->chipio_mutex
);
1724 status
= chipio_write_address(codec
, chip_addx
);
1728 status
= chipio_write_data_multiple(codec
, data
, count
);
1730 mutex_unlock(&spec
->chipio_mutex
);
1736 * Read the given address through the chip I/O widget
1737 * protected by the Mutex
1739 static int chipio_read(struct hda_codec
*codec
,
1740 unsigned int chip_addx
, unsigned int *data
)
1742 struct ca0132_spec
*spec
= codec
->spec
;
1745 mutex_lock(&spec
->chipio_mutex
);
1747 /* write the address, and if successful proceed to write data */
1748 err
= chipio_write_address(codec
, chip_addx
);
1752 err
= chipio_read_data(codec
, data
);
1757 mutex_unlock(&spec
->chipio_mutex
);
1762 * Set chip control flags through the chip I/O widget.
1764 static void chipio_set_control_flag(struct hda_codec
*codec
,
1765 enum control_flag_id flag_id
,
1769 unsigned int flag_bit
;
1771 flag_bit
= (flag_state
? 1 : 0);
1772 val
= (flag_bit
<< 7) | (flag_id
);
1773 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1774 VENDOR_CHIPIO_FLAG_SET
, val
);
1778 * Set chip parameters through the chip I/O widget.
1780 static void chipio_set_control_param(struct hda_codec
*codec
,
1781 enum control_param_id param_id
, int param_val
)
1783 struct ca0132_spec
*spec
= codec
->spec
;
1786 if ((param_id
< 32) && (param_val
< 8)) {
1787 val
= (param_val
<< 5) | (param_id
);
1788 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1789 VENDOR_CHIPIO_PARAM_SET
, val
);
1791 mutex_lock(&spec
->chipio_mutex
);
1792 if (chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0) == 0) {
1793 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1794 VENDOR_CHIPIO_PARAM_EX_ID_SET
,
1796 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1797 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
,
1800 mutex_unlock(&spec
->chipio_mutex
);
1805 * Set chip parameters through the chip I/O widget. NO MUTEX.
1807 static void chipio_set_control_param_no_mutex(struct hda_codec
*codec
,
1808 enum control_param_id param_id
, int param_val
)
1812 if ((param_id
< 32) && (param_val
< 8)) {
1813 val
= (param_val
<< 5) | (param_id
);
1814 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1815 VENDOR_CHIPIO_PARAM_SET
, val
);
1817 if (chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0) == 0) {
1818 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1819 VENDOR_CHIPIO_PARAM_EX_ID_SET
,
1821 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1822 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
,
1828 * Connect stream to a source point, and then connect
1829 * that source point to a destination point.
1831 static void chipio_set_stream_source_dest(struct hda_codec
*codec
,
1832 int streamid
, int source_point
, int dest_point
)
1834 chipio_set_control_param_no_mutex(codec
,
1835 CONTROL_PARAM_STREAM_ID
, streamid
);
1836 chipio_set_control_param_no_mutex(codec
,
1837 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT
, source_point
);
1838 chipio_set_control_param_no_mutex(codec
,
1839 CONTROL_PARAM_STREAM_DEST_CONN_POINT
, dest_point
);
1843 * Set number of channels in the selected stream.
1845 static void chipio_set_stream_channels(struct hda_codec
*codec
,
1846 int streamid
, unsigned int channels
)
1848 chipio_set_control_param_no_mutex(codec
,
1849 CONTROL_PARAM_STREAM_ID
, streamid
);
1850 chipio_set_control_param_no_mutex(codec
,
1851 CONTROL_PARAM_STREAMS_CHANNELS
, channels
);
1855 * Enable/Disable audio stream.
1857 static void chipio_set_stream_control(struct hda_codec
*codec
,
1858 int streamid
, int enable
)
1860 chipio_set_control_param_no_mutex(codec
,
1861 CONTROL_PARAM_STREAM_ID
, streamid
);
1862 chipio_set_control_param_no_mutex(codec
,
1863 CONTROL_PARAM_STREAM_CONTROL
, enable
);
1867 * Get ChipIO audio stream's status.
1869 static void chipio_get_stream_control(struct hda_codec
*codec
,
1870 int streamid
, unsigned int *enable
)
1872 chipio_set_control_param_no_mutex(codec
,
1873 CONTROL_PARAM_STREAM_ID
, streamid
);
1874 *enable
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
1875 VENDOR_CHIPIO_PARAM_GET
,
1876 CONTROL_PARAM_STREAM_CONTROL
);
1880 * Set sampling rate of the connection point. NO MUTEX.
1882 static void chipio_set_conn_rate_no_mutex(struct hda_codec
*codec
,
1883 int connid
, enum ca0132_sample_rate rate
)
1885 chipio_set_control_param_no_mutex(codec
,
1886 CONTROL_PARAM_CONN_POINT_ID
, connid
);
1887 chipio_set_control_param_no_mutex(codec
,
1888 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
, rate
);
1892 * Set sampling rate of the connection point.
1894 static void chipio_set_conn_rate(struct hda_codec
*codec
,
1895 int connid
, enum ca0132_sample_rate rate
)
1897 chipio_set_control_param(codec
, CONTROL_PARAM_CONN_POINT_ID
, connid
);
1898 chipio_set_control_param(codec
, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
,
1903 * Writes to the 8051's internal address space directly instead of indirectly,
1904 * giving access to the special function registers located at addresses
1907 static void chipio_8051_write_direct(struct hda_codec
*codec
,
1908 unsigned int addr
, unsigned int data
)
1912 verb
= VENDOR_CHIPIO_8051_WRITE_DIRECT
| data
;
1913 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, verb
, addr
);
1917 * Writes to the 8051's exram, which has 16-bits of address space.
1918 * Data at addresses 0x2000-0x7fff is mirrored to 0x8000-0xdfff.
1919 * Data at 0x8000-0xdfff can also be used as program memory for the 8051 by
1920 * setting the pmem bank selection SFR.
1921 * 0xe000-0xffff is always mapped as program memory, with only 0xf000-0xffff
1924 static void chipio_8051_set_address(struct hda_codec
*codec
, unsigned int addr
)
1930 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1931 VENDOR_CHIPIO_8051_ADDRESS_LOW
, tmp
);
1934 tmp
= (addr
>> 8) & 0xff;
1935 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1936 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, tmp
);
1939 static void chipio_8051_set_data(struct hda_codec
*codec
, unsigned int data
)
1941 /* 8-bits of data. */
1942 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1943 VENDOR_CHIPIO_8051_DATA_WRITE
, data
& 0xff);
1946 static unsigned int chipio_8051_get_data(struct hda_codec
*codec
)
1948 return snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
1949 VENDOR_CHIPIO_8051_DATA_READ
, 0);
1952 /* PLL_PMU writes share the lower address register of the 8051 exram writes. */
1953 static void chipio_8051_set_data_pll(struct hda_codec
*codec
, unsigned int data
)
1955 /* 8-bits of data. */
1956 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1957 VENDOR_CHIPIO_PLL_PMU_WRITE
, data
& 0xff);
1960 static void chipio_8051_write_exram(struct hda_codec
*codec
,
1961 unsigned int addr
, unsigned int data
)
1963 struct ca0132_spec
*spec
= codec
->spec
;
1965 mutex_lock(&spec
->chipio_mutex
);
1967 chipio_8051_set_address(codec
, addr
);
1968 chipio_8051_set_data(codec
, data
);
1970 mutex_unlock(&spec
->chipio_mutex
);
1973 static void chipio_8051_write_exram_no_mutex(struct hda_codec
*codec
,
1974 unsigned int addr
, unsigned int data
)
1976 chipio_8051_set_address(codec
, addr
);
1977 chipio_8051_set_data(codec
, data
);
1980 /* Readback data from the 8051's exram. No mutex. */
1981 static void chipio_8051_read_exram(struct hda_codec
*codec
,
1982 unsigned int addr
, unsigned int *data
)
1984 chipio_8051_set_address(codec
, addr
);
1985 *data
= chipio_8051_get_data(codec
);
1988 static void chipio_8051_write_pll_pmu(struct hda_codec
*codec
,
1989 unsigned int addr
, unsigned int data
)
1991 struct ca0132_spec
*spec
= codec
->spec
;
1993 mutex_lock(&spec
->chipio_mutex
);
1995 chipio_8051_set_address(codec
, addr
& 0xff);
1996 chipio_8051_set_data_pll(codec
, data
);
1998 mutex_unlock(&spec
->chipio_mutex
);
2001 static void chipio_8051_write_pll_pmu_no_mutex(struct hda_codec
*codec
,
2002 unsigned int addr
, unsigned int data
)
2004 chipio_8051_set_address(codec
, addr
& 0xff);
2005 chipio_8051_set_data_pll(codec
, data
);
2011 static void chipio_enable_clocks(struct hda_codec
*codec
)
2013 struct ca0132_spec
*spec
= codec
->spec
;
2015 mutex_lock(&spec
->chipio_mutex
);
2017 chipio_8051_write_pll_pmu_no_mutex(codec
, 0x00, 0xff);
2018 chipio_8051_write_pll_pmu_no_mutex(codec
, 0x05, 0x0b);
2019 chipio_8051_write_pll_pmu_no_mutex(codec
, 0x06, 0xff);
2021 mutex_unlock(&spec
->chipio_mutex
);
2025 * CA0132 DSP IO stuffs
2027 static int dspio_send(struct hda_codec
*codec
, unsigned int reg
,
2031 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
2033 /* send bits of data specified by reg to dsp */
2035 res
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0, reg
, data
);
2036 if ((res
>= 0) && (res
!= VENDOR_STATUS_DSPIO_BUSY
))
2039 } while (time_before(jiffies
, timeout
));
2045 * Wait for DSP to be ready for commands
2047 static void dspio_write_wait(struct hda_codec
*codec
)
2050 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
2053 status
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
2054 VENDOR_DSPIO_STATUS
, 0);
2055 if ((status
== VENDOR_STATUS_DSPIO_OK
) ||
2056 (status
== VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
))
2059 } while (time_before(jiffies
, timeout
));
2063 * Write SCP data to DSP
2065 static int dspio_write(struct hda_codec
*codec
, unsigned int scp_data
)
2067 struct ca0132_spec
*spec
= codec
->spec
;
2070 dspio_write_wait(codec
);
2072 mutex_lock(&spec
->chipio_mutex
);
2073 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_WRITE_DATA_LOW
,
2078 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH
,
2083 /* OK, now check if the write itself has executed*/
2084 status
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
2085 VENDOR_DSPIO_STATUS
, 0);
2087 mutex_unlock(&spec
->chipio_mutex
);
2089 return (status
== VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL
) ?
2094 * Write multiple SCP data to DSP
2096 static int dspio_write_multiple(struct hda_codec
*codec
,
2097 unsigned int *buffer
, unsigned int size
)
2106 while (count
< size
) {
2107 status
= dspio_write(codec
, *buffer
++);
2116 static int dspio_read(struct hda_codec
*codec
, unsigned int *data
)
2120 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_POST_READ_DATA
, 0);
2124 status
= dspio_send(codec
, VENDOR_DSPIO_STATUS
, 0);
2125 if (status
== -EIO
||
2126 status
== VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
)
2129 *data
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
2130 VENDOR_DSPIO_SCP_READ_DATA
, 0);
2135 static int dspio_read_multiple(struct hda_codec
*codec
, unsigned int *buffer
,
2136 unsigned int *buf_size
, unsigned int size_count
)
2139 unsigned int size
= *buf_size
;
2141 unsigned int skip_count
;
2148 while (count
< size
&& count
< size_count
) {
2149 status
= dspio_read(codec
, buffer
++);
2157 while (skip_count
< size
) {
2158 status
= dspio_read(codec
, &dummy
);
2170 * Construct the SCP header using corresponding fields
2172 static inline unsigned int
2173 make_scp_header(unsigned int target_id
, unsigned int source_id
,
2174 unsigned int get_flag
, unsigned int req
,
2175 unsigned int device_flag
, unsigned int resp_flag
,
2176 unsigned int error_flag
, unsigned int data_size
)
2178 unsigned int header
= 0;
2180 header
= (data_size
& 0x1f) << 27;
2181 header
|= (error_flag
& 0x01) << 26;
2182 header
|= (resp_flag
& 0x01) << 25;
2183 header
|= (device_flag
& 0x01) << 24;
2184 header
|= (req
& 0x7f) << 17;
2185 header
|= (get_flag
& 0x01) << 16;
2186 header
|= (source_id
& 0xff) << 8;
2187 header
|= target_id
& 0xff;
2193 * Extract corresponding fields from SCP header
2196 extract_scp_header(unsigned int header
,
2197 unsigned int *target_id
, unsigned int *source_id
,
2198 unsigned int *get_flag
, unsigned int *req
,
2199 unsigned int *device_flag
, unsigned int *resp_flag
,
2200 unsigned int *error_flag
, unsigned int *data_size
)
2203 *data_size
= (header
>> 27) & 0x1f;
2205 *error_flag
= (header
>> 26) & 0x01;
2207 *resp_flag
= (header
>> 25) & 0x01;
2209 *device_flag
= (header
>> 24) & 0x01;
2211 *req
= (header
>> 17) & 0x7f;
2213 *get_flag
= (header
>> 16) & 0x01;
2215 *source_id
= (header
>> 8) & 0xff;
2217 *target_id
= header
& 0xff;
2220 #define SCP_MAX_DATA_WORDS (16)
2222 /* Structure to contain any SCP message */
2225 unsigned int data
[SCP_MAX_DATA_WORDS
];
2228 static void dspio_clear_response_queue(struct hda_codec
*codec
)
2230 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
2231 unsigned int dummy
= 0;
2234 /* clear all from the response queue */
2236 status
= dspio_read(codec
, &dummy
);
2237 } while (status
== 0 && time_before(jiffies
, timeout
));
2240 static int dspio_get_response_data(struct hda_codec
*codec
)
2242 struct ca0132_spec
*spec
= codec
->spec
;
2243 unsigned int data
= 0;
2246 if (dspio_read(codec
, &data
) < 0)
2249 if ((data
& 0x00ffffff) == spec
->wait_scp_header
) {
2250 spec
->scp_resp_header
= data
;
2251 spec
->scp_resp_count
= data
>> 27;
2252 count
= spec
->wait_num_data
;
2253 dspio_read_multiple(codec
, spec
->scp_resp_data
,
2254 &spec
->scp_resp_count
, count
);
2262 * Send SCP message to DSP
2264 static int dspio_send_scp_message(struct hda_codec
*codec
,
2265 unsigned char *send_buf
,
2266 unsigned int send_buf_size
,
2267 unsigned char *return_buf
,
2268 unsigned int return_buf_size
,
2269 unsigned int *bytes_returned
)
2271 struct ca0132_spec
*spec
= codec
->spec
;
2273 unsigned int scp_send_size
= 0;
2274 unsigned int total_size
;
2275 bool waiting_for_resp
= false;
2276 unsigned int header
;
2277 struct scp_msg
*ret_msg
;
2278 unsigned int resp_src_id
, resp_target_id
;
2279 unsigned int data_size
, src_id
, target_id
, get_flag
, device_flag
;
2282 *bytes_returned
= 0;
2284 /* get scp header from buffer */
2285 header
= *((unsigned int *)send_buf
);
2286 extract_scp_header(header
, &target_id
, &src_id
, &get_flag
, NULL
,
2287 &device_flag
, NULL
, NULL
, &data_size
);
2288 scp_send_size
= data_size
+ 1;
2289 total_size
= (scp_send_size
* 4);
2291 if (send_buf_size
< total_size
)
2294 if (get_flag
|| device_flag
) {
2295 if (!return_buf
|| return_buf_size
< 4 || !bytes_returned
)
2298 spec
->wait_scp_header
= *((unsigned int *)send_buf
);
2300 /* swap source id with target id */
2301 resp_target_id
= src_id
;
2302 resp_src_id
= target_id
;
2303 spec
->wait_scp_header
&= 0xffff0000;
2304 spec
->wait_scp_header
|= (resp_src_id
<< 8) | (resp_target_id
);
2305 spec
->wait_num_data
= return_buf_size
/sizeof(unsigned int) - 1;
2307 waiting_for_resp
= true;
2310 status
= dspio_write_multiple(codec
, (unsigned int *)send_buf
,
2317 if (waiting_for_resp
) {
2318 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
2319 memset(return_buf
, 0, return_buf_size
);
2322 } while (spec
->wait_scp
&& time_before(jiffies
, timeout
));
2323 waiting_for_resp
= false;
2324 if (!spec
->wait_scp
) {
2325 ret_msg
= (struct scp_msg
*)return_buf
;
2326 memcpy(&ret_msg
->hdr
, &spec
->scp_resp_header
, 4);
2327 memcpy(&ret_msg
->data
, spec
->scp_resp_data
,
2328 spec
->wait_num_data
);
2329 *bytes_returned
= (spec
->scp_resp_count
+ 1) * 4;
2341 * Prepare and send the SCP message to DSP
2342 * @codec: the HDA codec
2343 * @mod_id: ID of the DSP module to send the command
2344 * @src_id: ID of the source
2345 * @req: ID of request to send to the DSP module
2347 * @data: pointer to the data to send with the request, request specific
2348 * @len: length of the data, in bytes
2349 * @reply: point to the buffer to hold data returned for a reply
2350 * @reply_len: length of the reply buffer returned from GET
2352 * Returns zero or a negative error code.
2354 static int dspio_scp(struct hda_codec
*codec
,
2355 int mod_id
, int src_id
, int req
, int dir
, const void *data
,
2356 unsigned int len
, void *reply
, unsigned int *reply_len
)
2359 struct scp_msg scp_send
, scp_reply
;
2360 unsigned int ret_bytes
, send_size
, ret_size
;
2361 unsigned int send_get_flag
, reply_resp_flag
, reply_error_flag
;
2362 unsigned int reply_data_size
;
2364 memset(&scp_send
, 0, sizeof(scp_send
));
2365 memset(&scp_reply
, 0, sizeof(scp_reply
));
2367 if ((len
!= 0 && data
== NULL
) || (len
> SCP_MAX_DATA_WORDS
))
2370 if (dir
== SCP_GET
&& reply
== NULL
) {
2371 codec_dbg(codec
, "dspio_scp get but has no buffer\n");
2375 if (reply
!= NULL
&& (reply_len
== NULL
|| (*reply_len
== 0))) {
2376 codec_dbg(codec
, "dspio_scp bad resp buf len parms\n");
2380 scp_send
.hdr
= make_scp_header(mod_id
, src_id
, (dir
== SCP_GET
), req
,
2381 0, 0, 0, len
/sizeof(unsigned int));
2382 if (data
!= NULL
&& len
> 0) {
2383 len
= min((unsigned int)(sizeof(scp_send
.data
)), len
);
2384 memcpy(scp_send
.data
, data
, len
);
2388 send_size
= sizeof(unsigned int) + len
;
2389 status
= dspio_send_scp_message(codec
, (unsigned char *)&scp_send
,
2390 send_size
, (unsigned char *)&scp_reply
,
2391 sizeof(scp_reply
), &ret_bytes
);
2394 codec_dbg(codec
, "dspio_scp: send scp msg failed\n");
2398 /* extract send and reply headers members */
2399 extract_scp_header(scp_send
.hdr
, NULL
, NULL
, &send_get_flag
,
2400 NULL
, NULL
, NULL
, NULL
, NULL
);
2401 extract_scp_header(scp_reply
.hdr
, NULL
, NULL
, NULL
, NULL
, NULL
,
2402 &reply_resp_flag
, &reply_error_flag
,
2408 if (reply_resp_flag
&& !reply_error_flag
) {
2409 ret_size
= (ret_bytes
- sizeof(scp_reply
.hdr
))
2410 / sizeof(unsigned int);
2412 if (*reply_len
< ret_size
*sizeof(unsigned int)) {
2413 codec_dbg(codec
, "reply too long for buf\n");
2415 } else if (ret_size
!= reply_data_size
) {
2416 codec_dbg(codec
, "RetLen and HdrLen .NE.\n");
2418 } else if (!reply
) {
2419 codec_dbg(codec
, "NULL reply\n");
2422 *reply_len
= ret_size
*sizeof(unsigned int);
2423 memcpy(reply
, scp_reply
.data
, *reply_len
);
2426 codec_dbg(codec
, "reply ill-formed or errflag set\n");
2434 * Set DSP parameters
2436 static int dspio_set_param(struct hda_codec
*codec
, int mod_id
,
2437 int src_id
, int req
, const void *data
, unsigned int len
)
2439 return dspio_scp(codec
, mod_id
, src_id
, req
, SCP_SET
, data
, len
, NULL
,
2443 static int dspio_set_uint_param(struct hda_codec
*codec
, int mod_id
,
2444 int req
, const unsigned int data
)
2446 return dspio_set_param(codec
, mod_id
, 0x20, req
, &data
,
2447 sizeof(unsigned int));
2451 * Allocate a DSP DMA channel via an SCP message
2453 static int dspio_alloc_dma_chan(struct hda_codec
*codec
, unsigned int *dma_chan
)
2456 unsigned int size
= sizeof(dma_chan
);
2458 codec_dbg(codec
, " dspio_alloc_dma_chan() -- begin\n");
2459 status
= dspio_scp(codec
, MASTERCONTROL
, 0x20,
2460 MASTERCONTROL_ALLOC_DMA_CHAN
, SCP_GET
, NULL
, 0,
2464 codec_dbg(codec
, "dspio_alloc_dma_chan: SCP Failed\n");
2468 if ((*dma_chan
+ 1) == 0) {
2469 codec_dbg(codec
, "no free dma channels to allocate\n");
2473 codec_dbg(codec
, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan
);
2474 codec_dbg(codec
, " dspio_alloc_dma_chan() -- complete\n");
2480 * Free a DSP DMA via an SCP message
2482 static int dspio_free_dma_chan(struct hda_codec
*codec
, unsigned int dma_chan
)
2485 unsigned int dummy
= 0;
2487 codec_dbg(codec
, " dspio_free_dma_chan() -- begin\n");
2488 codec_dbg(codec
, "dspio_free_dma_chan: chan=%d\n", dma_chan
);
2490 status
= dspio_scp(codec
, MASTERCONTROL
, 0x20,
2491 MASTERCONTROL_ALLOC_DMA_CHAN
, SCP_SET
, &dma_chan
,
2492 sizeof(dma_chan
), NULL
, &dummy
);
2495 codec_dbg(codec
, "dspio_free_dma_chan: SCP Failed\n");
2499 codec_dbg(codec
, " dspio_free_dma_chan() -- complete\n");
2507 static int dsp_set_run_state(struct hda_codec
*codec
)
2509 unsigned int dbg_ctrl_reg
;
2510 unsigned int halt_state
;
2513 err
= chipio_read(codec
, DSP_DBGCNTL_INST_OFFSET
, &dbg_ctrl_reg
);
2517 halt_state
= (dbg_ctrl_reg
& DSP_DBGCNTL_STATE_MASK
) >>
2518 DSP_DBGCNTL_STATE_LOBIT
;
2520 if (halt_state
!= 0) {
2521 dbg_ctrl_reg
&= ~((halt_state
<< DSP_DBGCNTL_SS_LOBIT
) &
2522 DSP_DBGCNTL_SS_MASK
);
2523 err
= chipio_write(codec
, DSP_DBGCNTL_INST_OFFSET
,
2528 dbg_ctrl_reg
|= (halt_state
<< DSP_DBGCNTL_EXEC_LOBIT
) &
2529 DSP_DBGCNTL_EXEC_MASK
;
2530 err
= chipio_write(codec
, DSP_DBGCNTL_INST_OFFSET
,
2542 static int dsp_reset(struct hda_codec
*codec
)
2547 codec_dbg(codec
, "dsp_reset\n");
2549 res
= dspio_send(codec
, VENDOR_DSPIO_DSP_INIT
, 0);
2551 } while (res
== -EIO
&& retry
);
2554 codec_dbg(codec
, "dsp_reset timeout\n");
2562 * Convert chip address to DSP address
2564 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx
,
2565 bool *code
, bool *yram
)
2567 *code
= *yram
= false;
2569 if (UC_RANGE(chip_addx
, 1)) {
2571 return UC_OFF(chip_addx
);
2572 } else if (X_RANGE_ALL(chip_addx
, 1)) {
2573 return X_OFF(chip_addx
);
2574 } else if (Y_RANGE_ALL(chip_addx
, 1)) {
2576 return Y_OFF(chip_addx
);
2579 return INVALID_CHIP_ADDRESS
;
2583 * Check if the DSP DMA is active
2585 static bool dsp_is_dma_active(struct hda_codec
*codec
, unsigned int dma_chan
)
2587 unsigned int dma_chnlstart_reg
;
2589 chipio_read(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
, &dma_chnlstart_reg
);
2591 return ((dma_chnlstart_reg
& (1 <<
2592 (DSPDMAC_CHNLSTART_EN_LOBIT
+ dma_chan
))) != 0);
2595 static int dsp_dma_setup_common(struct hda_codec
*codec
,
2596 unsigned int chip_addx
,
2597 unsigned int dma_chan
,
2598 unsigned int port_map_mask
,
2602 unsigned int chnl_prop
;
2603 unsigned int dsp_addx
;
2604 unsigned int active
;
2607 codec_dbg(codec
, "-- dsp_dma_setup_common() -- Begin ---------\n");
2609 if (dma_chan
>= DSPDMAC_DMA_CFG_CHANNEL_COUNT
) {
2610 codec_dbg(codec
, "dma chan num invalid\n");
2614 if (dsp_is_dma_active(codec
, dma_chan
)) {
2615 codec_dbg(codec
, "dma already active\n");
2619 dsp_addx
= dsp_chip_to_dsp_addx(chip_addx
, &code
, &yram
);
2621 if (dsp_addx
== INVALID_CHIP_ADDRESS
) {
2622 codec_dbg(codec
, "invalid chip addr\n");
2626 chnl_prop
= DSPDMAC_CHNLPROP_AC_MASK
;
2629 codec_dbg(codec
, " dsp_dma_setup_common() start reg pgm\n");
2632 status
= chipio_read(codec
, DSPDMAC_CHNLPROP_INST_OFFSET
,
2636 codec_dbg(codec
, "read CHNLPROP Reg fail\n");
2639 codec_dbg(codec
, "dsp_dma_setup_common() Read CHNLPROP\n");
2643 chnl_prop
&= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT
+ dma_chan
));
2645 chnl_prop
|= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT
+ dma_chan
));
2647 chnl_prop
&= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT
+ dma_chan
));
2649 status
= chipio_write(codec
, DSPDMAC_CHNLPROP_INST_OFFSET
, chnl_prop
);
2651 codec_dbg(codec
, "write CHNLPROP Reg fail\n");
2654 codec_dbg(codec
, " dsp_dma_setup_common() Write CHNLPROP\n");
2657 status
= chipio_read(codec
, DSPDMAC_ACTIVE_INST_OFFSET
,
2661 codec_dbg(codec
, "read ACTIVE Reg fail\n");
2664 codec_dbg(codec
, "dsp_dma_setup_common() Read ACTIVE\n");
2667 active
&= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT
+ dma_chan
))) &
2668 DSPDMAC_ACTIVE_AAR_MASK
;
2670 status
= chipio_write(codec
, DSPDMAC_ACTIVE_INST_OFFSET
, active
);
2672 codec_dbg(codec
, "write ACTIVE Reg fail\n");
2676 codec_dbg(codec
, " dsp_dma_setup_common() Write ACTIVE\n");
2678 status
= chipio_write(codec
, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan
),
2681 codec_dbg(codec
, "write AUDCHSEL Reg fail\n");
2684 codec_dbg(codec
, " dsp_dma_setup_common() Write AUDCHSEL\n");
2686 status
= chipio_write(codec
, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan
),
2687 DSPDMAC_IRQCNT_BICNT_MASK
| DSPDMAC_IRQCNT_CICNT_MASK
);
2689 codec_dbg(codec
, "write IRQCNT Reg fail\n");
2692 codec_dbg(codec
, " dsp_dma_setup_common() Write IRQCNT\n");
2695 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2696 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2697 chip_addx
, dsp_addx
, dma_chan
,
2698 port_map_mask
, chnl_prop
, active
);
2700 codec_dbg(codec
, "-- dsp_dma_setup_common() -- Complete ------\n");
2706 * Setup the DSP DMA per-transfer-specific registers
2708 static int dsp_dma_setup(struct hda_codec
*codec
,
2709 unsigned int chip_addx
,
2711 unsigned int dma_chan
)
2715 unsigned int dsp_addx
;
2716 unsigned int addr_field
;
2717 unsigned int incr_field
;
2718 unsigned int base_cnt
;
2719 unsigned int cur_cnt
;
2720 unsigned int dma_cfg
= 0;
2721 unsigned int adr_ofs
= 0;
2722 unsigned int xfr_cnt
= 0;
2723 const unsigned int max_dma_count
= 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT
-
2724 DSPDMAC_XFRCNT_BCNT_LOBIT
+ 1);
2726 codec_dbg(codec
, "-- dsp_dma_setup() -- Begin ---------\n");
2728 if (count
> max_dma_count
) {
2729 codec_dbg(codec
, "count too big\n");
2733 dsp_addx
= dsp_chip_to_dsp_addx(chip_addx
, &code
, &yram
);
2734 if (dsp_addx
== INVALID_CHIP_ADDRESS
) {
2735 codec_dbg(codec
, "invalid chip addr\n");
2739 codec_dbg(codec
, " dsp_dma_setup() start reg pgm\n");
2741 addr_field
= dsp_addx
<< DSPDMAC_DMACFG_DBADR_LOBIT
;
2747 addr_field
|= (1 << DSPDMAC_DMACFG_DBADR_LOBIT
);
2749 incr_field
= (1 << DSPDMAC_DMACFG_AINCR_LOBIT
);
2752 dma_cfg
= addr_field
+ incr_field
;
2753 status
= chipio_write(codec
, DSPDMAC_DMACFG_INST_OFFSET(dma_chan
),
2756 codec_dbg(codec
, "write DMACFG Reg fail\n");
2759 codec_dbg(codec
, " dsp_dma_setup() Write DMACFG\n");
2761 adr_ofs
= (count
- 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT
+
2764 status
= chipio_write(codec
, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan
),
2767 codec_dbg(codec
, "write DSPADROFS Reg fail\n");
2770 codec_dbg(codec
, " dsp_dma_setup() Write DSPADROFS\n");
2772 base_cnt
= (count
- 1) << DSPDMAC_XFRCNT_BCNT_LOBIT
;
2774 cur_cnt
= (count
- 1) << DSPDMAC_XFRCNT_CCNT_LOBIT
;
2776 xfr_cnt
= base_cnt
| cur_cnt
;
2778 status
= chipio_write(codec
,
2779 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan
), xfr_cnt
);
2781 codec_dbg(codec
, "write XFRCNT Reg fail\n");
2784 codec_dbg(codec
, " dsp_dma_setup() Write XFRCNT\n");
2787 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2788 "ADROFS=0x%x, XFRCNT=0x%x\n",
2789 chip_addx
, count
, dma_cfg
, adr_ofs
, xfr_cnt
);
2791 codec_dbg(codec
, "-- dsp_dma_setup() -- Complete ---------\n");
2799 static int dsp_dma_start(struct hda_codec
*codec
,
2800 unsigned int dma_chan
, bool ovly
)
2802 unsigned int reg
= 0;
2805 codec_dbg(codec
, "-- dsp_dma_start() -- Begin ---------\n");
2808 status
= chipio_read(codec
,
2809 DSPDMAC_CHNLSTART_INST_OFFSET
, ®
);
2812 codec_dbg(codec
, "read CHNLSTART reg fail\n");
2815 codec_dbg(codec
, "-- dsp_dma_start() Read CHNLSTART\n");
2817 reg
&= ~(DSPDMAC_CHNLSTART_EN_MASK
|
2818 DSPDMAC_CHNLSTART_DIS_MASK
);
2821 status
= chipio_write(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
,
2822 reg
| (1 << (dma_chan
+ DSPDMAC_CHNLSTART_EN_LOBIT
)));
2824 codec_dbg(codec
, "write CHNLSTART reg fail\n");
2827 codec_dbg(codec
, "-- dsp_dma_start() -- Complete ---------\n");
2835 static int dsp_dma_stop(struct hda_codec
*codec
,
2836 unsigned int dma_chan
, bool ovly
)
2838 unsigned int reg
= 0;
2841 codec_dbg(codec
, "-- dsp_dma_stop() -- Begin ---------\n");
2844 status
= chipio_read(codec
,
2845 DSPDMAC_CHNLSTART_INST_OFFSET
, ®
);
2848 codec_dbg(codec
, "read CHNLSTART reg fail\n");
2851 codec_dbg(codec
, "-- dsp_dma_stop() Read CHNLSTART\n");
2852 reg
&= ~(DSPDMAC_CHNLSTART_EN_MASK
|
2853 DSPDMAC_CHNLSTART_DIS_MASK
);
2856 status
= chipio_write(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
,
2857 reg
| (1 << (dma_chan
+ DSPDMAC_CHNLSTART_DIS_LOBIT
)));
2859 codec_dbg(codec
, "write CHNLSTART reg fail\n");
2862 codec_dbg(codec
, "-- dsp_dma_stop() -- Complete ---------\n");
2868 * Allocate router ports
2870 * @codec: the HDA codec
2871 * @num_chans: number of channels in the stream
2872 * @ports_per_channel: number of ports per channel
2873 * @start_device: start device
2874 * @port_map: pointer to the port list to hold the allocated ports
2876 * Returns zero or a negative error code.
2878 static int dsp_allocate_router_ports(struct hda_codec
*codec
,
2879 unsigned int num_chans
,
2880 unsigned int ports_per_channel
,
2881 unsigned int start_device
,
2882 unsigned int *port_map
)
2888 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2892 val
= start_device
<< 6;
2893 val
|= (ports_per_channel
- 1) << 4;
2894 val
|= num_chans
- 1;
2896 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
2897 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET
,
2900 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
2901 VENDOR_CHIPIO_PORT_ALLOC_SET
,
2904 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2908 res
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
2909 VENDOR_CHIPIO_PORT_ALLOC_GET
, 0);
2913 return (res
< 0) ? res
: 0;
2919 static int dsp_free_router_ports(struct hda_codec
*codec
)
2923 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2927 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
2928 VENDOR_CHIPIO_PORT_FREE_SET
,
2931 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2937 * Allocate DSP ports for the download stream
2939 static int dsp_allocate_ports(struct hda_codec
*codec
,
2940 unsigned int num_chans
,
2941 unsigned int rate_multi
, unsigned int *port_map
)
2945 codec_dbg(codec
, " dsp_allocate_ports() -- begin\n");
2947 if ((rate_multi
!= 1) && (rate_multi
!= 2) && (rate_multi
!= 4)) {
2948 codec_dbg(codec
, "bad rate multiple\n");
2952 status
= dsp_allocate_router_ports(codec
, num_chans
,
2953 rate_multi
, 0, port_map
);
2955 codec_dbg(codec
, " dsp_allocate_ports() -- complete\n");
2960 static int dsp_allocate_ports_format(struct hda_codec
*codec
,
2961 const unsigned short fmt
,
2962 unsigned int *port_map
)
2965 unsigned int num_chans
;
2967 unsigned int sample_rate_div
= ((get_hdafmt_rate(fmt
) >> 0) & 3) + 1;
2968 unsigned int sample_rate_mul
= ((get_hdafmt_rate(fmt
) >> 3) & 3) + 1;
2969 unsigned int rate_multi
= sample_rate_mul
/ sample_rate_div
;
2971 if ((rate_multi
!= 1) && (rate_multi
!= 2) && (rate_multi
!= 4)) {
2972 codec_dbg(codec
, "bad rate multiple\n");
2976 num_chans
= get_hdafmt_chs(fmt
) + 1;
2978 status
= dsp_allocate_ports(codec
, num_chans
, rate_multi
, port_map
);
2986 static int dsp_free_ports(struct hda_codec
*codec
)
2990 codec_dbg(codec
, " dsp_free_ports() -- begin\n");
2992 status
= dsp_free_router_ports(codec
);
2994 codec_dbg(codec
, "free router ports fail\n");
2997 codec_dbg(codec
, " dsp_free_ports() -- complete\n");
3003 * HDA DMA engine stuffs for DSP code download
3006 struct hda_codec
*codec
;
3007 unsigned short m_converter_format
;
3008 struct snd_dma_buffer
*dmab
;
3009 unsigned int buf_size
;
3018 static int dma_convert_to_hda_format(struct hda_codec
*codec
,
3019 unsigned int sample_rate
,
3020 unsigned short channels
,
3021 unsigned short *hda_format
)
3023 unsigned int format_val
;
3025 format_val
= snd_hdac_calc_stream_format(sample_rate
,
3026 channels
, SNDRV_PCM_FORMAT_S32_LE
, 32, 0);
3029 *hda_format
= (unsigned short)format_val
;
3035 * Reset DMA for DSP download
3037 static int dma_reset(struct dma_engine
*dma
)
3039 struct hda_codec
*codec
= dma
->codec
;
3040 struct ca0132_spec
*spec
= codec
->spec
;
3043 if (dma
->dmab
->area
)
3044 snd_hda_codec_load_dsp_cleanup(codec
, dma
->dmab
);
3046 status
= snd_hda_codec_load_dsp_prepare(codec
,
3047 dma
->m_converter_format
,
3052 spec
->dsp_stream_id
= status
;
3056 static int dma_set_state(struct dma_engine
*dma
, enum dma_state state
)
3061 case DMA_STATE_STOP
:
3071 snd_hda_codec_load_dsp_trigger(dma
->codec
, cmd
);
3075 static unsigned int dma_get_buffer_size(struct dma_engine
*dma
)
3077 return dma
->dmab
->bytes
;
3080 static unsigned char *dma_get_buffer_addr(struct dma_engine
*dma
)
3082 return dma
->dmab
->area
;
3085 static int dma_xfer(struct dma_engine
*dma
,
3086 const unsigned int *data
,
3089 memcpy(dma
->dmab
->area
, data
, count
);
3093 static void dma_get_converter_format(
3094 struct dma_engine
*dma
,
3095 unsigned short *format
)
3098 *format
= dma
->m_converter_format
;
3101 static unsigned int dma_get_stream_id(struct dma_engine
*dma
)
3103 struct ca0132_spec
*spec
= dma
->codec
->spec
;
3105 return spec
->dsp_stream_id
;
3108 struct dsp_image_seg
{
3115 static const u32 g_magic_value
= 0x4c46584d;
3116 static const u32 g_chip_addr_magic_value
= 0xFFFFFF01;
3118 static bool is_valid(const struct dsp_image_seg
*p
)
3120 return p
->magic
== g_magic_value
;
3123 static bool is_hci_prog_list_seg(const struct dsp_image_seg
*p
)
3125 return g_chip_addr_magic_value
== p
->chip_addr
;
3128 static bool is_last(const struct dsp_image_seg
*p
)
3130 return p
->count
== 0;
3133 static size_t dsp_sizeof(const struct dsp_image_seg
*p
)
3135 return struct_size(p
, data
, p
->count
);
3138 static const struct dsp_image_seg
*get_next_seg_ptr(
3139 const struct dsp_image_seg
*p
)
3141 return (struct dsp_image_seg
*)((unsigned char *)(p
) + dsp_sizeof(p
));
3145 * CA0132 chip DSP transfer stuffs. For DSP download.
3147 #define INVALID_DMA_CHANNEL (~0U)
3150 * Program a list of address/data pairs via the ChipIO widget.
3151 * The segment data is in the format of successive pairs of words.
3152 * These are repeated as indicated by the segment's count field.
3154 static int dspxfr_hci_write(struct hda_codec
*codec
,
3155 const struct dsp_image_seg
*fls
)
3161 if (fls
== NULL
|| fls
->chip_addr
!= g_chip_addr_magic_value
) {
3162 codec_dbg(codec
, "hci_write invalid params\n");
3167 data
= (u32
*)(fls
->data
);
3168 while (count
>= 2) {
3169 status
= chipio_write(codec
, data
[0], data
[1]);
3171 codec_dbg(codec
, "hci_write chipio failed\n");
3181 * Write a block of data into DSP code or data RAM using pre-allocated
3184 * @codec: the HDA codec
3185 * @fls: pointer to a fast load image
3186 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3188 * @dma_engine: pointer to DMA engine to be used for DSP download
3189 * @dma_chan: The number of DMA channels used for DSP download
3190 * @port_map_mask: port mapping
3191 * @ovly: TRUE if overlay format is required
3193 * Returns zero or a negative error code.
3195 static int dspxfr_one_seg(struct hda_codec
*codec
,
3196 const struct dsp_image_seg
*fls
,
3198 struct dma_engine
*dma_engine
,
3199 unsigned int dma_chan
,
3200 unsigned int port_map_mask
,
3204 bool comm_dma_setup_done
= false;
3205 const unsigned int *data
;
3206 unsigned int chip_addx
;
3207 unsigned int words_to_write
;
3208 unsigned int buffer_size_words
;
3209 unsigned char *buffer_addx
;
3210 unsigned short hda_format
;
3211 unsigned int sample_rate_div
;
3212 unsigned int sample_rate_mul
;
3213 unsigned int num_chans
;
3214 unsigned int hda_frame_size_words
;
3215 unsigned int remainder_words
;
3216 const u32
*data_remainder
;
3217 u32 chip_addx_remainder
;
3218 unsigned int run_size_words
;
3219 const struct dsp_image_seg
*hci_write
= NULL
;
3220 unsigned long timeout
;
3225 if (is_hci_prog_list_seg(fls
)) {
3227 fls
= get_next_seg_ptr(fls
);
3230 if (hci_write
&& (!fls
|| is_last(fls
))) {
3231 codec_dbg(codec
, "hci_write\n");
3232 return dspxfr_hci_write(codec
, hci_write
);
3235 if (fls
== NULL
|| dma_engine
== NULL
|| port_map_mask
== 0) {
3236 codec_dbg(codec
, "Invalid Params\n");
3241 chip_addx
= fls
->chip_addr
;
3242 words_to_write
= fls
->count
;
3244 if (!words_to_write
)
3245 return hci_write
? dspxfr_hci_write(codec
, hci_write
) : 0;
3247 chip_addx
= (chip_addx
& (0xFFFF0000 << 2)) + (reloc
<< 2);
3249 if (!UC_RANGE(chip_addx
, words_to_write
) &&
3250 !X_RANGE_ALL(chip_addx
, words_to_write
) &&
3251 !Y_RANGE_ALL(chip_addx
, words_to_write
)) {
3252 codec_dbg(codec
, "Invalid chip_addx Params\n");
3256 buffer_size_words
= (unsigned int)dma_get_buffer_size(dma_engine
) /
3259 buffer_addx
= dma_get_buffer_addr(dma_engine
);
3261 if (buffer_addx
== NULL
) {
3262 codec_dbg(codec
, "dma_engine buffer NULL\n");
3266 dma_get_converter_format(dma_engine
, &hda_format
);
3267 sample_rate_div
= ((get_hdafmt_rate(hda_format
) >> 0) & 3) + 1;
3268 sample_rate_mul
= ((get_hdafmt_rate(hda_format
) >> 3) & 3) + 1;
3269 num_chans
= get_hdafmt_chs(hda_format
) + 1;
3271 hda_frame_size_words
= ((sample_rate_div
== 0) ? 0 :
3272 (num_chans
* sample_rate_mul
/ sample_rate_div
));
3274 if (hda_frame_size_words
== 0) {
3275 codec_dbg(codec
, "frmsz zero\n");
3279 buffer_size_words
= min(buffer_size_words
,
3280 (unsigned int)(UC_RANGE(chip_addx
, 1) ?
3282 buffer_size_words
-= buffer_size_words
% hda_frame_size_words
;
3284 "chpadr=0x%08x frmsz=%u nchan=%u "
3285 "rate_mul=%u div=%u bufsz=%u\n",
3286 chip_addx
, hda_frame_size_words
, num_chans
,
3287 sample_rate_mul
, sample_rate_div
, buffer_size_words
);
3289 if (buffer_size_words
< hda_frame_size_words
) {
3290 codec_dbg(codec
, "dspxfr_one_seg:failed\n");
3294 remainder_words
= words_to_write
% hda_frame_size_words
;
3295 data_remainder
= data
;
3296 chip_addx_remainder
= chip_addx
;
3298 data
+= remainder_words
;
3299 chip_addx
+= remainder_words
*sizeof(u32
);
3300 words_to_write
-= remainder_words
;
3302 while (words_to_write
!= 0) {
3303 run_size_words
= min(buffer_size_words
, words_to_write
);
3304 codec_dbg(codec
, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
3305 words_to_write
, run_size_words
, remainder_words
);
3306 dma_xfer(dma_engine
, data
, run_size_words
*sizeof(u32
));
3307 if (!comm_dma_setup_done
) {
3308 status
= dsp_dma_stop(codec
, dma_chan
, ovly
);
3311 status
= dsp_dma_setup_common(codec
, chip_addx
,
3312 dma_chan
, port_map_mask
, ovly
);
3315 comm_dma_setup_done
= true;
3318 status
= dsp_dma_setup(codec
, chip_addx
,
3319 run_size_words
, dma_chan
);
3322 status
= dsp_dma_start(codec
, dma_chan
, ovly
);
3325 if (!dsp_is_dma_active(codec
, dma_chan
)) {
3326 codec_dbg(codec
, "dspxfr:DMA did not start\n");
3329 status
= dma_set_state(dma_engine
, DMA_STATE_RUN
);
3332 if (remainder_words
!= 0) {
3333 status
= chipio_write_multiple(codec
,
3334 chip_addx_remainder
,
3339 remainder_words
= 0;
3342 status
= dspxfr_hci_write(codec
, hci_write
);
3348 timeout
= jiffies
+ msecs_to_jiffies(2000);
3350 dma_active
= dsp_is_dma_active(codec
, dma_chan
);
3354 } while (time_before(jiffies
, timeout
));
3358 codec_dbg(codec
, "+++++ DMA complete\n");
3359 dma_set_state(dma_engine
, DMA_STATE_STOP
);
3360 status
= dma_reset(dma_engine
);
3365 data
+= run_size_words
;
3366 chip_addx
+= run_size_words
*sizeof(u32
);
3367 words_to_write
-= run_size_words
;
3370 if (remainder_words
!= 0) {
3371 status
= chipio_write_multiple(codec
, chip_addx_remainder
,
3372 data_remainder
, remainder_words
);
3379 * Write the entire DSP image of a DSP code/data overlay to DSP memories
3381 * @codec: the HDA codec
3382 * @fls_data: pointer to a fast load image
3383 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3385 * @sample_rate: sampling rate of the stream used for DSP download
3386 * @channels: channels of the stream used for DSP download
3387 * @ovly: TRUE if overlay format is required
3389 * Returns zero or a negative error code.
3391 static int dspxfr_image(struct hda_codec
*codec
,
3392 const struct dsp_image_seg
*fls_data
,
3394 unsigned int sample_rate
,
3395 unsigned short channels
,
3398 struct ca0132_spec
*spec
= codec
->spec
;
3400 unsigned short hda_format
= 0;
3401 unsigned int response
;
3402 unsigned char stream_id
= 0;
3403 struct dma_engine
*dma_engine
;
3404 unsigned int dma_chan
;
3405 unsigned int port_map_mask
;
3407 if (fls_data
== NULL
)
3410 dma_engine
= kzalloc(sizeof(*dma_engine
), GFP_KERNEL
);
3414 dma_engine
->dmab
= kzalloc(sizeof(*dma_engine
->dmab
), GFP_KERNEL
);
3415 if (!dma_engine
->dmab
) {
3420 dma_engine
->codec
= codec
;
3421 dma_convert_to_hda_format(codec
, sample_rate
, channels
, &hda_format
);
3422 dma_engine
->m_converter_format
= hda_format
;
3423 dma_engine
->buf_size
= (ovly
? DSP_DMA_WRITE_BUFLEN_OVLY
:
3424 DSP_DMA_WRITE_BUFLEN_INIT
) * 2;
3426 dma_chan
= ovly
? INVALID_DMA_CHANNEL
: 0;
3428 status
= codec_set_converter_format(codec
, WIDGET_CHIP_CTRL
,
3429 hda_format
, &response
);
3432 codec_dbg(codec
, "set converter format fail\n");
3436 status
= snd_hda_codec_load_dsp_prepare(codec
,
3437 dma_engine
->m_converter_format
,
3438 dma_engine
->buf_size
,
3442 spec
->dsp_stream_id
= status
;
3445 status
= dspio_alloc_dma_chan(codec
, &dma_chan
);
3447 codec_dbg(codec
, "alloc dmachan fail\n");
3448 dma_chan
= INVALID_DMA_CHANNEL
;
3454 status
= dsp_allocate_ports_format(codec
, hda_format
,
3457 codec_dbg(codec
, "alloc ports fail\n");
3461 stream_id
= dma_get_stream_id(dma_engine
);
3462 status
= codec_set_converter_stream_channel(codec
,
3463 WIDGET_CHIP_CTRL
, stream_id
, 0, &response
);
3465 codec_dbg(codec
, "set stream chan fail\n");
3469 while ((fls_data
!= NULL
) && !is_last(fls_data
)) {
3470 if (!is_valid(fls_data
)) {
3471 codec_dbg(codec
, "FLS check fail\n");
3475 status
= dspxfr_one_seg(codec
, fls_data
, reloc
,
3476 dma_engine
, dma_chan
,
3477 port_map_mask
, ovly
);
3481 if (is_hci_prog_list_seg(fls_data
))
3482 fls_data
= get_next_seg_ptr(fls_data
);
3484 if ((fls_data
!= NULL
) && !is_last(fls_data
))
3485 fls_data
= get_next_seg_ptr(fls_data
);
3488 if (port_map_mask
!= 0)
3489 status
= dsp_free_ports(codec
);
3494 status
= codec_set_converter_stream_channel(codec
,
3495 WIDGET_CHIP_CTRL
, 0, 0, &response
);
3498 if (ovly
&& (dma_chan
!= INVALID_DMA_CHANNEL
))
3499 dspio_free_dma_chan(codec
, dma_chan
);
3501 if (dma_engine
->dmab
->area
)
3502 snd_hda_codec_load_dsp_cleanup(codec
, dma_engine
->dmab
);
3503 kfree(dma_engine
->dmab
);
3510 * CA0132 DSP download stuffs.
3512 static void dspload_post_setup(struct hda_codec
*codec
)
3514 struct ca0132_spec
*spec
= codec
->spec
;
3515 codec_dbg(codec
, "---- dspload_post_setup ------\n");
3516 if (!ca0132_use_alt_functions(spec
)) {
3517 /*set DSP speaker to 2.0 configuration*/
3518 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3519 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3521 /*update write pointer*/
3522 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3527 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3529 * @codec: the HDA codec
3530 * @fls: pointer to a fast load image
3531 * @ovly: TRUE if overlay format is required
3532 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3534 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3535 * @router_chans: number of audio router channels to be allocated (0 means use
3536 * internal defaults; max is 32)
3538 * Download DSP from a DSP Image Fast Load structure. This structure is a
3539 * linear, non-constant sized element array of structures, each of which
3540 * contain the count of the data to be loaded, the data itself, and the
3541 * corresponding starting chip address of the starting data location.
3542 * Returns zero or a negative error code.
3544 static int dspload_image(struct hda_codec
*codec
,
3545 const struct dsp_image_seg
*fls
,
3552 unsigned int sample_rate
;
3553 unsigned short channels
;
3555 codec_dbg(codec
, "---- dspload_image begin ------\n");
3556 if (router_chans
== 0) {
3558 router_chans
= DMA_TRANSFER_FRAME_SIZE_NWORDS
;
3560 router_chans
= DMA_OVERLAY_FRAME_SIZE_NWORDS
;
3563 sample_rate
= 48000;
3564 channels
= (unsigned short)router_chans
;
3566 while (channels
> 16) {
3572 codec_dbg(codec
, "Ready to program DMA\n");
3574 status
= dsp_reset(codec
);
3579 codec_dbg(codec
, "dsp_reset() complete\n");
3580 status
= dspxfr_image(codec
, fls
, reloc
, sample_rate
, channels
,
3586 codec_dbg(codec
, "dspxfr_image() complete\n");
3587 if (autostart
&& !ovly
) {
3588 dspload_post_setup(codec
);
3589 status
= dsp_set_run_state(codec
);
3592 codec_dbg(codec
, "LOAD FINISHED\n");
3598 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3599 static bool dspload_is_loaded(struct hda_codec
*codec
)
3601 unsigned int data
= 0;
3604 status
= chipio_read(codec
, 0x40004, &data
);
3605 if ((status
< 0) || (data
!= 1))
3611 #define dspload_is_loaded(codec) false
3614 static bool dspload_wait_loaded(struct hda_codec
*codec
)
3616 unsigned long timeout
= jiffies
+ msecs_to_jiffies(2000);
3619 if (dspload_is_loaded(codec
)) {
3620 codec_info(codec
, "ca0132 DSP downloaded and running\n");
3624 } while (time_before(jiffies
, timeout
));
3626 codec_err(codec
, "ca0132 failed to download DSP\n");
3631 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3632 * based cards, and has a second mmio region, region2, that's used for special
3637 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3638 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3639 * The first eight bits are just the number of the pin. So far, I've only seen
3640 * this number go to 7.
3641 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3642 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3643 * then off to send that bit.
3645 static void ca0113_mmio_gpio_set(struct hda_codec
*codec
, unsigned int gpio_pin
,
3648 struct ca0132_spec
*spec
= codec
->spec
;
3649 unsigned short gpio_data
;
3651 gpio_data
= gpio_pin
& 0xF;
3652 gpio_data
|= ((enable
<< 8) & 0x100);
3654 writew(gpio_data
, spec
->mem_base
+ 0x320);
3658 * Special pci region2 commands that are only used by the AE-5. They follow
3659 * a set format, and require reads at certain points to seemingly 'clear'
3660 * the response data. My first tests didn't do these reads, and would cause
3661 * the card to get locked up until the memory was read. These commands
3662 * seem to work with three distinct values that I've taken to calling group,
3663 * target-id, and value.
3665 static void ca0113_mmio_command_set(struct hda_codec
*codec
, unsigned int group
,
3666 unsigned int target
, unsigned int value
)
3668 struct ca0132_spec
*spec
= codec
->spec
;
3669 unsigned int write_val
;
3671 writel(0x0000007e, spec
->mem_base
+ 0x210);
3672 readl(spec
->mem_base
+ 0x210);
3673 writel(0x0000005a, spec
->mem_base
+ 0x210);
3674 readl(spec
->mem_base
+ 0x210);
3675 readl(spec
->mem_base
+ 0x210);
3677 writel(0x00800005, spec
->mem_base
+ 0x20c);
3678 writel(group
, spec
->mem_base
+ 0x804);
3680 writel(0x00800005, spec
->mem_base
+ 0x20c);
3681 write_val
= (target
& 0xff);
3682 write_val
|= (value
<< 8);
3685 writel(write_val
, spec
->mem_base
+ 0x204);
3687 * Need delay here or else it goes too fast and works inconsistently.
3691 readl(spec
->mem_base
+ 0x860);
3692 readl(spec
->mem_base
+ 0x854);
3693 readl(spec
->mem_base
+ 0x840);
3695 writel(0x00800004, spec
->mem_base
+ 0x20c);
3696 writel(0x00000000, spec
->mem_base
+ 0x210);
3697 readl(spec
->mem_base
+ 0x210);
3698 readl(spec
->mem_base
+ 0x210);
3702 * This second type of command is used for setting the sound filter type.
3704 static void ca0113_mmio_command_set_type2(struct hda_codec
*codec
,
3705 unsigned int group
, unsigned int target
, unsigned int value
)
3707 struct ca0132_spec
*spec
= codec
->spec
;
3708 unsigned int write_val
;
3710 writel(0x0000007e, spec
->mem_base
+ 0x210);
3711 readl(spec
->mem_base
+ 0x210);
3712 writel(0x0000005a, spec
->mem_base
+ 0x210);
3713 readl(spec
->mem_base
+ 0x210);
3714 readl(spec
->mem_base
+ 0x210);
3716 writel(0x00800003, spec
->mem_base
+ 0x20c);
3717 writel(group
, spec
->mem_base
+ 0x804);
3719 writel(0x00800005, spec
->mem_base
+ 0x20c);
3720 write_val
= (target
& 0xff);
3721 write_val
|= (value
<< 8);
3724 writel(write_val
, spec
->mem_base
+ 0x204);
3726 readl(spec
->mem_base
+ 0x860);
3727 readl(spec
->mem_base
+ 0x854);
3728 readl(spec
->mem_base
+ 0x840);
3730 writel(0x00800004, spec
->mem_base
+ 0x20c);
3731 writel(0x00000000, spec
->mem_base
+ 0x210);
3732 readl(spec
->mem_base
+ 0x210);
3733 readl(spec
->mem_base
+ 0x210);
3737 * Setup GPIO for the other variants of Core3D.
3741 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3742 * the card shows as having no GPIO pins.
3744 static void ca0132_gpio_init(struct hda_codec
*codec
)
3746 struct ca0132_spec
*spec
= codec
->spec
;
3748 switch (ca0132_quirk(spec
)) {
3752 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
3753 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x53);
3754 snd_hda_codec_write(codec
, 0x01, 0, 0x790, 0x23);
3757 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
3758 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x5B);
3766 /* Sets the GPIO for audio output. */
3767 static void ca0132_gpio_setup(struct hda_codec
*codec
)
3769 struct ca0132_spec
*spec
= codec
->spec
;
3771 switch (ca0132_quirk(spec
)) {
3773 snd_hda_codec_write(codec
, 0x01, 0,
3774 AC_VERB_SET_GPIO_DIRECTION
, 0x07);
3775 snd_hda_codec_write(codec
, 0x01, 0,
3776 AC_VERB_SET_GPIO_MASK
, 0x07);
3777 snd_hda_codec_write(codec
, 0x01, 0,
3778 AC_VERB_SET_GPIO_DATA
, 0x04);
3779 snd_hda_codec_write(codec
, 0x01, 0,
3780 AC_VERB_SET_GPIO_DATA
, 0x06);
3783 snd_hda_codec_write(codec
, 0x01, 0,
3784 AC_VERB_SET_GPIO_DIRECTION
, 0x1E);
3785 snd_hda_codec_write(codec
, 0x01, 0,
3786 AC_VERB_SET_GPIO_MASK
, 0x1F);
3787 snd_hda_codec_write(codec
, 0x01, 0,
3788 AC_VERB_SET_GPIO_DATA
, 0x0C);
3796 * GPIO control functions for the Recon3D integrated.
3799 enum r3di_gpio_bit
{
3800 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3801 R3DI_MIC_SELECT_BIT
= 1,
3802 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3803 R3DI_OUT_SELECT_BIT
= 2,
3805 * I dunno what this actually does, but it stays on until the dsp
3808 R3DI_GPIO_DSP_DOWNLOADING
= 3,
3810 * Same as above, no clue what it does, but it comes on after the dsp
3813 R3DI_GPIO_DSP_DOWNLOADED
= 4
3816 enum r3di_mic_select
{
3817 /* Set GPIO bit 1 to 0 for rear mic */
3819 /* Set GPIO bit 1 to 1 for front microphone*/
3823 enum r3di_out_select
{
3824 /* Set GPIO bit 2 to 0 for headphone */
3825 R3DI_HEADPHONE_OUT
= 0,
3826 /* Set GPIO bit 2 to 1 for speaker */
3829 enum r3di_dsp_status
{
3830 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3831 R3DI_DSP_DOWNLOADING
= 0,
3832 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3833 R3DI_DSP_DOWNLOADED
= 1
3837 static void r3di_gpio_mic_set(struct hda_codec
*codec
,
3838 enum r3di_mic_select cur_mic
)
3840 unsigned int cur_gpio
;
3842 /* Get the current GPIO Data setup */
3843 cur_gpio
= snd_hda_codec_read(codec
, 0x01, 0, AC_VERB_GET_GPIO_DATA
, 0);
3847 cur_gpio
&= ~(1 << R3DI_MIC_SELECT_BIT
);
3849 case R3DI_FRONT_MIC
:
3850 cur_gpio
|= (1 << R3DI_MIC_SELECT_BIT
);
3853 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3854 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3857 static void r3di_gpio_dsp_status_set(struct hda_codec
*codec
,
3858 enum r3di_dsp_status dsp_status
)
3860 unsigned int cur_gpio
;
3862 /* Get the current GPIO Data setup */
3863 cur_gpio
= snd_hda_codec_read(codec
, 0x01, 0, AC_VERB_GET_GPIO_DATA
, 0);
3865 switch (dsp_status
) {
3866 case R3DI_DSP_DOWNLOADING
:
3867 cur_gpio
|= (1 << R3DI_GPIO_DSP_DOWNLOADING
);
3868 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3869 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3871 case R3DI_DSP_DOWNLOADED
:
3872 /* Set DOWNLOADING bit to 0. */
3873 cur_gpio
&= ~(1 << R3DI_GPIO_DSP_DOWNLOADING
);
3875 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3876 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3878 cur_gpio
|= (1 << R3DI_GPIO_DSP_DOWNLOADED
);
3882 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3883 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3889 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
3890 struct hda_codec
*codec
,
3891 unsigned int stream_tag
,
3892 unsigned int format
,
3893 struct snd_pcm_substream
*substream
)
3895 struct ca0132_spec
*spec
= codec
->spec
;
3897 snd_hda_codec_setup_stream(codec
, spec
->dacs
[0], stream_tag
, 0, format
);
3902 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
3903 struct hda_codec
*codec
,
3904 struct snd_pcm_substream
*substream
)
3906 struct ca0132_spec
*spec
= codec
->spec
;
3908 if (spec
->dsp_state
== DSP_DOWNLOADING
)
3911 /*If Playback effects are on, allow stream some time to flush
3913 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
3916 snd_hda_codec_cleanup_stream(codec
, spec
->dacs
[0]);
3921 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream
*info
,
3922 struct hda_codec
*codec
,
3923 struct snd_pcm_substream
*substream
)
3925 struct ca0132_spec
*spec
= codec
->spec
;
3926 unsigned int latency
= DSP_PLAYBACK_INIT_LATENCY
;
3927 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3929 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
3932 /* Add latency if playback enhancement and either effect is enabled. */
3933 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
]) {
3934 if ((spec
->effects_switch
[SURROUND
- EFFECT_START_NID
]) ||
3935 (spec
->effects_switch
[DIALOG_PLUS
- EFFECT_START_NID
]))
3936 latency
+= DSP_PLAY_ENHANCEMENT_LATENCY
;
3939 /* Applying Speaker EQ adds latency as well. */
3940 if (spec
->cur_out_type
== SPEAKER_OUT
)
3941 latency
+= DSP_SPEAKER_OUT_LATENCY
;
3943 return (latency
* runtime
->rate
) / 1000;
3949 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
3950 struct hda_codec
*codec
,
3951 struct snd_pcm_substream
*substream
)
3953 struct ca0132_spec
*spec
= codec
->spec
;
3954 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
3957 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
3958 struct hda_codec
*codec
,
3959 unsigned int stream_tag
,
3960 unsigned int format
,
3961 struct snd_pcm_substream
*substream
)
3963 struct ca0132_spec
*spec
= codec
->spec
;
3964 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
3965 stream_tag
, format
, substream
);
3968 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
3969 struct hda_codec
*codec
,
3970 struct snd_pcm_substream
*substream
)
3972 struct ca0132_spec
*spec
= codec
->spec
;
3973 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
3976 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
3977 struct hda_codec
*codec
,
3978 struct snd_pcm_substream
*substream
)
3980 struct ca0132_spec
*spec
= codec
->spec
;
3981 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
3987 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
3988 struct hda_codec
*codec
,
3989 unsigned int stream_tag
,
3990 unsigned int format
,
3991 struct snd_pcm_substream
*substream
)
3993 snd_hda_codec_setup_stream(codec
, hinfo
->nid
,
3994 stream_tag
, 0, format
);
3999 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
4000 struct hda_codec
*codec
,
4001 struct snd_pcm_substream
*substream
)
4003 struct ca0132_spec
*spec
= codec
->spec
;
4005 if (spec
->dsp_state
== DSP_DOWNLOADING
)
4008 snd_hda_codec_cleanup_stream(codec
, hinfo
->nid
);
4012 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream
*info
,
4013 struct hda_codec
*codec
,
4014 struct snd_pcm_substream
*substream
)
4016 struct ca0132_spec
*spec
= codec
->spec
;
4017 unsigned int latency
= DSP_CAPTURE_INIT_LATENCY
;
4018 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
4020 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
4023 if (spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
])
4024 latency
+= DSP_CRYSTAL_VOICE_LATENCY
;
4026 return (latency
* runtime
->rate
) / 1000;
4034 * Mixer controls helpers.
4036 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
4037 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4039 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4040 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
4041 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
4042 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
4043 .info = ca0132_volume_info, \
4044 .get = ca0132_volume_get, \
4045 .put = ca0132_volume_put, \
4046 .tlv = { .c = ca0132_volume_tlv }, \
4047 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4050 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
4051 * volume put, which is used for setting the DSP volume. This was done because
4052 * the ca0132 functions were taking too much time and causing lag.
4054 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
4055 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4057 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4058 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
4059 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
4060 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
4061 .info = snd_hda_mixer_amp_volume_info, \
4062 .get = snd_hda_mixer_amp_volume_get, \
4063 .put = ca0132_alt_volume_put, \
4064 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
4065 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4067 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
4068 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4070 .subdevice = HDA_SUBDEV_AMP_FLAG, \
4071 .info = snd_hda_mixer_amp_switch_info, \
4072 .get = ca0132_switch_get, \
4073 .put = ca0132_switch_put, \
4074 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
4077 #define CA0132_CODEC_VOL(xname, nid, dir) \
4078 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
4079 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
4080 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
4081 #define CA0132_CODEC_MUTE(xname, nid, dir) \
4082 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
4086 * Lookup table with decibel values for the DSP. When volume is changed in
4087 * Windows, the DSP is also sent the dB value in floating point. In Windows,
4088 * these values have decimal points, probably because the Windows driver
4089 * actually uses floating point. We can't here, so I made a lookup table of
4090 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
4091 * DAC's, and 9 is the maximum.
4093 static const unsigned int float_vol_db_lookup
[] = {
4094 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
4095 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
4096 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
4097 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
4098 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
4099 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
4100 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
4101 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
4102 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
4103 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
4104 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
4105 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
4106 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
4107 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
4108 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
4109 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
4110 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
4114 * This table counts from float 0 to 1 in increments of .01, which is
4115 * useful for a few different sliders.
4117 static const unsigned int float_zero_to_one_lookup
[] = {
4118 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
4119 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
4120 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
4121 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
4122 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
4123 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4124 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4125 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4126 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4127 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4128 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4129 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4130 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4131 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4132 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4133 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4134 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4138 * This table counts from float 10 to 1000, which is the range of the x-bass
4139 * crossover slider in Windows.
4141 static const unsigned int float_xbass_xover_lookup
[] = {
4142 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
4143 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
4144 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
4145 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
4146 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
4147 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
4148 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
4149 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
4150 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
4151 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
4152 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
4153 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
4154 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
4155 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
4156 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
4157 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
4158 0x44728000, 0x44750000, 0x44778000, 0x447A0000
4161 /* The following are for tuning of products */
4162 #ifdef ENABLE_TUNING_CONTROLS
4164 static const unsigned int voice_focus_vals_lookup
[] = {
4165 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
4166 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
4167 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
4168 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
4169 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
4170 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
4171 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
4172 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
4173 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
4174 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
4175 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
4176 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
4177 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
4178 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
4179 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
4180 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
4181 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
4182 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
4183 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
4184 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
4185 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
4186 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
4187 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
4188 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
4189 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
4190 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
4191 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
4194 static const unsigned int mic_svm_vals_lookup
[] = {
4195 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
4196 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
4197 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
4198 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
4199 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
4200 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
4201 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
4202 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
4203 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
4204 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
4205 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
4206 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
4207 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
4208 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
4209 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
4210 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
4211 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
4214 static const unsigned int equalizer_vals_lookup
[] = {
4215 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
4216 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
4217 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
4218 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
4219 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
4220 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
4221 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
4222 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
4226 static int tuning_ctl_set(struct hda_codec
*codec
, hda_nid_t nid
,
4227 const unsigned int *lookup
, int idx
)
4231 for (i
= 0; i
< TUNING_CTLS_COUNT
; i
++)
4232 if (nid
== ca0132_tuning_ctls
[i
].nid
)
4235 snd_hda_power_up(codec
);
4236 dspio_set_param(codec
, ca0132_tuning_ctls
[i
].mid
, 0x20,
4237 ca0132_tuning_ctls
[i
].req
,
4238 &(lookup
[idx
]), sizeof(unsigned int));
4239 snd_hda_power_down(codec
);
4244 static int tuning_ctl_get(struct snd_kcontrol
*kcontrol
,
4245 struct snd_ctl_elem_value
*ucontrol
)
4247 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4248 struct ca0132_spec
*spec
= codec
->spec
;
4249 hda_nid_t nid
= get_amp_nid(kcontrol
);
4250 long *valp
= ucontrol
->value
.integer
.value
;
4251 int idx
= nid
- TUNING_CTL_START_NID
;
4253 *valp
= spec
->cur_ctl_vals
[idx
];
4257 static int voice_focus_ctl_info(struct snd_kcontrol
*kcontrol
,
4258 struct snd_ctl_elem_info
*uinfo
)
4260 int chs
= get_amp_channels(kcontrol
);
4261 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
4262 uinfo
->count
= chs
== 3 ? 2 : 1;
4263 uinfo
->value
.integer
.min
= 20;
4264 uinfo
->value
.integer
.max
= 180;
4265 uinfo
->value
.integer
.step
= 1;
4270 static int voice_focus_ctl_put(struct snd_kcontrol
*kcontrol
,
4271 struct snd_ctl_elem_value
*ucontrol
)
4273 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4274 struct ca0132_spec
*spec
= codec
->spec
;
4275 hda_nid_t nid
= get_amp_nid(kcontrol
);
4276 long *valp
= ucontrol
->value
.integer
.value
;
4279 idx
= nid
- TUNING_CTL_START_NID
;
4281 if (spec
->cur_ctl_vals
[idx
] == *valp
)
4284 spec
->cur_ctl_vals
[idx
] = *valp
;
4287 tuning_ctl_set(codec
, nid
, voice_focus_vals_lookup
, idx
);
4292 static int mic_svm_ctl_info(struct snd_kcontrol
*kcontrol
,
4293 struct snd_ctl_elem_info
*uinfo
)
4295 int chs
= get_amp_channels(kcontrol
);
4296 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
4297 uinfo
->count
= chs
== 3 ? 2 : 1;
4298 uinfo
->value
.integer
.min
= 0;
4299 uinfo
->value
.integer
.max
= 100;
4300 uinfo
->value
.integer
.step
= 1;
4305 static int mic_svm_ctl_put(struct snd_kcontrol
*kcontrol
,
4306 struct snd_ctl_elem_value
*ucontrol
)
4308 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4309 struct ca0132_spec
*spec
= codec
->spec
;
4310 hda_nid_t nid
= get_amp_nid(kcontrol
);
4311 long *valp
= ucontrol
->value
.integer
.value
;
4314 idx
= nid
- TUNING_CTL_START_NID
;
4316 if (spec
->cur_ctl_vals
[idx
] == *valp
)
4319 spec
->cur_ctl_vals
[idx
] = *valp
;
4322 tuning_ctl_set(codec
, nid
, mic_svm_vals_lookup
, idx
);
4327 static int equalizer_ctl_info(struct snd_kcontrol
*kcontrol
,
4328 struct snd_ctl_elem_info
*uinfo
)
4330 int chs
= get_amp_channels(kcontrol
);
4331 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
4332 uinfo
->count
= chs
== 3 ? 2 : 1;
4333 uinfo
->value
.integer
.min
= 0;
4334 uinfo
->value
.integer
.max
= 48;
4335 uinfo
->value
.integer
.step
= 1;
4340 static int equalizer_ctl_put(struct snd_kcontrol
*kcontrol
,
4341 struct snd_ctl_elem_value
*ucontrol
)
4343 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4344 struct ca0132_spec
*spec
= codec
->spec
;
4345 hda_nid_t nid
= get_amp_nid(kcontrol
);
4346 long *valp
= ucontrol
->value
.integer
.value
;
4349 idx
= nid
- TUNING_CTL_START_NID
;
4351 if (spec
->cur_ctl_vals
[idx
] == *valp
)
4354 spec
->cur_ctl_vals
[idx
] = *valp
;
4357 tuning_ctl_set(codec
, nid
, equalizer_vals_lookup
, idx
);
4362 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale
, 2000, 100, 0);
4363 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale
, -2400, 100, 0);
4365 static int add_tuning_control(struct hda_codec
*codec
,
4366 hda_nid_t pnid
, hda_nid_t nid
,
4367 const char *name
, int dir
)
4369 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
4370 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
4371 struct snd_kcontrol_new knew
=
4372 HDA_CODEC_VOLUME_MONO(namestr
, nid
, 1, 0, type
);
4374 knew
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
4375 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
4380 knew
.info
= voice_focus_ctl_info
;
4381 knew
.get
= tuning_ctl_get
;
4382 knew
.put
= voice_focus_ctl_put
;
4383 knew
.tlv
.p
= voice_focus_db_scale
;
4386 knew
.info
= mic_svm_ctl_info
;
4387 knew
.get
= tuning_ctl_get
;
4388 knew
.put
= mic_svm_ctl_put
;
4391 knew
.info
= equalizer_ctl_info
;
4392 knew
.get
= tuning_ctl_get
;
4393 knew
.put
= equalizer_ctl_put
;
4394 knew
.tlv
.p
= eq_db_scale
;
4399 knew
.private_value
=
4400 HDA_COMPOSE_AMP_VAL(nid
, 1, 0, type
);
4401 sprintf(namestr
, "%s %s Volume", name
, dirstr
[dir
]);
4402 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
4405 static int add_tuning_ctls(struct hda_codec
*codec
)
4410 for (i
= 0; i
< TUNING_CTLS_COUNT
; i
++) {
4411 err
= add_tuning_control(codec
,
4412 ca0132_tuning_ctls
[i
].parent_nid
,
4413 ca0132_tuning_ctls
[i
].nid
,
4414 ca0132_tuning_ctls
[i
].name
,
4415 ca0132_tuning_ctls
[i
].direct
);
4423 static void ca0132_init_tuning_defaults(struct hda_codec
*codec
)
4425 struct ca0132_spec
*spec
= codec
->spec
;
4428 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
4429 spec
->cur_ctl_vals
[WEDGE_ANGLE
- TUNING_CTL_START_NID
] = 10;
4430 /* SVM level defaults to 0.74. */
4431 spec
->cur_ctl_vals
[SVM_LEVEL
- TUNING_CTL_START_NID
] = 74;
4433 /* EQ defaults to 0dB. */
4434 for (i
= 2; i
< TUNING_CTLS_COUNT
; i
++)
4435 spec
->cur_ctl_vals
[i
] = 24;
4437 #endif /*ENABLE_TUNING_CONTROLS*/
4440 * Select the active output.
4441 * If autodetect is enabled, output will be selected based on jack detection.
4442 * If jack inserted, headphone will be selected, else built-in speakers
4443 * If autodetect is disabled, output will be selected based on selection.
4445 static int ca0132_select_out(struct hda_codec
*codec
)
4447 struct ca0132_spec
*spec
= codec
->spec
;
4448 unsigned int pin_ctl
;
4454 codec_dbg(codec
, "ca0132_select_out\n");
4456 snd_hda_power_up_pm(codec
);
4458 auto_jack
= spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
4461 jack_present
= snd_hda_jack_detect(codec
, spec
->unsol_tag_hp
);
4464 spec
->vnode_lswitch
[VNID_HP_SEL
- VNODE_START_NID
];
4467 spec
->cur_out_type
= HEADPHONE_OUT
;
4469 spec
->cur_out_type
= SPEAKER_OUT
;
4471 if (spec
->cur_out_type
== SPEAKER_OUT
) {
4472 codec_dbg(codec
, "ca0132_select_out speaker\n");
4473 /*speaker out config*/
4475 err
= dspio_set_uint_param(codec
, 0x80, 0x04, tmp
);
4478 /*enable speaker EQ*/
4480 err
= dspio_set_uint_param(codec
, 0x8f, 0x00, tmp
);
4485 snd_hda_codec_write(codec
, spec
->out_pins
[1], 0,
4486 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x02);
4487 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4488 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
4489 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4490 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x00);
4491 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4492 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
4494 /* disable headphone node */
4495 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
4496 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4497 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
4499 /* enable speaker node */
4500 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
4501 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4502 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
4505 codec_dbg(codec
, "ca0132_select_out hp\n");
4506 /*headphone out config*/
4508 err
= dspio_set_uint_param(codec
, 0x80, 0x04, tmp
);
4511 /*disable speaker EQ*/
4513 err
= dspio_set_uint_param(codec
, 0x8f, 0x00, tmp
);
4518 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4519 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x00);
4520 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4521 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
4522 snd_hda_codec_write(codec
, spec
->out_pins
[1], 0,
4523 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x02);
4524 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4525 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
4527 /* disable speaker*/
4528 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
4529 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4530 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
4532 /* enable headphone*/
4533 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
4534 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4535 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
4540 snd_hda_power_down_pm(codec
);
4542 return err
< 0 ? err
: 0;
4545 static int ae5_headphone_gain_set(struct hda_codec
*codec
, long val
);
4546 static int zxr_headphone_gain_set(struct hda_codec
*codec
, long val
);
4547 static int ca0132_effects_set(struct hda_codec
*codec
, hda_nid_t nid
, long val
);
4549 static void ae5_mmio_select_out(struct hda_codec
*codec
)
4551 struct ca0132_spec
*spec
= codec
->spec
;
4552 const struct ae_ca0113_output_set
*out_cmds
;
4555 if (ca0132_quirk(spec
) == QUIRK_AE5
)
4556 out_cmds
= &ae5_ca0113_output_presets
;
4558 out_cmds
= &ae7_ca0113_output_presets
;
4560 for (i
= 0; i
< AE_CA0113_OUT_SET_COMMANDS
; i
++)
4561 ca0113_mmio_command_set(codec
, out_cmds
->group
[i
],
4562 out_cmds
->target
[i
],
4563 out_cmds
->vals
[spec
->cur_out_type
][i
]);
4566 static int ca0132_alt_set_full_range_speaker(struct hda_codec
*codec
)
4568 struct ca0132_spec
*spec
= codec
->spec
;
4569 int quirk
= ca0132_quirk(spec
);
4573 /* 2.0/4.0 setup has no LFE channel, so setting full-range does nothing. */
4574 if (spec
->channel_cfg_val
== SPEAKER_CHANNELS_4_0
4575 || spec
->channel_cfg_val
== SPEAKER_CHANNELS_2_0
)
4578 /* Set front L/R full range. Zero for full-range, one for redirection. */
4579 tmp
= spec
->speaker_range_val
[0] ? FLOAT_ZERO
: FLOAT_ONE
;
4580 err
= dspio_set_uint_param(codec
, 0x96,
4581 SPEAKER_FULL_RANGE_FRONT_L_R
, tmp
);
4585 /* When setting full-range rear, both rear and center/lfe are set. */
4586 tmp
= spec
->speaker_range_val
[1] ? FLOAT_ZERO
: FLOAT_ONE
;
4587 err
= dspio_set_uint_param(codec
, 0x96,
4588 SPEAKER_FULL_RANGE_CENTER_LFE
, tmp
);
4592 err
= dspio_set_uint_param(codec
, 0x96,
4593 SPEAKER_FULL_RANGE_REAR_L_R
, tmp
);
4598 * Only the AE series cards set this value when setting full-range,
4599 * and it's always 1.0f.
4601 if (quirk
== QUIRK_AE5
|| quirk
== QUIRK_AE7
) {
4602 err
= dspio_set_uint_param(codec
, 0x96,
4603 SPEAKER_FULL_RANGE_SURROUND_L_R
, FLOAT_ONE
);
4611 static int ca0132_alt_surround_set_bass_redirection(struct hda_codec
*codec
,
4614 struct ca0132_spec
*spec
= codec
->spec
;
4618 if (val
&& spec
->channel_cfg_val
!= SPEAKER_CHANNELS_4_0
&&
4619 spec
->channel_cfg_val
!= SPEAKER_CHANNELS_2_0
)
4624 err
= dspio_set_uint_param(codec
, 0x96, SPEAKER_BASS_REDIRECT
, tmp
);
4628 /* If it is enabled, make sure to set the crossover frequency. */
4630 tmp
= float_xbass_xover_lookup
[spec
->xbass_xover_freq
];
4631 err
= dspio_set_uint_param(codec
, 0x96,
4632 SPEAKER_BASS_REDIRECT_XOVER_FREQ
, tmp
);
4641 * These are the commands needed to setup output on each of the different card
4644 static void ca0132_alt_select_out_get_quirk_data(struct hda_codec
*codec
,
4645 const struct ca0132_alt_out_set_quirk_data
**quirk_data
)
4647 struct ca0132_spec
*spec
= codec
->spec
;
4648 int quirk
= ca0132_quirk(spec
);
4652 for (i
= 0; i
< ARRAY_SIZE(quirk_out_set_data
); i
++) {
4653 if (quirk_out_set_data
[i
].quirk_id
== quirk
) {
4654 *quirk_data
= &quirk_out_set_data
[i
];
4660 static int ca0132_alt_select_out_quirk_set(struct hda_codec
*codec
)
4662 const struct ca0132_alt_out_set_quirk_data
*quirk_data
;
4663 const struct ca0132_alt_out_set_info
*out_info
;
4664 struct ca0132_spec
*spec
= codec
->spec
;
4665 unsigned int i
, gpio_data
;
4668 ca0132_alt_select_out_get_quirk_data(codec
, &quirk_data
);
4672 out_info
= &quirk_data
->out_set_info
[spec
->cur_out_type
];
4673 if (quirk_data
->is_ae_series
)
4674 ae5_mmio_select_out(codec
);
4676 if (out_info
->has_hda_gpio
) {
4677 gpio_data
= snd_hda_codec_read(codec
, codec
->core
.afg
, 0,
4678 AC_VERB_GET_GPIO_DATA
, 0);
4680 if (out_info
->hda_gpio_set
)
4681 gpio_data
|= (1 << out_info
->hda_gpio_pin
);
4683 gpio_data
&= ~(1 << out_info
->hda_gpio_pin
);
4685 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
4686 AC_VERB_SET_GPIO_DATA
, gpio_data
);
4689 if (out_info
->mmio_gpio_count
) {
4690 for (i
= 0; i
< out_info
->mmio_gpio_count
; i
++) {
4691 ca0113_mmio_gpio_set(codec
, out_info
->mmio_gpio_pin
[i
],
4692 out_info
->mmio_gpio_set
[i
]);
4696 if (out_info
->scp_cmds_count
) {
4697 for (i
= 0; i
< out_info
->scp_cmds_count
; i
++) {
4698 err
= dspio_set_uint_param(codec
,
4699 out_info
->scp_cmd_mid
[i
],
4700 out_info
->scp_cmd_req
[i
],
4701 out_info
->scp_cmd_val
[i
]);
4707 chipio_set_control_param(codec
, 0x0d, out_info
->dac2port
);
4709 if (out_info
->has_chipio_write
) {
4710 chipio_write(codec
, out_info
->chipio_write_addr
,
4711 out_info
->chipio_write_data
);
4714 if (quirk_data
->has_headphone_gain
) {
4715 if (spec
->cur_out_type
!= HEADPHONE_OUT
) {
4716 if (quirk_data
->is_ae_series
)
4717 ae5_headphone_gain_set(codec
, 2);
4719 zxr_headphone_gain_set(codec
, 0);
4721 if (quirk_data
->is_ae_series
)
4722 ae5_headphone_gain_set(codec
,
4723 spec
->ae5_headphone_gain_val
);
4725 zxr_headphone_gain_set(codec
,
4726 spec
->zxr_gain_set
);
4733 static void ca0132_set_out_node_pincfg(struct hda_codec
*codec
, hda_nid_t nid
,
4734 bool out_enable
, bool hp_enable
)
4736 unsigned int pin_ctl
;
4738 pin_ctl
= snd_hda_codec_read(codec
, nid
, 0,
4739 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4741 pin_ctl
= hp_enable
? pin_ctl
| PIN_HP_AMP
: pin_ctl
& ~PIN_HP_AMP
;
4742 pin_ctl
= out_enable
? pin_ctl
| PIN_OUT
: pin_ctl
& ~PIN_OUT
;
4743 snd_hda_set_pin_ctl(codec
, nid
, pin_ctl
);
4747 * This function behaves similarly to the ca0132_select_out funciton above,
4748 * except with a few differences. It adds the ability to select the current
4749 * output with an enumerated control "output source" if the auto detect
4750 * mute switch is set to off. If the auto detect mute switch is enabled, it
4751 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
4752 * It also adds the ability to auto-detect the front headphone port.
4754 static int ca0132_alt_select_out(struct hda_codec
*codec
)
4756 struct ca0132_spec
*spec
= codec
->spec
;
4757 unsigned int tmp
, outfx_set
;
4761 /* Default Headphone is rear headphone */
4762 hda_nid_t headphone_nid
= spec
->out_pins
[1];
4764 codec_dbg(codec
, "%s\n", __func__
);
4766 snd_hda_power_up_pm(codec
);
4768 auto_jack
= spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
4771 * If headphone rear or front is plugged in, set to headphone.
4772 * If neither is plugged in, set to rear line out. Only if
4773 * hp/speaker auto detect is enabled.
4776 jack_present
= snd_hda_jack_detect(codec
, spec
->unsol_tag_hp
) ||
4777 snd_hda_jack_detect(codec
, spec
->unsol_tag_front_hp
);
4780 spec
->cur_out_type
= HEADPHONE_OUT
;
4782 spec
->cur_out_type
= SPEAKER_OUT
;
4784 spec
->cur_out_type
= spec
->out_enum_val
;
4786 outfx_set
= spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
];
4788 /* Begin DSP output switch, mute DSP volume. */
4789 err
= dspio_set_uint_param(codec
, 0x96, SPEAKER_TUNING_MUTE
, FLOAT_ONE
);
4793 if (ca0132_alt_select_out_quirk_set(codec
) < 0)
4796 switch (spec
->cur_out_type
) {
4798 codec_dbg(codec
, "%s speaker\n", __func__
);
4801 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4802 AC_VERB_SET_EAPD_BTLENABLE
, 0x01);
4804 /* Disable headphone node. */
4805 ca0132_set_out_node_pincfg(codec
, spec
->out_pins
[1], 0, 0);
4806 /* Set front L-R to output. */
4807 ca0132_set_out_node_pincfg(codec
, spec
->out_pins
[0], 1, 0);
4808 /* Set Center/LFE to output. */
4809 ca0132_set_out_node_pincfg(codec
, spec
->out_pins
[2], 1, 0);
4810 /* Set rear surround to output. */
4811 ca0132_set_out_node_pincfg(codec
, spec
->out_pins
[3], 1, 0);
4814 * Without PlayEnhancement being enabled, if we've got a 2.0
4815 * setup, set it to floating point eight to disable any DSP
4816 * processing effects.
4818 if (!outfx_set
&& spec
->channel_cfg_val
== SPEAKER_CHANNELS_2_0
)
4821 tmp
= speaker_channel_cfgs
[spec
->channel_cfg_val
].val
;
4823 err
= dspio_set_uint_param(codec
, 0x80, 0x04, tmp
);
4829 codec_dbg(codec
, "%s hp\n", __func__
);
4830 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4831 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
4833 /* Disable all speaker nodes. */
4834 ca0132_set_out_node_pincfg(codec
, spec
->out_pins
[0], 0, 0);
4835 ca0132_set_out_node_pincfg(codec
, spec
->out_pins
[2], 0, 0);
4836 ca0132_set_out_node_pincfg(codec
, spec
->out_pins
[3], 0, 0);
4838 /* enable headphone, either front or rear */
4839 if (snd_hda_jack_detect(codec
, spec
->unsol_tag_front_hp
))
4840 headphone_nid
= spec
->out_pins
[2];
4841 else if (snd_hda_jack_detect(codec
, spec
->unsol_tag_hp
))
4842 headphone_nid
= spec
->out_pins
[1];
4844 ca0132_set_out_node_pincfg(codec
, headphone_nid
, 1, 1);
4847 err
= dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_ONE
);
4849 err
= dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_ZERO
);
4856 * If output effects are enabled, set the X-Bass effect value again to
4857 * make sure that it's properly enabled/disabled for speaker
4858 * configurations with an LFE channel.
4861 ca0132_effects_set(codec
, X_BASS
,
4862 spec
->effects_switch
[X_BASS
- EFFECT_START_NID
]);
4864 /* Set speaker EQ bypass attenuation to 0. */
4865 err
= dspio_set_uint_param(codec
, 0x8f, 0x01, FLOAT_ZERO
);
4870 * Although unused on all cards but the AE series, this is always set
4871 * to zero when setting the output.
4873 err
= dspio_set_uint_param(codec
, 0x96,
4874 SPEAKER_TUNING_USE_SPEAKER_EQ
, FLOAT_ZERO
);
4878 if (spec
->cur_out_type
== SPEAKER_OUT
)
4879 err
= ca0132_alt_surround_set_bass_redirection(codec
,
4880 spec
->bass_redirection_val
);
4882 err
= ca0132_alt_surround_set_bass_redirection(codec
, 0);
4884 /* Unmute DSP now that we're done with output selection. */
4885 err
= dspio_set_uint_param(codec
, 0x96,
4886 SPEAKER_TUNING_MUTE
, FLOAT_ZERO
);
4890 if (spec
->cur_out_type
== SPEAKER_OUT
) {
4891 err
= ca0132_alt_set_full_range_speaker(codec
);
4897 snd_hda_power_down_pm(codec
);
4899 return err
< 0 ? err
: 0;
4902 static void ca0132_unsol_hp_delayed(struct work_struct
*work
)
4904 struct ca0132_spec
*spec
= container_of(
4905 to_delayed_work(work
), struct ca0132_spec
, unsol_hp_work
);
4906 struct hda_jack_tbl
*jack
;
4908 if (ca0132_use_alt_functions(spec
))
4909 ca0132_alt_select_out(spec
->codec
);
4911 ca0132_select_out(spec
->codec
);
4913 jack
= snd_hda_jack_tbl_get(spec
->codec
, spec
->unsol_tag_hp
);
4915 jack
->block_report
= 0;
4916 snd_hda_jack_report_sync(spec
->codec
);
4920 static void ca0132_set_dmic(struct hda_codec
*codec
, int enable
);
4921 static int ca0132_mic_boost_set(struct hda_codec
*codec
, long val
);
4922 static void resume_mic1(struct hda_codec
*codec
, unsigned int oldval
);
4923 static int stop_mic1(struct hda_codec
*codec
);
4924 static int ca0132_cvoice_switch_set(struct hda_codec
*codec
);
4925 static int ca0132_alt_mic_boost_set(struct hda_codec
*codec
, long val
);
4928 * Select the active VIP source
4930 static int ca0132_set_vipsource(struct hda_codec
*codec
, int val
)
4932 struct ca0132_spec
*spec
= codec
->spec
;
4935 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
4938 /* if CrystalVoice if off, vipsource should be 0 */
4939 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ||
4941 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, 0);
4942 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4943 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4944 if (spec
->cur_mic_type
== DIGITAL_MIC
)
4948 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4950 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4952 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_16_000
);
4953 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_16_000
);
4954 if (spec
->cur_mic_type
== DIGITAL_MIC
)
4958 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4960 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4962 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, val
);
4968 static int ca0132_alt_set_vipsource(struct hda_codec
*codec
, int val
)
4970 struct ca0132_spec
*spec
= codec
->spec
;
4973 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
4976 codec_dbg(codec
, "%s\n", __func__
);
4978 chipio_set_stream_control(codec
, 0x03, 0);
4979 chipio_set_stream_control(codec
, 0x04, 0);
4981 /* if CrystalVoice is off, vipsource should be 0 */
4982 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ||
4983 (val
== 0) || spec
->in_enum_val
== REAR_LINE_IN
) {
4984 codec_dbg(codec
, "%s: off.", __func__
);
4985 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, 0);
4988 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4990 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4991 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4992 if (ca0132_quirk(spec
) == QUIRK_R3DI
)
4993 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
4996 if (spec
->in_enum_val
== REAR_LINE_IN
)
4999 if (ca0132_quirk(spec
) == QUIRK_SBZ
)
5005 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
5008 codec_dbg(codec
, "%s: on.", __func__
);
5009 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_16_000
);
5010 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_16_000
);
5011 if (ca0132_quirk(spec
) == QUIRK_R3DI
)
5012 chipio_set_conn_rate(codec
, 0x0F, SR_16_000
);
5014 if (spec
->effects_switch
[VOICE_FOCUS
- EFFECT_START_NID
])
5018 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
5021 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
5024 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, val
);
5027 chipio_set_stream_control(codec
, 0x03, 1);
5028 chipio_set_stream_control(codec
, 0x04, 1);
5034 * Select the active microphone.
5035 * If autodetect is enabled, mic will be selected based on jack detection.
5036 * If jack inserted, ext.mic will be selected, else built-in mic
5037 * If autodetect is disabled, mic will be selected based on selection.
5039 static int ca0132_select_mic(struct hda_codec
*codec
)
5041 struct ca0132_spec
*spec
= codec
->spec
;
5045 codec_dbg(codec
, "ca0132_select_mic\n");
5047 snd_hda_power_up_pm(codec
);
5049 auto_jack
= spec
->vnode_lswitch
[VNID_AMIC1_ASEL
- VNODE_START_NID
];
5052 jack_present
= snd_hda_jack_detect(codec
, spec
->unsol_tag_amic1
);
5055 spec
->vnode_lswitch
[VNID_AMIC1_SEL
- VNODE_START_NID
];
5058 spec
->cur_mic_type
= LINE_MIC_IN
;
5060 spec
->cur_mic_type
= DIGITAL_MIC
;
5062 if (spec
->cur_mic_type
== DIGITAL_MIC
) {
5063 /* enable digital Mic */
5064 chipio_set_conn_rate(codec
, MEM_CONNID_DMIC
, SR_32_000
);
5065 ca0132_set_dmic(codec
, 1);
5066 ca0132_mic_boost_set(codec
, 0);
5067 /* set voice focus */
5068 ca0132_effects_set(codec
, VOICE_FOCUS
,
5069 spec
->effects_switch
5070 [VOICE_FOCUS
- EFFECT_START_NID
]);
5072 /* disable digital Mic */
5073 chipio_set_conn_rate(codec
, MEM_CONNID_DMIC
, SR_96_000
);
5074 ca0132_set_dmic(codec
, 0);
5075 ca0132_mic_boost_set(codec
, spec
->cur_mic_boost
);
5076 /* disable voice focus */
5077 ca0132_effects_set(codec
, VOICE_FOCUS
, 0);
5080 snd_hda_power_down_pm(codec
);
5086 * Select the active input.
5087 * Mic detection isn't used, because it's kind of pointless on the SBZ.
5088 * The front mic has no jack-detection, so the only way to switch to it
5089 * is to do it manually in alsamixer.
5091 static int ca0132_alt_select_in(struct hda_codec
*codec
)
5093 struct ca0132_spec
*spec
= codec
->spec
;
5096 codec_dbg(codec
, "%s\n", __func__
);
5098 snd_hda_power_up_pm(codec
);
5100 chipio_set_stream_control(codec
, 0x03, 0);
5101 chipio_set_stream_control(codec
, 0x04, 0);
5103 spec
->cur_mic_type
= spec
->in_enum_val
;
5105 switch (spec
->cur_mic_type
) {
5107 switch (ca0132_quirk(spec
)) {
5110 ca0113_mmio_gpio_set(codec
, 0, false);
5117 r3di_gpio_mic_set(codec
, R3DI_REAR_MIC
);
5121 ca0113_mmio_command_set(codec
, 0x30, 0x28, 0x00);
5125 ca0113_mmio_command_set(codec
, 0x30, 0x28, 0x00);
5127 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN2
,
5129 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT2
,
5131 dspio_set_uint_param(codec
, 0x80, 0x01, FLOAT_ZERO
);
5138 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
5139 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
5140 if (ca0132_quirk(spec
) == QUIRK_R3DI
)
5141 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
5143 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
5145 chipio_set_stream_control(codec
, 0x03, 1);
5146 chipio_set_stream_control(codec
, 0x04, 1);
5147 switch (ca0132_quirk(spec
)) {
5149 chipio_write(codec
, 0x18B098, 0x0000000C);
5150 chipio_write(codec
, 0x18B09C, 0x0000000C);
5153 chipio_write(codec
, 0x18B098, 0x0000000C);
5154 chipio_write(codec
, 0x18B09C, 0x000000CC);
5157 chipio_write(codec
, 0x18B098, 0x0000000C);
5158 chipio_write(codec
, 0x18B09C, 0x0000004C);
5163 ca0132_alt_mic_boost_set(codec
, spec
->mic_boost_enum_val
);
5166 ca0132_mic_boost_set(codec
, 0);
5167 switch (ca0132_quirk(spec
)) {
5170 ca0113_mmio_gpio_set(codec
, 0, false);
5173 r3di_gpio_mic_set(codec
, R3DI_REAR_MIC
);
5176 ca0113_mmio_command_set(codec
, 0x30, 0x28, 0x00);
5179 ca0113_mmio_command_set(codec
, 0x30, 0x28, 0x3f);
5180 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN2
,
5182 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT2
,
5184 dspio_set_uint_param(codec
, 0x80, 0x01, FLOAT_ZERO
);
5190 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
5191 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
5192 if (ca0132_quirk(spec
) == QUIRK_R3DI
)
5193 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
5195 if (ca0132_quirk(spec
) == QUIRK_AE7
)
5199 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
5201 switch (ca0132_quirk(spec
)) {
5204 chipio_write(codec
, 0x18B098, 0x00000000);
5205 chipio_write(codec
, 0x18B09C, 0x00000000);
5210 chipio_set_stream_control(codec
, 0x03, 1);
5211 chipio_set_stream_control(codec
, 0x04, 1);
5214 switch (ca0132_quirk(spec
)) {
5217 ca0113_mmio_gpio_set(codec
, 0, true);
5218 ca0113_mmio_gpio_set(codec
, 5, false);
5222 r3di_gpio_mic_set(codec
, R3DI_FRONT_MIC
);
5226 ca0113_mmio_command_set(codec
, 0x30, 0x28, 0x3f);
5234 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
5235 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
5236 if (ca0132_quirk(spec
) == QUIRK_R3DI
)
5237 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
5239 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
5241 chipio_set_stream_control(codec
, 0x03, 1);
5242 chipio_set_stream_control(codec
, 0x04, 1);
5244 switch (ca0132_quirk(spec
)) {
5246 chipio_write(codec
, 0x18B098, 0x0000000C);
5247 chipio_write(codec
, 0x18B09C, 0x000000CC);
5250 chipio_write(codec
, 0x18B098, 0x0000000C);
5251 chipio_write(codec
, 0x18B09C, 0x0000004C);
5256 ca0132_alt_mic_boost_set(codec
, spec
->mic_boost_enum_val
);
5259 ca0132_cvoice_switch_set(codec
);
5261 snd_hda_power_down_pm(codec
);
5266 * Check if VNODE settings take effect immediately.
5268 static bool ca0132_is_vnode_effective(struct hda_codec
*codec
,
5270 hda_nid_t
*shared_nid
)
5272 struct ca0132_spec
*spec
= codec
->spec
;
5277 nid
= spec
->shared_out_nid
;
5280 nid
= spec
->shared_mic_nid
;
5293 * The following functions are control change helpers.
5294 * They return 0 if no changed. Return 1 if changed.
5296 static int ca0132_voicefx_set(struct hda_codec
*codec
, int enable
)
5298 struct ca0132_spec
*spec
= codec
->spec
;
5301 /* based on CrystalVoice state to enable VoiceFX. */
5303 tmp
= spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ?
5304 FLOAT_ONE
: FLOAT_ZERO
;
5309 dspio_set_uint_param(codec
, ca0132_voicefx
.mid
,
5310 ca0132_voicefx
.reqs
[0], tmp
);
5316 * Set the effects parameters
5318 static int ca0132_effects_set(struct hda_codec
*codec
, hda_nid_t nid
, long val
)
5320 struct ca0132_spec
*spec
= codec
->spec
;
5321 unsigned int on
, tmp
, channel_cfg
;
5322 int num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
5324 int idx
= nid
- EFFECT_START_NID
;
5326 if ((idx
< 0) || (idx
>= num_fx
))
5327 return 0; /* no changed */
5329 /* for out effect, qualify with PE */
5330 if ((nid
>= OUT_EFFECT_START_NID
) && (nid
< OUT_EFFECT_END_NID
)) {
5331 /* if PE if off, turn off out effects. */
5332 if (!spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
5334 if (spec
->cur_out_type
== SPEAKER_OUT
&& nid
== X_BASS
) {
5335 channel_cfg
= spec
->channel_cfg_val
;
5336 if (channel_cfg
!= SPEAKER_CHANNELS_2_0
&&
5337 channel_cfg
!= SPEAKER_CHANNELS_4_0
)
5342 /* for in effect, qualify with CrystalVoice */
5343 if ((nid
>= IN_EFFECT_START_NID
) && (nid
< IN_EFFECT_END_NID
)) {
5344 /* if CrystalVoice if off, turn off in effects. */
5345 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
])
5348 /* Voice Focus applies to 2-ch Mic, Digital Mic */
5349 if ((nid
== VOICE_FOCUS
) && (spec
->cur_mic_type
!= DIGITAL_MIC
))
5352 /* If Voice Focus on SBZ, set to two channel. */
5353 if ((nid
== VOICE_FOCUS
) && ca0132_use_pci_mmio(spec
)
5354 && (spec
->cur_mic_type
!= REAR_LINE_IN
)) {
5355 if (spec
->effects_switch
[CRYSTAL_VOICE
-
5356 EFFECT_START_NID
]) {
5358 if (spec
->effects_switch
[VOICE_FOCUS
-
5359 EFFECT_START_NID
]) {
5365 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
5369 * For SBZ noise reduction, there's an extra command
5370 * to module ID 0x47. No clue why.
5372 if ((nid
== NOISE_REDUCTION
) && ca0132_use_pci_mmio(spec
)
5373 && (spec
->cur_mic_type
!= REAR_LINE_IN
)) {
5374 if (spec
->effects_switch
[CRYSTAL_VOICE
-
5375 EFFECT_START_NID
]) {
5376 if (spec
->effects_switch
[NOISE_REDUCTION
-
5384 dspio_set_uint_param(codec
, 0x47, 0x00, tmp
);
5387 /* If rear line in disable effects. */
5388 if (ca0132_use_alt_functions(spec
) &&
5389 spec
->in_enum_val
== REAR_LINE_IN
)
5393 codec_dbg(codec
, "ca0132_effect_set: nid=0x%x, val=%ld\n",
5396 on
= (val
== 0) ? FLOAT_ZERO
: FLOAT_ONE
;
5397 err
= dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
5398 ca0132_effects
[idx
].reqs
[0], on
);
5401 return 0; /* no changed */
5407 * Turn on/off Playback Enhancements
5409 static int ca0132_pe_switch_set(struct hda_codec
*codec
)
5411 struct ca0132_spec
*spec
= codec
->spec
;
5415 codec_dbg(codec
, "ca0132_pe_switch_set: val=%ld\n",
5416 spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
]);
5418 if (ca0132_use_alt_functions(spec
))
5419 ca0132_alt_select_out(codec
);
5421 i
= OUT_EFFECT_START_NID
- EFFECT_START_NID
;
5422 nid
= OUT_EFFECT_START_NID
;
5423 /* PE affects all out effects */
5424 for (; nid
< OUT_EFFECT_END_NID
; nid
++, i
++)
5425 ret
|= ca0132_effects_set(codec
, nid
, spec
->effects_switch
[i
]);
5430 /* Check if Mic1 is streaming, if so, stop streaming */
5431 static int stop_mic1(struct hda_codec
*codec
)
5433 struct ca0132_spec
*spec
= codec
->spec
;
5434 unsigned int oldval
= snd_hda_codec_read(codec
, spec
->adcs
[0], 0,
5435 AC_VERB_GET_CONV
, 0);
5437 snd_hda_codec_write(codec
, spec
->adcs
[0], 0,
5438 AC_VERB_SET_CHANNEL_STREAMID
,
5443 /* Resume Mic1 streaming if it was stopped. */
5444 static void resume_mic1(struct hda_codec
*codec
, unsigned int oldval
)
5446 struct ca0132_spec
*spec
= codec
->spec
;
5447 /* Restore the previous stream and channel */
5449 snd_hda_codec_write(codec
, spec
->adcs
[0], 0,
5450 AC_VERB_SET_CHANNEL_STREAMID
,
5455 * Turn on/off CrystalVoice
5457 static int ca0132_cvoice_switch_set(struct hda_codec
*codec
)
5459 struct ca0132_spec
*spec
= codec
->spec
;
5462 unsigned int oldval
;
5464 codec_dbg(codec
, "ca0132_cvoice_switch_set: val=%ld\n",
5465 spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
]);
5467 i
= IN_EFFECT_START_NID
- EFFECT_START_NID
;
5468 nid
= IN_EFFECT_START_NID
;
5469 /* CrystalVoice affects all in effects */
5470 for (; nid
< IN_EFFECT_END_NID
; nid
++, i
++)
5471 ret
|= ca0132_effects_set(codec
, nid
, spec
->effects_switch
[i
]);
5473 /* including VoiceFX */
5474 ret
|= ca0132_voicefx_set(codec
, (spec
->voicefx_val
? 1 : 0));
5476 /* set correct vipsource */
5477 oldval
= stop_mic1(codec
);
5478 if (ca0132_use_alt_functions(spec
))
5479 ret
|= ca0132_alt_set_vipsource(codec
, 1);
5481 ret
|= ca0132_set_vipsource(codec
, 1);
5482 resume_mic1(codec
, oldval
);
5486 static int ca0132_mic_boost_set(struct hda_codec
*codec
, long val
)
5488 struct ca0132_spec
*spec
= codec
->spec
;
5492 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
5493 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, 3);
5495 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
5496 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, 0);
5501 static int ca0132_alt_mic_boost_set(struct hda_codec
*codec
, long val
)
5503 struct ca0132_spec
*spec
= codec
->spec
;
5506 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
5507 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, val
);
5511 static int ae5_headphone_gain_set(struct hda_codec
*codec
, long val
)
5515 for (i
= 0; i
< 4; i
++)
5516 ca0113_mmio_command_set(codec
, 0x48, 0x11 + i
,
5517 ae5_headphone_gain_presets
[val
].vals
[i
]);
5522 * gpio pin 1 is a relay that switches on/off, apparently setting the headphone
5523 * amplifier to handle a 600 ohm load.
5525 static int zxr_headphone_gain_set(struct hda_codec
*codec
, long val
)
5527 ca0113_mmio_gpio_set(codec
, 1, val
);
5532 static int ca0132_vnode_switch_set(struct snd_kcontrol
*kcontrol
,
5533 struct snd_ctl_elem_value
*ucontrol
)
5535 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5536 hda_nid_t nid
= get_amp_nid(kcontrol
);
5537 hda_nid_t shared_nid
= 0;
5540 struct ca0132_spec
*spec
= codec
->spec
;
5543 if (nid
== VNID_HP_SEL
) {
5545 spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
5547 if (ca0132_use_alt_functions(spec
))
5548 ca0132_alt_select_out(codec
);
5550 ca0132_select_out(codec
);
5555 if (nid
== VNID_AMIC1_SEL
) {
5557 spec
->vnode_lswitch
[VNID_AMIC1_ASEL
- VNODE_START_NID
];
5559 ca0132_select_mic(codec
);
5563 if (nid
== VNID_HP_ASEL
) {
5564 if (ca0132_use_alt_functions(spec
))
5565 ca0132_alt_select_out(codec
);
5567 ca0132_select_out(codec
);
5571 if (nid
== VNID_AMIC1_ASEL
) {
5572 ca0132_select_mic(codec
);
5576 /* if effective conditions, then update hw immediately. */
5577 effective
= ca0132_is_vnode_effective(codec
, nid
, &shared_nid
);
5579 int dir
= get_amp_direction(kcontrol
);
5580 int ch
= get_amp_channels(kcontrol
);
5583 mutex_lock(&codec
->control_mutex
);
5584 pval
= kcontrol
->private_value
;
5585 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(shared_nid
, ch
,
5587 ret
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
5588 kcontrol
->private_value
= pval
;
5589 mutex_unlock(&codec
->control_mutex
);
5594 /* End of control change helpers. */
5596 static void ca0132_alt_bass_redirection_xover_set(struct hda_codec
*codec
,
5599 snd_hda_power_up(codec
);
5601 dspio_set_param(codec
, 0x96, 0x20, SPEAKER_BASS_REDIRECT_XOVER_FREQ
,
5602 &(float_xbass_xover_lookup
[idx
]), sizeof(unsigned int));
5604 snd_hda_power_down(codec
);
5608 * Below I've added controls to mess with the effect levels, I've only enabled
5609 * them on the Sound Blaster Z, but they would probably also work on the
5610 * Chromebook. I figured they were probably tuned specifically for it, and left
5614 /* Sets DSP effect level from the sliders above the controls */
5616 static int ca0132_alt_slider_ctl_set(struct hda_codec
*codec
, hda_nid_t nid
,
5617 const unsigned int *lookup
, int idx
)
5622 * For X_BASS, req 2 is actually crossover freq instead of
5630 snd_hda_power_up(codec
);
5631 if (nid
== XBASS_XOVER
) {
5632 for (i
= 0; i
< OUT_EFFECTS_COUNT
; i
++)
5633 if (ca0132_effects
[i
].nid
== X_BASS
)
5636 dspio_set_param(codec
, ca0132_effects
[i
].mid
, 0x20,
5637 ca0132_effects
[i
].reqs
[1],
5638 &(lookup
[idx
- 1]), sizeof(unsigned int));
5640 /* Find the actual effect structure */
5641 for (i
= 0; i
< OUT_EFFECTS_COUNT
; i
++)
5642 if (nid
== ca0132_effects
[i
].nid
)
5645 dspio_set_param(codec
, ca0132_effects
[i
].mid
, 0x20,
5646 ca0132_effects
[i
].reqs
[y
],
5647 &(lookup
[idx
]), sizeof(unsigned int));
5650 snd_hda_power_down(codec
);
5655 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol
*kcontrol
,
5656 struct snd_ctl_elem_value
*ucontrol
)
5658 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5659 struct ca0132_spec
*spec
= codec
->spec
;
5660 long *valp
= ucontrol
->value
.integer
.value
;
5661 hda_nid_t nid
= get_amp_nid(kcontrol
);
5663 if (nid
== BASS_REDIRECTION_XOVER
)
5664 *valp
= spec
->bass_redirect_xover_freq
;
5666 *valp
= spec
->xbass_xover_freq
;
5671 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol
*kcontrol
,
5672 struct snd_ctl_elem_value
*ucontrol
)
5674 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5675 struct ca0132_spec
*spec
= codec
->spec
;
5676 hda_nid_t nid
= get_amp_nid(kcontrol
);
5677 long *valp
= ucontrol
->value
.integer
.value
;
5678 int idx
= nid
- OUT_EFFECT_START_NID
;
5680 *valp
= spec
->fx_ctl_val
[idx
];
5685 * The X-bass crossover starts at 10hz, so the min is 1. The
5686 * frequency is set in multiples of 10.
5688 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol
*kcontrol
,
5689 struct snd_ctl_elem_info
*uinfo
)
5691 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
5693 uinfo
->value
.integer
.min
= 1;
5694 uinfo
->value
.integer
.max
= 100;
5695 uinfo
->value
.integer
.step
= 1;
5700 static int ca0132_alt_effect_slider_info(struct snd_kcontrol
*kcontrol
,
5701 struct snd_ctl_elem_info
*uinfo
)
5703 int chs
= get_amp_channels(kcontrol
);
5705 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
5706 uinfo
->count
= chs
== 3 ? 2 : 1;
5707 uinfo
->value
.integer
.min
= 0;
5708 uinfo
->value
.integer
.max
= 100;
5709 uinfo
->value
.integer
.step
= 1;
5714 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol
*kcontrol
,
5715 struct snd_ctl_elem_value
*ucontrol
)
5717 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5718 struct ca0132_spec
*spec
= codec
->spec
;
5719 hda_nid_t nid
= get_amp_nid(kcontrol
);
5720 long *valp
= ucontrol
->value
.integer
.value
;
5724 if (nid
== BASS_REDIRECTION_XOVER
)
5725 cur_val
= &spec
->bass_redirect_xover_freq
;
5727 cur_val
= &spec
->xbass_xover_freq
;
5730 if (*cur_val
== *valp
)
5736 if (nid
== BASS_REDIRECTION_XOVER
)
5737 ca0132_alt_bass_redirection_xover_set(codec
, *cur_val
);
5739 ca0132_alt_slider_ctl_set(codec
, nid
, float_xbass_xover_lookup
, idx
);
5744 static int ca0132_alt_effect_slider_put(struct snd_kcontrol
*kcontrol
,
5745 struct snd_ctl_elem_value
*ucontrol
)
5747 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5748 struct ca0132_spec
*spec
= codec
->spec
;
5749 hda_nid_t nid
= get_amp_nid(kcontrol
);
5750 long *valp
= ucontrol
->value
.integer
.value
;
5753 idx
= nid
- EFFECT_START_NID
;
5755 if (spec
->fx_ctl_val
[idx
] == *valp
)
5758 spec
->fx_ctl_val
[idx
] = *valp
;
5761 ca0132_alt_slider_ctl_set(codec
, nid
, float_zero_to_one_lookup
, idx
);
5768 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
5769 * only has off or full 30 dB, and didn't like making a volume slider that has
5770 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
5772 #define MIC_BOOST_NUM_OF_STEPS 4
5773 #define MIC_BOOST_ENUM_MAX_STRLEN 10
5775 static int ca0132_alt_mic_boost_info(struct snd_kcontrol
*kcontrol
,
5776 struct snd_ctl_elem_info
*uinfo
)
5779 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
5781 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5783 uinfo
->value
.enumerated
.items
= MIC_BOOST_NUM_OF_STEPS
;
5784 if (uinfo
->value
.enumerated
.item
>= MIC_BOOST_NUM_OF_STEPS
)
5785 uinfo
->value
.enumerated
.item
= MIC_BOOST_NUM_OF_STEPS
- 1;
5786 sprintf(namestr
, "%d %s", (uinfo
->value
.enumerated
.item
* 10), sfx
);
5787 strcpy(uinfo
->value
.enumerated
.name
, namestr
);
5791 static int ca0132_alt_mic_boost_get(struct snd_kcontrol
*kcontrol
,
5792 struct snd_ctl_elem_value
*ucontrol
)
5794 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5795 struct ca0132_spec
*spec
= codec
->spec
;
5797 ucontrol
->value
.enumerated
.item
[0] = spec
->mic_boost_enum_val
;
5801 static int ca0132_alt_mic_boost_put(struct snd_kcontrol
*kcontrol
,
5802 struct snd_ctl_elem_value
*ucontrol
)
5804 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5805 struct ca0132_spec
*spec
= codec
->spec
;
5806 int sel
= ucontrol
->value
.enumerated
.item
[0];
5807 unsigned int items
= MIC_BOOST_NUM_OF_STEPS
;
5812 codec_dbg(codec
, "ca0132_alt_mic_boost: boost=%d\n",
5815 spec
->mic_boost_enum_val
= sel
;
5817 if (spec
->in_enum_val
!= REAR_LINE_IN
)
5818 ca0132_alt_mic_boost_set(codec
, spec
->mic_boost_enum_val
);
5824 * Sound BlasterX AE-5 Headphone Gain Controls.
5826 #define AE5_HEADPHONE_GAIN_MAX 3
5827 static int ae5_headphone_gain_info(struct snd_kcontrol
*kcontrol
,
5828 struct snd_ctl_elem_info
*uinfo
)
5830 char *sfx
= " Ohms)";
5831 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
5833 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5835 uinfo
->value
.enumerated
.items
= AE5_HEADPHONE_GAIN_MAX
;
5836 if (uinfo
->value
.enumerated
.item
>= AE5_HEADPHONE_GAIN_MAX
)
5837 uinfo
->value
.enumerated
.item
= AE5_HEADPHONE_GAIN_MAX
- 1;
5838 sprintf(namestr
, "%s %s",
5839 ae5_headphone_gain_presets
[uinfo
->value
.enumerated
.item
].name
,
5841 strcpy(uinfo
->value
.enumerated
.name
, namestr
);
5845 static int ae5_headphone_gain_get(struct snd_kcontrol
*kcontrol
,
5846 struct snd_ctl_elem_value
*ucontrol
)
5848 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5849 struct ca0132_spec
*spec
= codec
->spec
;
5851 ucontrol
->value
.enumerated
.item
[0] = spec
->ae5_headphone_gain_val
;
5855 static int ae5_headphone_gain_put(struct snd_kcontrol
*kcontrol
,
5856 struct snd_ctl_elem_value
*ucontrol
)
5858 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5859 struct ca0132_spec
*spec
= codec
->spec
;
5860 int sel
= ucontrol
->value
.enumerated
.item
[0];
5861 unsigned int items
= AE5_HEADPHONE_GAIN_MAX
;
5866 codec_dbg(codec
, "ae5_headphone_gain: boost=%d\n",
5869 spec
->ae5_headphone_gain_val
= sel
;
5871 if (spec
->out_enum_val
== HEADPHONE_OUT
)
5872 ae5_headphone_gain_set(codec
, spec
->ae5_headphone_gain_val
);
5878 * Sound BlasterX AE-5 sound filter enumerated control.
5880 #define AE5_SOUND_FILTER_MAX 3
5882 static int ae5_sound_filter_info(struct snd_kcontrol
*kcontrol
,
5883 struct snd_ctl_elem_info
*uinfo
)
5885 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
5887 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5889 uinfo
->value
.enumerated
.items
= AE5_SOUND_FILTER_MAX
;
5890 if (uinfo
->value
.enumerated
.item
>= AE5_SOUND_FILTER_MAX
)
5891 uinfo
->value
.enumerated
.item
= AE5_SOUND_FILTER_MAX
- 1;
5892 sprintf(namestr
, "%s",
5893 ae5_filter_presets
[uinfo
->value
.enumerated
.item
].name
);
5894 strcpy(uinfo
->value
.enumerated
.name
, namestr
);
5898 static int ae5_sound_filter_get(struct snd_kcontrol
*kcontrol
,
5899 struct snd_ctl_elem_value
*ucontrol
)
5901 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5902 struct ca0132_spec
*spec
= codec
->spec
;
5904 ucontrol
->value
.enumerated
.item
[0] = spec
->ae5_filter_val
;
5908 static int ae5_sound_filter_put(struct snd_kcontrol
*kcontrol
,
5909 struct snd_ctl_elem_value
*ucontrol
)
5911 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5912 struct ca0132_spec
*spec
= codec
->spec
;
5913 int sel
= ucontrol
->value
.enumerated
.item
[0];
5914 unsigned int items
= AE5_SOUND_FILTER_MAX
;
5919 codec_dbg(codec
, "ae5_sound_filter: %s\n",
5920 ae5_filter_presets
[sel
].name
);
5922 spec
->ae5_filter_val
= sel
;
5924 ca0113_mmio_command_set_type2(codec
, 0x48, 0x07,
5925 ae5_filter_presets
[sel
].val
);
5931 * Input Select Control for alternative ca0132 codecs. This exists because
5932 * front microphone has no auto-detect, and we need a way to set the rear
5935 static int ca0132_alt_input_source_info(struct snd_kcontrol
*kcontrol
,
5936 struct snd_ctl_elem_info
*uinfo
)
5938 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5940 uinfo
->value
.enumerated
.items
= IN_SRC_NUM_OF_INPUTS
;
5941 if (uinfo
->value
.enumerated
.item
>= IN_SRC_NUM_OF_INPUTS
)
5942 uinfo
->value
.enumerated
.item
= IN_SRC_NUM_OF_INPUTS
- 1;
5943 strcpy(uinfo
->value
.enumerated
.name
,
5944 in_src_str
[uinfo
->value
.enumerated
.item
]);
5948 static int ca0132_alt_input_source_get(struct snd_kcontrol
*kcontrol
,
5949 struct snd_ctl_elem_value
*ucontrol
)
5951 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5952 struct ca0132_spec
*spec
= codec
->spec
;
5954 ucontrol
->value
.enumerated
.item
[0] = spec
->in_enum_val
;
5958 static int ca0132_alt_input_source_put(struct snd_kcontrol
*kcontrol
,
5959 struct snd_ctl_elem_value
*ucontrol
)
5961 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5962 struct ca0132_spec
*spec
= codec
->spec
;
5963 int sel
= ucontrol
->value
.enumerated
.item
[0];
5964 unsigned int items
= IN_SRC_NUM_OF_INPUTS
;
5967 * The AE-7 has no front microphone, so limit items to 2: rear mic and
5970 if (ca0132_quirk(spec
) == QUIRK_AE7
)
5976 codec_dbg(codec
, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5977 sel
, in_src_str
[sel
]);
5979 spec
->in_enum_val
= sel
;
5981 ca0132_alt_select_in(codec
);
5986 /* Sound Blaster Z Output Select Control */
5987 static int ca0132_alt_output_select_get_info(struct snd_kcontrol
*kcontrol
,
5988 struct snd_ctl_elem_info
*uinfo
)
5990 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5992 uinfo
->value
.enumerated
.items
= NUM_OF_OUTPUTS
;
5993 if (uinfo
->value
.enumerated
.item
>= NUM_OF_OUTPUTS
)
5994 uinfo
->value
.enumerated
.item
= NUM_OF_OUTPUTS
- 1;
5995 strcpy(uinfo
->value
.enumerated
.name
,
5996 out_type_str
[uinfo
->value
.enumerated
.item
]);
6000 static int ca0132_alt_output_select_get(struct snd_kcontrol
*kcontrol
,
6001 struct snd_ctl_elem_value
*ucontrol
)
6003 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6004 struct ca0132_spec
*spec
= codec
->spec
;
6006 ucontrol
->value
.enumerated
.item
[0] = spec
->out_enum_val
;
6010 static int ca0132_alt_output_select_put(struct snd_kcontrol
*kcontrol
,
6011 struct snd_ctl_elem_value
*ucontrol
)
6013 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6014 struct ca0132_spec
*spec
= codec
->spec
;
6015 int sel
= ucontrol
->value
.enumerated
.item
[0];
6016 unsigned int items
= NUM_OF_OUTPUTS
;
6017 unsigned int auto_jack
;
6022 codec_dbg(codec
, "ca0132_alt_output_select: sel=%d, preset=%s\n",
6023 sel
, out_type_str
[sel
]);
6025 spec
->out_enum_val
= sel
;
6027 auto_jack
= spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
6030 ca0132_alt_select_out(codec
);
6035 /* Select surround output type: 2.1, 4.0, 4.1, or 5.1. */
6036 static int ca0132_alt_speaker_channel_cfg_get_info(struct snd_kcontrol
*kcontrol
,
6037 struct snd_ctl_elem_info
*uinfo
)
6039 unsigned int items
= SPEAKER_CHANNEL_CFG_COUNT
;
6041 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
6043 uinfo
->value
.enumerated
.items
= items
;
6044 if (uinfo
->value
.enumerated
.item
>= items
)
6045 uinfo
->value
.enumerated
.item
= items
- 1;
6046 strcpy(uinfo
->value
.enumerated
.name
,
6047 speaker_channel_cfgs
[uinfo
->value
.enumerated
.item
].name
);
6051 static int ca0132_alt_speaker_channel_cfg_get(struct snd_kcontrol
*kcontrol
,
6052 struct snd_ctl_elem_value
*ucontrol
)
6054 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6055 struct ca0132_spec
*spec
= codec
->spec
;
6057 ucontrol
->value
.enumerated
.item
[0] = spec
->channel_cfg_val
;
6061 static int ca0132_alt_speaker_channel_cfg_put(struct snd_kcontrol
*kcontrol
,
6062 struct snd_ctl_elem_value
*ucontrol
)
6064 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6065 struct ca0132_spec
*spec
= codec
->spec
;
6066 int sel
= ucontrol
->value
.enumerated
.item
[0];
6067 unsigned int items
= SPEAKER_CHANNEL_CFG_COUNT
;
6072 codec_dbg(codec
, "ca0132_alt_speaker_channels: sel=%d, channels=%s\n",
6073 sel
, speaker_channel_cfgs
[sel
].name
);
6075 spec
->channel_cfg_val
= sel
;
6077 if (spec
->out_enum_val
== SPEAKER_OUT
)
6078 ca0132_alt_select_out(codec
);
6084 * Smart Volume output setting control. Three different settings, Normal,
6085 * which takes the value from the smart volume slider. The two others, loud
6086 * and night, disregard the slider value and have uneditable values.
6088 #define NUM_OF_SVM_SETTINGS 3
6089 static const char *const out_svm_set_enum_str
[3] = {"Normal", "Loud", "Night" };
6091 static int ca0132_alt_svm_setting_info(struct snd_kcontrol
*kcontrol
,
6092 struct snd_ctl_elem_info
*uinfo
)
6094 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
6096 uinfo
->value
.enumerated
.items
= NUM_OF_SVM_SETTINGS
;
6097 if (uinfo
->value
.enumerated
.item
>= NUM_OF_SVM_SETTINGS
)
6098 uinfo
->value
.enumerated
.item
= NUM_OF_SVM_SETTINGS
- 1;
6099 strcpy(uinfo
->value
.enumerated
.name
,
6100 out_svm_set_enum_str
[uinfo
->value
.enumerated
.item
]);
6104 static int ca0132_alt_svm_setting_get(struct snd_kcontrol
*kcontrol
,
6105 struct snd_ctl_elem_value
*ucontrol
)
6107 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6108 struct ca0132_spec
*spec
= codec
->spec
;
6110 ucontrol
->value
.enumerated
.item
[0] = spec
->smart_volume_setting
;
6114 static int ca0132_alt_svm_setting_put(struct snd_kcontrol
*kcontrol
,
6115 struct snd_ctl_elem_value
*ucontrol
)
6117 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6118 struct ca0132_spec
*spec
= codec
->spec
;
6119 int sel
= ucontrol
->value
.enumerated
.item
[0];
6120 unsigned int items
= NUM_OF_SVM_SETTINGS
;
6121 unsigned int idx
= SMART_VOLUME
- EFFECT_START_NID
;
6127 codec_dbg(codec
, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
6128 sel
, out_svm_set_enum_str
[sel
]);
6130 spec
->smart_volume_setting
= sel
;
6146 /* Req 2 is the Smart Volume Setting req. */
6147 dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
6148 ca0132_effects
[idx
].reqs
[2], tmp
);
6152 /* Sound Blaster Z EQ preset controls */
6153 static int ca0132_alt_eq_preset_info(struct snd_kcontrol
*kcontrol
,
6154 struct snd_ctl_elem_info
*uinfo
)
6156 unsigned int items
= ARRAY_SIZE(ca0132_alt_eq_presets
);
6158 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
6160 uinfo
->value
.enumerated
.items
= items
;
6161 if (uinfo
->value
.enumerated
.item
>= items
)
6162 uinfo
->value
.enumerated
.item
= items
- 1;
6163 strcpy(uinfo
->value
.enumerated
.name
,
6164 ca0132_alt_eq_presets
[uinfo
->value
.enumerated
.item
].name
);
6168 static int ca0132_alt_eq_preset_get(struct snd_kcontrol
*kcontrol
,
6169 struct snd_ctl_elem_value
*ucontrol
)
6171 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6172 struct ca0132_spec
*spec
= codec
->spec
;
6174 ucontrol
->value
.enumerated
.item
[0] = spec
->eq_preset_val
;
6178 static int ca0132_alt_eq_preset_put(struct snd_kcontrol
*kcontrol
,
6179 struct snd_ctl_elem_value
*ucontrol
)
6181 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6182 struct ca0132_spec
*spec
= codec
->spec
;
6184 int sel
= ucontrol
->value
.enumerated
.item
[0];
6185 unsigned int items
= ARRAY_SIZE(ca0132_alt_eq_presets
);
6190 codec_dbg(codec
, "%s: sel=%d, preset=%s\n", __func__
, sel
,
6191 ca0132_alt_eq_presets
[sel
].name
);
6194 * Default needs to qualify with CrystalVoice state.
6196 for (i
= 0; i
< EQ_PRESET_MAX_PARAM_COUNT
; i
++) {
6197 err
= dspio_set_uint_param(codec
, ca0132_alt_eq_enum
.mid
,
6198 ca0132_alt_eq_enum
.reqs
[i
],
6199 ca0132_alt_eq_presets
[sel
].vals
[i
]);
6205 spec
->eq_preset_val
= sel
;
6210 static int ca0132_voicefx_info(struct snd_kcontrol
*kcontrol
,
6211 struct snd_ctl_elem_info
*uinfo
)
6213 unsigned int items
= ARRAY_SIZE(ca0132_voicefx_presets
);
6215 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
6217 uinfo
->value
.enumerated
.items
= items
;
6218 if (uinfo
->value
.enumerated
.item
>= items
)
6219 uinfo
->value
.enumerated
.item
= items
- 1;
6220 strcpy(uinfo
->value
.enumerated
.name
,
6221 ca0132_voicefx_presets
[uinfo
->value
.enumerated
.item
].name
);
6225 static int ca0132_voicefx_get(struct snd_kcontrol
*kcontrol
,
6226 struct snd_ctl_elem_value
*ucontrol
)
6228 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6229 struct ca0132_spec
*spec
= codec
->spec
;
6231 ucontrol
->value
.enumerated
.item
[0] = spec
->voicefx_val
;
6235 static int ca0132_voicefx_put(struct snd_kcontrol
*kcontrol
,
6236 struct snd_ctl_elem_value
*ucontrol
)
6238 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6239 struct ca0132_spec
*spec
= codec
->spec
;
6241 int sel
= ucontrol
->value
.enumerated
.item
[0];
6243 if (sel
>= ARRAY_SIZE(ca0132_voicefx_presets
))
6246 codec_dbg(codec
, "ca0132_voicefx_put: sel=%d, preset=%s\n",
6247 sel
, ca0132_voicefx_presets
[sel
].name
);
6251 * Default needs to qualify with CrystalVoice state.
6253 for (i
= 0; i
< VOICEFX_MAX_PARAM_COUNT
; i
++) {
6254 err
= dspio_set_uint_param(codec
, ca0132_voicefx
.mid
,
6255 ca0132_voicefx
.reqs
[i
],
6256 ca0132_voicefx_presets
[sel
].vals
[i
]);
6262 spec
->voicefx_val
= sel
;
6263 /* enable voice fx */
6264 ca0132_voicefx_set(codec
, (sel
? 1 : 0));
6270 static int ca0132_switch_get(struct snd_kcontrol
*kcontrol
,
6271 struct snd_ctl_elem_value
*ucontrol
)
6273 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6274 struct ca0132_spec
*spec
= codec
->spec
;
6275 hda_nid_t nid
= get_amp_nid(kcontrol
);
6276 int ch
= get_amp_channels(kcontrol
);
6277 long *valp
= ucontrol
->value
.integer
.value
;
6280 if ((nid
>= VNODE_START_NID
) && (nid
< VNODE_END_NID
)) {
6282 *valp
= spec
->vnode_lswitch
[nid
- VNODE_START_NID
];
6286 *valp
= spec
->vnode_rswitch
[nid
- VNODE_START_NID
];
6292 /* effects, include PE and CrystalVoice */
6293 if ((nid
>= EFFECT_START_NID
) && (nid
< EFFECT_END_NID
)) {
6294 *valp
= spec
->effects_switch
[nid
- EFFECT_START_NID
];
6299 if (nid
== spec
->input_pins
[0]) {
6300 *valp
= spec
->cur_mic_boost
;
6304 if (nid
== ZXR_HEADPHONE_GAIN
) {
6305 *valp
= spec
->zxr_gain_set
;
6309 if (nid
== SPEAKER_FULL_RANGE_FRONT
|| nid
== SPEAKER_FULL_RANGE_REAR
) {
6310 *valp
= spec
->speaker_range_val
[nid
- SPEAKER_FULL_RANGE_FRONT
];
6314 if (nid
== BASS_REDIRECTION
) {
6315 *valp
= spec
->bass_redirection_val
;
6322 static int ca0132_switch_put(struct snd_kcontrol
*kcontrol
,
6323 struct snd_ctl_elem_value
*ucontrol
)
6325 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6326 struct ca0132_spec
*spec
= codec
->spec
;
6327 hda_nid_t nid
= get_amp_nid(kcontrol
);
6328 int ch
= get_amp_channels(kcontrol
);
6329 long *valp
= ucontrol
->value
.integer
.value
;
6332 codec_dbg(codec
, "ca0132_switch_put: nid=0x%x, val=%ld\n",
6335 snd_hda_power_up(codec
);
6337 if ((nid
>= VNODE_START_NID
) && (nid
< VNODE_END_NID
)) {
6339 spec
->vnode_lswitch
[nid
- VNODE_START_NID
] = *valp
;
6343 spec
->vnode_rswitch
[nid
- VNODE_START_NID
] = *valp
;
6346 changed
= ca0132_vnode_switch_set(kcontrol
, ucontrol
);
6351 if (nid
== PLAY_ENHANCEMENT
) {
6352 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
6353 changed
= ca0132_pe_switch_set(codec
);
6358 if (nid
== CRYSTAL_VOICE
) {
6359 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
6360 changed
= ca0132_cvoice_switch_set(codec
);
6364 /* out and in effects */
6365 if (((nid
>= OUT_EFFECT_START_NID
) && (nid
< OUT_EFFECT_END_NID
)) ||
6366 ((nid
>= IN_EFFECT_START_NID
) && (nid
< IN_EFFECT_END_NID
))) {
6367 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
6368 changed
= ca0132_effects_set(codec
, nid
, *valp
);
6373 if (nid
== spec
->input_pins
[0]) {
6374 spec
->cur_mic_boost
= *valp
;
6375 if (ca0132_use_alt_functions(spec
)) {
6376 if (spec
->in_enum_val
!= REAR_LINE_IN
)
6377 changed
= ca0132_mic_boost_set(codec
, *valp
);
6379 /* Mic boost does not apply to Digital Mic */
6380 if (spec
->cur_mic_type
!= DIGITAL_MIC
)
6381 changed
= ca0132_mic_boost_set(codec
, *valp
);
6387 if (nid
== ZXR_HEADPHONE_GAIN
) {
6388 spec
->zxr_gain_set
= *valp
;
6389 if (spec
->cur_out_type
== HEADPHONE_OUT
)
6390 changed
= zxr_headphone_gain_set(codec
, *valp
);
6397 if (nid
== SPEAKER_FULL_RANGE_FRONT
|| nid
== SPEAKER_FULL_RANGE_REAR
) {
6398 spec
->speaker_range_val
[nid
- SPEAKER_FULL_RANGE_FRONT
] = *valp
;
6399 if (spec
->cur_out_type
== SPEAKER_OUT
)
6400 ca0132_alt_set_full_range_speaker(codec
);
6405 if (nid
== BASS_REDIRECTION
) {
6406 spec
->bass_redirection_val
= *valp
;
6407 if (spec
->cur_out_type
== SPEAKER_OUT
)
6408 ca0132_alt_surround_set_bass_redirection(codec
, *valp
);
6414 snd_hda_power_down(codec
);
6422 * Sets the internal DSP decibel level to match the DAC for output, and the
6423 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
6424 * all alternative codecs set DSP playback volume.
6426 static void ca0132_alt_dsp_volume_put(struct hda_codec
*codec
, hda_nid_t nid
)
6428 struct ca0132_spec
*spec
= codec
->spec
;
6429 unsigned int dsp_dir
;
6430 unsigned int lookup_val
;
6432 if (nid
== VNID_SPK
)
6433 dsp_dir
= DSP_VOL_OUT
;
6435 dsp_dir
= DSP_VOL_IN
;
6437 lookup_val
= spec
->vnode_lvol
[nid
- VNODE_START_NID
];
6439 dspio_set_uint_param(codec
,
6440 ca0132_alt_vol_ctls
[dsp_dir
].mid
,
6441 ca0132_alt_vol_ctls
[dsp_dir
].reqs
[0],
6442 float_vol_db_lookup
[lookup_val
]);
6444 lookup_val
= spec
->vnode_rvol
[nid
- VNODE_START_NID
];
6446 dspio_set_uint_param(codec
,
6447 ca0132_alt_vol_ctls
[dsp_dir
].mid
,
6448 ca0132_alt_vol_ctls
[dsp_dir
].reqs
[1],
6449 float_vol_db_lookup
[lookup_val
]);
6451 dspio_set_uint_param(codec
,
6452 ca0132_alt_vol_ctls
[dsp_dir
].mid
,
6453 ca0132_alt_vol_ctls
[dsp_dir
].reqs
[2], FLOAT_ZERO
);
6456 static int ca0132_volume_info(struct snd_kcontrol
*kcontrol
,
6457 struct snd_ctl_elem_info
*uinfo
)
6459 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6460 struct ca0132_spec
*spec
= codec
->spec
;
6461 hda_nid_t nid
= get_amp_nid(kcontrol
);
6462 int ch
= get_amp_channels(kcontrol
);
6463 int dir
= get_amp_direction(kcontrol
);
6469 /* follow shared_out info */
6470 nid
= spec
->shared_out_nid
;
6471 mutex_lock(&codec
->control_mutex
);
6472 pval
= kcontrol
->private_value
;
6473 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
6474 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
6475 kcontrol
->private_value
= pval
;
6476 mutex_unlock(&codec
->control_mutex
);
6479 /* follow shared_mic info */
6480 nid
= spec
->shared_mic_nid
;
6481 mutex_lock(&codec
->control_mutex
);
6482 pval
= kcontrol
->private_value
;
6483 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
6484 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
6485 kcontrol
->private_value
= pval
;
6486 mutex_unlock(&codec
->control_mutex
);
6489 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
6494 static int ca0132_volume_get(struct snd_kcontrol
*kcontrol
,
6495 struct snd_ctl_elem_value
*ucontrol
)
6497 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6498 struct ca0132_spec
*spec
= codec
->spec
;
6499 hda_nid_t nid
= get_amp_nid(kcontrol
);
6500 int ch
= get_amp_channels(kcontrol
);
6501 long *valp
= ucontrol
->value
.integer
.value
;
6503 /* store the left and right volume */
6505 *valp
= spec
->vnode_lvol
[nid
- VNODE_START_NID
];
6509 *valp
= spec
->vnode_rvol
[nid
- VNODE_START_NID
];
6515 static int ca0132_volume_put(struct snd_kcontrol
*kcontrol
,
6516 struct snd_ctl_elem_value
*ucontrol
)
6518 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6519 struct ca0132_spec
*spec
= codec
->spec
;
6520 hda_nid_t nid
= get_amp_nid(kcontrol
);
6521 int ch
= get_amp_channels(kcontrol
);
6522 long *valp
= ucontrol
->value
.integer
.value
;
6523 hda_nid_t shared_nid
= 0;
6527 /* store the left and right volume */
6529 spec
->vnode_lvol
[nid
- VNODE_START_NID
] = *valp
;
6533 spec
->vnode_rvol
[nid
- VNODE_START_NID
] = *valp
;
6537 /* if effective conditions, then update hw immediately. */
6538 effective
= ca0132_is_vnode_effective(codec
, nid
, &shared_nid
);
6540 int dir
= get_amp_direction(kcontrol
);
6543 snd_hda_power_up(codec
);
6544 mutex_lock(&codec
->control_mutex
);
6545 pval
= kcontrol
->private_value
;
6546 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(shared_nid
, ch
,
6548 changed
= snd_hda_mixer_amp_volume_put(kcontrol
, ucontrol
);
6549 kcontrol
->private_value
= pval
;
6550 mutex_unlock(&codec
->control_mutex
);
6551 snd_hda_power_down(codec
);
6558 * This function is the same as the one above, because using an if statement
6559 * inside of the above volume control for the DSP volume would cause too much
6560 * lag. This is a lot more smooth.
6562 static int ca0132_alt_volume_put(struct snd_kcontrol
*kcontrol
,
6563 struct snd_ctl_elem_value
*ucontrol
)
6565 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6566 struct ca0132_spec
*spec
= codec
->spec
;
6567 hda_nid_t nid
= get_amp_nid(kcontrol
);
6568 int ch
= get_amp_channels(kcontrol
);
6569 long *valp
= ucontrol
->value
.integer
.value
;
6582 /* store the left and right volume */
6584 spec
->vnode_lvol
[vnid
- VNODE_START_NID
] = *valp
;
6588 spec
->vnode_rvol
[vnid
- VNODE_START_NID
] = *valp
;
6592 snd_hda_power_up(codec
);
6593 ca0132_alt_dsp_volume_put(codec
, vnid
);
6594 mutex_lock(&codec
->control_mutex
);
6595 changed
= snd_hda_mixer_amp_volume_put(kcontrol
, ucontrol
);
6596 mutex_unlock(&codec
->control_mutex
);
6597 snd_hda_power_down(codec
);
6602 static int ca0132_volume_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
6603 unsigned int size
, unsigned int __user
*tlv
)
6605 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
6606 struct ca0132_spec
*spec
= codec
->spec
;
6607 hda_nid_t nid
= get_amp_nid(kcontrol
);
6608 int ch
= get_amp_channels(kcontrol
);
6609 int dir
= get_amp_direction(kcontrol
);
6615 /* follow shared_out tlv */
6616 nid
= spec
->shared_out_nid
;
6617 mutex_lock(&codec
->control_mutex
);
6618 pval
= kcontrol
->private_value
;
6619 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
6620 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
6621 kcontrol
->private_value
= pval
;
6622 mutex_unlock(&codec
->control_mutex
);
6625 /* follow shared_mic tlv */
6626 nid
= spec
->shared_mic_nid
;
6627 mutex_lock(&codec
->control_mutex
);
6628 pval
= kcontrol
->private_value
;
6629 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
6630 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
6631 kcontrol
->private_value
= pval
;
6632 mutex_unlock(&codec
->control_mutex
);
6635 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
6640 /* Add volume slider control for effect level */
6641 static int ca0132_alt_add_effect_slider(struct hda_codec
*codec
, hda_nid_t nid
,
6642 const char *pfx
, int dir
)
6644 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
6645 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
6646 struct snd_kcontrol_new knew
=
6647 HDA_CODEC_VOLUME_MONO(namestr
, nid
, 1, 0, type
);
6649 sprintf(namestr
, "FX: %s %s Volume", pfx
, dirstr
[dir
]);
6655 knew
.info
= ca0132_alt_xbass_xover_slider_info
;
6656 knew
.get
= ca0132_alt_xbass_xover_slider_ctl_get
;
6657 knew
.put
= ca0132_alt_xbass_xover_slider_put
;
6660 knew
.info
= ca0132_alt_effect_slider_info
;
6661 knew
.get
= ca0132_alt_slider_ctl_get
;
6662 knew
.put
= ca0132_alt_effect_slider_put
;
6663 knew
.private_value
=
6664 HDA_COMPOSE_AMP_VAL(nid
, 1, 0, type
);
6668 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
6672 * Added FX: prefix for the alternative codecs, because otherwise the surround
6673 * effect would conflict with the Surround sound volume control. Also seems more
6674 * clear as to what the switches do. Left alone for others.
6676 static int add_fx_switch(struct hda_codec
*codec
, hda_nid_t nid
,
6677 const char *pfx
, int dir
)
6679 struct ca0132_spec
*spec
= codec
->spec
;
6680 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
6681 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
6682 struct snd_kcontrol_new knew
=
6683 CA0132_CODEC_MUTE_MONO(namestr
, nid
, 1, type
);
6684 /* If using alt_controls, add FX: prefix. But, don't add FX:
6685 * prefix to OutFX or InFX enable controls.
6687 if (ca0132_use_alt_controls(spec
) && (nid
<= IN_EFFECT_END_NID
))
6688 sprintf(namestr
, "FX: %s %s Switch", pfx
, dirstr
[dir
]);
6690 sprintf(namestr
, "%s %s Switch", pfx
, dirstr
[dir
]);
6692 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
6695 static int add_voicefx(struct hda_codec
*codec
)
6697 struct snd_kcontrol_new knew
=
6698 HDA_CODEC_MUTE_MONO(ca0132_voicefx
.name
,
6699 VOICEFX
, 1, 0, HDA_INPUT
);
6700 knew
.info
= ca0132_voicefx_info
;
6701 knew
.get
= ca0132_voicefx_get
;
6702 knew
.put
= ca0132_voicefx_put
;
6703 return snd_hda_ctl_add(codec
, VOICEFX
, snd_ctl_new1(&knew
, codec
));
6706 /* Create the EQ Preset control */
6707 static int add_ca0132_alt_eq_presets(struct hda_codec
*codec
)
6709 struct snd_kcontrol_new knew
=
6710 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum
.name
,
6711 EQ_PRESET_ENUM
, 1, 0, HDA_OUTPUT
);
6712 knew
.info
= ca0132_alt_eq_preset_info
;
6713 knew
.get
= ca0132_alt_eq_preset_get
;
6714 knew
.put
= ca0132_alt_eq_preset_put
;
6715 return snd_hda_ctl_add(codec
, EQ_PRESET_ENUM
,
6716 snd_ctl_new1(&knew
, codec
));
6720 * Add enumerated control for the three different settings of the smart volume
6721 * output effect. Normal just uses the slider value, and loud and night are
6722 * their own things that ignore that value.
6724 static int ca0132_alt_add_svm_enum(struct hda_codec
*codec
)
6726 struct snd_kcontrol_new knew
=
6727 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
6728 SMART_VOLUME_ENUM
, 1, 0, HDA_OUTPUT
);
6729 knew
.info
= ca0132_alt_svm_setting_info
;
6730 knew
.get
= ca0132_alt_svm_setting_get
;
6731 knew
.put
= ca0132_alt_svm_setting_put
;
6732 return snd_hda_ctl_add(codec
, SMART_VOLUME_ENUM
,
6733 snd_ctl_new1(&knew
, codec
));
6738 * Create an Output Select enumerated control for codecs with surround
6741 static int ca0132_alt_add_output_enum(struct hda_codec
*codec
)
6743 struct snd_kcontrol_new knew
=
6744 HDA_CODEC_MUTE_MONO("Output Select",
6745 OUTPUT_SOURCE_ENUM
, 1, 0, HDA_OUTPUT
);
6746 knew
.info
= ca0132_alt_output_select_get_info
;
6747 knew
.get
= ca0132_alt_output_select_get
;
6748 knew
.put
= ca0132_alt_output_select_put
;
6749 return snd_hda_ctl_add(codec
, OUTPUT_SOURCE_ENUM
,
6750 snd_ctl_new1(&knew
, codec
));
6754 * Add a control for selecting channel count on speaker output. Setting this
6755 * allows the DSP to do bass redirection and channel upmixing on surround
6758 static int ca0132_alt_add_speaker_channel_cfg_enum(struct hda_codec
*codec
)
6760 struct snd_kcontrol_new knew
=
6761 HDA_CODEC_MUTE_MONO("Surround Channel Config",
6762 SPEAKER_CHANNEL_CFG_ENUM
, 1, 0, HDA_OUTPUT
);
6763 knew
.info
= ca0132_alt_speaker_channel_cfg_get_info
;
6764 knew
.get
= ca0132_alt_speaker_channel_cfg_get
;
6765 knew
.put
= ca0132_alt_speaker_channel_cfg_put
;
6766 return snd_hda_ctl_add(codec
, SPEAKER_CHANNEL_CFG_ENUM
,
6767 snd_ctl_new1(&knew
, codec
));
6771 * Full range front stereo and rear surround switches. When these are set to
6772 * full range, the lower frequencies from these channels are no longer
6773 * redirected to the LFE channel.
6775 static int ca0132_alt_add_front_full_range_switch(struct hda_codec
*codec
)
6777 struct snd_kcontrol_new knew
=
6778 CA0132_CODEC_MUTE_MONO("Full-Range Front Speakers",
6779 SPEAKER_FULL_RANGE_FRONT
, 1, HDA_OUTPUT
);
6781 return snd_hda_ctl_add(codec
, SPEAKER_FULL_RANGE_FRONT
,
6782 snd_ctl_new1(&knew
, codec
));
6785 static int ca0132_alt_add_rear_full_range_switch(struct hda_codec
*codec
)
6787 struct snd_kcontrol_new knew
=
6788 CA0132_CODEC_MUTE_MONO("Full-Range Rear Speakers",
6789 SPEAKER_FULL_RANGE_REAR
, 1, HDA_OUTPUT
);
6791 return snd_hda_ctl_add(codec
, SPEAKER_FULL_RANGE_REAR
,
6792 snd_ctl_new1(&knew
, codec
));
6796 * Bass redirection redirects audio below the crossover frequency to the LFE
6797 * channel on speakers that are set as not being full-range. On configurations
6798 * without an LFE channel, it does nothing. Bass redirection seems to be the
6799 * replacement for X-Bass on configurations with an LFE channel.
6801 static int ca0132_alt_add_bass_redirection_crossover(struct hda_codec
*codec
)
6803 const char *namestr
= "Bass Redirection Crossover";
6804 struct snd_kcontrol_new knew
=
6805 HDA_CODEC_VOLUME_MONO(namestr
, BASS_REDIRECTION_XOVER
, 1, 0,
6809 knew
.info
= ca0132_alt_xbass_xover_slider_info
;
6810 knew
.get
= ca0132_alt_xbass_xover_slider_ctl_get
;
6811 knew
.put
= ca0132_alt_xbass_xover_slider_put
;
6813 return snd_hda_ctl_add(codec
, BASS_REDIRECTION_XOVER
,
6814 snd_ctl_new1(&knew
, codec
));
6817 static int ca0132_alt_add_bass_redirection_switch(struct hda_codec
*codec
)
6819 const char *namestr
= "Bass Redirection";
6820 struct snd_kcontrol_new knew
=
6821 CA0132_CODEC_MUTE_MONO(namestr
, BASS_REDIRECTION
, 1,
6824 return snd_hda_ctl_add(codec
, BASS_REDIRECTION
,
6825 snd_ctl_new1(&knew
, codec
));
6829 * Create an Input Source enumerated control for the alternate ca0132 codecs
6830 * because the front microphone has no auto-detect, and Line-in has to be set
6833 static int ca0132_alt_add_input_enum(struct hda_codec
*codec
)
6835 struct snd_kcontrol_new knew
=
6836 HDA_CODEC_MUTE_MONO("Input Source",
6837 INPUT_SOURCE_ENUM
, 1, 0, HDA_INPUT
);
6838 knew
.info
= ca0132_alt_input_source_info
;
6839 knew
.get
= ca0132_alt_input_source_get
;
6840 knew
.put
= ca0132_alt_input_source_put
;
6841 return snd_hda_ctl_add(codec
, INPUT_SOURCE_ENUM
,
6842 snd_ctl_new1(&knew
, codec
));
6846 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
6847 * more control than the original mic boost, which is either full 30dB or off.
6849 static int ca0132_alt_add_mic_boost_enum(struct hda_codec
*codec
)
6851 struct snd_kcontrol_new knew
=
6852 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
6853 MIC_BOOST_ENUM
, 1, 0, HDA_INPUT
);
6854 knew
.info
= ca0132_alt_mic_boost_info
;
6855 knew
.get
= ca0132_alt_mic_boost_get
;
6856 knew
.put
= ca0132_alt_mic_boost_put
;
6857 return snd_hda_ctl_add(codec
, MIC_BOOST_ENUM
,
6858 snd_ctl_new1(&knew
, codec
));
6863 * Add headphone gain enumerated control for the AE-5. This switches between
6864 * three modes, low, medium, and high. When non-headphone outputs are selected,
6865 * it is automatically set to high. This is the same behavior as Windows.
6867 static int ae5_add_headphone_gain_enum(struct hda_codec
*codec
)
6869 struct snd_kcontrol_new knew
=
6870 HDA_CODEC_MUTE_MONO("AE-5: Headphone Gain",
6871 AE5_HEADPHONE_GAIN_ENUM
, 1, 0, HDA_OUTPUT
);
6872 knew
.info
= ae5_headphone_gain_info
;
6873 knew
.get
= ae5_headphone_gain_get
;
6874 knew
.put
= ae5_headphone_gain_put
;
6875 return snd_hda_ctl_add(codec
, AE5_HEADPHONE_GAIN_ENUM
,
6876 snd_ctl_new1(&knew
, codec
));
6880 * Add sound filter enumerated control for the AE-5. This adds three different
6881 * settings: Slow Roll Off, Minimum Phase, and Fast Roll Off. From what I've
6882 * read into it, it changes the DAC's interpolation filter.
6884 static int ae5_add_sound_filter_enum(struct hda_codec
*codec
)
6886 struct snd_kcontrol_new knew
=
6887 HDA_CODEC_MUTE_MONO("AE-5: Sound Filter",
6888 AE5_SOUND_FILTER_ENUM
, 1, 0, HDA_OUTPUT
);
6889 knew
.info
= ae5_sound_filter_info
;
6890 knew
.get
= ae5_sound_filter_get
;
6891 knew
.put
= ae5_sound_filter_put
;
6892 return snd_hda_ctl_add(codec
, AE5_SOUND_FILTER_ENUM
,
6893 snd_ctl_new1(&knew
, codec
));
6896 static int zxr_add_headphone_gain_switch(struct hda_codec
*codec
)
6898 struct snd_kcontrol_new knew
=
6899 CA0132_CODEC_MUTE_MONO("ZxR: 600 Ohm Gain",
6900 ZXR_HEADPHONE_GAIN
, 1, HDA_OUTPUT
);
6902 return snd_hda_ctl_add(codec
, ZXR_HEADPHONE_GAIN
,
6903 snd_ctl_new1(&knew
, codec
));
6907 * Need to create follower controls for the alternate codecs that have surround
6910 static const char * const ca0132_alt_follower_pfxs
[] = {
6911 "Front", "Surround", "Center", "LFE", NULL
,
6915 * Also need special channel map, because the default one is incorrect.
6916 * I think this has to do with the pin for rear surround being 0x11,
6917 * and the center/lfe being 0x10. Usually the pin order is the opposite.
6919 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps
[] = {
6921 .map
= { SNDRV_CHMAP_FL
, SNDRV_CHMAP_FR
} },
6923 .map
= { SNDRV_CHMAP_FL
, SNDRV_CHMAP_FR
,
6924 SNDRV_CHMAP_RL
, SNDRV_CHMAP_RR
} },
6926 .map
= { SNDRV_CHMAP_FL
, SNDRV_CHMAP_FR
,
6927 SNDRV_CHMAP_FC
, SNDRV_CHMAP_LFE
,
6928 SNDRV_CHMAP_RL
, SNDRV_CHMAP_RR
} },
6932 /* Add the correct chmap for streams with 6 channels. */
6933 static void ca0132_alt_add_chmap_ctls(struct hda_codec
*codec
)
6936 struct hda_pcm
*pcm
;
6938 list_for_each_entry(pcm
, &codec
->pcm_list_head
, list
) {
6939 struct hda_pcm_stream
*hinfo
=
6940 &pcm
->stream
[SNDRV_PCM_STREAM_PLAYBACK
];
6941 struct snd_pcm_chmap
*chmap
;
6942 const struct snd_pcm_chmap_elem
*elem
;
6944 elem
= ca0132_alt_chmaps
;
6945 if (hinfo
->channels_max
== 6) {
6946 err
= snd_pcm_add_chmap_ctls(pcm
->pcm
,
6947 SNDRV_PCM_STREAM_PLAYBACK
,
6948 elem
, hinfo
->channels_max
, 0, &chmap
);
6950 codec_dbg(codec
, "snd_pcm_add_chmap_ctls failed!");
6956 * When changing Node IDs for Mixer Controls below, make sure to update
6957 * Node IDs in ca0132_config() as well.
6959 static const struct snd_kcontrol_new ca0132_mixer
[] = {
6960 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK
, HDA_OUTPUT
),
6961 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK
, HDA_OUTPUT
),
6962 CA0132_CODEC_VOL("Capture Volume", VNID_MIC
, HDA_INPUT
),
6963 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC
, HDA_INPUT
),
6964 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT
),
6965 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT
),
6966 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT
),
6967 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT
),
6968 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
6969 0x12, 1, HDA_INPUT
),
6970 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
6971 VNID_HP_SEL
, 1, HDA_OUTPUT
),
6972 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
6973 VNID_AMIC1_SEL
, 1, HDA_INPUT
),
6974 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6975 VNID_HP_ASEL
, 1, HDA_OUTPUT
),
6976 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
6977 VNID_AMIC1_ASEL
, 1, HDA_INPUT
),
6982 * Desktop specific control mixer. Removes auto-detect for mic, and adds
6983 * surround controls. Also sets both the Front Playback and Capture Volume
6984 * controls to alt so they set the DSP's decibel level.
6986 static const struct snd_kcontrol_new desktop_mixer
[] = {
6987 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT
),
6988 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK
, HDA_OUTPUT
),
6989 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT
),
6990 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT
),
6991 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT
),
6992 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT
),
6993 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT
),
6994 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT
),
6995 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT
),
6996 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC
, HDA_INPUT
),
6997 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT
),
6998 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT
),
6999 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
7000 VNID_HP_ASEL
, 1, HDA_OUTPUT
),
7005 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
7006 * because it doesn't set decibel levels for the DSP for capture.
7008 static const struct snd_kcontrol_new r3di_mixer
[] = {
7009 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT
),
7010 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK
, HDA_OUTPUT
),
7011 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT
),
7012 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT
),
7013 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT
),
7014 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT
),
7015 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT
),
7016 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT
),
7017 CA0132_CODEC_VOL("Capture Volume", VNID_MIC
, HDA_INPUT
),
7018 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC
, HDA_INPUT
),
7019 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT
),
7020 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT
),
7021 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
7022 VNID_HP_ASEL
, 1, HDA_OUTPUT
),
7026 static int ca0132_build_controls(struct hda_codec
*codec
)
7028 struct ca0132_spec
*spec
= codec
->spec
;
7029 int i
, num_fx
, num_sliders
;
7032 /* Add Mixer controls */
7033 for (i
= 0; i
< spec
->num_mixers
; i
++) {
7034 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
7038 /* Setup vmaster with surround followers for desktop ca0132 devices */
7039 if (ca0132_use_alt_functions(spec
)) {
7040 snd_hda_set_vmaster_tlv(codec
, spec
->dacs
[0], HDA_OUTPUT
,
7042 snd_hda_add_vmaster(codec
, "Master Playback Volume",
7043 spec
->tlv
, ca0132_alt_follower_pfxs
,
7045 err
= __snd_hda_add_vmaster(codec
, "Master Playback Switch",
7046 NULL
, ca0132_alt_follower_pfxs
,
7048 true, &spec
->vmaster_mute
.sw_kctl
);
7053 /* Add in and out effects controls.
7054 * VoiceFX, PE and CrystalVoice are added separately.
7056 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
7057 for (i
= 0; i
< num_fx
; i
++) {
7058 /* Desktop cards break if Echo Cancellation is used. */
7059 if (ca0132_use_pci_mmio(spec
)) {
7060 if (i
== (ECHO_CANCELLATION
- IN_EFFECT_START_NID
+
7065 err
= add_fx_switch(codec
, ca0132_effects
[i
].nid
,
7066 ca0132_effects
[i
].name
,
7067 ca0132_effects
[i
].direct
);
7072 * If codec has use_alt_controls set to true, add effect level sliders,
7073 * EQ presets, and Smart Volume presets. Also, change names to add FX
7074 * prefix, and change PlayEnhancement and CrystalVoice to match.
7076 if (ca0132_use_alt_controls(spec
)) {
7077 err
= ca0132_alt_add_svm_enum(codec
);
7081 err
= add_ca0132_alt_eq_presets(codec
);
7085 err
= add_fx_switch(codec
, PLAY_ENHANCEMENT
,
7090 err
= add_fx_switch(codec
, CRYSTAL_VOICE
,
7095 num_sliders
= OUT_EFFECTS_COUNT
- 1;
7096 for (i
= 0; i
< num_sliders
; i
++) {
7097 err
= ca0132_alt_add_effect_slider(codec
,
7098 ca0132_effects
[i
].nid
,
7099 ca0132_effects
[i
].name
,
7100 ca0132_effects
[i
].direct
);
7105 err
= ca0132_alt_add_effect_slider(codec
, XBASS_XOVER
,
7106 "X-Bass Crossover", EFX_DIR_OUT
);
7111 err
= add_fx_switch(codec
, PLAY_ENHANCEMENT
,
7112 "PlayEnhancement", 0);
7116 err
= add_fx_switch(codec
, CRYSTAL_VOICE
,
7121 err
= add_voicefx(codec
);
7126 * If the codec uses alt_functions, you need the enumerated controls
7127 * to select the new outputs and inputs, plus add the new mic boost
7130 if (ca0132_use_alt_functions(spec
)) {
7131 err
= ca0132_alt_add_output_enum(codec
);
7134 err
= ca0132_alt_add_speaker_channel_cfg_enum(codec
);
7137 err
= ca0132_alt_add_front_full_range_switch(codec
);
7140 err
= ca0132_alt_add_rear_full_range_switch(codec
);
7143 err
= ca0132_alt_add_bass_redirection_crossover(codec
);
7146 err
= ca0132_alt_add_bass_redirection_switch(codec
);
7149 err
= ca0132_alt_add_mic_boost_enum(codec
);
7153 * ZxR only has microphone input, there is no front panel
7154 * header on the card, and aux-in is handled by the DBPro board.
7156 if (ca0132_quirk(spec
) != QUIRK_ZXR
) {
7157 err
= ca0132_alt_add_input_enum(codec
);
7163 switch (ca0132_quirk(spec
)) {
7166 err
= ae5_add_headphone_gain_enum(codec
);
7169 err
= ae5_add_sound_filter_enum(codec
);
7174 err
= zxr_add_headphone_gain_switch(codec
);
7182 #ifdef ENABLE_TUNING_CONTROLS
7183 add_tuning_ctls(codec
);
7186 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
7190 if (spec
->dig_out
) {
7191 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->dig_out
,
7195 err
= snd_hda_create_spdif_share_sw(codec
, &spec
->multiout
);
7198 /* spec->multiout.share_spdif = 1; */
7202 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in
);
7207 if (ca0132_use_alt_functions(spec
))
7208 ca0132_alt_add_chmap_ctls(codec
);
7213 static int dbpro_build_controls(struct hda_codec
*codec
)
7215 struct ca0132_spec
*spec
= codec
->spec
;
7218 if (spec
->dig_out
) {
7219 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->dig_out
,
7226 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in
);
7237 static const struct hda_pcm_stream ca0132_pcm_analog_playback
= {
7242 .prepare
= ca0132_playback_pcm_prepare
,
7243 .cleanup
= ca0132_playback_pcm_cleanup
,
7244 .get_delay
= ca0132_playback_pcm_delay
,
7248 static const struct hda_pcm_stream ca0132_pcm_analog_capture
= {
7253 .prepare
= ca0132_capture_pcm_prepare
,
7254 .cleanup
= ca0132_capture_pcm_cleanup
,
7255 .get_delay
= ca0132_capture_pcm_delay
,
7259 static const struct hda_pcm_stream ca0132_pcm_digital_playback
= {
7264 .open
= ca0132_dig_playback_pcm_open
,
7265 .close
= ca0132_dig_playback_pcm_close
,
7266 .prepare
= ca0132_dig_playback_pcm_prepare
,
7267 .cleanup
= ca0132_dig_playback_pcm_cleanup
7271 static const struct hda_pcm_stream ca0132_pcm_digital_capture
= {
7277 static int ca0132_build_pcms(struct hda_codec
*codec
)
7279 struct ca0132_spec
*spec
= codec
->spec
;
7280 struct hda_pcm
*info
;
7282 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Analog");
7285 if (ca0132_use_alt_functions(spec
)) {
7286 info
->own_chmap
= true;
7287 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].chmap
7288 = ca0132_alt_chmaps
;
7290 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = ca0132_pcm_analog_playback
;
7291 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dacs
[0];
7292 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
7293 spec
->multiout
.max_channels
;
7294 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
7295 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
7296 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[0];
7298 /* With the DSP enabled, desktops don't use this ADC. */
7299 if (!ca0132_use_alt_functions(spec
)) {
7300 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Analog Mic-In2");
7303 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
7304 ca0132_pcm_analog_capture
;
7305 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
7306 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[1];
7309 info
= snd_hda_codec_pcm_new(codec
, "CA0132 What U Hear");
7312 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
7313 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
7314 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[2];
7316 if (!spec
->dig_out
&& !spec
->dig_in
)
7319 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Digital");
7322 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
7323 if (spec
->dig_out
) {
7324 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
7325 ca0132_pcm_digital_playback
;
7326 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dig_out
;
7329 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
7330 ca0132_pcm_digital_capture
;
7331 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in
;
7337 static int dbpro_build_pcms(struct hda_codec
*codec
)
7339 struct ca0132_spec
*spec
= codec
->spec
;
7340 struct hda_pcm
*info
;
7342 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Alt Analog");
7345 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
7346 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
7347 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[0];
7350 if (!spec
->dig_out
&& !spec
->dig_in
)
7353 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Digital");
7356 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
7357 if (spec
->dig_out
) {
7358 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
7359 ca0132_pcm_digital_playback
;
7360 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dig_out
;
7363 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
7364 ca0132_pcm_digital_capture
;
7365 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in
;
7371 static void init_output(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t dac
)
7374 snd_hda_set_pin_ctl(codec
, pin
, PIN_HP
);
7375 if (get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
)
7376 snd_hda_codec_write(codec
, pin
, 0,
7377 AC_VERB_SET_AMP_GAIN_MUTE
,
7380 if (dac
&& (get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
7381 snd_hda_codec_write(codec
, dac
, 0,
7382 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
);
7385 static void init_input(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t adc
)
7388 snd_hda_set_pin_ctl(codec
, pin
, PIN_VREF80
);
7389 if (get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
)
7390 snd_hda_codec_write(codec
, pin
, 0,
7391 AC_VERB_SET_AMP_GAIN_MUTE
,
7394 if (adc
&& (get_wcaps(codec
, adc
) & AC_WCAP_IN_AMP
)) {
7395 snd_hda_codec_write(codec
, adc
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
7398 /* init to 0 dB and unmute. */
7399 snd_hda_codec_amp_stereo(codec
, adc
, HDA_INPUT
, 0,
7400 HDA_AMP_VOLMASK
, 0x5a);
7401 snd_hda_codec_amp_stereo(codec
, adc
, HDA_INPUT
, 0,
7406 static void refresh_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
, int dir
)
7410 caps
= snd_hda_param_read(codec
, nid
, dir
== HDA_OUTPUT
?
7411 AC_PAR_AMP_OUT_CAP
: AC_PAR_AMP_IN_CAP
);
7412 snd_hda_override_amp_caps(codec
, nid
, dir
, caps
);
7416 * Switch between Digital built-in mic and analog mic.
7418 static void ca0132_set_dmic(struct hda_codec
*codec
, int enable
)
7420 struct ca0132_spec
*spec
= codec
->spec
;
7423 unsigned int oldval
;
7425 codec_dbg(codec
, "ca0132_set_dmic: enable=%d\n", enable
);
7427 oldval
= stop_mic1(codec
);
7428 ca0132_set_vipsource(codec
, 0);
7430 /* set DMic input as 2-ch */
7432 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
7434 val
= spec
->dmic_ctl
;
7436 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
7437 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
7439 if (!(spec
->dmic_ctl
& 0x20))
7440 chipio_set_control_flag(codec
, CONTROL_FLAG_DMIC
, 1);
7442 /* set AMic input as mono */
7444 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
7446 val
= spec
->dmic_ctl
;
7447 /* clear bit7 and bit5 to disable dmic */
7449 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
7450 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
7452 if (!(spec
->dmic_ctl
& 0x20))
7453 chipio_set_control_flag(codec
, CONTROL_FLAG_DMIC
, 0);
7455 ca0132_set_vipsource(codec
, 1);
7456 resume_mic1(codec
, oldval
);
7460 * Initialization for Digital Mic.
7462 static void ca0132_init_dmic(struct hda_codec
*codec
)
7464 struct ca0132_spec
*spec
= codec
->spec
;
7467 /* Setup Digital Mic here, but don't enable.
7468 * Enable based on jack detect.
7471 /* MCLK uses MPIO1, set to enable.
7472 * Bit 2-0: MPIO select
7473 * Bit 3: set to disable
7477 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
7478 VENDOR_CHIPIO_DMIC_MCLK_SET
, val
);
7480 /* Data1 uses MPIO3. Data2 not use
7481 * Bit 2-0: Data1 MPIO select
7482 * Bit 3: set disable Data1
7483 * Bit 6-4: Data2 MPIO select
7484 * Bit 7: set disable Data2
7487 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
7488 VENDOR_CHIPIO_DMIC_PIN_SET
, val
);
7490 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
7491 * Bit 3-0: Channel mask
7492 * Bit 4: set for 48KHz, clear for 32KHz
7494 * Bit 6: set to select Data2, clear for Data1
7495 * Bit 7: set to enable DMic, clear for AMic
7497 if (ca0132_quirk(spec
) == QUIRK_ALIENWARE_M17XR4
)
7501 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
7502 spec
->dmic_ctl
= val
;
7503 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
7504 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
7508 * Initialization for Analog Mic 2
7510 static void ca0132_init_analog_mic2(struct hda_codec
*codec
)
7512 struct ca0132_spec
*spec
= codec
->spec
;
7514 mutex_lock(&spec
->chipio_mutex
);
7516 chipio_8051_write_exram_no_mutex(codec
, 0x1920, 0x00);
7517 chipio_8051_write_exram_no_mutex(codec
, 0x192d, 0x00);
7519 mutex_unlock(&spec
->chipio_mutex
);
7522 static void ca0132_refresh_widget_caps(struct hda_codec
*codec
)
7524 struct ca0132_spec
*spec
= codec
->spec
;
7527 codec_dbg(codec
, "ca0132_refresh_widget_caps.\n");
7528 snd_hda_codec_update_widgets(codec
);
7530 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++)
7531 refresh_amp_caps(codec
, spec
->dacs
[i
], HDA_OUTPUT
);
7533 for (i
= 0; i
< spec
->num_outputs
; i
++)
7534 refresh_amp_caps(codec
, spec
->out_pins
[i
], HDA_OUTPUT
);
7536 for (i
= 0; i
< spec
->num_inputs
; i
++) {
7537 refresh_amp_caps(codec
, spec
->adcs
[i
], HDA_INPUT
);
7538 refresh_amp_caps(codec
, spec
->input_pins
[i
], HDA_INPUT
);
7543 /* If there is an active channel for some reason, find it and free it. */
7544 static void ca0132_alt_free_active_dma_channels(struct hda_codec
*codec
)
7546 unsigned int i
, tmp
;
7549 /* Read active DSPDMAC channel register. */
7550 status
= chipio_read(codec
, DSPDMAC_CHNLSTART_MODULE_OFFSET
, &tmp
);
7552 /* AND against 0xfff to get the active channel bits. */
7555 /* If there are no active channels, nothing to free. */
7559 codec_dbg(codec
, "%s: Failed to read active DSP DMA channel register.\n",
7565 * Check each DSP DMA channel for activity, and if the channel is
7568 for (i
= 0; i
< DSPDMAC_DMA_CFG_CHANNEL_COUNT
; i
++) {
7569 if (dsp_is_dma_active(codec
, i
)) {
7570 status
= dspio_free_dma_chan(codec
, i
);
7572 codec_dbg(codec
, "%s: Failed to free active DSP DMA channel %d.\n",
7579 * In the case of CT_EXTENSIONS_ENABLE being set to 1, and the DSP being in
7580 * use, audio is no longer routed directly to the DAC/ADC from the HDA stream.
7581 * Instead, audio is now routed through the DSP's DMA controllers, which
7582 * the DSP is tasked with setting up itself. Through debugging, it seems the
7583 * cause of most of the no-audio on startup issues were due to improperly
7584 * configured DSP DMA channels.
7586 * Normally, the DSP configures these the first time an HDA audio stream is
7587 * started post DSP firmware download. That is why creating a 'dummy' stream
7588 * worked in fixing the audio in some cases. This works most of the time, but
7589 * sometimes if a stream is started/stopped before the DSP can setup the DMA
7590 * configuration registers, it ends up in a broken state. Issues can also
7591 * arise if streams are started in an unusual order, i.e the audio output dma
7592 * channel being sandwiched between the mic1 and mic2 dma channels.
7594 * The solution to this is to make sure that the DSP has no DMA channels
7595 * in use post DSP firmware download, and then to manually start each default
7596 * DSP stream that uses the DMA channels. These are 0x0c, the audio output
7597 * stream, 0x03, analog mic 1, and 0x04, analog mic 2.
7599 static void ca0132_alt_start_dsp_audio_streams(struct hda_codec
*codec
)
7601 const unsigned int dsp_dma_stream_ids
[] = { 0x0c, 0x03, 0x04 };
7602 struct ca0132_spec
*spec
= codec
->spec
;
7603 unsigned int i
, tmp
;
7606 * Check if any of the default streams are active, and if they are,
7609 mutex_lock(&spec
->chipio_mutex
);
7611 for (i
= 0; i
< ARRAY_SIZE(dsp_dma_stream_ids
); i
++) {
7612 chipio_get_stream_control(codec
, dsp_dma_stream_ids
[i
], &tmp
);
7615 chipio_set_stream_control(codec
,
7616 dsp_dma_stream_ids
[i
], 0);
7620 mutex_unlock(&spec
->chipio_mutex
);
7623 * If all DSP streams are inactive, there should be no active DSP DMA
7624 * channels. Check and make sure this is the case, and if it isn't,
7625 * free any active channels.
7627 ca0132_alt_free_active_dma_channels(codec
);
7629 mutex_lock(&spec
->chipio_mutex
);
7631 /* Make sure stream 0x0c is six channels. */
7632 chipio_set_stream_channels(codec
, 0x0c, 6);
7634 for (i
= 0; i
< ARRAY_SIZE(dsp_dma_stream_ids
); i
++) {
7635 chipio_set_stream_control(codec
,
7636 dsp_dma_stream_ids
[i
], 1);
7638 /* Give the DSP some time to setup the DMA channel. */
7642 mutex_unlock(&spec
->chipio_mutex
);
7646 * The region of ChipIO memory from 0x190000-0x1903fc is a sort of 'audio
7647 * router', where each entry represents a 48khz audio channel, with a format
7648 * of an 8-bit destination, an 8-bit source, and an unknown 2-bit number
7649 * value. The 2-bit number value is seemingly 0 if inactive, 1 if active,
7650 * and 3 if it's using Sample Rate Converter ports.
7653 * In this case, f8 is the destination, and c0 is the source. The number value
7655 * This region of memory is normally managed internally by the 8051, where
7656 * the region of exram memory from 0x1477-0x1575 has each byte represent an
7657 * entry within the 0x190000 range, and when a range of entries is in use, the
7658 * ending value is overwritten with 0xff.
7659 * 0x1578 in exram is a table of 0x25 entries, corresponding to the ChipIO
7660 * streamID's, where each entry is a starting 0x190000 port offset.
7661 * 0x159d in exram is the same as 0x1578, except it contains the ending port
7662 * offset for the corresponding streamID.
7664 * On certain cards, such as the SBZ/ZxR/AE7, these are originally setup by
7665 * the 8051, then manually overwritten to remap the ports to work with the
7668 * Currently known portID's:
7669 * 0x00-0x1f: HDA audio stream input/output ports.
7670 * 0x80-0xbf: Sample rate converter input/outputs. Only valid ports seem to
7671 * have the lower-nibble set to 0x1, 0x2, and 0x9.
7672 * 0xc0-0xdf: DSP DMA input/output ports. Dynamically assigned.
7673 * 0xe0-0xff: DAC/ADC audio input/output ports.
7675 * Currently known streamID's:
7676 * 0x03: Mic1 ADC to DSP.
7677 * 0x04: Mic2 ADC to DSP.
7678 * 0x05: HDA node 0x02 audio stream to DSP.
7679 * 0x0f: DSP Mic exit to HDA node 0x07.
7680 * 0x0c: DSP processed audio to DACs.
7681 * 0x14: DAC0, front L/R.
7683 * It is possible to route the HDA audio streams directly to the DAC and
7684 * bypass the DSP entirely, with the only downside being that since the DSP
7685 * does volume control, the only volume control you'll get is through PCM on
7686 * the PC side, in the same way volume is handled for optical out. This may be
7687 * useful for debugging.
7689 static void chipio_remap_stream(struct hda_codec
*codec
,
7690 const struct chipio_stream_remap_data
*remap_data
)
7692 unsigned int i
, stream_offset
;
7694 /* Get the starting port for the stream to be remapped. */
7695 chipio_8051_read_exram(codec
, 0x1578 + remap_data
->stream_id
,
7699 * Check if the stream's port value is 0xff, because the 8051 may not
7700 * have gotten around to setting up the stream yet. Wait until it's
7701 * setup to remap it's ports.
7703 if (stream_offset
== 0xff) {
7704 for (i
= 0; i
< 5; i
++) {
7707 chipio_8051_read_exram(codec
, 0x1578 + remap_data
->stream_id
,
7710 if (stream_offset
!= 0xff)
7715 if (stream_offset
== 0xff) {
7716 codec_info(codec
, "%s: Stream 0x%02x ports aren't allocated, remap failed!\n",
7717 __func__
, remap_data
->stream_id
);
7721 /* Offset isn't in bytes, its in 32-bit words, so multiply it by 4. */
7722 stream_offset
*= 0x04;
7723 stream_offset
+= 0x190000;
7725 for (i
= 0; i
< remap_data
->count
; i
++) {
7726 chipio_write_no_mutex(codec
,
7727 stream_offset
+ remap_data
->offset
[i
],
7728 remap_data
->value
[i
]);
7731 /* Update stream map configuration. */
7732 chipio_write_no_mutex(codec
, 0x19042c, 0x00000001);
7736 * Default speaker tuning values setup for alternative codecs.
7738 static const unsigned int sbz_default_delay_values
[] = {
7739 /* Non-zero values are floating point 0.000198. */
7740 0x394f9e38, 0x394f9e38, 0x00000000, 0x00000000, 0x00000000, 0x00000000
7743 static const unsigned int zxr_default_delay_values
[] = {
7744 /* Non-zero values are floating point 0.000220. */
7745 0x00000000, 0x00000000, 0x3966afcd, 0x3966afcd, 0x3966afcd, 0x3966afcd
7748 static const unsigned int ae5_default_delay_values
[] = {
7749 /* Non-zero values are floating point 0.000100. */
7750 0x00000000, 0x00000000, 0x38d1b717, 0x38d1b717, 0x38d1b717, 0x38d1b717
7754 * If we never change these, probably only need them on initialization.
7756 static void ca0132_alt_init_speaker_tuning(struct hda_codec
*codec
)
7758 struct ca0132_spec
*spec
= codec
->spec
;
7759 unsigned int i
, tmp
, start_req
, end_req
;
7760 const unsigned int *values
;
7762 switch (ca0132_quirk(spec
)) {
7764 values
= sbz_default_delay_values
;
7767 values
= zxr_default_delay_values
;
7771 values
= ae5_default_delay_values
;
7774 values
= sbz_default_delay_values
;
7779 dspio_set_uint_param(codec
, 0x96, SPEAKER_TUNING_ENABLE_CENTER_EQ
, tmp
);
7781 start_req
= SPEAKER_TUNING_FRONT_LEFT_VOL_LEVEL
;
7782 end_req
= SPEAKER_TUNING_REAR_RIGHT_VOL_LEVEL
;
7783 for (i
= start_req
; i
< end_req
+ 1; i
++)
7784 dspio_set_uint_param(codec
, 0x96, i
, tmp
);
7786 start_req
= SPEAKER_TUNING_FRONT_LEFT_INVERT
;
7787 end_req
= SPEAKER_TUNING_REAR_RIGHT_INVERT
;
7788 for (i
= start_req
; i
< end_req
+ 1; i
++)
7789 dspio_set_uint_param(codec
, 0x96, i
, tmp
);
7792 for (i
= 0; i
< 6; i
++)
7793 dspio_set_uint_param(codec
, 0x96,
7794 SPEAKER_TUNING_FRONT_LEFT_DELAY
+ i
, values
[i
]);
7798 * Initialize mic for non-chromebook ca0132 implementations.
7800 static void ca0132_alt_init_analog_mics(struct hda_codec
*codec
)
7802 struct ca0132_spec
*spec
= codec
->spec
;
7806 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
7807 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
7808 if (ca0132_quirk(spec
) == QUIRK_R3DI
) {
7809 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
7813 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
7815 /* Mic 2 setup (not present on desktop cards) */
7816 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN2
, SR_96_000
);
7817 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT2
, SR_96_000
);
7818 if (ca0132_quirk(spec
) == QUIRK_R3DI
)
7819 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
7821 dspio_set_uint_param(codec
, 0x80, 0x01, tmp
);
7825 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
7826 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
7827 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
7828 * having an updated DAC, which changes the destination to that DAC.
7830 static void sbz_connect_streams(struct hda_codec
*codec
)
7832 struct ca0132_spec
*spec
= codec
->spec
;
7834 mutex_lock(&spec
->chipio_mutex
);
7836 codec_dbg(codec
, "Connect Streams entered, mutex locked and loaded.\n");
7838 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
7839 chipio_write_no_mutex(codec
, 0x18a020, 0x00000043);
7841 /* Setup stream 0x14 with it's source and destination points */
7842 chipio_set_stream_source_dest(codec
, 0x14, 0x48, 0x91);
7843 chipio_set_conn_rate_no_mutex(codec
, 0x48, SR_96_000
);
7844 chipio_set_conn_rate_no_mutex(codec
, 0x91, SR_96_000
);
7845 chipio_set_stream_channels(codec
, 0x14, 2);
7846 chipio_set_stream_control(codec
, 0x14, 1);
7848 codec_dbg(codec
, "Connect Streams exited, mutex released.\n");
7850 mutex_unlock(&spec
->chipio_mutex
);
7854 * Write data through ChipIO to setup proper stream destinations.
7855 * Not sure how it exactly works, but it seems to direct data
7856 * to different destinations. Example is f8 to c0, e0 to c0.
7857 * All I know is, if you don't set these, you get no sound.
7859 static void sbz_chipio_startup_data(struct hda_codec
*codec
)
7861 const struct chipio_stream_remap_data
*dsp_out_remap_data
;
7862 struct ca0132_spec
*spec
= codec
->spec
;
7864 mutex_lock(&spec
->chipio_mutex
);
7865 codec_dbg(codec
, "Startup Data entered, mutex locked and loaded.\n");
7867 /* Remap DAC0's output ports. */
7868 chipio_remap_stream(codec
, &stream_remap_data
[0]);
7870 /* Remap DSP audio output stream ports. */
7871 switch (ca0132_quirk(spec
)) {
7873 dsp_out_remap_data
= &stream_remap_data
[1];
7877 dsp_out_remap_data
= &stream_remap_data
[2];
7881 dsp_out_remap_data
= NULL
;
7885 if (dsp_out_remap_data
)
7886 chipio_remap_stream(codec
, dsp_out_remap_data
);
7888 codec_dbg(codec
, "Startup Data exited, mutex released.\n");
7889 mutex_unlock(&spec
->chipio_mutex
);
7892 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec
*codec
)
7894 struct ca0132_spec
*spec
= codec
->spec
;
7897 chipio_set_stream_control(codec
, 0x03, 0);
7898 chipio_set_stream_control(codec
, 0x04, 0);
7900 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
7901 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
7904 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
7906 chipio_set_stream_control(codec
, 0x03, 1);
7907 chipio_set_stream_control(codec
, 0x04, 1);
7909 switch (ca0132_quirk(spec
)) {
7911 chipio_write(codec
, 0x18b098, 0x0000000c);
7912 chipio_write(codec
, 0x18b09C, 0x0000000c);
7915 chipio_write(codec
, 0x18b098, 0x0000000c);
7916 chipio_write(codec
, 0x18b09c, 0x0000004c);
7923 static void ae5_post_dsp_register_set(struct hda_codec
*codec
)
7925 struct ca0132_spec
*spec
= codec
->spec
;
7927 chipio_8051_write_direct(codec
, 0x93, 0x10);
7928 chipio_8051_write_pll_pmu(codec
, 0x44, 0xc2);
7930 writeb(0xff, spec
->mem_base
+ 0x304);
7931 writeb(0xff, spec
->mem_base
+ 0x304);
7932 writeb(0xff, spec
->mem_base
+ 0x304);
7933 writeb(0xff, spec
->mem_base
+ 0x304);
7934 writeb(0x00, spec
->mem_base
+ 0x100);
7935 writeb(0xff, spec
->mem_base
+ 0x304);
7936 writeb(0x00, spec
->mem_base
+ 0x100);
7937 writeb(0xff, spec
->mem_base
+ 0x304);
7938 writeb(0x00, spec
->mem_base
+ 0x100);
7939 writeb(0xff, spec
->mem_base
+ 0x304);
7940 writeb(0x00, spec
->mem_base
+ 0x100);
7941 writeb(0xff, spec
->mem_base
+ 0x304);
7943 ca0113_mmio_command_set(codec
, 0x30, 0x2b, 0x3f);
7944 ca0113_mmio_command_set(codec
, 0x30, 0x2d, 0x3f);
7945 ca0113_mmio_command_set(codec
, 0x48, 0x07, 0x83);
7948 static void ae5_post_dsp_param_setup(struct hda_codec
*codec
)
7951 * Param3 in the 8051's memory is represented by the ascii string 'mch'
7952 * which seems to be 'multichannel'. This is also mentioned in the
7953 * AE-5's registry values in Windows.
7955 chipio_set_control_param(codec
, 3, 0);
7957 * I believe ASI is 'audio serial interface' and that it's used to
7958 * change colors on the external LED strip connected to the AE-5.
7960 chipio_set_control_flag(codec
, CONTROL_FLAG_ASI_96KHZ
, 1);
7962 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, 0x724, 0x83);
7963 chipio_set_control_param(codec
, CONTROL_PARAM_ASI
, 0);
7965 chipio_8051_write_exram(codec
, 0xfa92, 0x22);
7968 static void ae5_post_dsp_pll_setup(struct hda_codec
*codec
)
7970 chipio_8051_write_pll_pmu(codec
, 0x41, 0xc8);
7971 chipio_8051_write_pll_pmu(codec
, 0x45, 0xcc);
7972 chipio_8051_write_pll_pmu(codec
, 0x40, 0xcb);
7973 chipio_8051_write_pll_pmu(codec
, 0x43, 0xc7);
7974 chipio_8051_write_pll_pmu(codec
, 0x51, 0x8d);
7977 static void ae5_post_dsp_stream_setup(struct hda_codec
*codec
)
7979 struct ca0132_spec
*spec
= codec
->spec
;
7981 mutex_lock(&spec
->chipio_mutex
);
7983 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, 0x725, 0x81);
7985 chipio_set_conn_rate_no_mutex(codec
, 0x70, SR_96_000
);
7987 chipio_set_stream_source_dest(codec
, 0x5, 0x43, 0x0);
7989 chipio_set_stream_source_dest(codec
, 0x18, 0x9, 0xd0);
7990 chipio_set_conn_rate_no_mutex(codec
, 0xd0, SR_96_000
);
7991 chipio_set_stream_channels(codec
, 0x18, 6);
7992 chipio_set_stream_control(codec
, 0x18, 1);
7994 chipio_set_control_param_no_mutex(codec
, CONTROL_PARAM_ASI
, 4);
7996 chipio_8051_write_pll_pmu_no_mutex(codec
, 0x43, 0xc7);
7998 ca0113_mmio_command_set(codec
, 0x48, 0x01, 0x80);
8000 mutex_unlock(&spec
->chipio_mutex
);
8003 static void ae5_post_dsp_startup_data(struct hda_codec
*codec
)
8005 struct ca0132_spec
*spec
= codec
->spec
;
8007 mutex_lock(&spec
->chipio_mutex
);
8009 chipio_write_no_mutex(codec
, 0x189000, 0x0001f101);
8010 chipio_write_no_mutex(codec
, 0x189004, 0x0001f101);
8011 chipio_write_no_mutex(codec
, 0x189024, 0x00014004);
8012 chipio_write_no_mutex(codec
, 0x189028, 0x0002000f);
8014 ca0113_mmio_command_set(codec
, 0x48, 0x0a, 0x05);
8015 chipio_set_control_param_no_mutex(codec
, CONTROL_PARAM_ASI
, 7);
8016 ca0113_mmio_command_set(codec
, 0x48, 0x0b, 0x12);
8017 ca0113_mmio_command_set(codec
, 0x48, 0x04, 0x00);
8018 ca0113_mmio_command_set(codec
, 0x48, 0x06, 0x48);
8019 ca0113_mmio_command_set(codec
, 0x48, 0x0a, 0x05);
8020 ca0113_mmio_command_set(codec
, 0x48, 0x07, 0x83);
8021 ca0113_mmio_command_set(codec
, 0x48, 0x0f, 0x00);
8022 ca0113_mmio_command_set(codec
, 0x48, 0x10, 0x00);
8023 ca0113_mmio_gpio_set(codec
, 0, true);
8024 ca0113_mmio_gpio_set(codec
, 1, true);
8025 ca0113_mmio_command_set(codec
, 0x48, 0x07, 0x80);
8027 chipio_write_no_mutex(codec
, 0x18b03c, 0x00000012);
8029 ca0113_mmio_command_set(codec
, 0x48, 0x0f, 0x00);
8030 ca0113_mmio_command_set(codec
, 0x48, 0x10, 0x00);
8032 mutex_unlock(&spec
->chipio_mutex
);
8035 static void ae7_post_dsp_setup_ports(struct hda_codec
*codec
)
8037 struct ca0132_spec
*spec
= codec
->spec
;
8039 mutex_lock(&spec
->chipio_mutex
);
8041 /* Seems to share the same port remapping as the SBZ. */
8042 chipio_remap_stream(codec
, &stream_remap_data
[1]);
8044 ca0113_mmio_command_set(codec
, 0x30, 0x30, 0x00);
8045 ca0113_mmio_command_set(codec
, 0x48, 0x0d, 0x40);
8046 ca0113_mmio_command_set(codec
, 0x48, 0x17, 0x00);
8047 ca0113_mmio_command_set(codec
, 0x48, 0x19, 0x00);
8048 ca0113_mmio_command_set(codec
, 0x48, 0x11, 0xff);
8049 ca0113_mmio_command_set(codec
, 0x48, 0x12, 0xff);
8050 ca0113_mmio_command_set(codec
, 0x48, 0x13, 0xff);
8051 ca0113_mmio_command_set(codec
, 0x48, 0x14, 0x7f);
8053 mutex_unlock(&spec
->chipio_mutex
);
8056 static void ae7_post_dsp_asi_stream_setup(struct hda_codec
*codec
)
8058 struct ca0132_spec
*spec
= codec
->spec
;
8060 mutex_lock(&spec
->chipio_mutex
);
8062 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, 0x725, 0x81);
8063 ca0113_mmio_command_set(codec
, 0x30, 0x2b, 0x00);
8065 chipio_set_conn_rate_no_mutex(codec
, 0x70, SR_96_000
);
8067 chipio_set_stream_source_dest(codec
, 0x05, 0x43, 0x00);
8068 chipio_set_stream_source_dest(codec
, 0x18, 0x09, 0xd0);
8070 chipio_set_conn_rate_no_mutex(codec
, 0xd0, SR_96_000
);
8071 chipio_set_stream_channels(codec
, 0x18, 6);
8072 chipio_set_stream_control(codec
, 0x18, 1);
8074 chipio_set_control_param_no_mutex(codec
, CONTROL_PARAM_ASI
, 4);
8076 mutex_unlock(&spec
->chipio_mutex
);
8079 static void ae7_post_dsp_pll_setup(struct hda_codec
*codec
)
8081 static const unsigned int addr
[] = {
8082 0x41, 0x45, 0x40, 0x43, 0x51
8084 static const unsigned int data
[] = {
8085 0xc8, 0xcc, 0xcb, 0xc7, 0x8d
8089 for (i
= 0; i
< ARRAY_SIZE(addr
); i
++)
8090 chipio_8051_write_pll_pmu_no_mutex(codec
, addr
[i
], data
[i
]);
8093 static void ae7_post_dsp_asi_setup_ports(struct hda_codec
*codec
)
8095 struct ca0132_spec
*spec
= codec
->spec
;
8096 static const unsigned int target
[] = {
8097 0x0b, 0x04, 0x06, 0x0a, 0x0c, 0x11, 0x12, 0x13, 0x14
8099 static const unsigned int data
[] = {
8100 0x12, 0x00, 0x48, 0x05, 0x5f, 0xff, 0xff, 0xff, 0x7f
8104 mutex_lock(&spec
->chipio_mutex
);
8106 chipio_8051_write_pll_pmu_no_mutex(codec
, 0x43, 0xc7);
8108 chipio_write_no_mutex(codec
, 0x189000, 0x0001f101);
8109 chipio_write_no_mutex(codec
, 0x189004, 0x0001f101);
8110 chipio_write_no_mutex(codec
, 0x189024, 0x00014004);
8111 chipio_write_no_mutex(codec
, 0x189028, 0x0002000f);
8113 ae7_post_dsp_pll_setup(codec
);
8114 chipio_set_control_param_no_mutex(codec
, CONTROL_PARAM_ASI
, 7);
8116 for (i
= 0; i
< ARRAY_SIZE(target
); i
++)
8117 ca0113_mmio_command_set(codec
, 0x48, target
[i
], data
[i
]);
8119 ca0113_mmio_command_set_type2(codec
, 0x48, 0x07, 0x83);
8120 ca0113_mmio_command_set(codec
, 0x48, 0x0f, 0x00);
8121 ca0113_mmio_command_set(codec
, 0x48, 0x10, 0x00);
8123 chipio_set_stream_source_dest(codec
, 0x21, 0x64, 0x56);
8124 chipio_set_stream_channels(codec
, 0x21, 2);
8125 chipio_set_conn_rate_no_mutex(codec
, 0x56, SR_8_000
);
8127 chipio_set_control_param_no_mutex(codec
, CONTROL_PARAM_NODE_ID
, 0x09);
8129 * In the 8051's memory, this param is referred to as 'n2sid', which I
8130 * believe is 'node to streamID'. It seems to be a way to assign a
8131 * stream to a given HDA node.
8133 chipio_set_control_param_no_mutex(codec
, 0x20, 0x21);
8135 chipio_write_no_mutex(codec
, 0x18b038, 0x00000088);
8138 * Now, at this point on Windows, an actual stream is setup and
8139 * seemingly sends data to the HDA node 0x09, which is the digital
8140 * audio input node. This is left out here, because obviously I don't
8141 * know what data is being sent. Interestingly, the AE-5 seems to go
8142 * through the motions of getting here and never actually takes this
8143 * step, but the AE-7 does.
8146 ca0113_mmio_gpio_set(codec
, 0, 1);
8147 ca0113_mmio_gpio_set(codec
, 1, 1);
8149 ca0113_mmio_command_set_type2(codec
, 0x48, 0x07, 0x83);
8150 chipio_write_no_mutex(codec
, 0x18b03c, 0x00000000);
8151 ca0113_mmio_command_set(codec
, 0x48, 0x0f, 0x00);
8152 ca0113_mmio_command_set(codec
, 0x48, 0x10, 0x00);
8154 chipio_set_stream_source_dest(codec
, 0x05, 0x43, 0x00);
8155 chipio_set_stream_source_dest(codec
, 0x18, 0x09, 0xd0);
8157 chipio_set_conn_rate_no_mutex(codec
, 0xd0, SR_96_000
);
8158 chipio_set_stream_channels(codec
, 0x18, 6);
8161 * Runs again, this has been repeated a few times, but I'm just
8162 * following what the Windows driver does.
8164 ae7_post_dsp_pll_setup(codec
);
8165 chipio_set_control_param_no_mutex(codec
, CONTROL_PARAM_ASI
, 7);
8167 mutex_unlock(&spec
->chipio_mutex
);
8171 * The Windows driver has commands that seem to setup ASI, which I believe to
8172 * be some sort of audio serial interface. My current speculation is that it's
8173 * related to communicating with the new DAC.
8175 static void ae7_post_dsp_asi_setup(struct hda_codec
*codec
)
8177 chipio_8051_write_direct(codec
, 0x93, 0x10);
8179 chipio_8051_write_pll_pmu(codec
, 0x44, 0xc2);
8181 ca0113_mmio_command_set_type2(codec
, 0x48, 0x07, 0x83);
8182 ca0113_mmio_command_set(codec
, 0x30, 0x2e, 0x3f);
8184 chipio_set_control_param(codec
, 3, 3);
8185 chipio_set_control_flag(codec
, CONTROL_FLAG_ASI_96KHZ
, 1);
8187 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, 0x724, 0x83);
8188 chipio_set_control_param(codec
, CONTROL_PARAM_ASI
, 0);
8189 snd_hda_codec_write(codec
, 0x17, 0, 0x794, 0x00);
8191 chipio_8051_write_exram(codec
, 0xfa92, 0x22);
8193 ae7_post_dsp_pll_setup(codec
);
8194 ae7_post_dsp_asi_stream_setup(codec
);
8196 chipio_8051_write_pll_pmu(codec
, 0x43, 0xc7);
8198 ae7_post_dsp_asi_setup_ports(codec
);
8202 * Setup default parameters for DSP
8204 static void ca0132_setup_defaults(struct hda_codec
*codec
)
8206 struct ca0132_spec
*spec
= codec
->spec
;
8211 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
8214 /* out, in effects + voicefx */
8215 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
8216 for (idx
= 0; idx
< num_fx
; idx
++) {
8217 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
8218 dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
8219 ca0132_effects
[idx
].reqs
[i
],
8220 ca0132_effects
[idx
].def_vals
[i
]);
8224 /*remove DSP headroom*/
8226 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
8228 /*set speaker EQ bypass attenuation*/
8229 dspio_set_uint_param(codec
, 0x8f, 0x01, tmp
);
8231 /* set AMic1 and AMic2 as mono mic */
8233 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
8234 dspio_set_uint_param(codec
, 0x80, 0x01, tmp
);
8236 /* set AMic1 as CrystalVoice input */
8238 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
8240 /* set WUH source */
8242 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
8246 * Setup default parameters for Recon3D/Recon3Di DSP.
8249 static void r3d_setup_defaults(struct hda_codec
*codec
)
8251 struct ca0132_spec
*spec
= codec
->spec
;
8256 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
8259 ca0132_alt_init_analog_mics(codec
);
8260 ca0132_alt_start_dsp_audio_streams(codec
);
8262 /*remove DSP headroom*/
8264 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
8266 /* set WUH source */
8268 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
8269 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
8271 /* Set speaker source? */
8272 dspio_set_uint_param(codec
, 0x32, 0x00, tmp
);
8274 if (ca0132_quirk(spec
) == QUIRK_R3DI
)
8275 r3di_gpio_dsp_status_set(codec
, R3DI_DSP_DOWNLOADED
);
8277 /* Disable mute on Center/LFE. */
8278 if (ca0132_quirk(spec
) == QUIRK_R3D
) {
8279 ca0113_mmio_gpio_set(codec
, 2, false);
8280 ca0113_mmio_gpio_set(codec
, 4, true);
8283 /* Setup effect defaults */
8284 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
8285 for (idx
= 0; idx
< num_fx
; idx
++) {
8286 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
8287 dspio_set_uint_param(codec
,
8288 ca0132_effects
[idx
].mid
,
8289 ca0132_effects
[idx
].reqs
[i
],
8290 ca0132_effects
[idx
].def_vals
[i
]);
8296 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
8297 * than the Chromebook setup.
8299 static void sbz_setup_defaults(struct hda_codec
*codec
)
8301 struct ca0132_spec
*spec
= codec
->spec
;
8306 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
8309 ca0132_alt_init_analog_mics(codec
);
8310 ca0132_alt_start_dsp_audio_streams(codec
);
8311 sbz_connect_streams(codec
);
8312 sbz_chipio_startup_data(codec
);
8315 * Sets internal input loopback to off, used to have a switch to
8316 * enable input loopback, but turned out to be way too buggy.
8319 dspio_set_uint_param(codec
, 0x37, 0x08, tmp
);
8320 dspio_set_uint_param(codec
, 0x37, 0x10, tmp
);
8322 /*remove DSP headroom*/
8324 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
8326 /* set WUH source */
8328 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
8329 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
8331 /* Set speaker source? */
8332 dspio_set_uint_param(codec
, 0x32, 0x00, tmp
);
8334 ca0132_alt_dsp_initial_mic_setup(codec
);
8336 /* out, in effects + voicefx */
8337 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
8338 for (idx
= 0; idx
< num_fx
; idx
++) {
8339 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
8340 dspio_set_uint_param(codec
,
8341 ca0132_effects
[idx
].mid
,
8342 ca0132_effects
[idx
].reqs
[i
],
8343 ca0132_effects
[idx
].def_vals
[i
]);
8347 ca0132_alt_init_speaker_tuning(codec
);
8351 * Setup default parameters for the Sound BlasterX AE-5 DSP.
8353 static void ae5_setup_defaults(struct hda_codec
*codec
)
8355 struct ca0132_spec
*spec
= codec
->spec
;
8360 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
8363 ca0132_alt_init_analog_mics(codec
);
8364 ca0132_alt_start_dsp_audio_streams(codec
);
8366 /* New, unknown SCP req's */
8368 dspio_set_uint_param(codec
, 0x96, 0x29, tmp
);
8369 dspio_set_uint_param(codec
, 0x96, 0x2a, tmp
);
8370 dspio_set_uint_param(codec
, 0x80, 0x0d, tmp
);
8371 dspio_set_uint_param(codec
, 0x80, 0x0e, tmp
);
8373 ca0113_mmio_command_set(codec
, 0x30, 0x2e, 0x3f);
8374 ca0113_mmio_gpio_set(codec
, 0, false);
8375 ca0113_mmio_command_set(codec
, 0x30, 0x28, 0x00);
8377 /* Internal loopback off */
8379 dspio_set_uint_param(codec
, 0x37, 0x08, tmp
);
8380 dspio_set_uint_param(codec
, 0x37, 0x10, tmp
);
8382 /*remove DSP headroom*/
8384 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
8386 /* set WUH source */
8388 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
8389 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
8391 /* Set speaker source? */
8392 dspio_set_uint_param(codec
, 0x32, 0x00, tmp
);
8394 ca0132_alt_dsp_initial_mic_setup(codec
);
8395 ae5_post_dsp_register_set(codec
);
8396 ae5_post_dsp_param_setup(codec
);
8397 ae5_post_dsp_pll_setup(codec
);
8398 ae5_post_dsp_stream_setup(codec
);
8399 ae5_post_dsp_startup_data(codec
);
8401 /* out, in effects + voicefx */
8402 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
8403 for (idx
= 0; idx
< num_fx
; idx
++) {
8404 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
8405 dspio_set_uint_param(codec
,
8406 ca0132_effects
[idx
].mid
,
8407 ca0132_effects
[idx
].reqs
[i
],
8408 ca0132_effects
[idx
].def_vals
[i
]);
8412 ca0132_alt_init_speaker_tuning(codec
);
8416 * Setup default parameters for the Sound Blaster AE-7 DSP.
8418 static void ae7_setup_defaults(struct hda_codec
*codec
)
8420 struct ca0132_spec
*spec
= codec
->spec
;
8425 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
8428 ca0132_alt_init_analog_mics(codec
);
8429 ca0132_alt_start_dsp_audio_streams(codec
);
8430 ae7_post_dsp_setup_ports(codec
);
8433 dspio_set_uint_param(codec
, 0x96,
8434 SPEAKER_TUNING_FRONT_LEFT_INVERT
, tmp
);
8435 dspio_set_uint_param(codec
, 0x96,
8436 SPEAKER_TUNING_FRONT_RIGHT_INVERT
, tmp
);
8438 ca0113_mmio_command_set(codec
, 0x30, 0x2e, 0x3f);
8440 /* New, unknown SCP req's */
8441 dspio_set_uint_param(codec
, 0x80, 0x0d, tmp
);
8442 dspio_set_uint_param(codec
, 0x80, 0x0e, tmp
);
8444 ca0113_mmio_gpio_set(codec
, 0, false);
8446 /* Internal loopback off */
8448 dspio_set_uint_param(codec
, 0x37, 0x08, tmp
);
8449 dspio_set_uint_param(codec
, 0x37, 0x10, tmp
);
8451 /*remove DSP headroom*/
8453 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
8455 /* set WUH source */
8457 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
8458 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
8460 /* Set speaker source? */
8461 dspio_set_uint_param(codec
, 0x32, 0x00, tmp
);
8462 ca0113_mmio_command_set(codec
, 0x30, 0x28, 0x00);
8465 * This is the second time we've called this, but this is seemingly
8466 * what Windows does.
8468 ca0132_alt_init_analog_mics(codec
);
8470 ae7_post_dsp_asi_setup(codec
);
8473 * Not sure why, but these are both set to 1. They're only set to 0
8476 ca0113_mmio_gpio_set(codec
, 0, true);
8477 ca0113_mmio_gpio_set(codec
, 1, true);
8479 /* Volume control related. */
8480 ca0113_mmio_command_set(codec
, 0x48, 0x0f, 0x04);
8481 ca0113_mmio_command_set(codec
, 0x48, 0x10, 0x04);
8482 ca0113_mmio_command_set_type2(codec
, 0x48, 0x07, 0x80);
8484 /* out, in effects + voicefx */
8485 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
8486 for (idx
= 0; idx
< num_fx
; idx
++) {
8487 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
8488 dspio_set_uint_param(codec
,
8489 ca0132_effects
[idx
].mid
,
8490 ca0132_effects
[idx
].reqs
[i
],
8491 ca0132_effects
[idx
].def_vals
[i
]);
8495 ca0132_alt_init_speaker_tuning(codec
);
8499 * Initialization of flags in chip
8501 static void ca0132_init_flags(struct hda_codec
*codec
)
8503 struct ca0132_spec
*spec
= codec
->spec
;
8505 if (ca0132_use_alt_functions(spec
)) {
8506 chipio_set_control_flag(codec
, CONTROL_FLAG_DSP_96KHZ
, 1);
8507 chipio_set_control_flag(codec
, CONTROL_FLAG_DAC_96KHZ
, 1);
8508 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_B_96KHZ
, 1);
8509 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_96KHZ
, 1);
8510 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_RATE_96KHZ
, 1);
8511 chipio_set_control_flag(codec
, CONTROL_FLAG_IDLE_ENABLE
, 0);
8512 chipio_set_control_flag(codec
, CONTROL_FLAG_SPDIF2OUT
, 0);
8513 chipio_set_control_flag(codec
,
8514 CONTROL_FLAG_PORT_D_10KOHM_LOAD
, 0);
8515 chipio_set_control_flag(codec
,
8516 CONTROL_FLAG_PORT_A_10KOHM_LOAD
, 1);
8518 chipio_set_control_flag(codec
, CONTROL_FLAG_IDLE_ENABLE
, 0);
8519 chipio_set_control_flag(codec
,
8520 CONTROL_FLAG_PORT_A_COMMON_MODE
, 0);
8521 chipio_set_control_flag(codec
,
8522 CONTROL_FLAG_PORT_D_COMMON_MODE
, 0);
8523 chipio_set_control_flag(codec
,
8524 CONTROL_FLAG_PORT_A_10KOHM_LOAD
, 0);
8525 chipio_set_control_flag(codec
,
8526 CONTROL_FLAG_PORT_D_10KOHM_LOAD
, 0);
8527 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_HIGH_PASS
, 1);
8532 * Initialization of parameters in chip
8534 static void ca0132_init_params(struct hda_codec
*codec
)
8536 struct ca0132_spec
*spec
= codec
->spec
;
8538 if (ca0132_use_alt_functions(spec
)) {
8539 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
8540 chipio_set_conn_rate(codec
, 0x0B, SR_48_000
);
8541 chipio_set_control_param(codec
, CONTROL_PARAM_SPDIF1_SOURCE
, 0);
8542 chipio_set_control_param(codec
, 0, 0);
8543 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, 0);
8546 chipio_set_control_param(codec
, CONTROL_PARAM_PORTA_160OHM_GAIN
, 6);
8547 chipio_set_control_param(codec
, CONTROL_PARAM_PORTD_160OHM_GAIN
, 6);
8550 static void ca0132_set_dsp_msr(struct hda_codec
*codec
, bool is96k
)
8552 chipio_set_control_flag(codec
, CONTROL_FLAG_DSP_96KHZ
, is96k
);
8553 chipio_set_control_flag(codec
, CONTROL_FLAG_DAC_96KHZ
, is96k
);
8554 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_RATE_96KHZ
, is96k
);
8555 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_CLOCK_196MHZ
, is96k
);
8556 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_B_96KHZ
, is96k
);
8557 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_96KHZ
, is96k
);
8559 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
8560 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
8561 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
8564 static bool ca0132_download_dsp_images(struct hda_codec
*codec
)
8566 bool dsp_loaded
= false;
8567 struct ca0132_spec
*spec
= codec
->spec
;
8568 const struct dsp_image_seg
*dsp_os_image
;
8569 const struct firmware
*fw_entry
= NULL
;
8571 * Alternate firmwares for different variants. The Recon3Di apparently
8572 * can use the default firmware, but I'll leave the option in case
8573 * it needs it again.
8575 switch (ca0132_quirk(spec
)) {
8579 if (request_firmware(&fw_entry
, DESKTOP_EFX_FILE
,
8580 codec
->card
->dev
) != 0)
8581 codec_dbg(codec
, "Desktop firmware not found.");
8583 codec_dbg(codec
, "Desktop firmware selected.");
8586 if (request_firmware(&fw_entry
, R3DI_EFX_FILE
,
8587 codec
->card
->dev
) != 0)
8588 codec_dbg(codec
, "Recon3Di alt firmware not detected.");
8590 codec_dbg(codec
, "Recon3Di firmware selected.");
8596 * Use default ctefx.bin if no alt firmware is detected, or if none
8597 * exists for your particular codec.
8600 codec_dbg(codec
, "Default firmware selected.");
8601 if (request_firmware(&fw_entry
, EFX_FILE
,
8602 codec
->card
->dev
) != 0)
8606 dsp_os_image
= (struct dsp_image_seg
*)(fw_entry
->data
);
8607 if (dspload_image(codec
, dsp_os_image
, 0, 0, true, 0)) {
8608 codec_err(codec
, "ca0132 DSP load image failed\n");
8612 dsp_loaded
= dspload_wait_loaded(codec
);
8615 release_firmware(fw_entry
);
8620 static void ca0132_download_dsp(struct hda_codec
*codec
)
8622 struct ca0132_spec
*spec
= codec
->spec
;
8624 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
8628 if (spec
->dsp_state
== DSP_DOWNLOAD_FAILED
)
8629 return; /* don't retry failures */
8631 chipio_enable_clocks(codec
);
8632 if (spec
->dsp_state
!= DSP_DOWNLOADED
) {
8633 spec
->dsp_state
= DSP_DOWNLOADING
;
8635 if (!ca0132_download_dsp_images(codec
))
8636 spec
->dsp_state
= DSP_DOWNLOAD_FAILED
;
8638 spec
->dsp_state
= DSP_DOWNLOADED
;
8641 /* For codecs using alt functions, this is already done earlier */
8642 if (spec
->dsp_state
== DSP_DOWNLOADED
&& !ca0132_use_alt_functions(spec
))
8643 ca0132_set_dsp_msr(codec
, true);
8646 static void ca0132_process_dsp_response(struct hda_codec
*codec
,
8647 struct hda_jack_callback
*callback
)
8649 struct ca0132_spec
*spec
= codec
->spec
;
8651 codec_dbg(codec
, "ca0132_process_dsp_response\n");
8652 snd_hda_power_up_pm(codec
);
8653 if (spec
->wait_scp
) {
8654 if (dspio_get_response_data(codec
) >= 0)
8658 dspio_clear_response_queue(codec
);
8659 snd_hda_power_down_pm(codec
);
8662 static void hp_callback(struct hda_codec
*codec
, struct hda_jack_callback
*cb
)
8664 struct ca0132_spec
*spec
= codec
->spec
;
8665 struct hda_jack_tbl
*tbl
;
8667 /* Delay enabling the HP amp, to let the mic-detection
8668 * state machine run.
8670 tbl
= snd_hda_jack_tbl_get(codec
, cb
->nid
);
8672 tbl
->block_report
= 1;
8673 schedule_delayed_work(&spec
->unsol_hp_work
, msecs_to_jiffies(500));
8676 static void amic_callback(struct hda_codec
*codec
, struct hda_jack_callback
*cb
)
8678 struct ca0132_spec
*spec
= codec
->spec
;
8680 if (ca0132_use_alt_functions(spec
))
8681 ca0132_alt_select_in(codec
);
8683 ca0132_select_mic(codec
);
8686 static void ca0132_setup_unsol(struct hda_codec
*codec
)
8688 struct ca0132_spec
*spec
= codec
->spec
;
8689 snd_hda_jack_detect_enable_callback(codec
, spec
->unsol_tag_hp
, hp_callback
);
8690 snd_hda_jack_detect_enable_callback(codec
, spec
->unsol_tag_amic1
,
8692 snd_hda_jack_detect_enable_callback(codec
, UNSOL_TAG_DSP
,
8693 ca0132_process_dsp_response
);
8694 /* Front headphone jack detection */
8695 if (ca0132_use_alt_functions(spec
))
8696 snd_hda_jack_detect_enable_callback(codec
,
8697 spec
->unsol_tag_front_hp
, hp_callback
);
8704 /* Sends before DSP download. */
8705 static const struct hda_verb ca0132_base_init_verbs
[] = {
8706 /*enable ct extension*/
8707 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
, 0x1},
8712 static const struct hda_verb ca0132_base_exit_verbs
[] = {
8714 {0x01, AC_VERB_SET_POWER_STATE
, 0x03},
8715 /*disable ct extension*/
8716 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
, 0},
8720 /* Other verbs tables. Sends after DSP download. */
8722 static const struct hda_verb ca0132_init_verbs0
[] = {
8723 /* chip init verbs */
8724 {0x15, 0x70D, 0xF0},
8725 {0x15, 0x70E, 0xFE},
8726 {0x15, 0x707, 0x75},
8727 {0x15, 0x707, 0xD3},
8728 {0x15, 0x707, 0x09},
8729 {0x15, 0x707, 0x53},
8730 {0x15, 0x707, 0xD4},
8731 {0x15, 0x707, 0xEF},
8732 {0x15, 0x707, 0x75},
8733 {0x15, 0x707, 0xD3},
8734 {0x15, 0x707, 0x09},
8735 {0x15, 0x707, 0x02},
8736 {0x15, 0x707, 0x37},
8737 {0x15, 0x707, 0x78},
8738 {0x15, 0x53C, 0xCE},
8739 {0x15, 0x575, 0xC9},
8740 {0x15, 0x53D, 0xCE},
8741 {0x15, 0x5B7, 0xC9},
8742 {0x15, 0x70D, 0xE8},
8743 {0x15, 0x70E, 0xFE},
8744 {0x15, 0x707, 0x02},
8745 {0x15, 0x707, 0x68},
8746 {0x15, 0x707, 0x62},
8747 {0x15, 0x53A, 0xCE},
8748 {0x15, 0x546, 0xC9},
8749 {0x15, 0x53B, 0xCE},
8750 {0x15, 0x5E8, 0xC9},
8754 /* Extra init verbs for desktop cards. */
8755 static const struct hda_verb ca0132_init_verbs1
[] = {
8756 {0x15, 0x70D, 0x20},
8757 {0x15, 0x70E, 0x19},
8758 {0x15, 0x707, 0x00},
8759 {0x15, 0x539, 0xCE},
8760 {0x15, 0x546, 0xC9},
8761 {0x15, 0x70D, 0xB7},
8762 {0x15, 0x70E, 0x09},
8763 {0x15, 0x707, 0x10},
8764 {0x15, 0x70D, 0xAF},
8765 {0x15, 0x70E, 0x09},
8766 {0x15, 0x707, 0x01},
8767 {0x15, 0x707, 0x05},
8768 {0x15, 0x70D, 0x73},
8769 {0x15, 0x70E, 0x09},
8770 {0x15, 0x707, 0x14},
8771 {0x15, 0x6FF, 0xC4},
8775 static void ca0132_init_chip(struct hda_codec
*codec
)
8777 struct ca0132_spec
*spec
= codec
->spec
;
8782 mutex_init(&spec
->chipio_mutex
);
8785 * The Windows driver always does this upon startup, which seems to
8786 * clear out any previous configuration. This should help issues where
8787 * a boot into Windows prior to a boot into Linux breaks things. Also,
8788 * Windows always sends the reset twice.
8790 if (ca0132_use_alt_functions(spec
)) {
8791 chipio_set_control_flag(codec
, CONTROL_FLAG_IDLE_ENABLE
, 0);
8792 chipio_write_no_mutex(codec
, 0x18b0a4, 0x000000c2);
8794 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
8795 AC_VERB_SET_CODEC_RESET
, 0);
8796 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
8797 AC_VERB_SET_CODEC_RESET
, 0);
8800 spec
->cur_out_type
= SPEAKER_OUT
;
8801 if (!ca0132_use_alt_functions(spec
))
8802 spec
->cur_mic_type
= DIGITAL_MIC
;
8804 spec
->cur_mic_type
= REAR_MIC
;
8806 spec
->cur_mic_boost
= 0;
8808 for (i
= 0; i
< VNODES_COUNT
; i
++) {
8809 spec
->vnode_lvol
[i
] = 0x5a;
8810 spec
->vnode_rvol
[i
] = 0x5a;
8811 spec
->vnode_lswitch
[i
] = 0;
8812 spec
->vnode_rswitch
[i
] = 0;
8816 * Default states for effects are in ca0132_effects[].
8818 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
8819 for (i
= 0; i
< num_fx
; i
++) {
8820 on
= (unsigned int)ca0132_effects
[i
].reqs
[0];
8821 spec
->effects_switch
[i
] = on
? 1 : 0;
8824 * Sets defaults for the effect slider controls, only for alternative
8825 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
8827 if (ca0132_use_alt_controls(spec
)) {
8828 /* Set speakers to default to full range. */
8829 spec
->speaker_range_val
[0] = 1;
8830 spec
->speaker_range_val
[1] = 1;
8832 spec
->xbass_xover_freq
= 8;
8833 for (i
= 0; i
< EFFECT_LEVEL_SLIDERS
; i
++)
8834 spec
->fx_ctl_val
[i
] = effect_slider_defaults
[i
];
8836 spec
->bass_redirect_xover_freq
= 8;
8839 spec
->voicefx_val
= 0;
8840 spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
] = 1;
8841 spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] = 0;
8844 * The ZxR doesn't have a front panel header, and it's line-in is on
8845 * the daughter board. So, there is no input enum control, and we need
8846 * to make sure that spec->in_enum_val is set properly.
8848 if (ca0132_quirk(spec
) == QUIRK_ZXR
)
8849 spec
->in_enum_val
= REAR_MIC
;
8851 #ifdef ENABLE_TUNING_CONTROLS
8852 ca0132_init_tuning_defaults(codec
);
8857 * Recon3Di exit specific commands.
8859 /* prevents popping noise on shutdown */
8860 static void r3di_gpio_shutdown(struct hda_codec
*codec
)
8862 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
, 0x00);
8866 * Sound Blaster Z exit specific commands.
8868 static void sbz_region2_exit(struct hda_codec
*codec
)
8870 struct ca0132_spec
*spec
= codec
->spec
;
8873 for (i
= 0; i
< 4; i
++)
8874 writeb(0x0, spec
->mem_base
+ 0x100);
8875 for (i
= 0; i
< 8; i
++)
8876 writeb(0xb3, spec
->mem_base
+ 0x304);
8878 ca0113_mmio_gpio_set(codec
, 0, false);
8879 ca0113_mmio_gpio_set(codec
, 1, false);
8880 ca0113_mmio_gpio_set(codec
, 4, true);
8881 ca0113_mmio_gpio_set(codec
, 5, false);
8882 ca0113_mmio_gpio_set(codec
, 7, false);
8885 static void sbz_set_pin_ctl_default(struct hda_codec
*codec
)
8887 static const hda_nid_t pins
[] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
8890 snd_hda_codec_write(codec
, 0x11, 0,
8891 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40);
8893 for (i
= 0; i
< ARRAY_SIZE(pins
); i
++)
8894 snd_hda_codec_write(codec
, pins
[i
], 0,
8895 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x00);
8898 static void ca0132_clear_unsolicited(struct hda_codec
*codec
)
8900 static const hda_nid_t pins
[] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
8903 for (i
= 0; i
< ARRAY_SIZE(pins
); i
++) {
8904 snd_hda_codec_write(codec
, pins
[i
], 0,
8905 AC_VERB_SET_UNSOLICITED_ENABLE
, 0x00);
8909 /* On shutdown, sends commands in sets of three */
8910 static void sbz_gpio_shutdown_commands(struct hda_codec
*codec
, int dir
,
8914 snd_hda_codec_write(codec
, 0x01, 0,
8915 AC_VERB_SET_GPIO_DIRECTION
, dir
);
8917 snd_hda_codec_write(codec
, 0x01, 0,
8918 AC_VERB_SET_GPIO_MASK
, mask
);
8921 snd_hda_codec_write(codec
, 0x01, 0,
8922 AC_VERB_SET_GPIO_DATA
, data
);
8925 static void zxr_dbpro_power_state_shutdown(struct hda_codec
*codec
)
8927 static const hda_nid_t pins
[] = {0x05, 0x0c, 0x09, 0x0e, 0x08, 0x11, 0x01};
8930 for (i
= 0; i
< ARRAY_SIZE(pins
); i
++)
8931 snd_hda_codec_write(codec
, pins
[i
], 0,
8932 AC_VERB_SET_POWER_STATE
, 0x03);
8935 static void sbz_exit_chip(struct hda_codec
*codec
)
8937 chipio_set_stream_control(codec
, 0x03, 0);
8938 chipio_set_stream_control(codec
, 0x04, 0);
8940 /* Mess with GPIO */
8941 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, -1);
8942 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x05);
8943 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x01);
8945 chipio_set_stream_control(codec
, 0x14, 0);
8946 chipio_set_stream_control(codec
, 0x0C, 0);
8948 chipio_set_conn_rate(codec
, 0x41, SR_192_000
);
8949 chipio_set_conn_rate(codec
, 0x91, SR_192_000
);
8951 chipio_write(codec
, 0x18a020, 0x00000083);
8953 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x03);
8954 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x07);
8955 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x06);
8957 chipio_set_stream_control(codec
, 0x0C, 0);
8959 chipio_set_control_param(codec
, 0x0D, 0x24);
8961 ca0132_clear_unsolicited(codec
);
8962 sbz_set_pin_ctl_default(codec
);
8964 snd_hda_codec_write(codec
, 0x0B, 0,
8965 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
8967 sbz_region2_exit(codec
);
8970 static void r3d_exit_chip(struct hda_codec
*codec
)
8972 ca0132_clear_unsolicited(codec
);
8973 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
8974 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x5b);
8977 static void ae5_exit_chip(struct hda_codec
*codec
)
8979 chipio_set_stream_control(codec
, 0x03, 0);
8980 chipio_set_stream_control(codec
, 0x04, 0);
8982 ca0113_mmio_command_set(codec
, 0x30, 0x32, 0x3f);
8983 ca0113_mmio_command_set(codec
, 0x48, 0x07, 0x83);
8984 ca0113_mmio_command_set(codec
, 0x48, 0x07, 0x83);
8985 ca0113_mmio_command_set(codec
, 0x30, 0x30, 0x00);
8986 ca0113_mmio_command_set(codec
, 0x30, 0x2b, 0x00);
8987 ca0113_mmio_command_set(codec
, 0x30, 0x2d, 0x00);
8988 ca0113_mmio_gpio_set(codec
, 0, false);
8989 ca0113_mmio_gpio_set(codec
, 1, false);
8991 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
8992 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x53);
8994 chipio_set_control_param(codec
, CONTROL_PARAM_ASI
, 0);
8996 chipio_set_stream_control(codec
, 0x18, 0);
8997 chipio_set_stream_control(codec
, 0x0c, 0);
8999 snd_hda_codec_write(codec
, 0x01, 0, 0x724, 0x83);
9002 static void ae7_exit_chip(struct hda_codec
*codec
)
9004 chipio_set_stream_control(codec
, 0x18, 0);
9005 chipio_set_stream_source_dest(codec
, 0x21, 0xc8, 0xc8);
9006 chipio_set_stream_channels(codec
, 0x21, 0);
9007 chipio_set_control_param(codec
, CONTROL_PARAM_NODE_ID
, 0x09);
9008 chipio_set_control_param(codec
, 0x20, 0x01);
9010 chipio_set_control_param(codec
, CONTROL_PARAM_ASI
, 0);
9012 chipio_set_stream_control(codec
, 0x18, 0);
9013 chipio_set_stream_control(codec
, 0x0c, 0);
9015 ca0113_mmio_command_set(codec
, 0x30, 0x2b, 0x00);
9016 snd_hda_codec_write(codec
, 0x15, 0, 0x724, 0x83);
9017 ca0113_mmio_command_set_type2(codec
, 0x48, 0x07, 0x83);
9018 ca0113_mmio_command_set(codec
, 0x30, 0x30, 0x00);
9019 ca0113_mmio_command_set(codec
, 0x30, 0x2e, 0x00);
9020 ca0113_mmio_gpio_set(codec
, 0, false);
9021 ca0113_mmio_gpio_set(codec
, 1, false);
9022 ca0113_mmio_command_set(codec
, 0x30, 0x32, 0x3f);
9024 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
9025 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x53);
9028 static void zxr_exit_chip(struct hda_codec
*codec
)
9030 chipio_set_stream_control(codec
, 0x03, 0);
9031 chipio_set_stream_control(codec
, 0x04, 0);
9032 chipio_set_stream_control(codec
, 0x14, 0);
9033 chipio_set_stream_control(codec
, 0x0C, 0);
9035 chipio_set_conn_rate(codec
, 0x41, SR_192_000
);
9036 chipio_set_conn_rate(codec
, 0x91, SR_192_000
);
9038 chipio_write(codec
, 0x18a020, 0x00000083);
9040 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
9041 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x53);
9043 ca0132_clear_unsolicited(codec
);
9044 sbz_set_pin_ctl_default(codec
);
9045 snd_hda_codec_write(codec
, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
9047 ca0113_mmio_gpio_set(codec
, 5, false);
9048 ca0113_mmio_gpio_set(codec
, 2, false);
9049 ca0113_mmio_gpio_set(codec
, 3, false);
9050 ca0113_mmio_gpio_set(codec
, 0, false);
9051 ca0113_mmio_gpio_set(codec
, 4, true);
9052 ca0113_mmio_gpio_set(codec
, 0, true);
9053 ca0113_mmio_gpio_set(codec
, 5, true);
9054 ca0113_mmio_gpio_set(codec
, 2, false);
9055 ca0113_mmio_gpio_set(codec
, 3, false);
9058 static void ca0132_exit_chip(struct hda_codec
*codec
)
9060 /* put any chip cleanup stuffs here. */
9062 if (dspload_is_loaded(codec
))
9067 * This fixes a problem that was hard to reproduce. Very rarely, I would
9068 * boot up, and there would be no sound, but the DSP indicated it had loaded
9069 * properly. I did a few memory dumps to see if anything was different, and
9070 * there were a few areas of memory uninitialized with a1a2a3a4. This function
9071 * checks if those areas are uninitialized, and if they are, it'll attempt to
9072 * reload the card 3 times. Usually it fixes by the second.
9074 static void sbz_dsp_startup_check(struct hda_codec
*codec
)
9076 struct ca0132_spec
*spec
= codec
->spec
;
9077 unsigned int dsp_data_check
[4];
9078 unsigned int cur_address
= 0x390;
9080 unsigned int failure
= 0;
9081 unsigned int reload
= 3;
9083 if (spec
->startup_check_entered
)
9086 spec
->startup_check_entered
= true;
9088 for (i
= 0; i
< 4; i
++) {
9089 chipio_read(codec
, cur_address
, &dsp_data_check
[i
]);
9092 for (i
= 0; i
< 4; i
++) {
9093 if (dsp_data_check
[i
] == 0xa1a2a3a4)
9097 codec_dbg(codec
, "Startup Check: %d ", failure
);
9099 codec_info(codec
, "DSP not initialized properly. Attempting to fix.");
9101 * While the failure condition is true, and we haven't reached our
9102 * three reload limit, continue trying to reload the driver and
9105 while (failure
&& (reload
!= 0)) {
9106 codec_info(codec
, "Reloading... Tries left: %d", reload
);
9107 sbz_exit_chip(codec
);
9108 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
9109 codec
->patch_ops
.init(codec
);
9111 for (i
= 0; i
< 4; i
++) {
9112 chipio_read(codec
, cur_address
, &dsp_data_check
[i
]);
9115 for (i
= 0; i
< 4; i
++) {
9116 if (dsp_data_check
[i
] == 0xa1a2a3a4)
9122 if (!failure
&& reload
< 3)
9123 codec_info(codec
, "DSP fixed.");
9128 codec_info(codec
, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
9132 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
9133 * extra precision for decibel values. If you had the dB value in floating point
9134 * you would take the value after the decimal point, multiply by 64, and divide
9135 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
9136 * implement fixed point or floating point dB volumes. For now, I'll set them
9137 * to 0 just incase a value has lingered from a boot into Windows.
9139 static void ca0132_alt_vol_setup(struct hda_codec
*codec
)
9141 snd_hda_codec_write(codec
, 0x02, 0, 0x797, 0x00);
9142 snd_hda_codec_write(codec
, 0x02, 0, 0x798, 0x00);
9143 snd_hda_codec_write(codec
, 0x03, 0, 0x797, 0x00);
9144 snd_hda_codec_write(codec
, 0x03, 0, 0x798, 0x00);
9145 snd_hda_codec_write(codec
, 0x04, 0, 0x797, 0x00);
9146 snd_hda_codec_write(codec
, 0x04, 0, 0x798, 0x00);
9147 snd_hda_codec_write(codec
, 0x07, 0, 0x797, 0x00);
9148 snd_hda_codec_write(codec
, 0x07, 0, 0x798, 0x00);
9152 * Extra commands that don't really fit anywhere else.
9154 static void sbz_pre_dsp_setup(struct hda_codec
*codec
)
9156 struct ca0132_spec
*spec
= codec
->spec
;
9158 writel(0x00820680, spec
->mem_base
+ 0x01C);
9159 writel(0x00820680, spec
->mem_base
+ 0x01C);
9161 chipio_write(codec
, 0x18b0a4, 0x000000c2);
9163 snd_hda_codec_write(codec
, 0x11, 0,
9164 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x44);
9167 static void r3d_pre_dsp_setup(struct hda_codec
*codec
)
9169 chipio_write(codec
, 0x18b0a4, 0x000000c2);
9171 chipio_8051_write_exram(codec
, 0x1c1e, 0x5b);
9173 snd_hda_codec_write(codec
, 0x11, 0,
9174 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x44);
9177 static void r3di_pre_dsp_setup(struct hda_codec
*codec
)
9179 chipio_write(codec
, 0x18b0a4, 0x000000c2);
9181 chipio_8051_write_exram(codec
, 0x1c1e, 0x5b);
9182 chipio_8051_write_exram(codec
, 0x1920, 0x00);
9183 chipio_8051_write_exram(codec
, 0x1921, 0x40);
9185 snd_hda_codec_write(codec
, 0x11, 0,
9186 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x04);
9190 * The ZxR seems to use alternative DAC's for the surround channels, which
9191 * require PLL PMU setup for the clock rate, I'm guessing. Without setting
9192 * this up, we get no audio out of the surround jacks.
9194 static void zxr_pre_dsp_setup(struct hda_codec
*codec
)
9196 static const unsigned int addr
[] = { 0x43, 0x40, 0x41, 0x42, 0x45 };
9197 static const unsigned int data
[] = { 0x08, 0x0c, 0x0b, 0x07, 0x0d };
9200 chipio_write(codec
, 0x189000, 0x0001f100);
9202 chipio_write(codec
, 0x18900c, 0x0001f100);
9206 * This writes a RET instruction at the entry point of the function at
9207 * 0xfa92 in exram. This function seems to have something to do with
9208 * ASI. Might be some way to prevent the card from reconfiguring the
9211 chipio_8051_write_exram(codec
, 0xfa92, 0x22);
9213 chipio_8051_write_pll_pmu(codec
, 0x51, 0x98);
9215 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, 0x725, 0x82);
9216 chipio_set_control_param(codec
, CONTROL_PARAM_ASI
, 3);
9218 chipio_write(codec
, 0x18902c, 0x00000000);
9220 chipio_write(codec
, 0x18902c, 0x00000003);
9223 for (i
= 0; i
< ARRAY_SIZE(addr
); i
++)
9224 chipio_8051_write_pll_pmu(codec
, addr
[i
], data
[i
]);
9228 * These are sent before the DSP is downloaded. Not sure
9229 * what they do, or if they're necessary. Could possibly
9230 * be removed. Figure they're better to leave in.
9232 static const unsigned int ca0113_mmio_init_address_sbz
[] = {
9233 0x400, 0x408, 0x40c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c,
9234 0xc0c, 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04
9237 static const unsigned int ca0113_mmio_init_data_sbz
[] = {
9238 0x00000030, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9239 0x00000003, 0x000000c1, 0x000000f1, 0x00000001, 0x000000c7,
9240 0x000000c1, 0x00000080
9243 static const unsigned int ca0113_mmio_init_data_zxr
[] = {
9244 0x00000030, 0x00000000, 0x00000000, 0x00000003, 0x00000003,
9245 0x00000003, 0x00000001, 0x000000f1, 0x00000001, 0x000000c7,
9246 0x000000c1, 0x00000080
9249 static const unsigned int ca0113_mmio_init_address_ae5
[] = {
9250 0x400, 0x42c, 0x46c, 0x4ac, 0x4ec, 0x43c, 0x47c, 0x4bc, 0x4fc, 0x408,
9251 0x100, 0x410, 0x40c, 0x100, 0x100, 0x830, 0x86c, 0x800, 0x86c, 0x800,
9252 0x804, 0x20c, 0x01c, 0xc0c, 0xc00, 0xc04, 0xc0c, 0xc0c, 0xc0c, 0xc0c,
9253 0xc08, 0xc08, 0xc08, 0xc08, 0xc08, 0xc04, 0x01c
9256 static const unsigned int ca0113_mmio_init_data_ae5
[] = {
9257 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
9258 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
9259 0x00000600, 0x00000014, 0x00000001, 0x0000060f, 0x0000070f,
9260 0x00000aff, 0x00000000, 0x0000006b, 0x00000001, 0x0000006b,
9261 0x00000057, 0x00800000, 0x00880680, 0x00000080, 0x00000030,
9262 0x00000000, 0x00000000, 0x00000003, 0x00000003, 0x00000003,
9263 0x00000001, 0x000000f1, 0x00000001, 0x000000c7, 0x000000c1,
9264 0x00000080, 0x00880680
9267 static void ca0132_mmio_init_sbz(struct hda_codec
*codec
)
9269 struct ca0132_spec
*spec
= codec
->spec
;
9270 unsigned int tmp
[2], i
, count
, cur_addr
;
9271 const unsigned int *addr
, *data
;
9273 addr
= ca0113_mmio_init_address_sbz
;
9274 for (i
= 0; i
< 3; i
++)
9275 writel(0x00000000, spec
->mem_base
+ addr
[i
]);
9278 switch (ca0132_quirk(spec
)) {
9280 tmp
[0] = 0x00880480;
9281 tmp
[1] = 0x00000080;
9284 tmp
[0] = 0x00820680;
9285 tmp
[1] = 0x00000083;
9288 tmp
[0] = 0x00880680;
9289 tmp
[1] = 0x00000083;
9292 tmp
[0] = 0x00000000;
9293 tmp
[1] = 0x00000000;
9297 for (i
= 0; i
< 2; i
++)
9298 writel(tmp
[i
], spec
->mem_base
+ addr
[cur_addr
+ i
]);
9302 switch (ca0132_quirk(spec
)) {
9304 count
= ARRAY_SIZE(ca0113_mmio_init_data_zxr
);
9305 data
= ca0113_mmio_init_data_zxr
;
9308 count
= ARRAY_SIZE(ca0113_mmio_init_data_sbz
);
9309 data
= ca0113_mmio_init_data_sbz
;
9313 for (i
= 0; i
< count
; i
++)
9314 writel(data
[i
], spec
->mem_base
+ addr
[cur_addr
+ i
]);
9317 static void ca0132_mmio_init_ae5(struct hda_codec
*codec
)
9319 struct ca0132_spec
*spec
= codec
->spec
;
9320 const unsigned int *addr
, *data
;
9321 unsigned int i
, count
;
9323 addr
= ca0113_mmio_init_address_ae5
;
9324 data
= ca0113_mmio_init_data_ae5
;
9325 count
= ARRAY_SIZE(ca0113_mmio_init_data_ae5
);
9327 if (ca0132_quirk(spec
) == QUIRK_AE7
) {
9328 writel(0x00000680, spec
->mem_base
+ 0x1c);
9329 writel(0x00880680, spec
->mem_base
+ 0x1c);
9332 for (i
= 0; i
< count
; i
++) {
9334 * AE-7 shares all writes with the AE-5, except that it writes
9335 * a different value to 0x20c.
9337 if (i
== 21 && ca0132_quirk(spec
) == QUIRK_AE7
) {
9338 writel(0x00800001, spec
->mem_base
+ addr
[i
]);
9342 writel(data
[i
], spec
->mem_base
+ addr
[i
]);
9345 if (ca0132_quirk(spec
) == QUIRK_AE5
)
9346 writel(0x00880680, spec
->mem_base
+ 0x1c);
9349 static void ca0132_mmio_init(struct hda_codec
*codec
)
9351 struct ca0132_spec
*spec
= codec
->spec
;
9353 switch (ca0132_quirk(spec
)) {
9357 ca0132_mmio_init_sbz(codec
);
9360 ca0132_mmio_init_ae5(codec
);
9367 static const unsigned int ca0132_ae5_register_set_addresses
[] = {
9368 0x304, 0x304, 0x304, 0x304, 0x100, 0x304, 0x100, 0x304, 0x100, 0x304,
9369 0x100, 0x304, 0x86c, 0x800, 0x86c, 0x800, 0x804
9372 static const unsigned char ca0132_ae5_register_set_data
[] = {
9373 0x0f, 0x0e, 0x1f, 0x0c, 0x3f, 0x08, 0x7f, 0x00, 0xff, 0x00, 0x6b,
9378 * This function writes to some SFR's, does some region2 writes, and then
9379 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
9382 static void ae5_register_set(struct hda_codec
*codec
)
9384 struct ca0132_spec
*spec
= codec
->spec
;
9385 unsigned int count
= ARRAY_SIZE(ca0132_ae5_register_set_addresses
);
9386 const unsigned int *addr
= ca0132_ae5_register_set_addresses
;
9387 const unsigned char *data
= ca0132_ae5_register_set_data
;
9388 unsigned int i
, cur_addr
;
9389 unsigned char tmp
[3];
9391 if (ca0132_quirk(spec
) == QUIRK_AE7
)
9392 chipio_8051_write_pll_pmu(codec
, 0x41, 0xc8);
9394 chipio_8051_write_direct(codec
, 0x93, 0x10);
9395 chipio_8051_write_pll_pmu(codec
, 0x44, 0xc2);
9397 if (ca0132_quirk(spec
) == QUIRK_AE7
) {
9407 for (i
= cur_addr
= 0; i
< 3; i
++, cur_addr
++)
9408 writeb(tmp
[i
], spec
->mem_base
+ addr
[cur_addr
]);
9411 * First writes are in single bytes, final are in 4 bytes. So, we use
9412 * writeb, then writel.
9414 for (i
= 0; cur_addr
< 12; i
++, cur_addr
++)
9415 writeb(data
[i
], spec
->mem_base
+ addr
[cur_addr
]);
9417 for (; cur_addr
< count
; i
++, cur_addr
++)
9418 writel(data
[i
], spec
->mem_base
+ addr
[cur_addr
]);
9420 writel(0x00800001, spec
->mem_base
+ 0x20c);
9422 if (ca0132_quirk(spec
) == QUIRK_AE7
) {
9423 ca0113_mmio_command_set_type2(codec
, 0x48, 0x07, 0x83);
9424 ca0113_mmio_command_set(codec
, 0x30, 0x2e, 0x3f);
9426 ca0113_mmio_command_set(codec
, 0x30, 0x2d, 0x3f);
9429 chipio_8051_write_direct(codec
, 0x90, 0x00);
9430 chipio_8051_write_direct(codec
, 0x90, 0x10);
9432 if (ca0132_quirk(spec
) == QUIRK_AE5
)
9433 ca0113_mmio_command_set(codec
, 0x48, 0x07, 0x83);
9437 * Extra init functions for alternative ca0132 codecs. Done
9438 * here so they don't clutter up the main ca0132_init function
9439 * anymore than they have to.
9441 static void ca0132_alt_init(struct hda_codec
*codec
)
9443 struct ca0132_spec
*spec
= codec
->spec
;
9445 ca0132_alt_vol_setup(codec
);
9447 switch (ca0132_quirk(spec
)) {
9449 codec_dbg(codec
, "SBZ alt_init");
9450 ca0132_gpio_init(codec
);
9451 sbz_pre_dsp_setup(codec
);
9452 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
9453 snd_hda_sequence_write(codec
, spec
->desktop_init_verbs
);
9456 codec_dbg(codec
, "R3DI alt_init");
9457 ca0132_gpio_init(codec
);
9458 ca0132_gpio_setup(codec
);
9459 r3di_gpio_dsp_status_set(codec
, R3DI_DSP_DOWNLOADING
);
9460 r3di_pre_dsp_setup(codec
);
9461 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
9462 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, 0x6FF, 0xC4);
9465 r3d_pre_dsp_setup(codec
);
9466 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
9467 snd_hda_sequence_write(codec
, spec
->desktop_init_verbs
);
9470 ca0132_gpio_init(codec
);
9471 chipio_8051_write_pll_pmu(codec
, 0x49, 0x88);
9472 chipio_write(codec
, 0x18b030, 0x00000020);
9473 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
9474 snd_hda_sequence_write(codec
, spec
->desktop_init_verbs
);
9475 ca0113_mmio_command_set(codec
, 0x30, 0x32, 0x3f);
9478 ca0132_gpio_init(codec
);
9479 chipio_8051_write_pll_pmu(codec
, 0x49, 0x88);
9480 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
9481 snd_hda_sequence_write(codec
, spec
->desktop_init_verbs
);
9482 chipio_write(codec
, 0x18b008, 0x000000f8);
9483 chipio_write(codec
, 0x18b008, 0x000000f0);
9484 chipio_write(codec
, 0x18b030, 0x00000020);
9485 ca0113_mmio_command_set(codec
, 0x30, 0x32, 0x3f);
9488 chipio_8051_write_pll_pmu(codec
, 0x49, 0x88);
9489 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
9490 snd_hda_sequence_write(codec
, spec
->desktop_init_verbs
);
9491 zxr_pre_dsp_setup(codec
);
9498 static int ca0132_init(struct hda_codec
*codec
)
9500 struct ca0132_spec
*spec
= codec
->spec
;
9501 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
9506 * If the DSP is already downloaded, and init has been entered again,
9507 * there's only two reasons for it. One, the codec has awaken from a
9508 * suspended state, and in that case dspload_is_loaded will return
9509 * false, and the init will be ran again. The other reason it gets
9510 * re entered is on startup for some reason it triggers a suspend and
9511 * resume state. In this case, it will check if the DSP is downloaded,
9512 * and not run the init function again. For codecs using alt_functions,
9513 * it will check if the DSP is loaded properly.
9515 if (spec
->dsp_state
== DSP_DOWNLOADED
) {
9516 dsp_loaded
= dspload_is_loaded(codec
);
9518 spec
->dsp_reload
= true;
9519 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
9521 if (ca0132_quirk(spec
) == QUIRK_SBZ
)
9522 sbz_dsp_startup_check(codec
);
9527 if (spec
->dsp_state
!= DSP_DOWNLOAD_FAILED
)
9528 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
9529 spec
->curr_chip_addx
= INVALID_CHIP_ADDRESS
;
9531 if (ca0132_use_pci_mmio(spec
))
9532 ca0132_mmio_init(codec
);
9534 snd_hda_power_up_pm(codec
);
9536 if (ca0132_quirk(spec
) == QUIRK_AE5
|| ca0132_quirk(spec
) == QUIRK_AE7
)
9537 ae5_register_set(codec
);
9539 ca0132_init_params(codec
);
9540 ca0132_init_flags(codec
);
9542 snd_hda_sequence_write(codec
, spec
->base_init_verbs
);
9544 if (ca0132_use_alt_functions(spec
))
9545 ca0132_alt_init(codec
);
9547 ca0132_download_dsp(codec
);
9549 ca0132_refresh_widget_caps(codec
);
9551 switch (ca0132_quirk(spec
)) {
9554 r3d_setup_defaults(codec
);
9558 sbz_setup_defaults(codec
);
9561 ae5_setup_defaults(codec
);
9564 ae7_setup_defaults(codec
);
9567 ca0132_setup_defaults(codec
);
9568 ca0132_init_analog_mic2(codec
);
9569 ca0132_init_dmic(codec
);
9573 for (i
= 0; i
< spec
->num_outputs
; i
++)
9574 init_output(codec
, spec
->out_pins
[i
], spec
->dacs
[0]);
9576 init_output(codec
, cfg
->dig_out_pins
[0], spec
->dig_out
);
9578 for (i
= 0; i
< spec
->num_inputs
; i
++)
9579 init_input(codec
, spec
->input_pins
[i
], spec
->adcs
[i
]);
9581 init_input(codec
, cfg
->dig_in_pin
, spec
->dig_in
);
9583 if (!ca0132_use_alt_functions(spec
)) {
9584 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
9585 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
9586 VENDOR_CHIPIO_PARAM_EX_ID_SET
, 0x0D);
9587 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
9588 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
, 0x20);
9591 if (ca0132_quirk(spec
) == QUIRK_SBZ
)
9592 ca0132_gpio_setup(codec
);
9594 snd_hda_sequence_write(codec
, spec
->spec_init_verbs
);
9595 if (ca0132_use_alt_functions(spec
)) {
9596 ca0132_alt_select_out(codec
);
9597 ca0132_alt_select_in(codec
);
9599 ca0132_select_out(codec
);
9600 ca0132_select_mic(codec
);
9603 snd_hda_jack_report_sync(codec
);
9606 * Re set the PlayEnhancement switch on a resume event, because the
9607 * controls will not be reloaded.
9609 if (spec
->dsp_reload
) {
9610 spec
->dsp_reload
= false;
9611 ca0132_pe_switch_set(codec
);
9614 snd_hda_power_down_pm(codec
);
9619 static int dbpro_init(struct hda_codec
*codec
)
9621 struct ca0132_spec
*spec
= codec
->spec
;
9622 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
9625 init_output(codec
, cfg
->dig_out_pins
[0], spec
->dig_out
);
9626 init_input(codec
, cfg
->dig_in_pin
, spec
->dig_in
);
9628 for (i
= 0; i
< spec
->num_inputs
; i
++)
9629 init_input(codec
, spec
->input_pins
[i
], spec
->adcs
[i
]);
9634 static void ca0132_free(struct hda_codec
*codec
)
9636 struct ca0132_spec
*spec
= codec
->spec
;
9638 cancel_delayed_work_sync(&spec
->unsol_hp_work
);
9639 snd_hda_power_up(codec
);
9640 switch (ca0132_quirk(spec
)) {
9642 sbz_exit_chip(codec
);
9645 zxr_exit_chip(codec
);
9648 r3d_exit_chip(codec
);
9651 ae5_exit_chip(codec
);
9654 ae7_exit_chip(codec
);
9657 r3di_gpio_shutdown(codec
);
9663 snd_hda_sequence_write(codec
, spec
->base_exit_verbs
);
9664 ca0132_exit_chip(codec
);
9666 snd_hda_power_down(codec
);
9669 pci_iounmap(codec
->bus
->pci
, spec
->mem_base
);
9671 kfree(spec
->spec_init_verbs
);
9675 static void dbpro_free(struct hda_codec
*codec
)
9677 struct ca0132_spec
*spec
= codec
->spec
;
9679 zxr_dbpro_power_state_shutdown(codec
);
9681 kfree(spec
->spec_init_verbs
);
9685 static void ca0132_reboot_notify(struct hda_codec
*codec
)
9687 codec
->patch_ops
.free(codec
);
9691 static int ca0132_suspend(struct hda_codec
*codec
)
9693 struct ca0132_spec
*spec
= codec
->spec
;
9695 cancel_delayed_work_sync(&spec
->unsol_hp_work
);
9700 static const struct hda_codec_ops ca0132_patch_ops
= {
9701 .build_controls
= ca0132_build_controls
,
9702 .build_pcms
= ca0132_build_pcms
,
9703 .init
= ca0132_init
,
9704 .free
= ca0132_free
,
9705 .unsol_event
= snd_hda_jack_unsol_event
,
9707 .suspend
= ca0132_suspend
,
9709 .reboot_notify
= ca0132_reboot_notify
,
9712 static const struct hda_codec_ops dbpro_patch_ops
= {
9713 .build_controls
= dbpro_build_controls
,
9714 .build_pcms
= dbpro_build_pcms
,
9719 static void ca0132_config(struct hda_codec
*codec
)
9721 struct ca0132_spec
*spec
= codec
->spec
;
9723 spec
->dacs
[0] = 0x2;
9724 spec
->dacs
[1] = 0x3;
9725 spec
->dacs
[2] = 0x4;
9727 spec
->multiout
.dac_nids
= spec
->dacs
;
9728 spec
->multiout
.num_dacs
= 3;
9730 if (!ca0132_use_alt_functions(spec
))
9731 spec
->multiout
.max_channels
= 2;
9733 spec
->multiout
.max_channels
= 6;
9735 switch (ca0132_quirk(spec
)) {
9736 case QUIRK_ALIENWARE
:
9737 codec_dbg(codec
, "%s: QUIRK_ALIENWARE applied.\n", __func__
);
9738 snd_hda_apply_pincfgs(codec
, alienware_pincfgs
);
9741 codec_dbg(codec
, "%s: QUIRK_SBZ applied.\n", __func__
);
9742 snd_hda_apply_pincfgs(codec
, sbz_pincfgs
);
9745 codec_dbg(codec
, "%s: QUIRK_ZXR applied.\n", __func__
);
9746 snd_hda_apply_pincfgs(codec
, zxr_pincfgs
);
9749 codec_dbg(codec
, "%s: QUIRK_R3D applied.\n", __func__
);
9750 snd_hda_apply_pincfgs(codec
, r3d_pincfgs
);
9753 codec_dbg(codec
, "%s: QUIRK_R3DI applied.\n", __func__
);
9754 snd_hda_apply_pincfgs(codec
, r3di_pincfgs
);
9757 codec_dbg(codec
, "%s: QUIRK_AE5 applied.\n", __func__
);
9758 snd_hda_apply_pincfgs(codec
, ae5_pincfgs
);
9761 codec_dbg(codec
, "%s: QUIRK_AE7 applied.\n", __func__
);
9762 snd_hda_apply_pincfgs(codec
, ae7_pincfgs
);
9768 switch (ca0132_quirk(spec
)) {
9769 case QUIRK_ALIENWARE
:
9770 spec
->num_outputs
= 2;
9771 spec
->out_pins
[0] = 0x0b; /* speaker out */
9772 spec
->out_pins
[1] = 0x0f;
9773 spec
->shared_out_nid
= 0x2;
9774 spec
->unsol_tag_hp
= 0x0f;
9776 spec
->adcs
[0] = 0x7; /* digital mic / analog mic1 */
9777 spec
->adcs
[1] = 0x8; /* analog mic2 */
9778 spec
->adcs
[2] = 0xa; /* what u hear */
9780 spec
->num_inputs
= 3;
9781 spec
->input_pins
[0] = 0x12;
9782 spec
->input_pins
[1] = 0x11;
9783 spec
->input_pins
[2] = 0x13;
9784 spec
->shared_mic_nid
= 0x7;
9785 spec
->unsol_tag_amic1
= 0x11;
9789 spec
->num_outputs
= 2;
9790 spec
->out_pins
[0] = 0x0B; /* Line out */
9791 spec
->out_pins
[1] = 0x0F; /* Rear headphone out */
9792 spec
->out_pins
[2] = 0x10; /* Front Headphone / Center/LFE*/
9793 spec
->out_pins
[3] = 0x11; /* Rear surround */
9794 spec
->shared_out_nid
= 0x2;
9795 spec
->unsol_tag_hp
= spec
->out_pins
[1];
9796 spec
->unsol_tag_front_hp
= spec
->out_pins
[2];
9798 spec
->adcs
[0] = 0x7; /* Rear Mic / Line-in */
9799 spec
->adcs
[1] = 0x8; /* Front Mic, but only if no DSP */
9800 spec
->adcs
[2] = 0xa; /* what u hear */
9802 spec
->num_inputs
= 2;
9803 spec
->input_pins
[0] = 0x12; /* Rear Mic / Line-in */
9804 spec
->input_pins
[1] = 0x13; /* What U Hear */
9805 spec
->shared_mic_nid
= 0x7;
9806 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
9809 spec
->dig_out
= 0x05;
9810 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
9811 spec
->dig_in
= 0x09;
9814 spec
->num_outputs
= 2;
9815 spec
->out_pins
[0] = 0x0B; /* Line out */
9816 spec
->out_pins
[1] = 0x0F; /* Rear headphone out */
9817 spec
->out_pins
[2] = 0x10; /* Center/LFE */
9818 spec
->out_pins
[3] = 0x11; /* Rear surround */
9819 spec
->shared_out_nid
= 0x2;
9820 spec
->unsol_tag_hp
= spec
->out_pins
[1];
9821 spec
->unsol_tag_front_hp
= spec
->out_pins
[2];
9823 spec
->adcs
[0] = 0x7; /* Rear Mic / Line-in */
9824 spec
->adcs
[1] = 0x8; /* Not connected, no front mic */
9825 spec
->adcs
[2] = 0xa; /* what u hear */
9827 spec
->num_inputs
= 2;
9828 spec
->input_pins
[0] = 0x12; /* Rear Mic / Line-in */
9829 spec
->input_pins
[1] = 0x13; /* What U Hear */
9830 spec
->shared_mic_nid
= 0x7;
9831 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
9833 case QUIRK_ZXR_DBPRO
:
9834 spec
->adcs
[0] = 0x8; /* ZxR DBPro Aux In */
9836 spec
->num_inputs
= 1;
9837 spec
->input_pins
[0] = 0x11; /* RCA Line-in */
9839 spec
->dig_out
= 0x05;
9840 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
9842 spec
->dig_in
= 0x09;
9846 spec
->num_outputs
= 2;
9847 spec
->out_pins
[0] = 0x0B; /* Line out */
9848 spec
->out_pins
[1] = 0x11; /* Rear headphone out */
9849 spec
->out_pins
[2] = 0x10; /* Front Headphone / Center/LFE*/
9850 spec
->out_pins
[3] = 0x0F; /* Rear surround */
9851 spec
->shared_out_nid
= 0x2;
9852 spec
->unsol_tag_hp
= spec
->out_pins
[1];
9853 spec
->unsol_tag_front_hp
= spec
->out_pins
[2];
9855 spec
->adcs
[0] = 0x7; /* Rear Mic / Line-in */
9856 spec
->adcs
[1] = 0x8; /* Front Mic, but only if no DSP */
9857 spec
->adcs
[2] = 0xa; /* what u hear */
9859 spec
->num_inputs
= 2;
9860 spec
->input_pins
[0] = 0x12; /* Rear Mic / Line-in */
9861 spec
->input_pins
[1] = 0x13; /* What U Hear */
9862 spec
->shared_mic_nid
= 0x7;
9863 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
9866 spec
->dig_out
= 0x05;
9867 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
9870 spec
->num_outputs
= 2;
9871 spec
->out_pins
[0] = 0x0B; /* Line out */
9872 spec
->out_pins
[1] = 0x0F; /* Rear headphone out */
9873 spec
->out_pins
[2] = 0x10; /* Front Headphone / Center/LFE*/
9874 spec
->out_pins
[3] = 0x11; /* Rear surround */
9875 spec
->shared_out_nid
= 0x2;
9876 spec
->unsol_tag_hp
= spec
->out_pins
[1];
9877 spec
->unsol_tag_front_hp
= spec
->out_pins
[2];
9879 spec
->adcs
[0] = 0x07; /* Rear Mic / Line-in */
9880 spec
->adcs
[1] = 0x08; /* Front Mic, but only if no DSP */
9881 spec
->adcs
[2] = 0x0a; /* what u hear */
9883 spec
->num_inputs
= 2;
9884 spec
->input_pins
[0] = 0x12; /* Rear Mic / Line-in */
9885 spec
->input_pins
[1] = 0x13; /* What U Hear */
9886 spec
->shared_mic_nid
= 0x7;
9887 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
9890 spec
->dig_out
= 0x05;
9891 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
9894 spec
->num_outputs
= 2;
9895 spec
->out_pins
[0] = 0x0b; /* speaker out */
9896 spec
->out_pins
[1] = 0x10; /* headphone out */
9897 spec
->shared_out_nid
= 0x2;
9898 spec
->unsol_tag_hp
= spec
->out_pins
[1];
9900 spec
->adcs
[0] = 0x7; /* digital mic / analog mic1 */
9901 spec
->adcs
[1] = 0x8; /* analog mic2 */
9902 spec
->adcs
[2] = 0xa; /* what u hear */
9904 spec
->num_inputs
= 3;
9905 spec
->input_pins
[0] = 0x12;
9906 spec
->input_pins
[1] = 0x11;
9907 spec
->input_pins
[2] = 0x13;
9908 spec
->shared_mic_nid
= 0x7;
9909 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
9912 spec
->dig_out
= 0x05;
9913 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
9914 spec
->dig_in
= 0x09;
9919 static int ca0132_prepare_verbs(struct hda_codec
*codec
)
9921 /* Verbs + terminator (an empty element) */
9922 #define NUM_SPEC_VERBS 2
9923 struct ca0132_spec
*spec
= codec
->spec
;
9925 spec
->chip_init_verbs
= ca0132_init_verbs0
;
9927 * Since desktop cards use pci_mmio, this can be used to determine
9928 * whether or not to use these verbs instead of a separate bool.
9930 if (ca0132_use_pci_mmio(spec
))
9931 spec
->desktop_init_verbs
= ca0132_init_verbs1
;
9932 spec
->spec_init_verbs
= kcalloc(NUM_SPEC_VERBS
,
9933 sizeof(struct hda_verb
),
9935 if (!spec
->spec_init_verbs
)
9939 spec
->spec_init_verbs
[0].nid
= 0x0b;
9940 spec
->spec_init_verbs
[0].param
= 0x78D;
9941 spec
->spec_init_verbs
[0].verb
= 0x00;
9943 /* Previously commented configuration */
9945 spec->spec_init_verbs[2].nid = 0x0b;
9946 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
9947 spec->spec_init_verbs[2].verb = 0x02;
9949 spec->spec_init_verbs[3].nid = 0x10;
9950 spec->spec_init_verbs[3].param = 0x78D;
9951 spec->spec_init_verbs[3].verb = 0x02;
9953 spec->spec_init_verbs[4].nid = 0x10;
9954 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
9955 spec->spec_init_verbs[4].verb = 0x02;
9958 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
9963 * The Sound Blaster ZxR shares the same PCI subsystem ID as some regular
9964 * Sound Blaster Z cards. However, they have different HDA codec subsystem
9965 * ID's. So, we check for the ZxR's subsystem ID, as well as the DBPro
9966 * daughter boards ID.
9968 static void sbz_detect_quirk(struct hda_codec
*codec
)
9970 struct ca0132_spec
*spec
= codec
->spec
;
9972 switch (codec
->core
.subsystem_id
) {
9974 spec
->quirk
= QUIRK_ZXR
;
9977 spec
->quirk
= QUIRK_ZXR_DBPRO
;
9980 spec
->quirk
= QUIRK_SBZ
;
9985 static int patch_ca0132(struct hda_codec
*codec
)
9987 struct ca0132_spec
*spec
;
9989 const struct snd_pci_quirk
*quirk
;
9991 codec_dbg(codec
, "patch_ca0132\n");
9993 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
9997 spec
->codec
= codec
;
9999 /* Detect codec quirk */
10000 quirk
= snd_pci_quirk_lookup(codec
->bus
->pci
, ca0132_quirks
);
10002 spec
->quirk
= quirk
->value
;
10004 spec
->quirk
= QUIRK_NONE
;
10005 if (ca0132_quirk(spec
) == QUIRK_SBZ
)
10006 sbz_detect_quirk(codec
);
10008 if (ca0132_quirk(spec
) == QUIRK_ZXR_DBPRO
)
10009 codec
->patch_ops
= dbpro_patch_ops
;
10011 codec
->patch_ops
= ca0132_patch_ops
;
10013 codec
->pcm_format_first
= 1;
10014 codec
->no_sticky_stream
= 1;
10017 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
10018 spec
->num_mixers
= 1;
10020 /* Set which mixers each quirk uses. */
10021 switch (ca0132_quirk(spec
)) {
10023 spec
->mixers
[0] = desktop_mixer
;
10024 snd_hda_codec_set_name(codec
, "Sound Blaster Z");
10027 spec
->mixers
[0] = desktop_mixer
;
10028 snd_hda_codec_set_name(codec
, "Sound Blaster ZxR");
10030 case QUIRK_ZXR_DBPRO
:
10033 spec
->mixers
[0] = desktop_mixer
;
10034 snd_hda_codec_set_name(codec
, "Recon3D");
10037 spec
->mixers
[0] = r3di_mixer
;
10038 snd_hda_codec_set_name(codec
, "Recon3Di");
10041 spec
->mixers
[0] = desktop_mixer
;
10042 snd_hda_codec_set_name(codec
, "Sound BlasterX AE-5");
10045 spec
->mixers
[0] = desktop_mixer
;
10046 snd_hda_codec_set_name(codec
, "Sound Blaster AE-7");
10049 spec
->mixers
[0] = ca0132_mixer
;
10053 /* Setup whether or not to use alt functions/controls/pci_mmio */
10054 switch (ca0132_quirk(spec
)) {
10060 spec
->use_alt_controls
= true;
10061 spec
->use_alt_functions
= true;
10062 spec
->use_pci_mmio
= true;
10065 spec
->use_alt_controls
= true;
10066 spec
->use_alt_functions
= true;
10067 spec
->use_pci_mmio
= false;
10070 spec
->use_alt_controls
= false;
10071 spec
->use_alt_functions
= false;
10072 spec
->use_pci_mmio
= false;
10077 if (spec
->use_pci_mmio
) {
10078 spec
->mem_base
= pci_iomap(codec
->bus
->pci
, 2, 0xC20);
10079 if (spec
->mem_base
== NULL
) {
10080 codec_warn(codec
, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
10081 spec
->quirk
= QUIRK_NONE
;
10086 spec
->base_init_verbs
= ca0132_base_init_verbs
;
10087 spec
->base_exit_verbs
= ca0132_base_exit_verbs
;
10089 INIT_DELAYED_WORK(&spec
->unsol_hp_work
, ca0132_unsol_hp_delayed
);
10091 ca0132_init_chip(codec
);
10093 ca0132_config(codec
);
10095 err
= ca0132_prepare_verbs(codec
);
10099 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
10103 ca0132_setup_unsol(codec
);
10108 ca0132_free(codec
);
10115 static const struct hda_device_id snd_hda_id_ca0132
[] = {
10116 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132
),
10117 {} /* terminator */
10119 MODULE_DEVICE_TABLE(hdaudio
, snd_hda_id_ca0132
);
10121 MODULE_LICENSE("GPL");
10122 MODULE_DESCRIPTION("Creative Sound Core3D codec");
10124 static struct hda_codec_driver ca0132_driver
= {
10125 .id
= snd_hda_id_ca0132
,
10128 module_hda_codec_driver(ca0132_driver
);