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 "/*(DEBLOBBED)*/"
85 #define SBZ_EFX_FILE "/*(DEBLOBBED)*/"
86 #define R3DI_EFX_FILE "/*(DEBLOBBED)*/"
88 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
92 static const char *const dirstr[2] = { "Playback", "Capture" };
94 #define NUM_OF_OUTPUTS 3
106 /* Strings for Input Source Enum Control */
107 static const char *const in_src_str[3] = { "Microphone", "Line In", "Front Microphone" };
108 #define IN_SRC_NUM_OF_INPUTS 3
116 #define VNODE_START_NID 0x80
117 VNID_SPK = VNODE_START_NID, /* Speaker vnid */
124 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
126 #define EFFECT_START_NID 0x90
127 #define OUT_EFFECT_START_NID EFFECT_START_NID
128 SURROUND = OUT_EFFECT_START_NID,
135 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
137 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
138 ECHO_CANCELLATION = IN_EFFECT_START_NID,
143 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
145 VOICEFX = IN_EFFECT_END_NID,
155 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
158 /* Effects values size*/
159 #define EFFECT_VALS_MAX_COUNT 12
162 * Default values for the effect slider controls, they are in order of their
163 * effect NID's. Surround, Crystalizer, Dialog Plus, Smart Volume, and then
166 static const unsigned int effect_slider_defaults[] = {67, 65, 50, 74, 50};
167 /* Amount of effect level sliders for ca0132_alt controls. */
168 #define EFFECT_LEVEL_SLIDERS 5
170 /* Latency introduced by DSP blocks in milliseconds. */
171 #define DSP_CAPTURE_INIT_LATENCY 0
172 #define DSP_CRYSTAL_VOICE_LATENCY 124
173 #define DSP_PLAYBACK_INIT_LATENCY 13
174 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
175 #define DSP_SPEAKER_OUT_LATENCY 7
178 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
180 int mid; /*effect module ID*/
181 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
182 int direct; /* 0:output; 1:input*/
183 int params; /* number of default non-on/off params */
184 /*effect default values, 1st is on/off. */
185 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
188 #define EFX_DIR_OUT 0
191 static const struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
192 { .name = "Surround",
196 .direct = EFX_DIR_OUT,
198 .def_vals = {0x3F800000, 0x3F2B851F}
200 { .name = "Crystalizer",
204 .direct = EFX_DIR_OUT,
206 .def_vals = {0x3F800000, 0x3F266666}
208 { .name = "Dialog Plus",
212 .direct = EFX_DIR_OUT,
214 .def_vals = {0x00000000, 0x3F000000}
216 { .name = "Smart Volume",
220 .direct = EFX_DIR_OUT,
222 .def_vals = {0x3F800000, 0x3F3D70A4, 0x00000000}
227 .reqs = {24, 23, 25},
228 .direct = EFX_DIR_OUT,
230 .def_vals = {0x3F800000, 0x42A00000, 0x3F000000}
232 { .name = "Equalizer",
235 .reqs = {9, 10, 11, 12, 13, 14,
236 15, 16, 17, 18, 19, 20},
237 .direct = EFX_DIR_OUT,
239 .def_vals = {0x00000000, 0x00000000, 0x00000000, 0x00000000,
240 0x00000000, 0x00000000, 0x00000000, 0x00000000,
241 0x00000000, 0x00000000, 0x00000000, 0x00000000}
243 { .name = "Echo Cancellation",
244 .nid = ECHO_CANCELLATION,
246 .reqs = {0, 1, 2, 3},
247 .direct = EFX_DIR_IN,
249 .def_vals = {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
251 { .name = "Voice Focus",
254 .reqs = {6, 7, 8, 9},
255 .direct = EFX_DIR_IN,
257 .def_vals = {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
263 .direct = EFX_DIR_IN,
265 .def_vals = {0x00000000, 0x3F3D70A4}
267 { .name = "Noise Reduction",
268 .nid = NOISE_REDUCTION,
271 .direct = EFX_DIR_IN,
273 .def_vals = {0x3F800000, 0x3F000000}
278 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18},
279 .direct = EFX_DIR_IN,
281 .def_vals = {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
282 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
287 /* Tuning controls */
288 #ifdef ENABLE_TUNING_CONTROLS
291 #define TUNING_CTL_START_NID 0xC0
292 WEDGE_ANGLE = TUNING_CTL_START_NID,
305 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
308 struct ct_tuning_ctl {
309 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
310 hda_nid_t parent_nid;
312 int mid; /*effect module ID*/
313 int req; /*effect module request*/
314 int direct; /* 0:output; 1:input*/
315 unsigned int def_val;/*effect default values*/
318 static const struct ct_tuning_ctl ca0132_tuning_ctls[] = {
319 { .name = "Wedge Angle",
320 .parent_nid = VOICE_FOCUS,
324 .direct = EFX_DIR_IN,
325 .def_val = 0x41F00000
327 { .name = "SVM Level",
328 .parent_nid = MIC_SVM,
332 .direct = EFX_DIR_IN,
333 .def_val = 0x3F3D70A4
335 { .name = "EQ Band0",
336 .parent_nid = EQUALIZER,
337 .nid = EQUALIZER_BAND_0,
340 .direct = EFX_DIR_OUT,
341 .def_val = 0x00000000
343 { .name = "EQ Band1",
344 .parent_nid = EQUALIZER,
345 .nid = EQUALIZER_BAND_1,
348 .direct = EFX_DIR_OUT,
349 .def_val = 0x00000000
351 { .name = "EQ Band2",
352 .parent_nid = EQUALIZER,
353 .nid = EQUALIZER_BAND_2,
356 .direct = EFX_DIR_OUT,
357 .def_val = 0x00000000
359 { .name = "EQ Band3",
360 .parent_nid = EQUALIZER,
361 .nid = EQUALIZER_BAND_3,
364 .direct = EFX_DIR_OUT,
365 .def_val = 0x00000000
367 { .name = "EQ Band4",
368 .parent_nid = EQUALIZER,
369 .nid = EQUALIZER_BAND_4,
372 .direct = EFX_DIR_OUT,
373 .def_val = 0x00000000
375 { .name = "EQ Band5",
376 .parent_nid = EQUALIZER,
377 .nid = EQUALIZER_BAND_5,
380 .direct = EFX_DIR_OUT,
381 .def_val = 0x00000000
383 { .name = "EQ Band6",
384 .parent_nid = EQUALIZER,
385 .nid = EQUALIZER_BAND_6,
388 .direct = EFX_DIR_OUT,
389 .def_val = 0x00000000
391 { .name = "EQ Band7",
392 .parent_nid = EQUALIZER,
393 .nid = EQUALIZER_BAND_7,
396 .direct = EFX_DIR_OUT,
397 .def_val = 0x00000000
399 { .name = "EQ Band8",
400 .parent_nid = EQUALIZER,
401 .nid = EQUALIZER_BAND_8,
404 .direct = EFX_DIR_OUT,
405 .def_val = 0x00000000
407 { .name = "EQ Band9",
408 .parent_nid = EQUALIZER,
409 .nid = EQUALIZER_BAND_9,
412 .direct = EFX_DIR_OUT,
413 .def_val = 0x00000000
418 /* Voice FX Presets */
419 #define VOICEFX_MAX_PARAM_COUNT 9
425 int reqs[VOICEFX_MAX_PARAM_COUNT]; /*effect module request*/
428 struct ct_voicefx_preset {
429 char *name; /*preset name*/
430 unsigned int vals[VOICEFX_MAX_PARAM_COUNT];
433 static const struct ct_voicefx ca0132_voicefx = {
434 .name = "VoiceFX Capture Switch",
437 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18}
440 static const struct ct_voicefx_preset ca0132_voicefx_presets[] = {
442 .vals = { 0x00000000, 0x43C80000, 0x44AF0000,
443 0x44FA0000, 0x3F800000, 0x3F800000,
444 0x3F800000, 0x00000000, 0x00000000 }
446 { .name = "Female2Male",
447 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
448 0x44FA0000, 0x3F19999A, 0x3F866666,
449 0x3F800000, 0x00000000, 0x00000000 }
451 { .name = "Male2Female",
452 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
453 0x450AC000, 0x4017AE14, 0x3F6B851F,
454 0x3F800000, 0x00000000, 0x00000000 }
456 { .name = "ScrappyKid",
457 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
458 0x44FA0000, 0x40400000, 0x3F28F5C3,
459 0x3F800000, 0x00000000, 0x00000000 }
462 .vals = { 0x3F800000, 0x44324000, 0x44BB8000,
463 0x44E10000, 0x3FB33333, 0x3FB9999A,
464 0x3F800000, 0x3E3A2E43, 0x00000000 }
467 .vals = { 0x3F800000, 0x43EA0000, 0x44A52000,
468 0x45098000, 0x3F266666, 0x3FC00000,
469 0x3F800000, 0x00000000, 0x00000000 }
472 .vals = { 0x3F800000, 0x43C70000, 0x44AE6000,
473 0x45193000, 0x3F8E147B, 0x3F75C28F,
474 0x3F800000, 0x00000000, 0x00000000 }
477 .vals = { 0x3F800000, 0x43930000, 0x44BEE000,
478 0x45007000, 0x3F451EB8, 0x3F7851EC,
479 0x3F800000, 0x00000000, 0x00000000 }
481 { .name = "AlienBrute",
482 .vals = { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
483 0x451F6000, 0x3F266666, 0x3FA7D945,
484 0x3F800000, 0x3CF5C28F, 0x00000000 }
487 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
488 0x44FA0000, 0x3FB2718B, 0x3F800000,
489 0xBC07010E, 0x00000000, 0x00000000 }
492 .vals = { 0x3F800000, 0x43C20000, 0x44906000,
493 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
494 0x3F0A3D71, 0x00000000, 0x00000000 }
497 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
498 0x44FA0000, 0x3F800000, 0x3F800000,
499 0x3E4CCCCD, 0x00000000, 0x00000000 }
501 { .name = "DeepVoice",
502 .vals = { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
503 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
504 0x3F800000, 0x00000000, 0x00000000 }
506 { .name = "Munchkin",
507 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
508 0x44FA0000, 0x3F800000, 0x3F1A043C,
509 0x3F800000, 0x00000000, 0x00000000 }
513 /* ca0132 EQ presets, taken from Windows Sound Blaster Z Driver */
515 #define EQ_PRESET_MAX_PARAM_COUNT 11
521 int reqs[EQ_PRESET_MAX_PARAM_COUNT]; /*effect module request*/
524 struct ct_eq_preset {
525 char *name; /*preset name*/
526 unsigned int vals[EQ_PRESET_MAX_PARAM_COUNT];
529 static const struct ct_eq ca0132_alt_eq_enum = {
530 .name = "FX: Equalizer Preset Switch",
531 .nid = EQ_PRESET_ENUM,
533 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
537 static const struct ct_eq_preset ca0132_alt_eq_presets[] = {
539 .vals = { 0x00000000, 0x00000000, 0x00000000,
540 0x00000000, 0x00000000, 0x00000000,
541 0x00000000, 0x00000000, 0x00000000,
542 0x00000000, 0x00000000 }
544 { .name = "Acoustic",
545 .vals = { 0x00000000, 0x00000000, 0x3F8CCCCD,
546 0x40000000, 0x00000000, 0x00000000,
547 0x00000000, 0x00000000, 0x40000000,
548 0x40000000, 0x40000000 }
550 { .name = "Classical",
551 .vals = { 0x00000000, 0x00000000, 0x40C00000,
552 0x40C00000, 0x40466666, 0x00000000,
553 0x00000000, 0x00000000, 0x00000000,
554 0x40466666, 0x40466666 }
557 .vals = { 0x00000000, 0xBF99999A, 0x00000000,
558 0x3FA66666, 0x3FA66666, 0x3F8CCCCD,
559 0x00000000, 0x00000000, 0x40000000,
560 0x40466666, 0x40800000 }
563 .vals = { 0x00000000, 0xBF99999A, 0x40000000,
564 0x40466666, 0x40866666, 0xBF99999A,
565 0xBF99999A, 0x00000000, 0x00000000,
566 0x40800000, 0x40800000 }
569 .vals = { 0x00000000, 0x00000000, 0x00000000,
570 0x3F8CCCCD, 0x40800000, 0x40800000,
571 0x40800000, 0x00000000, 0x3F8CCCCD,
572 0x40466666, 0x40466666 }
575 .vals = { 0x00000000, 0x00000000, 0x40000000,
576 0x40000000, 0x00000000, 0x00000000,
577 0x00000000, 0x3F8CCCCD, 0x40000000,
578 0x40000000, 0x40000000 }
581 .vals = { 0x00000000, 0xBFCCCCCD, 0x00000000,
582 0x40000000, 0x40000000, 0x00000000,
583 0xBF99999A, 0xBF99999A, 0x00000000,
584 0x40466666, 0x40C00000 }
587 .vals = { 0x00000000, 0xBF99999A, 0xBF99999A,
588 0x3F8CCCCD, 0x40000000, 0xBF99999A,
589 0xBF99999A, 0x00000000, 0x00000000,
590 0x40800000, 0x40800000 }
593 .vals = { 0x00000000, 0xC0000000, 0xBF99999A,
594 0xBF99999A, 0x00000000, 0x40466666,
595 0x40800000, 0x40466666, 0x00000000,
596 0x00000000, 0x3F8CCCCD }
600 /* DSP command sequences for ca0132_alt_select_out */
601 #define ALT_OUT_SET_MAX_COMMANDS 9 /* Max number of commands in sequence */
602 struct ca0132_alt_out_set {
603 char *name; /*preset name*/
604 unsigned char commands;
605 unsigned int mids[ALT_OUT_SET_MAX_COMMANDS];
606 unsigned int reqs[ALT_OUT_SET_MAX_COMMANDS];
607 unsigned int vals[ALT_OUT_SET_MAX_COMMANDS];
610 static const struct ca0132_alt_out_set alt_out_presets[] = {
611 { .name = "Line Out",
613 .mids = { 0x96, 0x96, 0x96, 0x8F,
615 .reqs = { 0x19, 0x17, 0x18, 0x01,
617 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
618 0x00000000, 0x00000000, 0x00000000,
621 { .name = "Headphone",
623 .mids = { 0x96, 0x96, 0x96, 0x8F,
625 .reqs = { 0x19, 0x17, 0x18, 0x01,
627 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
628 0x00000000, 0x00000000, 0x00000000,
631 { .name = "Surround",
633 .mids = { 0x96, 0x8F, 0x96, 0x96,
634 0x96, 0x96, 0x96, 0x96 },
635 .reqs = { 0x18, 0x01, 0x1F, 0x15,
636 0x3A, 0x1A, 0x1B, 0x1C },
637 .vals = { 0x00000000, 0x00000000, 0x00000000,
638 0x00000000, 0x00000000, 0x00000000,
639 0x00000000, 0x00000000 }
644 * DSP volume setting structs. Req 1 is left volume, req 2 is right volume,
645 * and I don't know what the third req is, but it's always zero. I assume it's
646 * some sort of update or set command to tell the DSP there's new volume info.
648 #define DSP_VOL_OUT 0
651 struct ct_dsp_volume_ctl {
653 int mid; /* module ID*/
654 unsigned int reqs[3]; /* scp req ID */
657 static const struct ct_dsp_volume_ctl ca0132_alt_vol_ctls[] = {
668 enum hda_cmd_vendor_io {
670 VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000,
671 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100,
673 VENDOR_DSPIO_STATUS = 0xF01,
674 VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702,
675 VENDOR_DSPIO_SCP_READ_DATA = 0xF02,
676 VENDOR_DSPIO_DSP_INIT = 0x703,
677 VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704,
678 VENDOR_DSPIO_SCP_READ_COUNT = 0xF04,
680 /* for ChipIO node */
681 VENDOR_CHIPIO_ADDRESS_LOW = 0x000,
682 VENDOR_CHIPIO_ADDRESS_HIGH = 0x100,
683 VENDOR_CHIPIO_STREAM_FORMAT = 0x200,
684 VENDOR_CHIPIO_DATA_LOW = 0x300,
685 VENDOR_CHIPIO_DATA_HIGH = 0x400,
687 VENDOR_CHIPIO_GET_PARAMETER = 0xF00,
688 VENDOR_CHIPIO_STATUS = 0xF01,
689 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
690 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
692 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
693 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
695 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
696 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
698 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
699 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
700 VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D,
701 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
702 VENDOR_CHIPIO_FLAG_SET = 0x70F,
703 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
704 VENDOR_CHIPIO_PARAM_SET = 0x710,
705 VENDOR_CHIPIO_PARAM_GET = 0xF10,
707 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
708 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
709 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
710 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
712 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
713 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
714 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
715 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
717 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
718 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
719 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
720 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
721 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
722 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
724 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
730 enum control_flag_id {
731 /* Connection manager stream setup is bypassed/enabled */
732 CONTROL_FLAG_C_MGR = 0,
733 /* DSP DMA is bypassed/enabled */
734 CONTROL_FLAG_DMA = 1,
735 /* 8051 'idle' mode is disabled/enabled */
736 CONTROL_FLAG_IDLE_ENABLE = 2,
737 /* Tracker for the SPDIF-in path is bypassed/enabled */
738 CONTROL_FLAG_TRACKER = 3,
739 /* DigitalOut to Spdif2Out connection is disabled/enabled */
740 CONTROL_FLAG_SPDIF2OUT = 4,
741 /* Digital Microphone is disabled/enabled */
742 CONTROL_FLAG_DMIC = 5,
743 /* ADC_B rate is 48 kHz/96 kHz */
744 CONTROL_FLAG_ADC_B_96KHZ = 6,
745 /* ADC_C rate is 48 kHz/96 kHz */
746 CONTROL_FLAG_ADC_C_96KHZ = 7,
747 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
748 CONTROL_FLAG_DAC_96KHZ = 8,
749 /* DSP rate is 48 kHz/96 kHz */
750 CONTROL_FLAG_DSP_96KHZ = 9,
751 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
752 CONTROL_FLAG_SRC_CLOCK_196MHZ = 10,
753 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
754 CONTROL_FLAG_SRC_RATE_96KHZ = 11,
755 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
756 CONTROL_FLAG_DECODE_LOOP = 12,
757 /* De-emphasis filter on DAC-1 disabled/enabled */
758 CONTROL_FLAG_DAC1_DEEMPHASIS = 13,
759 /* De-emphasis filter on DAC-2 disabled/enabled */
760 CONTROL_FLAG_DAC2_DEEMPHASIS = 14,
761 /* De-emphasis filter on DAC-3 disabled/enabled */
762 CONTROL_FLAG_DAC3_DEEMPHASIS = 15,
763 /* High-pass filter on ADC_B disabled/enabled */
764 CONTROL_FLAG_ADC_B_HIGH_PASS = 16,
765 /* High-pass filter on ADC_C disabled/enabled */
766 CONTROL_FLAG_ADC_C_HIGH_PASS = 17,
767 /* Common mode on Port_A disabled/enabled */
768 CONTROL_FLAG_PORT_A_COMMON_MODE = 18,
769 /* Common mode on Port_D disabled/enabled */
770 CONTROL_FLAG_PORT_D_COMMON_MODE = 19,
771 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
772 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
773 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
774 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
775 /* ASI rate is 48kHz/96kHz */
776 CONTROL_FLAG_ASI_96KHZ = 22,
777 /* DAC power settings able to control attached ports no/yes */
778 CONTROL_FLAG_DACS_CONTROL_PORTS = 23,
779 /* Clock Stop OK reporting is disabled/enabled */
780 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24,
781 /* Number of control flags */
782 CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1)
786 * Control parameter IDs
788 enum control_param_id {
789 /* 0: None, 1: Mic1In*/
790 CONTROL_PARAM_VIP_SOURCE = 1,
791 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
792 CONTROL_PARAM_SPDIF1_SOURCE = 2,
793 /* Port A output stage gain setting to use when 16 Ohm output
794 * impedance is selected*/
795 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
796 /* Port D output stage gain setting to use when 16 Ohm output
797 * impedance is selected*/
798 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
802 /* Select stream with the given ID */
803 CONTROL_PARAM_STREAM_ID = 24,
804 /* Source connection point for the selected stream */
805 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25,
806 /* Destination connection point for the selected stream */
807 CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26,
808 /* Number of audio channels in the selected stream */
809 CONTROL_PARAM_STREAMS_CHANNELS = 27,
810 /*Enable control for the selected stream */
811 CONTROL_PARAM_STREAM_CONTROL = 28,
813 /* Connection Point Control */
815 /* Select connection point with the given ID */
816 CONTROL_PARAM_CONN_POINT_ID = 29,
817 /* Connection point sample rate */
818 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30,
822 /* Select HDA node with the given ID */
823 CONTROL_PARAM_NODE_ID = 31
827 * Dsp Io Status codes
829 enum hda_vendor_status_dspio {
831 VENDOR_STATUS_DSPIO_OK = 0x00,
832 /* Busy, unable to accept new command, the host must retry */
833 VENDOR_STATUS_DSPIO_BUSY = 0x01,
834 /* SCP command queue is full */
835 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02,
836 /* SCP response queue is empty */
837 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03
841 * Chip Io Status codes
843 enum hda_vendor_status_chipio {
845 VENDOR_STATUS_CHIPIO_OK = 0x00,
846 /* Busy, unable to accept new command, the host must retry */
847 VENDOR_STATUS_CHIPIO_BUSY = 0x01
853 enum ca0132_sample_rate {
873 SR_RATE_UNKNOWN = 0x1F
876 enum dsp_download_state {
877 DSP_DOWNLOAD_FAILED = -1,
878 DSP_DOWNLOAD_INIT = 0,
883 /* retrieve parameters from hda format */
884 #define get_hdafmt_chs(fmt) (fmt & 0xf)
885 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
886 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
887 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
894 const struct snd_kcontrol_new *mixers[5];
895 unsigned int num_mixers;
896 const struct hda_verb *base_init_verbs;
897 const struct hda_verb *base_exit_verbs;
898 const struct hda_verb *chip_init_verbs;
899 const struct hda_verb *desktop_init_verbs;
900 struct hda_verb *spec_init_verbs;
901 struct auto_pin_cfg autocfg;
903 /* Nodes configurations */
904 struct hda_multi_out multiout;
905 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
906 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
907 unsigned int num_outputs;
908 hda_nid_t input_pins[AUTO_PIN_LAST];
909 hda_nid_t adcs[AUTO_PIN_LAST];
912 unsigned int num_inputs;
913 hda_nid_t shared_mic_nid;
914 hda_nid_t shared_out_nid;
915 hda_nid_t unsol_tag_hp;
916 hda_nid_t unsol_tag_front_hp; /* for desktop ca0132 codecs */
917 hda_nid_t unsol_tag_amic1;
920 struct mutex chipio_mutex; /* chip access mutex */
923 /* DSP download related */
924 enum dsp_download_state dsp_state;
925 unsigned int dsp_stream_id;
926 unsigned int wait_scp;
927 unsigned int wait_scp_header;
928 unsigned int wait_num_data;
929 unsigned int scp_resp_header;
930 unsigned int scp_resp_data[4];
931 unsigned int scp_resp_count;
932 bool alt_firmware_present;
933 bool startup_check_entered;
936 /* mixer and effects related */
937 unsigned char dmic_ctl;
940 long vnode_lvol[VNODES_COUNT];
941 long vnode_rvol[VNODES_COUNT];
942 long vnode_lswitch[VNODES_COUNT];
943 long vnode_rswitch[VNODES_COUNT];
944 long effects_switch[EFFECTS_COUNT];
947 /* ca0132_alt control related values */
948 unsigned char in_enum_val;
949 unsigned char out_enum_val;
950 unsigned char mic_boost_enum_val;
951 unsigned char smart_volume_setting;
952 long fx_ctl_val[EFFECT_LEVEL_SLIDERS];
953 long xbass_xover_freq;
956 struct hda_vmaster_mute_hook vmaster_mute;
959 struct hda_codec *codec;
960 struct delayed_work unsol_hp_work;
963 #ifdef ENABLE_TUNING_CONTROLS
964 long cur_ctl_vals[TUNING_CTLS_COUNT];
967 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
968 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
972 void __iomem *mem_base;
975 * Whether or not to use the alt functions like alt_select_out,
976 * alt_select_in, etc. Only used on desktop codecs for now, because of
977 * surround sound support.
979 bool use_alt_functions;
982 * Whether or not to use alt controls: volume effect sliders, EQ
983 * presets, smart volume presets, and new control names with FX prefix.
984 * Renames PlayEnhancement and CrystalVoice too.
986 bool use_alt_controls;
990 * CA0132 quirks table
995 QUIRK_ALIENWARE_M17XR4,
1001 static const struct hda_pintbl alienware_pincfgs[] = {
1002 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1003 { 0x0c, 0x411111f0 }, /* N/A */
1004 { 0x0d, 0x411111f0 }, /* N/A */
1005 { 0x0e, 0x411111f0 }, /* N/A */
1006 { 0x0f, 0x0321101f }, /* HP */
1007 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1008 { 0x11, 0x03a11021 }, /* Mic */
1009 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1010 { 0x13, 0x411111f0 }, /* N/A */
1011 { 0x18, 0x411111f0 }, /* N/A */
1015 /* Sound Blaster Z pin configs taken from Windows Driver */
1016 static const struct hda_pintbl sbz_pincfgs[] = {
1017 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1018 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1019 { 0x0d, 0x014510f0 }, /* Digital Out */
1020 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1021 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1022 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1023 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1024 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1025 { 0x13, 0x908700f0 }, /* What U Hear In*/
1026 { 0x18, 0x50d000f0 }, /* N/A */
1030 /* Recon3D pin configs taken from Windows Driver */
1031 static const struct hda_pintbl r3d_pincfgs[] = {
1032 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1033 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1034 { 0x0d, 0x014510f0 }, /* Digital Out */
1035 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1036 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1037 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1038 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1039 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1040 { 0x13, 0x908700f0 }, /* What U Hear In*/
1041 { 0x18, 0x50d000f0 }, /* N/A */
1045 /* Recon3D integrated pin configs taken from Windows Driver */
1046 static const struct hda_pintbl r3di_pincfgs[] = {
1047 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1048 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1049 { 0x0d, 0x014510f0 }, /* Digital Out */
1050 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1051 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1052 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1053 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1054 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1055 { 0x13, 0x908700f0 }, /* What U Hear In*/
1056 { 0x18, 0x500000f0 }, /* N/A */
1060 static const struct snd_pci_quirk ca0132_quirks[] = {
1061 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4),
1062 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE),
1063 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE),
1064 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE),
1065 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ),
1066 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ),
1067 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
1068 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
1069 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
1070 SND_PCI_QUIRK(0x3842, 0x1038, "EVGA X99 Classified", QUIRK_R3DI),
1071 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1076 * CA0132 codec access
1078 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1079 unsigned int verb, unsigned int parm, unsigned int *res)
1081 unsigned int response;
1082 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1085 return ((response == -1) ? -1 : 0);
1088 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1089 unsigned short converter_format, unsigned int *res)
1091 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1092 converter_format & 0xffff, res);
1095 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1096 hda_nid_t nid, unsigned char stream,
1097 unsigned char channel, unsigned int *res)
1099 unsigned char converter_stream_channel = 0;
1101 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1102 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1103 converter_stream_channel, res);
1106 /* Chip access helper function */
1107 static int chipio_send(struct hda_codec *codec,
1112 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1114 /* send bits of data specified by reg */
1116 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1118 if (res == VENDOR_STATUS_CHIPIO_OK)
1121 } while (time_before(jiffies, timeout));
1127 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1129 static int chipio_write_address(struct hda_codec *codec,
1130 unsigned int chip_addx)
1132 struct ca0132_spec *spec = codec->spec;
1135 if (spec->curr_chip_addx == chip_addx)
1138 /* send low 16 bits of the address */
1139 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1140 chip_addx & 0xffff);
1143 /* send high 16 bits of the address */
1144 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1148 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1154 * Write data through the vendor widget -- NOT protected by the Mutex!
1156 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1158 struct ca0132_spec *spec = codec->spec;
1161 /* send low 16 bits of the data */
1162 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1165 /* send high 16 bits of the data */
1166 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1170 /*If no error encountered, automatically increment the address
1171 as per chip behaviour*/
1172 spec->curr_chip_addx = (res != -EIO) ?
1173 (spec->curr_chip_addx + 4) : ~0U;
1178 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1180 static int chipio_write_data_multiple(struct hda_codec *codec,
1187 codec_dbg(codec, "chipio_write_data null ptr\n");
1191 while ((count-- != 0) && (status == 0))
1192 status = chipio_write_data(codec, *data++);
1199 * Read data through the vendor widget -- NOT protected by the Mutex!
1201 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1203 struct ca0132_spec *spec = codec->spec;
1207 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1211 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1216 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1217 VENDOR_CHIPIO_HIC_READ_DATA,
1221 /*If no error encountered, automatically increment the address
1222 as per chip behaviour*/
1223 spec->curr_chip_addx = (res != -EIO) ?
1224 (spec->curr_chip_addx + 4) : ~0U;
1229 * Write given value to the given address through the chip I/O widget.
1230 * protected by the Mutex
1232 static int chipio_write(struct hda_codec *codec,
1233 unsigned int chip_addx, const unsigned int data)
1235 struct ca0132_spec *spec = codec->spec;
1238 mutex_lock(&spec->chipio_mutex);
1240 /* write the address, and if successful proceed to write data */
1241 err = chipio_write_address(codec, chip_addx);
1245 err = chipio_write_data(codec, data);
1250 mutex_unlock(&spec->chipio_mutex);
1255 * Write given value to the given address through the chip I/O widget.
1256 * not protected by the Mutex
1258 static int chipio_write_no_mutex(struct hda_codec *codec,
1259 unsigned int chip_addx, const unsigned int data)
1264 /* write the address, and if successful proceed to write data */
1265 err = chipio_write_address(codec, chip_addx);
1269 err = chipio_write_data(codec, data);
1278 * Write multiple values to the given address through the chip I/O widget.
1279 * protected by the Mutex
1281 static int chipio_write_multiple(struct hda_codec *codec,
1286 struct ca0132_spec *spec = codec->spec;
1289 mutex_lock(&spec->chipio_mutex);
1290 status = chipio_write_address(codec, chip_addx);
1294 status = chipio_write_data_multiple(codec, data, count);
1296 mutex_unlock(&spec->chipio_mutex);
1302 * Read the given address through the chip I/O widget
1303 * protected by the Mutex
1305 static int chipio_read(struct hda_codec *codec,
1306 unsigned int chip_addx, unsigned int *data)
1308 struct ca0132_spec *spec = codec->spec;
1311 mutex_lock(&spec->chipio_mutex);
1313 /* write the address, and if successful proceed to write data */
1314 err = chipio_write_address(codec, chip_addx);
1318 err = chipio_read_data(codec, data);
1323 mutex_unlock(&spec->chipio_mutex);
1328 * Set chip control flags through the chip I/O widget.
1330 static void chipio_set_control_flag(struct hda_codec *codec,
1331 enum control_flag_id flag_id,
1335 unsigned int flag_bit;
1337 flag_bit = (flag_state ? 1 : 0);
1338 val = (flag_bit << 7) | (flag_id);
1339 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1340 VENDOR_CHIPIO_FLAG_SET, val);
1344 * Set chip parameters through the chip I/O widget.
1346 static void chipio_set_control_param(struct hda_codec *codec,
1347 enum control_param_id param_id, int param_val)
1349 struct ca0132_spec *spec = codec->spec;
1352 if ((param_id < 32) && (param_val < 8)) {
1353 val = (param_val << 5) | (param_id);
1354 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1355 VENDOR_CHIPIO_PARAM_SET, val);
1357 mutex_lock(&spec->chipio_mutex);
1358 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1359 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1360 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1362 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1363 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1366 mutex_unlock(&spec->chipio_mutex);
1371 * Set chip parameters through the chip I/O widget. NO MUTEX.
1373 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1374 enum control_param_id param_id, int param_val)
1378 if ((param_id < 32) && (param_val < 8)) {
1379 val = (param_val << 5) | (param_id);
1380 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1381 VENDOR_CHIPIO_PARAM_SET, val);
1383 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1384 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1385 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1387 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1388 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1394 * Connect stream to a source point, and then connect
1395 * that source point to a destination point.
1397 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1398 int streamid, int source_point, int dest_point)
1400 chipio_set_control_param_no_mutex(codec,
1401 CONTROL_PARAM_STREAM_ID, streamid);
1402 chipio_set_control_param_no_mutex(codec,
1403 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1404 chipio_set_control_param_no_mutex(codec,
1405 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1409 * Set number of channels in the selected stream.
1411 static void chipio_set_stream_channels(struct hda_codec *codec,
1412 int streamid, unsigned int channels)
1414 chipio_set_control_param_no_mutex(codec,
1415 CONTROL_PARAM_STREAM_ID, streamid);
1416 chipio_set_control_param_no_mutex(codec,
1417 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1421 * Enable/Disable audio stream.
1423 static void chipio_set_stream_control(struct hda_codec *codec,
1424 int streamid, int enable)
1426 chipio_set_control_param_no_mutex(codec,
1427 CONTROL_PARAM_STREAM_ID, streamid);
1428 chipio_set_control_param_no_mutex(codec,
1429 CONTROL_PARAM_STREAM_CONTROL, enable);
1434 * Set sampling rate of the connection point. NO MUTEX.
1436 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1437 int connid, enum ca0132_sample_rate rate)
1439 chipio_set_control_param_no_mutex(codec,
1440 CONTROL_PARAM_CONN_POINT_ID, connid);
1441 chipio_set_control_param_no_mutex(codec,
1442 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1446 * Set sampling rate of the connection point.
1448 static void chipio_set_conn_rate(struct hda_codec *codec,
1449 int connid, enum ca0132_sample_rate rate)
1451 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1452 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1459 static void chipio_enable_clocks(struct hda_codec *codec)
1461 struct ca0132_spec *spec = codec->spec;
1463 mutex_lock(&spec->chipio_mutex);
1464 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1465 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1466 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1467 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1468 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1469 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1470 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1471 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1472 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1473 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1474 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1475 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1476 mutex_unlock(&spec->chipio_mutex);
1480 * CA0132 DSP IO stuffs
1482 static int dspio_send(struct hda_codec *codec, unsigned int reg,
1486 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1488 /* send bits of data specified by reg to dsp */
1490 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1491 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1494 } while (time_before(jiffies, timeout));
1500 * Wait for DSP to be ready for commands
1502 static void dspio_write_wait(struct hda_codec *codec)
1505 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1508 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1509 VENDOR_DSPIO_STATUS, 0);
1510 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1511 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1514 } while (time_before(jiffies, timeout));
1518 * Write SCP data to DSP
1520 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1522 struct ca0132_spec *spec = codec->spec;
1525 dspio_write_wait(codec);
1527 mutex_lock(&spec->chipio_mutex);
1528 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1533 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1538 /* OK, now check if the write itself has executed*/
1539 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1540 VENDOR_DSPIO_STATUS, 0);
1542 mutex_unlock(&spec->chipio_mutex);
1544 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1549 * Write multiple SCP data to DSP
1551 static int dspio_write_multiple(struct hda_codec *codec,
1552 unsigned int *buffer, unsigned int size)
1561 while (count < size) {
1562 status = dspio_write(codec, *buffer++);
1571 static int dspio_read(struct hda_codec *codec, unsigned int *data)
1575 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1579 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1580 if (status == -EIO ||
1581 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
1584 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1585 VENDOR_DSPIO_SCP_READ_DATA, 0);
1590 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
1591 unsigned int *buf_size, unsigned int size_count)
1594 unsigned int size = *buf_size;
1596 unsigned int skip_count;
1603 while (count < size && count < size_count) {
1604 status = dspio_read(codec, buffer++);
1612 while (skip_count < size) {
1613 status = dspio_read(codec, &dummy);
1625 * Construct the SCP header using corresponding fields
1627 static inline unsigned int
1628 make_scp_header(unsigned int target_id, unsigned int source_id,
1629 unsigned int get_flag, unsigned int req,
1630 unsigned int device_flag, unsigned int resp_flag,
1631 unsigned int error_flag, unsigned int data_size)
1633 unsigned int header = 0;
1635 header = (data_size & 0x1f) << 27;
1636 header |= (error_flag & 0x01) << 26;
1637 header |= (resp_flag & 0x01) << 25;
1638 header |= (device_flag & 0x01) << 24;
1639 header |= (req & 0x7f) << 17;
1640 header |= (get_flag & 0x01) << 16;
1641 header |= (source_id & 0xff) << 8;
1642 header |= target_id & 0xff;
1648 * Extract corresponding fields from SCP header
1651 extract_scp_header(unsigned int header,
1652 unsigned int *target_id, unsigned int *source_id,
1653 unsigned int *get_flag, unsigned int *req,
1654 unsigned int *device_flag, unsigned int *resp_flag,
1655 unsigned int *error_flag, unsigned int *data_size)
1658 *data_size = (header >> 27) & 0x1f;
1660 *error_flag = (header >> 26) & 0x01;
1662 *resp_flag = (header >> 25) & 0x01;
1664 *device_flag = (header >> 24) & 0x01;
1666 *req = (header >> 17) & 0x7f;
1668 *get_flag = (header >> 16) & 0x01;
1670 *source_id = (header >> 8) & 0xff;
1672 *target_id = header & 0xff;
1675 #define SCP_MAX_DATA_WORDS (16)
1677 /* Structure to contain any SCP message */
1680 unsigned int data[SCP_MAX_DATA_WORDS];
1683 static void dspio_clear_response_queue(struct hda_codec *codec)
1685 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1686 unsigned int dummy = 0;
1689 /* clear all from the response queue */
1691 status = dspio_read(codec, &dummy);
1692 } while (status == 0 && time_before(jiffies, timeout));
1695 static int dspio_get_response_data(struct hda_codec *codec)
1697 struct ca0132_spec *spec = codec->spec;
1698 unsigned int data = 0;
1701 if (dspio_read(codec, &data) < 0)
1704 if ((data & 0x00ffffff) == spec->wait_scp_header) {
1705 spec->scp_resp_header = data;
1706 spec->scp_resp_count = data >> 27;
1707 count = spec->wait_num_data;
1708 dspio_read_multiple(codec, spec->scp_resp_data,
1709 &spec->scp_resp_count, count);
1717 * Send SCP message to DSP
1719 static int dspio_send_scp_message(struct hda_codec *codec,
1720 unsigned char *send_buf,
1721 unsigned int send_buf_size,
1722 unsigned char *return_buf,
1723 unsigned int return_buf_size,
1724 unsigned int *bytes_returned)
1726 struct ca0132_spec *spec = codec->spec;
1728 unsigned int scp_send_size = 0;
1729 unsigned int total_size;
1730 bool waiting_for_resp = false;
1731 unsigned int header;
1732 struct scp_msg *ret_msg;
1733 unsigned int resp_src_id, resp_target_id;
1734 unsigned int data_size, src_id, target_id, get_flag, device_flag;
1737 *bytes_returned = 0;
1739 /* get scp header from buffer */
1740 header = *((unsigned int *)send_buf);
1741 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
1742 &device_flag, NULL, NULL, &data_size);
1743 scp_send_size = data_size + 1;
1744 total_size = (scp_send_size * 4);
1746 if (send_buf_size < total_size)
1749 if (get_flag || device_flag) {
1750 if (!return_buf || return_buf_size < 4 || !bytes_returned)
1753 spec->wait_scp_header = *((unsigned int *)send_buf);
1755 /* swap source id with target id */
1756 resp_target_id = src_id;
1757 resp_src_id = target_id;
1758 spec->wait_scp_header &= 0xffff0000;
1759 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
1760 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
1762 waiting_for_resp = true;
1765 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
1772 if (waiting_for_resp) {
1773 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1774 memset(return_buf, 0, return_buf_size);
1777 } while (spec->wait_scp && time_before(jiffies, timeout));
1778 waiting_for_resp = false;
1779 if (!spec->wait_scp) {
1780 ret_msg = (struct scp_msg *)return_buf;
1781 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
1782 memcpy(&ret_msg->data, spec->scp_resp_data,
1783 spec->wait_num_data);
1784 *bytes_returned = (spec->scp_resp_count + 1) * 4;
1796 * Prepare and send the SCP message to DSP
1797 * @codec: the HDA codec
1798 * @mod_id: ID of the DSP module to send the command
1799 * @req: ID of request to send to the DSP module
1801 * @data: pointer to the data to send with the request, request specific
1802 * @len: length of the data, in bytes
1803 * @reply: point to the buffer to hold data returned for a reply
1804 * @reply_len: length of the reply buffer returned from GET
1806 * Returns zero or a negative error code.
1808 static int dspio_scp(struct hda_codec *codec,
1809 int mod_id, int src_id, int req, int dir, const void *data,
1810 unsigned int len, void *reply, unsigned int *reply_len)
1813 struct scp_msg scp_send, scp_reply;
1814 unsigned int ret_bytes, send_size, ret_size;
1815 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
1816 unsigned int reply_data_size;
1818 memset(&scp_send, 0, sizeof(scp_send));
1819 memset(&scp_reply, 0, sizeof(scp_reply));
1821 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
1824 if (dir == SCP_GET && reply == NULL) {
1825 codec_dbg(codec, "dspio_scp get but has no buffer\n");
1829 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
1830 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
1834 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
1835 0, 0, 0, len/sizeof(unsigned int));
1836 if (data != NULL && len > 0) {
1837 len = min((unsigned int)(sizeof(scp_send.data)), len);
1838 memcpy(scp_send.data, data, len);
1842 send_size = sizeof(unsigned int) + len;
1843 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
1844 send_size, (unsigned char *)&scp_reply,
1845 sizeof(scp_reply), &ret_bytes);
1848 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
1852 /* extract send and reply headers members */
1853 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
1854 NULL, NULL, NULL, NULL, NULL);
1855 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
1856 &reply_resp_flag, &reply_error_flag,
1862 if (reply_resp_flag && !reply_error_flag) {
1863 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
1864 / sizeof(unsigned int);
1866 if (*reply_len < ret_size*sizeof(unsigned int)) {
1867 codec_dbg(codec, "reply too long for buf\n");
1869 } else if (ret_size != reply_data_size) {
1870 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
1872 } else if (!reply) {
1873 codec_dbg(codec, "NULL reply\n");
1876 *reply_len = ret_size*sizeof(unsigned int);
1877 memcpy(reply, scp_reply.data, *reply_len);
1880 codec_dbg(codec, "reply ill-formed or errflag set\n");
1888 * Set DSP parameters
1890 static int dspio_set_param(struct hda_codec *codec, int mod_id,
1891 int src_id, int req, const void *data, unsigned int len)
1893 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
1897 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
1898 int req, const unsigned int data)
1900 return dspio_set_param(codec, mod_id, 0x20, req, &data,
1901 sizeof(unsigned int));
1904 static int dspio_set_uint_param_no_source(struct hda_codec *codec, int mod_id,
1905 int req, const unsigned int data)
1907 return dspio_set_param(codec, mod_id, 0x00, req, &data,
1908 sizeof(unsigned int));
1912 * Allocate a DSP DMA channel via an SCP message
1914 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
1917 unsigned int size = sizeof(dma_chan);
1919 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
1920 status = dspio_scp(codec, MASTERCONTROL, 0x20,
1921 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
1925 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
1929 if ((*dma_chan + 1) == 0) {
1930 codec_dbg(codec, "no free dma channels to allocate\n");
1934 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
1935 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
1941 * Free a DSP DMA via an SCP message
1943 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
1946 unsigned int dummy = 0;
1948 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
1949 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
1951 status = dspio_scp(codec, MASTERCONTROL, 0x20,
1952 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
1953 sizeof(dma_chan), NULL, &dummy);
1956 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
1960 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
1968 static int dsp_set_run_state(struct hda_codec *codec)
1970 unsigned int dbg_ctrl_reg;
1971 unsigned int halt_state;
1974 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
1978 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
1979 DSP_DBGCNTL_STATE_LOBIT;
1981 if (halt_state != 0) {
1982 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
1983 DSP_DBGCNTL_SS_MASK);
1984 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
1989 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
1990 DSP_DBGCNTL_EXEC_MASK;
1991 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2003 static int dsp_reset(struct hda_codec *codec)
2008 codec_dbg(codec, "dsp_reset\n");
2010 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2012 } while (res == -EIO && retry);
2015 codec_dbg(codec, "dsp_reset timeout\n");
2023 * Convert chip address to DSP address
2025 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2026 bool *code, bool *yram)
2028 *code = *yram = false;
2030 if (UC_RANGE(chip_addx, 1)) {
2032 return UC_OFF(chip_addx);
2033 } else if (X_RANGE_ALL(chip_addx, 1)) {
2034 return X_OFF(chip_addx);
2035 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2037 return Y_OFF(chip_addx);
2040 return INVALID_CHIP_ADDRESS;
2044 * Check if the DSP DMA is active
2046 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2048 unsigned int dma_chnlstart_reg;
2050 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2052 return ((dma_chnlstart_reg & (1 <<
2053 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2056 static int dsp_dma_setup_common(struct hda_codec *codec,
2057 unsigned int chip_addx,
2058 unsigned int dma_chan,
2059 unsigned int port_map_mask,
2063 unsigned int chnl_prop;
2064 unsigned int dsp_addx;
2065 unsigned int active;
2068 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2070 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2071 codec_dbg(codec, "dma chan num invalid\n");
2075 if (dsp_is_dma_active(codec, dma_chan)) {
2076 codec_dbg(codec, "dma already active\n");
2080 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2082 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2083 codec_dbg(codec, "invalid chip addr\n");
2087 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2090 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2093 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2097 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2100 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2104 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2106 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2108 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2110 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2112 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2115 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2118 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2122 codec_dbg(codec, "read ACTIVE Reg fail\n");
2125 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2128 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2129 DSPDMAC_ACTIVE_AAR_MASK;
2131 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2133 codec_dbg(codec, "write ACTIVE Reg fail\n");
2137 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2139 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2142 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2145 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2147 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2148 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2150 codec_dbg(codec, "write IRQCNT Reg fail\n");
2153 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2156 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2157 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2158 chip_addx, dsp_addx, dma_chan,
2159 port_map_mask, chnl_prop, active);
2161 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2167 * Setup the DSP DMA per-transfer-specific registers
2169 static int dsp_dma_setup(struct hda_codec *codec,
2170 unsigned int chip_addx,
2172 unsigned int dma_chan)
2176 unsigned int dsp_addx;
2177 unsigned int addr_field;
2178 unsigned int incr_field;
2179 unsigned int base_cnt;
2180 unsigned int cur_cnt;
2181 unsigned int dma_cfg = 0;
2182 unsigned int adr_ofs = 0;
2183 unsigned int xfr_cnt = 0;
2184 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2185 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2187 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2189 if (count > max_dma_count) {
2190 codec_dbg(codec, "count too big\n");
2194 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2195 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2196 codec_dbg(codec, "invalid chip addr\n");
2200 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2202 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2208 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2210 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2213 dma_cfg = addr_field + incr_field;
2214 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2217 codec_dbg(codec, "write DMACFG Reg fail\n");
2220 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2222 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2225 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2228 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2231 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2233 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2235 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2237 xfr_cnt = base_cnt | cur_cnt;
2239 status = chipio_write(codec,
2240 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2242 codec_dbg(codec, "write XFRCNT Reg fail\n");
2245 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2248 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2249 "ADROFS=0x%x, XFRCNT=0x%x\n",
2250 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2252 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2260 static int dsp_dma_start(struct hda_codec *codec,
2261 unsigned int dma_chan, bool ovly)
2263 unsigned int reg = 0;
2266 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2269 status = chipio_read(codec,
2270 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2273 codec_dbg(codec, "read CHNLSTART reg fail\n");
2276 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2278 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2279 DSPDMAC_CHNLSTART_DIS_MASK);
2282 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2283 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2285 codec_dbg(codec, "write CHNLSTART reg fail\n");
2288 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2296 static int dsp_dma_stop(struct hda_codec *codec,
2297 unsigned int dma_chan, bool ovly)
2299 unsigned int reg = 0;
2302 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2305 status = chipio_read(codec,
2306 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2309 codec_dbg(codec, "read CHNLSTART reg fail\n");
2312 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2313 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2314 DSPDMAC_CHNLSTART_DIS_MASK);
2317 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2318 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2320 codec_dbg(codec, "write CHNLSTART reg fail\n");
2323 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2329 * Allocate router ports
2331 * @codec: the HDA codec
2332 * @num_chans: number of channels in the stream
2333 * @ports_per_channel: number of ports per channel
2334 * @start_device: start device
2335 * @port_map: pointer to the port list to hold the allocated ports
2337 * Returns zero or a negative error code.
2339 static int dsp_allocate_router_ports(struct hda_codec *codec,
2340 unsigned int num_chans,
2341 unsigned int ports_per_channel,
2342 unsigned int start_device,
2343 unsigned int *port_map)
2349 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2353 val = start_device << 6;
2354 val |= (ports_per_channel - 1) << 4;
2355 val |= num_chans - 1;
2357 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2358 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2361 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2362 VENDOR_CHIPIO_PORT_ALLOC_SET,
2365 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2369 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2370 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2374 return (res < 0) ? res : 0;
2380 static int dsp_free_router_ports(struct hda_codec *codec)
2384 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2388 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2389 VENDOR_CHIPIO_PORT_FREE_SET,
2392 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2398 * Allocate DSP ports for the download stream
2400 static int dsp_allocate_ports(struct hda_codec *codec,
2401 unsigned int num_chans,
2402 unsigned int rate_multi, unsigned int *port_map)
2406 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2408 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2409 codec_dbg(codec, "bad rate multiple\n");
2413 status = dsp_allocate_router_ports(codec, num_chans,
2414 rate_multi, 0, port_map);
2416 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2421 static int dsp_allocate_ports_format(struct hda_codec *codec,
2422 const unsigned short fmt,
2423 unsigned int *port_map)
2426 unsigned int num_chans;
2428 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2429 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2430 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2432 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2433 codec_dbg(codec, "bad rate multiple\n");
2437 num_chans = get_hdafmt_chs(fmt) + 1;
2439 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2447 static int dsp_free_ports(struct hda_codec *codec)
2451 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2453 status = dsp_free_router_ports(codec);
2455 codec_dbg(codec, "free router ports fail\n");
2458 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2464 * HDA DMA engine stuffs for DSP code download
2467 struct hda_codec *codec;
2468 unsigned short m_converter_format;
2469 struct snd_dma_buffer *dmab;
2470 unsigned int buf_size;
2479 static int dma_convert_to_hda_format(struct hda_codec *codec,
2480 unsigned int sample_rate,
2481 unsigned short channels,
2482 unsigned short *hda_format)
2484 unsigned int format_val;
2486 format_val = snd_hdac_calc_stream_format(sample_rate,
2487 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
2490 *hda_format = (unsigned short)format_val;
2496 * Reset DMA for DSP download
2498 static int dma_reset(struct dma_engine *dma)
2500 struct hda_codec *codec = dma->codec;
2501 struct ca0132_spec *spec = codec->spec;
2504 if (dma->dmab->area)
2505 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2507 status = snd_hda_codec_load_dsp_prepare(codec,
2508 dma->m_converter_format,
2513 spec->dsp_stream_id = status;
2517 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2522 case DMA_STATE_STOP:
2532 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2536 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2538 return dma->dmab->bytes;
2541 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2543 return dma->dmab->area;
2546 static int dma_xfer(struct dma_engine *dma,
2547 const unsigned int *data,
2550 memcpy(dma->dmab->area, data, count);
2554 static void dma_get_converter_format(
2555 struct dma_engine *dma,
2556 unsigned short *format)
2559 *format = dma->m_converter_format;
2562 static unsigned int dma_get_stream_id(struct dma_engine *dma)
2564 struct ca0132_spec *spec = dma->codec->spec;
2566 return spec->dsp_stream_id;
2569 struct dsp_image_seg {
2576 static const u32 g_magic_value = 0x4c46584d;
2577 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2579 static bool is_valid(const struct dsp_image_seg *p)
2581 return p->magic == g_magic_value;
2584 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
2586 return g_chip_addr_magic_value == p->chip_addr;
2589 static bool is_last(const struct dsp_image_seg *p)
2591 return p->count == 0;
2594 static size_t dsp_sizeof(const struct dsp_image_seg *p)
2596 return sizeof(*p) + p->count*sizeof(u32);
2599 static const struct dsp_image_seg *get_next_seg_ptr(
2600 const struct dsp_image_seg *p)
2602 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
2606 * CA0132 chip DSP transfer stuffs. For DSP download.
2608 #define INVALID_DMA_CHANNEL (~0U)
2611 * Program a list of address/data pairs via the ChipIO widget.
2612 * The segment data is in the format of successive pairs of words.
2613 * These are repeated as indicated by the segment's count field.
2615 static int dspxfr_hci_write(struct hda_codec *codec,
2616 const struct dsp_image_seg *fls)
2622 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
2623 codec_dbg(codec, "hci_write invalid params\n");
2628 data = (u32 *)(fls->data);
2629 while (count >= 2) {
2630 status = chipio_write(codec, data[0], data[1]);
2632 codec_dbg(codec, "hci_write chipio failed\n");
2642 * Write a block of data into DSP code or data RAM using pre-allocated
2645 * @codec: the HDA codec
2646 * @fls: pointer to a fast load image
2647 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2649 * @dma_engine: pointer to DMA engine to be used for DSP download
2650 * @dma_chan: The number of DMA channels used for DSP download
2651 * @port_map_mask: port mapping
2652 * @ovly: TRUE if overlay format is required
2654 * Returns zero or a negative error code.
2656 static int dspxfr_one_seg(struct hda_codec *codec,
2657 const struct dsp_image_seg *fls,
2659 struct dma_engine *dma_engine,
2660 unsigned int dma_chan,
2661 unsigned int port_map_mask,
2665 bool comm_dma_setup_done = false;
2666 const unsigned int *data;
2667 unsigned int chip_addx;
2668 unsigned int words_to_write;
2669 unsigned int buffer_size_words;
2670 unsigned char *buffer_addx;
2671 unsigned short hda_format;
2672 unsigned int sample_rate_div;
2673 unsigned int sample_rate_mul;
2674 unsigned int num_chans;
2675 unsigned int hda_frame_size_words;
2676 unsigned int remainder_words;
2677 const u32 *data_remainder;
2678 u32 chip_addx_remainder;
2679 unsigned int run_size_words;
2680 const struct dsp_image_seg *hci_write = NULL;
2681 unsigned long timeout;
2686 if (is_hci_prog_list_seg(fls)) {
2688 fls = get_next_seg_ptr(fls);
2691 if (hci_write && (!fls || is_last(fls))) {
2692 codec_dbg(codec, "hci_write\n");
2693 return dspxfr_hci_write(codec, hci_write);
2696 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2697 codec_dbg(codec, "Invalid Params\n");
2702 chip_addx = fls->chip_addr,
2703 words_to_write = fls->count;
2705 if (!words_to_write)
2706 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
2708 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
2710 if (!UC_RANGE(chip_addx, words_to_write) &&
2711 !X_RANGE_ALL(chip_addx, words_to_write) &&
2712 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2713 codec_dbg(codec, "Invalid chip_addx Params\n");
2717 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
2720 buffer_addx = dma_get_buffer_addr(dma_engine);
2722 if (buffer_addx == NULL) {
2723 codec_dbg(codec, "dma_engine buffer NULL\n");
2727 dma_get_converter_format(dma_engine, &hda_format);
2728 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
2729 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
2730 num_chans = get_hdafmt_chs(hda_format) + 1;
2732 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
2733 (num_chans * sample_rate_mul / sample_rate_div));
2735 if (hda_frame_size_words == 0) {
2736 codec_dbg(codec, "frmsz zero\n");
2740 buffer_size_words = min(buffer_size_words,
2741 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2743 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2745 "chpadr=0x%08x frmsz=%u nchan=%u "
2746 "rate_mul=%u div=%u bufsz=%u\n",
2747 chip_addx, hda_frame_size_words, num_chans,
2748 sample_rate_mul, sample_rate_div, buffer_size_words);
2750 if (buffer_size_words < hda_frame_size_words) {
2751 codec_dbg(codec, "dspxfr_one_seg:failed\n");
2755 remainder_words = words_to_write % hda_frame_size_words;
2756 data_remainder = data;
2757 chip_addx_remainder = chip_addx;
2759 data += remainder_words;
2760 chip_addx += remainder_words*sizeof(u32);
2761 words_to_write -= remainder_words;
2763 while (words_to_write != 0) {
2764 run_size_words = min(buffer_size_words, words_to_write);
2765 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2766 words_to_write, run_size_words, remainder_words);
2767 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2768 if (!comm_dma_setup_done) {
2769 status = dsp_dma_stop(codec, dma_chan, ovly);
2772 status = dsp_dma_setup_common(codec, chip_addx,
2773 dma_chan, port_map_mask, ovly);
2776 comm_dma_setup_done = true;
2779 status = dsp_dma_setup(codec, chip_addx,
2780 run_size_words, dma_chan);
2783 status = dsp_dma_start(codec, dma_chan, ovly);
2786 if (!dsp_is_dma_active(codec, dma_chan)) {
2787 codec_dbg(codec, "dspxfr:DMA did not start\n");
2790 status = dma_set_state(dma_engine, DMA_STATE_RUN);
2793 if (remainder_words != 0) {
2794 status = chipio_write_multiple(codec,
2795 chip_addx_remainder,
2800 remainder_words = 0;
2803 status = dspxfr_hci_write(codec, hci_write);
2809 timeout = jiffies + msecs_to_jiffies(2000);
2811 dma_active = dsp_is_dma_active(codec, dma_chan);
2815 } while (time_before(jiffies, timeout));
2819 codec_dbg(codec, "+++++ DMA complete\n");
2820 dma_set_state(dma_engine, DMA_STATE_STOP);
2821 status = dma_reset(dma_engine);
2826 data += run_size_words;
2827 chip_addx += run_size_words*sizeof(u32);
2828 words_to_write -= run_size_words;
2831 if (remainder_words != 0) {
2832 status = chipio_write_multiple(codec, chip_addx_remainder,
2833 data_remainder, remainder_words);
2840 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2842 * @codec: the HDA codec
2843 * @fls_data: pointer to a fast load image
2844 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2846 * @sample_rate: sampling rate of the stream used for DSP download
2847 * @channels: channels of the stream used for DSP download
2848 * @ovly: TRUE if overlay format is required
2850 * Returns zero or a negative error code.
2852 static int dspxfr_image(struct hda_codec *codec,
2853 const struct dsp_image_seg *fls_data,
2855 unsigned int sample_rate,
2856 unsigned short channels,
2859 struct ca0132_spec *spec = codec->spec;
2861 unsigned short hda_format = 0;
2862 unsigned int response;
2863 unsigned char stream_id = 0;
2864 struct dma_engine *dma_engine;
2865 unsigned int dma_chan;
2866 unsigned int port_map_mask;
2868 if (fls_data == NULL)
2871 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
2875 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
2876 if (!dma_engine->dmab) {
2881 dma_engine->codec = codec;
2882 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
2883 dma_engine->m_converter_format = hda_format;
2884 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
2885 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
2887 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
2889 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
2890 hda_format, &response);
2893 codec_dbg(codec, "set converter format fail\n");
2897 status = snd_hda_codec_load_dsp_prepare(codec,
2898 dma_engine->m_converter_format,
2899 dma_engine->buf_size,
2903 spec->dsp_stream_id = status;
2906 status = dspio_alloc_dma_chan(codec, &dma_chan);
2908 codec_dbg(codec, "alloc dmachan fail\n");
2909 dma_chan = INVALID_DMA_CHANNEL;
2915 status = dsp_allocate_ports_format(codec, hda_format,
2918 codec_dbg(codec, "alloc ports fail\n");
2922 stream_id = dma_get_stream_id(dma_engine);
2923 status = codec_set_converter_stream_channel(codec,
2924 WIDGET_CHIP_CTRL, stream_id, 0, &response);
2926 codec_dbg(codec, "set stream chan fail\n");
2930 while ((fls_data != NULL) && !is_last(fls_data)) {
2931 if (!is_valid(fls_data)) {
2932 codec_dbg(codec, "FLS check fail\n");
2936 status = dspxfr_one_seg(codec, fls_data, reloc,
2937 dma_engine, dma_chan,
2938 port_map_mask, ovly);
2942 if (is_hci_prog_list_seg(fls_data))
2943 fls_data = get_next_seg_ptr(fls_data);
2945 if ((fls_data != NULL) && !is_last(fls_data))
2946 fls_data = get_next_seg_ptr(fls_data);
2949 if (port_map_mask != 0)
2950 status = dsp_free_ports(codec);
2955 status = codec_set_converter_stream_channel(codec,
2956 WIDGET_CHIP_CTRL, 0, 0, &response);
2959 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
2960 dspio_free_dma_chan(codec, dma_chan);
2962 if (dma_engine->dmab->area)
2963 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
2964 kfree(dma_engine->dmab);
2971 * CA0132 DSP download stuffs.
2973 static void dspload_post_setup(struct hda_codec *codec)
2975 struct ca0132_spec *spec = codec->spec;
2976 codec_dbg(codec, "---- dspload_post_setup ------\n");
2977 if (!spec->use_alt_functions) {
2978 /*set DSP speaker to 2.0 configuration*/
2979 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
2980 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
2982 /*update write pointer*/
2983 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
2988 * dspload_image - Download DSP from a DSP Image Fast Load structure.
2990 * @codec: the HDA codec
2991 * @fls: pointer to a fast load image
2992 * @ovly: TRUE if overlay format is required
2993 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2995 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
2996 * @router_chans: number of audio router channels to be allocated (0 means use
2997 * internal defaults; max is 32)
2999 * Download DSP from a DSP Image Fast Load structure. This structure is a
3000 * linear, non-constant sized element array of structures, each of which
3001 * contain the count of the data to be loaded, the data itself, and the
3002 * corresponding starting chip address of the starting data location.
3003 * Returns zero or a negative error code.
3005 static int dspload_image(struct hda_codec *codec,
3006 const struct dsp_image_seg *fls,
3013 unsigned int sample_rate;
3014 unsigned short channels;
3016 codec_dbg(codec, "---- dspload_image begin ------\n");
3017 if (router_chans == 0) {
3019 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3021 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3024 sample_rate = 48000;
3025 channels = (unsigned short)router_chans;
3027 while (channels > 16) {
3033 codec_dbg(codec, "Ready to program DMA\n");
3035 status = dsp_reset(codec);
3040 codec_dbg(codec, "dsp_reset() complete\n");
3041 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3047 codec_dbg(codec, "dspxfr_image() complete\n");
3048 if (autostart && !ovly) {
3049 dspload_post_setup(codec);
3050 status = dsp_set_run_state(codec);
3053 codec_dbg(codec, "LOAD FINISHED\n");
3059 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3060 static bool dspload_is_loaded(struct hda_codec *codec)
3062 unsigned int data = 0;
3065 status = chipio_read(codec, 0x40004, &data);
3066 if ((status < 0) || (data != 1))
3072 #define dspload_is_loaded(codec) false
3075 static bool dspload_wait_loaded(struct hda_codec *codec)
3077 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3080 if (dspload_is_loaded(codec)) {
3081 codec_info(codec, "ca0132 DSP downloaded and running\n");
3085 } while (time_before(jiffies, timeout));
3087 codec_err(codec, "ca0132 failed to download DSP\n");
3092 * Setup GPIO for the other variants of Core3D.
3096 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3097 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3098 * The first eight bits are just the number of the pin. So far, I've only seen
3099 * this number go to 7.
3101 static void ca0132_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3104 struct ca0132_spec *spec = codec->spec;
3105 unsigned short gpio_data;
3107 gpio_data = gpio_pin & 0xF;
3108 gpio_data |= ((enable << 8) & 0x100);
3110 writew(gpio_data, spec->mem_base + 0x320);
3114 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3115 * the card shows as having no GPIO pins.
3117 static void ca0132_gpio_init(struct hda_codec *codec)
3119 struct ca0132_spec *spec = codec->spec;
3121 switch (spec->quirk) {
3123 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3124 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3125 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3128 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3129 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3135 /* Sets the GPIO for audio output. */
3136 static void ca0132_gpio_setup(struct hda_codec *codec)
3138 struct ca0132_spec *spec = codec->spec;
3140 switch (spec->quirk) {
3142 snd_hda_codec_write(codec, 0x01, 0,
3143 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3144 snd_hda_codec_write(codec, 0x01, 0,
3145 AC_VERB_SET_GPIO_MASK, 0x07);
3146 snd_hda_codec_write(codec, 0x01, 0,
3147 AC_VERB_SET_GPIO_DATA, 0x04);
3148 snd_hda_codec_write(codec, 0x01, 0,
3149 AC_VERB_SET_GPIO_DATA, 0x06);
3152 snd_hda_codec_write(codec, 0x01, 0,
3153 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3154 snd_hda_codec_write(codec, 0x01, 0,
3155 AC_VERB_SET_GPIO_MASK, 0x1F);
3156 snd_hda_codec_write(codec, 0x01, 0,
3157 AC_VERB_SET_GPIO_DATA, 0x0C);
3163 * GPIO control functions for the Recon3D integrated.
3166 enum r3di_gpio_bit {
3167 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3168 R3DI_MIC_SELECT_BIT = 1,
3169 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3170 R3DI_OUT_SELECT_BIT = 2,
3172 * I dunno what this actually does, but it stays on until the dsp
3175 R3DI_GPIO_DSP_DOWNLOADING = 3,
3177 * Same as above, no clue what it does, but it comes on after the dsp
3180 R3DI_GPIO_DSP_DOWNLOADED = 4
3183 enum r3di_mic_select {
3184 /* Set GPIO bit 1 to 0 for rear mic */
3186 /* Set GPIO bit 1 to 1 for front microphone*/
3190 enum r3di_out_select {
3191 /* Set GPIO bit 2 to 0 for headphone */
3192 R3DI_HEADPHONE_OUT = 0,
3193 /* Set GPIO bit 2 to 1 for speaker */
3196 enum r3di_dsp_status {
3197 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3198 R3DI_DSP_DOWNLOADING = 0,
3199 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3200 R3DI_DSP_DOWNLOADED = 1
3204 static void r3di_gpio_mic_set(struct hda_codec *codec,
3205 enum r3di_mic_select cur_mic)
3207 unsigned int cur_gpio;
3209 /* Get the current GPIO Data setup */
3210 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3214 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3216 case R3DI_FRONT_MIC:
3217 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3220 snd_hda_codec_write(codec, codec->core.afg, 0,
3221 AC_VERB_SET_GPIO_DATA, cur_gpio);
3224 static void r3di_gpio_out_set(struct hda_codec *codec,
3225 enum r3di_out_select cur_out)
3227 unsigned int cur_gpio;
3229 /* Get the current GPIO Data setup */
3230 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3233 case R3DI_HEADPHONE_OUT:
3234 cur_gpio &= ~(1 << R3DI_OUT_SELECT_BIT);
3237 cur_gpio |= (1 << R3DI_OUT_SELECT_BIT);
3240 snd_hda_codec_write(codec, codec->core.afg, 0,
3241 AC_VERB_SET_GPIO_DATA, cur_gpio);
3244 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3245 enum r3di_dsp_status dsp_status)
3247 unsigned int cur_gpio;
3249 /* Get the current GPIO Data setup */
3250 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3252 switch (dsp_status) {
3253 case R3DI_DSP_DOWNLOADING:
3254 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3255 snd_hda_codec_write(codec, codec->core.afg, 0,
3256 AC_VERB_SET_GPIO_DATA, cur_gpio);
3258 case R3DI_DSP_DOWNLOADED:
3259 /* Set DOWNLOADING bit to 0. */
3260 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3262 snd_hda_codec_write(codec, codec->core.afg, 0,
3263 AC_VERB_SET_GPIO_DATA, cur_gpio);
3265 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3269 snd_hda_codec_write(codec, codec->core.afg, 0,
3270 AC_VERB_SET_GPIO_DATA, cur_gpio);
3276 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3277 struct hda_codec *codec,
3278 unsigned int stream_tag,
3279 unsigned int format,
3280 struct snd_pcm_substream *substream)
3282 struct ca0132_spec *spec = codec->spec;
3284 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3289 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3290 struct hda_codec *codec,
3291 struct snd_pcm_substream *substream)
3293 struct ca0132_spec *spec = codec->spec;
3295 if (spec->dsp_state == DSP_DOWNLOADING)
3298 /*If Playback effects are on, allow stream some time to flush
3300 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3303 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3308 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3309 struct hda_codec *codec,
3310 struct snd_pcm_substream *substream)
3312 struct ca0132_spec *spec = codec->spec;
3313 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3314 struct snd_pcm_runtime *runtime = substream->runtime;
3316 if (spec->dsp_state != DSP_DOWNLOADED)
3319 /* Add latency if playback enhancement and either effect is enabled. */
3320 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3321 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3322 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3323 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3326 /* Applying Speaker EQ adds latency as well. */
3327 if (spec->cur_out_type == SPEAKER_OUT)
3328 latency += DSP_SPEAKER_OUT_LATENCY;
3330 return (latency * runtime->rate) / 1000;
3336 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3337 struct hda_codec *codec,
3338 struct snd_pcm_substream *substream)
3340 struct ca0132_spec *spec = codec->spec;
3341 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3344 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3345 struct hda_codec *codec,
3346 unsigned int stream_tag,
3347 unsigned int format,
3348 struct snd_pcm_substream *substream)
3350 struct ca0132_spec *spec = codec->spec;
3351 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3352 stream_tag, format, substream);
3355 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3356 struct hda_codec *codec,
3357 struct snd_pcm_substream *substream)
3359 struct ca0132_spec *spec = codec->spec;
3360 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3363 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3364 struct hda_codec *codec,
3365 struct snd_pcm_substream *substream)
3367 struct ca0132_spec *spec = codec->spec;
3368 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3374 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3375 struct hda_codec *codec,
3376 unsigned int stream_tag,
3377 unsigned int format,
3378 struct snd_pcm_substream *substream)
3380 snd_hda_codec_setup_stream(codec, hinfo->nid,
3381 stream_tag, 0, format);
3386 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3387 struct hda_codec *codec,
3388 struct snd_pcm_substream *substream)
3390 struct ca0132_spec *spec = codec->spec;
3392 if (spec->dsp_state == DSP_DOWNLOADING)
3395 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3399 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
3400 struct hda_codec *codec,
3401 struct snd_pcm_substream *substream)
3403 struct ca0132_spec *spec = codec->spec;
3404 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
3405 struct snd_pcm_runtime *runtime = substream->runtime;
3407 if (spec->dsp_state != DSP_DOWNLOADED)
3410 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3411 latency += DSP_CRYSTAL_VOICE_LATENCY;
3413 return (latency * runtime->rate) / 1000;
3421 * Mixer controls helpers.
3423 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
3424 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3426 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3427 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3428 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3429 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3430 .info = ca0132_volume_info, \
3431 .get = ca0132_volume_get, \
3432 .put = ca0132_volume_put, \
3433 .tlv = { .c = ca0132_volume_tlv }, \
3434 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3437 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
3438 * volume put, which is used for setting the DSP volume. This was done because
3439 * the ca0132 functions were taking too much time and causing lag.
3441 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
3442 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3444 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3445 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3446 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3447 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3448 .info = snd_hda_mixer_amp_volume_info, \
3449 .get = snd_hda_mixer_amp_volume_get, \
3450 .put = ca0132_alt_volume_put, \
3451 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
3452 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3454 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
3455 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3457 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3458 .info = snd_hda_mixer_amp_switch_info, \
3459 .get = ca0132_switch_get, \
3460 .put = ca0132_switch_put, \
3461 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3464 #define CA0132_CODEC_VOL(xname, nid, dir) \
3465 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
3466 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
3467 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
3468 #define CA0132_CODEC_MUTE(xname, nid, dir) \
3469 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
3473 * Lookup table with decibel values for the DSP. When volume is changed in
3474 * Windows, the DSP is also sent the dB value in floating point. In Windows,
3475 * these values have decimal points, probably because the Windows driver
3476 * actually uses floating point. We can't here, so I made a lookup table of
3477 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
3478 * DAC's, and 9 is the maximum.
3480 static const unsigned int float_vol_db_lookup[] = {
3481 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
3482 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
3483 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
3484 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
3485 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
3486 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
3487 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
3488 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
3489 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
3490 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
3491 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
3492 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3493 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3494 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3495 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3496 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3497 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
3501 * This table counts from float 0 to 1 in increments of .01, which is
3502 * useful for a few different sliders.
3504 static const unsigned int float_zero_to_one_lookup[] = {
3505 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3506 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3507 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3508 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3509 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3510 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3511 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3512 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3513 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3514 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3515 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3516 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3517 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3518 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3519 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3520 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3521 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3525 * This table counts from float 10 to 1000, which is the range of the x-bass
3526 * crossover slider in Windows.
3528 static const unsigned int float_xbass_xover_lookup[] = {
3529 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
3530 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
3531 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
3532 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
3533 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
3534 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
3535 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
3536 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
3537 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
3538 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
3539 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
3540 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
3541 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
3542 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
3543 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
3544 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
3545 0x44728000, 0x44750000, 0x44778000, 0x447A0000
3548 /* The following are for tuning of products */
3549 #ifdef ENABLE_TUNING_CONTROLS
3551 static unsigned int voice_focus_vals_lookup[] = {
3552 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
3553 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
3554 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
3555 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
3556 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
3557 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
3558 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
3559 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
3560 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
3561 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
3562 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
3563 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
3564 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
3565 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
3566 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
3567 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
3568 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
3569 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
3570 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
3571 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
3572 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
3573 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
3574 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
3575 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
3576 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
3577 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
3578 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
3581 static unsigned int mic_svm_vals_lookup[] = {
3582 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3583 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3584 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3585 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3586 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3587 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3588 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3589 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3590 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3591 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3592 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3593 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3594 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3595 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3596 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3597 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3598 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3601 static unsigned int equalizer_vals_lookup[] = {
3602 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3603 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3604 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3605 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3606 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3607 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
3608 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
3609 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
3613 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
3614 unsigned int *lookup, int idx)
3618 for (i = 0; i < TUNING_CTLS_COUNT; i++)
3619 if (nid == ca0132_tuning_ctls[i].nid)
3622 snd_hda_power_up(codec);
3623 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
3624 ca0132_tuning_ctls[i].req,
3625 &(lookup[idx]), sizeof(unsigned int));
3626 snd_hda_power_down(codec);
3631 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
3632 struct snd_ctl_elem_value *ucontrol)
3634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3635 struct ca0132_spec *spec = codec->spec;
3636 hda_nid_t nid = get_amp_nid(kcontrol);
3637 long *valp = ucontrol->value.integer.value;
3638 int idx = nid - TUNING_CTL_START_NID;
3640 *valp = spec->cur_ctl_vals[idx];
3644 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
3645 struct snd_ctl_elem_info *uinfo)
3647 int chs = get_amp_channels(kcontrol);
3648 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3649 uinfo->count = chs == 3 ? 2 : 1;
3650 uinfo->value.integer.min = 20;
3651 uinfo->value.integer.max = 180;
3652 uinfo->value.integer.step = 1;
3657 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
3658 struct snd_ctl_elem_value *ucontrol)
3660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3661 struct ca0132_spec *spec = codec->spec;
3662 hda_nid_t nid = get_amp_nid(kcontrol);
3663 long *valp = ucontrol->value.integer.value;
3666 idx = nid - TUNING_CTL_START_NID;
3668 if (spec->cur_ctl_vals[idx] == *valp)
3671 spec->cur_ctl_vals[idx] = *valp;
3674 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
3679 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
3680 struct snd_ctl_elem_info *uinfo)
3682 int chs = get_amp_channels(kcontrol);
3683 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3684 uinfo->count = chs == 3 ? 2 : 1;
3685 uinfo->value.integer.min = 0;
3686 uinfo->value.integer.max = 100;
3687 uinfo->value.integer.step = 1;
3692 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
3693 struct snd_ctl_elem_value *ucontrol)
3695 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3696 struct ca0132_spec *spec = codec->spec;
3697 hda_nid_t nid = get_amp_nid(kcontrol);
3698 long *valp = ucontrol->value.integer.value;
3701 idx = nid - TUNING_CTL_START_NID;
3703 if (spec->cur_ctl_vals[idx] == *valp)
3706 spec->cur_ctl_vals[idx] = *valp;
3709 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
3714 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
3715 struct snd_ctl_elem_info *uinfo)
3717 int chs = get_amp_channels(kcontrol);
3718 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3719 uinfo->count = chs == 3 ? 2 : 1;
3720 uinfo->value.integer.min = 0;
3721 uinfo->value.integer.max = 48;
3722 uinfo->value.integer.step = 1;
3727 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
3728 struct snd_ctl_elem_value *ucontrol)
3730 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3731 struct ca0132_spec *spec = codec->spec;
3732 hda_nid_t nid = get_amp_nid(kcontrol);
3733 long *valp = ucontrol->value.integer.value;
3736 idx = nid - TUNING_CTL_START_NID;
3738 if (spec->cur_ctl_vals[idx] == *valp)
3741 spec->cur_ctl_vals[idx] = *valp;
3744 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
3749 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
3750 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
3752 static int add_tuning_control(struct hda_codec *codec,
3753 hda_nid_t pnid, hda_nid_t nid,
3754 const char *name, int dir)
3756 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3757 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3758 struct snd_kcontrol_new knew =
3759 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
3761 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3762 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3767 knew.info = voice_focus_ctl_info;
3768 knew.get = tuning_ctl_get;
3769 knew.put = voice_focus_ctl_put;
3770 knew.tlv.p = voice_focus_db_scale;
3773 knew.info = mic_svm_ctl_info;
3774 knew.get = tuning_ctl_get;
3775 knew.put = mic_svm_ctl_put;
3778 knew.info = equalizer_ctl_info;
3779 knew.get = tuning_ctl_get;
3780 knew.put = equalizer_ctl_put;
3781 knew.tlv.p = eq_db_scale;
3786 knew.private_value =
3787 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
3788 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
3789 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
3792 static int add_tuning_ctls(struct hda_codec *codec)
3797 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
3798 err = add_tuning_control(codec,
3799 ca0132_tuning_ctls[i].parent_nid,
3800 ca0132_tuning_ctls[i].nid,
3801 ca0132_tuning_ctls[i].name,
3802 ca0132_tuning_ctls[i].direct);
3810 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
3812 struct ca0132_spec *spec = codec->spec;
3815 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
3816 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
3817 /* SVM level defaults to 0.74. */
3818 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
3820 /* EQ defaults to 0dB. */
3821 for (i = 2; i < TUNING_CTLS_COUNT; i++)
3822 spec->cur_ctl_vals[i] = 24;
3824 #endif /*ENABLE_TUNING_CONTROLS*/
3827 * Select the active output.
3828 * If autodetect is enabled, output will be selected based on jack detection.
3829 * If jack inserted, headphone will be selected, else built-in speakers
3830 * If autodetect is disabled, output will be selected based on selection.
3832 static int ca0132_select_out(struct hda_codec *codec)
3834 struct ca0132_spec *spec = codec->spec;
3835 unsigned int pin_ctl;
3841 codec_dbg(codec, "ca0132_select_out\n");
3843 snd_hda_power_up_pm(codec);
3845 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
3848 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
3851 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
3854 spec->cur_out_type = HEADPHONE_OUT;
3856 spec->cur_out_type = SPEAKER_OUT;
3858 if (spec->cur_out_type == SPEAKER_OUT) {
3859 codec_dbg(codec, "ca0132_select_out speaker\n");
3860 /*speaker out config*/
3862 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
3865 /*enable speaker EQ*/
3867 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
3872 snd_hda_codec_write(codec, spec->out_pins[1], 0,
3873 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
3874 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3875 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
3876 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3877 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
3878 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3879 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3881 /* disable headphone node */
3882 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
3883 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3884 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
3886 /* enable speaker node */
3887 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
3888 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3889 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
3892 codec_dbg(codec, "ca0132_select_out hp\n");
3893 /*headphone out config*/
3895 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
3898 /*disable speaker EQ*/
3900 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
3905 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3906 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
3907 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3908 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
3909 snd_hda_codec_write(codec, spec->out_pins[1], 0,
3910 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
3911 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3912 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3914 /* disable speaker*/
3915 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
3916 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3917 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
3919 /* enable headphone*/
3920 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
3921 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3922 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
3927 snd_hda_power_down_pm(codec);
3929 return err < 0 ? err : 0;
3933 * This function behaves similarly to the ca0132_select_out funciton above,
3934 * except with a few differences. It adds the ability to select the current
3935 * output with an enumerated control "output source" if the auto detect
3936 * mute switch is set to off. If the auto detect mute switch is enabled, it
3937 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
3938 * It also adds the ability to auto-detect the front headphone port. The only
3939 * way to select surround is to disable auto detect, and set Surround with the
3940 * enumerated control.
3942 static int ca0132_alt_select_out(struct hda_codec *codec)
3944 struct ca0132_spec *spec = codec->spec;
3945 unsigned int pin_ctl;
3951 /* Default Headphone is rear headphone */
3952 hda_nid_t headphone_nid = spec->out_pins[1];
3954 codec_dbg(codec, "%s\n", __func__);
3956 snd_hda_power_up_pm(codec);
3958 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
3961 * If headphone rear or front is plugged in, set to headphone.
3962 * If neither is plugged in, set to rear line out. Only if
3963 * hp/speaker auto detect is enabled.
3966 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
3967 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
3970 spec->cur_out_type = HEADPHONE_OUT;
3972 spec->cur_out_type = SPEAKER_OUT;
3974 spec->cur_out_type = spec->out_enum_val;
3976 /* Begin DSP output switch */
3978 err = dspio_set_uint_param(codec, 0x96, 0x3A, tmp);
3982 switch (spec->cur_out_type) {
3984 codec_dbg(codec, "%s speaker\n", __func__);
3985 /*speaker out config*/
3986 switch (spec->quirk) {
3988 ca0132_mmio_gpio_set(codec, 7, false);
3989 ca0132_mmio_gpio_set(codec, 4, true);
3990 ca0132_mmio_gpio_set(codec, 1, true);
3991 chipio_set_control_param(codec, 0x0D, 0x18);
3994 chipio_set_control_param(codec, 0x0D, 0x24);
3995 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
3998 chipio_set_control_param(codec, 0x0D, 0x24);
3999 ca0132_mmio_gpio_set(codec, 1, true);
4003 /* disable headphone node */
4004 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4005 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4006 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4008 /* enable line-out node */
4009 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4010 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4011 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4014 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4015 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4017 /* If PlayEnhancement is enabled, set different source */
4018 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4019 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4021 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4024 codec_dbg(codec, "%s hp\n", __func__);
4025 /* Headphone out config*/
4026 switch (spec->quirk) {
4028 ca0132_mmio_gpio_set(codec, 7, true);
4029 ca0132_mmio_gpio_set(codec, 4, true);
4030 ca0132_mmio_gpio_set(codec, 1, false);
4031 chipio_set_control_param(codec, 0x0D, 0x12);
4034 chipio_set_control_param(codec, 0x0D, 0x21);
4035 r3di_gpio_out_set(codec, R3DI_HEADPHONE_OUT);
4038 chipio_set_control_param(codec, 0x0D, 0x21);
4039 ca0132_mmio_gpio_set(codec, 0x1, false);
4043 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4044 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4046 /* disable speaker*/
4047 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4048 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4049 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4052 /* enable headphone, either front or rear */
4054 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4055 headphone_nid = spec->out_pins[2];
4056 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4057 headphone_nid = spec->out_pins[1];
4059 pin_ctl = snd_hda_codec_read(codec, headphone_nid, 0,
4060 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4061 snd_hda_set_pin_ctl(codec, headphone_nid,
4064 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4065 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4067 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4070 codec_dbg(codec, "%s surround\n", __func__);
4071 /* Surround out config*/
4072 switch (spec->quirk) {
4074 ca0132_mmio_gpio_set(codec, 7, false);
4075 ca0132_mmio_gpio_set(codec, 4, true);
4076 ca0132_mmio_gpio_set(codec, 1, true);
4077 chipio_set_control_param(codec, 0x0D, 0x18);
4080 chipio_set_control_param(codec, 0x0D, 0x24);
4081 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
4084 ca0132_mmio_gpio_set(codec, 1, true);
4085 chipio_set_control_param(codec, 0x0D, 0x24);
4088 /* enable line out node */
4089 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4090 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4091 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4093 /* Disable headphone out */
4094 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4095 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4096 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4098 /* Enable EAPD on line out */
4099 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4100 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4101 /* enable center/lfe out node */
4102 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[2], 0,
4103 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4104 snd_hda_set_pin_ctl(codec, spec->out_pins[2],
4106 /* Now set rear surround node as out. */
4107 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[3], 0,
4108 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4109 snd_hda_set_pin_ctl(codec, spec->out_pins[3],
4112 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4113 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4115 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4119 /* run through the output dsp commands for line-out */
4120 for (i = 0; i < alt_out_presets[spec->cur_out_type].commands; i++) {
4121 err = dspio_set_uint_param(codec,
4122 alt_out_presets[spec->cur_out_type].mids[i],
4123 alt_out_presets[spec->cur_out_type].reqs[i],
4124 alt_out_presets[spec->cur_out_type].vals[i]);
4131 snd_hda_power_down_pm(codec);
4133 return err < 0 ? err : 0;
4136 static void ca0132_unsol_hp_delayed(struct work_struct *work)
4138 struct ca0132_spec *spec = container_of(
4139 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
4140 struct hda_jack_tbl *jack;
4142 if (spec->use_alt_functions)
4143 ca0132_alt_select_out(spec->codec);
4145 ca0132_select_out(spec->codec);
4147 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4149 jack->block_report = 0;
4150 snd_hda_jack_report_sync(spec->codec);
4154 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4155 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4156 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4157 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4158 static int stop_mic1(struct hda_codec *codec);
4159 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4160 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4163 * Select the active VIP source
4165 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4167 struct ca0132_spec *spec = codec->spec;
4170 if (spec->dsp_state != DSP_DOWNLOADED)
4173 /* if CrystalVoice if off, vipsource should be 0 */
4174 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4176 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4177 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4178 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4179 if (spec->cur_mic_type == DIGITAL_MIC)
4183 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4185 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4187 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4188 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4189 if (spec->cur_mic_type == DIGITAL_MIC)
4193 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4195 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4197 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4203 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4205 struct ca0132_spec *spec = codec->spec;
4208 if (spec->dsp_state != DSP_DOWNLOADED)
4211 codec_dbg(codec, "%s\n", __func__);
4213 chipio_set_stream_control(codec, 0x03, 0);
4214 chipio_set_stream_control(codec, 0x04, 0);
4216 /* if CrystalVoice is off, vipsource should be 0 */
4217 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4218 (val == 0) || spec->in_enum_val == REAR_LINE_IN) {
4219 codec_dbg(codec, "%s: off.", __func__);
4220 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4223 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4225 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4226 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4227 if (spec->quirk == QUIRK_R3DI)
4228 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4231 if (spec->in_enum_val == REAR_LINE_IN)
4234 if (spec->quirk == QUIRK_SBZ)
4240 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4243 codec_dbg(codec, "%s: on.", __func__);
4244 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4245 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4246 if (spec->quirk == QUIRK_R3DI)
4247 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
4249 if (spec->effects_switch[VOICE_FOCUS - EFFECT_START_NID])
4253 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4256 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4259 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4262 chipio_set_stream_control(codec, 0x03, 1);
4263 chipio_set_stream_control(codec, 0x04, 1);
4269 * Select the active microphone.
4270 * If autodetect is enabled, mic will be selected based on jack detection.
4271 * If jack inserted, ext.mic will be selected, else built-in mic
4272 * If autodetect is disabled, mic will be selected based on selection.
4274 static int ca0132_select_mic(struct hda_codec *codec)
4276 struct ca0132_spec *spec = codec->spec;
4280 codec_dbg(codec, "ca0132_select_mic\n");
4282 snd_hda_power_up_pm(codec);
4284 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
4287 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
4290 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
4293 spec->cur_mic_type = LINE_MIC_IN;
4295 spec->cur_mic_type = DIGITAL_MIC;
4297 if (spec->cur_mic_type == DIGITAL_MIC) {
4298 /* enable digital Mic */
4299 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
4300 ca0132_set_dmic(codec, 1);
4301 ca0132_mic_boost_set(codec, 0);
4302 /* set voice focus */
4303 ca0132_effects_set(codec, VOICE_FOCUS,
4304 spec->effects_switch
4305 [VOICE_FOCUS - EFFECT_START_NID]);
4307 /* disable digital Mic */
4308 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
4309 ca0132_set_dmic(codec, 0);
4310 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
4311 /* disable voice focus */
4312 ca0132_effects_set(codec, VOICE_FOCUS, 0);
4315 snd_hda_power_down_pm(codec);
4321 * Select the active input.
4322 * Mic detection isn't used, because it's kind of pointless on the SBZ.
4323 * The front mic has no jack-detection, so the only way to switch to it
4324 * is to do it manually in alsamixer.
4326 static int ca0132_alt_select_in(struct hda_codec *codec)
4328 struct ca0132_spec *spec = codec->spec;
4331 codec_dbg(codec, "%s\n", __func__);
4333 snd_hda_power_up_pm(codec);
4335 chipio_set_stream_control(codec, 0x03, 0);
4336 chipio_set_stream_control(codec, 0x04, 0);
4338 spec->cur_mic_type = spec->in_enum_val;
4340 switch (spec->cur_mic_type) {
4342 switch (spec->quirk) {
4345 ca0132_mmio_gpio_set(codec, 0, false);
4349 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4357 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4358 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4359 if (spec->quirk == QUIRK_R3DI)
4360 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4362 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4364 chipio_set_stream_control(codec, 0x03, 1);
4365 chipio_set_stream_control(codec, 0x04, 1);
4367 if (spec->quirk == QUIRK_SBZ) {
4368 chipio_write(codec, 0x18B098, 0x0000000C);
4369 chipio_write(codec, 0x18B09C, 0x0000000C);
4371 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4374 ca0132_mic_boost_set(codec, 0);
4375 switch (spec->quirk) {
4378 ca0132_mmio_gpio_set(codec, 0, false);
4381 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4385 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4386 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4387 if (spec->quirk == QUIRK_R3DI)
4388 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4391 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4393 if (spec->quirk == QUIRK_SBZ) {
4394 chipio_write(codec, 0x18B098, 0x00000000);
4395 chipio_write(codec, 0x18B09C, 0x00000000);
4398 chipio_set_stream_control(codec, 0x03, 1);
4399 chipio_set_stream_control(codec, 0x04, 1);
4402 switch (spec->quirk) {
4405 ca0132_mmio_gpio_set(codec, 0, true);
4406 ca0132_mmio_gpio_set(codec, 5, false);
4410 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
4418 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4419 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4420 if (spec->quirk == QUIRK_R3DI)
4421 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4423 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4425 chipio_set_stream_control(codec, 0x03, 1);
4426 chipio_set_stream_control(codec, 0x04, 1);
4428 if (spec->quirk == QUIRK_SBZ) {
4429 chipio_write(codec, 0x18B098, 0x0000000C);
4430 chipio_write(codec, 0x18B09C, 0x000000CC);
4432 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4435 ca0132_cvoice_switch_set(codec);
4437 snd_hda_power_down_pm(codec);
4443 * Check if VNODE settings take effect immediately.
4445 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
4447 hda_nid_t *shared_nid)
4449 struct ca0132_spec *spec = codec->spec;
4454 nid = spec->shared_out_nid;
4457 nid = spec->shared_mic_nid;
4470 * The following functions are control change helpers.
4471 * They return 0 if no changed. Return 1 if changed.
4473 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
4475 struct ca0132_spec *spec = codec->spec;
4478 /* based on CrystalVoice state to enable VoiceFX. */
4480 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
4481 FLOAT_ONE : FLOAT_ZERO;
4486 dspio_set_uint_param(codec, ca0132_voicefx.mid,
4487 ca0132_voicefx.reqs[0], tmp);
4493 * Set the effects parameters
4495 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
4497 struct ca0132_spec *spec = codec->spec;
4498 unsigned int on, tmp;
4499 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
4501 int idx = nid - EFFECT_START_NID;
4503 if ((idx < 0) || (idx >= num_fx))
4504 return 0; /* no changed */
4506 /* for out effect, qualify with PE */
4507 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
4508 /* if PE if off, turn off out effects. */
4509 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4513 /* for in effect, qualify with CrystalVoice */
4514 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
4515 /* if CrystalVoice if off, turn off in effects. */
4516 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
4519 /* Voice Focus applies to 2-ch Mic, Digital Mic */
4520 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
4523 /* If Voice Focus on SBZ, set to two channel. */
4524 if ((nid == VOICE_FOCUS) && (spec->use_pci_mmio)
4525 && (spec->cur_mic_type != REAR_LINE_IN)) {
4526 if (spec->effects_switch[CRYSTAL_VOICE -
4527 EFFECT_START_NID]) {
4529 if (spec->effects_switch[VOICE_FOCUS -
4530 EFFECT_START_NID]) {
4536 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4540 * For SBZ noise reduction, there's an extra command
4541 * to module ID 0x47. No clue why.
4543 if ((nid == NOISE_REDUCTION) && (spec->use_pci_mmio)
4544 && (spec->cur_mic_type != REAR_LINE_IN)) {
4545 if (spec->effects_switch[CRYSTAL_VOICE -
4546 EFFECT_START_NID]) {
4547 if (spec->effects_switch[NOISE_REDUCTION -
4555 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
4558 /* If rear line in disable effects. */
4559 if (spec->use_alt_functions &&
4560 spec->in_enum_val == REAR_LINE_IN)
4564 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
4567 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
4568 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
4569 ca0132_effects[idx].reqs[0], on);
4572 return 0; /* no changed */
4578 * Turn on/off Playback Enhancements
4580 static int ca0132_pe_switch_set(struct hda_codec *codec)
4582 struct ca0132_spec *spec = codec->spec;
4586 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
4587 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
4589 if (spec->use_alt_functions)
4590 ca0132_alt_select_out(codec);
4592 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
4593 nid = OUT_EFFECT_START_NID;
4594 /* PE affects all out effects */
4595 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
4596 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
4601 /* Check if Mic1 is streaming, if so, stop streaming */
4602 static int stop_mic1(struct hda_codec *codec)
4604 struct ca0132_spec *spec = codec->spec;
4605 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
4606 AC_VERB_GET_CONV, 0);
4608 snd_hda_codec_write(codec, spec->adcs[0], 0,
4609 AC_VERB_SET_CHANNEL_STREAMID,
4614 /* Resume Mic1 streaming if it was stopped. */
4615 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
4617 struct ca0132_spec *spec = codec->spec;
4618 /* Restore the previous stream and channel */
4620 snd_hda_codec_write(codec, spec->adcs[0], 0,
4621 AC_VERB_SET_CHANNEL_STREAMID,
4626 * Turn on/off CrystalVoice
4628 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
4630 struct ca0132_spec *spec = codec->spec;
4633 unsigned int oldval;
4635 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
4636 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
4638 i = IN_EFFECT_START_NID - EFFECT_START_NID;
4639 nid = IN_EFFECT_START_NID;
4640 /* CrystalVoice affects all in effects */
4641 for (; nid < IN_EFFECT_END_NID; nid++, i++)
4642 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
4644 /* including VoiceFX */
4645 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
4647 /* set correct vipsource */
4648 oldval = stop_mic1(codec);
4649 if (spec->use_alt_functions)
4650 ret |= ca0132_alt_set_vipsource(codec, 1);
4652 ret |= ca0132_set_vipsource(codec, 1);
4653 resume_mic1(codec, oldval);
4657 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
4659 struct ca0132_spec *spec = codec->spec;
4663 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
4664 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
4666 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
4667 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
4672 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
4674 struct ca0132_spec *spec = codec->spec;
4677 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
4678 HDA_INPUT, 0, HDA_AMP_VOLMASK, val);
4682 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
4683 struct snd_ctl_elem_value *ucontrol)
4685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4686 hda_nid_t nid = get_amp_nid(kcontrol);
4687 hda_nid_t shared_nid = 0;
4690 struct ca0132_spec *spec = codec->spec;
4693 if (nid == VNID_HP_SEL) {
4695 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4697 if (spec->use_alt_functions)
4698 ca0132_alt_select_out(codec);
4700 ca0132_select_out(codec);
4705 if (nid == VNID_AMIC1_SEL) {
4707 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
4709 ca0132_select_mic(codec);
4713 if (nid == VNID_HP_ASEL) {
4714 if (spec->use_alt_functions)
4715 ca0132_alt_select_out(codec);
4717 ca0132_select_out(codec);
4721 if (nid == VNID_AMIC1_ASEL) {
4722 ca0132_select_mic(codec);
4726 /* if effective conditions, then update hw immediately. */
4727 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
4729 int dir = get_amp_direction(kcontrol);
4730 int ch = get_amp_channels(kcontrol);
4733 mutex_lock(&codec->control_mutex);
4734 pval = kcontrol->private_value;
4735 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
4737 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
4738 kcontrol->private_value = pval;
4739 mutex_unlock(&codec->control_mutex);
4744 /* End of control change helpers. */
4746 * Below I've added controls to mess with the effect levels, I've only enabled
4747 * them on the Sound Blaster Z, but they would probably also work on the
4748 * Chromebook. I figured they were probably tuned specifically for it, and left
4752 /* Sets DSP effect level from the sliders above the controls */
4753 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
4754 const unsigned int *lookup, int idx)
4759 * For X_BASS, req 2 is actually crossover freq instead of
4767 snd_hda_power_up(codec);
4768 if (nid == XBASS_XOVER) {
4769 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
4770 if (ca0132_effects[i].nid == X_BASS)
4773 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
4774 ca0132_effects[i].reqs[1],
4775 &(lookup[idx - 1]), sizeof(unsigned int));
4777 /* Find the actual effect structure */
4778 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
4779 if (nid == ca0132_effects[i].nid)
4782 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
4783 ca0132_effects[i].reqs[y],
4784 &(lookup[idx]), sizeof(unsigned int));
4787 snd_hda_power_down(codec);
4792 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol *kcontrol,
4793 struct snd_ctl_elem_value *ucontrol)
4795 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4796 struct ca0132_spec *spec = codec->spec;
4797 long *valp = ucontrol->value.integer.value;
4799 *valp = spec->xbass_xover_freq;
4803 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol *kcontrol,
4804 struct snd_ctl_elem_value *ucontrol)
4806 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4807 struct ca0132_spec *spec = codec->spec;
4808 hda_nid_t nid = get_amp_nid(kcontrol);
4809 long *valp = ucontrol->value.integer.value;
4810 int idx = nid - OUT_EFFECT_START_NID;
4812 *valp = spec->fx_ctl_val[idx];
4817 * The X-bass crossover starts at 10hz, so the min is 1. The
4818 * frequency is set in multiples of 10.
4820 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol *kcontrol,
4821 struct snd_ctl_elem_info *uinfo)
4823 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4825 uinfo->value.integer.min = 1;
4826 uinfo->value.integer.max = 100;
4827 uinfo->value.integer.step = 1;
4832 static int ca0132_alt_effect_slider_info(struct snd_kcontrol *kcontrol,
4833 struct snd_ctl_elem_info *uinfo)
4835 int chs = get_amp_channels(kcontrol);
4837 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4838 uinfo->count = chs == 3 ? 2 : 1;
4839 uinfo->value.integer.min = 0;
4840 uinfo->value.integer.max = 100;
4841 uinfo->value.integer.step = 1;
4846 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol *kcontrol,
4847 struct snd_ctl_elem_value *ucontrol)
4849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4850 struct ca0132_spec *spec = codec->spec;
4851 hda_nid_t nid = get_amp_nid(kcontrol);
4852 long *valp = ucontrol->value.integer.value;
4856 if (spec->xbass_xover_freq == *valp)
4859 spec->xbass_xover_freq = *valp;
4862 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
4867 static int ca0132_alt_effect_slider_put(struct snd_kcontrol *kcontrol,
4868 struct snd_ctl_elem_value *ucontrol)
4870 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4871 struct ca0132_spec *spec = codec->spec;
4872 hda_nid_t nid = get_amp_nid(kcontrol);
4873 long *valp = ucontrol->value.integer.value;
4876 idx = nid - EFFECT_START_NID;
4878 if (spec->fx_ctl_val[idx] == *valp)
4881 spec->fx_ctl_val[idx] = *valp;
4884 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
4891 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
4892 * only has off or full 30 dB, and didn't like making a volume slider that has
4893 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
4895 #define MIC_BOOST_NUM_OF_STEPS 4
4896 #define MIC_BOOST_ENUM_MAX_STRLEN 10
4898 static int ca0132_alt_mic_boost_info(struct snd_kcontrol *kcontrol,
4899 struct snd_ctl_elem_info *uinfo)
4902 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
4904 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4906 uinfo->value.enumerated.items = MIC_BOOST_NUM_OF_STEPS;
4907 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS)
4908 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1;
4909 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx);
4910 strcpy(uinfo->value.enumerated.name, namestr);
4914 static int ca0132_alt_mic_boost_get(struct snd_kcontrol *kcontrol,
4915 struct snd_ctl_elem_value *ucontrol)
4917 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4918 struct ca0132_spec *spec = codec->spec;
4920 ucontrol->value.enumerated.item[0] = spec->mic_boost_enum_val;
4924 static int ca0132_alt_mic_boost_put(struct snd_kcontrol *kcontrol,
4925 struct snd_ctl_elem_value *ucontrol)
4927 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4928 struct ca0132_spec *spec = codec->spec;
4929 int sel = ucontrol->value.enumerated.item[0];
4930 unsigned int items = MIC_BOOST_NUM_OF_STEPS;
4935 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
4938 spec->mic_boost_enum_val = sel;
4940 if (spec->in_enum_val != REAR_LINE_IN)
4941 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4948 * Input Select Control for alternative ca0132 codecs. This exists because
4949 * front microphone has no auto-detect, and we need a way to set the rear
4952 static int ca0132_alt_input_source_info(struct snd_kcontrol *kcontrol,
4953 struct snd_ctl_elem_info *uinfo)
4955 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4957 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS;
4958 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS)
4959 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1;
4960 strcpy(uinfo->value.enumerated.name,
4961 in_src_str[uinfo->value.enumerated.item]);
4965 static int ca0132_alt_input_source_get(struct snd_kcontrol *kcontrol,
4966 struct snd_ctl_elem_value *ucontrol)
4968 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4969 struct ca0132_spec *spec = codec->spec;
4971 ucontrol->value.enumerated.item[0] = spec->in_enum_val;
4975 static int ca0132_alt_input_source_put(struct snd_kcontrol *kcontrol,
4976 struct snd_ctl_elem_value *ucontrol)
4978 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4979 struct ca0132_spec *spec = codec->spec;
4980 int sel = ucontrol->value.enumerated.item[0];
4981 unsigned int items = IN_SRC_NUM_OF_INPUTS;
4986 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
4987 sel, in_src_str[sel]);
4989 spec->in_enum_val = sel;
4991 ca0132_alt_select_in(codec);
4996 /* Sound Blaster Z Output Select Control */
4997 static int ca0132_alt_output_select_get_info(struct snd_kcontrol *kcontrol,
4998 struct snd_ctl_elem_info *uinfo)
5000 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5002 uinfo->value.enumerated.items = NUM_OF_OUTPUTS;
5003 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS)
5004 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1;
5005 strcpy(uinfo->value.enumerated.name,
5006 alt_out_presets[uinfo->value.enumerated.item].name);
5010 static int ca0132_alt_output_select_get(struct snd_kcontrol *kcontrol,
5011 struct snd_ctl_elem_value *ucontrol)
5013 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5014 struct ca0132_spec *spec = codec->spec;
5016 ucontrol->value.enumerated.item[0] = spec->out_enum_val;
5020 static int ca0132_alt_output_select_put(struct snd_kcontrol *kcontrol,
5021 struct snd_ctl_elem_value *ucontrol)
5023 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5024 struct ca0132_spec *spec = codec->spec;
5025 int sel = ucontrol->value.enumerated.item[0];
5026 unsigned int items = NUM_OF_OUTPUTS;
5027 unsigned int auto_jack;
5032 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
5033 sel, alt_out_presets[sel].name);
5035 spec->out_enum_val = sel;
5037 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5040 ca0132_alt_select_out(codec);
5046 * Smart Volume output setting control. Three different settings, Normal,
5047 * which takes the value from the smart volume slider. The two others, loud
5048 * and night, disregard the slider value and have uneditable values.
5050 #define NUM_OF_SVM_SETTINGS 3
5051 static const char *const out_svm_set_enum_str[3] = {"Normal", "Loud", "Night" };
5053 static int ca0132_alt_svm_setting_info(struct snd_kcontrol *kcontrol,
5054 struct snd_ctl_elem_info *uinfo)
5056 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5058 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS;
5059 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS)
5060 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1;
5061 strcpy(uinfo->value.enumerated.name,
5062 out_svm_set_enum_str[uinfo->value.enumerated.item]);
5066 static int ca0132_alt_svm_setting_get(struct snd_kcontrol *kcontrol,
5067 struct snd_ctl_elem_value *ucontrol)
5069 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5070 struct ca0132_spec *spec = codec->spec;
5072 ucontrol->value.enumerated.item[0] = spec->smart_volume_setting;
5076 static int ca0132_alt_svm_setting_put(struct snd_kcontrol *kcontrol,
5077 struct snd_ctl_elem_value *ucontrol)
5079 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5080 struct ca0132_spec *spec = codec->spec;
5081 int sel = ucontrol->value.enumerated.item[0];
5082 unsigned int items = NUM_OF_SVM_SETTINGS;
5083 unsigned int idx = SMART_VOLUME - EFFECT_START_NID;
5089 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
5090 sel, out_svm_set_enum_str[sel]);
5092 spec->smart_volume_setting = sel;
5108 /* Req 2 is the Smart Volume Setting req. */
5109 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5110 ca0132_effects[idx].reqs[2], tmp);
5114 /* Sound Blaster Z EQ preset controls */
5115 static int ca0132_alt_eq_preset_info(struct snd_kcontrol *kcontrol,
5116 struct snd_ctl_elem_info *uinfo)
5118 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5120 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5122 uinfo->value.enumerated.items = items;
5123 if (uinfo->value.enumerated.item >= items)
5124 uinfo->value.enumerated.item = items - 1;
5125 strcpy(uinfo->value.enumerated.name,
5126 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name);
5130 static int ca0132_alt_eq_preset_get(struct snd_kcontrol *kcontrol,
5131 struct snd_ctl_elem_value *ucontrol)
5133 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5134 struct ca0132_spec *spec = codec->spec;
5136 ucontrol->value.enumerated.item[0] = spec->eq_preset_val;
5140 static int ca0132_alt_eq_preset_put(struct snd_kcontrol *kcontrol,
5141 struct snd_ctl_elem_value *ucontrol)
5143 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5144 struct ca0132_spec *spec = codec->spec;
5146 int sel = ucontrol->value.enumerated.item[0];
5147 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5152 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
5153 ca0132_alt_eq_presets[sel].name);
5156 * Default needs to qualify with CrystalVoice state.
5158 for (i = 0; i < EQ_PRESET_MAX_PARAM_COUNT; i++) {
5159 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
5160 ca0132_alt_eq_enum.reqs[i],
5161 ca0132_alt_eq_presets[sel].vals[i]);
5167 spec->eq_preset_val = sel;
5172 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
5173 struct snd_ctl_elem_info *uinfo)
5175 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
5177 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5179 uinfo->value.enumerated.items = items;
5180 if (uinfo->value.enumerated.item >= items)
5181 uinfo->value.enumerated.item = items - 1;
5182 strcpy(uinfo->value.enumerated.name,
5183 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
5187 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
5188 struct snd_ctl_elem_value *ucontrol)
5190 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5191 struct ca0132_spec *spec = codec->spec;
5193 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
5197 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
5198 struct snd_ctl_elem_value *ucontrol)
5200 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5201 struct ca0132_spec *spec = codec->spec;
5203 int sel = ucontrol->value.enumerated.item[0];
5205 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
5208 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
5209 sel, ca0132_voicefx_presets[sel].name);
5213 * Default needs to qualify with CrystalVoice state.
5215 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
5216 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
5217 ca0132_voicefx.reqs[i],
5218 ca0132_voicefx_presets[sel].vals[i]);
5224 spec->voicefx_val = sel;
5225 /* enable voice fx */
5226 ca0132_voicefx_set(codec, (sel ? 1 : 0));
5232 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
5233 struct snd_ctl_elem_value *ucontrol)
5235 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5236 struct ca0132_spec *spec = codec->spec;
5237 hda_nid_t nid = get_amp_nid(kcontrol);
5238 int ch = get_amp_channels(kcontrol);
5239 long *valp = ucontrol->value.integer.value;
5242 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5244 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
5248 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
5254 /* effects, include PE and CrystalVoice */
5255 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
5256 *valp = spec->effects_switch[nid - EFFECT_START_NID];
5261 if (nid == spec->input_pins[0]) {
5262 *valp = spec->cur_mic_boost;
5269 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
5270 struct snd_ctl_elem_value *ucontrol)
5272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5273 struct ca0132_spec *spec = codec->spec;
5274 hda_nid_t nid = get_amp_nid(kcontrol);
5275 int ch = get_amp_channels(kcontrol);
5276 long *valp = ucontrol->value.integer.value;
5279 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
5282 snd_hda_power_up(codec);
5284 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5286 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
5290 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
5293 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
5298 if (nid == PLAY_ENHANCEMENT) {
5299 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5300 changed = ca0132_pe_switch_set(codec);
5305 if (nid == CRYSTAL_VOICE) {
5306 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5307 changed = ca0132_cvoice_switch_set(codec);
5311 /* out and in effects */
5312 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
5313 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
5314 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5315 changed = ca0132_effects_set(codec, nid, *valp);
5320 if (nid == spec->input_pins[0]) {
5321 spec->cur_mic_boost = *valp;
5322 if (spec->use_alt_functions) {
5323 if (spec->in_enum_val != REAR_LINE_IN)
5324 changed = ca0132_mic_boost_set(codec, *valp);
5326 /* Mic boost does not apply to Digital Mic */
5327 if (spec->cur_mic_type != DIGITAL_MIC)
5328 changed = ca0132_mic_boost_set(codec, *valp);
5335 snd_hda_power_down(codec);
5343 * Sets the internal DSP decibel level to match the DAC for output, and the
5344 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
5345 * all alternative codecs set DSP playback volume.
5347 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
5349 struct ca0132_spec *spec = codec->spec;
5350 unsigned int dsp_dir;
5351 unsigned int lookup_val;
5353 if (nid == VNID_SPK)
5354 dsp_dir = DSP_VOL_OUT;
5356 dsp_dir = DSP_VOL_IN;
5358 lookup_val = spec->vnode_lvol[nid - VNODE_START_NID];
5360 dspio_set_uint_param(codec,
5361 ca0132_alt_vol_ctls[dsp_dir].mid,
5362 ca0132_alt_vol_ctls[dsp_dir].reqs[0],
5363 float_vol_db_lookup[lookup_val]);
5365 lookup_val = spec->vnode_rvol[nid - VNODE_START_NID];
5367 dspio_set_uint_param(codec,
5368 ca0132_alt_vol_ctls[dsp_dir].mid,
5369 ca0132_alt_vol_ctls[dsp_dir].reqs[1],
5370 float_vol_db_lookup[lookup_val]);
5372 dspio_set_uint_param(codec,
5373 ca0132_alt_vol_ctls[dsp_dir].mid,
5374 ca0132_alt_vol_ctls[dsp_dir].reqs[2], FLOAT_ZERO);
5377 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
5378 struct snd_ctl_elem_info *uinfo)
5380 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5381 struct ca0132_spec *spec = codec->spec;
5382 hda_nid_t nid = get_amp_nid(kcontrol);
5383 int ch = get_amp_channels(kcontrol);
5384 int dir = get_amp_direction(kcontrol);
5390 /* follow shared_out info */
5391 nid = spec->shared_out_nid;
5392 mutex_lock(&codec->control_mutex);
5393 pval = kcontrol->private_value;
5394 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5395 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5396 kcontrol->private_value = pval;
5397 mutex_unlock(&codec->control_mutex);
5400 /* follow shared_mic info */
5401 nid = spec->shared_mic_nid;
5402 mutex_lock(&codec->control_mutex);
5403 pval = kcontrol->private_value;
5404 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5405 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5406 kcontrol->private_value = pval;
5407 mutex_unlock(&codec->control_mutex);
5410 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5415 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
5416 struct snd_ctl_elem_value *ucontrol)
5418 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5419 struct ca0132_spec *spec = codec->spec;
5420 hda_nid_t nid = get_amp_nid(kcontrol);
5421 int ch = get_amp_channels(kcontrol);
5422 long *valp = ucontrol->value.integer.value;
5424 /* store the left and right volume */
5426 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
5430 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
5436 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
5437 struct snd_ctl_elem_value *ucontrol)
5439 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5440 struct ca0132_spec *spec = codec->spec;
5441 hda_nid_t nid = get_amp_nid(kcontrol);
5442 int ch = get_amp_channels(kcontrol);
5443 long *valp = ucontrol->value.integer.value;
5444 hda_nid_t shared_nid = 0;
5448 /* store the left and right volume */
5450 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
5454 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
5458 /* if effective conditions, then update hw immediately. */
5459 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5461 int dir = get_amp_direction(kcontrol);
5464 snd_hda_power_up(codec);
5465 mutex_lock(&codec->control_mutex);
5466 pval = kcontrol->private_value;
5467 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5469 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
5470 kcontrol->private_value = pval;
5471 mutex_unlock(&codec->control_mutex);
5472 snd_hda_power_down(codec);
5479 * This function is the same as the one above, because using an if statement
5480 * inside of the above volume control for the DSP volume would cause too much
5481 * lag. This is a lot more smooth.
5483 static int ca0132_alt_volume_put(struct snd_kcontrol *kcontrol,
5484 struct snd_ctl_elem_value *ucontrol)
5486 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5487 struct ca0132_spec *spec = codec->spec;
5488 hda_nid_t nid = get_amp_nid(kcontrol);
5489 int ch = get_amp_channels(kcontrol);
5490 long *valp = ucontrol->value.integer.value;
5503 /* store the left and right volume */
5505 spec->vnode_lvol[vnid - VNODE_START_NID] = *valp;
5509 spec->vnode_rvol[vnid - VNODE_START_NID] = *valp;
5513 snd_hda_power_up(codec);
5514 ca0132_alt_dsp_volume_put(codec, vnid);
5515 mutex_lock(&codec->control_mutex);
5516 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
5517 mutex_unlock(&codec->control_mutex);
5518 snd_hda_power_down(codec);
5523 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
5524 unsigned int size, unsigned int __user *tlv)
5526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5527 struct ca0132_spec *spec = codec->spec;
5528 hda_nid_t nid = get_amp_nid(kcontrol);
5529 int ch = get_amp_channels(kcontrol);
5530 int dir = get_amp_direction(kcontrol);
5536 /* follow shared_out tlv */
5537 nid = spec->shared_out_nid;
5538 mutex_lock(&codec->control_mutex);
5539 pval = kcontrol->private_value;
5540 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5541 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
5542 kcontrol->private_value = pval;
5543 mutex_unlock(&codec->control_mutex);
5546 /* follow shared_mic tlv */
5547 nid = spec->shared_mic_nid;
5548 mutex_lock(&codec->control_mutex);
5549 pval = kcontrol->private_value;
5550 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5551 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
5552 kcontrol->private_value = pval;
5553 mutex_unlock(&codec->control_mutex);
5556 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
5561 /* Add volume slider control for effect level */
5562 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
5563 const char *pfx, int dir)
5565 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5566 int type = dir ? HDA_INPUT : HDA_OUTPUT;
5567 struct snd_kcontrol_new knew =
5568 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
5570 sprintf(namestr, "FX: %s %s Volume", pfx, dirstr[dir]);
5576 knew.info = ca0132_alt_xbass_xover_slider_info;
5577 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
5578 knew.put = ca0132_alt_xbass_xover_slider_put;
5581 knew.info = ca0132_alt_effect_slider_info;
5582 knew.get = ca0132_alt_slider_ctl_get;
5583 knew.put = ca0132_alt_effect_slider_put;
5584 knew.private_value =
5585 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
5589 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
5593 * Added FX: prefix for the alternative codecs, because otherwise the surround
5594 * effect would conflict with the Surround sound volume control. Also seems more
5595 * clear as to what the switches do. Left alone for others.
5597 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
5598 const char *pfx, int dir)
5600 struct ca0132_spec *spec = codec->spec;
5601 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5602 int type = dir ? HDA_INPUT : HDA_OUTPUT;
5603 struct snd_kcontrol_new knew =
5604 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
5605 /* If using alt_controls, add FX: prefix. But, don't add FX:
5606 * prefix to OutFX or InFX enable controls.
5608 if ((spec->use_alt_controls) && (nid <= IN_EFFECT_END_NID))
5609 sprintf(namestr, "FX: %s %s Switch", pfx, dirstr[dir]);
5611 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
5613 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
5616 static int add_voicefx(struct hda_codec *codec)
5618 struct snd_kcontrol_new knew =
5619 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
5620 VOICEFX, 1, 0, HDA_INPUT);
5621 knew.info = ca0132_voicefx_info;
5622 knew.get = ca0132_voicefx_get;
5623 knew.put = ca0132_voicefx_put;
5624 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
5627 /* Create the EQ Preset control */
5628 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
5630 struct snd_kcontrol_new knew =
5631 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum.name,
5632 EQ_PRESET_ENUM, 1, 0, HDA_OUTPUT);
5633 knew.info = ca0132_alt_eq_preset_info;
5634 knew.get = ca0132_alt_eq_preset_get;
5635 knew.put = ca0132_alt_eq_preset_put;
5636 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
5637 snd_ctl_new1(&knew, codec));
5641 * Add enumerated control for the three different settings of the smart volume
5642 * output effect. Normal just uses the slider value, and loud and night are
5643 * their own things that ignore that value.
5645 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
5647 struct snd_kcontrol_new knew =
5648 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
5649 SMART_VOLUME_ENUM, 1, 0, HDA_OUTPUT);
5650 knew.info = ca0132_alt_svm_setting_info;
5651 knew.get = ca0132_alt_svm_setting_get;
5652 knew.put = ca0132_alt_svm_setting_put;
5653 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
5654 snd_ctl_new1(&knew, codec));
5659 * Create an Output Select enumerated control for codecs with surround
5662 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
5664 struct snd_kcontrol_new knew =
5665 HDA_CODEC_MUTE_MONO("Output Select",
5666 OUTPUT_SOURCE_ENUM, 1, 0, HDA_OUTPUT);
5667 knew.info = ca0132_alt_output_select_get_info;
5668 knew.get = ca0132_alt_output_select_get;
5669 knew.put = ca0132_alt_output_select_put;
5670 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
5671 snd_ctl_new1(&knew, codec));
5675 * Create an Input Source enumerated control for the alternate ca0132 codecs
5676 * because the front microphone has no auto-detect, and Line-in has to be set
5679 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
5681 struct snd_kcontrol_new knew =
5682 HDA_CODEC_MUTE_MONO("Input Source",
5683 INPUT_SOURCE_ENUM, 1, 0, HDA_INPUT);
5684 knew.info = ca0132_alt_input_source_info;
5685 knew.get = ca0132_alt_input_source_get;
5686 knew.put = ca0132_alt_input_source_put;
5687 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
5688 snd_ctl_new1(&knew, codec));
5692 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
5693 * more control than the original mic boost, which is either full 30dB or off.
5695 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
5697 struct snd_kcontrol_new knew =
5698 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
5699 MIC_BOOST_ENUM, 1, 0, HDA_INPUT);
5700 knew.info = ca0132_alt_mic_boost_info;
5701 knew.get = ca0132_alt_mic_boost_get;
5702 knew.put = ca0132_alt_mic_boost_put;
5703 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
5704 snd_ctl_new1(&knew, codec));
5709 * Need to create slave controls for the alternate codecs that have surround
5712 static const char * const ca0132_alt_slave_pfxs[] = {
5713 "Front", "Surround", "Center", "LFE", NULL,
5717 * Also need special channel map, because the default one is incorrect.
5718 * I think this has to do with the pin for rear surround being 0x11,
5719 * and the center/lfe being 0x10. Usually the pin order is the opposite.
5721 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps[] = {
5723 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
5725 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
5726 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
5728 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
5729 SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE,
5730 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
5734 /* Add the correct chmap for streams with 6 channels. */
5735 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
5738 struct hda_pcm *pcm;
5740 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
5741 struct hda_pcm_stream *hinfo =
5742 &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
5743 struct snd_pcm_chmap *chmap;
5744 const struct snd_pcm_chmap_elem *elem;
5746 elem = ca0132_alt_chmaps;
5747 if (hinfo->channels_max == 6) {
5748 err = snd_pcm_add_chmap_ctls(pcm->pcm,
5749 SNDRV_PCM_STREAM_PLAYBACK,
5750 elem, hinfo->channels_max, 0, &chmap);
5752 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
5758 * When changing Node IDs for Mixer Controls below, make sure to update
5759 * Node IDs in ca0132_config() as well.
5761 static const struct snd_kcontrol_new ca0132_mixer[] = {
5762 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
5763 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
5764 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
5765 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
5766 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
5767 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
5768 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
5769 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
5770 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
5771 0x12, 1, HDA_INPUT),
5772 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
5773 VNID_HP_SEL, 1, HDA_OUTPUT),
5774 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
5775 VNID_AMIC1_SEL, 1, HDA_INPUT),
5776 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
5777 VNID_HP_ASEL, 1, HDA_OUTPUT),
5778 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
5779 VNID_AMIC1_ASEL, 1, HDA_INPUT),
5784 * Desktop specific control mixer. Removes auto-detect for mic, and adds
5785 * surround controls. Also sets both the Front Playback and Capture Volume
5786 * controls to alt so they set the DSP's decibel level.
5788 static const struct snd_kcontrol_new desktop_mixer[] = {
5789 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
5790 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
5791 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
5792 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
5793 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
5794 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
5795 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
5796 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
5797 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT),
5798 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
5799 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
5800 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
5801 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
5802 VNID_HP_ASEL, 1, HDA_OUTPUT),
5807 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
5808 * because it doesn't set decibel levels for the DSP for capture.
5810 static const struct snd_kcontrol_new r3di_mixer[] = {
5811 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
5812 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
5813 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
5814 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
5815 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
5816 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
5817 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
5818 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
5819 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
5820 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
5821 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
5822 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
5823 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
5824 VNID_HP_ASEL, 1, HDA_OUTPUT),
5828 static int ca0132_build_controls(struct hda_codec *codec)
5830 struct ca0132_spec *spec = codec->spec;
5831 int i, num_fx, num_sliders;
5834 /* Add Mixer controls */
5835 for (i = 0; i < spec->num_mixers; i++) {
5836 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
5840 /* Setup vmaster with surround slaves for desktop ca0132 devices */
5841 if (spec->use_alt_functions) {
5842 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
5844 snd_hda_add_vmaster(codec, "Master Playback Volume",
5845 spec->tlv, ca0132_alt_slave_pfxs,
5847 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
5848 NULL, ca0132_alt_slave_pfxs,
5850 true, &spec->vmaster_mute.sw_kctl);
5854 /* Add in and out effects controls.
5855 * VoiceFX, PE and CrystalVoice are added separately.
5857 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
5858 for (i = 0; i < num_fx; i++) {
5859 /* Desktop cards break if Echo Cancellation is used. */
5860 if (spec->use_pci_mmio) {
5861 if (i == (ECHO_CANCELLATION - IN_EFFECT_START_NID +
5866 err = add_fx_switch(codec, ca0132_effects[i].nid,
5867 ca0132_effects[i].name,
5868 ca0132_effects[i].direct);
5873 * If codec has use_alt_controls set to true, add effect level sliders,
5874 * EQ presets, and Smart Volume presets. Also, change names to add FX
5875 * prefix, and change PlayEnhancement and CrystalVoice to match.
5877 if (spec->use_alt_controls) {
5878 ca0132_alt_add_svm_enum(codec);
5879 add_ca0132_alt_eq_presets(codec);
5880 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
5885 err = add_fx_switch(codec, CRYSTAL_VOICE,
5890 num_sliders = OUT_EFFECTS_COUNT - 1;
5891 for (i = 0; i < num_sliders; i++) {
5892 err = ca0132_alt_add_effect_slider(codec,
5893 ca0132_effects[i].nid,
5894 ca0132_effects[i].name,
5895 ca0132_effects[i].direct);
5900 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
5901 "X-Bass Crossover", EFX_DIR_OUT);
5906 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
5907 "PlayEnhancement", 0);
5911 err = add_fx_switch(codec, CRYSTAL_VOICE,
5919 * If the codec uses alt_functions, you need the enumerated controls
5920 * to select the new outputs and inputs, plus add the new mic boost
5923 if (spec->use_alt_functions) {
5924 ca0132_alt_add_output_enum(codec);
5925 ca0132_alt_add_input_enum(codec);
5926 ca0132_alt_add_mic_boost_enum(codec);
5928 #ifdef ENABLE_TUNING_CONTROLS
5929 add_tuning_ctls(codec);
5932 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
5936 if (spec->dig_out) {
5937 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
5941 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
5944 /* spec->multiout.share_spdif = 1; */
5948 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
5953 if (spec->use_alt_functions)
5954 ca0132_alt_add_chmap_ctls(codec);
5962 static const struct hda_pcm_stream ca0132_pcm_analog_playback = {
5967 .prepare = ca0132_playback_pcm_prepare,
5968 .cleanup = ca0132_playback_pcm_cleanup,
5969 .get_delay = ca0132_playback_pcm_delay,
5973 static const struct hda_pcm_stream ca0132_pcm_analog_capture = {
5978 .prepare = ca0132_capture_pcm_prepare,
5979 .cleanup = ca0132_capture_pcm_cleanup,
5980 .get_delay = ca0132_capture_pcm_delay,
5984 static const struct hda_pcm_stream ca0132_pcm_digital_playback = {
5989 .open = ca0132_dig_playback_pcm_open,
5990 .close = ca0132_dig_playback_pcm_close,
5991 .prepare = ca0132_dig_playback_pcm_prepare,
5992 .cleanup = ca0132_dig_playback_pcm_cleanup
5996 static const struct hda_pcm_stream ca0132_pcm_digital_capture = {
6002 static int ca0132_build_pcms(struct hda_codec *codec)
6004 struct ca0132_spec *spec = codec->spec;
6005 struct hda_pcm *info;
6007 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
6010 if (spec->use_alt_functions) {
6011 info->own_chmap = true;
6012 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap
6013 = ca0132_alt_chmaps;
6015 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
6016 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
6017 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
6018 spec->multiout.max_channels;
6019 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6020 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6021 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
6023 /* With the DSP enabled, desktops don't use this ADC. */
6024 if (!spec->use_alt_functions) {
6025 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
6028 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6029 ca0132_pcm_analog_capture;
6030 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6031 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
6034 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
6037 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6038 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6039 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
6041 if (!spec->dig_out && !spec->dig_in)
6044 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
6047 info->pcm_type = HDA_PCM_TYPE_SPDIF;
6048 if (spec->dig_out) {
6049 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
6050 ca0132_pcm_digital_playback;
6051 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
6054 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6055 ca0132_pcm_digital_capture;
6056 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
6062 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
6065 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
6066 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
6067 snd_hda_codec_write(codec, pin, 0,
6068 AC_VERB_SET_AMP_GAIN_MUTE,
6071 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
6072 snd_hda_codec_write(codec, dac, 0,
6073 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
6076 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
6079 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
6080 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
6081 snd_hda_codec_write(codec, pin, 0,
6082 AC_VERB_SET_AMP_GAIN_MUTE,
6085 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
6086 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6089 /* init to 0 dB and unmute. */
6090 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6091 HDA_AMP_VOLMASK, 0x5a);
6092 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6097 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
6101 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
6102 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
6103 snd_hda_override_amp_caps(codec, nid, dir, caps);
6107 * Switch between Digital built-in mic and analog mic.
6109 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
6111 struct ca0132_spec *spec = codec->spec;
6114 unsigned int oldval;
6116 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
6118 oldval = stop_mic1(codec);
6119 ca0132_set_vipsource(codec, 0);
6121 /* set DMic input as 2-ch */
6123 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6125 val = spec->dmic_ctl;
6127 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6128 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6130 if (!(spec->dmic_ctl & 0x20))
6131 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
6133 /* set AMic input as mono */
6135 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6137 val = spec->dmic_ctl;
6138 /* clear bit7 and bit5 to disable dmic */
6140 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6141 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6143 if (!(spec->dmic_ctl & 0x20))
6144 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
6146 ca0132_set_vipsource(codec, 1);
6147 resume_mic1(codec, oldval);
6151 * Initialization for Digital Mic.
6153 static void ca0132_init_dmic(struct hda_codec *codec)
6155 struct ca0132_spec *spec = codec->spec;
6158 /* Setup Digital Mic here, but don't enable.
6159 * Enable based on jack detect.
6162 /* MCLK uses MPIO1, set to enable.
6163 * Bit 2-0: MPIO select
6164 * Bit 3: set to disable
6168 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6169 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
6171 /* Data1 uses MPIO3. Data2 not use
6172 * Bit 2-0: Data1 MPIO select
6173 * Bit 3: set disable Data1
6174 * Bit 6-4: Data2 MPIO select
6175 * Bit 7: set disable Data2
6178 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6179 VENDOR_CHIPIO_DMIC_PIN_SET, val);
6181 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
6182 * Bit 3-0: Channel mask
6183 * Bit 4: set for 48KHz, clear for 32KHz
6185 * Bit 6: set to select Data2, clear for Data1
6186 * Bit 7: set to enable DMic, clear for AMic
6188 if (spec->quirk == QUIRK_ALIENWARE_M17XR4)
6192 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
6193 spec->dmic_ctl = val;
6194 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6195 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6199 * Initialization for Analog Mic 2
6201 static void ca0132_init_analog_mic2(struct hda_codec *codec)
6203 struct ca0132_spec *spec = codec->spec;
6205 mutex_lock(&spec->chipio_mutex);
6206 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6207 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
6208 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6209 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6210 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6211 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6212 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6213 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
6214 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6215 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6216 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6217 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6218 mutex_unlock(&spec->chipio_mutex);
6221 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
6223 struct ca0132_spec *spec = codec->spec;
6226 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
6227 snd_hda_codec_update_widgets(codec);
6229 for (i = 0; i < spec->multiout.num_dacs; i++)
6230 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
6232 for (i = 0; i < spec->num_outputs; i++)
6233 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
6235 for (i = 0; i < spec->num_inputs; i++) {
6236 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
6237 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
6242 * Recon3D r3d_setup_defaults sub functions.
6245 static void r3d_dsp_scp_startup(struct hda_codec *codec)
6250 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
6253 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
6256 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
6259 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
6262 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
6266 static void r3d_dsp_initial_mic_setup(struct hda_codec *codec)
6271 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
6272 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
6273 /* This ConnPointID is unique to Recon3Di. Haven't seen it elsewhere */
6274 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6276 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6278 /* Mic 2 Setup, even though it isn't connected on SBZ */
6279 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
6280 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
6281 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6283 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
6287 * Initialize Sound Blaster Z analog microphones.
6289 static void sbz_init_analog_mics(struct hda_codec *codec)
6294 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
6295 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
6297 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6299 /* Mic 2 Setup, even though it isn't connected on SBZ */
6300 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
6301 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
6303 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
6308 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
6309 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
6310 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
6311 * having an updated DAC, which changes the destination to that DAC.
6313 static void sbz_connect_streams(struct hda_codec *codec)
6315 struct ca0132_spec *spec = codec->spec;
6317 mutex_lock(&spec->chipio_mutex);
6319 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
6321 chipio_set_stream_channels(codec, 0x0C, 6);
6322 chipio_set_stream_control(codec, 0x0C, 1);
6324 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
6325 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
6327 /* Setup stream 0x14 with it's source and destination points */
6328 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
6329 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
6330 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
6331 chipio_set_stream_channels(codec, 0x14, 2);
6332 chipio_set_stream_control(codec, 0x14, 1);
6334 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
6336 mutex_unlock(&spec->chipio_mutex);
6341 * Write data through ChipIO to setup proper stream destinations.
6342 * Not sure how it exactly works, but it seems to direct data
6343 * to different destinations. Example is f8 to c0, e0 to c0.
6344 * All I know is, if you don't set these, you get no sound.
6346 static void sbz_chipio_startup_data(struct hda_codec *codec)
6348 struct ca0132_spec *spec = codec->spec;
6350 mutex_lock(&spec->chipio_mutex);
6351 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
6353 /* These control audio output */
6354 chipio_write_no_mutex(codec, 0x190060, 0x0001f8c0);
6355 chipio_write_no_mutex(codec, 0x190064, 0x0001f9c1);
6356 chipio_write_no_mutex(codec, 0x190068, 0x0001fac6);
6357 chipio_write_no_mutex(codec, 0x19006c, 0x0001fbc7);
6358 /* Signal to update I think */
6359 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
6361 chipio_set_stream_channels(codec, 0x0C, 6);
6362 chipio_set_stream_control(codec, 0x0C, 1);
6363 /* No clue what these control */
6364 chipio_write_no_mutex(codec, 0x190030, 0x0001e0c0);
6365 chipio_write_no_mutex(codec, 0x190034, 0x0001e1c1);
6366 chipio_write_no_mutex(codec, 0x190038, 0x0001e4c2);
6367 chipio_write_no_mutex(codec, 0x19003c, 0x0001e5c3);
6368 chipio_write_no_mutex(codec, 0x190040, 0x0001e2c4);
6369 chipio_write_no_mutex(codec, 0x190044, 0x0001e3c5);
6370 chipio_write_no_mutex(codec, 0x190048, 0x0001e8c6);
6371 chipio_write_no_mutex(codec, 0x19004c, 0x0001e9c7);
6372 chipio_write_no_mutex(codec, 0x190050, 0x0001ecc8);
6373 chipio_write_no_mutex(codec, 0x190054, 0x0001edc9);
6374 chipio_write_no_mutex(codec, 0x190058, 0x0001eaca);
6375 chipio_write_no_mutex(codec, 0x19005c, 0x0001ebcb);
6377 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
6379 codec_dbg(codec, "Startup Data exited, mutex released.\n");
6380 mutex_unlock(&spec->chipio_mutex);
6384 * Sound Blaster Z uses these after DSP is loaded. Weird SCP commands
6385 * without a 0x20 source like normal.
6387 static void sbz_dsp_scp_startup(struct hda_codec *codec)
6392 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
6395 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
6398 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
6401 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
6404 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
6407 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
6411 static void sbz_dsp_initial_mic_setup(struct hda_codec *codec)
6415 chipio_set_stream_control(codec, 0x03, 0);
6416 chipio_set_stream_control(codec, 0x04, 0);
6418 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
6419 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
6422 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6424 chipio_set_stream_control(codec, 0x03, 1);
6425 chipio_set_stream_control(codec, 0x04, 1);
6427 chipio_write(codec, 0x18b098, 0x0000000c);
6428 chipio_write(codec, 0x18b09C, 0x0000000c);
6432 * Setup default parameters for DSP
6434 static void ca0132_setup_defaults(struct hda_codec *codec)
6436 struct ca0132_spec *spec = codec->spec;
6441 if (spec->dsp_state != DSP_DOWNLOADED)
6444 /* out, in effects + voicefx */
6445 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
6446 for (idx = 0; idx < num_fx; idx++) {
6447 for (i = 0; i <= ca0132_effects[idx].params; i++) {
6448 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
6449 ca0132_effects[idx].reqs[i],
6450 ca0132_effects[idx].def_vals[i]);
6454 /*remove DSP headroom*/
6456 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
6458 /*set speaker EQ bypass attenuation*/
6459 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
6461 /* set AMic1 and AMic2 as mono mic */
6463 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6464 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
6466 /* set AMic1 as CrystalVoice input */
6468 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
6470 /* set WUH source */
6472 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
6476 * Setup default parameters for Recon3D/Recon3Di DSP.
6479 static void r3d_setup_defaults(struct hda_codec *codec)
6481 struct ca0132_spec *spec = codec->spec;
6486 if (spec->dsp_state != DSP_DOWNLOADED)
6489 r3d_dsp_scp_startup(codec);
6491 r3d_dsp_initial_mic_setup(codec);
6493 /*remove DSP headroom*/
6495 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
6497 /* set WUH source */
6499 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
6500 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
6502 /* Set speaker source? */
6503 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
6505 if (spec->quirk == QUIRK_R3DI)
6506 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
6508 /* Setup effect defaults */
6509 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
6510 for (idx = 0; idx < num_fx; idx++) {
6511 for (i = 0; i <= ca0132_effects[idx].params; i++) {
6512 dspio_set_uint_param(codec,
6513 ca0132_effects[idx].mid,
6514 ca0132_effects[idx].reqs[i],
6515 ca0132_effects[idx].def_vals[i]);
6521 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
6522 * than the Chromebook setup.
6524 static void sbz_setup_defaults(struct hda_codec *codec)
6526 struct ca0132_spec *spec = codec->spec;
6527 unsigned int tmp, stream_format;
6531 if (spec->dsp_state != DSP_DOWNLOADED)
6534 sbz_dsp_scp_startup(codec);
6536 sbz_init_analog_mics(codec);
6538 sbz_connect_streams(codec);
6540 sbz_chipio_startup_data(codec);
6542 chipio_set_stream_control(codec, 0x03, 1);
6543 chipio_set_stream_control(codec, 0x04, 1);
6546 * Sets internal input loopback to off, used to have a switch to
6547 * enable input loopback, but turned out to be way too buggy.
6550 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
6551 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
6553 /*remove DSP headroom*/
6555 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
6557 /* set WUH source */
6559 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
6560 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
6562 /* Set speaker source? */
6563 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
6565 sbz_dsp_initial_mic_setup(codec);
6568 /* out, in effects + voicefx */
6569 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
6570 for (idx = 0; idx < num_fx; idx++) {
6571 for (i = 0; i <= ca0132_effects[idx].params; i++) {
6572 dspio_set_uint_param(codec,
6573 ca0132_effects[idx].mid,
6574 ca0132_effects[idx].reqs[i],
6575 ca0132_effects[idx].def_vals[i]);
6580 * Have to make a stream to bind the sound output to, otherwise
6581 * you'll get dead audio. Before I did this, it would bind to an
6582 * audio input, and would never work
6584 stream_format = snd_hdac_calc_stream_format(48000, 2,
6585 SNDRV_PCM_FORMAT_S32_LE, 32, 0);
6587 snd_hda_codec_setup_stream(codec, spec->dacs[0], spec->dsp_stream_id,
6590 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
6592 snd_hda_codec_setup_stream(codec, spec->dacs[0], spec->dsp_stream_id,
6595 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
6599 * Initialization of flags in chip
6601 static void ca0132_init_flags(struct hda_codec *codec)
6603 struct ca0132_spec *spec = codec->spec;
6605 if (spec->use_alt_functions) {
6606 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
6607 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
6608 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
6609 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
6610 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
6611 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
6612 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
6613 chipio_set_control_flag(codec,
6614 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
6615 chipio_set_control_flag(codec,
6616 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 1);
6618 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
6619 chipio_set_control_flag(codec,
6620 CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
6621 chipio_set_control_flag(codec,
6622 CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
6623 chipio_set_control_flag(codec,
6624 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
6625 chipio_set_control_flag(codec,
6626 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
6627 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
6632 * Initialization of parameters in chip
6634 static void ca0132_init_params(struct hda_codec *codec)
6636 struct ca0132_spec *spec = codec->spec;
6638 if (spec->use_alt_functions) {
6639 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
6640 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
6641 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
6642 chipio_set_control_param(codec, 0, 0);
6643 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
6646 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
6647 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
6650 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
6652 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
6653 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
6654 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
6655 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
6656 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
6657 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
6659 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
6660 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
6661 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
6664 static bool ca0132_download_dsp_images(struct hda_codec *codec)
6666 bool dsp_loaded = false;
6667 struct ca0132_spec *spec = codec->spec;
6668 const struct dsp_image_seg *dsp_os_image;
6669 const struct firmware *fw_entry;
6671 * Alternate firmwares for different variants. The Recon3Di apparently
6672 * can use the default firmware, but I'll leave the option in case
6673 * it needs it again.
6675 switch (spec->quirk) {
6677 if (reject_firmware(&fw_entry, SBZ_EFX_FILE,
6678 codec->card->dev) != 0) {
6679 codec_dbg(codec, "SBZ alt firmware not detected. ");
6680 spec->alt_firmware_present = false;
6682 codec_dbg(codec, "Sound Blaster Z firmware selected.");
6683 spec->alt_firmware_present = true;
6687 if (reject_firmware(&fw_entry, R3DI_EFX_FILE,
6688 codec->card->dev) != 0) {
6689 codec_dbg(codec, "Recon3Di alt firmware not detected.");
6690 spec->alt_firmware_present = false;
6692 codec_dbg(codec, "Recon3Di firmware selected.");
6693 spec->alt_firmware_present = true;
6697 spec->alt_firmware_present = false;
6701 if (!spec->alt_firmware_present) {
6702 codec_dbg(codec, "Default firmware selected.");
6703 if (reject_firmware(&fw_entry, EFX_FILE,
6704 codec->card->dev) != 0)
6708 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
6709 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
6710 codec_err(codec, "ca0132 DSP load image failed\n");
6714 dsp_loaded = dspload_wait_loaded(codec);
6717 release_firmware(fw_entry);
6722 static void ca0132_download_dsp(struct hda_codec *codec)
6724 struct ca0132_spec *spec = codec->spec;
6726 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
6730 if (spec->dsp_state == DSP_DOWNLOAD_FAILED)
6731 return; /* don't retry failures */
6733 chipio_enable_clocks(codec);
6734 if (spec->dsp_state != DSP_DOWNLOADED) {
6735 spec->dsp_state = DSP_DOWNLOADING;
6737 if (!ca0132_download_dsp_images(codec))
6738 spec->dsp_state = DSP_DOWNLOAD_FAILED;
6740 spec->dsp_state = DSP_DOWNLOADED;
6743 /* For codecs using alt functions, this is already done earlier */
6744 if (spec->dsp_state == DSP_DOWNLOADED && (!spec->use_alt_functions))
6745 ca0132_set_dsp_msr(codec, true);
6748 static void ca0132_process_dsp_response(struct hda_codec *codec,
6749 struct hda_jack_callback *callback)
6751 struct ca0132_spec *spec = codec->spec;
6753 codec_dbg(codec, "ca0132_process_dsp_response\n");
6754 snd_hda_power_up_pm(codec);
6755 if (spec->wait_scp) {
6756 if (dspio_get_response_data(codec) >= 0)
6760 dspio_clear_response_queue(codec);
6761 snd_hda_power_down_pm(codec);
6764 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
6766 struct ca0132_spec *spec = codec->spec;
6767 struct hda_jack_tbl *tbl;
6769 /* Delay enabling the HP amp, to let the mic-detection
6770 * state machine run.
6772 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
6774 tbl->block_report = 1;
6775 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
6778 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
6780 struct ca0132_spec *spec = codec->spec;
6782 if (spec->use_alt_functions)
6783 ca0132_alt_select_in(codec);
6785 ca0132_select_mic(codec);
6788 static void ca0132_init_unsol(struct hda_codec *codec)
6790 struct ca0132_spec *spec = codec->spec;
6791 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
6792 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
6794 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
6795 ca0132_process_dsp_response);
6796 /* Front headphone jack detection */
6797 if (spec->use_alt_functions)
6798 snd_hda_jack_detect_enable_callback(codec,
6799 spec->unsol_tag_front_hp, hp_callback);
6806 /* Sends before DSP download. */
6807 static struct hda_verb ca0132_base_init_verbs[] = {
6808 /*enable ct extension*/
6809 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
6814 static struct hda_verb ca0132_base_exit_verbs[] = {
6816 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
6817 /*disable ct extension*/
6818 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
6822 /* Other verbs tables. Sends after DSP download. */
6824 static struct hda_verb ca0132_init_verbs0[] = {
6825 /* chip init verbs */
6826 {0x15, 0x70D, 0xF0},
6827 {0x15, 0x70E, 0xFE},
6828 {0x15, 0x707, 0x75},
6829 {0x15, 0x707, 0xD3},
6830 {0x15, 0x707, 0x09},
6831 {0x15, 0x707, 0x53},
6832 {0x15, 0x707, 0xD4},
6833 {0x15, 0x707, 0xEF},
6834 {0x15, 0x707, 0x75},
6835 {0x15, 0x707, 0xD3},
6836 {0x15, 0x707, 0x09},
6837 {0x15, 0x707, 0x02},
6838 {0x15, 0x707, 0x37},
6839 {0x15, 0x707, 0x78},
6840 {0x15, 0x53C, 0xCE},
6841 {0x15, 0x575, 0xC9},
6842 {0x15, 0x53D, 0xCE},
6843 {0x15, 0x5B7, 0xC9},
6844 {0x15, 0x70D, 0xE8},
6845 {0x15, 0x70E, 0xFE},
6846 {0x15, 0x707, 0x02},
6847 {0x15, 0x707, 0x68},
6848 {0x15, 0x707, 0x62},
6849 {0x15, 0x53A, 0xCE},
6850 {0x15, 0x546, 0xC9},
6851 {0x15, 0x53B, 0xCE},
6852 {0x15, 0x5E8, 0xC9},
6856 /* Extra init verbs for desktop cards. */
6857 static struct hda_verb ca0132_init_verbs1[] = {
6858 {0x15, 0x70D, 0x20},
6859 {0x15, 0x70E, 0x19},
6860 {0x15, 0x707, 0x00},
6861 {0x15, 0x539, 0xCE},
6862 {0x15, 0x546, 0xC9},
6863 {0x15, 0x70D, 0xB7},
6864 {0x15, 0x70E, 0x09},
6865 {0x15, 0x707, 0x10},
6866 {0x15, 0x70D, 0xAF},
6867 {0x15, 0x70E, 0x09},
6868 {0x15, 0x707, 0x01},
6869 {0x15, 0x707, 0x05},
6870 {0x15, 0x70D, 0x73},
6871 {0x15, 0x70E, 0x09},
6872 {0x15, 0x707, 0x14},
6873 {0x15, 0x6FF, 0xC4},
6877 static void ca0132_init_chip(struct hda_codec *codec)
6879 struct ca0132_spec *spec = codec->spec;
6884 mutex_init(&spec->chipio_mutex);
6886 spec->cur_out_type = SPEAKER_OUT;
6887 if (!spec->use_alt_functions)
6888 spec->cur_mic_type = DIGITAL_MIC;
6890 spec->cur_mic_type = REAR_MIC;
6892 spec->cur_mic_boost = 0;
6894 for (i = 0; i < VNODES_COUNT; i++) {
6895 spec->vnode_lvol[i] = 0x5a;
6896 spec->vnode_rvol[i] = 0x5a;
6897 spec->vnode_lswitch[i] = 0;
6898 spec->vnode_rswitch[i] = 0;
6902 * Default states for effects are in ca0132_effects[].
6904 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
6905 for (i = 0; i < num_fx; i++) {
6906 on = (unsigned int)ca0132_effects[i].reqs[0];
6907 spec->effects_switch[i] = on ? 1 : 0;
6910 * Sets defaults for the effect slider controls, only for alternative
6911 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
6913 if (spec->use_alt_controls) {
6914 spec->xbass_xover_freq = 8;
6915 for (i = 0; i < EFFECT_LEVEL_SLIDERS; i++)
6916 spec->fx_ctl_val[i] = effect_slider_defaults[i];
6919 spec->voicefx_val = 0;
6920 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
6921 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
6923 #ifdef ENABLE_TUNING_CONTROLS
6924 ca0132_init_tuning_defaults(codec);
6929 * Recon3Di exit specific commands.
6931 /* prevents popping noise on shutdown */
6932 static void r3di_gpio_shutdown(struct hda_codec *codec)
6934 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
6938 * Sound Blaster Z exit specific commands.
6940 static void sbz_region2_exit(struct hda_codec *codec)
6942 struct ca0132_spec *spec = codec->spec;
6945 for (i = 0; i < 4; i++)
6946 writeb(0x0, spec->mem_base + 0x100);
6947 for (i = 0; i < 8; i++)
6948 writeb(0xb3, spec->mem_base + 0x304);
6950 ca0132_mmio_gpio_set(codec, 0, false);
6951 ca0132_mmio_gpio_set(codec, 1, false);
6952 ca0132_mmio_gpio_set(codec, 4, true);
6953 ca0132_mmio_gpio_set(codec, 5, false);
6954 ca0132_mmio_gpio_set(codec, 7, false);
6957 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
6959 hda_nid_t pins[5] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
6962 snd_hda_codec_write(codec, 0x11, 0,
6963 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40);
6965 for (i = 0; i < 5; i++)
6966 snd_hda_codec_write(codec, pins[i], 0,
6967 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00);
6970 static void ca0132_clear_unsolicited(struct hda_codec *codec)
6972 hda_nid_t pins[7] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
6975 for (i = 0; i < 7; i++) {
6976 snd_hda_codec_write(codec, pins[i], 0,
6977 AC_VERB_SET_UNSOLICITED_ENABLE, 0x00);
6981 /* On shutdown, sends commands in sets of three */
6982 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
6986 snd_hda_codec_write(codec, 0x01, 0,
6987 AC_VERB_SET_GPIO_DIRECTION, dir);
6989 snd_hda_codec_write(codec, 0x01, 0,
6990 AC_VERB_SET_GPIO_MASK, mask);
6993 snd_hda_codec_write(codec, 0x01, 0,
6994 AC_VERB_SET_GPIO_DATA, data);
6997 static void sbz_exit_chip(struct hda_codec *codec)
6999 chipio_set_stream_control(codec, 0x03, 0);
7000 chipio_set_stream_control(codec, 0x04, 0);
7002 /* Mess with GPIO */
7003 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
7004 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
7005 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
7007 chipio_set_stream_control(codec, 0x14, 0);
7008 chipio_set_stream_control(codec, 0x0C, 0);
7010 chipio_set_conn_rate(codec, 0x41, SR_192_000);
7011 chipio_set_conn_rate(codec, 0x91, SR_192_000);
7013 chipio_write(codec, 0x18a020, 0x00000083);
7015 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
7016 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
7017 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
7019 chipio_set_stream_control(codec, 0x0C, 0);
7021 chipio_set_control_param(codec, 0x0D, 0x24);
7023 ca0132_clear_unsolicited(codec);
7024 sbz_set_pin_ctl_default(codec);
7026 snd_hda_codec_write(codec, 0x0B, 0,
7027 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
7029 sbz_region2_exit(codec);
7032 static void r3d_exit_chip(struct hda_codec *codec)
7034 ca0132_clear_unsolicited(codec);
7035 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7036 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
7039 static void ca0132_exit_chip(struct hda_codec *codec)
7041 /* put any chip cleanup stuffs here. */
7043 if (dspload_is_loaded(codec))
7048 * This fixes a problem that was hard to reproduce. Very rarely, I would
7049 * boot up, and there would be no sound, but the DSP indicated it had loaded
7050 * properly. I did a few memory dumps to see if anything was different, and
7051 * there were a few areas of memory uninitialized with a1a2a3a4. This function
7052 * checks if those areas are uninitialized, and if they are, it'll attempt to
7053 * reload the card 3 times. Usually it fixes by the second.
7055 static void sbz_dsp_startup_check(struct hda_codec *codec)
7057 struct ca0132_spec *spec = codec->spec;
7058 unsigned int dsp_data_check[4];
7059 unsigned int cur_address = 0x390;
7061 unsigned int failure = 0;
7062 unsigned int reload = 3;
7064 if (spec->startup_check_entered)
7067 spec->startup_check_entered = true;
7069 for (i = 0; i < 4; i++) {
7070 chipio_read(codec, cur_address, &dsp_data_check[i]);
7073 for (i = 0; i < 4; i++) {
7074 if (dsp_data_check[i] == 0xa1a2a3a4)
7078 codec_dbg(codec, "Startup Check: %d ", failure);
7080 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
7082 * While the failure condition is true, and we haven't reached our
7083 * three reload limit, continue trying to reload the driver and
7086 while (failure && (reload != 0)) {
7087 codec_info(codec, "Reloading... Tries left: %d", reload);
7088 sbz_exit_chip(codec);
7089 spec->dsp_state = DSP_DOWNLOAD_INIT;
7090 codec->patch_ops.init(codec);
7092 for (i = 0; i < 4; i++) {
7093 chipio_read(codec, cur_address, &dsp_data_check[i]);
7096 for (i = 0; i < 4; i++) {
7097 if (dsp_data_check[i] == 0xa1a2a3a4)
7103 if (!failure && reload < 3)
7104 codec_info(codec, "DSP fixed.");
7109 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
7113 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
7114 * extra precision for decibel values. If you had the dB value in floating point
7115 * you would take the value after the decimal point, multiply by 64, and divide
7116 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
7117 * implement fixed point or floating point dB volumes. For now, I'll set them
7118 * to 0 just incase a value has lingered from a boot into Windows.
7120 static void ca0132_alt_vol_setup(struct hda_codec *codec)
7122 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
7123 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
7124 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
7125 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
7126 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
7127 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
7128 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
7129 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
7133 * Extra commands that don't really fit anywhere else.
7135 static void sbz_pre_dsp_setup(struct hda_codec *codec)
7137 struct ca0132_spec *spec = codec->spec;
7139 writel(0x00820680, spec->mem_base + 0x01C);
7140 writel(0x00820680, spec->mem_base + 0x01C);
7142 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xfc);
7143 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xfd);
7144 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xfe);
7145 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xff);
7147 chipio_write(codec, 0x18b0a4, 0x000000c2);
7149 snd_hda_codec_write(codec, 0x11, 0,
7150 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
7153 static void r3d_pre_dsp_setup(struct hda_codec *codec)
7156 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xfc);
7157 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xfd);
7158 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xfe);
7159 snd_hda_codec_write(codec, 0x15, 0, 0xd00, 0xff);
7161 chipio_write(codec, 0x18b0a4, 0x000000c2);
7163 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7164 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
7165 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7166 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
7167 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7168 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
7170 snd_hda_codec_write(codec, 0x11, 0,
7171 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
7174 static void r3di_pre_dsp_setup(struct hda_codec *codec)
7176 chipio_write(codec, 0x18b0a4, 0x000000c2);
7178 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7179 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
7180 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7181 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
7182 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7183 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
7185 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7186 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
7187 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7188 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
7189 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7190 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
7191 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7192 VENDOR_CHIPIO_8051_DATA_WRITE, 0x40);
7194 snd_hda_codec_write(codec, 0x11, 0,
7195 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
7199 * These are sent before the DSP is downloaded. Not sure
7200 * what they do, or if they're necessary. Could possibly
7201 * be removed. Figure they're better to leave in.
7203 static void ca0132_mmio_init(struct hda_codec *codec)
7205 struct ca0132_spec *spec = codec->spec;
7207 writel(0x00000000, spec->mem_base + 0x400);
7208 writel(0x00000000, spec->mem_base + 0x408);
7209 writel(0x00000000, spec->mem_base + 0x40C);
7210 writel(0x00880680, spec->mem_base + 0x01C);
7211 writel(0x00000083, spec->mem_base + 0xC0C);
7212 writel(0x00000030, spec->mem_base + 0xC00);
7213 writel(0x00000000, spec->mem_base + 0xC04);
7214 writel(0x00000003, spec->mem_base + 0xC0C);
7215 writel(0x00000003, spec->mem_base + 0xC0C);
7216 writel(0x00000003, spec->mem_base + 0xC0C);
7217 writel(0x00000003, spec->mem_base + 0xC0C);
7218 writel(0x000000C1, spec->mem_base + 0xC08);
7219 writel(0x000000F1, spec->mem_base + 0xC08);
7220 writel(0x00000001, spec->mem_base + 0xC08);
7221 writel(0x000000C7, spec->mem_base + 0xC08);
7222 writel(0x000000C1, spec->mem_base + 0xC08);
7223 writel(0x00000080, spec->mem_base + 0xC04);
7227 * Extra init functions for alternative ca0132 codecs. Done
7228 * here so they don't clutter up the main ca0132_init function
7229 * anymore than they have to.
7231 static void ca0132_alt_init(struct hda_codec *codec)
7233 struct ca0132_spec *spec = codec->spec;
7235 ca0132_alt_vol_setup(codec);
7237 switch (spec->quirk) {
7239 codec_dbg(codec, "SBZ alt_init");
7240 ca0132_gpio_init(codec);
7241 sbz_pre_dsp_setup(codec);
7242 snd_hda_sequence_write(codec, spec->chip_init_verbs);
7243 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
7246 codec_dbg(codec, "R3DI alt_init");
7247 ca0132_gpio_init(codec);
7248 ca0132_gpio_setup(codec);
7249 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
7250 r3di_pre_dsp_setup(codec);
7251 snd_hda_sequence_write(codec, spec->chip_init_verbs);
7252 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
7255 r3d_pre_dsp_setup(codec);
7256 snd_hda_sequence_write(codec, spec->chip_init_verbs);
7257 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
7262 static int ca0132_init(struct hda_codec *codec)
7264 struct ca0132_spec *spec = codec->spec;
7265 struct auto_pin_cfg *cfg = &spec->autocfg;
7270 * If the DSP is already downloaded, and init has been entered again,
7271 * there's only two reasons for it. One, the codec has awaken from a
7272 * suspended state, and in that case dspload_is_loaded will return
7273 * false, and the init will be ran again. The other reason it gets
7274 * re entered is on startup for some reason it triggers a suspend and
7275 * resume state. In this case, it will check if the DSP is downloaded,
7276 * and not run the init function again. For codecs using alt_functions,
7277 * it will check if the DSP is loaded properly.
7279 if (spec->dsp_state == DSP_DOWNLOADED) {
7280 dsp_loaded = dspload_is_loaded(codec);
7282 spec->dsp_reload = true;
7283 spec->dsp_state = DSP_DOWNLOAD_INIT;
7285 if (spec->quirk == QUIRK_SBZ)
7286 sbz_dsp_startup_check(codec);
7291 if (spec->dsp_state != DSP_DOWNLOAD_FAILED)
7292 spec->dsp_state = DSP_DOWNLOAD_INIT;
7293 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
7295 if (spec->use_pci_mmio)
7296 ca0132_mmio_init(codec);
7298 snd_hda_power_up_pm(codec);
7300 ca0132_init_unsol(codec);
7301 ca0132_init_params(codec);
7302 ca0132_init_flags(codec);
7304 snd_hda_sequence_write(codec, spec->base_init_verbs);
7306 if (spec->use_alt_functions)
7307 ca0132_alt_init(codec);
7309 ca0132_download_dsp(codec);
7311 ca0132_refresh_widget_caps(codec);
7313 switch (spec->quirk) {
7316 r3d_setup_defaults(codec);
7319 sbz_setup_defaults(codec);
7322 ca0132_setup_defaults(codec);
7323 ca0132_init_analog_mic2(codec);
7324 ca0132_init_dmic(codec);
7328 for (i = 0; i < spec->num_outputs; i++)
7329 init_output(codec, spec->out_pins[i], spec->dacs[0]);
7331 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
7333 for (i = 0; i < spec->num_inputs; i++)
7334 init_input(codec, spec->input_pins[i], spec->adcs[i]);
7336 init_input(codec, cfg->dig_in_pin, spec->dig_in);
7338 if (!spec->use_alt_functions) {
7339 snd_hda_sequence_write(codec, spec->chip_init_verbs);
7340 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7341 VENDOR_CHIPIO_PARAM_EX_ID_SET, 0x0D);
7342 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7343 VENDOR_CHIPIO_PARAM_EX_VALUE_SET, 0x20);
7346 if (spec->quirk == QUIRK_SBZ)
7347 ca0132_gpio_setup(codec);
7349 snd_hda_sequence_write(codec, spec->spec_init_verbs);
7350 if (spec->use_alt_functions) {
7351 ca0132_alt_select_out(codec);
7352 ca0132_alt_select_in(codec);
7354 ca0132_select_out(codec);
7355 ca0132_select_mic(codec);
7358 snd_hda_jack_report_sync(codec);
7361 * Re set the PlayEnhancement switch on a resume event, because the
7362 * controls will not be reloaded.
7364 if (spec->dsp_reload) {
7365 spec->dsp_reload = false;
7366 ca0132_pe_switch_set(codec);
7369 snd_hda_power_down_pm(codec);
7374 static void ca0132_free(struct hda_codec *codec)
7376 struct ca0132_spec *spec = codec->spec;
7378 cancel_delayed_work_sync(&spec->unsol_hp_work);
7379 snd_hda_power_up(codec);
7380 switch (spec->quirk) {
7382 sbz_exit_chip(codec);
7385 r3d_exit_chip(codec);
7388 r3di_gpio_shutdown(codec);
7392 snd_hda_sequence_write(codec, spec->base_exit_verbs);
7393 ca0132_exit_chip(codec);
7395 snd_hda_power_down(codec);
7398 pci_iounmap(codec->bus->pci, spec->mem_base);
7400 kfree(spec->spec_init_verbs);
7404 static void ca0132_reboot_notify(struct hda_codec *codec)
7406 codec->patch_ops.free(codec);
7410 static int ca0132_suspend(struct hda_codec *codec)
7412 struct ca0132_spec *spec = codec->spec;
7414 cancel_delayed_work_sync(&spec->unsol_hp_work);
7419 static const struct hda_codec_ops ca0132_patch_ops = {
7420 .build_controls = ca0132_build_controls,
7421 .build_pcms = ca0132_build_pcms,
7422 .init = ca0132_init,
7423 .free = ca0132_free,
7424 .unsol_event = snd_hda_jack_unsol_event,
7426 .suspend = ca0132_suspend,
7428 .reboot_notify = ca0132_reboot_notify,
7431 static void ca0132_config(struct hda_codec *codec)
7433 struct ca0132_spec *spec = codec->spec;
7435 spec->dacs[0] = 0x2;
7436 spec->dacs[1] = 0x3;
7437 spec->dacs[2] = 0x4;
7439 spec->multiout.dac_nids = spec->dacs;
7440 spec->multiout.num_dacs = 3;
7442 if (!spec->use_alt_functions)
7443 spec->multiout.max_channels = 2;
7445 spec->multiout.max_channels = 6;
7447 switch (spec->quirk) {
7448 case QUIRK_ALIENWARE:
7449 codec_dbg(codec, "ca0132_config: QUIRK_ALIENWARE applied.\n");
7450 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
7452 spec->num_outputs = 2;
7453 spec->out_pins[0] = 0x0b; /* speaker out */
7454 spec->out_pins[1] = 0x0f;
7455 spec->shared_out_nid = 0x2;
7456 spec->unsol_tag_hp = 0x0f;
7458 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
7459 spec->adcs[1] = 0x8; /* analog mic2 */
7460 spec->adcs[2] = 0xa; /* what u hear */
7462 spec->num_inputs = 3;
7463 spec->input_pins[0] = 0x12;
7464 spec->input_pins[1] = 0x11;
7465 spec->input_pins[2] = 0x13;
7466 spec->shared_mic_nid = 0x7;
7467 spec->unsol_tag_amic1 = 0x11;
7471 if (spec->quirk == QUIRK_SBZ) {
7472 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
7473 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
7475 if (spec->quirk == QUIRK_R3D) {
7476 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
7477 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
7480 spec->num_outputs = 2;
7481 spec->out_pins[0] = 0x0B; /* Line out */
7482 spec->out_pins[1] = 0x0F; /* Rear headphone out */
7483 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
7484 spec->out_pins[3] = 0x11; /* Rear surround */
7485 spec->shared_out_nid = 0x2;
7486 spec->unsol_tag_hp = spec->out_pins[1];
7487 spec->unsol_tag_front_hp = spec->out_pins[2];
7489 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
7490 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
7491 spec->adcs[2] = 0xa; /* what u hear */
7493 spec->num_inputs = 2;
7494 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
7495 spec->input_pins[1] = 0x13; /* What U Hear */
7496 spec->shared_mic_nid = 0x7;
7497 spec->unsol_tag_amic1 = spec->input_pins[0];
7500 spec->dig_out = 0x05;
7501 spec->multiout.dig_out_nid = spec->dig_out;
7502 spec->dig_in = 0x09;
7505 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
7506 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
7508 spec->num_outputs = 2;
7509 spec->out_pins[0] = 0x0B; /* Line out */
7510 spec->out_pins[1] = 0x0F; /* Rear headphone out */
7511 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
7512 spec->out_pins[3] = 0x11; /* Rear surround */
7513 spec->shared_out_nid = 0x2;
7514 spec->unsol_tag_hp = spec->out_pins[1];
7515 spec->unsol_tag_front_hp = spec->out_pins[2];
7517 spec->adcs[0] = 0x07; /* Rear Mic / Line-in */
7518 spec->adcs[1] = 0x08; /* Front Mic, but only if no DSP */
7519 spec->adcs[2] = 0x0a; /* what u hear */
7521 spec->num_inputs = 2;
7522 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
7523 spec->input_pins[1] = 0x13; /* What U Hear */
7524 spec->shared_mic_nid = 0x7;
7525 spec->unsol_tag_amic1 = spec->input_pins[0];
7528 spec->dig_out = 0x05;
7529 spec->multiout.dig_out_nid = spec->dig_out;
7532 spec->num_outputs = 2;
7533 spec->out_pins[0] = 0x0b; /* speaker out */
7534 spec->out_pins[1] = 0x10; /* headphone out */
7535 spec->shared_out_nid = 0x2;
7536 spec->unsol_tag_hp = spec->out_pins[1];
7538 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
7539 spec->adcs[1] = 0x8; /* analog mic2 */
7540 spec->adcs[2] = 0xa; /* what u hear */
7542 spec->num_inputs = 3;
7543 spec->input_pins[0] = 0x12;
7544 spec->input_pins[1] = 0x11;
7545 spec->input_pins[2] = 0x13;
7546 spec->shared_mic_nid = 0x7;
7547 spec->unsol_tag_amic1 = spec->input_pins[0];
7550 spec->dig_out = 0x05;
7551 spec->multiout.dig_out_nid = spec->dig_out;
7552 spec->dig_in = 0x09;
7557 static int ca0132_prepare_verbs(struct hda_codec *codec)
7559 /* Verbs + terminator (an empty element) */
7560 #define NUM_SPEC_VERBS 2
7561 struct ca0132_spec *spec = codec->spec;
7563 spec->chip_init_verbs = ca0132_init_verbs0;
7564 if (spec->quirk == QUIRK_SBZ || spec->quirk == QUIRK_R3D)
7565 spec->desktop_init_verbs = ca0132_init_verbs1;
7566 spec->spec_init_verbs = kcalloc(NUM_SPEC_VERBS,
7567 sizeof(struct hda_verb),
7569 if (!spec->spec_init_verbs)
7573 spec->spec_init_verbs[0].nid = 0x0b;
7574 spec->spec_init_verbs[0].param = 0x78D;
7575 spec->spec_init_verbs[0].verb = 0x00;
7577 /* Previously commented configuration */
7579 spec->spec_init_verbs[2].nid = 0x0b;
7580 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
7581 spec->spec_init_verbs[2].verb = 0x02;
7583 spec->spec_init_verbs[3].nid = 0x10;
7584 spec->spec_init_verbs[3].param = 0x78D;
7585 spec->spec_init_verbs[3].verb = 0x02;
7587 spec->spec_init_verbs[4].nid = 0x10;
7588 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
7589 spec->spec_init_verbs[4].verb = 0x02;
7592 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
7596 static int patch_ca0132(struct hda_codec *codec)
7598 struct ca0132_spec *spec;
7600 const struct snd_pci_quirk *quirk;
7602 codec_dbg(codec, "patch_ca0132\n");
7604 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7608 spec->codec = codec;
7610 codec->patch_ops = ca0132_patch_ops;
7611 codec->pcm_format_first = 1;
7612 codec->no_sticky_stream = 1;
7614 /* Detect codec quirk */
7615 quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks);
7617 spec->quirk = quirk->value;
7619 spec->quirk = QUIRK_NONE;
7621 spec->dsp_state = DSP_DOWNLOAD_INIT;
7622 spec->num_mixers = 1;
7624 /* Set which mixers each quirk uses. */
7625 switch (spec->quirk) {
7627 spec->mixers[0] = desktop_mixer;
7628 snd_hda_codec_set_name(codec, "Sound Blaster Z");
7631 spec->mixers[0] = desktop_mixer;
7632 snd_hda_codec_set_name(codec, "Recon3D");
7635 spec->mixers[0] = r3di_mixer;
7636 snd_hda_codec_set_name(codec, "Recon3Di");
7639 spec->mixers[0] = ca0132_mixer;
7643 /* Setup whether or not to use alt functions/controls/pci_mmio */
7644 switch (spec->quirk) {
7647 spec->use_alt_controls = true;
7648 spec->use_alt_functions = true;
7649 spec->use_pci_mmio = true;
7652 spec->use_alt_controls = true;
7653 spec->use_alt_functions = true;
7654 spec->use_pci_mmio = false;
7657 spec->use_alt_controls = false;
7658 spec->use_alt_functions = false;
7659 spec->use_pci_mmio = false;
7663 if (spec->use_pci_mmio) {
7664 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
7665 if (spec->mem_base == NULL) {
7666 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
7667 spec->quirk = QUIRK_NONE;
7671 spec->base_init_verbs = ca0132_base_init_verbs;
7672 spec->base_exit_verbs = ca0132_base_exit_verbs;
7674 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
7676 ca0132_init_chip(codec);
7678 ca0132_config(codec);
7680 err = ca0132_prepare_verbs(codec);
7684 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
7698 static struct hda_device_id snd_hda_id_ca0132[] = {
7699 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132),
7702 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132);
7704 MODULE_LICENSE("GPL");
7705 MODULE_DESCRIPTION("Creative Sound Core3D codec");
7707 static struct hda_codec_driver ca0132_driver = {
7708 .id = snd_hda_id_ca0132,
7711 module_hda_codec_driver(ca0132_driver);