2 * HD audio interface patch for Creative CA0132 chip
4 * Copyright (c) 2011, Creative Technology Ltd.
6 * Based on patch_ca0110.c
7 * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/mutex.h>
28 #include <linux/module.h>
29 #include <linux/firmware.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
33 #include <linux/pci.h>
35 #include <sound/core.h>
36 #include "hda_codec.h"
37 #include "hda_local.h"
38 #include "hda_auto_parser.h"
41 #include "ca0132_regs.h"
43 /* Enable this to see controls for tuning purpose. */
44 /*#define ENABLE_TUNING_CONTROLS*/
46 #ifdef ENABLE_TUNING_CONTROLS
47 #include <sound/tlv.h>
50 #define FLOAT_ZERO 0x00000000
51 #define FLOAT_ONE 0x3f800000
52 #define FLOAT_TWO 0x40000000
53 #define FLOAT_THREE 0x40400000
54 #define FLOAT_EIGHT 0x41000000
55 #define FLOAT_MINUS_5 0xc0a00000
57 #define UNSOL_TAG_DSP 0x16
59 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
60 #define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
62 #define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
63 #define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
64 #define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
66 #define MASTERCONTROL 0x80
67 #define MASTERCONTROL_ALLOC_DMA_CHAN 10
68 #define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
70 #define WIDGET_CHIP_CTRL 0x15
71 #define WIDGET_DSP_CTRL 0x16
73 #define MEM_CONNID_MICIN1 3
74 #define MEM_CONNID_MICIN2 5
75 #define MEM_CONNID_MICOUT1 12
76 #define MEM_CONNID_MICOUT2 14
77 #define MEM_CONNID_WUH 10
78 #define MEM_CONNID_DSP 16
79 #define MEM_CONNID_DMIC 100
84 #define EFX_FILE "ctefx.bin"
85 #define SBZ_EFX_FILE "ctefx-sbz.bin"
86 #define R3DI_EFX_FILE "ctefx-r3di.bin"
88 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
89 MODULE_FIRMWARE(EFX_FILE
);
90 MODULE_FIRMWARE(SBZ_EFX_FILE
);
91 MODULE_FIRMWARE(R3DI_EFX_FILE
);
94 static const char *const dirstr
[2] = { "Playback", "Capture" };
96 #define NUM_OF_OUTPUTS 3
108 /* Strings for Input Source Enum Control */
109 static const char *const in_src_str
[3] = {"Rear Mic", "Line", "Front Mic" };
110 #define IN_SRC_NUM_OF_INPUTS 3
118 #define VNODE_START_NID 0x80
119 VNID_SPK
= VNODE_START_NID
, /* Speaker vnid */
126 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
128 #define EFFECT_START_NID 0x90
129 #define OUT_EFFECT_START_NID EFFECT_START_NID
130 SURROUND
= OUT_EFFECT_START_NID
,
137 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
139 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
140 ECHO_CANCELLATION
= IN_EFFECT_START_NID
,
145 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
147 VOICEFX
= IN_EFFECT_END_NID
,
157 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
160 /* Effects values size*/
161 #define EFFECT_VALS_MAX_COUNT 12
164 * Default values for the effect slider controls, they are in order of their
165 * effect NID's. Surround, Crystalizer, Dialog Plus, Smart Volume, and then
168 static const unsigned int effect_slider_defaults
[] = {67, 65, 50, 74, 50};
169 /* Amount of effect level sliders for ca0132_alt controls. */
170 #define EFFECT_LEVEL_SLIDERS 5
172 /* Latency introduced by DSP blocks in milliseconds. */
173 #define DSP_CAPTURE_INIT_LATENCY 0
174 #define DSP_CRYSTAL_VOICE_LATENCY 124
175 #define DSP_PLAYBACK_INIT_LATENCY 13
176 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
177 #define DSP_SPEAKER_OUT_LATENCY 7
180 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
182 int mid
; /*effect module ID*/
183 int reqs
[EFFECT_VALS_MAX_COUNT
]; /*effect module request*/
184 int direct
; /* 0:output; 1:input*/
185 int params
; /* number of default non-on/off params */
186 /*effect default values, 1st is on/off. */
187 unsigned int def_vals
[EFFECT_VALS_MAX_COUNT
];
190 #define EFX_DIR_OUT 0
193 static const struct ct_effect ca0132_effects
[EFFECTS_COUNT
] = {
194 { .name
= "Surround",
198 .direct
= EFX_DIR_OUT
,
200 .def_vals
= {0x3F800000, 0x3F2B851F}
202 { .name
= "Crystalizer",
206 .direct
= EFX_DIR_OUT
,
208 .def_vals
= {0x3F800000, 0x3F266666}
210 { .name
= "Dialog Plus",
214 .direct
= EFX_DIR_OUT
,
216 .def_vals
= {0x00000000, 0x3F000000}
218 { .name
= "Smart Volume",
222 .direct
= EFX_DIR_OUT
,
224 .def_vals
= {0x3F800000, 0x3F3D70A4, 0x00000000}
229 .reqs
= {24, 23, 25},
230 .direct
= EFX_DIR_OUT
,
232 .def_vals
= {0x3F800000, 0x42A00000, 0x3F000000}
234 { .name
= "Equalizer",
237 .reqs
= {9, 10, 11, 12, 13, 14,
238 15, 16, 17, 18, 19, 20},
239 .direct
= EFX_DIR_OUT
,
241 .def_vals
= {0x00000000, 0x00000000, 0x00000000, 0x00000000,
242 0x00000000, 0x00000000, 0x00000000, 0x00000000,
243 0x00000000, 0x00000000, 0x00000000, 0x00000000}
245 { .name
= "Echo Cancellation",
246 .nid
= ECHO_CANCELLATION
,
248 .reqs
= {0, 1, 2, 3},
249 .direct
= EFX_DIR_IN
,
251 .def_vals
= {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
253 { .name
= "Voice Focus",
256 .reqs
= {6, 7, 8, 9},
257 .direct
= EFX_DIR_IN
,
259 .def_vals
= {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
265 .direct
= EFX_DIR_IN
,
267 .def_vals
= {0x00000000, 0x3F3D70A4}
269 { .name
= "Noise Reduction",
270 .nid
= NOISE_REDUCTION
,
273 .direct
= EFX_DIR_IN
,
275 .def_vals
= {0x3F800000, 0x3F000000}
280 .reqs
= {10, 11, 12, 13, 14, 15, 16, 17, 18},
281 .direct
= EFX_DIR_IN
,
283 .def_vals
= {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
284 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
289 /* Tuning controls */
290 #ifdef ENABLE_TUNING_CONTROLS
293 #define TUNING_CTL_START_NID 0xC0
294 WEDGE_ANGLE
= TUNING_CTL_START_NID
,
307 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
310 struct ct_tuning_ctl
{
311 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
312 hda_nid_t parent_nid
;
314 int mid
; /*effect module ID*/
315 int req
; /*effect module request*/
316 int direct
; /* 0:output; 1:input*/
317 unsigned int def_val
;/*effect default values*/
320 static const struct ct_tuning_ctl ca0132_tuning_ctls
[] = {
321 { .name
= "Wedge Angle",
322 .parent_nid
= VOICE_FOCUS
,
326 .direct
= EFX_DIR_IN
,
327 .def_val
= 0x41F00000
329 { .name
= "SVM Level",
330 .parent_nid
= MIC_SVM
,
334 .direct
= EFX_DIR_IN
,
335 .def_val
= 0x3F3D70A4
337 { .name
= "EQ Band0",
338 .parent_nid
= EQUALIZER
,
339 .nid
= EQUALIZER_BAND_0
,
342 .direct
= EFX_DIR_OUT
,
343 .def_val
= 0x00000000
345 { .name
= "EQ Band1",
346 .parent_nid
= EQUALIZER
,
347 .nid
= EQUALIZER_BAND_1
,
350 .direct
= EFX_DIR_OUT
,
351 .def_val
= 0x00000000
353 { .name
= "EQ Band2",
354 .parent_nid
= EQUALIZER
,
355 .nid
= EQUALIZER_BAND_2
,
358 .direct
= EFX_DIR_OUT
,
359 .def_val
= 0x00000000
361 { .name
= "EQ Band3",
362 .parent_nid
= EQUALIZER
,
363 .nid
= EQUALIZER_BAND_3
,
366 .direct
= EFX_DIR_OUT
,
367 .def_val
= 0x00000000
369 { .name
= "EQ Band4",
370 .parent_nid
= EQUALIZER
,
371 .nid
= EQUALIZER_BAND_4
,
374 .direct
= EFX_DIR_OUT
,
375 .def_val
= 0x00000000
377 { .name
= "EQ Band5",
378 .parent_nid
= EQUALIZER
,
379 .nid
= EQUALIZER_BAND_5
,
382 .direct
= EFX_DIR_OUT
,
383 .def_val
= 0x00000000
385 { .name
= "EQ Band6",
386 .parent_nid
= EQUALIZER
,
387 .nid
= EQUALIZER_BAND_6
,
390 .direct
= EFX_DIR_OUT
,
391 .def_val
= 0x00000000
393 { .name
= "EQ Band7",
394 .parent_nid
= EQUALIZER
,
395 .nid
= EQUALIZER_BAND_7
,
398 .direct
= EFX_DIR_OUT
,
399 .def_val
= 0x00000000
401 { .name
= "EQ Band8",
402 .parent_nid
= EQUALIZER
,
403 .nid
= EQUALIZER_BAND_8
,
406 .direct
= EFX_DIR_OUT
,
407 .def_val
= 0x00000000
409 { .name
= "EQ Band9",
410 .parent_nid
= EQUALIZER
,
411 .nid
= EQUALIZER_BAND_9
,
414 .direct
= EFX_DIR_OUT
,
415 .def_val
= 0x00000000
420 /* Voice FX Presets */
421 #define VOICEFX_MAX_PARAM_COUNT 9
427 int reqs
[VOICEFX_MAX_PARAM_COUNT
]; /*effect module request*/
430 struct ct_voicefx_preset
{
431 char *name
; /*preset name*/
432 unsigned int vals
[VOICEFX_MAX_PARAM_COUNT
];
435 static const struct ct_voicefx ca0132_voicefx
= {
436 .name
= "VoiceFX Capture Switch",
439 .reqs
= {10, 11, 12, 13, 14, 15, 16, 17, 18}
442 static const struct ct_voicefx_preset ca0132_voicefx_presets
[] = {
444 .vals
= { 0x00000000, 0x43C80000, 0x44AF0000,
445 0x44FA0000, 0x3F800000, 0x3F800000,
446 0x3F800000, 0x00000000, 0x00000000 }
448 { .name
= "Female2Male",
449 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
450 0x44FA0000, 0x3F19999A, 0x3F866666,
451 0x3F800000, 0x00000000, 0x00000000 }
453 { .name
= "Male2Female",
454 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
455 0x450AC000, 0x4017AE14, 0x3F6B851F,
456 0x3F800000, 0x00000000, 0x00000000 }
458 { .name
= "ScrappyKid",
459 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
460 0x44FA0000, 0x40400000, 0x3F28F5C3,
461 0x3F800000, 0x00000000, 0x00000000 }
464 .vals
= { 0x3F800000, 0x44324000, 0x44BB8000,
465 0x44E10000, 0x3FB33333, 0x3FB9999A,
466 0x3F800000, 0x3E3A2E43, 0x00000000 }
469 .vals
= { 0x3F800000, 0x43EA0000, 0x44A52000,
470 0x45098000, 0x3F266666, 0x3FC00000,
471 0x3F800000, 0x00000000, 0x00000000 }
474 .vals
= { 0x3F800000, 0x43C70000, 0x44AE6000,
475 0x45193000, 0x3F8E147B, 0x3F75C28F,
476 0x3F800000, 0x00000000, 0x00000000 }
479 .vals
= { 0x3F800000, 0x43930000, 0x44BEE000,
480 0x45007000, 0x3F451EB8, 0x3F7851EC,
481 0x3F800000, 0x00000000, 0x00000000 }
483 { .name
= "AlienBrute",
484 .vals
= { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
485 0x451F6000, 0x3F266666, 0x3FA7D945,
486 0x3F800000, 0x3CF5C28F, 0x00000000 }
489 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
490 0x44FA0000, 0x3FB2718B, 0x3F800000,
491 0xBC07010E, 0x00000000, 0x00000000 }
494 .vals
= { 0x3F800000, 0x43C20000, 0x44906000,
495 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
496 0x3F0A3D71, 0x00000000, 0x00000000 }
499 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
500 0x44FA0000, 0x3F800000, 0x3F800000,
501 0x3E4CCCCD, 0x00000000, 0x00000000 }
503 { .name
= "DeepVoice",
504 .vals
= { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
505 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
506 0x3F800000, 0x00000000, 0x00000000 }
508 { .name
= "Munchkin",
509 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
510 0x44FA0000, 0x3F800000, 0x3F1A043C,
511 0x3F800000, 0x00000000, 0x00000000 }
515 /* ca0132 EQ presets, taken from Windows Sound Blaster Z Driver */
517 #define EQ_PRESET_MAX_PARAM_COUNT 11
523 int reqs
[EQ_PRESET_MAX_PARAM_COUNT
]; /*effect module request*/
526 struct ct_eq_preset
{
527 char *name
; /*preset name*/
528 unsigned int vals
[EQ_PRESET_MAX_PARAM_COUNT
];
531 static const struct ct_eq ca0132_alt_eq_enum
= {
532 .name
= "FX: Equalizer Preset Switch",
533 .nid
= EQ_PRESET_ENUM
,
535 .reqs
= {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
539 static const struct ct_eq_preset ca0132_alt_eq_presets
[] = {
541 .vals
= { 0x00000000, 0x00000000, 0x00000000,
542 0x00000000, 0x00000000, 0x00000000,
543 0x00000000, 0x00000000, 0x00000000,
544 0x00000000, 0x00000000 }
546 { .name
= "Acoustic",
547 .vals
= { 0x00000000, 0x00000000, 0x3F8CCCCD,
548 0x40000000, 0x00000000, 0x00000000,
549 0x00000000, 0x00000000, 0x40000000,
550 0x40000000, 0x40000000 }
552 { .name
= "Classical",
553 .vals
= { 0x00000000, 0x00000000, 0x40C00000,
554 0x40C00000, 0x40466666, 0x00000000,
555 0x00000000, 0x00000000, 0x00000000,
556 0x40466666, 0x40466666 }
559 .vals
= { 0x00000000, 0xBF99999A, 0x00000000,
560 0x3FA66666, 0x3FA66666, 0x3F8CCCCD,
561 0x00000000, 0x00000000, 0x40000000,
562 0x40466666, 0x40800000 }
565 .vals
= { 0x00000000, 0xBF99999A, 0x40000000,
566 0x40466666, 0x40866666, 0xBF99999A,
567 0xBF99999A, 0x00000000, 0x00000000,
568 0x40800000, 0x40800000 }
571 .vals
= { 0x00000000, 0x00000000, 0x00000000,
572 0x3F8CCCCD, 0x40800000, 0x40800000,
573 0x40800000, 0x00000000, 0x3F8CCCCD,
574 0x40466666, 0x40466666 }
577 .vals
= { 0x00000000, 0x00000000, 0x40000000,
578 0x40000000, 0x00000000, 0x00000000,
579 0x00000000, 0x3F8CCCCD, 0x40000000,
580 0x40000000, 0x40000000 }
583 .vals
= { 0x00000000, 0xBFCCCCCD, 0x00000000,
584 0x40000000, 0x40000000, 0x00000000,
585 0xBF99999A, 0xBF99999A, 0x00000000,
586 0x40466666, 0x40C00000 }
589 .vals
= { 0x00000000, 0xBF99999A, 0xBF99999A,
590 0x3F8CCCCD, 0x40000000, 0xBF99999A,
591 0xBF99999A, 0x00000000, 0x00000000,
592 0x40800000, 0x40800000 }
595 .vals
= { 0x00000000, 0xC0000000, 0xBF99999A,
596 0xBF99999A, 0x00000000, 0x40466666,
597 0x40800000, 0x40466666, 0x00000000,
598 0x00000000, 0x3F8CCCCD }
602 /* DSP command sequences for ca0132_alt_select_out */
603 #define ALT_OUT_SET_MAX_COMMANDS 9 /* Max number of commands in sequence */
604 struct ca0132_alt_out_set
{
605 char *name
; /*preset name*/
606 unsigned char commands
;
607 unsigned int mids
[ALT_OUT_SET_MAX_COMMANDS
];
608 unsigned int reqs
[ALT_OUT_SET_MAX_COMMANDS
];
609 unsigned int vals
[ALT_OUT_SET_MAX_COMMANDS
];
612 static const struct ca0132_alt_out_set alt_out_presets
[] = {
613 { .name
= "Line Out",
615 .mids
= { 0x96, 0x96, 0x96, 0x8F,
617 .reqs
= { 0x19, 0x17, 0x18, 0x01,
619 .vals
= { 0x3F000000, 0x42A00000, 0x00000000,
620 0x00000000, 0x00000000, 0x00000000,
623 { .name
= "Headphone",
625 .mids
= { 0x96, 0x96, 0x96, 0x8F,
627 .reqs
= { 0x19, 0x17, 0x18, 0x01,
629 .vals
= { 0x3F000000, 0x42A00000, 0x00000000,
630 0x00000000, 0x00000000, 0x00000000,
633 { .name
= "Surround",
635 .mids
= { 0x96, 0x8F, 0x96, 0x96,
636 0x96, 0x96, 0x96, 0x96 },
637 .reqs
= { 0x18, 0x01, 0x1F, 0x15,
638 0x3A, 0x1A, 0x1B, 0x1C },
639 .vals
= { 0x00000000, 0x00000000, 0x00000000,
640 0x00000000, 0x00000000, 0x00000000,
641 0x00000000, 0x00000000 }
646 * DSP volume setting structs. Req 1 is left volume, req 2 is right volume,
647 * and I don't know what the third req is, but it's always zero. I assume it's
648 * some sort of update or set command to tell the DSP there's new volume info.
650 #define DSP_VOL_OUT 0
653 struct ct_dsp_volume_ctl
{
655 int mid
; /* module ID*/
656 unsigned int reqs
[3]; /* scp req ID */
659 static const struct ct_dsp_volume_ctl ca0132_alt_vol_ctls
[] = {
670 enum hda_cmd_vendor_io
{
672 VENDOR_DSPIO_SCP_WRITE_DATA_LOW
= 0x000,
673 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH
= 0x100,
675 VENDOR_DSPIO_STATUS
= 0xF01,
676 VENDOR_DSPIO_SCP_POST_READ_DATA
= 0x702,
677 VENDOR_DSPIO_SCP_READ_DATA
= 0xF02,
678 VENDOR_DSPIO_DSP_INIT
= 0x703,
679 VENDOR_DSPIO_SCP_POST_COUNT_QUERY
= 0x704,
680 VENDOR_DSPIO_SCP_READ_COUNT
= 0xF04,
682 /* for ChipIO node */
683 VENDOR_CHIPIO_ADDRESS_LOW
= 0x000,
684 VENDOR_CHIPIO_ADDRESS_HIGH
= 0x100,
685 VENDOR_CHIPIO_STREAM_FORMAT
= 0x200,
686 VENDOR_CHIPIO_DATA_LOW
= 0x300,
687 VENDOR_CHIPIO_DATA_HIGH
= 0x400,
689 VENDOR_CHIPIO_GET_PARAMETER
= 0xF00,
690 VENDOR_CHIPIO_STATUS
= 0xF01,
691 VENDOR_CHIPIO_HIC_POST_READ
= 0x702,
692 VENDOR_CHIPIO_HIC_READ_DATA
= 0xF03,
694 VENDOR_CHIPIO_8051_DATA_WRITE
= 0x707,
695 VENDOR_CHIPIO_8051_DATA_READ
= 0xF07,
697 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
= 0x70A,
698 VENDOR_CHIPIO_CT_EXTENSIONS_GET
= 0xF0A,
700 VENDOR_CHIPIO_PLL_PMU_WRITE
= 0x70C,
701 VENDOR_CHIPIO_PLL_PMU_READ
= 0xF0C,
702 VENDOR_CHIPIO_8051_ADDRESS_LOW
= 0x70D,
703 VENDOR_CHIPIO_8051_ADDRESS_HIGH
= 0x70E,
704 VENDOR_CHIPIO_FLAG_SET
= 0x70F,
705 VENDOR_CHIPIO_FLAGS_GET
= 0xF0F,
706 VENDOR_CHIPIO_PARAM_SET
= 0x710,
707 VENDOR_CHIPIO_PARAM_GET
= 0xF10,
709 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET
= 0x711,
710 VENDOR_CHIPIO_PORT_ALLOC_SET
= 0x712,
711 VENDOR_CHIPIO_PORT_ALLOC_GET
= 0xF12,
712 VENDOR_CHIPIO_PORT_FREE_SET
= 0x713,
714 VENDOR_CHIPIO_PARAM_EX_ID_GET
= 0xF17,
715 VENDOR_CHIPIO_PARAM_EX_ID_SET
= 0x717,
716 VENDOR_CHIPIO_PARAM_EX_VALUE_GET
= 0xF18,
717 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
= 0x718,
719 VENDOR_CHIPIO_DMIC_CTL_SET
= 0x788,
720 VENDOR_CHIPIO_DMIC_CTL_GET
= 0xF88,
721 VENDOR_CHIPIO_DMIC_PIN_SET
= 0x789,
722 VENDOR_CHIPIO_DMIC_PIN_GET
= 0xF89,
723 VENDOR_CHIPIO_DMIC_MCLK_SET
= 0x78A,
724 VENDOR_CHIPIO_DMIC_MCLK_GET
= 0xF8A,
726 VENDOR_CHIPIO_EAPD_SEL_SET
= 0x78D
732 enum control_flag_id
{
733 /* Connection manager stream setup is bypassed/enabled */
734 CONTROL_FLAG_C_MGR
= 0,
735 /* DSP DMA is bypassed/enabled */
736 CONTROL_FLAG_DMA
= 1,
737 /* 8051 'idle' mode is disabled/enabled */
738 CONTROL_FLAG_IDLE_ENABLE
= 2,
739 /* Tracker for the SPDIF-in path is bypassed/enabled */
740 CONTROL_FLAG_TRACKER
= 3,
741 /* DigitalOut to Spdif2Out connection is disabled/enabled */
742 CONTROL_FLAG_SPDIF2OUT
= 4,
743 /* Digital Microphone is disabled/enabled */
744 CONTROL_FLAG_DMIC
= 5,
745 /* ADC_B rate is 48 kHz/96 kHz */
746 CONTROL_FLAG_ADC_B_96KHZ
= 6,
747 /* ADC_C rate is 48 kHz/96 kHz */
748 CONTROL_FLAG_ADC_C_96KHZ
= 7,
749 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
750 CONTROL_FLAG_DAC_96KHZ
= 8,
751 /* DSP rate is 48 kHz/96 kHz */
752 CONTROL_FLAG_DSP_96KHZ
= 9,
753 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
754 CONTROL_FLAG_SRC_CLOCK_196MHZ
= 10,
755 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
756 CONTROL_FLAG_SRC_RATE_96KHZ
= 11,
757 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
758 CONTROL_FLAG_DECODE_LOOP
= 12,
759 /* De-emphasis filter on DAC-1 disabled/enabled */
760 CONTROL_FLAG_DAC1_DEEMPHASIS
= 13,
761 /* De-emphasis filter on DAC-2 disabled/enabled */
762 CONTROL_FLAG_DAC2_DEEMPHASIS
= 14,
763 /* De-emphasis filter on DAC-3 disabled/enabled */
764 CONTROL_FLAG_DAC3_DEEMPHASIS
= 15,
765 /* High-pass filter on ADC_B disabled/enabled */
766 CONTROL_FLAG_ADC_B_HIGH_PASS
= 16,
767 /* High-pass filter on ADC_C disabled/enabled */
768 CONTROL_FLAG_ADC_C_HIGH_PASS
= 17,
769 /* Common mode on Port_A disabled/enabled */
770 CONTROL_FLAG_PORT_A_COMMON_MODE
= 18,
771 /* Common mode on Port_D disabled/enabled */
772 CONTROL_FLAG_PORT_D_COMMON_MODE
= 19,
773 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
774 CONTROL_FLAG_PORT_A_10KOHM_LOAD
= 20,
775 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
776 CONTROL_FLAG_PORT_D_10KOHM_LOAD
= 21,
777 /* ASI rate is 48kHz/96kHz */
778 CONTROL_FLAG_ASI_96KHZ
= 22,
779 /* DAC power settings able to control attached ports no/yes */
780 CONTROL_FLAG_DACS_CONTROL_PORTS
= 23,
781 /* Clock Stop OK reporting is disabled/enabled */
782 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
= 24,
783 /* Number of control flags */
784 CONTROL_FLAGS_MAX
= (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
+1)
788 * Control parameter IDs
790 enum control_param_id
{
791 /* 0: None, 1: Mic1In*/
792 CONTROL_PARAM_VIP_SOURCE
= 1,
793 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
794 CONTROL_PARAM_SPDIF1_SOURCE
= 2,
795 /* Port A output stage gain setting to use when 16 Ohm output
796 * impedance is selected*/
797 CONTROL_PARAM_PORTA_160OHM_GAIN
= 8,
798 /* Port D output stage gain setting to use when 16 Ohm output
799 * impedance is selected*/
800 CONTROL_PARAM_PORTD_160OHM_GAIN
= 10,
804 /* Select stream with the given ID */
805 CONTROL_PARAM_STREAM_ID
= 24,
806 /* Source connection point for the selected stream */
807 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT
= 25,
808 /* Destination connection point for the selected stream */
809 CONTROL_PARAM_STREAM_DEST_CONN_POINT
= 26,
810 /* Number of audio channels in the selected stream */
811 CONTROL_PARAM_STREAMS_CHANNELS
= 27,
812 /*Enable control for the selected stream */
813 CONTROL_PARAM_STREAM_CONTROL
= 28,
815 /* Connection Point Control */
817 /* Select connection point with the given ID */
818 CONTROL_PARAM_CONN_POINT_ID
= 29,
819 /* Connection point sample rate */
820 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
= 30,
824 /* Select HDA node with the given ID */
825 CONTROL_PARAM_NODE_ID
= 31
829 * Dsp Io Status codes
831 enum hda_vendor_status_dspio
{
833 VENDOR_STATUS_DSPIO_OK
= 0x00,
834 /* Busy, unable to accept new command, the host must retry */
835 VENDOR_STATUS_DSPIO_BUSY
= 0x01,
836 /* SCP command queue is full */
837 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL
= 0x02,
838 /* SCP response queue is empty */
839 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
= 0x03
843 * Chip Io Status codes
845 enum hda_vendor_status_chipio
{
847 VENDOR_STATUS_CHIPIO_OK
= 0x00,
848 /* Busy, unable to accept new command, the host must retry */
849 VENDOR_STATUS_CHIPIO_BUSY
= 0x01
855 enum ca0132_sample_rate
{
875 SR_RATE_UNKNOWN
= 0x1F
878 enum dsp_download_state
{
879 DSP_DOWNLOAD_FAILED
= -1,
880 DSP_DOWNLOAD_INIT
= 0,
885 /* retrieve parameters from hda format */
886 #define get_hdafmt_chs(fmt) (fmt & 0xf)
887 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
888 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
889 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
896 const struct snd_kcontrol_new
*mixers
[5];
897 unsigned int num_mixers
;
898 const struct hda_verb
*base_init_verbs
;
899 const struct hda_verb
*base_exit_verbs
;
900 const struct hda_verb
*chip_init_verbs
;
901 const struct hda_verb
*desktop_init_verbs
;
902 struct hda_verb
*spec_init_verbs
;
903 struct auto_pin_cfg autocfg
;
905 /* Nodes configurations */
906 struct hda_multi_out multiout
;
907 hda_nid_t out_pins
[AUTO_CFG_MAX_OUTS
];
908 hda_nid_t dacs
[AUTO_CFG_MAX_OUTS
];
909 unsigned int num_outputs
;
910 hda_nid_t input_pins
[AUTO_PIN_LAST
];
911 hda_nid_t adcs
[AUTO_PIN_LAST
];
914 unsigned int num_inputs
;
915 hda_nid_t shared_mic_nid
;
916 hda_nid_t shared_out_nid
;
917 hda_nid_t unsol_tag_hp
;
918 hda_nid_t unsol_tag_front_hp
; /* for desktop ca0132 codecs */
919 hda_nid_t unsol_tag_amic1
;
922 struct mutex chipio_mutex
; /* chip access mutex */
925 /* DSP download related */
926 enum dsp_download_state dsp_state
;
927 unsigned int dsp_stream_id
;
928 unsigned int wait_scp
;
929 unsigned int wait_scp_header
;
930 unsigned int wait_num_data
;
931 unsigned int scp_resp_header
;
932 unsigned int scp_resp_data
[4];
933 unsigned int scp_resp_count
;
934 bool alt_firmware_present
;
935 bool startup_check_entered
;
938 /* mixer and effects related */
939 unsigned char dmic_ctl
;
942 long vnode_lvol
[VNODES_COUNT
];
943 long vnode_rvol
[VNODES_COUNT
];
944 long vnode_lswitch
[VNODES_COUNT
];
945 long vnode_rswitch
[VNODES_COUNT
];
946 long effects_switch
[EFFECTS_COUNT
];
949 /* ca0132_alt control related values */
950 unsigned char in_enum_val
;
951 unsigned char out_enum_val
;
952 unsigned char mic_boost_enum_val
;
953 unsigned char smart_volume_setting
;
954 long fx_ctl_val
[EFFECT_LEVEL_SLIDERS
];
955 long xbass_xover_freq
;
958 struct hda_vmaster_mute_hook vmaster_mute
;
961 struct hda_codec
*codec
;
962 struct delayed_work unsol_hp_work
;
965 #ifdef ENABLE_TUNING_CONTROLS
966 long cur_ctl_vals
[TUNING_CTLS_COUNT
];
969 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
970 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
974 void __iomem
*mem_base
;
977 * Whether or not to use the alt functions like alt_select_out,
978 * alt_select_in, etc. Only used on desktop codecs for now, because of
979 * surround sound support.
981 bool use_alt_functions
;
984 * Whether or not to use alt controls: volume effect sliders, EQ
985 * presets, smart volume presets, and new control names with FX prefix.
986 * Renames PlayEnhancement and CrystalVoice too.
988 bool use_alt_controls
;
992 * CA0132 quirks table
997 QUIRK_ALIENWARE_M17XR4
,
1003 static const struct hda_pintbl alienware_pincfgs
[] = {
1004 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1005 { 0x0c, 0x411111f0 }, /* N/A */
1006 { 0x0d, 0x411111f0 }, /* N/A */
1007 { 0x0e, 0x411111f0 }, /* N/A */
1008 { 0x0f, 0x0321101f }, /* HP */
1009 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1010 { 0x11, 0x03a11021 }, /* Mic */
1011 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1012 { 0x13, 0x411111f0 }, /* N/A */
1013 { 0x18, 0x411111f0 }, /* N/A */
1017 /* Sound Blaster Z pin configs taken from Windows Driver */
1018 static const struct hda_pintbl sbz_pincfgs
[] = {
1019 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1020 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1021 { 0x0d, 0x014510f0 }, /* Digital Out */
1022 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1023 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1024 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1025 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1026 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1027 { 0x13, 0x908700f0 }, /* What U Hear In*/
1028 { 0x18, 0x50d000f0 }, /* N/A */
1032 /* Recon3D pin configs taken from Windows Driver */
1033 static const struct hda_pintbl r3d_pincfgs
[] = {
1034 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1035 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1036 { 0x0d, 0x014510f0 }, /* Digital Out */
1037 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1038 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1039 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1040 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1041 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1042 { 0x13, 0x908700f0 }, /* What U Hear In*/
1043 { 0x18, 0x50d000f0 }, /* N/A */
1047 /* Recon3D integrated pin configs taken from Windows Driver */
1048 static const struct hda_pintbl r3di_pincfgs
[] = {
1049 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1050 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1051 { 0x0d, 0x014510f0 }, /* Digital Out */
1052 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1053 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1054 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1055 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1056 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1057 { 0x13, 0x908700f0 }, /* What U Hear In*/
1058 { 0x18, 0x500000f0 }, /* N/A */
1062 static const struct snd_pci_quirk ca0132_quirks
[] = {
1063 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4
),
1064 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE
),
1065 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE
),
1066 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE
),
1067 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ
),
1068 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ
),
1069 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI
),
1070 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI
),
1071 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI
),
1072 SND_PCI_QUIRK(0x3842, 0x1038, "EVGA X99 Classified", QUIRK_R3DI
),
1073 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D
),
1078 * CA0132 codec access
1080 static unsigned int codec_send_command(struct hda_codec
*codec
, hda_nid_t nid
,
1081 unsigned int verb
, unsigned int parm
, unsigned int *res
)
1083 unsigned int response
;
1084 response
= snd_hda_codec_read(codec
, nid
, 0, verb
, parm
);
1087 return ((response
== -1) ? -1 : 0);
1090 static int codec_set_converter_format(struct hda_codec
*codec
, hda_nid_t nid
,
1091 unsigned short converter_format
, unsigned int *res
)
1093 return codec_send_command(codec
, nid
, VENDOR_CHIPIO_STREAM_FORMAT
,
1094 converter_format
& 0xffff, res
);
1097 static int codec_set_converter_stream_channel(struct hda_codec
*codec
,
1098 hda_nid_t nid
, unsigned char stream
,
1099 unsigned char channel
, unsigned int *res
)
1101 unsigned char converter_stream_channel
= 0;
1103 converter_stream_channel
= (stream
<< 4) | (channel
& 0x0f);
1104 return codec_send_command(codec
, nid
, AC_VERB_SET_CHANNEL_STREAMID
,
1105 converter_stream_channel
, res
);
1108 /* Chip access helper function */
1109 static int chipio_send(struct hda_codec
*codec
,
1114 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1116 /* send bits of data specified by reg */
1118 res
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
1120 if (res
== VENDOR_STATUS_CHIPIO_OK
)
1123 } while (time_before(jiffies
, timeout
));
1129 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1131 static int chipio_write_address(struct hda_codec
*codec
,
1132 unsigned int chip_addx
)
1134 struct ca0132_spec
*spec
= codec
->spec
;
1137 if (spec
->curr_chip_addx
== chip_addx
)
1140 /* send low 16 bits of the address */
1141 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_LOW
,
1142 chip_addx
& 0xffff);
1145 /* send high 16 bits of the address */
1146 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_HIGH
,
1150 spec
->curr_chip_addx
= (res
< 0) ? ~0U : chip_addx
;
1156 * Write data through the vendor widget -- NOT protected by the Mutex!
1158 static int chipio_write_data(struct hda_codec
*codec
, unsigned int data
)
1160 struct ca0132_spec
*spec
= codec
->spec
;
1163 /* send low 16 bits of the data */
1164 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_LOW
, data
& 0xffff);
1167 /* send high 16 bits of the data */
1168 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_HIGH
,
1172 /*If no error encountered, automatically increment the address
1173 as per chip behaviour*/
1174 spec
->curr_chip_addx
= (res
!= -EIO
) ?
1175 (spec
->curr_chip_addx
+ 4) : ~0U;
1180 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1182 static int chipio_write_data_multiple(struct hda_codec
*codec
,
1189 codec_dbg(codec
, "chipio_write_data null ptr\n");
1193 while ((count
-- != 0) && (status
== 0))
1194 status
= chipio_write_data(codec
, *data
++);
1201 * Read data through the vendor widget -- NOT protected by the Mutex!
1203 static int chipio_read_data(struct hda_codec
*codec
, unsigned int *data
)
1205 struct ca0132_spec
*spec
= codec
->spec
;
1209 res
= chipio_send(codec
, VENDOR_CHIPIO_HIC_POST_READ
, 0);
1213 res
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
1218 *data
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
1219 VENDOR_CHIPIO_HIC_READ_DATA
,
1223 /*If no error encountered, automatically increment the address
1224 as per chip behaviour*/
1225 spec
->curr_chip_addx
= (res
!= -EIO
) ?
1226 (spec
->curr_chip_addx
+ 4) : ~0U;
1231 * Write given value to the given address through the chip I/O widget.
1232 * protected by the Mutex
1234 static int chipio_write(struct hda_codec
*codec
,
1235 unsigned int chip_addx
, const unsigned int data
)
1237 struct ca0132_spec
*spec
= codec
->spec
;
1240 mutex_lock(&spec
->chipio_mutex
);
1242 /* write the address, and if successful proceed to write data */
1243 err
= chipio_write_address(codec
, chip_addx
);
1247 err
= chipio_write_data(codec
, data
);
1252 mutex_unlock(&spec
->chipio_mutex
);
1257 * Write given value to the given address through the chip I/O widget.
1258 * not protected by the Mutex
1260 static int chipio_write_no_mutex(struct hda_codec
*codec
,
1261 unsigned int chip_addx
, const unsigned int data
)
1266 /* write the address, and if successful proceed to write data */
1267 err
= chipio_write_address(codec
, chip_addx
);
1271 err
= chipio_write_data(codec
, data
);
1280 * Write multiple values to the given address through the chip I/O widget.
1281 * protected by the Mutex
1283 static int chipio_write_multiple(struct hda_codec
*codec
,
1288 struct ca0132_spec
*spec
= codec
->spec
;
1291 mutex_lock(&spec
->chipio_mutex
);
1292 status
= chipio_write_address(codec
, chip_addx
);
1296 status
= chipio_write_data_multiple(codec
, data
, count
);
1298 mutex_unlock(&spec
->chipio_mutex
);
1304 * Read the given address through the chip I/O widget
1305 * protected by the Mutex
1307 static int chipio_read(struct hda_codec
*codec
,
1308 unsigned int chip_addx
, unsigned int *data
)
1310 struct ca0132_spec
*spec
= codec
->spec
;
1313 mutex_lock(&spec
->chipio_mutex
);
1315 /* write the address, and if successful proceed to write data */
1316 err
= chipio_write_address(codec
, chip_addx
);
1320 err
= chipio_read_data(codec
, data
);
1325 mutex_unlock(&spec
->chipio_mutex
);
1330 * Set chip control flags through the chip I/O widget.
1332 static void chipio_set_control_flag(struct hda_codec
*codec
,
1333 enum control_flag_id flag_id
,
1337 unsigned int flag_bit
;
1339 flag_bit
= (flag_state
? 1 : 0);
1340 val
= (flag_bit
<< 7) | (flag_id
);
1341 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1342 VENDOR_CHIPIO_FLAG_SET
, val
);
1346 * Set chip parameters through the chip I/O widget.
1348 static void chipio_set_control_param(struct hda_codec
*codec
,
1349 enum control_param_id param_id
, int param_val
)
1351 struct ca0132_spec
*spec
= codec
->spec
;
1354 if ((param_id
< 32) && (param_val
< 8)) {
1355 val
= (param_val
<< 5) | (param_id
);
1356 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1357 VENDOR_CHIPIO_PARAM_SET
, val
);
1359 mutex_lock(&spec
->chipio_mutex
);
1360 if (chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0) == 0) {
1361 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1362 VENDOR_CHIPIO_PARAM_EX_ID_SET
,
1364 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1365 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
,
1368 mutex_unlock(&spec
->chipio_mutex
);
1373 * Set chip parameters through the chip I/O widget. NO MUTEX.
1375 static void chipio_set_control_param_no_mutex(struct hda_codec
*codec
,
1376 enum control_param_id param_id
, int param_val
)
1380 if ((param_id
< 32) && (param_val
< 8)) {
1381 val
= (param_val
<< 5) | (param_id
);
1382 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1383 VENDOR_CHIPIO_PARAM_SET
, val
);
1385 if (chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0) == 0) {
1386 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1387 VENDOR_CHIPIO_PARAM_EX_ID_SET
,
1389 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1390 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
,
1396 * Connect stream to a source point, and then connect
1397 * that source point to a destination point.
1399 static void chipio_set_stream_source_dest(struct hda_codec
*codec
,
1400 int streamid
, int source_point
, int dest_point
)
1402 chipio_set_control_param_no_mutex(codec
,
1403 CONTROL_PARAM_STREAM_ID
, streamid
);
1404 chipio_set_control_param_no_mutex(codec
,
1405 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT
, source_point
);
1406 chipio_set_control_param_no_mutex(codec
,
1407 CONTROL_PARAM_STREAM_DEST_CONN_POINT
, dest_point
);
1411 * Set number of channels in the selected stream.
1413 static void chipio_set_stream_channels(struct hda_codec
*codec
,
1414 int streamid
, unsigned int channels
)
1416 chipio_set_control_param_no_mutex(codec
,
1417 CONTROL_PARAM_STREAM_ID
, streamid
);
1418 chipio_set_control_param_no_mutex(codec
,
1419 CONTROL_PARAM_STREAMS_CHANNELS
, channels
);
1423 * Enable/Disable audio stream.
1425 static void chipio_set_stream_control(struct hda_codec
*codec
,
1426 int streamid
, int enable
)
1428 chipio_set_control_param_no_mutex(codec
,
1429 CONTROL_PARAM_STREAM_ID
, streamid
);
1430 chipio_set_control_param_no_mutex(codec
,
1431 CONTROL_PARAM_STREAM_CONTROL
, enable
);
1436 * Set sampling rate of the connection point. NO MUTEX.
1438 static void chipio_set_conn_rate_no_mutex(struct hda_codec
*codec
,
1439 int connid
, enum ca0132_sample_rate rate
)
1441 chipio_set_control_param_no_mutex(codec
,
1442 CONTROL_PARAM_CONN_POINT_ID
, connid
);
1443 chipio_set_control_param_no_mutex(codec
,
1444 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
, rate
);
1448 * Set sampling rate of the connection point.
1450 static void chipio_set_conn_rate(struct hda_codec
*codec
,
1451 int connid
, enum ca0132_sample_rate rate
)
1453 chipio_set_control_param(codec
, CONTROL_PARAM_CONN_POINT_ID
, connid
);
1454 chipio_set_control_param(codec
, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
,
1461 static void chipio_enable_clocks(struct hda_codec
*codec
)
1463 struct ca0132_spec
*spec
= codec
->spec
;
1465 mutex_lock(&spec
->chipio_mutex
);
1466 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1467 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0);
1468 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1469 VENDOR_CHIPIO_PLL_PMU_WRITE
, 0xff);
1470 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1471 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 5);
1472 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1473 VENDOR_CHIPIO_PLL_PMU_WRITE
, 0x0b);
1474 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1475 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 6);
1476 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1477 VENDOR_CHIPIO_PLL_PMU_WRITE
, 0xff);
1478 mutex_unlock(&spec
->chipio_mutex
);
1482 * CA0132 DSP IO stuffs
1484 static int dspio_send(struct hda_codec
*codec
, unsigned int reg
,
1488 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1490 /* send bits of data specified by reg to dsp */
1492 res
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0, reg
, data
);
1493 if ((res
>= 0) && (res
!= VENDOR_STATUS_DSPIO_BUSY
))
1496 } while (time_before(jiffies
, timeout
));
1502 * Wait for DSP to be ready for commands
1504 static void dspio_write_wait(struct hda_codec
*codec
)
1507 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1510 status
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
1511 VENDOR_DSPIO_STATUS
, 0);
1512 if ((status
== VENDOR_STATUS_DSPIO_OK
) ||
1513 (status
== VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
))
1516 } while (time_before(jiffies
, timeout
));
1520 * Write SCP data to DSP
1522 static int dspio_write(struct hda_codec
*codec
, unsigned int scp_data
)
1524 struct ca0132_spec
*spec
= codec
->spec
;
1527 dspio_write_wait(codec
);
1529 mutex_lock(&spec
->chipio_mutex
);
1530 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_WRITE_DATA_LOW
,
1535 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH
,
1540 /* OK, now check if the write itself has executed*/
1541 status
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
1542 VENDOR_DSPIO_STATUS
, 0);
1544 mutex_unlock(&spec
->chipio_mutex
);
1546 return (status
== VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL
) ?
1551 * Write multiple SCP data to DSP
1553 static int dspio_write_multiple(struct hda_codec
*codec
,
1554 unsigned int *buffer
, unsigned int size
)
1563 while (count
< size
) {
1564 status
= dspio_write(codec
, *buffer
++);
1573 static int dspio_read(struct hda_codec
*codec
, unsigned int *data
)
1577 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_POST_READ_DATA
, 0);
1581 status
= dspio_send(codec
, VENDOR_DSPIO_STATUS
, 0);
1582 if (status
== -EIO
||
1583 status
== VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
)
1586 *data
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
1587 VENDOR_DSPIO_SCP_READ_DATA
, 0);
1592 static int dspio_read_multiple(struct hda_codec
*codec
, unsigned int *buffer
,
1593 unsigned int *buf_size
, unsigned int size_count
)
1596 unsigned int size
= *buf_size
;
1598 unsigned int skip_count
;
1605 while (count
< size
&& count
< size_count
) {
1606 status
= dspio_read(codec
, buffer
++);
1614 while (skip_count
< size
) {
1615 status
= dspio_read(codec
, &dummy
);
1627 * Construct the SCP header using corresponding fields
1629 static inline unsigned int
1630 make_scp_header(unsigned int target_id
, unsigned int source_id
,
1631 unsigned int get_flag
, unsigned int req
,
1632 unsigned int device_flag
, unsigned int resp_flag
,
1633 unsigned int error_flag
, unsigned int data_size
)
1635 unsigned int header
= 0;
1637 header
= (data_size
& 0x1f) << 27;
1638 header
|= (error_flag
& 0x01) << 26;
1639 header
|= (resp_flag
& 0x01) << 25;
1640 header
|= (device_flag
& 0x01) << 24;
1641 header
|= (req
& 0x7f) << 17;
1642 header
|= (get_flag
& 0x01) << 16;
1643 header
|= (source_id
& 0xff) << 8;
1644 header
|= target_id
& 0xff;
1650 * Extract corresponding fields from SCP header
1653 extract_scp_header(unsigned int header
,
1654 unsigned int *target_id
, unsigned int *source_id
,
1655 unsigned int *get_flag
, unsigned int *req
,
1656 unsigned int *device_flag
, unsigned int *resp_flag
,
1657 unsigned int *error_flag
, unsigned int *data_size
)
1660 *data_size
= (header
>> 27) & 0x1f;
1662 *error_flag
= (header
>> 26) & 0x01;
1664 *resp_flag
= (header
>> 25) & 0x01;
1666 *device_flag
= (header
>> 24) & 0x01;
1668 *req
= (header
>> 17) & 0x7f;
1670 *get_flag
= (header
>> 16) & 0x01;
1672 *source_id
= (header
>> 8) & 0xff;
1674 *target_id
= header
& 0xff;
1677 #define SCP_MAX_DATA_WORDS (16)
1679 /* Structure to contain any SCP message */
1682 unsigned int data
[SCP_MAX_DATA_WORDS
];
1685 static void dspio_clear_response_queue(struct hda_codec
*codec
)
1687 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1688 unsigned int dummy
= 0;
1691 /* clear all from the response queue */
1693 status
= dspio_read(codec
, &dummy
);
1694 } while (status
== 0 && time_before(jiffies
, timeout
));
1697 static int dspio_get_response_data(struct hda_codec
*codec
)
1699 struct ca0132_spec
*spec
= codec
->spec
;
1700 unsigned int data
= 0;
1703 if (dspio_read(codec
, &data
) < 0)
1706 if ((data
& 0x00ffffff) == spec
->wait_scp_header
) {
1707 spec
->scp_resp_header
= data
;
1708 spec
->scp_resp_count
= data
>> 27;
1709 count
= spec
->wait_num_data
;
1710 dspio_read_multiple(codec
, spec
->scp_resp_data
,
1711 &spec
->scp_resp_count
, count
);
1719 * Send SCP message to DSP
1721 static int dspio_send_scp_message(struct hda_codec
*codec
,
1722 unsigned char *send_buf
,
1723 unsigned int send_buf_size
,
1724 unsigned char *return_buf
,
1725 unsigned int return_buf_size
,
1726 unsigned int *bytes_returned
)
1728 struct ca0132_spec
*spec
= codec
->spec
;
1730 unsigned int scp_send_size
= 0;
1731 unsigned int total_size
;
1732 bool waiting_for_resp
= false;
1733 unsigned int header
;
1734 struct scp_msg
*ret_msg
;
1735 unsigned int resp_src_id
, resp_target_id
;
1736 unsigned int data_size
, src_id
, target_id
, get_flag
, device_flag
;
1739 *bytes_returned
= 0;
1741 /* get scp header from buffer */
1742 header
= *((unsigned int *)send_buf
);
1743 extract_scp_header(header
, &target_id
, &src_id
, &get_flag
, NULL
,
1744 &device_flag
, NULL
, NULL
, &data_size
);
1745 scp_send_size
= data_size
+ 1;
1746 total_size
= (scp_send_size
* 4);
1748 if (send_buf_size
< total_size
)
1751 if (get_flag
|| device_flag
) {
1752 if (!return_buf
|| return_buf_size
< 4 || !bytes_returned
)
1755 spec
->wait_scp_header
= *((unsigned int *)send_buf
);
1757 /* swap source id with target id */
1758 resp_target_id
= src_id
;
1759 resp_src_id
= target_id
;
1760 spec
->wait_scp_header
&= 0xffff0000;
1761 spec
->wait_scp_header
|= (resp_src_id
<< 8) | (resp_target_id
);
1762 spec
->wait_num_data
= return_buf_size
/sizeof(unsigned int) - 1;
1764 waiting_for_resp
= true;
1767 status
= dspio_write_multiple(codec
, (unsigned int *)send_buf
,
1774 if (waiting_for_resp
) {
1775 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1776 memset(return_buf
, 0, return_buf_size
);
1779 } while (spec
->wait_scp
&& time_before(jiffies
, timeout
));
1780 waiting_for_resp
= false;
1781 if (!spec
->wait_scp
) {
1782 ret_msg
= (struct scp_msg
*)return_buf
;
1783 memcpy(&ret_msg
->hdr
, &spec
->scp_resp_header
, 4);
1784 memcpy(&ret_msg
->data
, spec
->scp_resp_data
,
1785 spec
->wait_num_data
);
1786 *bytes_returned
= (spec
->scp_resp_count
+ 1) * 4;
1798 * Prepare and send the SCP message to DSP
1799 * @codec: the HDA codec
1800 * @mod_id: ID of the DSP module to send the command
1801 * @req: ID of request to send to the DSP module
1803 * @data: pointer to the data to send with the request, request specific
1804 * @len: length of the data, in bytes
1805 * @reply: point to the buffer to hold data returned for a reply
1806 * @reply_len: length of the reply buffer returned from GET
1808 * Returns zero or a negative error code.
1810 static int dspio_scp(struct hda_codec
*codec
,
1811 int mod_id
, int src_id
, int req
, int dir
, const void *data
,
1812 unsigned int len
, void *reply
, unsigned int *reply_len
)
1815 struct scp_msg scp_send
, scp_reply
;
1816 unsigned int ret_bytes
, send_size
, ret_size
;
1817 unsigned int send_get_flag
, reply_resp_flag
, reply_error_flag
;
1818 unsigned int reply_data_size
;
1820 memset(&scp_send
, 0, sizeof(scp_send
));
1821 memset(&scp_reply
, 0, sizeof(scp_reply
));
1823 if ((len
!= 0 && data
== NULL
) || (len
> SCP_MAX_DATA_WORDS
))
1826 if (dir
== SCP_GET
&& reply
== NULL
) {
1827 codec_dbg(codec
, "dspio_scp get but has no buffer\n");
1831 if (reply
!= NULL
&& (reply_len
== NULL
|| (*reply_len
== 0))) {
1832 codec_dbg(codec
, "dspio_scp bad resp buf len parms\n");
1836 scp_send
.hdr
= make_scp_header(mod_id
, src_id
, (dir
== SCP_GET
), req
,
1837 0, 0, 0, len
/sizeof(unsigned int));
1838 if (data
!= NULL
&& len
> 0) {
1839 len
= min((unsigned int)(sizeof(scp_send
.data
)), len
);
1840 memcpy(scp_send
.data
, data
, len
);
1844 send_size
= sizeof(unsigned int) + len
;
1845 status
= dspio_send_scp_message(codec
, (unsigned char *)&scp_send
,
1846 send_size
, (unsigned char *)&scp_reply
,
1847 sizeof(scp_reply
), &ret_bytes
);
1850 codec_dbg(codec
, "dspio_scp: send scp msg failed\n");
1854 /* extract send and reply headers members */
1855 extract_scp_header(scp_send
.hdr
, NULL
, NULL
, &send_get_flag
,
1856 NULL
, NULL
, NULL
, NULL
, NULL
);
1857 extract_scp_header(scp_reply
.hdr
, NULL
, NULL
, NULL
, NULL
, NULL
,
1858 &reply_resp_flag
, &reply_error_flag
,
1864 if (reply_resp_flag
&& !reply_error_flag
) {
1865 ret_size
= (ret_bytes
- sizeof(scp_reply
.hdr
))
1866 / sizeof(unsigned int);
1868 if (*reply_len
< ret_size
*sizeof(unsigned int)) {
1869 codec_dbg(codec
, "reply too long for buf\n");
1871 } else if (ret_size
!= reply_data_size
) {
1872 codec_dbg(codec
, "RetLen and HdrLen .NE.\n");
1874 } else if (!reply
) {
1875 codec_dbg(codec
, "NULL reply\n");
1878 *reply_len
= ret_size
*sizeof(unsigned int);
1879 memcpy(reply
, scp_reply
.data
, *reply_len
);
1882 codec_dbg(codec
, "reply ill-formed or errflag set\n");
1890 * Set DSP parameters
1892 static int dspio_set_param(struct hda_codec
*codec
, int mod_id
,
1893 int src_id
, int req
, const void *data
, unsigned int len
)
1895 return dspio_scp(codec
, mod_id
, src_id
, req
, SCP_SET
, data
, len
, NULL
,
1899 static int dspio_set_uint_param(struct hda_codec
*codec
, int mod_id
,
1900 int req
, const unsigned int data
)
1902 return dspio_set_param(codec
, mod_id
, 0x20, req
, &data
,
1903 sizeof(unsigned int));
1906 static int dspio_set_uint_param_no_source(struct hda_codec
*codec
, int mod_id
,
1907 int req
, const unsigned int data
)
1909 return dspio_set_param(codec
, mod_id
, 0x00, req
, &data
,
1910 sizeof(unsigned int));
1914 * Allocate a DSP DMA channel via an SCP message
1916 static int dspio_alloc_dma_chan(struct hda_codec
*codec
, unsigned int *dma_chan
)
1919 unsigned int size
= sizeof(dma_chan
);
1921 codec_dbg(codec
, " dspio_alloc_dma_chan() -- begin\n");
1922 status
= dspio_scp(codec
, MASTERCONTROL
, 0x20,
1923 MASTERCONTROL_ALLOC_DMA_CHAN
, SCP_GET
, NULL
, 0,
1927 codec_dbg(codec
, "dspio_alloc_dma_chan: SCP Failed\n");
1931 if ((*dma_chan
+ 1) == 0) {
1932 codec_dbg(codec
, "no free dma channels to allocate\n");
1936 codec_dbg(codec
, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan
);
1937 codec_dbg(codec
, " dspio_alloc_dma_chan() -- complete\n");
1943 * Free a DSP DMA via an SCP message
1945 static int dspio_free_dma_chan(struct hda_codec
*codec
, unsigned int dma_chan
)
1948 unsigned int dummy
= 0;
1950 codec_dbg(codec
, " dspio_free_dma_chan() -- begin\n");
1951 codec_dbg(codec
, "dspio_free_dma_chan: chan=%d\n", dma_chan
);
1953 status
= dspio_scp(codec
, MASTERCONTROL
, 0x20,
1954 MASTERCONTROL_ALLOC_DMA_CHAN
, SCP_SET
, &dma_chan
,
1955 sizeof(dma_chan
), NULL
, &dummy
);
1958 codec_dbg(codec
, "dspio_free_dma_chan: SCP Failed\n");
1962 codec_dbg(codec
, " dspio_free_dma_chan() -- complete\n");
1970 static int dsp_set_run_state(struct hda_codec
*codec
)
1972 unsigned int dbg_ctrl_reg
;
1973 unsigned int halt_state
;
1976 err
= chipio_read(codec
, DSP_DBGCNTL_INST_OFFSET
, &dbg_ctrl_reg
);
1980 halt_state
= (dbg_ctrl_reg
& DSP_DBGCNTL_STATE_MASK
) >>
1981 DSP_DBGCNTL_STATE_LOBIT
;
1983 if (halt_state
!= 0) {
1984 dbg_ctrl_reg
&= ~((halt_state
<< DSP_DBGCNTL_SS_LOBIT
) &
1985 DSP_DBGCNTL_SS_MASK
);
1986 err
= chipio_write(codec
, DSP_DBGCNTL_INST_OFFSET
,
1991 dbg_ctrl_reg
|= (halt_state
<< DSP_DBGCNTL_EXEC_LOBIT
) &
1992 DSP_DBGCNTL_EXEC_MASK
;
1993 err
= chipio_write(codec
, DSP_DBGCNTL_INST_OFFSET
,
2005 static int dsp_reset(struct hda_codec
*codec
)
2010 codec_dbg(codec
, "dsp_reset\n");
2012 res
= dspio_send(codec
, VENDOR_DSPIO_DSP_INIT
, 0);
2014 } while (res
== -EIO
&& retry
);
2017 codec_dbg(codec
, "dsp_reset timeout\n");
2025 * Convert chip address to DSP address
2027 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx
,
2028 bool *code
, bool *yram
)
2030 *code
= *yram
= false;
2032 if (UC_RANGE(chip_addx
, 1)) {
2034 return UC_OFF(chip_addx
);
2035 } else if (X_RANGE_ALL(chip_addx
, 1)) {
2036 return X_OFF(chip_addx
);
2037 } else if (Y_RANGE_ALL(chip_addx
, 1)) {
2039 return Y_OFF(chip_addx
);
2042 return INVALID_CHIP_ADDRESS
;
2046 * Check if the DSP DMA is active
2048 static bool dsp_is_dma_active(struct hda_codec
*codec
, unsigned int dma_chan
)
2050 unsigned int dma_chnlstart_reg
;
2052 chipio_read(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
, &dma_chnlstart_reg
);
2054 return ((dma_chnlstart_reg
& (1 <<
2055 (DSPDMAC_CHNLSTART_EN_LOBIT
+ dma_chan
))) != 0);
2058 static int dsp_dma_setup_common(struct hda_codec
*codec
,
2059 unsigned int chip_addx
,
2060 unsigned int dma_chan
,
2061 unsigned int port_map_mask
,
2065 unsigned int chnl_prop
;
2066 unsigned int dsp_addx
;
2067 unsigned int active
;
2070 codec_dbg(codec
, "-- dsp_dma_setup_common() -- Begin ---------\n");
2072 if (dma_chan
>= DSPDMAC_DMA_CFG_CHANNEL_COUNT
) {
2073 codec_dbg(codec
, "dma chan num invalid\n");
2077 if (dsp_is_dma_active(codec
, dma_chan
)) {
2078 codec_dbg(codec
, "dma already active\n");
2082 dsp_addx
= dsp_chip_to_dsp_addx(chip_addx
, &code
, &yram
);
2084 if (dsp_addx
== INVALID_CHIP_ADDRESS
) {
2085 codec_dbg(codec
, "invalid chip addr\n");
2089 chnl_prop
= DSPDMAC_CHNLPROP_AC_MASK
;
2092 codec_dbg(codec
, " dsp_dma_setup_common() start reg pgm\n");
2095 status
= chipio_read(codec
, DSPDMAC_CHNLPROP_INST_OFFSET
,
2099 codec_dbg(codec
, "read CHNLPROP Reg fail\n");
2102 codec_dbg(codec
, "dsp_dma_setup_common() Read CHNLPROP\n");
2106 chnl_prop
&= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT
+ dma_chan
));
2108 chnl_prop
|= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT
+ dma_chan
));
2110 chnl_prop
&= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT
+ dma_chan
));
2112 status
= chipio_write(codec
, DSPDMAC_CHNLPROP_INST_OFFSET
, chnl_prop
);
2114 codec_dbg(codec
, "write CHNLPROP Reg fail\n");
2117 codec_dbg(codec
, " dsp_dma_setup_common() Write CHNLPROP\n");
2120 status
= chipio_read(codec
, DSPDMAC_ACTIVE_INST_OFFSET
,
2124 codec_dbg(codec
, "read ACTIVE Reg fail\n");
2127 codec_dbg(codec
, "dsp_dma_setup_common() Read ACTIVE\n");
2130 active
&= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT
+ dma_chan
))) &
2131 DSPDMAC_ACTIVE_AAR_MASK
;
2133 status
= chipio_write(codec
, DSPDMAC_ACTIVE_INST_OFFSET
, active
);
2135 codec_dbg(codec
, "write ACTIVE Reg fail\n");
2139 codec_dbg(codec
, " dsp_dma_setup_common() Write ACTIVE\n");
2141 status
= chipio_write(codec
, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan
),
2144 codec_dbg(codec
, "write AUDCHSEL Reg fail\n");
2147 codec_dbg(codec
, " dsp_dma_setup_common() Write AUDCHSEL\n");
2149 status
= chipio_write(codec
, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan
),
2150 DSPDMAC_IRQCNT_BICNT_MASK
| DSPDMAC_IRQCNT_CICNT_MASK
);
2152 codec_dbg(codec
, "write IRQCNT Reg fail\n");
2155 codec_dbg(codec
, " dsp_dma_setup_common() Write IRQCNT\n");
2158 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2159 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2160 chip_addx
, dsp_addx
, dma_chan
,
2161 port_map_mask
, chnl_prop
, active
);
2163 codec_dbg(codec
, "-- dsp_dma_setup_common() -- Complete ------\n");
2169 * Setup the DSP DMA per-transfer-specific registers
2171 static int dsp_dma_setup(struct hda_codec
*codec
,
2172 unsigned int chip_addx
,
2174 unsigned int dma_chan
)
2178 unsigned int dsp_addx
;
2179 unsigned int addr_field
;
2180 unsigned int incr_field
;
2181 unsigned int base_cnt
;
2182 unsigned int cur_cnt
;
2183 unsigned int dma_cfg
= 0;
2184 unsigned int adr_ofs
= 0;
2185 unsigned int xfr_cnt
= 0;
2186 const unsigned int max_dma_count
= 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT
-
2187 DSPDMAC_XFRCNT_BCNT_LOBIT
+ 1);
2189 codec_dbg(codec
, "-- dsp_dma_setup() -- Begin ---------\n");
2191 if (count
> max_dma_count
) {
2192 codec_dbg(codec
, "count too big\n");
2196 dsp_addx
= dsp_chip_to_dsp_addx(chip_addx
, &code
, &yram
);
2197 if (dsp_addx
== INVALID_CHIP_ADDRESS
) {
2198 codec_dbg(codec
, "invalid chip addr\n");
2202 codec_dbg(codec
, " dsp_dma_setup() start reg pgm\n");
2204 addr_field
= dsp_addx
<< DSPDMAC_DMACFG_DBADR_LOBIT
;
2210 addr_field
|= (1 << DSPDMAC_DMACFG_DBADR_LOBIT
);
2212 incr_field
= (1 << DSPDMAC_DMACFG_AINCR_LOBIT
);
2215 dma_cfg
= addr_field
+ incr_field
;
2216 status
= chipio_write(codec
, DSPDMAC_DMACFG_INST_OFFSET(dma_chan
),
2219 codec_dbg(codec
, "write DMACFG Reg fail\n");
2222 codec_dbg(codec
, " dsp_dma_setup() Write DMACFG\n");
2224 adr_ofs
= (count
- 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT
+
2227 status
= chipio_write(codec
, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan
),
2230 codec_dbg(codec
, "write DSPADROFS Reg fail\n");
2233 codec_dbg(codec
, " dsp_dma_setup() Write DSPADROFS\n");
2235 base_cnt
= (count
- 1) << DSPDMAC_XFRCNT_BCNT_LOBIT
;
2237 cur_cnt
= (count
- 1) << DSPDMAC_XFRCNT_CCNT_LOBIT
;
2239 xfr_cnt
= base_cnt
| cur_cnt
;
2241 status
= chipio_write(codec
,
2242 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan
), xfr_cnt
);
2244 codec_dbg(codec
, "write XFRCNT Reg fail\n");
2247 codec_dbg(codec
, " dsp_dma_setup() Write XFRCNT\n");
2250 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2251 "ADROFS=0x%x, XFRCNT=0x%x\n",
2252 chip_addx
, count
, dma_cfg
, adr_ofs
, xfr_cnt
);
2254 codec_dbg(codec
, "-- dsp_dma_setup() -- Complete ---------\n");
2262 static int dsp_dma_start(struct hda_codec
*codec
,
2263 unsigned int dma_chan
, bool ovly
)
2265 unsigned int reg
= 0;
2268 codec_dbg(codec
, "-- dsp_dma_start() -- Begin ---------\n");
2271 status
= chipio_read(codec
,
2272 DSPDMAC_CHNLSTART_INST_OFFSET
, ®
);
2275 codec_dbg(codec
, "read CHNLSTART reg fail\n");
2278 codec_dbg(codec
, "-- dsp_dma_start() Read CHNLSTART\n");
2280 reg
&= ~(DSPDMAC_CHNLSTART_EN_MASK
|
2281 DSPDMAC_CHNLSTART_DIS_MASK
);
2284 status
= chipio_write(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
,
2285 reg
| (1 << (dma_chan
+ DSPDMAC_CHNLSTART_EN_LOBIT
)));
2287 codec_dbg(codec
, "write CHNLSTART reg fail\n");
2290 codec_dbg(codec
, "-- dsp_dma_start() -- Complete ---------\n");
2298 static int dsp_dma_stop(struct hda_codec
*codec
,
2299 unsigned int dma_chan
, bool ovly
)
2301 unsigned int reg
= 0;
2304 codec_dbg(codec
, "-- dsp_dma_stop() -- Begin ---------\n");
2307 status
= chipio_read(codec
,
2308 DSPDMAC_CHNLSTART_INST_OFFSET
, ®
);
2311 codec_dbg(codec
, "read CHNLSTART reg fail\n");
2314 codec_dbg(codec
, "-- dsp_dma_stop() Read CHNLSTART\n");
2315 reg
&= ~(DSPDMAC_CHNLSTART_EN_MASK
|
2316 DSPDMAC_CHNLSTART_DIS_MASK
);
2319 status
= chipio_write(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
,
2320 reg
| (1 << (dma_chan
+ DSPDMAC_CHNLSTART_DIS_LOBIT
)));
2322 codec_dbg(codec
, "write CHNLSTART reg fail\n");
2325 codec_dbg(codec
, "-- dsp_dma_stop() -- Complete ---------\n");
2331 * Allocate router ports
2333 * @codec: the HDA codec
2334 * @num_chans: number of channels in the stream
2335 * @ports_per_channel: number of ports per channel
2336 * @start_device: start device
2337 * @port_map: pointer to the port list to hold the allocated ports
2339 * Returns zero or a negative error code.
2341 static int dsp_allocate_router_ports(struct hda_codec
*codec
,
2342 unsigned int num_chans
,
2343 unsigned int ports_per_channel
,
2344 unsigned int start_device
,
2345 unsigned int *port_map
)
2351 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2355 val
= start_device
<< 6;
2356 val
|= (ports_per_channel
- 1) << 4;
2357 val
|= num_chans
- 1;
2359 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
2360 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET
,
2363 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
2364 VENDOR_CHIPIO_PORT_ALLOC_SET
,
2367 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2371 res
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
2372 VENDOR_CHIPIO_PORT_ALLOC_GET
, 0);
2376 return (res
< 0) ? res
: 0;
2382 static int dsp_free_router_ports(struct hda_codec
*codec
)
2386 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2390 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
2391 VENDOR_CHIPIO_PORT_FREE_SET
,
2394 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
2400 * Allocate DSP ports for the download stream
2402 static int dsp_allocate_ports(struct hda_codec
*codec
,
2403 unsigned int num_chans
,
2404 unsigned int rate_multi
, unsigned int *port_map
)
2408 codec_dbg(codec
, " dsp_allocate_ports() -- begin\n");
2410 if ((rate_multi
!= 1) && (rate_multi
!= 2) && (rate_multi
!= 4)) {
2411 codec_dbg(codec
, "bad rate multiple\n");
2415 status
= dsp_allocate_router_ports(codec
, num_chans
,
2416 rate_multi
, 0, port_map
);
2418 codec_dbg(codec
, " dsp_allocate_ports() -- complete\n");
2423 static int dsp_allocate_ports_format(struct hda_codec
*codec
,
2424 const unsigned short fmt
,
2425 unsigned int *port_map
)
2428 unsigned int num_chans
;
2430 unsigned int sample_rate_div
= ((get_hdafmt_rate(fmt
) >> 0) & 3) + 1;
2431 unsigned int sample_rate_mul
= ((get_hdafmt_rate(fmt
) >> 3) & 3) + 1;
2432 unsigned int rate_multi
= sample_rate_mul
/ sample_rate_div
;
2434 if ((rate_multi
!= 1) && (rate_multi
!= 2) && (rate_multi
!= 4)) {
2435 codec_dbg(codec
, "bad rate multiple\n");
2439 num_chans
= get_hdafmt_chs(fmt
) + 1;
2441 status
= dsp_allocate_ports(codec
, num_chans
, rate_multi
, port_map
);
2449 static int dsp_free_ports(struct hda_codec
*codec
)
2453 codec_dbg(codec
, " dsp_free_ports() -- begin\n");
2455 status
= dsp_free_router_ports(codec
);
2457 codec_dbg(codec
, "free router ports fail\n");
2460 codec_dbg(codec
, " dsp_free_ports() -- complete\n");
2466 * HDA DMA engine stuffs for DSP code download
2469 struct hda_codec
*codec
;
2470 unsigned short m_converter_format
;
2471 struct snd_dma_buffer
*dmab
;
2472 unsigned int buf_size
;
2481 static int dma_convert_to_hda_format(struct hda_codec
*codec
,
2482 unsigned int sample_rate
,
2483 unsigned short channels
,
2484 unsigned short *hda_format
)
2486 unsigned int format_val
;
2488 format_val
= snd_hdac_calc_stream_format(sample_rate
,
2489 channels
, SNDRV_PCM_FORMAT_S32_LE
, 32, 0);
2492 *hda_format
= (unsigned short)format_val
;
2498 * Reset DMA for DSP download
2500 static int dma_reset(struct dma_engine
*dma
)
2502 struct hda_codec
*codec
= dma
->codec
;
2503 struct ca0132_spec
*spec
= codec
->spec
;
2506 if (dma
->dmab
->area
)
2507 snd_hda_codec_load_dsp_cleanup(codec
, dma
->dmab
);
2509 status
= snd_hda_codec_load_dsp_prepare(codec
,
2510 dma
->m_converter_format
,
2515 spec
->dsp_stream_id
= status
;
2519 static int dma_set_state(struct dma_engine
*dma
, enum dma_state state
)
2524 case DMA_STATE_STOP
:
2534 snd_hda_codec_load_dsp_trigger(dma
->codec
, cmd
);
2538 static unsigned int dma_get_buffer_size(struct dma_engine
*dma
)
2540 return dma
->dmab
->bytes
;
2543 static unsigned char *dma_get_buffer_addr(struct dma_engine
*dma
)
2545 return dma
->dmab
->area
;
2548 static int dma_xfer(struct dma_engine
*dma
,
2549 const unsigned int *data
,
2552 memcpy(dma
->dmab
->area
, data
, count
);
2556 static void dma_get_converter_format(
2557 struct dma_engine
*dma
,
2558 unsigned short *format
)
2561 *format
= dma
->m_converter_format
;
2564 static unsigned int dma_get_stream_id(struct dma_engine
*dma
)
2566 struct ca0132_spec
*spec
= dma
->codec
->spec
;
2568 return spec
->dsp_stream_id
;
2571 struct dsp_image_seg
{
2578 static const u32 g_magic_value
= 0x4c46584d;
2579 static const u32 g_chip_addr_magic_value
= 0xFFFFFF01;
2581 static bool is_valid(const struct dsp_image_seg
*p
)
2583 return p
->magic
== g_magic_value
;
2586 static bool is_hci_prog_list_seg(const struct dsp_image_seg
*p
)
2588 return g_chip_addr_magic_value
== p
->chip_addr
;
2591 static bool is_last(const struct dsp_image_seg
*p
)
2593 return p
->count
== 0;
2596 static size_t dsp_sizeof(const struct dsp_image_seg
*p
)
2598 return sizeof(*p
) + p
->count
*sizeof(u32
);
2601 static const struct dsp_image_seg
*get_next_seg_ptr(
2602 const struct dsp_image_seg
*p
)
2604 return (struct dsp_image_seg
*)((unsigned char *)(p
) + dsp_sizeof(p
));
2608 * CA0132 chip DSP transfer stuffs. For DSP download.
2610 #define INVALID_DMA_CHANNEL (~0U)
2613 * Program a list of address/data pairs via the ChipIO widget.
2614 * The segment data is in the format of successive pairs of words.
2615 * These are repeated as indicated by the segment's count field.
2617 static int dspxfr_hci_write(struct hda_codec
*codec
,
2618 const struct dsp_image_seg
*fls
)
2624 if (fls
== NULL
|| fls
->chip_addr
!= g_chip_addr_magic_value
) {
2625 codec_dbg(codec
, "hci_write invalid params\n");
2630 data
= (u32
*)(fls
->data
);
2631 while (count
>= 2) {
2632 status
= chipio_write(codec
, data
[0], data
[1]);
2634 codec_dbg(codec
, "hci_write chipio failed\n");
2644 * Write a block of data into DSP code or data RAM using pre-allocated
2647 * @codec: the HDA codec
2648 * @fls: pointer to a fast load image
2649 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2651 * @dma_engine: pointer to DMA engine to be used for DSP download
2652 * @dma_chan: The number of DMA channels used for DSP download
2653 * @port_map_mask: port mapping
2654 * @ovly: TRUE if overlay format is required
2656 * Returns zero or a negative error code.
2658 static int dspxfr_one_seg(struct hda_codec
*codec
,
2659 const struct dsp_image_seg
*fls
,
2661 struct dma_engine
*dma_engine
,
2662 unsigned int dma_chan
,
2663 unsigned int port_map_mask
,
2667 bool comm_dma_setup_done
= false;
2668 const unsigned int *data
;
2669 unsigned int chip_addx
;
2670 unsigned int words_to_write
;
2671 unsigned int buffer_size_words
;
2672 unsigned char *buffer_addx
;
2673 unsigned short hda_format
;
2674 unsigned int sample_rate_div
;
2675 unsigned int sample_rate_mul
;
2676 unsigned int num_chans
;
2677 unsigned int hda_frame_size_words
;
2678 unsigned int remainder_words
;
2679 const u32
*data_remainder
;
2680 u32 chip_addx_remainder
;
2681 unsigned int run_size_words
;
2682 const struct dsp_image_seg
*hci_write
= NULL
;
2683 unsigned long timeout
;
2688 if (is_hci_prog_list_seg(fls
)) {
2690 fls
= get_next_seg_ptr(fls
);
2693 if (hci_write
&& (!fls
|| is_last(fls
))) {
2694 codec_dbg(codec
, "hci_write\n");
2695 return dspxfr_hci_write(codec
, hci_write
);
2698 if (fls
== NULL
|| dma_engine
== NULL
|| port_map_mask
== 0) {
2699 codec_dbg(codec
, "Invalid Params\n");
2704 chip_addx
= fls
->chip_addr
,
2705 words_to_write
= fls
->count
;
2707 if (!words_to_write
)
2708 return hci_write
? dspxfr_hci_write(codec
, hci_write
) : 0;
2710 chip_addx
= (chip_addx
& (0xFFFF0000 << 2)) + (reloc
<< 2);
2712 if (!UC_RANGE(chip_addx
, words_to_write
) &&
2713 !X_RANGE_ALL(chip_addx
, words_to_write
) &&
2714 !Y_RANGE_ALL(chip_addx
, words_to_write
)) {
2715 codec_dbg(codec
, "Invalid chip_addx Params\n");
2719 buffer_size_words
= (unsigned int)dma_get_buffer_size(dma_engine
) /
2722 buffer_addx
= dma_get_buffer_addr(dma_engine
);
2724 if (buffer_addx
== NULL
) {
2725 codec_dbg(codec
, "dma_engine buffer NULL\n");
2729 dma_get_converter_format(dma_engine
, &hda_format
);
2730 sample_rate_div
= ((get_hdafmt_rate(hda_format
) >> 0) & 3) + 1;
2731 sample_rate_mul
= ((get_hdafmt_rate(hda_format
) >> 3) & 3) + 1;
2732 num_chans
= get_hdafmt_chs(hda_format
) + 1;
2734 hda_frame_size_words
= ((sample_rate_div
== 0) ? 0 :
2735 (num_chans
* sample_rate_mul
/ sample_rate_div
));
2737 if (hda_frame_size_words
== 0) {
2738 codec_dbg(codec
, "frmsz zero\n");
2742 buffer_size_words
= min(buffer_size_words
,
2743 (unsigned int)(UC_RANGE(chip_addx
, 1) ?
2745 buffer_size_words
-= buffer_size_words
% hda_frame_size_words
;
2747 "chpadr=0x%08x frmsz=%u nchan=%u "
2748 "rate_mul=%u div=%u bufsz=%u\n",
2749 chip_addx
, hda_frame_size_words
, num_chans
,
2750 sample_rate_mul
, sample_rate_div
, buffer_size_words
);
2752 if (buffer_size_words
< hda_frame_size_words
) {
2753 codec_dbg(codec
, "dspxfr_one_seg:failed\n");
2757 remainder_words
= words_to_write
% hda_frame_size_words
;
2758 data_remainder
= data
;
2759 chip_addx_remainder
= chip_addx
;
2761 data
+= remainder_words
;
2762 chip_addx
+= remainder_words
*sizeof(u32
);
2763 words_to_write
-= remainder_words
;
2765 while (words_to_write
!= 0) {
2766 run_size_words
= min(buffer_size_words
, words_to_write
);
2767 codec_dbg(codec
, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2768 words_to_write
, run_size_words
, remainder_words
);
2769 dma_xfer(dma_engine
, data
, run_size_words
*sizeof(u32
));
2770 if (!comm_dma_setup_done
) {
2771 status
= dsp_dma_stop(codec
, dma_chan
, ovly
);
2774 status
= dsp_dma_setup_common(codec
, chip_addx
,
2775 dma_chan
, port_map_mask
, ovly
);
2778 comm_dma_setup_done
= true;
2781 status
= dsp_dma_setup(codec
, chip_addx
,
2782 run_size_words
, dma_chan
);
2785 status
= dsp_dma_start(codec
, dma_chan
, ovly
);
2788 if (!dsp_is_dma_active(codec
, dma_chan
)) {
2789 codec_dbg(codec
, "dspxfr:DMA did not start\n");
2792 status
= dma_set_state(dma_engine
, DMA_STATE_RUN
);
2795 if (remainder_words
!= 0) {
2796 status
= chipio_write_multiple(codec
,
2797 chip_addx_remainder
,
2802 remainder_words
= 0;
2805 status
= dspxfr_hci_write(codec
, hci_write
);
2811 timeout
= jiffies
+ msecs_to_jiffies(2000);
2813 dma_active
= dsp_is_dma_active(codec
, dma_chan
);
2817 } while (time_before(jiffies
, timeout
));
2821 codec_dbg(codec
, "+++++ DMA complete\n");
2822 dma_set_state(dma_engine
, DMA_STATE_STOP
);
2823 status
= dma_reset(dma_engine
);
2828 data
+= run_size_words
;
2829 chip_addx
+= run_size_words
*sizeof(u32
);
2830 words_to_write
-= run_size_words
;
2833 if (remainder_words
!= 0) {
2834 status
= chipio_write_multiple(codec
, chip_addx_remainder
,
2835 data_remainder
, remainder_words
);
2842 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2844 * @codec: the HDA codec
2845 * @fls_data: pointer to a fast load image
2846 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2848 * @sample_rate: sampling rate of the stream used for DSP download
2849 * @channels: channels of the stream used for DSP download
2850 * @ovly: TRUE if overlay format is required
2852 * Returns zero or a negative error code.
2854 static int dspxfr_image(struct hda_codec
*codec
,
2855 const struct dsp_image_seg
*fls_data
,
2857 unsigned int sample_rate
,
2858 unsigned short channels
,
2861 struct ca0132_spec
*spec
= codec
->spec
;
2863 unsigned short hda_format
= 0;
2864 unsigned int response
;
2865 unsigned char stream_id
= 0;
2866 struct dma_engine
*dma_engine
;
2867 unsigned int dma_chan
;
2868 unsigned int port_map_mask
;
2870 if (fls_data
== NULL
)
2873 dma_engine
= kzalloc(sizeof(*dma_engine
), GFP_KERNEL
);
2877 dma_engine
->dmab
= kzalloc(sizeof(*dma_engine
->dmab
), GFP_KERNEL
);
2878 if (!dma_engine
->dmab
) {
2883 dma_engine
->codec
= codec
;
2884 dma_convert_to_hda_format(codec
, sample_rate
, channels
, &hda_format
);
2885 dma_engine
->m_converter_format
= hda_format
;
2886 dma_engine
->buf_size
= (ovly
? DSP_DMA_WRITE_BUFLEN_OVLY
:
2887 DSP_DMA_WRITE_BUFLEN_INIT
) * 2;
2889 dma_chan
= ovly
? INVALID_DMA_CHANNEL
: 0;
2891 status
= codec_set_converter_format(codec
, WIDGET_CHIP_CTRL
,
2892 hda_format
, &response
);
2895 codec_dbg(codec
, "set converter format fail\n");
2899 status
= snd_hda_codec_load_dsp_prepare(codec
,
2900 dma_engine
->m_converter_format
,
2901 dma_engine
->buf_size
,
2905 spec
->dsp_stream_id
= status
;
2908 status
= dspio_alloc_dma_chan(codec
, &dma_chan
);
2910 codec_dbg(codec
, "alloc dmachan fail\n");
2911 dma_chan
= INVALID_DMA_CHANNEL
;
2917 status
= dsp_allocate_ports_format(codec
, hda_format
,
2920 codec_dbg(codec
, "alloc ports fail\n");
2924 stream_id
= dma_get_stream_id(dma_engine
);
2925 status
= codec_set_converter_stream_channel(codec
,
2926 WIDGET_CHIP_CTRL
, stream_id
, 0, &response
);
2928 codec_dbg(codec
, "set stream chan fail\n");
2932 while ((fls_data
!= NULL
) && !is_last(fls_data
)) {
2933 if (!is_valid(fls_data
)) {
2934 codec_dbg(codec
, "FLS check fail\n");
2938 status
= dspxfr_one_seg(codec
, fls_data
, reloc
,
2939 dma_engine
, dma_chan
,
2940 port_map_mask
, ovly
);
2944 if (is_hci_prog_list_seg(fls_data
))
2945 fls_data
= get_next_seg_ptr(fls_data
);
2947 if ((fls_data
!= NULL
) && !is_last(fls_data
))
2948 fls_data
= get_next_seg_ptr(fls_data
);
2951 if (port_map_mask
!= 0)
2952 status
= dsp_free_ports(codec
);
2957 status
= codec_set_converter_stream_channel(codec
,
2958 WIDGET_CHIP_CTRL
, 0, 0, &response
);
2961 if (ovly
&& (dma_chan
!= INVALID_DMA_CHANNEL
))
2962 dspio_free_dma_chan(codec
, dma_chan
);
2964 if (dma_engine
->dmab
->area
)
2965 snd_hda_codec_load_dsp_cleanup(codec
, dma_engine
->dmab
);
2966 kfree(dma_engine
->dmab
);
2973 * CA0132 DSP download stuffs.
2975 static void dspload_post_setup(struct hda_codec
*codec
)
2977 struct ca0132_spec
*spec
= codec
->spec
;
2978 codec_dbg(codec
, "---- dspload_post_setup ------\n");
2979 if (!spec
->use_alt_functions
) {
2980 /*set DSP speaker to 2.0 configuration*/
2981 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
2982 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
2984 /*update write pointer*/
2985 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
2990 * dspload_image - Download DSP from a DSP Image Fast Load structure.
2992 * @codec: the HDA codec
2993 * @fls: pointer to a fast load image
2994 * @ovly: TRUE if overlay format is required
2995 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2997 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
2998 * @router_chans: number of audio router channels to be allocated (0 means use
2999 * internal defaults; max is 32)
3001 * Download DSP from a DSP Image Fast Load structure. This structure is a
3002 * linear, non-constant sized element array of structures, each of which
3003 * contain the count of the data to be loaded, the data itself, and the
3004 * corresponding starting chip address of the starting data location.
3005 * Returns zero or a negative error code.
3007 static int dspload_image(struct hda_codec
*codec
,
3008 const struct dsp_image_seg
*fls
,
3015 unsigned int sample_rate
;
3016 unsigned short channels
;
3018 codec_dbg(codec
, "---- dspload_image begin ------\n");
3019 if (router_chans
== 0) {
3021 router_chans
= DMA_TRANSFER_FRAME_SIZE_NWORDS
;
3023 router_chans
= DMA_OVERLAY_FRAME_SIZE_NWORDS
;
3026 sample_rate
= 48000;
3027 channels
= (unsigned short)router_chans
;
3029 while (channels
> 16) {
3035 codec_dbg(codec
, "Ready to program DMA\n");
3037 status
= dsp_reset(codec
);
3042 codec_dbg(codec
, "dsp_reset() complete\n");
3043 status
= dspxfr_image(codec
, fls
, reloc
, sample_rate
, channels
,
3049 codec_dbg(codec
, "dspxfr_image() complete\n");
3050 if (autostart
&& !ovly
) {
3051 dspload_post_setup(codec
);
3052 status
= dsp_set_run_state(codec
);
3055 codec_dbg(codec
, "LOAD FINISHED\n");
3061 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3062 static bool dspload_is_loaded(struct hda_codec
*codec
)
3064 unsigned int data
= 0;
3067 status
= chipio_read(codec
, 0x40004, &data
);
3068 if ((status
< 0) || (data
!= 1))
3074 #define dspload_is_loaded(codec) false
3077 static bool dspload_wait_loaded(struct hda_codec
*codec
)
3079 unsigned long timeout
= jiffies
+ msecs_to_jiffies(2000);
3082 if (dspload_is_loaded(codec
)) {
3083 codec_info(codec
, "ca0132 DSP downloaded and running\n");
3087 } while (time_before(jiffies
, timeout
));
3089 codec_err(codec
, "ca0132 failed to download DSP\n");
3094 * Setup GPIO for the other variants of Core3D.
3098 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3099 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3100 * The first eight bits are just the number of the pin. So far, I've only seen
3101 * this number go to 7.
3103 static void ca0132_mmio_gpio_set(struct hda_codec
*codec
, unsigned int gpio_pin
,
3106 struct ca0132_spec
*spec
= codec
->spec
;
3107 unsigned short gpio_data
;
3109 gpio_data
= gpio_pin
& 0xF;
3110 gpio_data
|= ((enable
<< 8) & 0x100);
3112 writew(gpio_data
, spec
->mem_base
+ 0x320);
3116 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3117 * the card shows as having no GPIO pins.
3119 static void ca0132_gpio_init(struct hda_codec
*codec
)
3121 struct ca0132_spec
*spec
= codec
->spec
;
3123 switch (spec
->quirk
) {
3125 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
3126 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x53);
3127 snd_hda_codec_write(codec
, 0x01, 0, 0x790, 0x23);
3130 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
3131 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x5B);
3137 /* Sets the GPIO for audio output. */
3138 static void ca0132_gpio_setup(struct hda_codec
*codec
)
3140 struct ca0132_spec
*spec
= codec
->spec
;
3142 switch (spec
->quirk
) {
3144 snd_hda_codec_write(codec
, 0x01, 0,
3145 AC_VERB_SET_GPIO_DIRECTION
, 0x07);
3146 snd_hda_codec_write(codec
, 0x01, 0,
3147 AC_VERB_SET_GPIO_MASK
, 0x07);
3148 snd_hda_codec_write(codec
, 0x01, 0,
3149 AC_VERB_SET_GPIO_DATA
, 0x04);
3150 snd_hda_codec_write(codec
, 0x01, 0,
3151 AC_VERB_SET_GPIO_DATA
, 0x06);
3154 snd_hda_codec_write(codec
, 0x01, 0,
3155 AC_VERB_SET_GPIO_DIRECTION
, 0x1E);
3156 snd_hda_codec_write(codec
, 0x01, 0,
3157 AC_VERB_SET_GPIO_MASK
, 0x1F);
3158 snd_hda_codec_write(codec
, 0x01, 0,
3159 AC_VERB_SET_GPIO_DATA
, 0x0C);
3165 * GPIO control functions for the Recon3D integrated.
3168 enum r3di_gpio_bit
{
3169 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3170 R3DI_MIC_SELECT_BIT
= 1,
3171 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3172 R3DI_OUT_SELECT_BIT
= 2,
3174 * I dunno what this actually does, but it stays on until the dsp
3177 R3DI_GPIO_DSP_DOWNLOADING
= 3,
3179 * Same as above, no clue what it does, but it comes on after the dsp
3182 R3DI_GPIO_DSP_DOWNLOADED
= 4
3185 enum r3di_mic_select
{
3186 /* Set GPIO bit 1 to 0 for rear mic */
3188 /* Set GPIO bit 1 to 1 for front microphone*/
3192 enum r3di_out_select
{
3193 /* Set GPIO bit 2 to 0 for headphone */
3194 R3DI_HEADPHONE_OUT
= 0,
3195 /* Set GPIO bit 2 to 1 for speaker */
3198 enum r3di_dsp_status
{
3199 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3200 R3DI_DSP_DOWNLOADING
= 0,
3201 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3202 R3DI_DSP_DOWNLOADED
= 1
3206 static void r3di_gpio_mic_set(struct hda_codec
*codec
,
3207 enum r3di_mic_select cur_mic
)
3209 unsigned int cur_gpio
;
3211 /* Get the current GPIO Data setup */
3212 cur_gpio
= snd_hda_codec_read(codec
, 0x01, 0, AC_VERB_GET_GPIO_DATA
, 0);
3216 cur_gpio
&= ~(1 << R3DI_MIC_SELECT_BIT
);
3218 case R3DI_FRONT_MIC
:
3219 cur_gpio
|= (1 << R3DI_MIC_SELECT_BIT
);
3222 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3223 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3226 static void r3di_gpio_out_set(struct hda_codec
*codec
,
3227 enum r3di_out_select cur_out
)
3229 unsigned int cur_gpio
;
3231 /* Get the current GPIO Data setup */
3232 cur_gpio
= snd_hda_codec_read(codec
, 0x01, 0, AC_VERB_GET_GPIO_DATA
, 0);
3235 case R3DI_HEADPHONE_OUT
:
3236 cur_gpio
&= ~(1 << R3DI_OUT_SELECT_BIT
);
3239 cur_gpio
|= (1 << R3DI_OUT_SELECT_BIT
);
3242 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3243 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3246 static void r3di_gpio_dsp_status_set(struct hda_codec
*codec
,
3247 enum r3di_dsp_status dsp_status
)
3249 unsigned int cur_gpio
;
3251 /* Get the current GPIO Data setup */
3252 cur_gpio
= snd_hda_codec_read(codec
, 0x01, 0, AC_VERB_GET_GPIO_DATA
, 0);
3254 switch (dsp_status
) {
3255 case R3DI_DSP_DOWNLOADING
:
3256 cur_gpio
|= (1 << R3DI_GPIO_DSP_DOWNLOADING
);
3257 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3258 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3260 case R3DI_DSP_DOWNLOADED
:
3261 /* Set DOWNLOADING bit to 0. */
3262 cur_gpio
&= ~(1 << R3DI_GPIO_DSP_DOWNLOADING
);
3264 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3265 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3267 cur_gpio
|= (1 << R3DI_GPIO_DSP_DOWNLOADED
);
3271 snd_hda_codec_write(codec
, codec
->core
.afg
, 0,
3272 AC_VERB_SET_GPIO_DATA
, cur_gpio
);
3278 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
3279 struct hda_codec
*codec
,
3280 unsigned int stream_tag
,
3281 unsigned int format
,
3282 struct snd_pcm_substream
*substream
)
3284 struct ca0132_spec
*spec
= codec
->spec
;
3286 snd_hda_codec_setup_stream(codec
, spec
->dacs
[0], stream_tag
, 0, format
);
3291 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
3292 struct hda_codec
*codec
,
3293 struct snd_pcm_substream
*substream
)
3295 struct ca0132_spec
*spec
= codec
->spec
;
3297 if (spec
->dsp_state
== DSP_DOWNLOADING
)
3300 /*If Playback effects are on, allow stream some time to flush
3302 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
3305 snd_hda_codec_cleanup_stream(codec
, spec
->dacs
[0]);
3310 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream
*info
,
3311 struct hda_codec
*codec
,
3312 struct snd_pcm_substream
*substream
)
3314 struct ca0132_spec
*spec
= codec
->spec
;
3315 unsigned int latency
= DSP_PLAYBACK_INIT_LATENCY
;
3316 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3318 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
3321 /* Add latency if playback enhancement and either effect is enabled. */
3322 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
]) {
3323 if ((spec
->effects_switch
[SURROUND
- EFFECT_START_NID
]) ||
3324 (spec
->effects_switch
[DIALOG_PLUS
- EFFECT_START_NID
]))
3325 latency
+= DSP_PLAY_ENHANCEMENT_LATENCY
;
3328 /* Applying Speaker EQ adds latency as well. */
3329 if (spec
->cur_out_type
== SPEAKER_OUT
)
3330 latency
+= DSP_SPEAKER_OUT_LATENCY
;
3332 return (latency
* runtime
->rate
) / 1000;
3338 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
3339 struct hda_codec
*codec
,
3340 struct snd_pcm_substream
*substream
)
3342 struct ca0132_spec
*spec
= codec
->spec
;
3343 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
3346 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
3347 struct hda_codec
*codec
,
3348 unsigned int stream_tag
,
3349 unsigned int format
,
3350 struct snd_pcm_substream
*substream
)
3352 struct ca0132_spec
*spec
= codec
->spec
;
3353 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
3354 stream_tag
, format
, substream
);
3357 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
3358 struct hda_codec
*codec
,
3359 struct snd_pcm_substream
*substream
)
3361 struct ca0132_spec
*spec
= codec
->spec
;
3362 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
3365 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
3366 struct hda_codec
*codec
,
3367 struct snd_pcm_substream
*substream
)
3369 struct ca0132_spec
*spec
= codec
->spec
;
3370 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
3376 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
3377 struct hda_codec
*codec
,
3378 unsigned int stream_tag
,
3379 unsigned int format
,
3380 struct snd_pcm_substream
*substream
)
3382 snd_hda_codec_setup_stream(codec
, hinfo
->nid
,
3383 stream_tag
, 0, format
);
3388 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
3389 struct hda_codec
*codec
,
3390 struct snd_pcm_substream
*substream
)
3392 struct ca0132_spec
*spec
= codec
->spec
;
3394 if (spec
->dsp_state
== DSP_DOWNLOADING
)
3397 snd_hda_codec_cleanup_stream(codec
, hinfo
->nid
);
3401 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream
*info
,
3402 struct hda_codec
*codec
,
3403 struct snd_pcm_substream
*substream
)
3405 struct ca0132_spec
*spec
= codec
->spec
;
3406 unsigned int latency
= DSP_CAPTURE_INIT_LATENCY
;
3407 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3409 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
3412 if (spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
])
3413 latency
+= DSP_CRYSTAL_VOICE_LATENCY
;
3415 return (latency
* runtime
->rate
) / 1000;
3423 * Mixer controls helpers.
3425 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
3426 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3428 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3429 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3430 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3431 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3432 .info = ca0132_volume_info, \
3433 .get = ca0132_volume_get, \
3434 .put = ca0132_volume_put, \
3435 .tlv = { .c = ca0132_volume_tlv }, \
3436 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3439 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
3440 * volume put, which is used for setting the DSP volume. This was done because
3441 * the ca0132 functions were taking too much time and causing lag.
3443 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
3444 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3446 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3447 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3448 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3449 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3450 .info = snd_hda_mixer_amp_volume_info, \
3451 .get = snd_hda_mixer_amp_volume_get, \
3452 .put = ca0132_alt_volume_put, \
3453 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
3454 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3456 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
3457 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3459 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3460 .info = snd_hda_mixer_amp_switch_info, \
3461 .get = ca0132_switch_get, \
3462 .put = ca0132_switch_put, \
3463 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3466 #define CA0132_CODEC_VOL(xname, nid, dir) \
3467 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
3468 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
3469 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
3470 #define CA0132_CODEC_MUTE(xname, nid, dir) \
3471 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
3475 * Lookup table with decibel values for the DSP. When volume is changed in
3476 * Windows, the DSP is also sent the dB value in floating point. In Windows,
3477 * these values have decimal points, probably because the Windows driver
3478 * actually uses floating point. We can't here, so I made a lookup table of
3479 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
3480 * DAC's, and 9 is the maximum.
3482 static const unsigned int float_vol_db_lookup
[] = {
3483 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
3484 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
3485 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
3486 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
3487 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
3488 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
3489 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
3490 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
3491 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
3492 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
3493 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
3494 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3495 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3496 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3497 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3498 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3499 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
3503 * This table counts from float 0 to 1 in increments of .01, which is
3504 * useful for a few different sliders.
3506 static const unsigned int float_zero_to_one_lookup
[] = {
3507 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3508 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3509 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3510 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3511 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3512 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3513 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3514 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3515 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3516 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3517 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3518 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3519 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3520 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3521 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3522 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3523 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3527 * This table counts from float 10 to 1000, which is the range of the x-bass
3528 * crossover slider in Windows.
3530 static const unsigned int float_xbass_xover_lookup
[] = {
3531 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
3532 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
3533 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
3534 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
3535 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
3536 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
3537 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
3538 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
3539 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
3540 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
3541 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
3542 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
3543 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
3544 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
3545 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
3546 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
3547 0x44728000, 0x44750000, 0x44778000, 0x447A0000
3550 /* The following are for tuning of products */
3551 #ifdef ENABLE_TUNING_CONTROLS
3553 static unsigned int voice_focus_vals_lookup
[] = {
3554 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
3555 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
3556 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
3557 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
3558 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
3559 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
3560 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
3561 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
3562 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
3563 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
3564 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
3565 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
3566 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
3567 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
3568 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
3569 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
3570 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
3571 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
3572 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
3573 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
3574 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
3575 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
3576 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
3577 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
3578 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
3579 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
3580 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
3583 static unsigned int mic_svm_vals_lookup
[] = {
3584 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3585 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3586 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3587 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3588 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3589 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3590 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3591 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3592 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3593 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3594 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3595 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3596 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3597 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3598 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3599 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3600 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3603 static unsigned int equalizer_vals_lookup
[] = {
3604 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3605 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3606 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3607 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3608 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3609 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
3610 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
3611 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
3615 static int tuning_ctl_set(struct hda_codec
*codec
, hda_nid_t nid
,
3616 unsigned int *lookup
, int idx
)
3620 for (i
= 0; i
< TUNING_CTLS_COUNT
; i
++)
3621 if (nid
== ca0132_tuning_ctls
[i
].nid
)
3624 snd_hda_power_up(codec
);
3625 dspio_set_param(codec
, ca0132_tuning_ctls
[i
].mid
, 0x20,
3626 ca0132_tuning_ctls
[i
].req
,
3627 &(lookup
[idx
]), sizeof(unsigned int));
3628 snd_hda_power_down(codec
);
3633 static int tuning_ctl_get(struct snd_kcontrol
*kcontrol
,
3634 struct snd_ctl_elem_value
*ucontrol
)
3636 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3637 struct ca0132_spec
*spec
= codec
->spec
;
3638 hda_nid_t nid
= get_amp_nid(kcontrol
);
3639 long *valp
= ucontrol
->value
.integer
.value
;
3640 int idx
= nid
- TUNING_CTL_START_NID
;
3642 *valp
= spec
->cur_ctl_vals
[idx
];
3646 static int voice_focus_ctl_info(struct snd_kcontrol
*kcontrol
,
3647 struct snd_ctl_elem_info
*uinfo
)
3649 int chs
= get_amp_channels(kcontrol
);
3650 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3651 uinfo
->count
= chs
== 3 ? 2 : 1;
3652 uinfo
->value
.integer
.min
= 20;
3653 uinfo
->value
.integer
.max
= 180;
3654 uinfo
->value
.integer
.step
= 1;
3659 static int voice_focus_ctl_put(struct snd_kcontrol
*kcontrol
,
3660 struct snd_ctl_elem_value
*ucontrol
)
3662 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3663 struct ca0132_spec
*spec
= codec
->spec
;
3664 hda_nid_t nid
= get_amp_nid(kcontrol
);
3665 long *valp
= ucontrol
->value
.integer
.value
;
3668 idx
= nid
- TUNING_CTL_START_NID
;
3670 if (spec
->cur_ctl_vals
[idx
] == *valp
)
3673 spec
->cur_ctl_vals
[idx
] = *valp
;
3676 tuning_ctl_set(codec
, nid
, voice_focus_vals_lookup
, idx
);
3681 static int mic_svm_ctl_info(struct snd_kcontrol
*kcontrol
,
3682 struct snd_ctl_elem_info
*uinfo
)
3684 int chs
= get_amp_channels(kcontrol
);
3685 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3686 uinfo
->count
= chs
== 3 ? 2 : 1;
3687 uinfo
->value
.integer
.min
= 0;
3688 uinfo
->value
.integer
.max
= 100;
3689 uinfo
->value
.integer
.step
= 1;
3694 static int mic_svm_ctl_put(struct snd_kcontrol
*kcontrol
,
3695 struct snd_ctl_elem_value
*ucontrol
)
3697 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3698 struct ca0132_spec
*spec
= codec
->spec
;
3699 hda_nid_t nid
= get_amp_nid(kcontrol
);
3700 long *valp
= ucontrol
->value
.integer
.value
;
3703 idx
= nid
- TUNING_CTL_START_NID
;
3705 if (spec
->cur_ctl_vals
[idx
] == *valp
)
3708 spec
->cur_ctl_vals
[idx
] = *valp
;
3711 tuning_ctl_set(codec
, nid
, mic_svm_vals_lookup
, idx
);
3716 static int equalizer_ctl_info(struct snd_kcontrol
*kcontrol
,
3717 struct snd_ctl_elem_info
*uinfo
)
3719 int chs
= get_amp_channels(kcontrol
);
3720 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3721 uinfo
->count
= chs
== 3 ? 2 : 1;
3722 uinfo
->value
.integer
.min
= 0;
3723 uinfo
->value
.integer
.max
= 48;
3724 uinfo
->value
.integer
.step
= 1;
3729 static int equalizer_ctl_put(struct snd_kcontrol
*kcontrol
,
3730 struct snd_ctl_elem_value
*ucontrol
)
3732 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3733 struct ca0132_spec
*spec
= codec
->spec
;
3734 hda_nid_t nid
= get_amp_nid(kcontrol
);
3735 long *valp
= ucontrol
->value
.integer
.value
;
3738 idx
= nid
- TUNING_CTL_START_NID
;
3740 if (spec
->cur_ctl_vals
[idx
] == *valp
)
3743 spec
->cur_ctl_vals
[idx
] = *valp
;
3746 tuning_ctl_set(codec
, nid
, equalizer_vals_lookup
, idx
);
3751 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale
, 2000, 100, 0);
3752 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale
, -2400, 100, 0);
3754 static int add_tuning_control(struct hda_codec
*codec
,
3755 hda_nid_t pnid
, hda_nid_t nid
,
3756 const char *name
, int dir
)
3758 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
3759 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
3760 struct snd_kcontrol_new knew
=
3761 HDA_CODEC_VOLUME_MONO(namestr
, nid
, 1, 0, type
);
3763 knew
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
3764 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
3769 knew
.info
= voice_focus_ctl_info
;
3770 knew
.get
= tuning_ctl_get
;
3771 knew
.put
= voice_focus_ctl_put
;
3772 knew
.tlv
.p
= voice_focus_db_scale
;
3775 knew
.info
= mic_svm_ctl_info
;
3776 knew
.get
= tuning_ctl_get
;
3777 knew
.put
= mic_svm_ctl_put
;
3780 knew
.info
= equalizer_ctl_info
;
3781 knew
.get
= tuning_ctl_get
;
3782 knew
.put
= equalizer_ctl_put
;
3783 knew
.tlv
.p
= eq_db_scale
;
3788 knew
.private_value
=
3789 HDA_COMPOSE_AMP_VAL(nid
, 1, 0, type
);
3790 sprintf(namestr
, "%s %s Volume", name
, dirstr
[dir
]);
3791 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
3794 static int add_tuning_ctls(struct hda_codec
*codec
)
3799 for (i
= 0; i
< TUNING_CTLS_COUNT
; i
++) {
3800 err
= add_tuning_control(codec
,
3801 ca0132_tuning_ctls
[i
].parent_nid
,
3802 ca0132_tuning_ctls
[i
].nid
,
3803 ca0132_tuning_ctls
[i
].name
,
3804 ca0132_tuning_ctls
[i
].direct
);
3812 static void ca0132_init_tuning_defaults(struct hda_codec
*codec
)
3814 struct ca0132_spec
*spec
= codec
->spec
;
3817 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
3818 spec
->cur_ctl_vals
[WEDGE_ANGLE
- TUNING_CTL_START_NID
] = 10;
3819 /* SVM level defaults to 0.74. */
3820 spec
->cur_ctl_vals
[SVM_LEVEL
- TUNING_CTL_START_NID
] = 74;
3822 /* EQ defaults to 0dB. */
3823 for (i
= 2; i
< TUNING_CTLS_COUNT
; i
++)
3824 spec
->cur_ctl_vals
[i
] = 24;
3826 #endif /*ENABLE_TUNING_CONTROLS*/
3829 * Select the active output.
3830 * If autodetect is enabled, output will be selected based on jack detection.
3831 * If jack inserted, headphone will be selected, else built-in speakers
3832 * If autodetect is disabled, output will be selected based on selection.
3834 static int ca0132_select_out(struct hda_codec
*codec
)
3836 struct ca0132_spec
*spec
= codec
->spec
;
3837 unsigned int pin_ctl
;
3843 codec_dbg(codec
, "ca0132_select_out\n");
3845 snd_hda_power_up_pm(codec
);
3847 auto_jack
= spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
3850 jack_present
= snd_hda_jack_detect(codec
, spec
->unsol_tag_hp
);
3853 spec
->vnode_lswitch
[VNID_HP_SEL
- VNODE_START_NID
];
3856 spec
->cur_out_type
= HEADPHONE_OUT
;
3858 spec
->cur_out_type
= SPEAKER_OUT
;
3860 if (spec
->cur_out_type
== SPEAKER_OUT
) {
3861 codec_dbg(codec
, "ca0132_select_out speaker\n");
3862 /*speaker out config*/
3864 err
= dspio_set_uint_param(codec
, 0x80, 0x04, tmp
);
3867 /*enable speaker EQ*/
3869 err
= dspio_set_uint_param(codec
, 0x8f, 0x00, tmp
);
3874 snd_hda_codec_write(codec
, spec
->out_pins
[1], 0,
3875 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x02);
3876 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3877 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
3878 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3879 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x00);
3880 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3881 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
3883 /* disable headphone node */
3884 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
3885 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3886 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
3888 /* enable speaker node */
3889 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
3890 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3891 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
3894 codec_dbg(codec
, "ca0132_select_out hp\n");
3895 /*headphone out config*/
3897 err
= dspio_set_uint_param(codec
, 0x80, 0x04, tmp
);
3900 /*disable speaker EQ*/
3902 err
= dspio_set_uint_param(codec
, 0x8f, 0x00, tmp
);
3907 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3908 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x00);
3909 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3910 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
3911 snd_hda_codec_write(codec
, spec
->out_pins
[1], 0,
3912 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x02);
3913 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3914 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
3916 /* disable speaker*/
3917 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
3918 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3919 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
3921 /* enable headphone*/
3922 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
3923 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3924 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
3929 snd_hda_power_down_pm(codec
);
3931 return err
< 0 ? err
: 0;
3935 * This function behaves similarly to the ca0132_select_out funciton above,
3936 * except with a few differences. It adds the ability to select the current
3937 * output with an enumerated control "output source" if the auto detect
3938 * mute switch is set to off. If the auto detect mute switch is enabled, it
3939 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
3940 * It also adds the ability to auto-detect the front headphone port. The only
3941 * way to select surround is to disable auto detect, and set Surround with the
3942 * enumerated control.
3944 static int ca0132_alt_select_out(struct hda_codec
*codec
)
3946 struct ca0132_spec
*spec
= codec
->spec
;
3947 unsigned int pin_ctl
;
3953 /* Default Headphone is rear headphone */
3954 hda_nid_t headphone_nid
= spec
->out_pins
[1];
3956 codec_dbg(codec
, "%s\n", __func__
);
3958 snd_hda_power_up_pm(codec
);
3960 auto_jack
= spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
3963 * If headphone rear or front is plugged in, set to headphone.
3964 * If neither is plugged in, set to rear line out. Only if
3965 * hp/speaker auto detect is enabled.
3968 jack_present
= snd_hda_jack_detect(codec
, spec
->unsol_tag_hp
) ||
3969 snd_hda_jack_detect(codec
, spec
->unsol_tag_front_hp
);
3972 spec
->cur_out_type
= HEADPHONE_OUT
;
3974 spec
->cur_out_type
= SPEAKER_OUT
;
3976 spec
->cur_out_type
= spec
->out_enum_val
;
3978 /* Begin DSP output switch */
3980 err
= dspio_set_uint_param(codec
, 0x96, 0x3A, tmp
);
3984 switch (spec
->cur_out_type
) {
3986 codec_dbg(codec
, "%s speaker\n", __func__
);
3987 /*speaker out config*/
3988 switch (spec
->quirk
) {
3990 ca0132_mmio_gpio_set(codec
, 7, false);
3991 ca0132_mmio_gpio_set(codec
, 4, true);
3992 ca0132_mmio_gpio_set(codec
, 1, true);
3993 chipio_set_control_param(codec
, 0x0D, 0x18);
3996 chipio_set_control_param(codec
, 0x0D, 0x24);
3997 r3di_gpio_out_set(codec
, R3DI_LINE_OUT
);
4000 chipio_set_control_param(codec
, 0x0D, 0x24);
4001 ca0132_mmio_gpio_set(codec
, 1, true);
4005 /* disable headphone node */
4006 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
4007 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4008 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
4010 /* enable line-out node */
4011 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
4012 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4013 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
4016 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4017 AC_VERB_SET_EAPD_BTLENABLE
, 0x01);
4019 /* If PlayEnhancement is enabled, set different source */
4020 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
4021 dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_ONE
);
4023 dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_EIGHT
);
4026 codec_dbg(codec
, "%s hp\n", __func__
);
4027 /* Headphone out config*/
4028 switch (spec
->quirk
) {
4030 ca0132_mmio_gpio_set(codec
, 7, true);
4031 ca0132_mmio_gpio_set(codec
, 4, true);
4032 ca0132_mmio_gpio_set(codec
, 1, false);
4033 chipio_set_control_param(codec
, 0x0D, 0x12);
4036 chipio_set_control_param(codec
, 0x0D, 0x21);
4037 r3di_gpio_out_set(codec
, R3DI_HEADPHONE_OUT
);
4040 chipio_set_control_param(codec
, 0x0D, 0x21);
4041 ca0132_mmio_gpio_set(codec
, 0x1, false);
4045 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4046 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
4048 /* disable speaker*/
4049 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
4050 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4051 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
4054 /* enable headphone, either front or rear */
4056 if (snd_hda_jack_detect(codec
, spec
->unsol_tag_front_hp
))
4057 headphone_nid
= spec
->out_pins
[2];
4058 else if (snd_hda_jack_detect(codec
, spec
->unsol_tag_hp
))
4059 headphone_nid
= spec
->out_pins
[1];
4061 pin_ctl
= snd_hda_codec_read(codec
, headphone_nid
, 0,
4062 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4063 snd_hda_set_pin_ctl(codec
, headphone_nid
,
4066 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
4067 dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_ONE
);
4069 dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_ZERO
);
4072 codec_dbg(codec
, "%s surround\n", __func__
);
4073 /* Surround out config*/
4074 switch (spec
->quirk
) {
4076 ca0132_mmio_gpio_set(codec
, 7, false);
4077 ca0132_mmio_gpio_set(codec
, 4, true);
4078 ca0132_mmio_gpio_set(codec
, 1, true);
4079 chipio_set_control_param(codec
, 0x0D, 0x18);
4082 chipio_set_control_param(codec
, 0x0D, 0x24);
4083 r3di_gpio_out_set(codec
, R3DI_LINE_OUT
);
4086 ca0132_mmio_gpio_set(codec
, 1, true);
4087 chipio_set_control_param(codec
, 0x0D, 0x24);
4090 /* enable line out node */
4091 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
4092 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4093 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
4095 /* Disable headphone out */
4096 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
4097 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4098 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
4100 /* Enable EAPD on line out */
4101 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
4102 AC_VERB_SET_EAPD_BTLENABLE
, 0x01);
4103 /* enable center/lfe out node */
4104 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[2], 0,
4105 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4106 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[2],
4108 /* Now set rear surround node as out. */
4109 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[3], 0,
4110 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4111 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[3],
4114 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
4115 dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_ONE
);
4117 dspio_set_uint_param(codec
, 0x80, 0x04, FLOAT_EIGHT
);
4121 /* run through the output dsp commands for line-out */
4122 for (i
= 0; i
< alt_out_presets
[spec
->cur_out_type
].commands
; i
++) {
4123 err
= dspio_set_uint_param(codec
,
4124 alt_out_presets
[spec
->cur_out_type
].mids
[i
],
4125 alt_out_presets
[spec
->cur_out_type
].reqs
[i
],
4126 alt_out_presets
[spec
->cur_out_type
].vals
[i
]);
4133 snd_hda_power_down_pm(codec
);
4135 return err
< 0 ? err
: 0;
4138 static void ca0132_unsol_hp_delayed(struct work_struct
*work
)
4140 struct ca0132_spec
*spec
= container_of(
4141 to_delayed_work(work
), struct ca0132_spec
, unsol_hp_work
);
4142 struct hda_jack_tbl
*jack
;
4144 if (spec
->use_alt_functions
)
4145 ca0132_alt_select_out(spec
->codec
);
4147 ca0132_select_out(spec
->codec
);
4149 jack
= snd_hda_jack_tbl_get(spec
->codec
, spec
->unsol_tag_hp
);
4151 jack
->block_report
= 0;
4152 snd_hda_jack_report_sync(spec
->codec
);
4156 static void ca0132_set_dmic(struct hda_codec
*codec
, int enable
);
4157 static int ca0132_mic_boost_set(struct hda_codec
*codec
, long val
);
4158 static int ca0132_effects_set(struct hda_codec
*codec
, hda_nid_t nid
, long val
);
4159 static void resume_mic1(struct hda_codec
*codec
, unsigned int oldval
);
4160 static int stop_mic1(struct hda_codec
*codec
);
4161 static int ca0132_cvoice_switch_set(struct hda_codec
*codec
);
4162 static int ca0132_alt_mic_boost_set(struct hda_codec
*codec
, long val
);
4165 * Select the active VIP source
4167 static int ca0132_set_vipsource(struct hda_codec
*codec
, int val
)
4169 struct ca0132_spec
*spec
= codec
->spec
;
4172 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
4175 /* if CrystalVoice if off, vipsource should be 0 */
4176 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ||
4178 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, 0);
4179 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4180 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4181 if (spec
->cur_mic_type
== DIGITAL_MIC
)
4185 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4187 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4189 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_16_000
);
4190 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_16_000
);
4191 if (spec
->cur_mic_type
== DIGITAL_MIC
)
4195 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4197 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4199 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, val
);
4205 static int ca0132_alt_set_vipsource(struct hda_codec
*codec
, int val
)
4207 struct ca0132_spec
*spec
= codec
->spec
;
4210 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
4213 codec_dbg(codec
, "%s\n", __func__
);
4215 chipio_set_stream_control(codec
, 0x03, 0);
4216 chipio_set_stream_control(codec
, 0x04, 0);
4218 /* if CrystalVoice is off, vipsource should be 0 */
4219 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ||
4220 (val
== 0) || spec
->in_enum_val
== REAR_LINE_IN
) {
4221 codec_dbg(codec
, "%s: off.", __func__
);
4222 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, 0);
4225 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4227 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4228 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4229 if (spec
->quirk
== QUIRK_R3DI
)
4230 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
4233 if (spec
->in_enum_val
== REAR_LINE_IN
)
4236 if (spec
->quirk
== QUIRK_SBZ
)
4242 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4245 codec_dbg(codec
, "%s: on.", __func__
);
4246 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_16_000
);
4247 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_16_000
);
4248 if (spec
->quirk
== QUIRK_R3DI
)
4249 chipio_set_conn_rate(codec
, 0x0F, SR_16_000
);
4251 if (spec
->effects_switch
[VOICE_FOCUS
- EFFECT_START_NID
])
4255 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4258 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4261 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, val
);
4264 chipio_set_stream_control(codec
, 0x03, 1);
4265 chipio_set_stream_control(codec
, 0x04, 1);
4271 * Select the active microphone.
4272 * If autodetect is enabled, mic will be selected based on jack detection.
4273 * If jack inserted, ext.mic will be selected, else built-in mic
4274 * If autodetect is disabled, mic will be selected based on selection.
4276 static int ca0132_select_mic(struct hda_codec
*codec
)
4278 struct ca0132_spec
*spec
= codec
->spec
;
4282 codec_dbg(codec
, "ca0132_select_mic\n");
4284 snd_hda_power_up_pm(codec
);
4286 auto_jack
= spec
->vnode_lswitch
[VNID_AMIC1_ASEL
- VNODE_START_NID
];
4289 jack_present
= snd_hda_jack_detect(codec
, spec
->unsol_tag_amic1
);
4292 spec
->vnode_lswitch
[VNID_AMIC1_SEL
- VNODE_START_NID
];
4295 spec
->cur_mic_type
= LINE_MIC_IN
;
4297 spec
->cur_mic_type
= DIGITAL_MIC
;
4299 if (spec
->cur_mic_type
== DIGITAL_MIC
) {
4300 /* enable digital Mic */
4301 chipio_set_conn_rate(codec
, MEM_CONNID_DMIC
, SR_32_000
);
4302 ca0132_set_dmic(codec
, 1);
4303 ca0132_mic_boost_set(codec
, 0);
4304 /* set voice focus */
4305 ca0132_effects_set(codec
, VOICE_FOCUS
,
4306 spec
->effects_switch
4307 [VOICE_FOCUS
- EFFECT_START_NID
]);
4309 /* disable digital Mic */
4310 chipio_set_conn_rate(codec
, MEM_CONNID_DMIC
, SR_96_000
);
4311 ca0132_set_dmic(codec
, 0);
4312 ca0132_mic_boost_set(codec
, spec
->cur_mic_boost
);
4313 /* disable voice focus */
4314 ca0132_effects_set(codec
, VOICE_FOCUS
, 0);
4317 snd_hda_power_down_pm(codec
);
4323 * Select the active input.
4324 * Mic detection isn't used, because it's kind of pointless on the SBZ.
4325 * The front mic has no jack-detection, so the only way to switch to it
4326 * is to do it manually in alsamixer.
4328 static int ca0132_alt_select_in(struct hda_codec
*codec
)
4330 struct ca0132_spec
*spec
= codec
->spec
;
4333 codec_dbg(codec
, "%s\n", __func__
);
4335 snd_hda_power_up_pm(codec
);
4337 chipio_set_stream_control(codec
, 0x03, 0);
4338 chipio_set_stream_control(codec
, 0x04, 0);
4340 spec
->cur_mic_type
= spec
->in_enum_val
;
4342 switch (spec
->cur_mic_type
) {
4344 switch (spec
->quirk
) {
4347 ca0132_mmio_gpio_set(codec
, 0, false);
4351 r3di_gpio_mic_set(codec
, R3DI_REAR_MIC
);
4359 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4360 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4361 if (spec
->quirk
== QUIRK_R3DI
)
4362 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
4364 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4366 chipio_set_stream_control(codec
, 0x03, 1);
4367 chipio_set_stream_control(codec
, 0x04, 1);
4369 if (spec
->quirk
== QUIRK_SBZ
) {
4370 chipio_write(codec
, 0x18B098, 0x0000000C);
4371 chipio_write(codec
, 0x18B09C, 0x0000000C);
4373 ca0132_alt_mic_boost_set(codec
, spec
->mic_boost_enum_val
);
4376 ca0132_mic_boost_set(codec
, 0);
4377 switch (spec
->quirk
) {
4380 ca0132_mmio_gpio_set(codec
, 0, false);
4383 r3di_gpio_mic_set(codec
, R3DI_REAR_MIC
);
4387 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4388 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4389 if (spec
->quirk
== QUIRK_R3DI
)
4390 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
4393 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4395 if (spec
->quirk
== QUIRK_SBZ
) {
4396 chipio_write(codec
, 0x18B098, 0x00000000);
4397 chipio_write(codec
, 0x18B09C, 0x00000000);
4400 chipio_set_stream_control(codec
, 0x03, 1);
4401 chipio_set_stream_control(codec
, 0x04, 1);
4404 switch (spec
->quirk
) {
4407 ca0132_mmio_gpio_set(codec
, 0, true);
4408 ca0132_mmio_gpio_set(codec
, 5, false);
4412 r3di_gpio_mic_set(codec
, R3DI_FRONT_MIC
);
4420 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4421 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4422 if (spec
->quirk
== QUIRK_R3DI
)
4423 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
4425 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4427 chipio_set_stream_control(codec
, 0x03, 1);
4428 chipio_set_stream_control(codec
, 0x04, 1);
4430 if (spec
->quirk
== QUIRK_SBZ
) {
4431 chipio_write(codec
, 0x18B098, 0x0000000C);
4432 chipio_write(codec
, 0x18B09C, 0x000000CC);
4434 ca0132_alt_mic_boost_set(codec
, spec
->mic_boost_enum_val
);
4437 ca0132_cvoice_switch_set(codec
);
4439 snd_hda_power_down_pm(codec
);
4445 * Check if VNODE settings take effect immediately.
4447 static bool ca0132_is_vnode_effective(struct hda_codec
*codec
,
4449 hda_nid_t
*shared_nid
)
4451 struct ca0132_spec
*spec
= codec
->spec
;
4456 nid
= spec
->shared_out_nid
;
4459 nid
= spec
->shared_mic_nid
;
4472 * The following functions are control change helpers.
4473 * They return 0 if no changed. Return 1 if changed.
4475 static int ca0132_voicefx_set(struct hda_codec
*codec
, int enable
)
4477 struct ca0132_spec
*spec
= codec
->spec
;
4480 /* based on CrystalVoice state to enable VoiceFX. */
4482 tmp
= spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ?
4483 FLOAT_ONE
: FLOAT_ZERO
;
4488 dspio_set_uint_param(codec
, ca0132_voicefx
.mid
,
4489 ca0132_voicefx
.reqs
[0], tmp
);
4495 * Set the effects parameters
4497 static int ca0132_effects_set(struct hda_codec
*codec
, hda_nid_t nid
, long val
)
4499 struct ca0132_spec
*spec
= codec
->spec
;
4500 unsigned int on
, tmp
;
4501 int num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
4503 int idx
= nid
- EFFECT_START_NID
;
4505 if ((idx
< 0) || (idx
>= num_fx
))
4506 return 0; /* no changed */
4508 /* for out effect, qualify with PE */
4509 if ((nid
>= OUT_EFFECT_START_NID
) && (nid
< OUT_EFFECT_END_NID
)) {
4510 /* if PE if off, turn off out effects. */
4511 if (!spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
4515 /* for in effect, qualify with CrystalVoice */
4516 if ((nid
>= IN_EFFECT_START_NID
) && (nid
< IN_EFFECT_END_NID
)) {
4517 /* if CrystalVoice if off, turn off in effects. */
4518 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
])
4521 /* Voice Focus applies to 2-ch Mic, Digital Mic */
4522 if ((nid
== VOICE_FOCUS
) && (spec
->cur_mic_type
!= DIGITAL_MIC
))
4525 /* If Voice Focus on SBZ, set to two channel. */
4526 if ((nid
== VOICE_FOCUS
) && (spec
->use_pci_mmio
)
4527 && (spec
->cur_mic_type
!= REAR_LINE_IN
)) {
4528 if (spec
->effects_switch
[CRYSTAL_VOICE
-
4529 EFFECT_START_NID
]) {
4531 if (spec
->effects_switch
[VOICE_FOCUS
-
4532 EFFECT_START_NID
]) {
4538 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4542 * For SBZ noise reduction, there's an extra command
4543 * to module ID 0x47. No clue why.
4545 if ((nid
== NOISE_REDUCTION
) && (spec
->use_pci_mmio
)
4546 && (spec
->cur_mic_type
!= REAR_LINE_IN
)) {
4547 if (spec
->effects_switch
[CRYSTAL_VOICE
-
4548 EFFECT_START_NID
]) {
4549 if (spec
->effects_switch
[NOISE_REDUCTION
-
4557 dspio_set_uint_param(codec
, 0x47, 0x00, tmp
);
4560 /* If rear line in disable effects. */
4561 if (spec
->use_alt_functions
&&
4562 spec
->in_enum_val
== REAR_LINE_IN
)
4566 codec_dbg(codec
, "ca0132_effect_set: nid=0x%x, val=%ld\n",
4569 on
= (val
== 0) ? FLOAT_ZERO
: FLOAT_ONE
;
4570 err
= dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
4571 ca0132_effects
[idx
].reqs
[0], on
);
4574 return 0; /* no changed */
4580 * Turn on/off Playback Enhancements
4582 static int ca0132_pe_switch_set(struct hda_codec
*codec
)
4584 struct ca0132_spec
*spec
= codec
->spec
;
4588 codec_dbg(codec
, "ca0132_pe_switch_set: val=%ld\n",
4589 spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
]);
4591 if (spec
->use_alt_functions
)
4592 ca0132_alt_select_out(codec
);
4594 i
= OUT_EFFECT_START_NID
- EFFECT_START_NID
;
4595 nid
= OUT_EFFECT_START_NID
;
4596 /* PE affects all out effects */
4597 for (; nid
< OUT_EFFECT_END_NID
; nid
++, i
++)
4598 ret
|= ca0132_effects_set(codec
, nid
, spec
->effects_switch
[i
]);
4603 /* Check if Mic1 is streaming, if so, stop streaming */
4604 static int stop_mic1(struct hda_codec
*codec
)
4606 struct ca0132_spec
*spec
= codec
->spec
;
4607 unsigned int oldval
= snd_hda_codec_read(codec
, spec
->adcs
[0], 0,
4608 AC_VERB_GET_CONV
, 0);
4610 snd_hda_codec_write(codec
, spec
->adcs
[0], 0,
4611 AC_VERB_SET_CHANNEL_STREAMID
,
4616 /* Resume Mic1 streaming if it was stopped. */
4617 static void resume_mic1(struct hda_codec
*codec
, unsigned int oldval
)
4619 struct ca0132_spec
*spec
= codec
->spec
;
4620 /* Restore the previous stream and channel */
4622 snd_hda_codec_write(codec
, spec
->adcs
[0], 0,
4623 AC_VERB_SET_CHANNEL_STREAMID
,
4628 * Turn on/off CrystalVoice
4630 static int ca0132_cvoice_switch_set(struct hda_codec
*codec
)
4632 struct ca0132_spec
*spec
= codec
->spec
;
4635 unsigned int oldval
;
4637 codec_dbg(codec
, "ca0132_cvoice_switch_set: val=%ld\n",
4638 spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
]);
4640 i
= IN_EFFECT_START_NID
- EFFECT_START_NID
;
4641 nid
= IN_EFFECT_START_NID
;
4642 /* CrystalVoice affects all in effects */
4643 for (; nid
< IN_EFFECT_END_NID
; nid
++, i
++)
4644 ret
|= ca0132_effects_set(codec
, nid
, spec
->effects_switch
[i
]);
4646 /* including VoiceFX */
4647 ret
|= ca0132_voicefx_set(codec
, (spec
->voicefx_val
? 1 : 0));
4649 /* set correct vipsource */
4650 oldval
= stop_mic1(codec
);
4651 if (spec
->use_alt_functions
)
4652 ret
|= ca0132_alt_set_vipsource(codec
, 1);
4654 ret
|= ca0132_set_vipsource(codec
, 1);
4655 resume_mic1(codec
, oldval
);
4659 static int ca0132_mic_boost_set(struct hda_codec
*codec
, long val
)
4661 struct ca0132_spec
*spec
= codec
->spec
;
4665 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
4666 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, 3);
4668 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
4669 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, 0);
4674 static int ca0132_alt_mic_boost_set(struct hda_codec
*codec
, long val
)
4676 struct ca0132_spec
*spec
= codec
->spec
;
4679 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
4680 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, val
);
4684 static int ca0132_vnode_switch_set(struct snd_kcontrol
*kcontrol
,
4685 struct snd_ctl_elem_value
*ucontrol
)
4687 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4688 hda_nid_t nid
= get_amp_nid(kcontrol
);
4689 hda_nid_t shared_nid
= 0;
4692 struct ca0132_spec
*spec
= codec
->spec
;
4695 if (nid
== VNID_HP_SEL
) {
4697 spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
4699 if (spec
->use_alt_functions
)
4700 ca0132_alt_select_out(codec
);
4702 ca0132_select_out(codec
);
4707 if (nid
== VNID_AMIC1_SEL
) {
4709 spec
->vnode_lswitch
[VNID_AMIC1_ASEL
- VNODE_START_NID
];
4711 ca0132_select_mic(codec
);
4715 if (nid
== VNID_HP_ASEL
) {
4716 if (spec
->use_alt_functions
)
4717 ca0132_alt_select_out(codec
);
4719 ca0132_select_out(codec
);
4723 if (nid
== VNID_AMIC1_ASEL
) {
4724 ca0132_select_mic(codec
);
4728 /* if effective conditions, then update hw immediately. */
4729 effective
= ca0132_is_vnode_effective(codec
, nid
, &shared_nid
);
4731 int dir
= get_amp_direction(kcontrol
);
4732 int ch
= get_amp_channels(kcontrol
);
4735 mutex_lock(&codec
->control_mutex
);
4736 pval
= kcontrol
->private_value
;
4737 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(shared_nid
, ch
,
4739 ret
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
4740 kcontrol
->private_value
= pval
;
4741 mutex_unlock(&codec
->control_mutex
);
4746 /* End of control change helpers. */
4748 * Below I've added controls to mess with the effect levels, I've only enabled
4749 * them on the Sound Blaster Z, but they would probably also work on the
4750 * Chromebook. I figured they were probably tuned specifically for it, and left
4754 /* Sets DSP effect level from the sliders above the controls */
4755 static int ca0132_alt_slider_ctl_set(struct hda_codec
*codec
, hda_nid_t nid
,
4756 const unsigned int *lookup
, int idx
)
4761 * For X_BASS, req 2 is actually crossover freq instead of
4769 snd_hda_power_up(codec
);
4770 if (nid
== XBASS_XOVER
) {
4771 for (i
= 0; i
< OUT_EFFECTS_COUNT
; i
++)
4772 if (ca0132_effects
[i
].nid
== X_BASS
)
4775 dspio_set_param(codec
, ca0132_effects
[i
].mid
, 0x20,
4776 ca0132_effects
[i
].reqs
[1],
4777 &(lookup
[idx
- 1]), sizeof(unsigned int));
4779 /* Find the actual effect structure */
4780 for (i
= 0; i
< OUT_EFFECTS_COUNT
; i
++)
4781 if (nid
== ca0132_effects
[i
].nid
)
4784 dspio_set_param(codec
, ca0132_effects
[i
].mid
, 0x20,
4785 ca0132_effects
[i
].reqs
[y
],
4786 &(lookup
[idx
]), sizeof(unsigned int));
4789 snd_hda_power_down(codec
);
4794 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol
*kcontrol
,
4795 struct snd_ctl_elem_value
*ucontrol
)
4797 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4798 struct ca0132_spec
*spec
= codec
->spec
;
4799 long *valp
= ucontrol
->value
.integer
.value
;
4801 *valp
= spec
->xbass_xover_freq
;
4805 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol
*kcontrol
,
4806 struct snd_ctl_elem_value
*ucontrol
)
4808 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4809 struct ca0132_spec
*spec
= codec
->spec
;
4810 hda_nid_t nid
= get_amp_nid(kcontrol
);
4811 long *valp
= ucontrol
->value
.integer
.value
;
4812 int idx
= nid
- OUT_EFFECT_START_NID
;
4814 *valp
= spec
->fx_ctl_val
[idx
];
4819 * The X-bass crossover starts at 10hz, so the min is 1. The
4820 * frequency is set in multiples of 10.
4822 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol
*kcontrol
,
4823 struct snd_ctl_elem_info
*uinfo
)
4825 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
4827 uinfo
->value
.integer
.min
= 1;
4828 uinfo
->value
.integer
.max
= 100;
4829 uinfo
->value
.integer
.step
= 1;
4834 static int ca0132_alt_effect_slider_info(struct snd_kcontrol
*kcontrol
,
4835 struct snd_ctl_elem_info
*uinfo
)
4837 int chs
= get_amp_channels(kcontrol
);
4839 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
4840 uinfo
->count
= chs
== 3 ? 2 : 1;
4841 uinfo
->value
.integer
.min
= 0;
4842 uinfo
->value
.integer
.max
= 100;
4843 uinfo
->value
.integer
.step
= 1;
4848 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol
*kcontrol
,
4849 struct snd_ctl_elem_value
*ucontrol
)
4851 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4852 struct ca0132_spec
*spec
= codec
->spec
;
4853 hda_nid_t nid
= get_amp_nid(kcontrol
);
4854 long *valp
= ucontrol
->value
.integer
.value
;
4858 if (spec
->xbass_xover_freq
== *valp
)
4861 spec
->xbass_xover_freq
= *valp
;
4864 ca0132_alt_slider_ctl_set(codec
, nid
, float_xbass_xover_lookup
, idx
);
4869 static int ca0132_alt_effect_slider_put(struct snd_kcontrol
*kcontrol
,
4870 struct snd_ctl_elem_value
*ucontrol
)
4872 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4873 struct ca0132_spec
*spec
= codec
->spec
;
4874 hda_nid_t nid
= get_amp_nid(kcontrol
);
4875 long *valp
= ucontrol
->value
.integer
.value
;
4878 idx
= nid
- EFFECT_START_NID
;
4880 if (spec
->fx_ctl_val
[idx
] == *valp
)
4883 spec
->fx_ctl_val
[idx
] = *valp
;
4886 ca0132_alt_slider_ctl_set(codec
, nid
, float_zero_to_one_lookup
, idx
);
4893 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
4894 * only has off or full 30 dB, and didn't like making a volume slider that has
4895 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
4897 #define MIC_BOOST_NUM_OF_STEPS 4
4898 #define MIC_BOOST_ENUM_MAX_STRLEN 10
4900 static int ca0132_alt_mic_boost_info(struct snd_kcontrol
*kcontrol
,
4901 struct snd_ctl_elem_info
*uinfo
)
4904 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
4906 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
4908 uinfo
->value
.enumerated
.items
= MIC_BOOST_NUM_OF_STEPS
;
4909 if (uinfo
->value
.enumerated
.item
>= MIC_BOOST_NUM_OF_STEPS
)
4910 uinfo
->value
.enumerated
.item
= MIC_BOOST_NUM_OF_STEPS
- 1;
4911 sprintf(namestr
, "%d %s", (uinfo
->value
.enumerated
.item
* 10), sfx
);
4912 strcpy(uinfo
->value
.enumerated
.name
, namestr
);
4916 static int ca0132_alt_mic_boost_get(struct snd_kcontrol
*kcontrol
,
4917 struct snd_ctl_elem_value
*ucontrol
)
4919 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4920 struct ca0132_spec
*spec
= codec
->spec
;
4922 ucontrol
->value
.enumerated
.item
[0] = spec
->mic_boost_enum_val
;
4926 static int ca0132_alt_mic_boost_put(struct snd_kcontrol
*kcontrol
,
4927 struct snd_ctl_elem_value
*ucontrol
)
4929 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4930 struct ca0132_spec
*spec
= codec
->spec
;
4931 int sel
= ucontrol
->value
.enumerated
.item
[0];
4932 unsigned int items
= MIC_BOOST_NUM_OF_STEPS
;
4937 codec_dbg(codec
, "ca0132_alt_mic_boost: boost=%d\n",
4940 spec
->mic_boost_enum_val
= sel
;
4942 if (spec
->in_enum_val
!= REAR_LINE_IN
)
4943 ca0132_alt_mic_boost_set(codec
, spec
->mic_boost_enum_val
);
4950 * Input Select Control for alternative ca0132 codecs. This exists because
4951 * front microphone has no auto-detect, and we need a way to set the rear
4954 static int ca0132_alt_input_source_info(struct snd_kcontrol
*kcontrol
,
4955 struct snd_ctl_elem_info
*uinfo
)
4957 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
4959 uinfo
->value
.enumerated
.items
= IN_SRC_NUM_OF_INPUTS
;
4960 if (uinfo
->value
.enumerated
.item
>= IN_SRC_NUM_OF_INPUTS
)
4961 uinfo
->value
.enumerated
.item
= IN_SRC_NUM_OF_INPUTS
- 1;
4962 strcpy(uinfo
->value
.enumerated
.name
,
4963 in_src_str
[uinfo
->value
.enumerated
.item
]);
4967 static int ca0132_alt_input_source_get(struct snd_kcontrol
*kcontrol
,
4968 struct snd_ctl_elem_value
*ucontrol
)
4970 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4971 struct ca0132_spec
*spec
= codec
->spec
;
4973 ucontrol
->value
.enumerated
.item
[0] = spec
->in_enum_val
;
4977 static int ca0132_alt_input_source_put(struct snd_kcontrol
*kcontrol
,
4978 struct snd_ctl_elem_value
*ucontrol
)
4980 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4981 struct ca0132_spec
*spec
= codec
->spec
;
4982 int sel
= ucontrol
->value
.enumerated
.item
[0];
4983 unsigned int items
= IN_SRC_NUM_OF_INPUTS
;
4988 codec_dbg(codec
, "ca0132_alt_input_select: sel=%d, preset=%s\n",
4989 sel
, in_src_str
[sel
]);
4991 spec
->in_enum_val
= sel
;
4993 ca0132_alt_select_in(codec
);
4998 /* Sound Blaster Z Output Select Control */
4999 static int ca0132_alt_output_select_get_info(struct snd_kcontrol
*kcontrol
,
5000 struct snd_ctl_elem_info
*uinfo
)
5002 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5004 uinfo
->value
.enumerated
.items
= NUM_OF_OUTPUTS
;
5005 if (uinfo
->value
.enumerated
.item
>= NUM_OF_OUTPUTS
)
5006 uinfo
->value
.enumerated
.item
= NUM_OF_OUTPUTS
- 1;
5007 strcpy(uinfo
->value
.enumerated
.name
,
5008 alt_out_presets
[uinfo
->value
.enumerated
.item
].name
);
5012 static int ca0132_alt_output_select_get(struct snd_kcontrol
*kcontrol
,
5013 struct snd_ctl_elem_value
*ucontrol
)
5015 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5016 struct ca0132_spec
*spec
= codec
->spec
;
5018 ucontrol
->value
.enumerated
.item
[0] = spec
->out_enum_val
;
5022 static int ca0132_alt_output_select_put(struct snd_kcontrol
*kcontrol
,
5023 struct snd_ctl_elem_value
*ucontrol
)
5025 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5026 struct ca0132_spec
*spec
= codec
->spec
;
5027 int sel
= ucontrol
->value
.enumerated
.item
[0];
5028 unsigned int items
= NUM_OF_OUTPUTS
;
5029 unsigned int auto_jack
;
5034 codec_dbg(codec
, "ca0132_alt_output_select: sel=%d, preset=%s\n",
5035 sel
, alt_out_presets
[sel
].name
);
5037 spec
->out_enum_val
= sel
;
5039 auto_jack
= spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
5042 ca0132_alt_select_out(codec
);
5048 * Smart Volume output setting control. Three different settings, Normal,
5049 * which takes the value from the smart volume slider. The two others, loud
5050 * and night, disregard the slider value and have uneditable values.
5052 #define NUM_OF_SVM_SETTINGS 3
5053 static const char *const out_svm_set_enum_str
[3] = {"Normal", "Loud", "Night" };
5055 static int ca0132_alt_svm_setting_info(struct snd_kcontrol
*kcontrol
,
5056 struct snd_ctl_elem_info
*uinfo
)
5058 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5060 uinfo
->value
.enumerated
.items
= NUM_OF_SVM_SETTINGS
;
5061 if (uinfo
->value
.enumerated
.item
>= NUM_OF_SVM_SETTINGS
)
5062 uinfo
->value
.enumerated
.item
= NUM_OF_SVM_SETTINGS
- 1;
5063 strcpy(uinfo
->value
.enumerated
.name
,
5064 out_svm_set_enum_str
[uinfo
->value
.enumerated
.item
]);
5068 static int ca0132_alt_svm_setting_get(struct snd_kcontrol
*kcontrol
,
5069 struct snd_ctl_elem_value
*ucontrol
)
5071 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5072 struct ca0132_spec
*spec
= codec
->spec
;
5074 ucontrol
->value
.enumerated
.item
[0] = spec
->smart_volume_setting
;
5078 static int ca0132_alt_svm_setting_put(struct snd_kcontrol
*kcontrol
,
5079 struct snd_ctl_elem_value
*ucontrol
)
5081 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5082 struct ca0132_spec
*spec
= codec
->spec
;
5083 int sel
= ucontrol
->value
.enumerated
.item
[0];
5084 unsigned int items
= NUM_OF_SVM_SETTINGS
;
5085 unsigned int idx
= SMART_VOLUME
- EFFECT_START_NID
;
5091 codec_dbg(codec
, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
5092 sel
, out_svm_set_enum_str
[sel
]);
5094 spec
->smart_volume_setting
= sel
;
5110 /* Req 2 is the Smart Volume Setting req. */
5111 dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
5112 ca0132_effects
[idx
].reqs
[2], tmp
);
5116 /* Sound Blaster Z EQ preset controls */
5117 static int ca0132_alt_eq_preset_info(struct snd_kcontrol
*kcontrol
,
5118 struct snd_ctl_elem_info
*uinfo
)
5120 unsigned int items
= ARRAY_SIZE(ca0132_alt_eq_presets
);
5122 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5124 uinfo
->value
.enumerated
.items
= items
;
5125 if (uinfo
->value
.enumerated
.item
>= items
)
5126 uinfo
->value
.enumerated
.item
= items
- 1;
5127 strcpy(uinfo
->value
.enumerated
.name
,
5128 ca0132_alt_eq_presets
[uinfo
->value
.enumerated
.item
].name
);
5132 static int ca0132_alt_eq_preset_get(struct snd_kcontrol
*kcontrol
,
5133 struct snd_ctl_elem_value
*ucontrol
)
5135 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5136 struct ca0132_spec
*spec
= codec
->spec
;
5138 ucontrol
->value
.enumerated
.item
[0] = spec
->eq_preset_val
;
5142 static int ca0132_alt_eq_preset_put(struct snd_kcontrol
*kcontrol
,
5143 struct snd_ctl_elem_value
*ucontrol
)
5145 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5146 struct ca0132_spec
*spec
= codec
->spec
;
5148 int sel
= ucontrol
->value
.enumerated
.item
[0];
5149 unsigned int items
= ARRAY_SIZE(ca0132_alt_eq_presets
);
5154 codec_dbg(codec
, "%s: sel=%d, preset=%s\n", __func__
, sel
,
5155 ca0132_alt_eq_presets
[sel
].name
);
5158 * Default needs to qualify with CrystalVoice state.
5160 for (i
= 0; i
< EQ_PRESET_MAX_PARAM_COUNT
; i
++) {
5161 err
= dspio_set_uint_param(codec
, ca0132_alt_eq_enum
.mid
,
5162 ca0132_alt_eq_enum
.reqs
[i
],
5163 ca0132_alt_eq_presets
[sel
].vals
[i
]);
5169 spec
->eq_preset_val
= sel
;
5174 static int ca0132_voicefx_info(struct snd_kcontrol
*kcontrol
,
5175 struct snd_ctl_elem_info
*uinfo
)
5177 unsigned int items
= ARRAY_SIZE(ca0132_voicefx_presets
);
5179 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
5181 uinfo
->value
.enumerated
.items
= items
;
5182 if (uinfo
->value
.enumerated
.item
>= items
)
5183 uinfo
->value
.enumerated
.item
= items
- 1;
5184 strcpy(uinfo
->value
.enumerated
.name
,
5185 ca0132_voicefx_presets
[uinfo
->value
.enumerated
.item
].name
);
5189 static int ca0132_voicefx_get(struct snd_kcontrol
*kcontrol
,
5190 struct snd_ctl_elem_value
*ucontrol
)
5192 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5193 struct ca0132_spec
*spec
= codec
->spec
;
5195 ucontrol
->value
.enumerated
.item
[0] = spec
->voicefx_val
;
5199 static int ca0132_voicefx_put(struct snd_kcontrol
*kcontrol
,
5200 struct snd_ctl_elem_value
*ucontrol
)
5202 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5203 struct ca0132_spec
*spec
= codec
->spec
;
5205 int sel
= ucontrol
->value
.enumerated
.item
[0];
5207 if (sel
>= ARRAY_SIZE(ca0132_voicefx_presets
))
5210 codec_dbg(codec
, "ca0132_voicefx_put: sel=%d, preset=%s\n",
5211 sel
, ca0132_voicefx_presets
[sel
].name
);
5215 * Default needs to qualify with CrystalVoice state.
5217 for (i
= 0; i
< VOICEFX_MAX_PARAM_COUNT
; i
++) {
5218 err
= dspio_set_uint_param(codec
, ca0132_voicefx
.mid
,
5219 ca0132_voicefx
.reqs
[i
],
5220 ca0132_voicefx_presets
[sel
].vals
[i
]);
5226 spec
->voicefx_val
= sel
;
5227 /* enable voice fx */
5228 ca0132_voicefx_set(codec
, (sel
? 1 : 0));
5234 static int ca0132_switch_get(struct snd_kcontrol
*kcontrol
,
5235 struct snd_ctl_elem_value
*ucontrol
)
5237 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5238 struct ca0132_spec
*spec
= codec
->spec
;
5239 hda_nid_t nid
= get_amp_nid(kcontrol
);
5240 int ch
= get_amp_channels(kcontrol
);
5241 long *valp
= ucontrol
->value
.integer
.value
;
5244 if ((nid
>= VNODE_START_NID
) && (nid
< VNODE_END_NID
)) {
5246 *valp
= spec
->vnode_lswitch
[nid
- VNODE_START_NID
];
5250 *valp
= spec
->vnode_rswitch
[nid
- VNODE_START_NID
];
5256 /* effects, include PE and CrystalVoice */
5257 if ((nid
>= EFFECT_START_NID
) && (nid
< EFFECT_END_NID
)) {
5258 *valp
= spec
->effects_switch
[nid
- EFFECT_START_NID
];
5263 if (nid
== spec
->input_pins
[0]) {
5264 *valp
= spec
->cur_mic_boost
;
5271 static int ca0132_switch_put(struct snd_kcontrol
*kcontrol
,
5272 struct snd_ctl_elem_value
*ucontrol
)
5274 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5275 struct ca0132_spec
*spec
= codec
->spec
;
5276 hda_nid_t nid
= get_amp_nid(kcontrol
);
5277 int ch
= get_amp_channels(kcontrol
);
5278 long *valp
= ucontrol
->value
.integer
.value
;
5281 codec_dbg(codec
, "ca0132_switch_put: nid=0x%x, val=%ld\n",
5284 snd_hda_power_up(codec
);
5286 if ((nid
>= VNODE_START_NID
) && (nid
< VNODE_END_NID
)) {
5288 spec
->vnode_lswitch
[nid
- VNODE_START_NID
] = *valp
;
5292 spec
->vnode_rswitch
[nid
- VNODE_START_NID
] = *valp
;
5295 changed
= ca0132_vnode_switch_set(kcontrol
, ucontrol
);
5300 if (nid
== PLAY_ENHANCEMENT
) {
5301 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
5302 changed
= ca0132_pe_switch_set(codec
);
5307 if (nid
== CRYSTAL_VOICE
) {
5308 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
5309 changed
= ca0132_cvoice_switch_set(codec
);
5313 /* out and in effects */
5314 if (((nid
>= OUT_EFFECT_START_NID
) && (nid
< OUT_EFFECT_END_NID
)) ||
5315 ((nid
>= IN_EFFECT_START_NID
) && (nid
< IN_EFFECT_END_NID
))) {
5316 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
5317 changed
= ca0132_effects_set(codec
, nid
, *valp
);
5322 if (nid
== spec
->input_pins
[0]) {
5323 spec
->cur_mic_boost
= *valp
;
5324 if (spec
->use_alt_functions
) {
5325 if (spec
->in_enum_val
!= REAR_LINE_IN
)
5326 changed
= ca0132_mic_boost_set(codec
, *valp
);
5328 /* Mic boost does not apply to Digital Mic */
5329 if (spec
->cur_mic_type
!= DIGITAL_MIC
)
5330 changed
= ca0132_mic_boost_set(codec
, *valp
);
5337 snd_hda_power_down(codec
);
5345 * Sets the internal DSP decibel level to match the DAC for output, and the
5346 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
5347 * all alternative codecs set DSP playback volume.
5349 static void ca0132_alt_dsp_volume_put(struct hda_codec
*codec
, hda_nid_t nid
)
5351 struct ca0132_spec
*spec
= codec
->spec
;
5352 unsigned int dsp_dir
;
5353 unsigned int lookup_val
;
5355 if (nid
== VNID_SPK
)
5356 dsp_dir
= DSP_VOL_OUT
;
5358 dsp_dir
= DSP_VOL_IN
;
5360 lookup_val
= spec
->vnode_lvol
[nid
- VNODE_START_NID
];
5362 dspio_set_uint_param(codec
,
5363 ca0132_alt_vol_ctls
[dsp_dir
].mid
,
5364 ca0132_alt_vol_ctls
[dsp_dir
].reqs
[0],
5365 float_vol_db_lookup
[lookup_val
]);
5367 lookup_val
= spec
->vnode_rvol
[nid
- VNODE_START_NID
];
5369 dspio_set_uint_param(codec
,
5370 ca0132_alt_vol_ctls
[dsp_dir
].mid
,
5371 ca0132_alt_vol_ctls
[dsp_dir
].reqs
[1],
5372 float_vol_db_lookup
[lookup_val
]);
5374 dspio_set_uint_param(codec
,
5375 ca0132_alt_vol_ctls
[dsp_dir
].mid
,
5376 ca0132_alt_vol_ctls
[dsp_dir
].reqs
[2], FLOAT_ZERO
);
5379 static int ca0132_volume_info(struct snd_kcontrol
*kcontrol
,
5380 struct snd_ctl_elem_info
*uinfo
)
5382 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5383 struct ca0132_spec
*spec
= codec
->spec
;
5384 hda_nid_t nid
= get_amp_nid(kcontrol
);
5385 int ch
= get_amp_channels(kcontrol
);
5386 int dir
= get_amp_direction(kcontrol
);
5392 /* follow shared_out info */
5393 nid
= spec
->shared_out_nid
;
5394 mutex_lock(&codec
->control_mutex
);
5395 pval
= kcontrol
->private_value
;
5396 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
5397 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
5398 kcontrol
->private_value
= pval
;
5399 mutex_unlock(&codec
->control_mutex
);
5402 /* follow shared_mic info */
5403 nid
= spec
->shared_mic_nid
;
5404 mutex_lock(&codec
->control_mutex
);
5405 pval
= kcontrol
->private_value
;
5406 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
5407 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
5408 kcontrol
->private_value
= pval
;
5409 mutex_unlock(&codec
->control_mutex
);
5412 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
5417 static int ca0132_volume_get(struct snd_kcontrol
*kcontrol
,
5418 struct snd_ctl_elem_value
*ucontrol
)
5420 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5421 struct ca0132_spec
*spec
= codec
->spec
;
5422 hda_nid_t nid
= get_amp_nid(kcontrol
);
5423 int ch
= get_amp_channels(kcontrol
);
5424 long *valp
= ucontrol
->value
.integer
.value
;
5426 /* store the left and right volume */
5428 *valp
= spec
->vnode_lvol
[nid
- VNODE_START_NID
];
5432 *valp
= spec
->vnode_rvol
[nid
- VNODE_START_NID
];
5438 static int ca0132_volume_put(struct snd_kcontrol
*kcontrol
,
5439 struct snd_ctl_elem_value
*ucontrol
)
5441 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5442 struct ca0132_spec
*spec
= codec
->spec
;
5443 hda_nid_t nid
= get_amp_nid(kcontrol
);
5444 int ch
= get_amp_channels(kcontrol
);
5445 long *valp
= ucontrol
->value
.integer
.value
;
5446 hda_nid_t shared_nid
= 0;
5450 /* store the left and right volume */
5452 spec
->vnode_lvol
[nid
- VNODE_START_NID
] = *valp
;
5456 spec
->vnode_rvol
[nid
- VNODE_START_NID
] = *valp
;
5460 /* if effective conditions, then update hw immediately. */
5461 effective
= ca0132_is_vnode_effective(codec
, nid
, &shared_nid
);
5463 int dir
= get_amp_direction(kcontrol
);
5466 snd_hda_power_up(codec
);
5467 mutex_lock(&codec
->control_mutex
);
5468 pval
= kcontrol
->private_value
;
5469 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(shared_nid
, ch
,
5471 changed
= snd_hda_mixer_amp_volume_put(kcontrol
, ucontrol
);
5472 kcontrol
->private_value
= pval
;
5473 mutex_unlock(&codec
->control_mutex
);
5474 snd_hda_power_down(codec
);
5481 * This function is the same as the one above, because using an if statement
5482 * inside of the above volume control for the DSP volume would cause too much
5483 * lag. This is a lot more smooth.
5485 static int ca0132_alt_volume_put(struct snd_kcontrol
*kcontrol
,
5486 struct snd_ctl_elem_value
*ucontrol
)
5488 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5489 struct ca0132_spec
*spec
= codec
->spec
;
5490 hda_nid_t nid
= get_amp_nid(kcontrol
);
5491 int ch
= get_amp_channels(kcontrol
);
5492 long *valp
= ucontrol
->value
.integer
.value
;
5505 /* store the left and right volume */
5507 spec
->vnode_lvol
[vnid
- VNODE_START_NID
] = *valp
;
5511 spec
->vnode_rvol
[vnid
- VNODE_START_NID
] = *valp
;
5515 snd_hda_power_up(codec
);
5516 ca0132_alt_dsp_volume_put(codec
, vnid
);
5517 mutex_lock(&codec
->control_mutex
);
5518 changed
= snd_hda_mixer_amp_volume_put(kcontrol
, ucontrol
);
5519 mutex_unlock(&codec
->control_mutex
);
5520 snd_hda_power_down(codec
);
5525 static int ca0132_volume_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
5526 unsigned int size
, unsigned int __user
*tlv
)
5528 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5529 struct ca0132_spec
*spec
= codec
->spec
;
5530 hda_nid_t nid
= get_amp_nid(kcontrol
);
5531 int ch
= get_amp_channels(kcontrol
);
5532 int dir
= get_amp_direction(kcontrol
);
5538 /* follow shared_out tlv */
5539 nid
= spec
->shared_out_nid
;
5540 mutex_lock(&codec
->control_mutex
);
5541 pval
= kcontrol
->private_value
;
5542 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
5543 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
5544 kcontrol
->private_value
= pval
;
5545 mutex_unlock(&codec
->control_mutex
);
5548 /* follow shared_mic tlv */
5549 nid
= spec
->shared_mic_nid
;
5550 mutex_lock(&codec
->control_mutex
);
5551 pval
= kcontrol
->private_value
;
5552 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
5553 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
5554 kcontrol
->private_value
= pval
;
5555 mutex_unlock(&codec
->control_mutex
);
5558 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
5563 /* Add volume slider control for effect level */
5564 static int ca0132_alt_add_effect_slider(struct hda_codec
*codec
, hda_nid_t nid
,
5565 const char *pfx
, int dir
)
5567 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
5568 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
5569 struct snd_kcontrol_new knew
=
5570 HDA_CODEC_VOLUME_MONO(namestr
, nid
, 1, 0, type
);
5572 sprintf(namestr
, "FX: %s %s Volume", pfx
, dirstr
[dir
]);
5578 knew
.info
= ca0132_alt_xbass_xover_slider_info
;
5579 knew
.get
= ca0132_alt_xbass_xover_slider_ctl_get
;
5580 knew
.put
= ca0132_alt_xbass_xover_slider_put
;
5583 knew
.info
= ca0132_alt_effect_slider_info
;
5584 knew
.get
= ca0132_alt_slider_ctl_get
;
5585 knew
.put
= ca0132_alt_effect_slider_put
;
5586 knew
.private_value
=
5587 HDA_COMPOSE_AMP_VAL(nid
, 1, 0, type
);
5591 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
5595 * Added FX: prefix for the alternative codecs, because otherwise the surround
5596 * effect would conflict with the Surround sound volume control. Also seems more
5597 * clear as to what the switches do. Left alone for others.
5599 static int add_fx_switch(struct hda_codec
*codec
, hda_nid_t nid
,
5600 const char *pfx
, int dir
)
5602 struct ca0132_spec
*spec
= codec
->spec
;
5603 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
5604 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
5605 struct snd_kcontrol_new knew
=
5606 CA0132_CODEC_MUTE_MONO(namestr
, nid
, 1, type
);
5607 /* If using alt_controls, add FX: prefix. But, don't add FX:
5608 * prefix to OutFX or InFX enable controls.
5610 if ((spec
->use_alt_controls
) && (nid
<= IN_EFFECT_END_NID
))
5611 sprintf(namestr
, "FX: %s %s Switch", pfx
, dirstr
[dir
]);
5613 sprintf(namestr
, "%s %s Switch", pfx
, dirstr
[dir
]);
5615 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
5618 static int add_voicefx(struct hda_codec
*codec
)
5620 struct snd_kcontrol_new knew
=
5621 HDA_CODEC_MUTE_MONO(ca0132_voicefx
.name
,
5622 VOICEFX
, 1, 0, HDA_INPUT
);
5623 knew
.info
= ca0132_voicefx_info
;
5624 knew
.get
= ca0132_voicefx_get
;
5625 knew
.put
= ca0132_voicefx_put
;
5626 return snd_hda_ctl_add(codec
, VOICEFX
, snd_ctl_new1(&knew
, codec
));
5629 /* Create the EQ Preset control */
5630 static int add_ca0132_alt_eq_presets(struct hda_codec
*codec
)
5632 struct snd_kcontrol_new knew
=
5633 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum
.name
,
5634 EQ_PRESET_ENUM
, 1, 0, HDA_OUTPUT
);
5635 knew
.info
= ca0132_alt_eq_preset_info
;
5636 knew
.get
= ca0132_alt_eq_preset_get
;
5637 knew
.put
= ca0132_alt_eq_preset_put
;
5638 return snd_hda_ctl_add(codec
, EQ_PRESET_ENUM
,
5639 snd_ctl_new1(&knew
, codec
));
5643 * Add enumerated control for the three different settings of the smart volume
5644 * output effect. Normal just uses the slider value, and loud and night are
5645 * their own things that ignore that value.
5647 static int ca0132_alt_add_svm_enum(struct hda_codec
*codec
)
5649 struct snd_kcontrol_new knew
=
5650 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
5651 SMART_VOLUME_ENUM
, 1, 0, HDA_OUTPUT
);
5652 knew
.info
= ca0132_alt_svm_setting_info
;
5653 knew
.get
= ca0132_alt_svm_setting_get
;
5654 knew
.put
= ca0132_alt_svm_setting_put
;
5655 return snd_hda_ctl_add(codec
, SMART_VOLUME_ENUM
,
5656 snd_ctl_new1(&knew
, codec
));
5661 * Create an Output Select enumerated control for codecs with surround
5664 static int ca0132_alt_add_output_enum(struct hda_codec
*codec
)
5666 struct snd_kcontrol_new knew
=
5667 HDA_CODEC_MUTE_MONO("Output Select",
5668 OUTPUT_SOURCE_ENUM
, 1, 0, HDA_OUTPUT
);
5669 knew
.info
= ca0132_alt_output_select_get_info
;
5670 knew
.get
= ca0132_alt_output_select_get
;
5671 knew
.put
= ca0132_alt_output_select_put
;
5672 return snd_hda_ctl_add(codec
, OUTPUT_SOURCE_ENUM
,
5673 snd_ctl_new1(&knew
, codec
));
5677 * Create an Input Source enumerated control for the alternate ca0132 codecs
5678 * because the front microphone has no auto-detect, and Line-in has to be set
5681 static int ca0132_alt_add_input_enum(struct hda_codec
*codec
)
5683 struct snd_kcontrol_new knew
=
5684 HDA_CODEC_MUTE_MONO("Input Source",
5685 INPUT_SOURCE_ENUM
, 1, 0, HDA_INPUT
);
5686 knew
.info
= ca0132_alt_input_source_info
;
5687 knew
.get
= ca0132_alt_input_source_get
;
5688 knew
.put
= ca0132_alt_input_source_put
;
5689 return snd_hda_ctl_add(codec
, INPUT_SOURCE_ENUM
,
5690 snd_ctl_new1(&knew
, codec
));
5694 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
5695 * more control than the original mic boost, which is either full 30dB or off.
5697 static int ca0132_alt_add_mic_boost_enum(struct hda_codec
*codec
)
5699 struct snd_kcontrol_new knew
=
5700 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
5701 MIC_BOOST_ENUM
, 1, 0, HDA_INPUT
);
5702 knew
.info
= ca0132_alt_mic_boost_info
;
5703 knew
.get
= ca0132_alt_mic_boost_get
;
5704 knew
.put
= ca0132_alt_mic_boost_put
;
5705 return snd_hda_ctl_add(codec
, MIC_BOOST_ENUM
,
5706 snd_ctl_new1(&knew
, codec
));
5711 * Need to create slave controls for the alternate codecs that have surround
5714 static const char * const ca0132_alt_slave_pfxs
[] = {
5715 "Front", "Surround", "Center", "LFE", NULL
,
5719 * Also need special channel map, because the default one is incorrect.
5720 * I think this has to do with the pin for rear surround being 0x11,
5721 * and the center/lfe being 0x10. Usually the pin order is the opposite.
5723 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps
[] = {
5725 .map
= { SNDRV_CHMAP_FL
, SNDRV_CHMAP_FR
} },
5727 .map
= { SNDRV_CHMAP_FL
, SNDRV_CHMAP_FR
,
5728 SNDRV_CHMAP_RL
, SNDRV_CHMAP_RR
} },
5730 .map
= { SNDRV_CHMAP_FL
, SNDRV_CHMAP_FR
,
5731 SNDRV_CHMAP_FC
, SNDRV_CHMAP_LFE
,
5732 SNDRV_CHMAP_RL
, SNDRV_CHMAP_RR
} },
5736 /* Add the correct chmap for streams with 6 channels. */
5737 static void ca0132_alt_add_chmap_ctls(struct hda_codec
*codec
)
5740 struct hda_pcm
*pcm
;
5742 list_for_each_entry(pcm
, &codec
->pcm_list_head
, list
) {
5743 struct hda_pcm_stream
*hinfo
=
5744 &pcm
->stream
[SNDRV_PCM_STREAM_PLAYBACK
];
5745 struct snd_pcm_chmap
*chmap
;
5746 const struct snd_pcm_chmap_elem
*elem
;
5748 elem
= ca0132_alt_chmaps
;
5749 if (hinfo
->channels_max
== 6) {
5750 err
= snd_pcm_add_chmap_ctls(pcm
->pcm
,
5751 SNDRV_PCM_STREAM_PLAYBACK
,
5752 elem
, hinfo
->channels_max
, 0, &chmap
);
5754 codec_dbg(codec
, "snd_pcm_add_chmap_ctls failed!");
5760 * When changing Node IDs for Mixer Controls below, make sure to update
5761 * Node IDs in ca0132_config() as well.
5763 static const struct snd_kcontrol_new ca0132_mixer
[] = {
5764 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK
, HDA_OUTPUT
),
5765 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK
, HDA_OUTPUT
),
5766 CA0132_CODEC_VOL("Capture Volume", VNID_MIC
, HDA_INPUT
),
5767 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC
, HDA_INPUT
),
5768 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT
),
5769 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT
),
5770 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT
),
5771 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT
),
5772 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
5773 0x12, 1, HDA_INPUT
),
5774 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
5775 VNID_HP_SEL
, 1, HDA_OUTPUT
),
5776 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
5777 VNID_AMIC1_SEL
, 1, HDA_INPUT
),
5778 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
5779 VNID_HP_ASEL
, 1, HDA_OUTPUT
),
5780 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
5781 VNID_AMIC1_ASEL
, 1, HDA_INPUT
),
5786 * Desktop specific control mixer. Removes auto-detect for mic, and adds
5787 * surround controls. Also sets both the Front Playback and Capture Volume
5788 * controls to alt so they set the DSP's decibel level.
5790 static const struct snd_kcontrol_new desktop_mixer
[] = {
5791 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT
),
5792 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK
, HDA_OUTPUT
),
5793 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT
),
5794 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT
),
5795 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT
),
5796 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT
),
5797 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT
),
5798 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT
),
5799 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT
),
5800 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC
, HDA_INPUT
),
5801 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT
),
5802 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT
),
5803 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
5804 VNID_HP_ASEL
, 1, HDA_OUTPUT
),
5809 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
5810 * because it doesn't set decibel levels for the DSP for capture.
5812 static const struct snd_kcontrol_new r3di_mixer
[] = {
5813 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT
),
5814 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK
, HDA_OUTPUT
),
5815 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT
),
5816 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT
),
5817 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT
),
5818 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT
),
5819 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT
),
5820 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT
),
5821 CA0132_CODEC_VOL("Capture Volume", VNID_MIC
, HDA_INPUT
),
5822 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC
, HDA_INPUT
),
5823 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT
),
5824 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT
),
5825 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
5826 VNID_HP_ASEL
, 1, HDA_OUTPUT
),
5830 static int ca0132_build_controls(struct hda_codec
*codec
)
5832 struct ca0132_spec
*spec
= codec
->spec
;
5833 int i
, num_fx
, num_sliders
;
5836 /* Add Mixer controls */
5837 for (i
= 0; i
< spec
->num_mixers
; i
++) {
5838 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
5842 /* Setup vmaster with surround slaves for desktop ca0132 devices */
5843 if (spec
->use_alt_functions
) {
5844 snd_hda_set_vmaster_tlv(codec
, spec
->dacs
[0], HDA_OUTPUT
,
5846 snd_hda_add_vmaster(codec
, "Master Playback Volume",
5847 spec
->tlv
, ca0132_alt_slave_pfxs
,
5849 err
= __snd_hda_add_vmaster(codec
, "Master Playback Switch",
5850 NULL
, ca0132_alt_slave_pfxs
,
5852 true, &spec
->vmaster_mute
.sw_kctl
);
5856 /* Add in and out effects controls.
5857 * VoiceFX, PE and CrystalVoice are added separately.
5859 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
5860 for (i
= 0; i
< num_fx
; i
++) {
5861 /* Desktop cards break if Echo Cancellation is used. */
5862 if (spec
->use_pci_mmio
) {
5863 if (i
== (ECHO_CANCELLATION
- IN_EFFECT_START_NID
+
5868 err
= add_fx_switch(codec
, ca0132_effects
[i
].nid
,
5869 ca0132_effects
[i
].name
,
5870 ca0132_effects
[i
].direct
);
5875 * If codec has use_alt_controls set to true, add effect level sliders,
5876 * EQ presets, and Smart Volume presets. Also, change names to add FX
5877 * prefix, and change PlayEnhancement and CrystalVoice to match.
5879 if (spec
->use_alt_controls
) {
5880 ca0132_alt_add_svm_enum(codec
);
5881 add_ca0132_alt_eq_presets(codec
);
5882 err
= add_fx_switch(codec
, PLAY_ENHANCEMENT
,
5887 err
= add_fx_switch(codec
, CRYSTAL_VOICE
,
5892 num_sliders
= OUT_EFFECTS_COUNT
- 1;
5893 for (i
= 0; i
< num_sliders
; i
++) {
5894 err
= ca0132_alt_add_effect_slider(codec
,
5895 ca0132_effects
[i
].nid
,
5896 ca0132_effects
[i
].name
,
5897 ca0132_effects
[i
].direct
);
5902 err
= ca0132_alt_add_effect_slider(codec
, XBASS_XOVER
,
5903 "X-Bass Crossover", EFX_DIR_OUT
);
5908 err
= add_fx_switch(codec
, PLAY_ENHANCEMENT
,
5909 "PlayEnhancement", 0);
5913 err
= add_fx_switch(codec
, CRYSTAL_VOICE
,
5921 * If the codec uses alt_functions, you need the enumerated controls
5922 * to select the new outputs and inputs, plus add the new mic boost
5925 if (spec
->use_alt_functions
) {
5926 ca0132_alt_add_output_enum(codec
);
5927 ca0132_alt_add_input_enum(codec
);
5928 ca0132_alt_add_mic_boost_enum(codec
);
5930 #ifdef ENABLE_TUNING_CONTROLS
5931 add_tuning_ctls(codec
);
5934 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
5938 if (spec
->dig_out
) {
5939 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->dig_out
,
5943 err
= snd_hda_create_spdif_share_sw(codec
, &spec
->multiout
);
5946 /* spec->multiout.share_spdif = 1; */
5950 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in
);
5955 if (spec
->use_alt_functions
)
5956 ca0132_alt_add_chmap_ctls(codec
);
5964 static const struct hda_pcm_stream ca0132_pcm_analog_playback
= {
5969 .prepare
= ca0132_playback_pcm_prepare
,
5970 .cleanup
= ca0132_playback_pcm_cleanup
,
5971 .get_delay
= ca0132_playback_pcm_delay
,
5975 static const struct hda_pcm_stream ca0132_pcm_analog_capture
= {
5980 .prepare
= ca0132_capture_pcm_prepare
,
5981 .cleanup
= ca0132_capture_pcm_cleanup
,
5982 .get_delay
= ca0132_capture_pcm_delay
,
5986 static const struct hda_pcm_stream ca0132_pcm_digital_playback
= {
5991 .open
= ca0132_dig_playback_pcm_open
,
5992 .close
= ca0132_dig_playback_pcm_close
,
5993 .prepare
= ca0132_dig_playback_pcm_prepare
,
5994 .cleanup
= ca0132_dig_playback_pcm_cleanup
5998 static const struct hda_pcm_stream ca0132_pcm_digital_capture
= {
6004 static int ca0132_build_pcms(struct hda_codec
*codec
)
6006 struct ca0132_spec
*spec
= codec
->spec
;
6007 struct hda_pcm
*info
;
6009 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Analog");
6012 if (spec
->use_alt_functions
) {
6013 info
->own_chmap
= true;
6014 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].chmap
6015 = ca0132_alt_chmaps
;
6017 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = ca0132_pcm_analog_playback
;
6018 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dacs
[0];
6019 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
6020 spec
->multiout
.max_channels
;
6021 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
6022 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
6023 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[0];
6025 /* With the DSP enabled, desktops don't use this ADC. */
6026 if (!spec
->use_alt_functions
) {
6027 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Analog Mic-In2");
6030 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
6031 ca0132_pcm_analog_capture
;
6032 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
6033 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[1];
6036 info
= snd_hda_codec_pcm_new(codec
, "CA0132 What U Hear");
6039 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
6040 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
6041 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[2];
6043 if (!spec
->dig_out
&& !spec
->dig_in
)
6046 info
= snd_hda_codec_pcm_new(codec
, "CA0132 Digital");
6049 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
6050 if (spec
->dig_out
) {
6051 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
6052 ca0132_pcm_digital_playback
;
6053 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dig_out
;
6056 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
6057 ca0132_pcm_digital_capture
;
6058 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in
;
6064 static void init_output(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t dac
)
6067 snd_hda_set_pin_ctl(codec
, pin
, PIN_HP
);
6068 if (get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
)
6069 snd_hda_codec_write(codec
, pin
, 0,
6070 AC_VERB_SET_AMP_GAIN_MUTE
,
6073 if (dac
&& (get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
6074 snd_hda_codec_write(codec
, dac
, 0,
6075 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
);
6078 static void init_input(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t adc
)
6081 snd_hda_set_pin_ctl(codec
, pin
, PIN_VREF80
);
6082 if (get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
)
6083 snd_hda_codec_write(codec
, pin
, 0,
6084 AC_VERB_SET_AMP_GAIN_MUTE
,
6087 if (adc
&& (get_wcaps(codec
, adc
) & AC_WCAP_IN_AMP
)) {
6088 snd_hda_codec_write(codec
, adc
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
6091 /* init to 0 dB and unmute. */
6092 snd_hda_codec_amp_stereo(codec
, adc
, HDA_INPUT
, 0,
6093 HDA_AMP_VOLMASK
, 0x5a);
6094 snd_hda_codec_amp_stereo(codec
, adc
, HDA_INPUT
, 0,
6099 static void refresh_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
, int dir
)
6103 caps
= snd_hda_param_read(codec
, nid
, dir
== HDA_OUTPUT
?
6104 AC_PAR_AMP_OUT_CAP
: AC_PAR_AMP_IN_CAP
);
6105 snd_hda_override_amp_caps(codec
, nid
, dir
, caps
);
6109 * Switch between Digital built-in mic and analog mic.
6111 static void ca0132_set_dmic(struct hda_codec
*codec
, int enable
)
6113 struct ca0132_spec
*spec
= codec
->spec
;
6116 unsigned int oldval
;
6118 codec_dbg(codec
, "ca0132_set_dmic: enable=%d\n", enable
);
6120 oldval
= stop_mic1(codec
);
6121 ca0132_set_vipsource(codec
, 0);
6123 /* set DMic input as 2-ch */
6125 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
6127 val
= spec
->dmic_ctl
;
6129 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
6130 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
6132 if (!(spec
->dmic_ctl
& 0x20))
6133 chipio_set_control_flag(codec
, CONTROL_FLAG_DMIC
, 1);
6135 /* set AMic input as mono */
6137 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
6139 val
= spec
->dmic_ctl
;
6140 /* clear bit7 and bit5 to disable dmic */
6142 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
6143 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
6145 if (!(spec
->dmic_ctl
& 0x20))
6146 chipio_set_control_flag(codec
, CONTROL_FLAG_DMIC
, 0);
6148 ca0132_set_vipsource(codec
, 1);
6149 resume_mic1(codec
, oldval
);
6153 * Initialization for Digital Mic.
6155 static void ca0132_init_dmic(struct hda_codec
*codec
)
6157 struct ca0132_spec
*spec
= codec
->spec
;
6160 /* Setup Digital Mic here, but don't enable.
6161 * Enable based on jack detect.
6164 /* MCLK uses MPIO1, set to enable.
6165 * Bit 2-0: MPIO select
6166 * Bit 3: set to disable
6170 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
6171 VENDOR_CHIPIO_DMIC_MCLK_SET
, val
);
6173 /* Data1 uses MPIO3. Data2 not use
6174 * Bit 2-0: Data1 MPIO select
6175 * Bit 3: set disable Data1
6176 * Bit 6-4: Data2 MPIO select
6177 * Bit 7: set disable Data2
6180 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
6181 VENDOR_CHIPIO_DMIC_PIN_SET
, val
);
6183 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
6184 * Bit 3-0: Channel mask
6185 * Bit 4: set for 48KHz, clear for 32KHz
6187 * Bit 6: set to select Data2, clear for Data1
6188 * Bit 7: set to enable DMic, clear for AMic
6190 if (spec
->quirk
== QUIRK_ALIENWARE_M17XR4
)
6194 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
6195 spec
->dmic_ctl
= val
;
6196 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
6197 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
6201 * Initialization for Analog Mic 2
6203 static void ca0132_init_analog_mic2(struct hda_codec
*codec
)
6205 struct ca0132_spec
*spec
= codec
->spec
;
6207 mutex_lock(&spec
->chipio_mutex
);
6208 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
6209 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0x20);
6210 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
6211 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, 0x19);
6212 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
6213 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x00);
6214 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
6215 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0x2D);
6216 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
6217 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, 0x19);
6218 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
6219 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x00);
6220 mutex_unlock(&spec
->chipio_mutex
);
6223 static void ca0132_refresh_widget_caps(struct hda_codec
*codec
)
6225 struct ca0132_spec
*spec
= codec
->spec
;
6228 codec_dbg(codec
, "ca0132_refresh_widget_caps.\n");
6229 snd_hda_codec_update_widgets(codec
);
6231 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++)
6232 refresh_amp_caps(codec
, spec
->dacs
[i
], HDA_OUTPUT
);
6234 for (i
= 0; i
< spec
->num_outputs
; i
++)
6235 refresh_amp_caps(codec
, spec
->out_pins
[i
], HDA_OUTPUT
);
6237 for (i
= 0; i
< spec
->num_inputs
; i
++) {
6238 refresh_amp_caps(codec
, spec
->adcs
[i
], HDA_INPUT
);
6239 refresh_amp_caps(codec
, spec
->input_pins
[i
], HDA_INPUT
);
6244 * Recon3D r3d_setup_defaults sub functions.
6247 static void r3d_dsp_scp_startup(struct hda_codec
*codec
)
6252 dspio_set_uint_param_no_source(codec
, 0x80, 0x0A, tmp
);
6255 dspio_set_uint_param_no_source(codec
, 0x80, 0x0B, tmp
);
6258 dspio_set_uint_param_no_source(codec
, 0x80, 0x0C, tmp
);
6261 dspio_set_uint_param_no_source(codec
, 0x80, 0x0C, tmp
);
6264 dspio_set_uint_param_no_source(codec
, 0x80, 0x0C, tmp
);
6268 static void r3d_dsp_initial_mic_setup(struct hda_codec
*codec
)
6273 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
6274 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
6275 /* This ConnPointID is unique to Recon3Di. Haven't seen it elsewhere */
6276 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
6278 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
6280 /* Mic 2 Setup, even though it isn't connected on SBZ */
6281 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN2
, SR_96_000
);
6282 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT2
, SR_96_000
);
6283 chipio_set_conn_rate(codec
, 0x0F, SR_96_000
);
6285 dspio_set_uint_param(codec
, 0x80, 0x01, tmp
);
6289 * Initialize Sound Blaster Z analog microphones.
6291 static void sbz_init_analog_mics(struct hda_codec
*codec
)
6296 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
6297 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
6299 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
6301 /* Mic 2 Setup, even though it isn't connected on SBZ */
6302 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN2
, SR_96_000
);
6303 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT2
, SR_96_000
);
6305 dspio_set_uint_param(codec
, 0x80, 0x01, tmp
);
6310 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
6311 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
6312 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
6313 * having an updated DAC, which changes the destination to that DAC.
6315 static void sbz_connect_streams(struct hda_codec
*codec
)
6317 struct ca0132_spec
*spec
= codec
->spec
;
6319 mutex_lock(&spec
->chipio_mutex
);
6321 codec_dbg(codec
, "Connect Streams entered, mutex locked and loaded.\n");
6323 chipio_set_stream_channels(codec
, 0x0C, 6);
6324 chipio_set_stream_control(codec
, 0x0C, 1);
6326 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
6327 chipio_write_no_mutex(codec
, 0x18a020, 0x00000043);
6329 /* Setup stream 0x14 with it's source and destination points */
6330 chipio_set_stream_source_dest(codec
, 0x14, 0x48, 0x91);
6331 chipio_set_conn_rate_no_mutex(codec
, 0x48, SR_96_000
);
6332 chipio_set_conn_rate_no_mutex(codec
, 0x91, SR_96_000
);
6333 chipio_set_stream_channels(codec
, 0x14, 2);
6334 chipio_set_stream_control(codec
, 0x14, 1);
6336 codec_dbg(codec
, "Connect Streams exited, mutex released.\n");
6338 mutex_unlock(&spec
->chipio_mutex
);
6343 * Write data through ChipIO to setup proper stream destinations.
6344 * Not sure how it exactly works, but it seems to direct data
6345 * to different destinations. Example is f8 to c0, e0 to c0.
6346 * All I know is, if you don't set these, you get no sound.
6348 static void sbz_chipio_startup_data(struct hda_codec
*codec
)
6350 struct ca0132_spec
*spec
= codec
->spec
;
6352 mutex_lock(&spec
->chipio_mutex
);
6353 codec_dbg(codec
, "Startup Data entered, mutex locked and loaded.\n");
6355 /* These control audio output */
6356 chipio_write_no_mutex(codec
, 0x190060, 0x0001f8c0);
6357 chipio_write_no_mutex(codec
, 0x190064, 0x0001f9c1);
6358 chipio_write_no_mutex(codec
, 0x190068, 0x0001fac6);
6359 chipio_write_no_mutex(codec
, 0x19006c, 0x0001fbc7);
6360 /* Signal to update I think */
6361 chipio_write_no_mutex(codec
, 0x19042c, 0x00000001);
6363 chipio_set_stream_channels(codec
, 0x0C, 6);
6364 chipio_set_stream_control(codec
, 0x0C, 1);
6365 /* No clue what these control */
6366 chipio_write_no_mutex(codec
, 0x190030, 0x0001e0c0);
6367 chipio_write_no_mutex(codec
, 0x190034, 0x0001e1c1);
6368 chipio_write_no_mutex(codec
, 0x190038, 0x0001e4c2);
6369 chipio_write_no_mutex(codec
, 0x19003c, 0x0001e5c3);
6370 chipio_write_no_mutex(codec
, 0x190040, 0x0001e2c4);
6371 chipio_write_no_mutex(codec
, 0x190044, 0x0001e3c5);
6372 chipio_write_no_mutex(codec
, 0x190048, 0x0001e8c6);
6373 chipio_write_no_mutex(codec
, 0x19004c, 0x0001e9c7);
6374 chipio_write_no_mutex(codec
, 0x190050, 0x0001ecc8);
6375 chipio_write_no_mutex(codec
, 0x190054, 0x0001edc9);
6376 chipio_write_no_mutex(codec
, 0x190058, 0x0001eaca);
6377 chipio_write_no_mutex(codec
, 0x19005c, 0x0001ebcb);
6379 chipio_write_no_mutex(codec
, 0x19042c, 0x00000001);
6381 codec_dbg(codec
, "Startup Data exited, mutex released.\n");
6382 mutex_unlock(&spec
->chipio_mutex
);
6386 * Sound Blaster Z uses these after DSP is loaded. Weird SCP commands
6387 * without a 0x20 source like normal.
6389 static void sbz_dsp_scp_startup(struct hda_codec
*codec
)
6394 dspio_set_uint_param_no_source(codec
, 0x80, 0x0C, tmp
);
6397 dspio_set_uint_param_no_source(codec
, 0x80, 0x0A, tmp
);
6400 dspio_set_uint_param_no_source(codec
, 0x80, 0x0B, tmp
);
6403 dspio_set_uint_param_no_source(codec
, 0x80, 0x0C, tmp
);
6406 dspio_set_uint_param_no_source(codec
, 0x80, 0x0C, tmp
);
6409 dspio_set_uint_param_no_source(codec
, 0x80, 0x0C, tmp
);
6413 static void sbz_dsp_initial_mic_setup(struct hda_codec
*codec
)
6417 chipio_set_stream_control(codec
, 0x03, 0);
6418 chipio_set_stream_control(codec
, 0x04, 0);
6420 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
6421 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
6424 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
6426 chipio_set_stream_control(codec
, 0x03, 1);
6427 chipio_set_stream_control(codec
, 0x04, 1);
6429 chipio_write(codec
, 0x18b098, 0x0000000c);
6430 chipio_write(codec
, 0x18b09C, 0x0000000c);
6434 * Setup default parameters for DSP
6436 static void ca0132_setup_defaults(struct hda_codec
*codec
)
6438 struct ca0132_spec
*spec
= codec
->spec
;
6443 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
6446 /* out, in effects + voicefx */
6447 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
6448 for (idx
= 0; idx
< num_fx
; idx
++) {
6449 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
6450 dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
6451 ca0132_effects
[idx
].reqs
[i
],
6452 ca0132_effects
[idx
].def_vals
[i
]);
6456 /*remove DSP headroom*/
6458 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
6460 /*set speaker EQ bypass attenuation*/
6461 dspio_set_uint_param(codec
, 0x8f, 0x01, tmp
);
6463 /* set AMic1 and AMic2 as mono mic */
6465 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
6466 dspio_set_uint_param(codec
, 0x80, 0x01, tmp
);
6468 /* set AMic1 as CrystalVoice input */
6470 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
6472 /* set WUH source */
6474 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
6478 * Setup default parameters for Recon3D/Recon3Di DSP.
6481 static void r3d_setup_defaults(struct hda_codec
*codec
)
6483 struct ca0132_spec
*spec
= codec
->spec
;
6488 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
6491 r3d_dsp_scp_startup(codec
);
6493 r3d_dsp_initial_mic_setup(codec
);
6495 /*remove DSP headroom*/
6497 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
6499 /* set WUH source */
6501 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
6502 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
6504 /* Set speaker source? */
6505 dspio_set_uint_param(codec
, 0x32, 0x00, tmp
);
6507 if (spec
->quirk
== QUIRK_R3DI
)
6508 r3di_gpio_dsp_status_set(codec
, R3DI_DSP_DOWNLOADED
);
6510 /* Setup effect defaults */
6511 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
6512 for (idx
= 0; idx
< num_fx
; idx
++) {
6513 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
6514 dspio_set_uint_param(codec
,
6515 ca0132_effects
[idx
].mid
,
6516 ca0132_effects
[idx
].reqs
[i
],
6517 ca0132_effects
[idx
].def_vals
[i
]);
6523 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
6524 * than the Chromebook setup.
6526 static void sbz_setup_defaults(struct hda_codec
*codec
)
6528 struct ca0132_spec
*spec
= codec
->spec
;
6529 unsigned int tmp
, stream_format
;
6533 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
6536 sbz_dsp_scp_startup(codec
);
6538 sbz_init_analog_mics(codec
);
6540 sbz_connect_streams(codec
);
6542 sbz_chipio_startup_data(codec
);
6544 chipio_set_stream_control(codec
, 0x03, 1);
6545 chipio_set_stream_control(codec
, 0x04, 1);
6548 * Sets internal input loopback to off, used to have a switch to
6549 * enable input loopback, but turned out to be way too buggy.
6552 dspio_set_uint_param(codec
, 0x37, 0x08, tmp
);
6553 dspio_set_uint_param(codec
, 0x37, 0x10, tmp
);
6555 /*remove DSP headroom*/
6557 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
6559 /* set WUH source */
6561 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
6562 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
6564 /* Set speaker source? */
6565 dspio_set_uint_param(codec
, 0x32, 0x00, tmp
);
6567 sbz_dsp_initial_mic_setup(codec
);
6570 /* out, in effects + voicefx */
6571 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
6572 for (idx
= 0; idx
< num_fx
; idx
++) {
6573 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
6574 dspio_set_uint_param(codec
,
6575 ca0132_effects
[idx
].mid
,
6576 ca0132_effects
[idx
].reqs
[i
],
6577 ca0132_effects
[idx
].def_vals
[i
]);
6582 * Have to make a stream to bind the sound output to, otherwise
6583 * you'll get dead audio. Before I did this, it would bind to an
6584 * audio input, and would never work
6586 stream_format
= snd_hdac_calc_stream_format(48000, 2,
6587 SNDRV_PCM_FORMAT_S32_LE
, 32, 0);
6589 snd_hda_codec_setup_stream(codec
, spec
->dacs
[0], spec
->dsp_stream_id
,
6592 snd_hda_codec_cleanup_stream(codec
, spec
->dacs
[0]);
6594 snd_hda_codec_setup_stream(codec
, spec
->dacs
[0], spec
->dsp_stream_id
,
6597 snd_hda_codec_cleanup_stream(codec
, spec
->dacs
[0]);
6601 * Initialization of flags in chip
6603 static void ca0132_init_flags(struct hda_codec
*codec
)
6605 struct ca0132_spec
*spec
= codec
->spec
;
6607 if (spec
->use_alt_functions
) {
6608 chipio_set_control_flag(codec
, CONTROL_FLAG_DSP_96KHZ
, 1);
6609 chipio_set_control_flag(codec
, CONTROL_FLAG_DAC_96KHZ
, 1);
6610 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_B_96KHZ
, 1);
6611 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_96KHZ
, 1);
6612 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_RATE_96KHZ
, 1);
6613 chipio_set_control_flag(codec
, CONTROL_FLAG_IDLE_ENABLE
, 0);
6614 chipio_set_control_flag(codec
, CONTROL_FLAG_SPDIF2OUT
, 0);
6615 chipio_set_control_flag(codec
,
6616 CONTROL_FLAG_PORT_D_10KOHM_LOAD
, 0);
6617 chipio_set_control_flag(codec
,
6618 CONTROL_FLAG_PORT_A_10KOHM_LOAD
, 1);
6620 chipio_set_control_flag(codec
, CONTROL_FLAG_IDLE_ENABLE
, 0);
6621 chipio_set_control_flag(codec
,
6622 CONTROL_FLAG_PORT_A_COMMON_MODE
, 0);
6623 chipio_set_control_flag(codec
,
6624 CONTROL_FLAG_PORT_D_COMMON_MODE
, 0);
6625 chipio_set_control_flag(codec
,
6626 CONTROL_FLAG_PORT_A_10KOHM_LOAD
, 0);
6627 chipio_set_control_flag(codec
,
6628 CONTROL_FLAG_PORT_D_10KOHM_LOAD
, 0);
6629 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_HIGH_PASS
, 1);
6634 * Initialization of parameters in chip
6636 static void ca0132_init_params(struct hda_codec
*codec
)
6638 struct ca0132_spec
*spec
= codec
->spec
;
6640 if (spec
->use_alt_functions
) {
6641 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
6642 chipio_set_conn_rate(codec
, 0x0B, SR_48_000
);
6643 chipio_set_control_param(codec
, CONTROL_PARAM_SPDIF1_SOURCE
, 0);
6644 chipio_set_control_param(codec
, 0, 0);
6645 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, 0);
6648 chipio_set_control_param(codec
, CONTROL_PARAM_PORTA_160OHM_GAIN
, 6);
6649 chipio_set_control_param(codec
, CONTROL_PARAM_PORTD_160OHM_GAIN
, 6);
6652 static void ca0132_set_dsp_msr(struct hda_codec
*codec
, bool is96k
)
6654 chipio_set_control_flag(codec
, CONTROL_FLAG_DSP_96KHZ
, is96k
);
6655 chipio_set_control_flag(codec
, CONTROL_FLAG_DAC_96KHZ
, is96k
);
6656 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_RATE_96KHZ
, is96k
);
6657 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_CLOCK_196MHZ
, is96k
);
6658 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_B_96KHZ
, is96k
);
6659 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_96KHZ
, is96k
);
6661 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
6662 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
6663 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
6666 static bool ca0132_download_dsp_images(struct hda_codec
*codec
)
6668 bool dsp_loaded
= false;
6669 struct ca0132_spec
*spec
= codec
->spec
;
6670 const struct dsp_image_seg
*dsp_os_image
;
6671 const struct firmware
*fw_entry
;
6673 * Alternate firmwares for different variants. The Recon3Di apparently
6674 * can use the default firmware, but I'll leave the option in case
6675 * it needs it again.
6677 switch (spec
->quirk
) {
6679 if (request_firmware(&fw_entry
, SBZ_EFX_FILE
,
6680 codec
->card
->dev
) != 0) {
6681 codec_dbg(codec
, "SBZ alt firmware not detected. ");
6682 spec
->alt_firmware_present
= false;
6684 codec_dbg(codec
, "Sound Blaster Z firmware selected.");
6685 spec
->alt_firmware_present
= true;
6689 if (request_firmware(&fw_entry
, R3DI_EFX_FILE
,
6690 codec
->card
->dev
) != 0) {
6691 codec_dbg(codec
, "Recon3Di alt firmware not detected.");
6692 spec
->alt_firmware_present
= false;
6694 codec_dbg(codec
, "Recon3Di firmware selected.");
6695 spec
->alt_firmware_present
= true;
6699 spec
->alt_firmware_present
= false;
6703 * Use default ctefx.bin if no alt firmware is detected, or if none
6704 * exists for your particular codec.
6706 if (!spec
->alt_firmware_present
) {
6707 codec_dbg(codec
, "Default firmware selected.");
6708 if (request_firmware(&fw_entry
, EFX_FILE
,
6709 codec
->card
->dev
) != 0)
6713 dsp_os_image
= (struct dsp_image_seg
*)(fw_entry
->data
);
6714 if (dspload_image(codec
, dsp_os_image
, 0, 0, true, 0)) {
6715 codec_err(codec
, "ca0132 DSP load image failed\n");
6719 dsp_loaded
= dspload_wait_loaded(codec
);
6722 release_firmware(fw_entry
);
6727 static void ca0132_download_dsp(struct hda_codec
*codec
)
6729 struct ca0132_spec
*spec
= codec
->spec
;
6731 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
6735 if (spec
->dsp_state
== DSP_DOWNLOAD_FAILED
)
6736 return; /* don't retry failures */
6738 chipio_enable_clocks(codec
);
6739 if (spec
->dsp_state
!= DSP_DOWNLOADED
) {
6740 spec
->dsp_state
= DSP_DOWNLOADING
;
6742 if (!ca0132_download_dsp_images(codec
))
6743 spec
->dsp_state
= DSP_DOWNLOAD_FAILED
;
6745 spec
->dsp_state
= DSP_DOWNLOADED
;
6748 /* For codecs using alt functions, this is already done earlier */
6749 if (spec
->dsp_state
== DSP_DOWNLOADED
&& (!spec
->use_alt_functions
))
6750 ca0132_set_dsp_msr(codec
, true);
6753 static void ca0132_process_dsp_response(struct hda_codec
*codec
,
6754 struct hda_jack_callback
*callback
)
6756 struct ca0132_spec
*spec
= codec
->spec
;
6758 codec_dbg(codec
, "ca0132_process_dsp_response\n");
6759 snd_hda_power_up_pm(codec
);
6760 if (spec
->wait_scp
) {
6761 if (dspio_get_response_data(codec
) >= 0)
6765 dspio_clear_response_queue(codec
);
6766 snd_hda_power_down_pm(codec
);
6769 static void hp_callback(struct hda_codec
*codec
, struct hda_jack_callback
*cb
)
6771 struct ca0132_spec
*spec
= codec
->spec
;
6772 struct hda_jack_tbl
*tbl
;
6774 /* Delay enabling the HP amp, to let the mic-detection
6775 * state machine run.
6777 tbl
= snd_hda_jack_tbl_get(codec
, cb
->nid
);
6779 tbl
->block_report
= 1;
6780 schedule_delayed_work(&spec
->unsol_hp_work
, msecs_to_jiffies(500));
6783 static void amic_callback(struct hda_codec
*codec
, struct hda_jack_callback
*cb
)
6785 struct ca0132_spec
*spec
= codec
->spec
;
6787 if (spec
->use_alt_functions
)
6788 ca0132_alt_select_in(codec
);
6790 ca0132_select_mic(codec
);
6793 static void ca0132_init_unsol(struct hda_codec
*codec
)
6795 struct ca0132_spec
*spec
= codec
->spec
;
6796 snd_hda_jack_detect_enable_callback(codec
, spec
->unsol_tag_hp
, hp_callback
);
6797 snd_hda_jack_detect_enable_callback(codec
, spec
->unsol_tag_amic1
,
6799 snd_hda_jack_detect_enable_callback(codec
, UNSOL_TAG_DSP
,
6800 ca0132_process_dsp_response
);
6801 /* Front headphone jack detection */
6802 if (spec
->use_alt_functions
)
6803 snd_hda_jack_detect_enable_callback(codec
,
6804 spec
->unsol_tag_front_hp
, hp_callback
);
6811 /* Sends before DSP download. */
6812 static struct hda_verb ca0132_base_init_verbs
[] = {
6813 /*enable ct extension*/
6814 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
, 0x1},
6819 static struct hda_verb ca0132_base_exit_verbs
[] = {
6821 {0x01, AC_VERB_SET_POWER_STATE
, 0x03},
6822 /*disable ct extension*/
6823 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
, 0},
6827 /* Other verbs tables. Sends after DSP download. */
6829 static struct hda_verb ca0132_init_verbs0
[] = {
6830 /* chip init verbs */
6831 {0x15, 0x70D, 0xF0},
6832 {0x15, 0x70E, 0xFE},
6833 {0x15, 0x707, 0x75},
6834 {0x15, 0x707, 0xD3},
6835 {0x15, 0x707, 0x09},
6836 {0x15, 0x707, 0x53},
6837 {0x15, 0x707, 0xD4},
6838 {0x15, 0x707, 0xEF},
6839 {0x15, 0x707, 0x75},
6840 {0x15, 0x707, 0xD3},
6841 {0x15, 0x707, 0x09},
6842 {0x15, 0x707, 0x02},
6843 {0x15, 0x707, 0x37},
6844 {0x15, 0x707, 0x78},
6845 {0x15, 0x53C, 0xCE},
6846 {0x15, 0x575, 0xC9},
6847 {0x15, 0x53D, 0xCE},
6848 {0x15, 0x5B7, 0xC9},
6849 {0x15, 0x70D, 0xE8},
6850 {0x15, 0x70E, 0xFE},
6851 {0x15, 0x707, 0x02},
6852 {0x15, 0x707, 0x68},
6853 {0x15, 0x707, 0x62},
6854 {0x15, 0x53A, 0xCE},
6855 {0x15, 0x546, 0xC9},
6856 {0x15, 0x53B, 0xCE},
6857 {0x15, 0x5E8, 0xC9},
6861 /* Extra init verbs for desktop cards. */
6862 static struct hda_verb ca0132_init_verbs1
[] = {
6863 {0x15, 0x70D, 0x20},
6864 {0x15, 0x70E, 0x19},
6865 {0x15, 0x707, 0x00},
6866 {0x15, 0x539, 0xCE},
6867 {0x15, 0x546, 0xC9},
6868 {0x15, 0x70D, 0xB7},
6869 {0x15, 0x70E, 0x09},
6870 {0x15, 0x707, 0x10},
6871 {0x15, 0x70D, 0xAF},
6872 {0x15, 0x70E, 0x09},
6873 {0x15, 0x707, 0x01},
6874 {0x15, 0x707, 0x05},
6875 {0x15, 0x70D, 0x73},
6876 {0x15, 0x70E, 0x09},
6877 {0x15, 0x707, 0x14},
6878 {0x15, 0x6FF, 0xC4},
6882 static void ca0132_init_chip(struct hda_codec
*codec
)
6884 struct ca0132_spec
*spec
= codec
->spec
;
6889 mutex_init(&spec
->chipio_mutex
);
6891 spec
->cur_out_type
= SPEAKER_OUT
;
6892 if (!spec
->use_alt_functions
)
6893 spec
->cur_mic_type
= DIGITAL_MIC
;
6895 spec
->cur_mic_type
= REAR_MIC
;
6897 spec
->cur_mic_boost
= 0;
6899 for (i
= 0; i
< VNODES_COUNT
; i
++) {
6900 spec
->vnode_lvol
[i
] = 0x5a;
6901 spec
->vnode_rvol
[i
] = 0x5a;
6902 spec
->vnode_lswitch
[i
] = 0;
6903 spec
->vnode_rswitch
[i
] = 0;
6907 * Default states for effects are in ca0132_effects[].
6909 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
6910 for (i
= 0; i
< num_fx
; i
++) {
6911 on
= (unsigned int)ca0132_effects
[i
].reqs
[0];
6912 spec
->effects_switch
[i
] = on
? 1 : 0;
6915 * Sets defaults for the effect slider controls, only for alternative
6916 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
6918 if (spec
->use_alt_controls
) {
6919 spec
->xbass_xover_freq
= 8;
6920 for (i
= 0; i
< EFFECT_LEVEL_SLIDERS
; i
++)
6921 spec
->fx_ctl_val
[i
] = effect_slider_defaults
[i
];
6924 spec
->voicefx_val
= 0;
6925 spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
] = 1;
6926 spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] = 0;
6928 #ifdef ENABLE_TUNING_CONTROLS
6929 ca0132_init_tuning_defaults(codec
);
6934 * Recon3Di exit specific commands.
6936 /* prevents popping noise on shutdown */
6937 static void r3di_gpio_shutdown(struct hda_codec
*codec
)
6939 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
, 0x00);
6943 * Sound Blaster Z exit specific commands.
6945 static void sbz_region2_exit(struct hda_codec
*codec
)
6947 struct ca0132_spec
*spec
= codec
->spec
;
6950 for (i
= 0; i
< 4; i
++)
6951 writeb(0x0, spec
->mem_base
+ 0x100);
6952 for (i
= 0; i
< 8; i
++)
6953 writeb(0xb3, spec
->mem_base
+ 0x304);
6955 ca0132_mmio_gpio_set(codec
, 0, false);
6956 ca0132_mmio_gpio_set(codec
, 1, false);
6957 ca0132_mmio_gpio_set(codec
, 4, true);
6958 ca0132_mmio_gpio_set(codec
, 5, false);
6959 ca0132_mmio_gpio_set(codec
, 7, false);
6962 static void sbz_set_pin_ctl_default(struct hda_codec
*codec
)
6964 hda_nid_t pins
[5] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
6967 snd_hda_codec_write(codec
, 0x11, 0,
6968 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40);
6970 for (i
= 0; i
< 5; i
++)
6971 snd_hda_codec_write(codec
, pins
[i
], 0,
6972 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x00);
6975 static void ca0132_clear_unsolicited(struct hda_codec
*codec
)
6977 hda_nid_t pins
[7] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
6980 for (i
= 0; i
< 7; i
++) {
6981 snd_hda_codec_write(codec
, pins
[i
], 0,
6982 AC_VERB_SET_UNSOLICITED_ENABLE
, 0x00);
6986 /* On shutdown, sends commands in sets of three */
6987 static void sbz_gpio_shutdown_commands(struct hda_codec
*codec
, int dir
,
6991 snd_hda_codec_write(codec
, 0x01, 0,
6992 AC_VERB_SET_GPIO_DIRECTION
, dir
);
6994 snd_hda_codec_write(codec
, 0x01, 0,
6995 AC_VERB_SET_GPIO_MASK
, mask
);
6998 snd_hda_codec_write(codec
, 0x01, 0,
6999 AC_VERB_SET_GPIO_DATA
, data
);
7002 static void sbz_exit_chip(struct hda_codec
*codec
)
7004 chipio_set_stream_control(codec
, 0x03, 0);
7005 chipio_set_stream_control(codec
, 0x04, 0);
7007 /* Mess with GPIO */
7008 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, -1);
7009 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x05);
7010 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x01);
7012 chipio_set_stream_control(codec
, 0x14, 0);
7013 chipio_set_stream_control(codec
, 0x0C, 0);
7015 chipio_set_conn_rate(codec
, 0x41, SR_192_000
);
7016 chipio_set_conn_rate(codec
, 0x91, SR_192_000
);
7018 chipio_write(codec
, 0x18a020, 0x00000083);
7020 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x03);
7021 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x07);
7022 sbz_gpio_shutdown_commands(codec
, 0x07, 0x07, 0x06);
7024 chipio_set_stream_control(codec
, 0x0C, 0);
7026 chipio_set_control_param(codec
, 0x0D, 0x24);
7028 ca0132_clear_unsolicited(codec
);
7029 sbz_set_pin_ctl_default(codec
);
7031 snd_hda_codec_write(codec
, 0x0B, 0,
7032 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
7034 sbz_region2_exit(codec
);
7037 static void r3d_exit_chip(struct hda_codec
*codec
)
7039 ca0132_clear_unsolicited(codec
);
7040 snd_hda_codec_write(codec
, 0x01, 0, 0x793, 0x00);
7041 snd_hda_codec_write(codec
, 0x01, 0, 0x794, 0x5b);
7044 static void ca0132_exit_chip(struct hda_codec
*codec
)
7046 /* put any chip cleanup stuffs here. */
7048 if (dspload_is_loaded(codec
))
7053 * This fixes a problem that was hard to reproduce. Very rarely, I would
7054 * boot up, and there would be no sound, but the DSP indicated it had loaded
7055 * properly. I did a few memory dumps to see if anything was different, and
7056 * there were a few areas of memory uninitialized with a1a2a3a4. This function
7057 * checks if those areas are uninitialized, and if they are, it'll attempt to
7058 * reload the card 3 times. Usually it fixes by the second.
7060 static void sbz_dsp_startup_check(struct hda_codec
*codec
)
7062 struct ca0132_spec
*spec
= codec
->spec
;
7063 unsigned int dsp_data_check
[4];
7064 unsigned int cur_address
= 0x390;
7066 unsigned int failure
= 0;
7067 unsigned int reload
= 3;
7069 if (spec
->startup_check_entered
)
7072 spec
->startup_check_entered
= true;
7074 for (i
= 0; i
< 4; i
++) {
7075 chipio_read(codec
, cur_address
, &dsp_data_check
[i
]);
7078 for (i
= 0; i
< 4; i
++) {
7079 if (dsp_data_check
[i
] == 0xa1a2a3a4)
7083 codec_dbg(codec
, "Startup Check: %d ", failure
);
7085 codec_info(codec
, "DSP not initialized properly. Attempting to fix.");
7087 * While the failure condition is true, and we haven't reached our
7088 * three reload limit, continue trying to reload the driver and
7091 while (failure
&& (reload
!= 0)) {
7092 codec_info(codec
, "Reloading... Tries left: %d", reload
);
7093 sbz_exit_chip(codec
);
7094 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
7095 codec
->patch_ops
.init(codec
);
7097 for (i
= 0; i
< 4; i
++) {
7098 chipio_read(codec
, cur_address
, &dsp_data_check
[i
]);
7101 for (i
= 0; i
< 4; i
++) {
7102 if (dsp_data_check
[i
] == 0xa1a2a3a4)
7108 if (!failure
&& reload
< 3)
7109 codec_info(codec
, "DSP fixed.");
7114 codec_info(codec
, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
7118 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
7119 * extra precision for decibel values. If you had the dB value in floating point
7120 * you would take the value after the decimal point, multiply by 64, and divide
7121 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
7122 * implement fixed point or floating point dB volumes. For now, I'll set them
7123 * to 0 just incase a value has lingered from a boot into Windows.
7125 static void ca0132_alt_vol_setup(struct hda_codec
*codec
)
7127 snd_hda_codec_write(codec
, 0x02, 0, 0x797, 0x00);
7128 snd_hda_codec_write(codec
, 0x02, 0, 0x798, 0x00);
7129 snd_hda_codec_write(codec
, 0x03, 0, 0x797, 0x00);
7130 snd_hda_codec_write(codec
, 0x03, 0, 0x798, 0x00);
7131 snd_hda_codec_write(codec
, 0x04, 0, 0x797, 0x00);
7132 snd_hda_codec_write(codec
, 0x04, 0, 0x798, 0x00);
7133 snd_hda_codec_write(codec
, 0x07, 0, 0x797, 0x00);
7134 snd_hda_codec_write(codec
, 0x07, 0, 0x798, 0x00);
7138 * Extra commands that don't really fit anywhere else.
7140 static void sbz_pre_dsp_setup(struct hda_codec
*codec
)
7142 struct ca0132_spec
*spec
= codec
->spec
;
7144 writel(0x00820680, spec
->mem_base
+ 0x01C);
7145 writel(0x00820680, spec
->mem_base
+ 0x01C);
7147 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xfc);
7148 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xfd);
7149 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xfe);
7150 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xff);
7152 chipio_write(codec
, 0x18b0a4, 0x000000c2);
7154 snd_hda_codec_write(codec
, 0x11, 0,
7155 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x44);
7158 static void r3d_pre_dsp_setup(struct hda_codec
*codec
)
7161 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xfc);
7162 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xfd);
7163 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xfe);
7164 snd_hda_codec_write(codec
, 0x15, 0, 0xd00, 0xff);
7166 chipio_write(codec
, 0x18b0a4, 0x000000c2);
7168 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7169 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0x1E);
7170 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7171 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, 0x1C);
7172 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7173 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x5B);
7175 snd_hda_codec_write(codec
, 0x11, 0,
7176 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x44);
7179 static void r3di_pre_dsp_setup(struct hda_codec
*codec
)
7181 chipio_write(codec
, 0x18b0a4, 0x000000c2);
7183 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7184 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0x1E);
7185 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7186 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, 0x1C);
7187 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7188 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x5B);
7190 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7191 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0x20);
7192 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7193 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, 0x19);
7194 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7195 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x00);
7196 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7197 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x40);
7199 snd_hda_codec_write(codec
, 0x11, 0,
7200 AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x04);
7204 * These are sent before the DSP is downloaded. Not sure
7205 * what they do, or if they're necessary. Could possibly
7206 * be removed. Figure they're better to leave in.
7208 static void ca0132_mmio_init(struct hda_codec
*codec
)
7210 struct ca0132_spec
*spec
= codec
->spec
;
7212 writel(0x00000000, spec
->mem_base
+ 0x400);
7213 writel(0x00000000, spec
->mem_base
+ 0x408);
7214 writel(0x00000000, spec
->mem_base
+ 0x40C);
7215 writel(0x00880680, spec
->mem_base
+ 0x01C);
7216 writel(0x00000083, spec
->mem_base
+ 0xC0C);
7217 writel(0x00000030, spec
->mem_base
+ 0xC00);
7218 writel(0x00000000, spec
->mem_base
+ 0xC04);
7219 writel(0x00000003, spec
->mem_base
+ 0xC0C);
7220 writel(0x00000003, spec
->mem_base
+ 0xC0C);
7221 writel(0x00000003, spec
->mem_base
+ 0xC0C);
7222 writel(0x00000003, spec
->mem_base
+ 0xC0C);
7223 writel(0x000000C1, spec
->mem_base
+ 0xC08);
7224 writel(0x000000F1, spec
->mem_base
+ 0xC08);
7225 writel(0x00000001, spec
->mem_base
+ 0xC08);
7226 writel(0x000000C7, spec
->mem_base
+ 0xC08);
7227 writel(0x000000C1, spec
->mem_base
+ 0xC08);
7228 writel(0x00000080, spec
->mem_base
+ 0xC04);
7232 * Extra init functions for alternative ca0132 codecs. Done
7233 * here so they don't clutter up the main ca0132_init function
7234 * anymore than they have to.
7236 static void ca0132_alt_init(struct hda_codec
*codec
)
7238 struct ca0132_spec
*spec
= codec
->spec
;
7240 ca0132_alt_vol_setup(codec
);
7242 switch (spec
->quirk
) {
7244 codec_dbg(codec
, "SBZ alt_init");
7245 ca0132_gpio_init(codec
);
7246 sbz_pre_dsp_setup(codec
);
7247 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
7248 snd_hda_sequence_write(codec
, spec
->desktop_init_verbs
);
7251 codec_dbg(codec
, "R3DI alt_init");
7252 ca0132_gpio_init(codec
);
7253 ca0132_gpio_setup(codec
);
7254 r3di_gpio_dsp_status_set(codec
, R3DI_DSP_DOWNLOADING
);
7255 r3di_pre_dsp_setup(codec
);
7256 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
7257 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0, 0x6FF, 0xC4);
7260 r3d_pre_dsp_setup(codec
);
7261 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
7262 snd_hda_sequence_write(codec
, spec
->desktop_init_verbs
);
7267 static int ca0132_init(struct hda_codec
*codec
)
7269 struct ca0132_spec
*spec
= codec
->spec
;
7270 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
7275 * If the DSP is already downloaded, and init has been entered again,
7276 * there's only two reasons for it. One, the codec has awaken from a
7277 * suspended state, and in that case dspload_is_loaded will return
7278 * false, and the init will be ran again. The other reason it gets
7279 * re entered is on startup for some reason it triggers a suspend and
7280 * resume state. In this case, it will check if the DSP is downloaded,
7281 * and not run the init function again. For codecs using alt_functions,
7282 * it will check if the DSP is loaded properly.
7284 if (spec
->dsp_state
== DSP_DOWNLOADED
) {
7285 dsp_loaded
= dspload_is_loaded(codec
);
7287 spec
->dsp_reload
= true;
7288 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
7290 if (spec
->quirk
== QUIRK_SBZ
)
7291 sbz_dsp_startup_check(codec
);
7296 if (spec
->dsp_state
!= DSP_DOWNLOAD_FAILED
)
7297 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
7298 spec
->curr_chip_addx
= INVALID_CHIP_ADDRESS
;
7300 if (spec
->use_pci_mmio
)
7301 ca0132_mmio_init(codec
);
7303 snd_hda_power_up_pm(codec
);
7305 ca0132_init_unsol(codec
);
7306 ca0132_init_params(codec
);
7307 ca0132_init_flags(codec
);
7309 snd_hda_sequence_write(codec
, spec
->base_init_verbs
);
7311 if (spec
->use_alt_functions
)
7312 ca0132_alt_init(codec
);
7314 ca0132_download_dsp(codec
);
7316 ca0132_refresh_widget_caps(codec
);
7318 switch (spec
->quirk
) {
7321 r3d_setup_defaults(codec
);
7324 sbz_setup_defaults(codec
);
7327 ca0132_setup_defaults(codec
);
7328 ca0132_init_analog_mic2(codec
);
7329 ca0132_init_dmic(codec
);
7333 for (i
= 0; i
< spec
->num_outputs
; i
++)
7334 init_output(codec
, spec
->out_pins
[i
], spec
->dacs
[0]);
7336 init_output(codec
, cfg
->dig_out_pins
[0], spec
->dig_out
);
7338 for (i
= 0; i
< spec
->num_inputs
; i
++)
7339 init_input(codec
, spec
->input_pins
[i
], spec
->adcs
[i
]);
7341 init_input(codec
, cfg
->dig_in_pin
, spec
->dig_in
);
7343 if (!spec
->use_alt_functions
) {
7344 snd_hda_sequence_write(codec
, spec
->chip_init_verbs
);
7345 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7346 VENDOR_CHIPIO_PARAM_EX_ID_SET
, 0x0D);
7347 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
7348 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
, 0x20);
7351 if (spec
->quirk
== QUIRK_SBZ
)
7352 ca0132_gpio_setup(codec
);
7354 snd_hda_sequence_write(codec
, spec
->spec_init_verbs
);
7355 if (spec
->use_alt_functions
) {
7356 ca0132_alt_select_out(codec
);
7357 ca0132_alt_select_in(codec
);
7359 ca0132_select_out(codec
);
7360 ca0132_select_mic(codec
);
7363 snd_hda_jack_report_sync(codec
);
7366 * Re set the PlayEnhancement switch on a resume event, because the
7367 * controls will not be reloaded.
7369 if (spec
->dsp_reload
) {
7370 spec
->dsp_reload
= false;
7371 ca0132_pe_switch_set(codec
);
7374 snd_hda_power_down_pm(codec
);
7379 static void ca0132_free(struct hda_codec
*codec
)
7381 struct ca0132_spec
*spec
= codec
->spec
;
7383 cancel_delayed_work_sync(&spec
->unsol_hp_work
);
7384 snd_hda_power_up(codec
);
7385 switch (spec
->quirk
) {
7387 sbz_exit_chip(codec
);
7390 r3d_exit_chip(codec
);
7393 r3di_gpio_shutdown(codec
);
7397 snd_hda_sequence_write(codec
, spec
->base_exit_verbs
);
7398 ca0132_exit_chip(codec
);
7400 snd_hda_power_down(codec
);
7403 pci_iounmap(codec
->bus
->pci
, spec
->mem_base
);
7405 kfree(spec
->spec_init_verbs
);
7409 static void ca0132_reboot_notify(struct hda_codec
*codec
)
7411 codec
->patch_ops
.free(codec
);
7415 static int ca0132_suspend(struct hda_codec
*codec
)
7417 struct ca0132_spec
*spec
= codec
->spec
;
7419 cancel_delayed_work_sync(&spec
->unsol_hp_work
);
7424 static const struct hda_codec_ops ca0132_patch_ops
= {
7425 .build_controls
= ca0132_build_controls
,
7426 .build_pcms
= ca0132_build_pcms
,
7427 .init
= ca0132_init
,
7428 .free
= ca0132_free
,
7429 .unsol_event
= snd_hda_jack_unsol_event
,
7431 .suspend
= ca0132_suspend
,
7433 .reboot_notify
= ca0132_reboot_notify
,
7436 static void ca0132_config(struct hda_codec
*codec
)
7438 struct ca0132_spec
*spec
= codec
->spec
;
7440 spec
->dacs
[0] = 0x2;
7441 spec
->dacs
[1] = 0x3;
7442 spec
->dacs
[2] = 0x4;
7444 spec
->multiout
.dac_nids
= spec
->dacs
;
7445 spec
->multiout
.num_dacs
= 3;
7447 if (!spec
->use_alt_functions
)
7448 spec
->multiout
.max_channels
= 2;
7450 spec
->multiout
.max_channels
= 6;
7452 switch (spec
->quirk
) {
7453 case QUIRK_ALIENWARE
:
7454 codec_dbg(codec
, "ca0132_config: QUIRK_ALIENWARE applied.\n");
7455 snd_hda_apply_pincfgs(codec
, alienware_pincfgs
);
7457 spec
->num_outputs
= 2;
7458 spec
->out_pins
[0] = 0x0b; /* speaker out */
7459 spec
->out_pins
[1] = 0x0f;
7460 spec
->shared_out_nid
= 0x2;
7461 spec
->unsol_tag_hp
= 0x0f;
7463 spec
->adcs
[0] = 0x7; /* digital mic / analog mic1 */
7464 spec
->adcs
[1] = 0x8; /* analog mic2 */
7465 spec
->adcs
[2] = 0xa; /* what u hear */
7467 spec
->num_inputs
= 3;
7468 spec
->input_pins
[0] = 0x12;
7469 spec
->input_pins
[1] = 0x11;
7470 spec
->input_pins
[2] = 0x13;
7471 spec
->shared_mic_nid
= 0x7;
7472 spec
->unsol_tag_amic1
= 0x11;
7476 if (spec
->quirk
== QUIRK_SBZ
) {
7477 codec_dbg(codec
, "%s: QUIRK_SBZ applied.\n", __func__
);
7478 snd_hda_apply_pincfgs(codec
, sbz_pincfgs
);
7480 if (spec
->quirk
== QUIRK_R3D
) {
7481 codec_dbg(codec
, "%s: QUIRK_R3D applied.\n", __func__
);
7482 snd_hda_apply_pincfgs(codec
, r3d_pincfgs
);
7485 spec
->num_outputs
= 2;
7486 spec
->out_pins
[0] = 0x0B; /* Line out */
7487 spec
->out_pins
[1] = 0x0F; /* Rear headphone out */
7488 spec
->out_pins
[2] = 0x10; /* Front Headphone / Center/LFE*/
7489 spec
->out_pins
[3] = 0x11; /* Rear surround */
7490 spec
->shared_out_nid
= 0x2;
7491 spec
->unsol_tag_hp
= spec
->out_pins
[1];
7492 spec
->unsol_tag_front_hp
= spec
->out_pins
[2];
7494 spec
->adcs
[0] = 0x7; /* Rear Mic / Line-in */
7495 spec
->adcs
[1] = 0x8; /* Front Mic, but only if no DSP */
7496 spec
->adcs
[2] = 0xa; /* what u hear */
7498 spec
->num_inputs
= 2;
7499 spec
->input_pins
[0] = 0x12; /* Rear Mic / Line-in */
7500 spec
->input_pins
[1] = 0x13; /* What U Hear */
7501 spec
->shared_mic_nid
= 0x7;
7502 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
7505 spec
->dig_out
= 0x05;
7506 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
7507 spec
->dig_in
= 0x09;
7510 codec_dbg(codec
, "%s: QUIRK_R3DI applied.\n", __func__
);
7511 snd_hda_apply_pincfgs(codec
, r3di_pincfgs
);
7513 spec
->num_outputs
= 2;
7514 spec
->out_pins
[0] = 0x0B; /* Line out */
7515 spec
->out_pins
[1] = 0x0F; /* Rear headphone out */
7516 spec
->out_pins
[2] = 0x10; /* Front Headphone / Center/LFE*/
7517 spec
->out_pins
[3] = 0x11; /* Rear surround */
7518 spec
->shared_out_nid
= 0x2;
7519 spec
->unsol_tag_hp
= spec
->out_pins
[1];
7520 spec
->unsol_tag_front_hp
= spec
->out_pins
[2];
7522 spec
->adcs
[0] = 0x07; /* Rear Mic / Line-in */
7523 spec
->adcs
[1] = 0x08; /* Front Mic, but only if no DSP */
7524 spec
->adcs
[2] = 0x0a; /* what u hear */
7526 spec
->num_inputs
= 2;
7527 spec
->input_pins
[0] = 0x12; /* Rear Mic / Line-in */
7528 spec
->input_pins
[1] = 0x13; /* What U Hear */
7529 spec
->shared_mic_nid
= 0x7;
7530 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
7533 spec
->dig_out
= 0x05;
7534 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
7537 spec
->num_outputs
= 2;
7538 spec
->out_pins
[0] = 0x0b; /* speaker out */
7539 spec
->out_pins
[1] = 0x10; /* headphone out */
7540 spec
->shared_out_nid
= 0x2;
7541 spec
->unsol_tag_hp
= spec
->out_pins
[1];
7543 spec
->adcs
[0] = 0x7; /* digital mic / analog mic1 */
7544 spec
->adcs
[1] = 0x8; /* analog mic2 */
7545 spec
->adcs
[2] = 0xa; /* what u hear */
7547 spec
->num_inputs
= 3;
7548 spec
->input_pins
[0] = 0x12;
7549 spec
->input_pins
[1] = 0x11;
7550 spec
->input_pins
[2] = 0x13;
7551 spec
->shared_mic_nid
= 0x7;
7552 spec
->unsol_tag_amic1
= spec
->input_pins
[0];
7555 spec
->dig_out
= 0x05;
7556 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
7557 spec
->dig_in
= 0x09;
7562 static int ca0132_prepare_verbs(struct hda_codec
*codec
)
7564 /* Verbs + terminator (an empty element) */
7565 #define NUM_SPEC_VERBS 2
7566 struct ca0132_spec
*spec
= codec
->spec
;
7568 spec
->chip_init_verbs
= ca0132_init_verbs0
;
7569 if (spec
->quirk
== QUIRK_SBZ
|| spec
->quirk
== QUIRK_R3D
)
7570 spec
->desktop_init_verbs
= ca0132_init_verbs1
;
7571 spec
->spec_init_verbs
= kcalloc(NUM_SPEC_VERBS
,
7572 sizeof(struct hda_verb
),
7574 if (!spec
->spec_init_verbs
)
7578 spec
->spec_init_verbs
[0].nid
= 0x0b;
7579 spec
->spec_init_verbs
[0].param
= 0x78D;
7580 spec
->spec_init_verbs
[0].verb
= 0x00;
7582 /* Previously commented configuration */
7584 spec->spec_init_verbs[2].nid = 0x0b;
7585 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
7586 spec->spec_init_verbs[2].verb = 0x02;
7588 spec->spec_init_verbs[3].nid = 0x10;
7589 spec->spec_init_verbs[3].param = 0x78D;
7590 spec->spec_init_verbs[3].verb = 0x02;
7592 spec->spec_init_verbs[4].nid = 0x10;
7593 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
7594 spec->spec_init_verbs[4].verb = 0x02;
7597 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
7601 static int patch_ca0132(struct hda_codec
*codec
)
7603 struct ca0132_spec
*spec
;
7605 const struct snd_pci_quirk
*quirk
;
7607 codec_dbg(codec
, "patch_ca0132\n");
7609 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
7613 spec
->codec
= codec
;
7615 codec
->patch_ops
= ca0132_patch_ops
;
7616 codec
->pcm_format_first
= 1;
7617 codec
->no_sticky_stream
= 1;
7619 /* Detect codec quirk */
7620 quirk
= snd_pci_quirk_lookup(codec
->bus
->pci
, ca0132_quirks
);
7622 spec
->quirk
= quirk
->value
;
7624 spec
->quirk
= QUIRK_NONE
;
7626 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
7627 spec
->num_mixers
= 1;
7629 /* Set which mixers each quirk uses. */
7630 switch (spec
->quirk
) {
7632 spec
->mixers
[0] = desktop_mixer
;
7633 snd_hda_codec_set_name(codec
, "Sound Blaster Z");
7636 spec
->mixers
[0] = desktop_mixer
;
7637 snd_hda_codec_set_name(codec
, "Recon3D");
7640 spec
->mixers
[0] = r3di_mixer
;
7641 snd_hda_codec_set_name(codec
, "Recon3Di");
7644 spec
->mixers
[0] = ca0132_mixer
;
7648 /* Setup whether or not to use alt functions/controls/pci_mmio */
7649 switch (spec
->quirk
) {
7652 spec
->use_alt_controls
= true;
7653 spec
->use_alt_functions
= true;
7654 spec
->use_pci_mmio
= true;
7657 spec
->use_alt_controls
= true;
7658 spec
->use_alt_functions
= true;
7659 spec
->use_pci_mmio
= false;
7662 spec
->use_alt_controls
= false;
7663 spec
->use_alt_functions
= false;
7664 spec
->use_pci_mmio
= false;
7668 if (spec
->use_pci_mmio
) {
7669 spec
->mem_base
= pci_iomap(codec
->bus
->pci
, 2, 0xC20);
7670 if (spec
->mem_base
== NULL
) {
7671 codec_warn(codec
, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
7672 spec
->quirk
= QUIRK_NONE
;
7676 spec
->base_init_verbs
= ca0132_base_init_verbs
;
7677 spec
->base_exit_verbs
= ca0132_base_exit_verbs
;
7679 INIT_DELAYED_WORK(&spec
->unsol_hp_work
, ca0132_unsol_hp_delayed
);
7681 ca0132_init_chip(codec
);
7683 ca0132_config(codec
);
7685 err
= ca0132_prepare_verbs(codec
);
7689 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
7703 static struct hda_device_id snd_hda_id_ca0132
[] = {
7704 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132
),
7707 MODULE_DEVICE_TABLE(hdaudio
, snd_hda_id_ca0132
);
7709 MODULE_LICENSE("GPL");
7710 MODULE_DESCRIPTION("Creative Sound Core3D codec");
7712 static struct hda_codec_driver ca0132_driver
= {
7713 .id
= snd_hda_id_ca0132
,
7716 module_hda_codec_driver(ca0132_driver
);