2 * HD audio interface patch for Creative CA0132 chip
4 * Copyright (c) 2011, Creative Technology Ltd.
6 * Based on patch_ca0110.c
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 <sound/hda_codec.h>
37 #include "hda_local.h"
38 #include "hda_auto_parser.h"
41 #include "ca0132_regs.h"
43 /* Enable this to see controls for tuning purpose. */
44 /*#define ENABLE_TUNING_CONTROLS*/
46 #ifdef ENABLE_TUNING_CONTROLS
47 #include <sound/tlv.h>
50 #define FLOAT_ZERO 0x00000000
51 #define FLOAT_ONE 0x3f800000
52 #define FLOAT_TWO 0x40000000
53 #define FLOAT_THREE 0x40400000
54 #define FLOAT_EIGHT 0x41000000
55 #define FLOAT_MINUS_5 0xc0a00000
57 #define UNSOL_TAG_DSP 0x16
59 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
60 #define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
62 #define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
63 #define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
64 #define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
66 #define MASTERCONTROL 0x80
67 #define MASTERCONTROL_ALLOC_DMA_CHAN 10
68 #define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
70 #define WIDGET_CHIP_CTRL 0x15
71 #define WIDGET_DSP_CTRL 0x16
73 #define MEM_CONNID_MICIN1 3
74 #define MEM_CONNID_MICIN2 5
75 #define MEM_CONNID_MICOUT1 12
76 #define MEM_CONNID_MICOUT2 14
77 #define MEM_CONNID_WUH 10
78 #define MEM_CONNID_DSP 16
79 #define MEM_CONNID_DMIC 100
84 #define EFX_FILE "ctefx.bin"
85 #define DESKTOP_EFX_FILE "ctefx-desktop.bin"
86 #define R3DI_EFX_FILE "ctefx-r3di.bin"
88 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
89 MODULE_FIRMWARE(EFX_FILE);
90 MODULE_FIRMWARE(DESKTOP_EFX_FILE);
91 MODULE_FIRMWARE(R3DI_EFX_FILE);
94 static const char *const dirstr[2] = { "Playback", "Capture" };
96 #define NUM_OF_OUTPUTS 3
108 /* Strings for Input Source Enum Control */
109 static const char *const in_src_str[3] = {"Rear Mic", "Line", "Front Mic" };
110 #define IN_SRC_NUM_OF_INPUTS 3
118 #define VNODE_START_NID 0x80
119 VNID_SPK = VNODE_START_NID, /* Speaker vnid */
126 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
128 #define EFFECT_START_NID 0x90
129 #define OUT_EFFECT_START_NID EFFECT_START_NID
130 SURROUND = OUT_EFFECT_START_NID,
137 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
139 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
140 ECHO_CANCELLATION = IN_EFFECT_START_NID,
145 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
147 VOICEFX = IN_EFFECT_END_NID,
157 AE5_HEADPHONE_GAIN_ENUM,
158 AE5_SOUND_FILTER_ENUM,
160 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
163 /* Effects values size*/
164 #define EFFECT_VALS_MAX_COUNT 12
167 * Default values for the effect slider controls, they are in order of their
168 * effect NID's. Surround, Crystalizer, Dialog Plus, Smart Volume, and then
171 static const unsigned int effect_slider_defaults[] = {67, 65, 50, 74, 50};
172 /* Amount of effect level sliders for ca0132_alt controls. */
173 #define EFFECT_LEVEL_SLIDERS 5
175 /* Latency introduced by DSP blocks in milliseconds. */
176 #define DSP_CAPTURE_INIT_LATENCY 0
177 #define DSP_CRYSTAL_VOICE_LATENCY 124
178 #define DSP_PLAYBACK_INIT_LATENCY 13
179 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
180 #define DSP_SPEAKER_OUT_LATENCY 7
183 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
185 int mid; /*effect module ID*/
186 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
187 int direct; /* 0:output; 1:input*/
188 int params; /* number of default non-on/off params */
189 /*effect default values, 1st is on/off. */
190 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
193 #define EFX_DIR_OUT 0
196 static const struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
197 { .name = "Surround",
201 .direct = EFX_DIR_OUT,
203 .def_vals = {0x3F800000, 0x3F2B851F}
205 { .name = "Crystalizer",
209 .direct = EFX_DIR_OUT,
211 .def_vals = {0x3F800000, 0x3F266666}
213 { .name = "Dialog Plus",
217 .direct = EFX_DIR_OUT,
219 .def_vals = {0x00000000, 0x3F000000}
221 { .name = "Smart Volume",
225 .direct = EFX_DIR_OUT,
227 .def_vals = {0x3F800000, 0x3F3D70A4, 0x00000000}
232 .reqs = {24, 23, 25},
233 .direct = EFX_DIR_OUT,
235 .def_vals = {0x3F800000, 0x42A00000, 0x3F000000}
237 { .name = "Equalizer",
240 .reqs = {9, 10, 11, 12, 13, 14,
241 15, 16, 17, 18, 19, 20},
242 .direct = EFX_DIR_OUT,
244 .def_vals = {0x00000000, 0x00000000, 0x00000000, 0x00000000,
245 0x00000000, 0x00000000, 0x00000000, 0x00000000,
246 0x00000000, 0x00000000, 0x00000000, 0x00000000}
248 { .name = "Echo Cancellation",
249 .nid = ECHO_CANCELLATION,
251 .reqs = {0, 1, 2, 3},
252 .direct = EFX_DIR_IN,
254 .def_vals = {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
256 { .name = "Voice Focus",
259 .reqs = {6, 7, 8, 9},
260 .direct = EFX_DIR_IN,
262 .def_vals = {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
268 .direct = EFX_DIR_IN,
270 .def_vals = {0x00000000, 0x3F3D70A4}
272 { .name = "Noise Reduction",
273 .nid = NOISE_REDUCTION,
276 .direct = EFX_DIR_IN,
278 .def_vals = {0x3F800000, 0x3F000000}
283 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18},
284 .direct = EFX_DIR_IN,
286 .def_vals = {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
287 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
292 /* Tuning controls */
293 #ifdef ENABLE_TUNING_CONTROLS
296 #define TUNING_CTL_START_NID 0xC0
297 WEDGE_ANGLE = TUNING_CTL_START_NID,
310 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
313 struct ct_tuning_ctl {
314 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
315 hda_nid_t parent_nid;
317 int mid; /*effect module ID*/
318 int req; /*effect module request*/
319 int direct; /* 0:output; 1:input*/
320 unsigned int def_val;/*effect default values*/
323 static const struct ct_tuning_ctl ca0132_tuning_ctls[] = {
324 { .name = "Wedge Angle",
325 .parent_nid = VOICE_FOCUS,
329 .direct = EFX_DIR_IN,
330 .def_val = 0x41F00000
332 { .name = "SVM Level",
333 .parent_nid = MIC_SVM,
337 .direct = EFX_DIR_IN,
338 .def_val = 0x3F3D70A4
340 { .name = "EQ Band0",
341 .parent_nid = EQUALIZER,
342 .nid = EQUALIZER_BAND_0,
345 .direct = EFX_DIR_OUT,
346 .def_val = 0x00000000
348 { .name = "EQ Band1",
349 .parent_nid = EQUALIZER,
350 .nid = EQUALIZER_BAND_1,
353 .direct = EFX_DIR_OUT,
354 .def_val = 0x00000000
356 { .name = "EQ Band2",
357 .parent_nid = EQUALIZER,
358 .nid = EQUALIZER_BAND_2,
361 .direct = EFX_DIR_OUT,
362 .def_val = 0x00000000
364 { .name = "EQ Band3",
365 .parent_nid = EQUALIZER,
366 .nid = EQUALIZER_BAND_3,
369 .direct = EFX_DIR_OUT,
370 .def_val = 0x00000000
372 { .name = "EQ Band4",
373 .parent_nid = EQUALIZER,
374 .nid = EQUALIZER_BAND_4,
377 .direct = EFX_DIR_OUT,
378 .def_val = 0x00000000
380 { .name = "EQ Band5",
381 .parent_nid = EQUALIZER,
382 .nid = EQUALIZER_BAND_5,
385 .direct = EFX_DIR_OUT,
386 .def_val = 0x00000000
388 { .name = "EQ Band6",
389 .parent_nid = EQUALIZER,
390 .nid = EQUALIZER_BAND_6,
393 .direct = EFX_DIR_OUT,
394 .def_val = 0x00000000
396 { .name = "EQ Band7",
397 .parent_nid = EQUALIZER,
398 .nid = EQUALIZER_BAND_7,
401 .direct = EFX_DIR_OUT,
402 .def_val = 0x00000000
404 { .name = "EQ Band8",
405 .parent_nid = EQUALIZER,
406 .nid = EQUALIZER_BAND_8,
409 .direct = EFX_DIR_OUT,
410 .def_val = 0x00000000
412 { .name = "EQ Band9",
413 .parent_nid = EQUALIZER,
414 .nid = EQUALIZER_BAND_9,
417 .direct = EFX_DIR_OUT,
418 .def_val = 0x00000000
423 /* Voice FX Presets */
424 #define VOICEFX_MAX_PARAM_COUNT 9
430 int reqs[VOICEFX_MAX_PARAM_COUNT]; /*effect module request*/
433 struct ct_voicefx_preset {
434 char *name; /*preset name*/
435 unsigned int vals[VOICEFX_MAX_PARAM_COUNT];
438 static const struct ct_voicefx ca0132_voicefx = {
439 .name = "VoiceFX Capture Switch",
442 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18}
445 static const struct ct_voicefx_preset ca0132_voicefx_presets[] = {
447 .vals = { 0x00000000, 0x43C80000, 0x44AF0000,
448 0x44FA0000, 0x3F800000, 0x3F800000,
449 0x3F800000, 0x00000000, 0x00000000 }
451 { .name = "Female2Male",
452 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
453 0x44FA0000, 0x3F19999A, 0x3F866666,
454 0x3F800000, 0x00000000, 0x00000000 }
456 { .name = "Male2Female",
457 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
458 0x450AC000, 0x4017AE14, 0x3F6B851F,
459 0x3F800000, 0x00000000, 0x00000000 }
461 { .name = "ScrappyKid",
462 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
463 0x44FA0000, 0x40400000, 0x3F28F5C3,
464 0x3F800000, 0x00000000, 0x00000000 }
467 .vals = { 0x3F800000, 0x44324000, 0x44BB8000,
468 0x44E10000, 0x3FB33333, 0x3FB9999A,
469 0x3F800000, 0x3E3A2E43, 0x00000000 }
472 .vals = { 0x3F800000, 0x43EA0000, 0x44A52000,
473 0x45098000, 0x3F266666, 0x3FC00000,
474 0x3F800000, 0x00000000, 0x00000000 }
477 .vals = { 0x3F800000, 0x43C70000, 0x44AE6000,
478 0x45193000, 0x3F8E147B, 0x3F75C28F,
479 0x3F800000, 0x00000000, 0x00000000 }
482 .vals = { 0x3F800000, 0x43930000, 0x44BEE000,
483 0x45007000, 0x3F451EB8, 0x3F7851EC,
484 0x3F800000, 0x00000000, 0x00000000 }
486 { .name = "AlienBrute",
487 .vals = { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
488 0x451F6000, 0x3F266666, 0x3FA7D945,
489 0x3F800000, 0x3CF5C28F, 0x00000000 }
492 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
493 0x44FA0000, 0x3FB2718B, 0x3F800000,
494 0xBC07010E, 0x00000000, 0x00000000 }
497 .vals = { 0x3F800000, 0x43C20000, 0x44906000,
498 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
499 0x3F0A3D71, 0x00000000, 0x00000000 }
502 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
503 0x44FA0000, 0x3F800000, 0x3F800000,
504 0x3E4CCCCD, 0x00000000, 0x00000000 }
506 { .name = "DeepVoice",
507 .vals = { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
508 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
509 0x3F800000, 0x00000000, 0x00000000 }
511 { .name = "Munchkin",
512 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
513 0x44FA0000, 0x3F800000, 0x3F1A043C,
514 0x3F800000, 0x00000000, 0x00000000 }
518 /* ca0132 EQ presets, taken from Windows Sound Blaster Z Driver */
520 #define EQ_PRESET_MAX_PARAM_COUNT 11
526 int reqs[EQ_PRESET_MAX_PARAM_COUNT]; /*effect module request*/
529 struct ct_eq_preset {
530 char *name; /*preset name*/
531 unsigned int vals[EQ_PRESET_MAX_PARAM_COUNT];
534 static const struct ct_eq ca0132_alt_eq_enum = {
535 .name = "FX: Equalizer Preset Switch",
536 .nid = EQ_PRESET_ENUM,
538 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
542 static const struct ct_eq_preset ca0132_alt_eq_presets[] = {
544 .vals = { 0x00000000, 0x00000000, 0x00000000,
545 0x00000000, 0x00000000, 0x00000000,
546 0x00000000, 0x00000000, 0x00000000,
547 0x00000000, 0x00000000 }
549 { .name = "Acoustic",
550 .vals = { 0x00000000, 0x00000000, 0x3F8CCCCD,
551 0x40000000, 0x00000000, 0x00000000,
552 0x00000000, 0x00000000, 0x40000000,
553 0x40000000, 0x40000000 }
555 { .name = "Classical",
556 .vals = { 0x00000000, 0x00000000, 0x40C00000,
557 0x40C00000, 0x40466666, 0x00000000,
558 0x00000000, 0x00000000, 0x00000000,
559 0x40466666, 0x40466666 }
562 .vals = { 0x00000000, 0xBF99999A, 0x00000000,
563 0x3FA66666, 0x3FA66666, 0x3F8CCCCD,
564 0x00000000, 0x00000000, 0x40000000,
565 0x40466666, 0x40800000 }
568 .vals = { 0x00000000, 0xBF99999A, 0x40000000,
569 0x40466666, 0x40866666, 0xBF99999A,
570 0xBF99999A, 0x00000000, 0x00000000,
571 0x40800000, 0x40800000 }
574 .vals = { 0x00000000, 0x00000000, 0x00000000,
575 0x3F8CCCCD, 0x40800000, 0x40800000,
576 0x40800000, 0x00000000, 0x3F8CCCCD,
577 0x40466666, 0x40466666 }
580 .vals = { 0x00000000, 0x00000000, 0x40000000,
581 0x40000000, 0x00000000, 0x00000000,
582 0x00000000, 0x3F8CCCCD, 0x40000000,
583 0x40000000, 0x40000000 }
586 .vals = { 0x00000000, 0xBFCCCCCD, 0x00000000,
587 0x40000000, 0x40000000, 0x00000000,
588 0xBF99999A, 0xBF99999A, 0x00000000,
589 0x40466666, 0x40C00000 }
592 .vals = { 0x00000000, 0xBF99999A, 0xBF99999A,
593 0x3F8CCCCD, 0x40000000, 0xBF99999A,
594 0xBF99999A, 0x00000000, 0x00000000,
595 0x40800000, 0x40800000 }
598 .vals = { 0x00000000, 0xC0000000, 0xBF99999A,
599 0xBF99999A, 0x00000000, 0x40466666,
600 0x40800000, 0x40466666, 0x00000000,
601 0x00000000, 0x3F8CCCCD }
605 /* DSP command sequences for ca0132_alt_select_out */
606 #define ALT_OUT_SET_MAX_COMMANDS 9 /* Max number of commands in sequence */
607 struct ca0132_alt_out_set {
608 char *name; /*preset name*/
609 unsigned char commands;
610 unsigned int mids[ALT_OUT_SET_MAX_COMMANDS];
611 unsigned int reqs[ALT_OUT_SET_MAX_COMMANDS];
612 unsigned int vals[ALT_OUT_SET_MAX_COMMANDS];
615 static const struct ca0132_alt_out_set alt_out_presets[] = {
616 { .name = "Line Out",
618 .mids = { 0x96, 0x96, 0x96, 0x8F,
620 .reqs = { 0x19, 0x17, 0x18, 0x01,
622 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
623 0x00000000, 0x00000000, 0x00000000,
626 { .name = "Headphone",
628 .mids = { 0x96, 0x96, 0x96, 0x8F,
630 .reqs = { 0x19, 0x17, 0x18, 0x01,
632 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
633 0x00000000, 0x00000000, 0x00000000,
636 { .name = "Surround",
638 .mids = { 0x96, 0x8F, 0x96, 0x96,
639 0x96, 0x96, 0x96, 0x96 },
640 .reqs = { 0x18, 0x01, 0x1F, 0x15,
641 0x3A, 0x1A, 0x1B, 0x1C },
642 .vals = { 0x00000000, 0x00000000, 0x00000000,
643 0x00000000, 0x00000000, 0x00000000,
644 0x00000000, 0x00000000 }
649 * DSP volume setting structs. Req 1 is left volume, req 2 is right volume,
650 * and I don't know what the third req is, but it's always zero. I assume it's
651 * some sort of update or set command to tell the DSP there's new volume info.
653 #define DSP_VOL_OUT 0
656 struct ct_dsp_volume_ctl {
658 int mid; /* module ID*/
659 unsigned int reqs[3]; /* scp req ID */
662 static const struct ct_dsp_volume_ctl ca0132_alt_vol_ctls[] = {
673 /* Values for ca0113_mmio_command_set for selecting output. */
674 #define AE5_CA0113_OUT_SET_COMMANDS 6
675 struct ae5_ca0113_output_set {
676 unsigned int group[AE5_CA0113_OUT_SET_COMMANDS];
677 unsigned int target[AE5_CA0113_OUT_SET_COMMANDS];
678 unsigned int vals[AE5_CA0113_OUT_SET_COMMANDS];
681 static const struct ae5_ca0113_output_set ae5_ca0113_output_presets[] = {
682 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
683 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
684 .vals = { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f }
686 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
687 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
688 .vals = { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 }
690 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
691 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
692 .vals = { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f }
696 /* ae5 ca0113 command sequences to set headphone gain levels. */
697 #define AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS 4
698 struct ae5_headphone_gain_set {
700 unsigned int vals[AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS];
703 static const struct ae5_headphone_gain_set ae5_headphone_gain_presets[] = {
704 { .name = "Low (16-31",
705 .vals = { 0xff, 0x2c, 0xf5, 0x32 }
707 { .name = "Medium (32-149",
708 .vals = { 0x38, 0xa8, 0x3e, 0x4c }
710 { .name = "High (150-600",
711 .vals = { 0xff, 0xff, 0xff, 0x7f }
715 struct ae5_filter_set {
720 static const struct ae5_filter_set ae5_filter_presets[] = {
721 { .name = "Slow Roll Off",
724 { .name = "Minimum Phase",
727 { .name = "Fast Roll Off",
732 enum hda_cmd_vendor_io {
734 VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000,
735 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100,
737 VENDOR_DSPIO_STATUS = 0xF01,
738 VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702,
739 VENDOR_DSPIO_SCP_READ_DATA = 0xF02,
740 VENDOR_DSPIO_DSP_INIT = 0x703,
741 VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704,
742 VENDOR_DSPIO_SCP_READ_COUNT = 0xF04,
744 /* for ChipIO node */
745 VENDOR_CHIPIO_ADDRESS_LOW = 0x000,
746 VENDOR_CHIPIO_ADDRESS_HIGH = 0x100,
747 VENDOR_CHIPIO_STREAM_FORMAT = 0x200,
748 VENDOR_CHIPIO_DATA_LOW = 0x300,
749 VENDOR_CHIPIO_DATA_HIGH = 0x400,
751 VENDOR_CHIPIO_8051_WRITE_DIRECT = 0x500,
752 VENDOR_CHIPIO_8051_READ_DIRECT = 0xD00,
754 VENDOR_CHIPIO_GET_PARAMETER = 0xF00,
755 VENDOR_CHIPIO_STATUS = 0xF01,
756 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
757 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
759 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
760 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
761 VENDOR_CHIPIO_8051_PMEM_READ = 0xF08,
762 VENDOR_CHIPIO_8051_IRAM_WRITE = 0x709,
763 VENDOR_CHIPIO_8051_IRAM_READ = 0xF09,
765 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
766 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
768 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
769 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
770 VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D,
771 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
772 VENDOR_CHIPIO_FLAG_SET = 0x70F,
773 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
774 VENDOR_CHIPIO_PARAM_SET = 0x710,
775 VENDOR_CHIPIO_PARAM_GET = 0xF10,
777 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
778 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
779 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
780 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
782 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
783 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
784 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
785 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
787 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
788 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
789 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
790 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
791 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
792 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
794 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
800 enum control_flag_id {
801 /* Connection manager stream setup is bypassed/enabled */
802 CONTROL_FLAG_C_MGR = 0,
803 /* DSP DMA is bypassed/enabled */
804 CONTROL_FLAG_DMA = 1,
805 /* 8051 'idle' mode is disabled/enabled */
806 CONTROL_FLAG_IDLE_ENABLE = 2,
807 /* Tracker for the SPDIF-in path is bypassed/enabled */
808 CONTROL_FLAG_TRACKER = 3,
809 /* DigitalOut to Spdif2Out connection is disabled/enabled */
810 CONTROL_FLAG_SPDIF2OUT = 4,
811 /* Digital Microphone is disabled/enabled */
812 CONTROL_FLAG_DMIC = 5,
813 /* ADC_B rate is 48 kHz/96 kHz */
814 CONTROL_FLAG_ADC_B_96KHZ = 6,
815 /* ADC_C rate is 48 kHz/96 kHz */
816 CONTROL_FLAG_ADC_C_96KHZ = 7,
817 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
818 CONTROL_FLAG_DAC_96KHZ = 8,
819 /* DSP rate is 48 kHz/96 kHz */
820 CONTROL_FLAG_DSP_96KHZ = 9,
821 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
822 CONTROL_FLAG_SRC_CLOCK_196MHZ = 10,
823 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
824 CONTROL_FLAG_SRC_RATE_96KHZ = 11,
825 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
826 CONTROL_FLAG_DECODE_LOOP = 12,
827 /* De-emphasis filter on DAC-1 disabled/enabled */
828 CONTROL_FLAG_DAC1_DEEMPHASIS = 13,
829 /* De-emphasis filter on DAC-2 disabled/enabled */
830 CONTROL_FLAG_DAC2_DEEMPHASIS = 14,
831 /* De-emphasis filter on DAC-3 disabled/enabled */
832 CONTROL_FLAG_DAC3_DEEMPHASIS = 15,
833 /* High-pass filter on ADC_B disabled/enabled */
834 CONTROL_FLAG_ADC_B_HIGH_PASS = 16,
835 /* High-pass filter on ADC_C disabled/enabled */
836 CONTROL_FLAG_ADC_C_HIGH_PASS = 17,
837 /* Common mode on Port_A disabled/enabled */
838 CONTROL_FLAG_PORT_A_COMMON_MODE = 18,
839 /* Common mode on Port_D disabled/enabled */
840 CONTROL_FLAG_PORT_D_COMMON_MODE = 19,
841 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
842 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
843 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
844 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
845 /* ASI rate is 48kHz/96kHz */
846 CONTROL_FLAG_ASI_96KHZ = 22,
847 /* DAC power settings able to control attached ports no/yes */
848 CONTROL_FLAG_DACS_CONTROL_PORTS = 23,
849 /* Clock Stop OK reporting is disabled/enabled */
850 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24,
851 /* Number of control flags */
852 CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1)
856 * Control parameter IDs
858 enum control_param_id {
859 /* 0: None, 1: Mic1In*/
860 CONTROL_PARAM_VIP_SOURCE = 1,
861 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
862 CONTROL_PARAM_SPDIF1_SOURCE = 2,
863 /* Port A output stage gain setting to use when 16 Ohm output
864 * impedance is selected*/
865 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
866 /* Port D output stage gain setting to use when 16 Ohm output
867 * impedance is selected*/
868 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
871 * This control param name was found in the 8051 memory, and makes
872 * sense given the fact the AE-5 uses it and has the ASI flag set.
874 CONTROL_PARAM_ASI = 23,
878 /* Select stream with the given ID */
879 CONTROL_PARAM_STREAM_ID = 24,
880 /* Source connection point for the selected stream */
881 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25,
882 /* Destination connection point for the selected stream */
883 CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26,
884 /* Number of audio channels in the selected stream */
885 CONTROL_PARAM_STREAMS_CHANNELS = 27,
886 /*Enable control for the selected stream */
887 CONTROL_PARAM_STREAM_CONTROL = 28,
889 /* Connection Point Control */
891 /* Select connection point with the given ID */
892 CONTROL_PARAM_CONN_POINT_ID = 29,
893 /* Connection point sample rate */
894 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30,
898 /* Select HDA node with the given ID */
899 CONTROL_PARAM_NODE_ID = 31
903 * Dsp Io Status codes
905 enum hda_vendor_status_dspio {
907 VENDOR_STATUS_DSPIO_OK = 0x00,
908 /* Busy, unable to accept new command, the host must retry */
909 VENDOR_STATUS_DSPIO_BUSY = 0x01,
910 /* SCP command queue is full */
911 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02,
912 /* SCP response queue is empty */
913 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03
917 * Chip Io Status codes
919 enum hda_vendor_status_chipio {
921 VENDOR_STATUS_CHIPIO_OK = 0x00,
922 /* Busy, unable to accept new command, the host must retry */
923 VENDOR_STATUS_CHIPIO_BUSY = 0x01
929 enum ca0132_sample_rate {
949 SR_RATE_UNKNOWN = 0x1F
952 enum dsp_download_state {
953 DSP_DOWNLOAD_FAILED = -1,
954 DSP_DOWNLOAD_INIT = 0,
959 /* retrieve parameters from hda format */
960 #define get_hdafmt_chs(fmt) (fmt & 0xf)
961 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
962 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
963 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
970 const struct snd_kcontrol_new *mixers[5];
971 unsigned int num_mixers;
972 const struct hda_verb *base_init_verbs;
973 const struct hda_verb *base_exit_verbs;
974 const struct hda_verb *chip_init_verbs;
975 const struct hda_verb *desktop_init_verbs;
976 struct hda_verb *spec_init_verbs;
977 struct auto_pin_cfg autocfg;
979 /* Nodes configurations */
980 struct hda_multi_out multiout;
981 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
982 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
983 unsigned int num_outputs;
984 hda_nid_t input_pins[AUTO_PIN_LAST];
985 hda_nid_t adcs[AUTO_PIN_LAST];
988 unsigned int num_inputs;
989 hda_nid_t shared_mic_nid;
990 hda_nid_t shared_out_nid;
991 hda_nid_t unsol_tag_hp;
992 hda_nid_t unsol_tag_front_hp; /* for desktop ca0132 codecs */
993 hda_nid_t unsol_tag_amic1;
996 struct mutex chipio_mutex; /* chip access mutex */
999 /* DSP download related */
1000 enum dsp_download_state dsp_state;
1001 unsigned int dsp_stream_id;
1002 unsigned int wait_scp;
1003 unsigned int wait_scp_header;
1004 unsigned int wait_num_data;
1005 unsigned int scp_resp_header;
1006 unsigned int scp_resp_data[4];
1007 unsigned int scp_resp_count;
1008 bool alt_firmware_present;
1009 bool startup_check_entered;
1012 /* mixer and effects related */
1013 unsigned char dmic_ctl;
1016 long vnode_lvol[VNODES_COUNT];
1017 long vnode_rvol[VNODES_COUNT];
1018 long vnode_lswitch[VNODES_COUNT];
1019 long vnode_rswitch[VNODES_COUNT];
1020 long effects_switch[EFFECTS_COUNT];
1023 /* ca0132_alt control related values */
1024 unsigned char in_enum_val;
1025 unsigned char out_enum_val;
1026 unsigned char mic_boost_enum_val;
1027 unsigned char smart_volume_setting;
1028 long fx_ctl_val[EFFECT_LEVEL_SLIDERS];
1029 long xbass_xover_freq;
1031 unsigned int tlv[4];
1032 struct hda_vmaster_mute_hook vmaster_mute;
1033 /* AE-5 Control values */
1034 unsigned char ae5_headphone_gain_val;
1035 unsigned char ae5_filter_val;
1036 /* ZxR Control Values */
1037 unsigned char zxr_gain_set;
1039 struct hda_codec *codec;
1040 struct delayed_work unsol_hp_work;
1043 #ifdef ENABLE_TUNING_CONTROLS
1044 long cur_ctl_vals[TUNING_CTLS_COUNT];
1047 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
1048 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
1052 void __iomem *mem_base;
1055 * Whether or not to use the alt functions like alt_select_out,
1056 * alt_select_in, etc. Only used on desktop codecs for now, because of
1057 * surround sound support.
1059 bool use_alt_functions;
1062 * Whether or not to use alt controls: volume effect sliders, EQ
1063 * presets, smart volume presets, and new control names with FX prefix.
1064 * Renames PlayEnhancement and CrystalVoice too.
1066 bool use_alt_controls;
1070 * CA0132 quirks table
1075 QUIRK_ALIENWARE_M17XR4,
1084 static const struct hda_pintbl alienware_pincfgs[] = {
1085 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1086 { 0x0c, 0x411111f0 }, /* N/A */
1087 { 0x0d, 0x411111f0 }, /* N/A */
1088 { 0x0e, 0x411111f0 }, /* N/A */
1089 { 0x0f, 0x0321101f }, /* HP */
1090 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1091 { 0x11, 0x03a11021 }, /* Mic */
1092 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1093 { 0x13, 0x411111f0 }, /* N/A */
1094 { 0x18, 0x411111f0 }, /* N/A */
1098 /* Sound Blaster Z pin configs taken from Windows Driver */
1099 static const struct hda_pintbl sbz_pincfgs[] = {
1100 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1101 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1102 { 0x0d, 0x014510f0 }, /* Digital Out */
1103 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1104 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1105 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1106 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1107 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1108 { 0x13, 0x908700f0 }, /* What U Hear In*/
1109 { 0x18, 0x50d000f0 }, /* N/A */
1113 /* Sound Blaster ZxR pin configs taken from Windows Driver */
1114 static const struct hda_pintbl zxr_pincfgs[] = {
1115 { 0x0b, 0x01047110 }, /* Port G -- Lineout FRONT L/R */
1116 { 0x0c, 0x414510f0 }, /* SPDIF Out 1 - Disabled*/
1117 { 0x0d, 0x014510f0 }, /* Digital Out */
1118 { 0x0e, 0x41c520f0 }, /* SPDIF In - Disabled*/
1119 { 0x0f, 0x0122711f }, /* Port A -- BackPanel HP */
1120 { 0x10, 0x01017111 }, /* Port D -- Center/LFE */
1121 { 0x11, 0x01017114 }, /* Port B -- LineMicIn2 / Rear L/R */
1122 { 0x12, 0x01a271f0 }, /* Port C -- LineIn1 */
1123 { 0x13, 0x908700f0 }, /* What U Hear In*/
1124 { 0x18, 0x50d000f0 }, /* N/A */
1128 /* Recon3D pin configs taken from Windows Driver */
1129 static const struct hda_pintbl r3d_pincfgs[] = {
1130 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1131 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1132 { 0x0d, 0x014510f0 }, /* Digital Out */
1133 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1134 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1135 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1136 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1137 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1138 { 0x13, 0x908700f0 }, /* What U Hear In*/
1139 { 0x18, 0x50d000f0 }, /* N/A */
1143 /* Sound Blaster AE-5 pin configs taken from Windows Driver */
1144 static const struct hda_pintbl ae5_pincfgs[] = {
1145 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1146 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1147 { 0x0d, 0x014510f0 }, /* Digital Out */
1148 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1149 { 0x0f, 0x01017114 }, /* Port A -- Rear L/R. */
1150 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1151 { 0x11, 0x01a170ff }, /* Port B -- LineMicIn2 / Rear Headphone */
1152 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1153 { 0x13, 0x908700f0 }, /* What U Hear In*/
1154 { 0x18, 0x50d000f0 }, /* N/A */
1158 /* Recon3D integrated pin configs taken from Windows Driver */
1159 static const struct hda_pintbl r3di_pincfgs[] = {
1160 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1161 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1162 { 0x0d, 0x014510f0 }, /* Digital Out */
1163 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1164 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1165 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1166 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1167 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1168 { 0x13, 0x908700f0 }, /* What U Hear In*/
1169 { 0x18, 0x500000f0 }, /* N/A */
1173 static const struct snd_pci_quirk ca0132_quirks[] = {
1174 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4),
1175 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE),
1176 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE),
1177 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE),
1178 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ),
1179 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ),
1180 SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ),
1181 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
1182 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
1183 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
1184 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1185 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5),
1190 * CA0132 codec access
1192 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1193 unsigned int verb, unsigned int parm, unsigned int *res)
1195 unsigned int response;
1196 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1199 return ((response == -1) ? -1 : 0);
1202 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1203 unsigned short converter_format, unsigned int *res)
1205 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1206 converter_format & 0xffff, res);
1209 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1210 hda_nid_t nid, unsigned char stream,
1211 unsigned char channel, unsigned int *res)
1213 unsigned char converter_stream_channel = 0;
1215 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1216 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1217 converter_stream_channel, res);
1220 /* Chip access helper function */
1221 static int chipio_send(struct hda_codec *codec,
1226 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1228 /* send bits of data specified by reg */
1230 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1232 if (res == VENDOR_STATUS_CHIPIO_OK)
1235 } while (time_before(jiffies, timeout));
1241 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1243 static int chipio_write_address(struct hda_codec *codec,
1244 unsigned int chip_addx)
1246 struct ca0132_spec *spec = codec->spec;
1249 if (spec->curr_chip_addx == chip_addx)
1252 /* send low 16 bits of the address */
1253 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1254 chip_addx & 0xffff);
1257 /* send high 16 bits of the address */
1258 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1262 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1268 * Write data through the vendor widget -- NOT protected by the Mutex!
1270 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1272 struct ca0132_spec *spec = codec->spec;
1275 /* send low 16 bits of the data */
1276 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1279 /* send high 16 bits of the data */
1280 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1284 /*If no error encountered, automatically increment the address
1285 as per chip behaviour*/
1286 spec->curr_chip_addx = (res != -EIO) ?
1287 (spec->curr_chip_addx + 4) : ~0U;
1292 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1294 static int chipio_write_data_multiple(struct hda_codec *codec,
1301 codec_dbg(codec, "chipio_write_data null ptr\n");
1305 while ((count-- != 0) && (status == 0))
1306 status = chipio_write_data(codec, *data++);
1313 * Read data through the vendor widget -- NOT protected by the Mutex!
1315 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1317 struct ca0132_spec *spec = codec->spec;
1321 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1325 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1330 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1331 VENDOR_CHIPIO_HIC_READ_DATA,
1335 /*If no error encountered, automatically increment the address
1336 as per chip behaviour*/
1337 spec->curr_chip_addx = (res != -EIO) ?
1338 (spec->curr_chip_addx + 4) : ~0U;
1343 * Write given value to the given address through the chip I/O widget.
1344 * protected by the Mutex
1346 static int chipio_write(struct hda_codec *codec,
1347 unsigned int chip_addx, const unsigned int data)
1349 struct ca0132_spec *spec = codec->spec;
1352 mutex_lock(&spec->chipio_mutex);
1354 /* write the address, and if successful proceed to write data */
1355 err = chipio_write_address(codec, chip_addx);
1359 err = chipio_write_data(codec, data);
1364 mutex_unlock(&spec->chipio_mutex);
1369 * Write given value to the given address through the chip I/O widget.
1370 * not protected by the Mutex
1372 static int chipio_write_no_mutex(struct hda_codec *codec,
1373 unsigned int chip_addx, const unsigned int data)
1378 /* write the address, and if successful proceed to write data */
1379 err = chipio_write_address(codec, chip_addx);
1383 err = chipio_write_data(codec, data);
1392 * Write multiple values to the given address through the chip I/O widget.
1393 * protected by the Mutex
1395 static int chipio_write_multiple(struct hda_codec *codec,
1400 struct ca0132_spec *spec = codec->spec;
1403 mutex_lock(&spec->chipio_mutex);
1404 status = chipio_write_address(codec, chip_addx);
1408 status = chipio_write_data_multiple(codec, data, count);
1410 mutex_unlock(&spec->chipio_mutex);
1416 * Read the given address through the chip I/O widget
1417 * protected by the Mutex
1419 static int chipio_read(struct hda_codec *codec,
1420 unsigned int chip_addx, unsigned int *data)
1422 struct ca0132_spec *spec = codec->spec;
1425 mutex_lock(&spec->chipio_mutex);
1427 /* write the address, and if successful proceed to write data */
1428 err = chipio_write_address(codec, chip_addx);
1432 err = chipio_read_data(codec, data);
1437 mutex_unlock(&spec->chipio_mutex);
1442 * Set chip control flags through the chip I/O widget.
1444 static void chipio_set_control_flag(struct hda_codec *codec,
1445 enum control_flag_id flag_id,
1449 unsigned int flag_bit;
1451 flag_bit = (flag_state ? 1 : 0);
1452 val = (flag_bit << 7) | (flag_id);
1453 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1454 VENDOR_CHIPIO_FLAG_SET, val);
1458 * Set chip parameters through the chip I/O widget.
1460 static void chipio_set_control_param(struct hda_codec *codec,
1461 enum control_param_id param_id, int param_val)
1463 struct ca0132_spec *spec = codec->spec;
1466 if ((param_id < 32) && (param_val < 8)) {
1467 val = (param_val << 5) | (param_id);
1468 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1469 VENDOR_CHIPIO_PARAM_SET, val);
1471 mutex_lock(&spec->chipio_mutex);
1472 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1473 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1474 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1476 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1477 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1480 mutex_unlock(&spec->chipio_mutex);
1485 * Set chip parameters through the chip I/O widget. NO MUTEX.
1487 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1488 enum control_param_id param_id, int param_val)
1492 if ((param_id < 32) && (param_val < 8)) {
1493 val = (param_val << 5) | (param_id);
1494 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1495 VENDOR_CHIPIO_PARAM_SET, val);
1497 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1498 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1499 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1501 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1502 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1508 * Connect stream to a source point, and then connect
1509 * that source point to a destination point.
1511 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1512 int streamid, int source_point, int dest_point)
1514 chipio_set_control_param_no_mutex(codec,
1515 CONTROL_PARAM_STREAM_ID, streamid);
1516 chipio_set_control_param_no_mutex(codec,
1517 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1518 chipio_set_control_param_no_mutex(codec,
1519 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1523 * Set number of channels in the selected stream.
1525 static void chipio_set_stream_channels(struct hda_codec *codec,
1526 int streamid, unsigned int channels)
1528 chipio_set_control_param_no_mutex(codec,
1529 CONTROL_PARAM_STREAM_ID, streamid);
1530 chipio_set_control_param_no_mutex(codec,
1531 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1535 * Enable/Disable audio stream.
1537 static void chipio_set_stream_control(struct hda_codec *codec,
1538 int streamid, int enable)
1540 chipio_set_control_param_no_mutex(codec,
1541 CONTROL_PARAM_STREAM_ID, streamid);
1542 chipio_set_control_param_no_mutex(codec,
1543 CONTROL_PARAM_STREAM_CONTROL, enable);
1548 * Set sampling rate of the connection point. NO MUTEX.
1550 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1551 int connid, enum ca0132_sample_rate rate)
1553 chipio_set_control_param_no_mutex(codec,
1554 CONTROL_PARAM_CONN_POINT_ID, connid);
1555 chipio_set_control_param_no_mutex(codec,
1556 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1560 * Set sampling rate of the connection point.
1562 static void chipio_set_conn_rate(struct hda_codec *codec,
1563 int connid, enum ca0132_sample_rate rate)
1565 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1566 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1571 * Writes to the 8051's internal address space directly instead of indirectly,
1572 * giving access to the special function registers located at addresses
1575 static void chipio_8051_write_direct(struct hda_codec *codec,
1576 unsigned int addr, unsigned int data)
1580 verb = VENDOR_CHIPIO_8051_WRITE_DIRECT | data;
1581 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1587 static void chipio_enable_clocks(struct hda_codec *codec)
1589 struct ca0132_spec *spec = codec->spec;
1591 mutex_lock(&spec->chipio_mutex);
1592 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1593 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1594 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1595 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1596 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1597 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1598 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1599 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1600 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1601 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1602 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1603 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1604 mutex_unlock(&spec->chipio_mutex);
1608 * CA0132 DSP IO stuffs
1610 static int dspio_send(struct hda_codec *codec, unsigned int reg,
1614 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1616 /* send bits of data specified by reg to dsp */
1618 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1619 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1622 } while (time_before(jiffies, timeout));
1628 * Wait for DSP to be ready for commands
1630 static void dspio_write_wait(struct hda_codec *codec)
1633 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1636 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1637 VENDOR_DSPIO_STATUS, 0);
1638 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1639 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1642 } while (time_before(jiffies, timeout));
1646 * Write SCP data to DSP
1648 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1650 struct ca0132_spec *spec = codec->spec;
1653 dspio_write_wait(codec);
1655 mutex_lock(&spec->chipio_mutex);
1656 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1661 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1666 /* OK, now check if the write itself has executed*/
1667 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1668 VENDOR_DSPIO_STATUS, 0);
1670 mutex_unlock(&spec->chipio_mutex);
1672 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1677 * Write multiple SCP data to DSP
1679 static int dspio_write_multiple(struct hda_codec *codec,
1680 unsigned int *buffer, unsigned int size)
1689 while (count < size) {
1690 status = dspio_write(codec, *buffer++);
1699 static int dspio_read(struct hda_codec *codec, unsigned int *data)
1703 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1707 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1708 if (status == -EIO ||
1709 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
1712 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1713 VENDOR_DSPIO_SCP_READ_DATA, 0);
1718 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
1719 unsigned int *buf_size, unsigned int size_count)
1722 unsigned int size = *buf_size;
1724 unsigned int skip_count;
1731 while (count < size && count < size_count) {
1732 status = dspio_read(codec, buffer++);
1740 while (skip_count < size) {
1741 status = dspio_read(codec, &dummy);
1753 * Construct the SCP header using corresponding fields
1755 static inline unsigned int
1756 make_scp_header(unsigned int target_id, unsigned int source_id,
1757 unsigned int get_flag, unsigned int req,
1758 unsigned int device_flag, unsigned int resp_flag,
1759 unsigned int error_flag, unsigned int data_size)
1761 unsigned int header = 0;
1763 header = (data_size & 0x1f) << 27;
1764 header |= (error_flag & 0x01) << 26;
1765 header |= (resp_flag & 0x01) << 25;
1766 header |= (device_flag & 0x01) << 24;
1767 header |= (req & 0x7f) << 17;
1768 header |= (get_flag & 0x01) << 16;
1769 header |= (source_id & 0xff) << 8;
1770 header |= target_id & 0xff;
1776 * Extract corresponding fields from SCP header
1779 extract_scp_header(unsigned int header,
1780 unsigned int *target_id, unsigned int *source_id,
1781 unsigned int *get_flag, unsigned int *req,
1782 unsigned int *device_flag, unsigned int *resp_flag,
1783 unsigned int *error_flag, unsigned int *data_size)
1786 *data_size = (header >> 27) & 0x1f;
1788 *error_flag = (header >> 26) & 0x01;
1790 *resp_flag = (header >> 25) & 0x01;
1792 *device_flag = (header >> 24) & 0x01;
1794 *req = (header >> 17) & 0x7f;
1796 *get_flag = (header >> 16) & 0x01;
1798 *source_id = (header >> 8) & 0xff;
1800 *target_id = header & 0xff;
1803 #define SCP_MAX_DATA_WORDS (16)
1805 /* Structure to contain any SCP message */
1808 unsigned int data[SCP_MAX_DATA_WORDS];
1811 static void dspio_clear_response_queue(struct hda_codec *codec)
1813 unsigned int dummy = 0;
1816 /* clear all from the response queue */
1818 status = dspio_read(codec, &dummy);
1819 } while (status == 0);
1822 static int dspio_get_response_data(struct hda_codec *codec)
1824 struct ca0132_spec *spec = codec->spec;
1825 unsigned int data = 0;
1828 if (dspio_read(codec, &data) < 0)
1831 if ((data & 0x00ffffff) == spec->wait_scp_header) {
1832 spec->scp_resp_header = data;
1833 spec->scp_resp_count = data >> 27;
1834 count = spec->wait_num_data;
1835 dspio_read_multiple(codec, spec->scp_resp_data,
1836 &spec->scp_resp_count, count);
1844 * Send SCP message to DSP
1846 static int dspio_send_scp_message(struct hda_codec *codec,
1847 unsigned char *send_buf,
1848 unsigned int send_buf_size,
1849 unsigned char *return_buf,
1850 unsigned int return_buf_size,
1851 unsigned int *bytes_returned)
1853 struct ca0132_spec *spec = codec->spec;
1855 unsigned int scp_send_size = 0;
1856 unsigned int total_size;
1857 bool waiting_for_resp = false;
1858 unsigned int header;
1859 struct scp_msg *ret_msg;
1860 unsigned int resp_src_id, resp_target_id;
1861 unsigned int data_size, src_id, target_id, get_flag, device_flag;
1864 *bytes_returned = 0;
1866 /* get scp header from buffer */
1867 header = *((unsigned int *)send_buf);
1868 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
1869 &device_flag, NULL, NULL, &data_size);
1870 scp_send_size = data_size + 1;
1871 total_size = (scp_send_size * 4);
1873 if (send_buf_size < total_size)
1876 if (get_flag || device_flag) {
1877 if (!return_buf || return_buf_size < 4 || !bytes_returned)
1880 spec->wait_scp_header = *((unsigned int *)send_buf);
1882 /* swap source id with target id */
1883 resp_target_id = src_id;
1884 resp_src_id = target_id;
1885 spec->wait_scp_header &= 0xffff0000;
1886 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
1887 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
1889 waiting_for_resp = true;
1892 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
1899 if (waiting_for_resp) {
1900 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1901 memset(return_buf, 0, return_buf_size);
1904 } while (spec->wait_scp && time_before(jiffies, timeout));
1905 waiting_for_resp = false;
1906 if (!spec->wait_scp) {
1907 ret_msg = (struct scp_msg *)return_buf;
1908 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
1909 memcpy(&ret_msg->data, spec->scp_resp_data,
1910 spec->wait_num_data);
1911 *bytes_returned = (spec->scp_resp_count + 1) * 4;
1923 * Prepare and send the SCP message to DSP
1924 * @codec: the HDA codec
1925 * @mod_id: ID of the DSP module to send the command
1926 * @req: ID of request to send to the DSP module
1928 * @data: pointer to the data to send with the request, request specific
1929 * @len: length of the data, in bytes
1930 * @reply: point to the buffer to hold data returned for a reply
1931 * @reply_len: length of the reply buffer returned from GET
1933 * Returns zero or a negative error code.
1935 static int dspio_scp(struct hda_codec *codec,
1936 int mod_id, int src_id, int req, int dir, const void *data,
1937 unsigned int len, void *reply, unsigned int *reply_len)
1940 struct scp_msg scp_send, scp_reply;
1941 unsigned int ret_bytes, send_size, ret_size;
1942 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
1943 unsigned int reply_data_size;
1945 memset(&scp_send, 0, sizeof(scp_send));
1946 memset(&scp_reply, 0, sizeof(scp_reply));
1948 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
1951 if (dir == SCP_GET && reply == NULL) {
1952 codec_dbg(codec, "dspio_scp get but has no buffer\n");
1956 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
1957 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
1961 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
1962 0, 0, 0, len/sizeof(unsigned int));
1963 if (data != NULL && len > 0) {
1964 len = min((unsigned int)(sizeof(scp_send.data)), len);
1965 memcpy(scp_send.data, data, len);
1969 send_size = sizeof(unsigned int) + len;
1970 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
1971 send_size, (unsigned char *)&scp_reply,
1972 sizeof(scp_reply), &ret_bytes);
1975 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
1979 /* extract send and reply headers members */
1980 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
1981 NULL, NULL, NULL, NULL, NULL);
1982 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
1983 &reply_resp_flag, &reply_error_flag,
1989 if (reply_resp_flag && !reply_error_flag) {
1990 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
1991 / sizeof(unsigned int);
1993 if (*reply_len < ret_size*sizeof(unsigned int)) {
1994 codec_dbg(codec, "reply too long for buf\n");
1996 } else if (ret_size != reply_data_size) {
1997 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
1999 } else if (!reply) {
2000 codec_dbg(codec, "NULL reply\n");
2003 *reply_len = ret_size*sizeof(unsigned int);
2004 memcpy(reply, scp_reply.data, *reply_len);
2007 codec_dbg(codec, "reply ill-formed or errflag set\n");
2015 * Set DSP parameters
2017 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2018 int src_id, int req, const void *data, unsigned int len)
2020 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2024 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2025 int req, const unsigned int data)
2027 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2028 sizeof(unsigned int));
2031 static int dspio_set_uint_param_no_source(struct hda_codec *codec, int mod_id,
2032 int req, const unsigned int data)
2034 return dspio_set_param(codec, mod_id, 0x00, req, &data,
2035 sizeof(unsigned int));
2039 * Allocate a DSP DMA channel via an SCP message
2041 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2044 unsigned int size = sizeof(dma_chan);
2046 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2047 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2048 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
2052 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2056 if ((*dma_chan + 1) == 0) {
2057 codec_dbg(codec, "no free dma channels to allocate\n");
2061 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2062 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2068 * Free a DSP DMA via an SCP message
2070 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2073 unsigned int dummy = 0;
2075 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2076 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2078 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2079 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
2080 sizeof(dma_chan), NULL, &dummy);
2083 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2087 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2095 static int dsp_set_run_state(struct hda_codec *codec)
2097 unsigned int dbg_ctrl_reg;
2098 unsigned int halt_state;
2101 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2105 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
2106 DSP_DBGCNTL_STATE_LOBIT;
2108 if (halt_state != 0) {
2109 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
2110 DSP_DBGCNTL_SS_MASK);
2111 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2116 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
2117 DSP_DBGCNTL_EXEC_MASK;
2118 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2130 static int dsp_reset(struct hda_codec *codec)
2135 codec_dbg(codec, "dsp_reset\n");
2137 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2139 } while (res == -EIO && retry);
2142 codec_dbg(codec, "dsp_reset timeout\n");
2150 * Convert chip address to DSP address
2152 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2153 bool *code, bool *yram)
2155 *code = *yram = false;
2157 if (UC_RANGE(chip_addx, 1)) {
2159 return UC_OFF(chip_addx);
2160 } else if (X_RANGE_ALL(chip_addx, 1)) {
2161 return X_OFF(chip_addx);
2162 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2164 return Y_OFF(chip_addx);
2167 return INVALID_CHIP_ADDRESS;
2171 * Check if the DSP DMA is active
2173 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2175 unsigned int dma_chnlstart_reg;
2177 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2179 return ((dma_chnlstart_reg & (1 <<
2180 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2183 static int dsp_dma_setup_common(struct hda_codec *codec,
2184 unsigned int chip_addx,
2185 unsigned int dma_chan,
2186 unsigned int port_map_mask,
2190 unsigned int chnl_prop;
2191 unsigned int dsp_addx;
2192 unsigned int active;
2195 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2197 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2198 codec_dbg(codec, "dma chan num invalid\n");
2202 if (dsp_is_dma_active(codec, dma_chan)) {
2203 codec_dbg(codec, "dma already active\n");
2207 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2209 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2210 codec_dbg(codec, "invalid chip addr\n");
2214 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2217 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2220 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2224 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2227 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2231 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2233 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2235 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2237 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2239 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2242 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2245 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2249 codec_dbg(codec, "read ACTIVE Reg fail\n");
2252 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2255 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2256 DSPDMAC_ACTIVE_AAR_MASK;
2258 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2260 codec_dbg(codec, "write ACTIVE Reg fail\n");
2264 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2266 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2269 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2272 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2274 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2275 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2277 codec_dbg(codec, "write IRQCNT Reg fail\n");
2280 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2283 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2284 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2285 chip_addx, dsp_addx, dma_chan,
2286 port_map_mask, chnl_prop, active);
2288 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2294 * Setup the DSP DMA per-transfer-specific registers
2296 static int dsp_dma_setup(struct hda_codec *codec,
2297 unsigned int chip_addx,
2299 unsigned int dma_chan)
2303 unsigned int dsp_addx;
2304 unsigned int addr_field;
2305 unsigned int incr_field;
2306 unsigned int base_cnt;
2307 unsigned int cur_cnt;
2308 unsigned int dma_cfg = 0;
2309 unsigned int adr_ofs = 0;
2310 unsigned int xfr_cnt = 0;
2311 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2312 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2314 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2316 if (count > max_dma_count) {
2317 codec_dbg(codec, "count too big\n");
2321 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2322 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2323 codec_dbg(codec, "invalid chip addr\n");
2327 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2329 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2335 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2337 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2340 dma_cfg = addr_field + incr_field;
2341 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2344 codec_dbg(codec, "write DMACFG Reg fail\n");
2347 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2349 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2352 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2355 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2358 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2360 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2362 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2364 xfr_cnt = base_cnt | cur_cnt;
2366 status = chipio_write(codec,
2367 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2369 codec_dbg(codec, "write XFRCNT Reg fail\n");
2372 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2375 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2376 "ADROFS=0x%x, XFRCNT=0x%x\n",
2377 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2379 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2387 static int dsp_dma_start(struct hda_codec *codec,
2388 unsigned int dma_chan, bool ovly)
2390 unsigned int reg = 0;
2393 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2396 status = chipio_read(codec,
2397 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2400 codec_dbg(codec, "read CHNLSTART reg fail\n");
2403 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2405 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2406 DSPDMAC_CHNLSTART_DIS_MASK);
2409 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2410 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2412 codec_dbg(codec, "write CHNLSTART reg fail\n");
2415 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2423 static int dsp_dma_stop(struct hda_codec *codec,
2424 unsigned int dma_chan, bool ovly)
2426 unsigned int reg = 0;
2429 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2432 status = chipio_read(codec,
2433 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2436 codec_dbg(codec, "read CHNLSTART reg fail\n");
2439 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2440 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2441 DSPDMAC_CHNLSTART_DIS_MASK);
2444 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2445 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2447 codec_dbg(codec, "write CHNLSTART reg fail\n");
2450 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2456 * Allocate router ports
2458 * @codec: the HDA codec
2459 * @num_chans: number of channels in the stream
2460 * @ports_per_channel: number of ports per channel
2461 * @start_device: start device
2462 * @port_map: pointer to the port list to hold the allocated ports
2464 * Returns zero or a negative error code.
2466 static int dsp_allocate_router_ports(struct hda_codec *codec,
2467 unsigned int num_chans,
2468 unsigned int ports_per_channel,
2469 unsigned int start_device,
2470 unsigned int *port_map)
2476 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2480 val = start_device << 6;
2481 val |= (ports_per_channel - 1) << 4;
2482 val |= num_chans - 1;
2484 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2485 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2488 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2489 VENDOR_CHIPIO_PORT_ALLOC_SET,
2492 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2496 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2497 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2501 return (res < 0) ? res : 0;
2507 static int dsp_free_router_ports(struct hda_codec *codec)
2511 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2515 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2516 VENDOR_CHIPIO_PORT_FREE_SET,
2519 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2525 * Allocate DSP ports for the download stream
2527 static int dsp_allocate_ports(struct hda_codec *codec,
2528 unsigned int num_chans,
2529 unsigned int rate_multi, unsigned int *port_map)
2533 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2535 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2536 codec_dbg(codec, "bad rate multiple\n");
2540 status = dsp_allocate_router_ports(codec, num_chans,
2541 rate_multi, 0, port_map);
2543 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2548 static int dsp_allocate_ports_format(struct hda_codec *codec,
2549 const unsigned short fmt,
2550 unsigned int *port_map)
2553 unsigned int num_chans;
2555 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2556 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2557 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2559 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2560 codec_dbg(codec, "bad rate multiple\n");
2564 num_chans = get_hdafmt_chs(fmt) + 1;
2566 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2574 static int dsp_free_ports(struct hda_codec *codec)
2578 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2580 status = dsp_free_router_ports(codec);
2582 codec_dbg(codec, "free router ports fail\n");
2585 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2591 * HDA DMA engine stuffs for DSP code download
2594 struct hda_codec *codec;
2595 unsigned short m_converter_format;
2596 struct snd_dma_buffer *dmab;
2597 unsigned int buf_size;
2606 static int dma_convert_to_hda_format(struct hda_codec *codec,
2607 unsigned int sample_rate,
2608 unsigned short channels,
2609 unsigned short *hda_format)
2611 unsigned int format_val;
2613 format_val = snd_hdac_calc_stream_format(sample_rate,
2614 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
2617 *hda_format = (unsigned short)format_val;
2623 * Reset DMA for DSP download
2625 static int dma_reset(struct dma_engine *dma)
2627 struct hda_codec *codec = dma->codec;
2628 struct ca0132_spec *spec = codec->spec;
2631 if (dma->dmab->area)
2632 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2634 status = snd_hda_codec_load_dsp_prepare(codec,
2635 dma->m_converter_format,
2640 spec->dsp_stream_id = status;
2644 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2649 case DMA_STATE_STOP:
2659 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2663 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2665 return dma->dmab->bytes;
2668 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2670 return dma->dmab->area;
2673 static int dma_xfer(struct dma_engine *dma,
2674 const unsigned int *data,
2677 memcpy(dma->dmab->area, data, count);
2681 static void dma_get_converter_format(
2682 struct dma_engine *dma,
2683 unsigned short *format)
2686 *format = dma->m_converter_format;
2689 static unsigned int dma_get_stream_id(struct dma_engine *dma)
2691 struct ca0132_spec *spec = dma->codec->spec;
2693 return spec->dsp_stream_id;
2696 struct dsp_image_seg {
2703 static const u32 g_magic_value = 0x4c46584d;
2704 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2706 static bool is_valid(const struct dsp_image_seg *p)
2708 return p->magic == g_magic_value;
2711 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
2713 return g_chip_addr_magic_value == p->chip_addr;
2716 static bool is_last(const struct dsp_image_seg *p)
2718 return p->count == 0;
2721 static size_t dsp_sizeof(const struct dsp_image_seg *p)
2723 return sizeof(*p) + p->count*sizeof(u32);
2726 static const struct dsp_image_seg *get_next_seg_ptr(
2727 const struct dsp_image_seg *p)
2729 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
2733 * CA0132 chip DSP transfer stuffs. For DSP download.
2735 #define INVALID_DMA_CHANNEL (~0U)
2738 * Program a list of address/data pairs via the ChipIO widget.
2739 * The segment data is in the format of successive pairs of words.
2740 * These are repeated as indicated by the segment's count field.
2742 static int dspxfr_hci_write(struct hda_codec *codec,
2743 const struct dsp_image_seg *fls)
2749 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
2750 codec_dbg(codec, "hci_write invalid params\n");
2755 data = (u32 *)(fls->data);
2756 while (count >= 2) {
2757 status = chipio_write(codec, data[0], data[1]);
2759 codec_dbg(codec, "hci_write chipio failed\n");
2769 * Write a block of data into DSP code or data RAM using pre-allocated
2772 * @codec: the HDA codec
2773 * @fls: pointer to a fast load image
2774 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2776 * @dma_engine: pointer to DMA engine to be used for DSP download
2777 * @dma_chan: The number of DMA channels used for DSP download
2778 * @port_map_mask: port mapping
2779 * @ovly: TRUE if overlay format is required
2781 * Returns zero or a negative error code.
2783 static int dspxfr_one_seg(struct hda_codec *codec,
2784 const struct dsp_image_seg *fls,
2786 struct dma_engine *dma_engine,
2787 unsigned int dma_chan,
2788 unsigned int port_map_mask,
2792 bool comm_dma_setup_done = false;
2793 const unsigned int *data;
2794 unsigned int chip_addx;
2795 unsigned int words_to_write;
2796 unsigned int buffer_size_words;
2797 unsigned char *buffer_addx;
2798 unsigned short hda_format;
2799 unsigned int sample_rate_div;
2800 unsigned int sample_rate_mul;
2801 unsigned int num_chans;
2802 unsigned int hda_frame_size_words;
2803 unsigned int remainder_words;
2804 const u32 *data_remainder;
2805 u32 chip_addx_remainder;
2806 unsigned int run_size_words;
2807 const struct dsp_image_seg *hci_write = NULL;
2808 unsigned long timeout;
2813 if (is_hci_prog_list_seg(fls)) {
2815 fls = get_next_seg_ptr(fls);
2818 if (hci_write && (!fls || is_last(fls))) {
2819 codec_dbg(codec, "hci_write\n");
2820 return dspxfr_hci_write(codec, hci_write);
2823 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2824 codec_dbg(codec, "Invalid Params\n");
2829 chip_addx = fls->chip_addr,
2830 words_to_write = fls->count;
2832 if (!words_to_write)
2833 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
2835 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
2837 if (!UC_RANGE(chip_addx, words_to_write) &&
2838 !X_RANGE_ALL(chip_addx, words_to_write) &&
2839 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2840 codec_dbg(codec, "Invalid chip_addx Params\n");
2844 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
2847 buffer_addx = dma_get_buffer_addr(dma_engine);
2849 if (buffer_addx == NULL) {
2850 codec_dbg(codec, "dma_engine buffer NULL\n");
2854 dma_get_converter_format(dma_engine, &hda_format);
2855 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
2856 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
2857 num_chans = get_hdafmt_chs(hda_format) + 1;
2859 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
2860 (num_chans * sample_rate_mul / sample_rate_div));
2862 if (hda_frame_size_words == 0) {
2863 codec_dbg(codec, "frmsz zero\n");
2867 buffer_size_words = min(buffer_size_words,
2868 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2870 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2872 "chpadr=0x%08x frmsz=%u nchan=%u "
2873 "rate_mul=%u div=%u bufsz=%u\n",
2874 chip_addx, hda_frame_size_words, num_chans,
2875 sample_rate_mul, sample_rate_div, buffer_size_words);
2877 if (buffer_size_words < hda_frame_size_words) {
2878 codec_dbg(codec, "dspxfr_one_seg:failed\n");
2882 remainder_words = words_to_write % hda_frame_size_words;
2883 data_remainder = data;
2884 chip_addx_remainder = chip_addx;
2886 data += remainder_words;
2887 chip_addx += remainder_words*sizeof(u32);
2888 words_to_write -= remainder_words;
2890 while (words_to_write != 0) {
2891 run_size_words = min(buffer_size_words, words_to_write);
2892 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2893 words_to_write, run_size_words, remainder_words);
2894 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2895 if (!comm_dma_setup_done) {
2896 status = dsp_dma_stop(codec, dma_chan, ovly);
2899 status = dsp_dma_setup_common(codec, chip_addx,
2900 dma_chan, port_map_mask, ovly);
2903 comm_dma_setup_done = true;
2906 status = dsp_dma_setup(codec, chip_addx,
2907 run_size_words, dma_chan);
2910 status = dsp_dma_start(codec, dma_chan, ovly);
2913 if (!dsp_is_dma_active(codec, dma_chan)) {
2914 codec_dbg(codec, "dspxfr:DMA did not start\n");
2917 status = dma_set_state(dma_engine, DMA_STATE_RUN);
2920 if (remainder_words != 0) {
2921 status = chipio_write_multiple(codec,
2922 chip_addx_remainder,
2927 remainder_words = 0;
2930 status = dspxfr_hci_write(codec, hci_write);
2936 timeout = jiffies + msecs_to_jiffies(2000);
2938 dma_active = dsp_is_dma_active(codec, dma_chan);
2942 } while (time_before(jiffies, timeout));
2946 codec_dbg(codec, "+++++ DMA complete\n");
2947 dma_set_state(dma_engine, DMA_STATE_STOP);
2948 status = dma_reset(dma_engine);
2953 data += run_size_words;
2954 chip_addx += run_size_words*sizeof(u32);
2955 words_to_write -= run_size_words;
2958 if (remainder_words != 0) {
2959 status = chipio_write_multiple(codec, chip_addx_remainder,
2960 data_remainder, remainder_words);
2967 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2969 * @codec: the HDA codec
2970 * @fls_data: pointer to a fast load image
2971 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2973 * @sample_rate: sampling rate of the stream used for DSP download
2974 * @channels: channels of the stream used for DSP download
2975 * @ovly: TRUE if overlay format is required
2977 * Returns zero or a negative error code.
2979 static int dspxfr_image(struct hda_codec *codec,
2980 const struct dsp_image_seg *fls_data,
2982 unsigned int sample_rate,
2983 unsigned short channels,
2986 struct ca0132_spec *spec = codec->spec;
2988 unsigned short hda_format = 0;
2989 unsigned int response;
2990 unsigned char stream_id = 0;
2991 struct dma_engine *dma_engine;
2992 unsigned int dma_chan;
2993 unsigned int port_map_mask;
2995 if (fls_data == NULL)
2998 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
3002 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
3003 if (!dma_engine->dmab) {
3008 dma_engine->codec = codec;
3009 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3010 dma_engine->m_converter_format = hda_format;
3011 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
3012 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
3014 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
3016 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3017 hda_format, &response);
3020 codec_dbg(codec, "set converter format fail\n");
3024 status = snd_hda_codec_load_dsp_prepare(codec,
3025 dma_engine->m_converter_format,
3026 dma_engine->buf_size,
3030 spec->dsp_stream_id = status;
3033 status = dspio_alloc_dma_chan(codec, &dma_chan);
3035 codec_dbg(codec, "alloc dmachan fail\n");
3036 dma_chan = INVALID_DMA_CHANNEL;
3042 status = dsp_allocate_ports_format(codec, hda_format,
3045 codec_dbg(codec, "alloc ports fail\n");
3049 stream_id = dma_get_stream_id(dma_engine);
3050 status = codec_set_converter_stream_channel(codec,
3051 WIDGET_CHIP_CTRL, stream_id, 0, &response);
3053 codec_dbg(codec, "set stream chan fail\n");
3057 while ((fls_data != NULL) && !is_last(fls_data)) {
3058 if (!is_valid(fls_data)) {
3059 codec_dbg(codec, "FLS check fail\n");
3063 status = dspxfr_one_seg(codec, fls_data, reloc,
3064 dma_engine, dma_chan,
3065 port_map_mask, ovly);
3069 if (is_hci_prog_list_seg(fls_data))
3070 fls_data = get_next_seg_ptr(fls_data);
3072 if ((fls_data != NULL) && !is_last(fls_data))
3073 fls_data = get_next_seg_ptr(fls_data);
3076 if (port_map_mask != 0)
3077 status = dsp_free_ports(codec);
3082 status = codec_set_converter_stream_channel(codec,
3083 WIDGET_CHIP_CTRL, 0, 0, &response);
3086 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
3087 dspio_free_dma_chan(codec, dma_chan);
3089 if (dma_engine->dmab->area)
3090 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3091 kfree(dma_engine->dmab);
3098 * CA0132 DSP download stuffs.
3100 static void dspload_post_setup(struct hda_codec *codec)
3102 struct ca0132_spec *spec = codec->spec;
3103 codec_dbg(codec, "---- dspload_post_setup ------\n");
3104 if (!spec->use_alt_functions) {
3105 /*set DSP speaker to 2.0 configuration*/
3106 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3107 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3109 /*update write pointer*/
3110 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3115 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3117 * @codec: the HDA codec
3118 * @fls: pointer to a fast load image
3119 * @ovly: TRUE if overlay format is required
3120 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3122 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3123 * @router_chans: number of audio router channels to be allocated (0 means use
3124 * internal defaults; max is 32)
3126 * Download DSP from a DSP Image Fast Load structure. This structure is a
3127 * linear, non-constant sized element array of structures, each of which
3128 * contain the count of the data to be loaded, the data itself, and the
3129 * corresponding starting chip address of the starting data location.
3130 * Returns zero or a negative error code.
3132 static int dspload_image(struct hda_codec *codec,
3133 const struct dsp_image_seg *fls,
3140 unsigned int sample_rate;
3141 unsigned short channels;
3143 codec_dbg(codec, "---- dspload_image begin ------\n");
3144 if (router_chans == 0) {
3146 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3148 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3151 sample_rate = 48000;
3152 channels = (unsigned short)router_chans;
3154 while (channels > 16) {
3160 codec_dbg(codec, "Ready to program DMA\n");
3162 status = dsp_reset(codec);
3167 codec_dbg(codec, "dsp_reset() complete\n");
3168 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3174 codec_dbg(codec, "dspxfr_image() complete\n");
3175 if (autostart && !ovly) {
3176 dspload_post_setup(codec);
3177 status = dsp_set_run_state(codec);
3180 codec_dbg(codec, "LOAD FINISHED\n");
3186 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3187 static bool dspload_is_loaded(struct hda_codec *codec)
3189 unsigned int data = 0;
3192 status = chipio_read(codec, 0x40004, &data);
3193 if ((status < 0) || (data != 1))
3199 #define dspload_is_loaded(codec) false
3202 static bool dspload_wait_loaded(struct hda_codec *codec)
3204 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3207 if (dspload_is_loaded(codec)) {
3208 codec_info(codec, "ca0132 DSP downloaded and running\n");
3212 } while (time_before(jiffies, timeout));
3214 codec_err(codec, "ca0132 failed to download DSP\n");
3219 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3220 * based cards, and has a second mmio region, region2, that's used for special
3225 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3226 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3227 * The first eight bits are just the number of the pin. So far, I've only seen
3228 * this number go to 7.
3229 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3230 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3231 * then off to send that bit.
3233 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3236 struct ca0132_spec *spec = codec->spec;
3237 unsigned short gpio_data;
3239 gpio_data = gpio_pin & 0xF;
3240 gpio_data |= ((enable << 8) & 0x100);
3242 writew(gpio_data, spec->mem_base + 0x320);
3246 * Special pci region2 commands that are only used by the AE-5. They follow
3247 * a set format, and require reads at certain points to seemingly 'clear'
3248 * the response data. My first tests didn't do these reads, and would cause
3249 * the card to get locked up until the memory was read. These commands
3250 * seem to work with three distinct values that I've taken to calling group,
3251 * target-id, and value.
3253 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3254 unsigned int target, unsigned int value)
3256 struct ca0132_spec *spec = codec->spec;
3257 unsigned int write_val;
3259 writel(0x0000007e, spec->mem_base + 0x210);
3260 readl(spec->mem_base + 0x210);
3261 writel(0x0000005a, spec->mem_base + 0x210);
3262 readl(spec->mem_base + 0x210);
3263 readl(spec->mem_base + 0x210);
3265 writel(0x00800005, spec->mem_base + 0x20c);
3266 writel(group, spec->mem_base + 0x804);
3268 writel(0x00800005, spec->mem_base + 0x20c);
3269 write_val = (target & 0xff);
3270 write_val |= (value << 8);
3273 writel(write_val, spec->mem_base + 0x204);
3275 * Need delay here or else it goes too fast and works inconsistently.
3279 readl(spec->mem_base + 0x860);
3280 readl(spec->mem_base + 0x854);
3281 readl(spec->mem_base + 0x840);
3283 writel(0x00800004, spec->mem_base + 0x20c);
3284 writel(0x00000000, spec->mem_base + 0x210);
3285 readl(spec->mem_base + 0x210);
3286 readl(spec->mem_base + 0x210);
3290 * This second type of command is used for setting the sound filter type.
3292 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3293 unsigned int group, unsigned int target, unsigned int value)
3295 struct ca0132_spec *spec = codec->spec;
3296 unsigned int write_val;
3298 writel(0x0000007e, spec->mem_base + 0x210);
3299 readl(spec->mem_base + 0x210);
3300 writel(0x0000005a, spec->mem_base + 0x210);
3301 readl(spec->mem_base + 0x210);
3302 readl(spec->mem_base + 0x210);
3304 writel(0x00800003, spec->mem_base + 0x20c);
3305 writel(group, spec->mem_base + 0x804);
3307 writel(0x00800005, spec->mem_base + 0x20c);
3308 write_val = (target & 0xff);
3309 write_val |= (value << 8);
3312 writel(write_val, spec->mem_base + 0x204);
3314 readl(spec->mem_base + 0x860);
3315 readl(spec->mem_base + 0x854);
3316 readl(spec->mem_base + 0x840);
3318 writel(0x00800004, spec->mem_base + 0x20c);
3319 writel(0x00000000, spec->mem_base + 0x210);
3320 readl(spec->mem_base + 0x210);
3321 readl(spec->mem_base + 0x210);
3325 * Setup GPIO for the other variants of Core3D.
3329 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3330 * the card shows as having no GPIO pins.
3332 static void ca0132_gpio_init(struct hda_codec *codec)
3334 struct ca0132_spec *spec = codec->spec;
3336 switch (spec->quirk) {
3339 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3340 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3341 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3344 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3345 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3351 /* Sets the GPIO for audio output. */
3352 static void ca0132_gpio_setup(struct hda_codec *codec)
3354 struct ca0132_spec *spec = codec->spec;
3356 switch (spec->quirk) {
3358 snd_hda_codec_write(codec, 0x01, 0,
3359 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3360 snd_hda_codec_write(codec, 0x01, 0,
3361 AC_VERB_SET_GPIO_MASK, 0x07);
3362 snd_hda_codec_write(codec, 0x01, 0,
3363 AC_VERB_SET_GPIO_DATA, 0x04);
3364 snd_hda_codec_write(codec, 0x01, 0,
3365 AC_VERB_SET_GPIO_DATA, 0x06);
3368 snd_hda_codec_write(codec, 0x01, 0,
3369 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3370 snd_hda_codec_write(codec, 0x01, 0,
3371 AC_VERB_SET_GPIO_MASK, 0x1F);
3372 snd_hda_codec_write(codec, 0x01, 0,
3373 AC_VERB_SET_GPIO_DATA, 0x0C);
3379 * GPIO control functions for the Recon3D integrated.
3382 enum r3di_gpio_bit {
3383 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3384 R3DI_MIC_SELECT_BIT = 1,
3385 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3386 R3DI_OUT_SELECT_BIT = 2,
3388 * I dunno what this actually does, but it stays on until the dsp
3391 R3DI_GPIO_DSP_DOWNLOADING = 3,
3393 * Same as above, no clue what it does, but it comes on after the dsp
3396 R3DI_GPIO_DSP_DOWNLOADED = 4
3399 enum r3di_mic_select {
3400 /* Set GPIO bit 1 to 0 for rear mic */
3402 /* Set GPIO bit 1 to 1 for front microphone*/
3406 enum r3di_out_select {
3407 /* Set GPIO bit 2 to 0 for headphone */
3408 R3DI_HEADPHONE_OUT = 0,
3409 /* Set GPIO bit 2 to 1 for speaker */
3412 enum r3di_dsp_status {
3413 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3414 R3DI_DSP_DOWNLOADING = 0,
3415 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3416 R3DI_DSP_DOWNLOADED = 1
3420 static void r3di_gpio_mic_set(struct hda_codec *codec,
3421 enum r3di_mic_select cur_mic)
3423 unsigned int cur_gpio;
3425 /* Get the current GPIO Data setup */
3426 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3430 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3432 case R3DI_FRONT_MIC:
3433 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3436 snd_hda_codec_write(codec, codec->core.afg, 0,
3437 AC_VERB_SET_GPIO_DATA, cur_gpio);
3440 static void r3di_gpio_out_set(struct hda_codec *codec,
3441 enum r3di_out_select cur_out)
3443 unsigned int cur_gpio;
3445 /* Get the current GPIO Data setup */
3446 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3449 case R3DI_HEADPHONE_OUT:
3450 cur_gpio &= ~(1 << R3DI_OUT_SELECT_BIT);
3453 cur_gpio |= (1 << R3DI_OUT_SELECT_BIT);
3456 snd_hda_codec_write(codec, codec->core.afg, 0,
3457 AC_VERB_SET_GPIO_DATA, cur_gpio);
3460 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3461 enum r3di_dsp_status dsp_status)
3463 unsigned int cur_gpio;
3465 /* Get the current GPIO Data setup */
3466 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3468 switch (dsp_status) {
3469 case R3DI_DSP_DOWNLOADING:
3470 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3471 snd_hda_codec_write(codec, codec->core.afg, 0,
3472 AC_VERB_SET_GPIO_DATA, cur_gpio);
3474 case R3DI_DSP_DOWNLOADED:
3475 /* Set DOWNLOADING bit to 0. */
3476 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3478 snd_hda_codec_write(codec, codec->core.afg, 0,
3479 AC_VERB_SET_GPIO_DATA, cur_gpio);
3481 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3485 snd_hda_codec_write(codec, codec->core.afg, 0,
3486 AC_VERB_SET_GPIO_DATA, cur_gpio);
3492 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3493 struct hda_codec *codec,
3494 unsigned int stream_tag,
3495 unsigned int format,
3496 struct snd_pcm_substream *substream)
3498 struct ca0132_spec *spec = codec->spec;
3500 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3505 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3506 struct hda_codec *codec,
3507 struct snd_pcm_substream *substream)
3509 struct ca0132_spec *spec = codec->spec;
3511 if (spec->dsp_state == DSP_DOWNLOADING)
3514 /*If Playback effects are on, allow stream some time to flush
3516 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3519 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3524 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3525 struct hda_codec *codec,
3526 struct snd_pcm_substream *substream)
3528 struct ca0132_spec *spec = codec->spec;
3529 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3530 struct snd_pcm_runtime *runtime = substream->runtime;
3532 if (spec->dsp_state != DSP_DOWNLOADED)
3535 /* Add latency if playback enhancement and either effect is enabled. */
3536 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3537 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3538 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3539 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3542 /* Applying Speaker EQ adds latency as well. */
3543 if (spec->cur_out_type == SPEAKER_OUT)
3544 latency += DSP_SPEAKER_OUT_LATENCY;
3546 return (latency * runtime->rate) / 1000;
3552 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3553 struct hda_codec *codec,
3554 struct snd_pcm_substream *substream)
3556 struct ca0132_spec *spec = codec->spec;
3557 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3560 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3561 struct hda_codec *codec,
3562 unsigned int stream_tag,
3563 unsigned int format,
3564 struct snd_pcm_substream *substream)
3566 struct ca0132_spec *spec = codec->spec;
3567 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3568 stream_tag, format, substream);
3571 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3572 struct hda_codec *codec,
3573 struct snd_pcm_substream *substream)
3575 struct ca0132_spec *spec = codec->spec;
3576 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3579 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3580 struct hda_codec *codec,
3581 struct snd_pcm_substream *substream)
3583 struct ca0132_spec *spec = codec->spec;
3584 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3590 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3591 struct hda_codec *codec,
3592 unsigned int stream_tag,
3593 unsigned int format,
3594 struct snd_pcm_substream *substream)
3596 snd_hda_codec_setup_stream(codec, hinfo->nid,
3597 stream_tag, 0, format);
3602 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3603 struct hda_codec *codec,
3604 struct snd_pcm_substream *substream)
3606 struct ca0132_spec *spec = codec->spec;
3608 if (spec->dsp_state == DSP_DOWNLOADING)
3611 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3615 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
3616 struct hda_codec *codec,
3617 struct snd_pcm_substream *substream)
3619 struct ca0132_spec *spec = codec->spec;
3620 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
3621 struct snd_pcm_runtime *runtime = substream->runtime;
3623 if (spec->dsp_state != DSP_DOWNLOADED)
3626 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3627 latency += DSP_CRYSTAL_VOICE_LATENCY;
3629 return (latency * runtime->rate) / 1000;
3637 * Mixer controls helpers.
3639 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
3640 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3642 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3643 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3644 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3645 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3646 .info = ca0132_volume_info, \
3647 .get = ca0132_volume_get, \
3648 .put = ca0132_volume_put, \
3649 .tlv = { .c = ca0132_volume_tlv }, \
3650 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3653 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
3654 * volume put, which is used for setting the DSP volume. This was done because
3655 * the ca0132 functions were taking too much time and causing lag.
3657 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
3658 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3660 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3661 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3662 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3663 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3664 .info = snd_hda_mixer_amp_volume_info, \
3665 .get = snd_hda_mixer_amp_volume_get, \
3666 .put = ca0132_alt_volume_put, \
3667 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
3668 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3670 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
3671 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3673 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3674 .info = snd_hda_mixer_amp_switch_info, \
3675 .get = ca0132_switch_get, \
3676 .put = ca0132_switch_put, \
3677 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3680 #define CA0132_CODEC_VOL(xname, nid, dir) \
3681 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
3682 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
3683 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
3684 #define CA0132_CODEC_MUTE(xname, nid, dir) \
3685 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
3689 * Lookup table with decibel values for the DSP. When volume is changed in
3690 * Windows, the DSP is also sent the dB value in floating point. In Windows,
3691 * these values have decimal points, probably because the Windows driver
3692 * actually uses floating point. We can't here, so I made a lookup table of
3693 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
3694 * DAC's, and 9 is the maximum.
3696 static const unsigned int float_vol_db_lookup[] = {
3697 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
3698 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
3699 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
3700 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
3701 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
3702 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
3703 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
3704 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
3705 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
3706 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
3707 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
3708 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3709 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3710 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3711 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3712 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3713 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
3717 * This table counts from float 0 to 1 in increments of .01, which is
3718 * useful for a few different sliders.
3720 static const unsigned int float_zero_to_one_lookup[] = {
3721 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3722 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3723 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3724 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3725 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3726 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3727 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3728 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3729 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3730 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3731 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3732 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3733 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3734 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3735 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3736 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3737 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3741 * This table counts from float 10 to 1000, which is the range of the x-bass
3742 * crossover slider in Windows.
3744 static const unsigned int float_xbass_xover_lookup[] = {
3745 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
3746 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
3747 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
3748 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
3749 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
3750 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
3751 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
3752 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
3753 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
3754 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
3755 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
3756 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
3757 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
3758 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
3759 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
3760 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
3761 0x44728000, 0x44750000, 0x44778000, 0x447A0000
3764 /* The following are for tuning of products */
3765 #ifdef ENABLE_TUNING_CONTROLS
3767 static unsigned int voice_focus_vals_lookup[] = {
3768 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
3769 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
3770 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
3771 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
3772 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
3773 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
3774 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
3775 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
3776 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
3777 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
3778 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
3779 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
3780 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
3781 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
3782 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
3783 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
3784 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
3785 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
3786 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
3787 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
3788 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
3789 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
3790 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
3791 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
3792 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
3793 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
3794 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
3797 static unsigned int mic_svm_vals_lookup[] = {
3798 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3799 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3800 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3801 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3802 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3803 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3804 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3805 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3806 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3807 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3808 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3809 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3810 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3811 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3812 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3813 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3814 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3817 static unsigned int equalizer_vals_lookup[] = {
3818 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3819 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3820 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3821 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3822 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3823 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
3824 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
3825 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
3829 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
3830 unsigned int *lookup, int idx)
3834 for (i = 0; i < TUNING_CTLS_COUNT; i++)
3835 if (nid == ca0132_tuning_ctls[i].nid)
3838 snd_hda_power_up(codec);
3839 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
3840 ca0132_tuning_ctls[i].req,
3841 &(lookup[idx]), sizeof(unsigned int));
3842 snd_hda_power_down(codec);
3847 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
3848 struct snd_ctl_elem_value *ucontrol)
3850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3851 struct ca0132_spec *spec = codec->spec;
3852 hda_nid_t nid = get_amp_nid(kcontrol);
3853 long *valp = ucontrol->value.integer.value;
3854 int idx = nid - TUNING_CTL_START_NID;
3856 *valp = spec->cur_ctl_vals[idx];
3860 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
3861 struct snd_ctl_elem_info *uinfo)
3863 int chs = get_amp_channels(kcontrol);
3864 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3865 uinfo->count = chs == 3 ? 2 : 1;
3866 uinfo->value.integer.min = 20;
3867 uinfo->value.integer.max = 180;
3868 uinfo->value.integer.step = 1;
3873 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
3874 struct snd_ctl_elem_value *ucontrol)
3876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3877 struct ca0132_spec *spec = codec->spec;
3878 hda_nid_t nid = get_amp_nid(kcontrol);
3879 long *valp = ucontrol->value.integer.value;
3882 idx = nid - TUNING_CTL_START_NID;
3884 if (spec->cur_ctl_vals[idx] == *valp)
3887 spec->cur_ctl_vals[idx] = *valp;
3890 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
3895 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
3896 struct snd_ctl_elem_info *uinfo)
3898 int chs = get_amp_channels(kcontrol);
3899 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3900 uinfo->count = chs == 3 ? 2 : 1;
3901 uinfo->value.integer.min = 0;
3902 uinfo->value.integer.max = 100;
3903 uinfo->value.integer.step = 1;
3908 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
3909 struct snd_ctl_elem_value *ucontrol)
3911 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3912 struct ca0132_spec *spec = codec->spec;
3913 hda_nid_t nid = get_amp_nid(kcontrol);
3914 long *valp = ucontrol->value.integer.value;
3917 idx = nid - TUNING_CTL_START_NID;
3919 if (spec->cur_ctl_vals[idx] == *valp)
3922 spec->cur_ctl_vals[idx] = *valp;
3925 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
3930 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
3931 struct snd_ctl_elem_info *uinfo)
3933 int chs = get_amp_channels(kcontrol);
3934 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3935 uinfo->count = chs == 3 ? 2 : 1;
3936 uinfo->value.integer.min = 0;
3937 uinfo->value.integer.max = 48;
3938 uinfo->value.integer.step = 1;
3943 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
3944 struct snd_ctl_elem_value *ucontrol)
3946 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3947 struct ca0132_spec *spec = codec->spec;
3948 hda_nid_t nid = get_amp_nid(kcontrol);
3949 long *valp = ucontrol->value.integer.value;
3952 idx = nid - TUNING_CTL_START_NID;
3954 if (spec->cur_ctl_vals[idx] == *valp)
3957 spec->cur_ctl_vals[idx] = *valp;
3960 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
3965 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
3966 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
3968 static int add_tuning_control(struct hda_codec *codec,
3969 hda_nid_t pnid, hda_nid_t nid,
3970 const char *name, int dir)
3972 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3973 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3974 struct snd_kcontrol_new knew =
3975 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
3977 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3978 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3983 knew.info = voice_focus_ctl_info;
3984 knew.get = tuning_ctl_get;
3985 knew.put = voice_focus_ctl_put;
3986 knew.tlv.p = voice_focus_db_scale;
3989 knew.info = mic_svm_ctl_info;
3990 knew.get = tuning_ctl_get;
3991 knew.put = mic_svm_ctl_put;
3994 knew.info = equalizer_ctl_info;
3995 knew.get = tuning_ctl_get;
3996 knew.put = equalizer_ctl_put;
3997 knew.tlv.p = eq_db_scale;
4002 knew.private_value =
4003 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
4004 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
4005 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
4008 static int add_tuning_ctls(struct hda_codec *codec)
4013 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
4014 err = add_tuning_control(codec,
4015 ca0132_tuning_ctls[i].parent_nid,
4016 ca0132_tuning_ctls[i].nid,
4017 ca0132_tuning_ctls[i].name,
4018 ca0132_tuning_ctls[i].direct);
4026 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
4028 struct ca0132_spec *spec = codec->spec;
4031 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
4032 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
4033 /* SVM level defaults to 0.74. */
4034 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
4036 /* EQ defaults to 0dB. */
4037 for (i = 2; i < TUNING_CTLS_COUNT; i++)
4038 spec->cur_ctl_vals[i] = 24;
4040 #endif /*ENABLE_TUNING_CONTROLS*/
4043 * Select the active output.
4044 * If autodetect is enabled, output will be selected based on jack detection.
4045 * If jack inserted, headphone will be selected, else built-in speakers
4046 * If autodetect is disabled, output will be selected based on selection.
4048 static int ca0132_select_out(struct hda_codec *codec)
4050 struct ca0132_spec *spec = codec->spec;
4051 unsigned int pin_ctl;
4057 codec_dbg(codec, "ca0132_select_out\n");
4059 snd_hda_power_up_pm(codec);
4061 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4064 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
4067 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
4070 spec->cur_out_type = HEADPHONE_OUT;
4072 spec->cur_out_type = SPEAKER_OUT;
4074 if (spec->cur_out_type == SPEAKER_OUT) {
4075 codec_dbg(codec, "ca0132_select_out speaker\n");
4076 /*speaker out config*/
4078 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4081 /*enable speaker EQ*/
4083 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4088 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4089 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4090 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4091 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4092 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4093 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4094 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4095 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4097 /* disable headphone node */
4098 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4099 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4100 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4102 /* enable speaker node */
4103 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4104 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4105 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4108 codec_dbg(codec, "ca0132_select_out hp\n");
4109 /*headphone out config*/
4111 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4114 /*disable speaker EQ*/
4116 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4121 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4122 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4123 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4124 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4125 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4126 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4127 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4128 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4130 /* disable speaker*/
4131 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4132 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4133 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4135 /* enable headphone*/
4136 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4137 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4138 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4143 snd_hda_power_down_pm(codec);
4145 return err < 0 ? err : 0;
4148 static int ae5_headphone_gain_set(struct hda_codec *codec, long val);
4149 static int zxr_headphone_gain_set(struct hda_codec *codec, long val);
4150 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4152 static void ae5_mmio_select_out(struct hda_codec *codec)
4154 struct ca0132_spec *spec = codec->spec;
4157 for (i = 0; i < AE5_CA0113_OUT_SET_COMMANDS; i++)
4158 ca0113_mmio_command_set(codec,
4159 ae5_ca0113_output_presets[spec->cur_out_type].group[i],
4160 ae5_ca0113_output_presets[spec->cur_out_type].target[i],
4161 ae5_ca0113_output_presets[spec->cur_out_type].vals[i]);
4165 * These are the commands needed to setup output on each of the different card
4168 static void ca0132_alt_select_out_quirk_handler(struct hda_codec *codec)
4170 struct ca0132_spec *spec = codec->spec;
4173 switch (spec->cur_out_type) {
4175 switch (spec->quirk) {
4177 ca0113_mmio_gpio_set(codec, 7, false);
4178 ca0113_mmio_gpio_set(codec, 4, true);
4179 ca0113_mmio_gpio_set(codec, 1, true);
4180 chipio_set_control_param(codec, 0x0d, 0x18);
4183 ca0113_mmio_gpio_set(codec, 2, true);
4184 ca0113_mmio_gpio_set(codec, 3, true);
4185 ca0113_mmio_gpio_set(codec, 5, false);
4186 zxr_headphone_gain_set(codec, 0);
4187 chipio_set_control_param(codec, 0x0d, 0x24);
4190 chipio_set_control_param(codec, 0x0d, 0x24);
4191 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
4194 chipio_set_control_param(codec, 0x0d, 0x24);
4195 ca0113_mmio_gpio_set(codec, 1, true);
4198 ae5_mmio_select_out(codec);
4199 ae5_headphone_gain_set(codec, 2);
4201 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4202 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4203 chipio_set_control_param(codec, 0x0d, 0xa4);
4204 chipio_write(codec, 0x18b03c, 0x00000012);
4209 switch (spec->quirk) {
4211 ca0113_mmio_gpio_set(codec, 7, true);
4212 ca0113_mmio_gpio_set(codec, 4, true);
4213 ca0113_mmio_gpio_set(codec, 1, false);
4214 chipio_set_control_param(codec, 0x0d, 0x12);
4217 ca0113_mmio_gpio_set(codec, 2, false);
4218 ca0113_mmio_gpio_set(codec, 3, false);
4219 ca0113_mmio_gpio_set(codec, 5, true);
4220 zxr_headphone_gain_set(codec, spec->zxr_gain_set);
4221 chipio_set_control_param(codec, 0x0d, 0x21);
4224 chipio_set_control_param(codec, 0x0d, 0x21);
4225 r3di_gpio_out_set(codec, R3DI_HEADPHONE_OUT);
4228 chipio_set_control_param(codec, 0x0d, 0x21);
4229 ca0113_mmio_gpio_set(codec, 0x1, false);
4232 ae5_mmio_select_out(codec);
4233 ae5_headphone_gain_set(codec,
4234 spec->ae5_headphone_gain_val);
4236 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4237 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4238 chipio_set_control_param(codec, 0x0d, 0xa1);
4239 chipio_write(codec, 0x18b03c, 0x00000012);
4244 switch (spec->quirk) {
4246 ca0113_mmio_gpio_set(codec, 7, false);
4247 ca0113_mmio_gpio_set(codec, 4, true);
4248 ca0113_mmio_gpio_set(codec, 1, true);
4249 chipio_set_control_param(codec, 0x0d, 0x18);
4252 ca0113_mmio_gpio_set(codec, 2, true);
4253 ca0113_mmio_gpio_set(codec, 3, true);
4254 ca0113_mmio_gpio_set(codec, 5, false);
4255 zxr_headphone_gain_set(codec, 0);
4256 chipio_set_control_param(codec, 0x0d, 0x24);
4259 chipio_set_control_param(codec, 0x0d, 0x24);
4260 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
4263 ca0113_mmio_gpio_set(codec, 1, true);
4264 chipio_set_control_param(codec, 0x0d, 0x24);
4267 ae5_mmio_select_out(codec);
4268 ae5_headphone_gain_set(codec, 2);
4270 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4271 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4272 chipio_set_control_param(codec, 0x0d, 0xa4);
4273 chipio_write(codec, 0x18b03c, 0x00000012);
4281 * This function behaves similarly to the ca0132_select_out funciton above,
4282 * except with a few differences. It adds the ability to select the current
4283 * output with an enumerated control "output source" if the auto detect
4284 * mute switch is set to off. If the auto detect mute switch is enabled, it
4285 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
4286 * It also adds the ability to auto-detect the front headphone port. The only
4287 * way to select surround is to disable auto detect, and set Surround with the
4288 * enumerated control.
4290 static int ca0132_alt_select_out(struct hda_codec *codec)
4292 struct ca0132_spec *spec = codec->spec;
4293 unsigned int pin_ctl;
4299 /* Default Headphone is rear headphone */
4300 hda_nid_t headphone_nid = spec->out_pins[1];
4302 codec_dbg(codec, "%s\n", __func__);
4304 snd_hda_power_up_pm(codec);
4306 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4309 * If headphone rear or front is plugged in, set to headphone.
4310 * If neither is plugged in, set to rear line out. Only if
4311 * hp/speaker auto detect is enabled.
4314 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
4315 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
4318 spec->cur_out_type = HEADPHONE_OUT;
4320 spec->cur_out_type = SPEAKER_OUT;
4322 spec->cur_out_type = spec->out_enum_val;
4324 /* Begin DSP output switch */
4326 err = dspio_set_uint_param(codec, 0x96, 0x3A, tmp);
4330 ca0132_alt_select_out_quirk_handler(codec);
4332 switch (spec->cur_out_type) {
4334 codec_dbg(codec, "%s speaker\n", __func__);
4336 /* disable headphone node */
4337 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4338 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4339 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4341 /* enable line-out node */
4342 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4343 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4344 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4347 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4348 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4350 /* If PlayEnhancement is enabled, set different source */
4351 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4352 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4354 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4357 codec_dbg(codec, "%s hp\n", __func__);
4359 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4360 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4362 /* disable speaker*/
4363 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4364 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4365 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4368 /* enable headphone, either front or rear */
4370 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4371 headphone_nid = spec->out_pins[2];
4372 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4373 headphone_nid = spec->out_pins[1];
4375 pin_ctl = snd_hda_codec_read(codec, headphone_nid, 0,
4376 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4377 snd_hda_set_pin_ctl(codec, headphone_nid,
4380 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4381 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4383 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4386 codec_dbg(codec, "%s surround\n", __func__);
4388 /* enable line out node */
4389 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4390 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4391 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4393 /* Disable headphone out */
4394 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4395 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4396 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4398 /* Enable EAPD on line out */
4399 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4400 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4401 /* enable center/lfe out node */
4402 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[2], 0,
4403 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4404 snd_hda_set_pin_ctl(codec, spec->out_pins[2],
4406 /* Now set rear surround node as out. */
4407 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[3], 0,
4408 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4409 snd_hda_set_pin_ctl(codec, spec->out_pins[3],
4412 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4416 * Surround always sets it's scp command to req 0x04 to FLOAT_EIGHT.
4417 * With this set though, X_BASS cannot be enabled. So, if we have OutFX
4418 * enabled, we need to make sure X_BASS is off, otherwise everything
4419 * sounds all muffled. Running ca0132_effects_set with X_BASS as the
4420 * effect should sort this out.
4422 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4423 ca0132_effects_set(codec, X_BASS,
4424 spec->effects_switch[X_BASS - EFFECT_START_NID]);
4426 /* run through the output dsp commands for the selected output. */
4427 for (i = 0; i < alt_out_presets[spec->cur_out_type].commands; i++) {
4428 err = dspio_set_uint_param(codec,
4429 alt_out_presets[spec->cur_out_type].mids[i],
4430 alt_out_presets[spec->cur_out_type].reqs[i],
4431 alt_out_presets[spec->cur_out_type].vals[i]);
4438 snd_hda_power_down_pm(codec);
4440 return err < 0 ? err : 0;
4443 static void ca0132_unsol_hp_delayed(struct work_struct *work)
4445 struct ca0132_spec *spec = container_of(
4446 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
4447 struct hda_jack_tbl *jack;
4449 if (spec->use_alt_functions)
4450 ca0132_alt_select_out(spec->codec);
4452 ca0132_select_out(spec->codec);
4454 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4456 jack->block_report = 0;
4457 snd_hda_jack_report_sync(spec->codec);
4461 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4462 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4463 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4464 static int stop_mic1(struct hda_codec *codec);
4465 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4466 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4469 * Select the active VIP source
4471 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4473 struct ca0132_spec *spec = codec->spec;
4476 if (spec->dsp_state != DSP_DOWNLOADED)
4479 /* if CrystalVoice if off, vipsource should be 0 */
4480 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4482 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4483 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4484 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4485 if (spec->cur_mic_type == DIGITAL_MIC)
4489 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4491 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4493 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4494 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4495 if (spec->cur_mic_type == DIGITAL_MIC)
4499 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4501 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4503 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4509 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4511 struct ca0132_spec *spec = codec->spec;
4514 if (spec->dsp_state != DSP_DOWNLOADED)
4517 codec_dbg(codec, "%s\n", __func__);
4519 chipio_set_stream_control(codec, 0x03, 0);
4520 chipio_set_stream_control(codec, 0x04, 0);
4522 /* if CrystalVoice is off, vipsource should be 0 */
4523 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4524 (val == 0) || spec->in_enum_val == REAR_LINE_IN) {
4525 codec_dbg(codec, "%s: off.", __func__);
4526 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4529 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4531 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4532 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4533 if (spec->quirk == QUIRK_R3DI)
4534 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4537 if (spec->in_enum_val == REAR_LINE_IN)
4540 if (spec->quirk == QUIRK_SBZ)
4546 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4549 codec_dbg(codec, "%s: on.", __func__);
4550 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4551 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4552 if (spec->quirk == QUIRK_R3DI)
4553 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
4555 if (spec->effects_switch[VOICE_FOCUS - EFFECT_START_NID])
4559 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4562 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4565 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4568 chipio_set_stream_control(codec, 0x03, 1);
4569 chipio_set_stream_control(codec, 0x04, 1);
4575 * Select the active microphone.
4576 * If autodetect is enabled, mic will be selected based on jack detection.
4577 * If jack inserted, ext.mic will be selected, else built-in mic
4578 * If autodetect is disabled, mic will be selected based on selection.
4580 static int ca0132_select_mic(struct hda_codec *codec)
4582 struct ca0132_spec *spec = codec->spec;
4586 codec_dbg(codec, "ca0132_select_mic\n");
4588 snd_hda_power_up_pm(codec);
4590 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
4593 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
4596 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
4599 spec->cur_mic_type = LINE_MIC_IN;
4601 spec->cur_mic_type = DIGITAL_MIC;
4603 if (spec->cur_mic_type == DIGITAL_MIC) {
4604 /* enable digital Mic */
4605 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
4606 ca0132_set_dmic(codec, 1);
4607 ca0132_mic_boost_set(codec, 0);
4608 /* set voice focus */
4609 ca0132_effects_set(codec, VOICE_FOCUS,
4610 spec->effects_switch
4611 [VOICE_FOCUS - EFFECT_START_NID]);
4613 /* disable digital Mic */
4614 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
4615 ca0132_set_dmic(codec, 0);
4616 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
4617 /* disable voice focus */
4618 ca0132_effects_set(codec, VOICE_FOCUS, 0);
4621 snd_hda_power_down_pm(codec);
4627 * Select the active input.
4628 * Mic detection isn't used, because it's kind of pointless on the SBZ.
4629 * The front mic has no jack-detection, so the only way to switch to it
4630 * is to do it manually in alsamixer.
4632 static int ca0132_alt_select_in(struct hda_codec *codec)
4634 struct ca0132_spec *spec = codec->spec;
4637 codec_dbg(codec, "%s\n", __func__);
4639 snd_hda_power_up_pm(codec);
4641 chipio_set_stream_control(codec, 0x03, 0);
4642 chipio_set_stream_control(codec, 0x04, 0);
4644 spec->cur_mic_type = spec->in_enum_val;
4646 switch (spec->cur_mic_type) {
4648 switch (spec->quirk) {
4651 ca0113_mmio_gpio_set(codec, 0, false);
4658 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4662 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x00);
4670 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4671 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4672 if (spec->quirk == QUIRK_R3DI)
4673 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4675 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4677 chipio_set_stream_control(codec, 0x03, 1);
4678 chipio_set_stream_control(codec, 0x04, 1);
4679 switch (spec->quirk) {
4681 chipio_write(codec, 0x18B098, 0x0000000C);
4682 chipio_write(codec, 0x18B09C, 0x0000000C);
4685 chipio_write(codec, 0x18B098, 0x0000000C);
4686 chipio_write(codec, 0x18B09C, 0x000000CC);
4689 chipio_write(codec, 0x18B098, 0x0000000C);
4690 chipio_write(codec, 0x18B09C, 0x0000004C);
4693 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4696 ca0132_mic_boost_set(codec, 0);
4697 switch (spec->quirk) {
4700 ca0113_mmio_gpio_set(codec, 0, false);
4703 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4706 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x00);
4710 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4711 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4712 if (spec->quirk == QUIRK_R3DI)
4713 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4716 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4718 switch (spec->quirk) {
4721 chipio_write(codec, 0x18B098, 0x00000000);
4722 chipio_write(codec, 0x18B09C, 0x00000000);
4725 chipio_set_stream_control(codec, 0x03, 1);
4726 chipio_set_stream_control(codec, 0x04, 1);
4729 switch (spec->quirk) {
4732 ca0113_mmio_gpio_set(codec, 0, true);
4733 ca0113_mmio_gpio_set(codec, 5, false);
4737 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
4741 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x3f);
4749 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4750 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4751 if (spec->quirk == QUIRK_R3DI)
4752 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4754 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4756 chipio_set_stream_control(codec, 0x03, 1);
4757 chipio_set_stream_control(codec, 0x04, 1);
4759 switch (spec->quirk) {
4761 chipio_write(codec, 0x18B098, 0x0000000C);
4762 chipio_write(codec, 0x18B09C, 0x000000CC);
4765 chipio_write(codec, 0x18B098, 0x0000000C);
4766 chipio_write(codec, 0x18B09C, 0x0000004C);
4769 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4772 ca0132_cvoice_switch_set(codec);
4774 snd_hda_power_down_pm(codec);
4779 * Check if VNODE settings take effect immediately.
4781 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
4783 hda_nid_t *shared_nid)
4785 struct ca0132_spec *spec = codec->spec;
4790 nid = spec->shared_out_nid;
4793 nid = spec->shared_mic_nid;
4806 * The following functions are control change helpers.
4807 * They return 0 if no changed. Return 1 if changed.
4809 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
4811 struct ca0132_spec *spec = codec->spec;
4814 /* based on CrystalVoice state to enable VoiceFX. */
4816 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
4817 FLOAT_ONE : FLOAT_ZERO;
4822 dspio_set_uint_param(codec, ca0132_voicefx.mid,
4823 ca0132_voicefx.reqs[0], tmp);
4829 * Set the effects parameters
4831 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
4833 struct ca0132_spec *spec = codec->spec;
4834 unsigned int on, tmp;
4835 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
4837 int idx = nid - EFFECT_START_NID;
4839 if ((idx < 0) || (idx >= num_fx))
4840 return 0; /* no changed */
4842 /* for out effect, qualify with PE */
4843 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
4844 /* if PE if off, turn off out effects. */
4845 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4847 if (spec->cur_out_type == SURROUND_OUT && nid == X_BASS)
4851 /* for in effect, qualify with CrystalVoice */
4852 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
4853 /* if CrystalVoice if off, turn off in effects. */
4854 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
4857 /* Voice Focus applies to 2-ch Mic, Digital Mic */
4858 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
4861 /* If Voice Focus on SBZ, set to two channel. */
4862 if ((nid == VOICE_FOCUS) && (spec->use_pci_mmio)
4863 && (spec->cur_mic_type != REAR_LINE_IN)) {
4864 if (spec->effects_switch[CRYSTAL_VOICE -
4865 EFFECT_START_NID]) {
4867 if (spec->effects_switch[VOICE_FOCUS -
4868 EFFECT_START_NID]) {
4874 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4878 * For SBZ noise reduction, there's an extra command
4879 * to module ID 0x47. No clue why.
4881 if ((nid == NOISE_REDUCTION) && (spec->use_pci_mmio)
4882 && (spec->cur_mic_type != REAR_LINE_IN)) {
4883 if (spec->effects_switch[CRYSTAL_VOICE -
4884 EFFECT_START_NID]) {
4885 if (spec->effects_switch[NOISE_REDUCTION -
4893 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
4896 /* If rear line in disable effects. */
4897 if (spec->use_alt_functions &&
4898 spec->in_enum_val == REAR_LINE_IN)
4902 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
4905 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
4906 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
4907 ca0132_effects[idx].reqs[0], on);
4910 return 0; /* no changed */
4916 * Turn on/off Playback Enhancements
4918 static int ca0132_pe_switch_set(struct hda_codec *codec)
4920 struct ca0132_spec *spec = codec->spec;
4924 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
4925 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
4927 if (spec->use_alt_functions)
4928 ca0132_alt_select_out(codec);
4930 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
4931 nid = OUT_EFFECT_START_NID;
4932 /* PE affects all out effects */
4933 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
4934 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
4939 /* Check if Mic1 is streaming, if so, stop streaming */
4940 static int stop_mic1(struct hda_codec *codec)
4942 struct ca0132_spec *spec = codec->spec;
4943 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
4944 AC_VERB_GET_CONV, 0);
4946 snd_hda_codec_write(codec, spec->adcs[0], 0,
4947 AC_VERB_SET_CHANNEL_STREAMID,
4952 /* Resume Mic1 streaming if it was stopped. */
4953 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
4955 struct ca0132_spec *spec = codec->spec;
4956 /* Restore the previous stream and channel */
4958 snd_hda_codec_write(codec, spec->adcs[0], 0,
4959 AC_VERB_SET_CHANNEL_STREAMID,
4964 * Turn on/off CrystalVoice
4966 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
4968 struct ca0132_spec *spec = codec->spec;
4971 unsigned int oldval;
4973 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
4974 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
4976 i = IN_EFFECT_START_NID - EFFECT_START_NID;
4977 nid = IN_EFFECT_START_NID;
4978 /* CrystalVoice affects all in effects */
4979 for (; nid < IN_EFFECT_END_NID; nid++, i++)
4980 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
4982 /* including VoiceFX */
4983 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
4985 /* set correct vipsource */
4986 oldval = stop_mic1(codec);
4987 if (spec->use_alt_functions)
4988 ret |= ca0132_alt_set_vipsource(codec, 1);
4990 ret |= ca0132_set_vipsource(codec, 1);
4991 resume_mic1(codec, oldval);
4995 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
4997 struct ca0132_spec *spec = codec->spec;
5001 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5002 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
5004 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5005 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
5010 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
5012 struct ca0132_spec *spec = codec->spec;
5015 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5016 HDA_INPUT, 0, HDA_AMP_VOLMASK, val);
5020 static int ae5_headphone_gain_set(struct hda_codec *codec, long val)
5024 for (i = 0; i < 4; i++)
5025 ca0113_mmio_command_set(codec, 0x48, 0x11 + i,
5026 ae5_headphone_gain_presets[val].vals[i]);
5031 * gpio pin 1 is a relay that switches on/off, apparently setting the headphone
5032 * amplifier to handle a 600 ohm load.
5034 static int zxr_headphone_gain_set(struct hda_codec *codec, long val)
5036 ca0113_mmio_gpio_set(codec, 1, val);
5041 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
5042 struct snd_ctl_elem_value *ucontrol)
5044 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5045 hda_nid_t nid = get_amp_nid(kcontrol);
5046 hda_nid_t shared_nid = 0;
5049 struct ca0132_spec *spec = codec->spec;
5052 if (nid == VNID_HP_SEL) {
5054 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5056 if (spec->use_alt_functions)
5057 ca0132_alt_select_out(codec);
5059 ca0132_select_out(codec);
5064 if (nid == VNID_AMIC1_SEL) {
5066 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5068 ca0132_select_mic(codec);
5072 if (nid == VNID_HP_ASEL) {
5073 if (spec->use_alt_functions)
5074 ca0132_alt_select_out(codec);
5076 ca0132_select_out(codec);
5080 if (nid == VNID_AMIC1_ASEL) {
5081 ca0132_select_mic(codec);
5085 /* if effective conditions, then update hw immediately. */
5086 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5088 int dir = get_amp_direction(kcontrol);
5089 int ch = get_amp_channels(kcontrol);
5092 mutex_lock(&codec->control_mutex);
5093 pval = kcontrol->private_value;
5094 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5096 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
5097 kcontrol->private_value = pval;
5098 mutex_unlock(&codec->control_mutex);
5103 /* End of control change helpers. */
5105 * Below I've added controls to mess with the effect levels, I've only enabled
5106 * them on the Sound Blaster Z, but they would probably also work on the
5107 * Chromebook. I figured they were probably tuned specifically for it, and left
5111 /* Sets DSP effect level from the sliders above the controls */
5112 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
5113 const unsigned int *lookup, int idx)
5118 * For X_BASS, req 2 is actually crossover freq instead of
5126 snd_hda_power_up(codec);
5127 if (nid == XBASS_XOVER) {
5128 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5129 if (ca0132_effects[i].nid == X_BASS)
5132 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5133 ca0132_effects[i].reqs[1],
5134 &(lookup[idx - 1]), sizeof(unsigned int));
5136 /* Find the actual effect structure */
5137 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5138 if (nid == ca0132_effects[i].nid)
5141 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5142 ca0132_effects[i].reqs[y],
5143 &(lookup[idx]), sizeof(unsigned int));
5146 snd_hda_power_down(codec);
5151 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol *kcontrol,
5152 struct snd_ctl_elem_value *ucontrol)
5154 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5155 struct ca0132_spec *spec = codec->spec;
5156 long *valp = ucontrol->value.integer.value;
5158 *valp = spec->xbass_xover_freq;
5162 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol *kcontrol,
5163 struct snd_ctl_elem_value *ucontrol)
5165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5166 struct ca0132_spec *spec = codec->spec;
5167 hda_nid_t nid = get_amp_nid(kcontrol);
5168 long *valp = ucontrol->value.integer.value;
5169 int idx = nid - OUT_EFFECT_START_NID;
5171 *valp = spec->fx_ctl_val[idx];
5176 * The X-bass crossover starts at 10hz, so the min is 1. The
5177 * frequency is set in multiples of 10.
5179 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol *kcontrol,
5180 struct snd_ctl_elem_info *uinfo)
5182 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5184 uinfo->value.integer.min = 1;
5185 uinfo->value.integer.max = 100;
5186 uinfo->value.integer.step = 1;
5191 static int ca0132_alt_effect_slider_info(struct snd_kcontrol *kcontrol,
5192 struct snd_ctl_elem_info *uinfo)
5194 int chs = get_amp_channels(kcontrol);
5196 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5197 uinfo->count = chs == 3 ? 2 : 1;
5198 uinfo->value.integer.min = 0;
5199 uinfo->value.integer.max = 100;
5200 uinfo->value.integer.step = 1;
5205 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol *kcontrol,
5206 struct snd_ctl_elem_value *ucontrol)
5208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5209 struct ca0132_spec *spec = codec->spec;
5210 hda_nid_t nid = get_amp_nid(kcontrol);
5211 long *valp = ucontrol->value.integer.value;
5215 if (spec->xbass_xover_freq == *valp)
5218 spec->xbass_xover_freq = *valp;
5221 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
5226 static int ca0132_alt_effect_slider_put(struct snd_kcontrol *kcontrol,
5227 struct snd_ctl_elem_value *ucontrol)
5229 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5230 struct ca0132_spec *spec = codec->spec;
5231 hda_nid_t nid = get_amp_nid(kcontrol);
5232 long *valp = ucontrol->value.integer.value;
5235 idx = nid - EFFECT_START_NID;
5237 if (spec->fx_ctl_val[idx] == *valp)
5240 spec->fx_ctl_val[idx] = *valp;
5243 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
5250 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
5251 * only has off or full 30 dB, and didn't like making a volume slider that has
5252 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
5254 #define MIC_BOOST_NUM_OF_STEPS 4
5255 #define MIC_BOOST_ENUM_MAX_STRLEN 10
5257 static int ca0132_alt_mic_boost_info(struct snd_kcontrol *kcontrol,
5258 struct snd_ctl_elem_info *uinfo)
5261 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5263 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5265 uinfo->value.enumerated.items = MIC_BOOST_NUM_OF_STEPS;
5266 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS)
5267 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1;
5268 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx);
5269 strcpy(uinfo->value.enumerated.name, namestr);
5273 static int ca0132_alt_mic_boost_get(struct snd_kcontrol *kcontrol,
5274 struct snd_ctl_elem_value *ucontrol)
5276 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5277 struct ca0132_spec *spec = codec->spec;
5279 ucontrol->value.enumerated.item[0] = spec->mic_boost_enum_val;
5283 static int ca0132_alt_mic_boost_put(struct snd_kcontrol *kcontrol,
5284 struct snd_ctl_elem_value *ucontrol)
5286 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5287 struct ca0132_spec *spec = codec->spec;
5288 int sel = ucontrol->value.enumerated.item[0];
5289 unsigned int items = MIC_BOOST_NUM_OF_STEPS;
5294 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
5297 spec->mic_boost_enum_val = sel;
5299 if (spec->in_enum_val != REAR_LINE_IN)
5300 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5306 * Sound BlasterX AE-5 Headphone Gain Controls.
5308 #define AE5_HEADPHONE_GAIN_MAX 3
5309 static int ae5_headphone_gain_info(struct snd_kcontrol *kcontrol,
5310 struct snd_ctl_elem_info *uinfo)
5312 char *sfx = " Ohms)";
5313 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5315 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5317 uinfo->value.enumerated.items = AE5_HEADPHONE_GAIN_MAX;
5318 if (uinfo->value.enumerated.item >= AE5_HEADPHONE_GAIN_MAX)
5319 uinfo->value.enumerated.item = AE5_HEADPHONE_GAIN_MAX - 1;
5320 sprintf(namestr, "%s %s",
5321 ae5_headphone_gain_presets[uinfo->value.enumerated.item].name,
5323 strcpy(uinfo->value.enumerated.name, namestr);
5327 static int ae5_headphone_gain_get(struct snd_kcontrol *kcontrol,
5328 struct snd_ctl_elem_value *ucontrol)
5330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5331 struct ca0132_spec *spec = codec->spec;
5333 ucontrol->value.enumerated.item[0] = spec->ae5_headphone_gain_val;
5337 static int ae5_headphone_gain_put(struct snd_kcontrol *kcontrol,
5338 struct snd_ctl_elem_value *ucontrol)
5340 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5341 struct ca0132_spec *spec = codec->spec;
5342 int sel = ucontrol->value.enumerated.item[0];
5343 unsigned int items = AE5_HEADPHONE_GAIN_MAX;
5348 codec_dbg(codec, "ae5_headphone_gain: boost=%d\n",
5351 spec->ae5_headphone_gain_val = sel;
5353 if (spec->out_enum_val == HEADPHONE_OUT)
5354 ae5_headphone_gain_set(codec, spec->ae5_headphone_gain_val);
5360 * Sound BlasterX AE-5 sound filter enumerated control.
5362 #define AE5_SOUND_FILTER_MAX 3
5364 static int ae5_sound_filter_info(struct snd_kcontrol *kcontrol,
5365 struct snd_ctl_elem_info *uinfo)
5367 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5369 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5371 uinfo->value.enumerated.items = AE5_SOUND_FILTER_MAX;
5372 if (uinfo->value.enumerated.item >= AE5_SOUND_FILTER_MAX)
5373 uinfo->value.enumerated.item = AE5_SOUND_FILTER_MAX - 1;
5374 sprintf(namestr, "%s",
5375 ae5_filter_presets[uinfo->value.enumerated.item].name);
5376 strcpy(uinfo->value.enumerated.name, namestr);
5380 static int ae5_sound_filter_get(struct snd_kcontrol *kcontrol,
5381 struct snd_ctl_elem_value *ucontrol)
5383 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5384 struct ca0132_spec *spec = codec->spec;
5386 ucontrol->value.enumerated.item[0] = spec->ae5_filter_val;
5390 static int ae5_sound_filter_put(struct snd_kcontrol *kcontrol,
5391 struct snd_ctl_elem_value *ucontrol)
5393 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5394 struct ca0132_spec *spec = codec->spec;
5395 int sel = ucontrol->value.enumerated.item[0];
5396 unsigned int items = AE5_SOUND_FILTER_MAX;
5401 codec_dbg(codec, "ae5_sound_filter: %s\n",
5402 ae5_filter_presets[sel].name);
5404 spec->ae5_filter_val = sel;
5406 ca0113_mmio_command_set_type2(codec, 0x48, 0x07,
5407 ae5_filter_presets[sel].val);
5413 * Input Select Control for alternative ca0132 codecs. This exists because
5414 * front microphone has no auto-detect, and we need a way to set the rear
5417 static int ca0132_alt_input_source_info(struct snd_kcontrol *kcontrol,
5418 struct snd_ctl_elem_info *uinfo)
5420 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5422 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS;
5423 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS)
5424 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1;
5425 strcpy(uinfo->value.enumerated.name,
5426 in_src_str[uinfo->value.enumerated.item]);
5430 static int ca0132_alt_input_source_get(struct snd_kcontrol *kcontrol,
5431 struct snd_ctl_elem_value *ucontrol)
5433 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5434 struct ca0132_spec *spec = codec->spec;
5436 ucontrol->value.enumerated.item[0] = spec->in_enum_val;
5440 static int ca0132_alt_input_source_put(struct snd_kcontrol *kcontrol,
5441 struct snd_ctl_elem_value *ucontrol)
5443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5444 struct ca0132_spec *spec = codec->spec;
5445 int sel = ucontrol->value.enumerated.item[0];
5446 unsigned int items = IN_SRC_NUM_OF_INPUTS;
5451 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5452 sel, in_src_str[sel]);
5454 spec->in_enum_val = sel;
5456 ca0132_alt_select_in(codec);
5461 /* Sound Blaster Z Output Select Control */
5462 static int ca0132_alt_output_select_get_info(struct snd_kcontrol *kcontrol,
5463 struct snd_ctl_elem_info *uinfo)
5465 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5467 uinfo->value.enumerated.items = NUM_OF_OUTPUTS;
5468 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS)
5469 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1;
5470 strcpy(uinfo->value.enumerated.name,
5471 alt_out_presets[uinfo->value.enumerated.item].name);
5475 static int ca0132_alt_output_select_get(struct snd_kcontrol *kcontrol,
5476 struct snd_ctl_elem_value *ucontrol)
5478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5479 struct ca0132_spec *spec = codec->spec;
5481 ucontrol->value.enumerated.item[0] = spec->out_enum_val;
5485 static int ca0132_alt_output_select_put(struct snd_kcontrol *kcontrol,
5486 struct snd_ctl_elem_value *ucontrol)
5488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5489 struct ca0132_spec *spec = codec->spec;
5490 int sel = ucontrol->value.enumerated.item[0];
5491 unsigned int items = NUM_OF_OUTPUTS;
5492 unsigned int auto_jack;
5497 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
5498 sel, alt_out_presets[sel].name);
5500 spec->out_enum_val = sel;
5502 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5505 ca0132_alt_select_out(codec);
5511 * Smart Volume output setting control. Three different settings, Normal,
5512 * which takes the value from the smart volume slider. The two others, loud
5513 * and night, disregard the slider value and have uneditable values.
5515 #define NUM_OF_SVM_SETTINGS 3
5516 static const char *const out_svm_set_enum_str[3] = {"Normal", "Loud", "Night" };
5518 static int ca0132_alt_svm_setting_info(struct snd_kcontrol *kcontrol,
5519 struct snd_ctl_elem_info *uinfo)
5521 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5523 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS;
5524 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS)
5525 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1;
5526 strcpy(uinfo->value.enumerated.name,
5527 out_svm_set_enum_str[uinfo->value.enumerated.item]);
5531 static int ca0132_alt_svm_setting_get(struct snd_kcontrol *kcontrol,
5532 struct snd_ctl_elem_value *ucontrol)
5534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5535 struct ca0132_spec *spec = codec->spec;
5537 ucontrol->value.enumerated.item[0] = spec->smart_volume_setting;
5541 static int ca0132_alt_svm_setting_put(struct snd_kcontrol *kcontrol,
5542 struct snd_ctl_elem_value *ucontrol)
5544 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5545 struct ca0132_spec *spec = codec->spec;
5546 int sel = ucontrol->value.enumerated.item[0];
5547 unsigned int items = NUM_OF_SVM_SETTINGS;
5548 unsigned int idx = SMART_VOLUME - EFFECT_START_NID;
5554 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
5555 sel, out_svm_set_enum_str[sel]);
5557 spec->smart_volume_setting = sel;
5573 /* Req 2 is the Smart Volume Setting req. */
5574 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5575 ca0132_effects[idx].reqs[2], tmp);
5579 /* Sound Blaster Z EQ preset controls */
5580 static int ca0132_alt_eq_preset_info(struct snd_kcontrol *kcontrol,
5581 struct snd_ctl_elem_info *uinfo)
5583 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5585 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5587 uinfo->value.enumerated.items = items;
5588 if (uinfo->value.enumerated.item >= items)
5589 uinfo->value.enumerated.item = items - 1;
5590 strcpy(uinfo->value.enumerated.name,
5591 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name);
5595 static int ca0132_alt_eq_preset_get(struct snd_kcontrol *kcontrol,
5596 struct snd_ctl_elem_value *ucontrol)
5598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5599 struct ca0132_spec *spec = codec->spec;
5601 ucontrol->value.enumerated.item[0] = spec->eq_preset_val;
5605 static int ca0132_alt_eq_preset_put(struct snd_kcontrol *kcontrol,
5606 struct snd_ctl_elem_value *ucontrol)
5608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5609 struct ca0132_spec *spec = codec->spec;
5611 int sel = ucontrol->value.enumerated.item[0];
5612 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5617 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
5618 ca0132_alt_eq_presets[sel].name);
5621 * Default needs to qualify with CrystalVoice state.
5623 for (i = 0; i < EQ_PRESET_MAX_PARAM_COUNT; i++) {
5624 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
5625 ca0132_alt_eq_enum.reqs[i],
5626 ca0132_alt_eq_presets[sel].vals[i]);
5632 spec->eq_preset_val = sel;
5637 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
5638 struct snd_ctl_elem_info *uinfo)
5640 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
5642 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5644 uinfo->value.enumerated.items = items;
5645 if (uinfo->value.enumerated.item >= items)
5646 uinfo->value.enumerated.item = items - 1;
5647 strcpy(uinfo->value.enumerated.name,
5648 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
5652 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
5653 struct snd_ctl_elem_value *ucontrol)
5655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5656 struct ca0132_spec *spec = codec->spec;
5658 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
5662 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
5663 struct snd_ctl_elem_value *ucontrol)
5665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5666 struct ca0132_spec *spec = codec->spec;
5668 int sel = ucontrol->value.enumerated.item[0];
5670 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
5673 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
5674 sel, ca0132_voicefx_presets[sel].name);
5678 * Default needs to qualify with CrystalVoice state.
5680 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
5681 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
5682 ca0132_voicefx.reqs[i],
5683 ca0132_voicefx_presets[sel].vals[i]);
5689 spec->voicefx_val = sel;
5690 /* enable voice fx */
5691 ca0132_voicefx_set(codec, (sel ? 1 : 0));
5697 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
5698 struct snd_ctl_elem_value *ucontrol)
5700 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5701 struct ca0132_spec *spec = codec->spec;
5702 hda_nid_t nid = get_amp_nid(kcontrol);
5703 int ch = get_amp_channels(kcontrol);
5704 long *valp = ucontrol->value.integer.value;
5707 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5709 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
5713 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
5719 /* effects, include PE and CrystalVoice */
5720 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
5721 *valp = spec->effects_switch[nid - EFFECT_START_NID];
5726 if (nid == spec->input_pins[0]) {
5727 *valp = spec->cur_mic_boost;
5734 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
5735 struct snd_ctl_elem_value *ucontrol)
5737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5738 struct ca0132_spec *spec = codec->spec;
5739 hda_nid_t nid = get_amp_nid(kcontrol);
5740 int ch = get_amp_channels(kcontrol);
5741 long *valp = ucontrol->value.integer.value;
5744 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
5747 snd_hda_power_up(codec);
5749 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5751 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
5755 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
5758 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
5763 if (nid == PLAY_ENHANCEMENT) {
5764 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5765 changed = ca0132_pe_switch_set(codec);
5770 if (nid == CRYSTAL_VOICE) {
5771 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5772 changed = ca0132_cvoice_switch_set(codec);
5776 /* out and in effects */
5777 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
5778 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
5779 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5780 changed = ca0132_effects_set(codec, nid, *valp);
5785 if (nid == spec->input_pins[0]) {
5786 spec->cur_mic_boost = *valp;
5787 if (spec->use_alt_functions) {
5788 if (spec->in_enum_val != REAR_LINE_IN)
5789 changed = ca0132_mic_boost_set(codec, *valp);
5791 /* Mic boost does not apply to Digital Mic */
5792 if (spec->cur_mic_type != DIGITAL_MIC)
5793 changed = ca0132_mic_boost_set(codec, *valp);
5799 if (nid == ZXR_HEADPHONE_GAIN) {
5800 spec->zxr_gain_set = *valp;
5801 if (spec->cur_out_type == HEADPHONE_OUT)
5802 changed = zxr_headphone_gain_set(codec, *valp);
5810 snd_hda_power_down(codec);
5818 * Sets the internal DSP decibel level to match the DAC for output, and the
5819 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
5820 * all alternative codecs set DSP playback volume.
5822 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
5824 struct ca0132_spec *spec = codec->spec;
5825 unsigned int dsp_dir;
5826 unsigned int lookup_val;
5828 if (nid == VNID_SPK)
5829 dsp_dir = DSP_VOL_OUT;
5831 dsp_dir = DSP_VOL_IN;
5833 lookup_val = spec->vnode_lvol[nid - VNODE_START_NID];
5835 dspio_set_uint_param(codec,
5836 ca0132_alt_vol_ctls[dsp_dir].mid,
5837 ca0132_alt_vol_ctls[dsp_dir].reqs[0],
5838 float_vol_db_lookup[lookup_val]);
5840 lookup_val = spec->vnode_rvol[nid - VNODE_START_NID];
5842 dspio_set_uint_param(codec,
5843 ca0132_alt_vol_ctls[dsp_dir].mid,
5844 ca0132_alt_vol_ctls[dsp_dir].reqs[1],
5845 float_vol_db_lookup[lookup_val]);
5847 dspio_set_uint_param(codec,
5848 ca0132_alt_vol_ctls[dsp_dir].mid,
5849 ca0132_alt_vol_ctls[dsp_dir].reqs[2], FLOAT_ZERO);
5852 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
5853 struct snd_ctl_elem_info *uinfo)
5855 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5856 struct ca0132_spec *spec = codec->spec;
5857 hda_nid_t nid = get_amp_nid(kcontrol);
5858 int ch = get_amp_channels(kcontrol);
5859 int dir = get_amp_direction(kcontrol);
5865 /* follow shared_out info */
5866 nid = spec->shared_out_nid;
5867 mutex_lock(&codec->control_mutex);
5868 pval = kcontrol->private_value;
5869 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5870 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5871 kcontrol->private_value = pval;
5872 mutex_unlock(&codec->control_mutex);
5875 /* follow shared_mic info */
5876 nid = spec->shared_mic_nid;
5877 mutex_lock(&codec->control_mutex);
5878 pval = kcontrol->private_value;
5879 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5880 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5881 kcontrol->private_value = pval;
5882 mutex_unlock(&codec->control_mutex);
5885 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5890 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
5891 struct snd_ctl_elem_value *ucontrol)
5893 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5894 struct ca0132_spec *spec = codec->spec;
5895 hda_nid_t nid = get_amp_nid(kcontrol);
5896 int ch = get_amp_channels(kcontrol);
5897 long *valp = ucontrol->value.integer.value;
5899 /* store the left and right volume */
5901 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
5905 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
5911 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
5912 struct snd_ctl_elem_value *ucontrol)
5914 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5915 struct ca0132_spec *spec = codec->spec;
5916 hda_nid_t nid = get_amp_nid(kcontrol);
5917 int ch = get_amp_channels(kcontrol);
5918 long *valp = ucontrol->value.integer.value;
5919 hda_nid_t shared_nid = 0;
5923 /* store the left and right volume */
5925 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
5929 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
5933 /* if effective conditions, then update hw immediately. */
5934 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5936 int dir = get_amp_direction(kcontrol);
5939 snd_hda_power_up(codec);
5940 mutex_lock(&codec->control_mutex);
5941 pval = kcontrol->private_value;
5942 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5944 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
5945 kcontrol->private_value = pval;
5946 mutex_unlock(&codec->control_mutex);
5947 snd_hda_power_down(codec);
5954 * This function is the same as the one above, because using an if statement
5955 * inside of the above volume control for the DSP volume would cause too much
5956 * lag. This is a lot more smooth.
5958 static int ca0132_alt_volume_put(struct snd_kcontrol *kcontrol,
5959 struct snd_ctl_elem_value *ucontrol)
5961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5962 struct ca0132_spec *spec = codec->spec;
5963 hda_nid_t nid = get_amp_nid(kcontrol);
5964 int ch = get_amp_channels(kcontrol);
5965 long *valp = ucontrol->value.integer.value;
5978 /* store the left and right volume */
5980 spec->vnode_lvol[vnid - VNODE_START_NID] = *valp;
5984 spec->vnode_rvol[vnid - VNODE_START_NID] = *valp;
5988 snd_hda_power_up(codec);
5989 ca0132_alt_dsp_volume_put(codec, vnid);
5990 mutex_lock(&codec->control_mutex);
5991 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
5992 mutex_unlock(&codec->control_mutex);
5993 snd_hda_power_down(codec);
5998 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
5999 unsigned int size, unsigned int __user *tlv)
6001 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6002 struct ca0132_spec *spec = codec->spec;
6003 hda_nid_t nid = get_amp_nid(kcontrol);
6004 int ch = get_amp_channels(kcontrol);
6005 int dir = get_amp_direction(kcontrol);
6011 /* follow shared_out tlv */
6012 nid = spec->shared_out_nid;
6013 mutex_lock(&codec->control_mutex);
6014 pval = kcontrol->private_value;
6015 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6016 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6017 kcontrol->private_value = pval;
6018 mutex_unlock(&codec->control_mutex);
6021 /* follow shared_mic tlv */
6022 nid = spec->shared_mic_nid;
6023 mutex_lock(&codec->control_mutex);
6024 pval = kcontrol->private_value;
6025 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6026 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6027 kcontrol->private_value = pval;
6028 mutex_unlock(&codec->control_mutex);
6031 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6036 /* Add volume slider control for effect level */
6037 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
6038 const char *pfx, int dir)
6040 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6041 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6042 struct snd_kcontrol_new knew =
6043 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
6045 sprintf(namestr, "FX: %s %s Volume", pfx, dirstr[dir]);
6051 knew.info = ca0132_alt_xbass_xover_slider_info;
6052 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6053 knew.put = ca0132_alt_xbass_xover_slider_put;
6056 knew.info = ca0132_alt_effect_slider_info;
6057 knew.get = ca0132_alt_slider_ctl_get;
6058 knew.put = ca0132_alt_effect_slider_put;
6059 knew.private_value =
6060 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
6064 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6068 * Added FX: prefix for the alternative codecs, because otherwise the surround
6069 * effect would conflict with the Surround sound volume control. Also seems more
6070 * clear as to what the switches do. Left alone for others.
6072 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
6073 const char *pfx, int dir)
6075 struct ca0132_spec *spec = codec->spec;
6076 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6077 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6078 struct snd_kcontrol_new knew =
6079 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
6080 /* If using alt_controls, add FX: prefix. But, don't add FX:
6081 * prefix to OutFX or InFX enable controls.
6083 if ((spec->use_alt_controls) && (nid <= IN_EFFECT_END_NID))
6084 sprintf(namestr, "FX: %s %s Switch", pfx, dirstr[dir]);
6086 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
6088 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6091 static int add_voicefx(struct hda_codec *codec)
6093 struct snd_kcontrol_new knew =
6094 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
6095 VOICEFX, 1, 0, HDA_INPUT);
6096 knew.info = ca0132_voicefx_info;
6097 knew.get = ca0132_voicefx_get;
6098 knew.put = ca0132_voicefx_put;
6099 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
6102 /* Create the EQ Preset control */
6103 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
6105 struct snd_kcontrol_new knew =
6106 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum.name,
6107 EQ_PRESET_ENUM, 1, 0, HDA_OUTPUT);
6108 knew.info = ca0132_alt_eq_preset_info;
6109 knew.get = ca0132_alt_eq_preset_get;
6110 knew.put = ca0132_alt_eq_preset_put;
6111 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
6112 snd_ctl_new1(&knew, codec));
6116 * Add enumerated control for the three different settings of the smart volume
6117 * output effect. Normal just uses the slider value, and loud and night are
6118 * their own things that ignore that value.
6120 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
6122 struct snd_kcontrol_new knew =
6123 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
6124 SMART_VOLUME_ENUM, 1, 0, HDA_OUTPUT);
6125 knew.info = ca0132_alt_svm_setting_info;
6126 knew.get = ca0132_alt_svm_setting_get;
6127 knew.put = ca0132_alt_svm_setting_put;
6128 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
6129 snd_ctl_new1(&knew, codec));
6134 * Create an Output Select enumerated control for codecs with surround
6137 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
6139 struct snd_kcontrol_new knew =
6140 HDA_CODEC_MUTE_MONO("Output Select",
6141 OUTPUT_SOURCE_ENUM, 1, 0, HDA_OUTPUT);
6142 knew.info = ca0132_alt_output_select_get_info;
6143 knew.get = ca0132_alt_output_select_get;
6144 knew.put = ca0132_alt_output_select_put;
6145 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
6146 snd_ctl_new1(&knew, codec));
6150 * Create an Input Source enumerated control for the alternate ca0132 codecs
6151 * because the front microphone has no auto-detect, and Line-in has to be set
6154 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
6156 struct snd_kcontrol_new knew =
6157 HDA_CODEC_MUTE_MONO("Input Source",
6158 INPUT_SOURCE_ENUM, 1, 0, HDA_INPUT);
6159 knew.info = ca0132_alt_input_source_info;
6160 knew.get = ca0132_alt_input_source_get;
6161 knew.put = ca0132_alt_input_source_put;
6162 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
6163 snd_ctl_new1(&knew, codec));
6167 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
6168 * more control than the original mic boost, which is either full 30dB or off.
6170 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
6172 struct snd_kcontrol_new knew =
6173 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
6174 MIC_BOOST_ENUM, 1, 0, HDA_INPUT);
6175 knew.info = ca0132_alt_mic_boost_info;
6176 knew.get = ca0132_alt_mic_boost_get;
6177 knew.put = ca0132_alt_mic_boost_put;
6178 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
6179 snd_ctl_new1(&knew, codec));
6184 * Add headphone gain enumerated control for the AE-5. This switches between
6185 * three modes, low, medium, and high. When non-headphone outputs are selected,
6186 * it is automatically set to high. This is the same behavior as Windows.
6188 static int ae5_add_headphone_gain_enum(struct hda_codec *codec)
6190 struct snd_kcontrol_new knew =
6191 HDA_CODEC_MUTE_MONO("AE-5: Headphone Gain",
6192 AE5_HEADPHONE_GAIN_ENUM, 1, 0, HDA_OUTPUT);
6193 knew.info = ae5_headphone_gain_info;
6194 knew.get = ae5_headphone_gain_get;
6195 knew.put = ae5_headphone_gain_put;
6196 return snd_hda_ctl_add(codec, AE5_HEADPHONE_GAIN_ENUM,
6197 snd_ctl_new1(&knew, codec));
6201 * Add sound filter enumerated control for the AE-5. This adds three different
6202 * settings: Slow Roll Off, Minimum Phase, and Fast Roll Off. From what I've
6203 * read into it, it changes the DAC's interpolation filter.
6205 static int ae5_add_sound_filter_enum(struct hda_codec *codec)
6207 struct snd_kcontrol_new knew =
6208 HDA_CODEC_MUTE_MONO("AE-5: Sound Filter",
6209 AE5_SOUND_FILTER_ENUM, 1, 0, HDA_OUTPUT);
6210 knew.info = ae5_sound_filter_info;
6211 knew.get = ae5_sound_filter_get;
6212 knew.put = ae5_sound_filter_put;
6213 return snd_hda_ctl_add(codec, AE5_SOUND_FILTER_ENUM,
6214 snd_ctl_new1(&knew, codec));
6217 static int zxr_add_headphone_gain_switch(struct hda_codec *codec)
6219 struct snd_kcontrol_new knew =
6220 CA0132_CODEC_MUTE_MONO("ZxR: 600 Ohm Gain",
6221 ZXR_HEADPHONE_GAIN, 1, HDA_OUTPUT);
6223 return snd_hda_ctl_add(codec, ZXR_HEADPHONE_GAIN,
6224 snd_ctl_new1(&knew, codec));
6228 * Need to create slave controls for the alternate codecs that have surround
6231 static const char * const ca0132_alt_slave_pfxs[] = {
6232 "Front", "Surround", "Center", "LFE", NULL,
6236 * Also need special channel map, because the default one is incorrect.
6237 * I think this has to do with the pin for rear surround being 0x11,
6238 * and the center/lfe being 0x10. Usually the pin order is the opposite.
6240 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps[] = {
6242 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
6244 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6245 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6247 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6248 SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE,
6249 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6253 /* Add the correct chmap for streams with 6 channels. */
6254 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
6257 struct hda_pcm *pcm;
6259 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
6260 struct hda_pcm_stream *hinfo =
6261 &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
6262 struct snd_pcm_chmap *chmap;
6263 const struct snd_pcm_chmap_elem *elem;
6265 elem = ca0132_alt_chmaps;
6266 if (hinfo->channels_max == 6) {
6267 err = snd_pcm_add_chmap_ctls(pcm->pcm,
6268 SNDRV_PCM_STREAM_PLAYBACK,
6269 elem, hinfo->channels_max, 0, &chmap);
6271 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
6277 * When changing Node IDs for Mixer Controls below, make sure to update
6278 * Node IDs in ca0132_config() as well.
6280 static const struct snd_kcontrol_new ca0132_mixer[] = {
6281 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
6282 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
6283 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6284 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6285 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
6286 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
6287 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6288 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6289 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
6290 0x12, 1, HDA_INPUT),
6291 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
6292 VNID_HP_SEL, 1, HDA_OUTPUT),
6293 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
6294 VNID_AMIC1_SEL, 1, HDA_INPUT),
6295 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6296 VNID_HP_ASEL, 1, HDA_OUTPUT),
6297 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
6298 VNID_AMIC1_ASEL, 1, HDA_INPUT),
6303 * Desktop specific control mixer. Removes auto-detect for mic, and adds
6304 * surround controls. Also sets both the Front Playback and Capture Volume
6305 * controls to alt so they set the DSP's decibel level.
6307 static const struct snd_kcontrol_new desktop_mixer[] = {
6308 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6309 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6310 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6311 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6312 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6313 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6314 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6315 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6316 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT),
6317 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6318 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6319 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6320 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6321 VNID_HP_ASEL, 1, HDA_OUTPUT),
6326 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
6327 * because it doesn't set decibel levels for the DSP for capture.
6329 static const struct snd_kcontrol_new r3di_mixer[] = {
6330 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6331 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6332 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6333 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6334 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6335 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6336 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6337 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6338 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6339 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6340 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6341 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6342 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6343 VNID_HP_ASEL, 1, HDA_OUTPUT),
6347 static int ca0132_build_controls(struct hda_codec *codec)
6349 struct ca0132_spec *spec = codec->spec;
6350 int i, num_fx, num_sliders;
6353 /* Add Mixer controls */
6354 for (i = 0; i < spec->num_mixers; i++) {
6355 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
6359 /* Setup vmaster with surround slaves for desktop ca0132 devices */
6360 if (spec->use_alt_functions) {
6361 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
6363 snd_hda_add_vmaster(codec, "Master Playback Volume",
6364 spec->tlv, ca0132_alt_slave_pfxs,
6366 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
6367 NULL, ca0132_alt_slave_pfxs,
6369 true, &spec->vmaster_mute.sw_kctl);
6374 /* Add in and out effects controls.
6375 * VoiceFX, PE and CrystalVoice are added separately.
6377 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
6378 for (i = 0; i < num_fx; i++) {
6379 /* Desktop cards break if Echo Cancellation is used. */
6380 if (spec->use_pci_mmio) {
6381 if (i == (ECHO_CANCELLATION - IN_EFFECT_START_NID +
6386 err = add_fx_switch(codec, ca0132_effects[i].nid,
6387 ca0132_effects[i].name,
6388 ca0132_effects[i].direct);
6393 * If codec has use_alt_controls set to true, add effect level sliders,
6394 * EQ presets, and Smart Volume presets. Also, change names to add FX
6395 * prefix, and change PlayEnhancement and CrystalVoice to match.
6397 if (spec->use_alt_controls) {
6398 err = ca0132_alt_add_svm_enum(codec);
6402 err = add_ca0132_alt_eq_presets(codec);
6406 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6411 err = add_fx_switch(codec, CRYSTAL_VOICE,
6416 num_sliders = OUT_EFFECTS_COUNT - 1;
6417 for (i = 0; i < num_sliders; i++) {
6418 err = ca0132_alt_add_effect_slider(codec,
6419 ca0132_effects[i].nid,
6420 ca0132_effects[i].name,
6421 ca0132_effects[i].direct);
6426 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
6427 "X-Bass Crossover", EFX_DIR_OUT);
6432 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6433 "PlayEnhancement", 0);
6437 err = add_fx_switch(codec, CRYSTAL_VOICE,
6442 err = add_voicefx(codec);
6447 * If the codec uses alt_functions, you need the enumerated controls
6448 * to select the new outputs and inputs, plus add the new mic boost
6451 if (spec->use_alt_functions) {
6452 err = ca0132_alt_add_output_enum(codec);
6455 err = ca0132_alt_add_mic_boost_enum(codec);
6459 * ZxR only has microphone input, there is no front panel
6460 * header on the card, and aux-in is handled by the DBPro board.
6462 if (spec->quirk != QUIRK_ZXR) {
6463 err = ca0132_alt_add_input_enum(codec);
6469 if (spec->quirk == QUIRK_AE5) {
6470 err = ae5_add_headphone_gain_enum(codec);
6473 err = ae5_add_sound_filter_enum(codec);
6478 if (spec->quirk == QUIRK_ZXR) {
6479 err = zxr_add_headphone_gain_switch(codec);
6483 #ifdef ENABLE_TUNING_CONTROLS
6484 add_tuning_ctls(codec);
6487 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
6491 if (spec->dig_out) {
6492 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
6496 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
6499 /* spec->multiout.share_spdif = 1; */
6503 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
6508 if (spec->use_alt_functions)
6509 ca0132_alt_add_chmap_ctls(codec);
6514 static int dbpro_build_controls(struct hda_codec *codec)
6516 struct ca0132_spec *spec = codec->spec;
6519 if (spec->dig_out) {
6520 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
6527 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
6538 static const struct hda_pcm_stream ca0132_pcm_analog_playback = {
6543 .prepare = ca0132_playback_pcm_prepare,
6544 .cleanup = ca0132_playback_pcm_cleanup,
6545 .get_delay = ca0132_playback_pcm_delay,
6549 static const struct hda_pcm_stream ca0132_pcm_analog_capture = {
6554 .prepare = ca0132_capture_pcm_prepare,
6555 .cleanup = ca0132_capture_pcm_cleanup,
6556 .get_delay = ca0132_capture_pcm_delay,
6560 static const struct hda_pcm_stream ca0132_pcm_digital_playback = {
6565 .open = ca0132_dig_playback_pcm_open,
6566 .close = ca0132_dig_playback_pcm_close,
6567 .prepare = ca0132_dig_playback_pcm_prepare,
6568 .cleanup = ca0132_dig_playback_pcm_cleanup
6572 static const struct hda_pcm_stream ca0132_pcm_digital_capture = {
6578 static int ca0132_build_pcms(struct hda_codec *codec)
6580 struct ca0132_spec *spec = codec->spec;
6581 struct hda_pcm *info;
6583 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
6586 if (spec->use_alt_functions) {
6587 info->own_chmap = true;
6588 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap
6589 = ca0132_alt_chmaps;
6591 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
6592 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
6593 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
6594 spec->multiout.max_channels;
6595 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6596 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6597 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
6599 /* With the DSP enabled, desktops don't use this ADC. */
6600 if (!spec->use_alt_functions) {
6601 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
6604 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6605 ca0132_pcm_analog_capture;
6606 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6607 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
6610 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
6613 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6614 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6615 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
6617 if (!spec->dig_out && !spec->dig_in)
6620 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
6623 info->pcm_type = HDA_PCM_TYPE_SPDIF;
6624 if (spec->dig_out) {
6625 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
6626 ca0132_pcm_digital_playback;
6627 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
6630 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6631 ca0132_pcm_digital_capture;
6632 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
6638 static int dbpro_build_pcms(struct hda_codec *codec)
6640 struct ca0132_spec *spec = codec->spec;
6641 struct hda_pcm *info;
6643 info = snd_hda_codec_pcm_new(codec, "CA0132 Alt Analog");
6646 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6647 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6648 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
6651 if (!spec->dig_out && !spec->dig_in)
6654 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
6657 info->pcm_type = HDA_PCM_TYPE_SPDIF;
6658 if (spec->dig_out) {
6659 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
6660 ca0132_pcm_digital_playback;
6661 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
6664 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6665 ca0132_pcm_digital_capture;
6666 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
6672 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
6675 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
6676 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
6677 snd_hda_codec_write(codec, pin, 0,
6678 AC_VERB_SET_AMP_GAIN_MUTE,
6681 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
6682 snd_hda_codec_write(codec, dac, 0,
6683 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
6686 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
6689 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
6690 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
6691 snd_hda_codec_write(codec, pin, 0,
6692 AC_VERB_SET_AMP_GAIN_MUTE,
6695 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
6696 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6699 /* init to 0 dB and unmute. */
6700 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6701 HDA_AMP_VOLMASK, 0x5a);
6702 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6707 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
6711 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
6712 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
6713 snd_hda_override_amp_caps(codec, nid, dir, caps);
6717 * Switch between Digital built-in mic and analog mic.
6719 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
6721 struct ca0132_spec *spec = codec->spec;
6724 unsigned int oldval;
6726 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
6728 oldval = stop_mic1(codec);
6729 ca0132_set_vipsource(codec, 0);
6731 /* set DMic input as 2-ch */
6733 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6735 val = spec->dmic_ctl;
6737 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6738 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6740 if (!(spec->dmic_ctl & 0x20))
6741 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
6743 /* set AMic input as mono */
6745 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6747 val = spec->dmic_ctl;
6748 /* clear bit7 and bit5 to disable dmic */
6750 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6751 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6753 if (!(spec->dmic_ctl & 0x20))
6754 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
6756 ca0132_set_vipsource(codec, 1);
6757 resume_mic1(codec, oldval);
6761 * Initialization for Digital Mic.
6763 static void ca0132_init_dmic(struct hda_codec *codec)
6765 struct ca0132_spec *spec = codec->spec;
6768 /* Setup Digital Mic here, but don't enable.
6769 * Enable based on jack detect.
6772 /* MCLK uses MPIO1, set to enable.
6773 * Bit 2-0: MPIO select
6774 * Bit 3: set to disable
6778 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6779 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
6781 /* Data1 uses MPIO3. Data2 not use
6782 * Bit 2-0: Data1 MPIO select
6783 * Bit 3: set disable Data1
6784 * Bit 6-4: Data2 MPIO select
6785 * Bit 7: set disable Data2
6788 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6789 VENDOR_CHIPIO_DMIC_PIN_SET, val);
6791 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
6792 * Bit 3-0: Channel mask
6793 * Bit 4: set for 48KHz, clear for 32KHz
6795 * Bit 6: set to select Data2, clear for Data1
6796 * Bit 7: set to enable DMic, clear for AMic
6798 if (spec->quirk == QUIRK_ALIENWARE_M17XR4)
6802 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
6803 spec->dmic_ctl = val;
6804 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6805 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6809 * Initialization for Analog Mic 2
6811 static void ca0132_init_analog_mic2(struct hda_codec *codec)
6813 struct ca0132_spec *spec = codec->spec;
6815 mutex_lock(&spec->chipio_mutex);
6816 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6817 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
6818 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6819 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6820 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6821 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6822 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6823 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
6824 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6825 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6826 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6827 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6828 mutex_unlock(&spec->chipio_mutex);
6831 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
6833 struct ca0132_spec *spec = codec->spec;
6836 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
6837 snd_hda_codec_update_widgets(codec);
6839 for (i = 0; i < spec->multiout.num_dacs; i++)
6840 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
6842 for (i = 0; i < spec->num_outputs; i++)
6843 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
6845 for (i = 0; i < spec->num_inputs; i++) {
6846 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
6847 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
6852 * Creates a dummy stream to bind the output to. This seems to have to be done
6853 * after changing the main outputs source and destination streams.
6855 static void ca0132_alt_create_dummy_stream(struct hda_codec *codec)
6857 struct ca0132_spec *spec = codec->spec;
6858 unsigned int stream_format;
6860 stream_format = snd_hdac_calc_stream_format(48000, 2,
6861 SNDRV_PCM_FORMAT_S32_LE, 32, 0);
6863 snd_hda_codec_setup_stream(codec, spec->dacs[0], spec->dsp_stream_id,
6866 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
6870 * Initialize mic for non-chromebook ca0132 implementations.
6872 static void ca0132_alt_init_analog_mics(struct hda_codec *codec)
6874 struct ca0132_spec *spec = codec->spec;
6878 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
6879 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
6880 if (spec->quirk == QUIRK_R3DI) {
6881 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6885 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6887 /* Mic 2 setup (not present on desktop cards) */
6888 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
6889 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
6890 if (spec->quirk == QUIRK_R3DI)
6891 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6893 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
6897 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
6898 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
6899 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
6900 * having an updated DAC, which changes the destination to that DAC.
6902 static void sbz_connect_streams(struct hda_codec *codec)
6904 struct ca0132_spec *spec = codec->spec;
6906 mutex_lock(&spec->chipio_mutex);
6908 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
6910 chipio_set_stream_channels(codec, 0x0C, 6);
6911 chipio_set_stream_control(codec, 0x0C, 1);
6913 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
6914 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
6916 /* Setup stream 0x14 with it's source and destination points */
6917 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
6918 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
6919 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
6920 chipio_set_stream_channels(codec, 0x14, 2);
6921 chipio_set_stream_control(codec, 0x14, 1);
6923 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
6925 mutex_unlock(&spec->chipio_mutex);
6929 * Write data through ChipIO to setup proper stream destinations.
6930 * Not sure how it exactly works, but it seems to direct data
6931 * to different destinations. Example is f8 to c0, e0 to c0.
6932 * All I know is, if you don't set these, you get no sound.
6934 static void sbz_chipio_startup_data(struct hda_codec *codec)
6936 struct ca0132_spec *spec = codec->spec;
6938 mutex_lock(&spec->chipio_mutex);
6939 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
6941 /* These control audio output */
6942 chipio_write_no_mutex(codec, 0x190060, 0x0001f8c0);
6943 chipio_write_no_mutex(codec, 0x190064, 0x0001f9c1);
6944 chipio_write_no_mutex(codec, 0x190068, 0x0001fac6);
6945 chipio_write_no_mutex(codec, 0x19006c, 0x0001fbc7);
6946 /* Signal to update I think */
6947 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
6949 chipio_set_stream_channels(codec, 0x0C, 6);
6950 chipio_set_stream_control(codec, 0x0C, 1);
6951 /* No clue what these control */
6952 if (spec->quirk == QUIRK_SBZ) {
6953 chipio_write_no_mutex(codec, 0x190030, 0x0001e0c0);
6954 chipio_write_no_mutex(codec, 0x190034, 0x0001e1c1);
6955 chipio_write_no_mutex(codec, 0x190038, 0x0001e4c2);
6956 chipio_write_no_mutex(codec, 0x19003c, 0x0001e5c3);
6957 chipio_write_no_mutex(codec, 0x190040, 0x0001e2c4);
6958 chipio_write_no_mutex(codec, 0x190044, 0x0001e3c5);
6959 chipio_write_no_mutex(codec, 0x190048, 0x0001e8c6);
6960 chipio_write_no_mutex(codec, 0x19004c, 0x0001e9c7);
6961 chipio_write_no_mutex(codec, 0x190050, 0x0001ecc8);
6962 chipio_write_no_mutex(codec, 0x190054, 0x0001edc9);
6963 chipio_write_no_mutex(codec, 0x190058, 0x0001eaca);
6964 chipio_write_no_mutex(codec, 0x19005c, 0x0001ebcb);
6965 } else if (spec->quirk == QUIRK_ZXR) {
6966 chipio_write_no_mutex(codec, 0x190038, 0x000140c2);
6967 chipio_write_no_mutex(codec, 0x19003c, 0x000141c3);
6968 chipio_write_no_mutex(codec, 0x190040, 0x000150c4);
6969 chipio_write_no_mutex(codec, 0x190044, 0x000151c5);
6970 chipio_write_no_mutex(codec, 0x190050, 0x000142c8);
6971 chipio_write_no_mutex(codec, 0x190054, 0x000143c9);
6972 chipio_write_no_mutex(codec, 0x190058, 0x000152ca);
6973 chipio_write_no_mutex(codec, 0x19005c, 0x000153cb);
6975 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
6977 codec_dbg(codec, "Startup Data exited, mutex released.\n");
6978 mutex_unlock(&spec->chipio_mutex);
6982 * Custom DSP SCP commands where the src value is 0x00 instead of 0x20. This is
6983 * done after the DSP is loaded.
6985 static void ca0132_alt_dsp_scp_startup(struct hda_codec *codec)
6987 struct ca0132_spec *spec = codec->spec;
6988 unsigned int tmp, i;
6991 * Gotta run these twice, or else mic works inconsistently. Not clear
6992 * why this is, but multiple tests have confirmed it.
6994 for (i = 0; i < 2; i++) {
6995 switch (spec->quirk) {
6999 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7001 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7003 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7005 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7007 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7009 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7014 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7016 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7018 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7020 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7022 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7029 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec *codec)
7031 struct ca0132_spec *spec = codec->spec;
7034 chipio_set_stream_control(codec, 0x03, 0);
7035 chipio_set_stream_control(codec, 0x04, 0);
7037 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7038 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7041 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7043 chipio_set_stream_control(codec, 0x03, 1);
7044 chipio_set_stream_control(codec, 0x04, 1);
7046 switch (spec->quirk) {
7048 chipio_write(codec, 0x18b098, 0x0000000c);
7049 chipio_write(codec, 0x18b09C, 0x0000000c);
7052 chipio_write(codec, 0x18b098, 0x0000000c);
7053 chipio_write(codec, 0x18b09c, 0x0000004c);
7058 static void ae5_post_dsp_register_set(struct hda_codec *codec)
7060 struct ca0132_spec *spec = codec->spec;
7062 chipio_8051_write_direct(codec, 0x93, 0x10);
7063 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7064 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
7065 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7066 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
7068 writeb(0xff, spec->mem_base + 0x304);
7069 writeb(0xff, spec->mem_base + 0x304);
7070 writeb(0xff, spec->mem_base + 0x304);
7071 writeb(0xff, spec->mem_base + 0x304);
7072 writeb(0x00, spec->mem_base + 0x100);
7073 writeb(0xff, spec->mem_base + 0x304);
7074 writeb(0x00, spec->mem_base + 0x100);
7075 writeb(0xff, spec->mem_base + 0x304);
7076 writeb(0x00, spec->mem_base + 0x100);
7077 writeb(0xff, spec->mem_base + 0x304);
7078 writeb(0x00, spec->mem_base + 0x100);
7079 writeb(0xff, spec->mem_base + 0x304);
7081 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x3f);
7082 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
7083 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7086 static void ae5_post_dsp_param_setup(struct hda_codec *codec)
7089 * Param3 in the 8051's memory is represented by the ascii string 'mch'
7090 * which seems to be 'multichannel'. This is also mentioned in the
7091 * AE-5's registry values in Windows.
7093 chipio_set_control_param(codec, 3, 0);
7095 * I believe ASI is 'audio serial interface' and that it's used to
7096 * change colors on the external LED strip connected to the AE-5.
7098 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
7100 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
7101 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7103 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7104 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x92);
7105 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7106 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0xfa);
7107 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7108 VENDOR_CHIPIO_8051_DATA_WRITE, 0x22);
7111 static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
7113 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7114 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x41);
7115 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7116 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc8);
7118 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7119 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x45);
7120 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7121 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcc);
7123 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7124 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x40);
7125 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7126 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcb);
7128 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7129 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7130 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7131 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7133 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7134 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x51);
7135 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7136 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x8d);
7139 static void ae5_post_dsp_stream_setup(struct hda_codec *codec)
7141 struct ca0132_spec *spec = codec->spec;
7143 mutex_lock(&spec->chipio_mutex);
7145 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7147 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7149 chipio_set_stream_channels(codec, 0x0C, 6);
7150 chipio_set_stream_control(codec, 0x0C, 1);
7152 chipio_set_stream_source_dest(codec, 0x5, 0x43, 0x0);
7154 chipio_set_stream_source_dest(codec, 0x18, 0x9, 0xd0);
7155 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7156 chipio_set_stream_channels(codec, 0x18, 6);
7157 chipio_set_stream_control(codec, 0x18, 1);
7159 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7161 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7162 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7163 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7164 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7166 ca0113_mmio_command_set(codec, 0x48, 0x01, 0x80);
7168 mutex_unlock(&spec->chipio_mutex);
7171 static void ae5_post_dsp_startup_data(struct hda_codec *codec)
7173 struct ca0132_spec *spec = codec->spec;
7175 mutex_lock(&spec->chipio_mutex);
7177 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
7178 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
7179 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
7180 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
7182 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7183 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
7184 ca0113_mmio_command_set(codec, 0x48, 0x0b, 0x12);
7185 ca0113_mmio_command_set(codec, 0x48, 0x04, 0x00);
7186 ca0113_mmio_command_set(codec, 0x48, 0x06, 0x48);
7187 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7188 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7189 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7190 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7191 ca0113_mmio_gpio_set(codec, 0, true);
7192 ca0113_mmio_gpio_set(codec, 1, true);
7193 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x80);
7195 chipio_write_no_mutex(codec, 0x18b03c, 0x00000012);
7197 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7198 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7200 mutex_unlock(&spec->chipio_mutex);
7204 * Setup default parameters for DSP
7206 static void ca0132_setup_defaults(struct hda_codec *codec)
7208 struct ca0132_spec *spec = codec->spec;
7213 if (spec->dsp_state != DSP_DOWNLOADED)
7216 /* out, in effects + voicefx */
7217 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7218 for (idx = 0; idx < num_fx; idx++) {
7219 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7220 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
7221 ca0132_effects[idx].reqs[i],
7222 ca0132_effects[idx].def_vals[i]);
7226 /*remove DSP headroom*/
7228 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7230 /*set speaker EQ bypass attenuation*/
7231 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
7233 /* set AMic1 and AMic2 as mono mic */
7235 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7236 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
7238 /* set AMic1 as CrystalVoice input */
7240 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
7242 /* set WUH source */
7244 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7248 * Setup default parameters for Recon3D/Recon3Di DSP.
7251 static void r3d_setup_defaults(struct hda_codec *codec)
7253 struct ca0132_spec *spec = codec->spec;
7258 if (spec->dsp_state != DSP_DOWNLOADED)
7261 ca0132_alt_dsp_scp_startup(codec);
7262 ca0132_alt_init_analog_mics(codec);
7264 /*remove DSP headroom*/
7266 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7268 /* set WUH source */
7270 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7271 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7273 /* Set speaker source? */
7274 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7276 if (spec->quirk == QUIRK_R3DI)
7277 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
7279 /* Setup effect defaults */
7280 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7281 for (idx = 0; idx < num_fx; idx++) {
7282 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7283 dspio_set_uint_param(codec,
7284 ca0132_effects[idx].mid,
7285 ca0132_effects[idx].reqs[i],
7286 ca0132_effects[idx].def_vals[i]);
7292 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
7293 * than the Chromebook setup.
7295 static void sbz_setup_defaults(struct hda_codec *codec)
7297 struct ca0132_spec *spec = codec->spec;
7302 if (spec->dsp_state != DSP_DOWNLOADED)
7305 ca0132_alt_dsp_scp_startup(codec);
7306 ca0132_alt_init_analog_mics(codec);
7307 sbz_connect_streams(codec);
7308 sbz_chipio_startup_data(codec);
7310 chipio_set_stream_control(codec, 0x03, 1);
7311 chipio_set_stream_control(codec, 0x04, 1);
7314 * Sets internal input loopback to off, used to have a switch to
7315 * enable input loopback, but turned out to be way too buggy.
7318 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
7319 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
7321 /*remove DSP headroom*/
7323 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7325 /* set WUH source */
7327 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7328 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7330 /* Set speaker source? */
7331 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7333 ca0132_alt_dsp_initial_mic_setup(codec);
7335 /* out, in effects + voicefx */
7336 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7337 for (idx = 0; idx < num_fx; idx++) {
7338 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7339 dspio_set_uint_param(codec,
7340 ca0132_effects[idx].mid,
7341 ca0132_effects[idx].reqs[i],
7342 ca0132_effects[idx].def_vals[i]);
7346 ca0132_alt_create_dummy_stream(codec);
7350 * Setup default parameters for the Sound BlasterX AE-5 DSP.
7352 static void ae5_setup_defaults(struct hda_codec *codec)
7354 struct ca0132_spec *spec = codec->spec;
7359 if (spec->dsp_state != DSP_DOWNLOADED)
7362 ca0132_alt_dsp_scp_startup(codec);
7363 ca0132_alt_init_analog_mics(codec);
7364 chipio_set_stream_control(codec, 0x03, 1);
7365 chipio_set_stream_control(codec, 0x04, 1);
7367 /* New, unknown SCP req's */
7369 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
7370 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
7371 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
7372 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
7374 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
7375 ca0113_mmio_gpio_set(codec, 0, false);
7376 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
7378 /* Internal loopback off */
7380 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
7381 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
7383 /*remove DSP headroom*/
7385 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7387 /* set WUH source */
7389 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7390 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7392 /* Set speaker source? */
7393 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7395 ca0132_alt_dsp_initial_mic_setup(codec);
7396 ae5_post_dsp_register_set(codec);
7397 ae5_post_dsp_param_setup(codec);
7398 ae5_post_dsp_pll_setup(codec);
7399 ae5_post_dsp_stream_setup(codec);
7400 ae5_post_dsp_startup_data(codec);
7402 /* out, in effects + voicefx */
7403 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7404 for (idx = 0; idx < num_fx; idx++) {
7405 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7406 dspio_set_uint_param(codec,
7407 ca0132_effects[idx].mid,
7408 ca0132_effects[idx].reqs[i],
7409 ca0132_effects[idx].def_vals[i]);
7413 ca0132_alt_create_dummy_stream(codec);
7417 * Initialization of flags in chip
7419 static void ca0132_init_flags(struct hda_codec *codec)
7421 struct ca0132_spec *spec = codec->spec;
7423 if (spec->use_alt_functions) {
7424 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
7425 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
7426 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
7427 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
7428 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
7429 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
7430 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
7431 chipio_set_control_flag(codec,
7432 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
7433 chipio_set_control_flag(codec,
7434 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 1);
7436 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
7437 chipio_set_control_flag(codec,
7438 CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
7439 chipio_set_control_flag(codec,
7440 CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
7441 chipio_set_control_flag(codec,
7442 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
7443 chipio_set_control_flag(codec,
7444 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
7445 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
7450 * Initialization of parameters in chip
7452 static void ca0132_init_params(struct hda_codec *codec)
7454 struct ca0132_spec *spec = codec->spec;
7456 if (spec->use_alt_functions) {
7457 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7458 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
7459 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
7460 chipio_set_control_param(codec, 0, 0);
7461 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
7464 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
7465 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
7468 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
7470 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
7471 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
7472 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
7473 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
7474 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
7475 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
7477 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7478 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7479 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7482 static bool ca0132_download_dsp_images(struct hda_codec *codec)
7484 bool dsp_loaded = false;
7485 struct ca0132_spec *spec = codec->spec;
7486 const struct dsp_image_seg *dsp_os_image;
7487 const struct firmware *fw_entry;
7489 * Alternate firmwares for different variants. The Recon3Di apparently
7490 * can use the default firmware, but I'll leave the option in case
7491 * it needs it again.
7493 switch (spec->quirk) {
7497 if (request_firmware(&fw_entry, DESKTOP_EFX_FILE,
7498 codec->card->dev) != 0) {
7499 codec_dbg(codec, "Desktop firmware not found.");
7500 spec->alt_firmware_present = false;
7502 codec_dbg(codec, "Desktop firmware selected.");
7503 spec->alt_firmware_present = true;
7507 if (request_firmware(&fw_entry, R3DI_EFX_FILE,
7508 codec->card->dev) != 0) {
7509 codec_dbg(codec, "Recon3Di alt firmware not detected.");
7510 spec->alt_firmware_present = false;
7512 codec_dbg(codec, "Recon3Di firmware selected.");
7513 spec->alt_firmware_present = true;
7517 spec->alt_firmware_present = false;
7521 * Use default ctefx.bin if no alt firmware is detected, or if none
7522 * exists for your particular codec.
7524 if (!spec->alt_firmware_present) {
7525 codec_dbg(codec, "Default firmware selected.");
7526 if (request_firmware(&fw_entry, EFX_FILE,
7527 codec->card->dev) != 0)
7531 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
7532 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
7533 codec_err(codec, "ca0132 DSP load image failed\n");
7537 dsp_loaded = dspload_wait_loaded(codec);
7540 release_firmware(fw_entry);
7545 static void ca0132_download_dsp(struct hda_codec *codec)
7547 struct ca0132_spec *spec = codec->spec;
7549 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
7553 if (spec->dsp_state == DSP_DOWNLOAD_FAILED)
7554 return; /* don't retry failures */
7556 chipio_enable_clocks(codec);
7557 if (spec->dsp_state != DSP_DOWNLOADED) {
7558 spec->dsp_state = DSP_DOWNLOADING;
7560 if (!ca0132_download_dsp_images(codec))
7561 spec->dsp_state = DSP_DOWNLOAD_FAILED;
7563 spec->dsp_state = DSP_DOWNLOADED;
7566 /* For codecs using alt functions, this is already done earlier */
7567 if (spec->dsp_state == DSP_DOWNLOADED && (!spec->use_alt_functions))
7568 ca0132_set_dsp_msr(codec, true);
7571 static void ca0132_process_dsp_response(struct hda_codec *codec,
7572 struct hda_jack_callback *callback)
7574 struct ca0132_spec *spec = codec->spec;
7576 codec_dbg(codec, "ca0132_process_dsp_response\n");
7577 if (spec->wait_scp) {
7578 if (dspio_get_response_data(codec) >= 0)
7582 dspio_clear_response_queue(codec);
7585 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
7587 struct ca0132_spec *spec = codec->spec;
7588 struct hda_jack_tbl *tbl;
7590 /* Delay enabling the HP amp, to let the mic-detection
7591 * state machine run.
7593 cancel_delayed_work_sync(&spec->unsol_hp_work);
7594 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
7595 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
7597 tbl->block_report = 1;
7600 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
7602 struct ca0132_spec *spec = codec->spec;
7604 if (spec->use_alt_functions)
7605 ca0132_alt_select_in(codec);
7607 ca0132_select_mic(codec);
7610 static void ca0132_init_unsol(struct hda_codec *codec)
7612 struct ca0132_spec *spec = codec->spec;
7613 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
7614 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
7616 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
7617 ca0132_process_dsp_response);
7618 /* Front headphone jack detection */
7619 if (spec->use_alt_functions)
7620 snd_hda_jack_detect_enable_callback(codec,
7621 spec->unsol_tag_front_hp, hp_callback);
7628 /* Sends before DSP download. */
7629 static struct hda_verb ca0132_base_init_verbs[] = {
7630 /*enable ct extension*/
7631 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
7636 static struct hda_verb ca0132_base_exit_verbs[] = {
7638 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
7639 /*disable ct extension*/
7640 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
7644 /* Other verbs tables. Sends after DSP download. */
7646 static struct hda_verb ca0132_init_verbs0[] = {
7647 /* chip init verbs */
7648 {0x15, 0x70D, 0xF0},
7649 {0x15, 0x70E, 0xFE},
7650 {0x15, 0x707, 0x75},
7651 {0x15, 0x707, 0xD3},
7652 {0x15, 0x707, 0x09},
7653 {0x15, 0x707, 0x53},
7654 {0x15, 0x707, 0xD4},
7655 {0x15, 0x707, 0xEF},
7656 {0x15, 0x707, 0x75},
7657 {0x15, 0x707, 0xD3},
7658 {0x15, 0x707, 0x09},
7659 {0x15, 0x707, 0x02},
7660 {0x15, 0x707, 0x37},
7661 {0x15, 0x707, 0x78},
7662 {0x15, 0x53C, 0xCE},
7663 {0x15, 0x575, 0xC9},
7664 {0x15, 0x53D, 0xCE},
7665 {0x15, 0x5B7, 0xC9},
7666 {0x15, 0x70D, 0xE8},
7667 {0x15, 0x70E, 0xFE},
7668 {0x15, 0x707, 0x02},
7669 {0x15, 0x707, 0x68},
7670 {0x15, 0x707, 0x62},
7671 {0x15, 0x53A, 0xCE},
7672 {0x15, 0x546, 0xC9},
7673 {0x15, 0x53B, 0xCE},
7674 {0x15, 0x5E8, 0xC9},
7678 /* Extra init verbs for desktop cards. */
7679 static struct hda_verb ca0132_init_verbs1[] = {
7680 {0x15, 0x70D, 0x20},
7681 {0x15, 0x70E, 0x19},
7682 {0x15, 0x707, 0x00},
7683 {0x15, 0x539, 0xCE},
7684 {0x15, 0x546, 0xC9},
7685 {0x15, 0x70D, 0xB7},
7686 {0x15, 0x70E, 0x09},
7687 {0x15, 0x707, 0x10},
7688 {0x15, 0x70D, 0xAF},
7689 {0x15, 0x70E, 0x09},
7690 {0x15, 0x707, 0x01},
7691 {0x15, 0x707, 0x05},
7692 {0x15, 0x70D, 0x73},
7693 {0x15, 0x70E, 0x09},
7694 {0x15, 0x707, 0x14},
7695 {0x15, 0x6FF, 0xC4},
7699 static void ca0132_init_chip(struct hda_codec *codec)
7701 struct ca0132_spec *spec = codec->spec;
7706 mutex_init(&spec->chipio_mutex);
7708 spec->cur_out_type = SPEAKER_OUT;
7709 if (!spec->use_alt_functions)
7710 spec->cur_mic_type = DIGITAL_MIC;
7712 spec->cur_mic_type = REAR_MIC;
7714 spec->cur_mic_boost = 0;
7716 for (i = 0; i < VNODES_COUNT; i++) {
7717 spec->vnode_lvol[i] = 0x5a;
7718 spec->vnode_rvol[i] = 0x5a;
7719 spec->vnode_lswitch[i] = 0;
7720 spec->vnode_rswitch[i] = 0;
7724 * Default states for effects are in ca0132_effects[].
7726 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
7727 for (i = 0; i < num_fx; i++) {
7728 on = (unsigned int)ca0132_effects[i].reqs[0];
7729 spec->effects_switch[i] = on ? 1 : 0;
7732 * Sets defaults for the effect slider controls, only for alternative
7733 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
7735 if (spec->use_alt_controls) {
7736 spec->xbass_xover_freq = 8;
7737 for (i = 0; i < EFFECT_LEVEL_SLIDERS; i++)
7738 spec->fx_ctl_val[i] = effect_slider_defaults[i];
7741 spec->voicefx_val = 0;
7742 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
7743 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
7746 * The ZxR doesn't have a front panel header, and it's line-in is on
7747 * the daughter board. So, there is no input enum control, and we need
7748 * to make sure that spec->in_enum_val is set properly.
7750 if (spec->quirk == QUIRK_ZXR)
7751 spec->in_enum_val = REAR_MIC;
7753 #ifdef ENABLE_TUNING_CONTROLS
7754 ca0132_init_tuning_defaults(codec);
7759 * Recon3Di exit specific commands.
7761 /* prevents popping noise on shutdown */
7762 static void r3di_gpio_shutdown(struct hda_codec *codec)
7764 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
7768 * Sound Blaster Z exit specific commands.
7770 static void sbz_region2_exit(struct hda_codec *codec)
7772 struct ca0132_spec *spec = codec->spec;
7775 for (i = 0; i < 4; i++)
7776 writeb(0x0, spec->mem_base + 0x100);
7777 for (i = 0; i < 8; i++)
7778 writeb(0xb3, spec->mem_base + 0x304);
7780 ca0113_mmio_gpio_set(codec, 0, false);
7781 ca0113_mmio_gpio_set(codec, 1, false);
7782 ca0113_mmio_gpio_set(codec, 4, true);
7783 ca0113_mmio_gpio_set(codec, 5, false);
7784 ca0113_mmio_gpio_set(codec, 7, false);
7787 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
7789 hda_nid_t pins[5] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
7792 snd_hda_codec_write(codec, 0x11, 0,
7793 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40);
7795 for (i = 0; i < 5; i++)
7796 snd_hda_codec_write(codec, pins[i], 0,
7797 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00);
7800 static void ca0132_clear_unsolicited(struct hda_codec *codec)
7802 hda_nid_t pins[7] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
7805 for (i = 0; i < 7; i++) {
7806 snd_hda_codec_write(codec, pins[i], 0,
7807 AC_VERB_SET_UNSOLICITED_ENABLE, 0x00);
7811 /* On shutdown, sends commands in sets of three */
7812 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
7816 snd_hda_codec_write(codec, 0x01, 0,
7817 AC_VERB_SET_GPIO_DIRECTION, dir);
7819 snd_hda_codec_write(codec, 0x01, 0,
7820 AC_VERB_SET_GPIO_MASK, mask);
7823 snd_hda_codec_write(codec, 0x01, 0,
7824 AC_VERB_SET_GPIO_DATA, data);
7827 static void zxr_dbpro_power_state_shutdown(struct hda_codec *codec)
7829 hda_nid_t pins[7] = {0x05, 0x0c, 0x09, 0x0e, 0x08, 0x11, 0x01};
7832 for (i = 0; i < 7; i++)
7833 snd_hda_codec_write(codec, pins[i], 0,
7834 AC_VERB_SET_POWER_STATE, 0x03);
7837 static void sbz_exit_chip(struct hda_codec *codec)
7839 chipio_set_stream_control(codec, 0x03, 0);
7840 chipio_set_stream_control(codec, 0x04, 0);
7842 /* Mess with GPIO */
7843 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
7844 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
7845 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
7847 chipio_set_stream_control(codec, 0x14, 0);
7848 chipio_set_stream_control(codec, 0x0C, 0);
7850 chipio_set_conn_rate(codec, 0x41, SR_192_000);
7851 chipio_set_conn_rate(codec, 0x91, SR_192_000);
7853 chipio_write(codec, 0x18a020, 0x00000083);
7855 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
7856 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
7857 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
7859 chipio_set_stream_control(codec, 0x0C, 0);
7861 chipio_set_control_param(codec, 0x0D, 0x24);
7863 ca0132_clear_unsolicited(codec);
7864 sbz_set_pin_ctl_default(codec);
7866 snd_hda_codec_write(codec, 0x0B, 0,
7867 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
7869 sbz_region2_exit(codec);
7872 static void r3d_exit_chip(struct hda_codec *codec)
7874 ca0132_clear_unsolicited(codec);
7875 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7876 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
7879 static void ae5_exit_chip(struct hda_codec *codec)
7881 chipio_set_stream_control(codec, 0x03, 0);
7882 chipio_set_stream_control(codec, 0x04, 0);
7884 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
7885 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7886 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7887 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
7888 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
7889 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x00);
7890 ca0113_mmio_gpio_set(codec, 0, false);
7891 ca0113_mmio_gpio_set(codec, 1, false);
7893 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7894 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
7896 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7898 chipio_set_stream_control(codec, 0x18, 0);
7899 chipio_set_stream_control(codec, 0x0c, 0);
7901 snd_hda_codec_write(codec, 0x01, 0, 0x724, 0x83);
7904 static void zxr_exit_chip(struct hda_codec *codec)
7906 chipio_set_stream_control(codec, 0x03, 0);
7907 chipio_set_stream_control(codec, 0x04, 0);
7908 chipio_set_stream_control(codec, 0x14, 0);
7909 chipio_set_stream_control(codec, 0x0C, 0);
7911 chipio_set_conn_rate(codec, 0x41, SR_192_000);
7912 chipio_set_conn_rate(codec, 0x91, SR_192_000);
7914 chipio_write(codec, 0x18a020, 0x00000083);
7916 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7917 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
7919 ca0132_clear_unsolicited(codec);
7920 sbz_set_pin_ctl_default(codec);
7921 snd_hda_codec_write(codec, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x00);
7923 ca0113_mmio_gpio_set(codec, 5, false);
7924 ca0113_mmio_gpio_set(codec, 2, false);
7925 ca0113_mmio_gpio_set(codec, 3, false);
7926 ca0113_mmio_gpio_set(codec, 0, false);
7927 ca0113_mmio_gpio_set(codec, 4, true);
7928 ca0113_mmio_gpio_set(codec, 0, true);
7929 ca0113_mmio_gpio_set(codec, 5, true);
7930 ca0113_mmio_gpio_set(codec, 2, false);
7931 ca0113_mmio_gpio_set(codec, 3, false);
7934 static void ca0132_exit_chip(struct hda_codec *codec)
7936 /* put any chip cleanup stuffs here. */
7938 if (dspload_is_loaded(codec))
7943 * This fixes a problem that was hard to reproduce. Very rarely, I would
7944 * boot up, and there would be no sound, but the DSP indicated it had loaded
7945 * properly. I did a few memory dumps to see if anything was different, and
7946 * there were a few areas of memory uninitialized with a1a2a3a4. This function
7947 * checks if those areas are uninitialized, and if they are, it'll attempt to
7948 * reload the card 3 times. Usually it fixes by the second.
7950 static void sbz_dsp_startup_check(struct hda_codec *codec)
7952 struct ca0132_spec *spec = codec->spec;
7953 unsigned int dsp_data_check[4];
7954 unsigned int cur_address = 0x390;
7956 unsigned int failure = 0;
7957 unsigned int reload = 3;
7959 if (spec->startup_check_entered)
7962 spec->startup_check_entered = true;
7964 for (i = 0; i < 4; i++) {
7965 chipio_read(codec, cur_address, &dsp_data_check[i]);
7968 for (i = 0; i < 4; i++) {
7969 if (dsp_data_check[i] == 0xa1a2a3a4)
7973 codec_dbg(codec, "Startup Check: %d ", failure);
7975 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
7977 * While the failure condition is true, and we haven't reached our
7978 * three reload limit, continue trying to reload the driver and
7981 while (failure && (reload != 0)) {
7982 codec_info(codec, "Reloading... Tries left: %d", reload);
7983 sbz_exit_chip(codec);
7984 spec->dsp_state = DSP_DOWNLOAD_INIT;
7985 codec->patch_ops.init(codec);
7987 for (i = 0; i < 4; i++) {
7988 chipio_read(codec, cur_address, &dsp_data_check[i]);
7991 for (i = 0; i < 4; i++) {
7992 if (dsp_data_check[i] == 0xa1a2a3a4)
7998 if (!failure && reload < 3)
7999 codec_info(codec, "DSP fixed.");
8004 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
8008 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
8009 * extra precision for decibel values. If you had the dB value in floating point
8010 * you would take the value after the decimal point, multiply by 64, and divide
8011 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
8012 * implement fixed point or floating point dB volumes. For now, I'll set them
8013 * to 0 just incase a value has lingered from a boot into Windows.
8015 static void ca0132_alt_vol_setup(struct hda_codec *codec)
8017 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
8018 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
8019 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
8020 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
8021 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
8022 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
8023 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
8024 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
8028 * Extra commands that don't really fit anywhere else.
8030 static void sbz_pre_dsp_setup(struct hda_codec *codec)
8032 struct ca0132_spec *spec = codec->spec;
8034 writel(0x00820680, spec->mem_base + 0x01C);
8035 writel(0x00820680, spec->mem_base + 0x01C);
8037 chipio_write(codec, 0x18b0a4, 0x000000c2);
8039 snd_hda_codec_write(codec, 0x11, 0,
8040 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
8043 static void r3d_pre_dsp_setup(struct hda_codec *codec)
8045 chipio_write(codec, 0x18b0a4, 0x000000c2);
8047 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8048 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
8049 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8050 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
8051 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8052 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
8054 snd_hda_codec_write(codec, 0x11, 0,
8055 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
8058 static void r3di_pre_dsp_setup(struct hda_codec *codec)
8060 chipio_write(codec, 0x18b0a4, 0x000000c2);
8062 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8063 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
8064 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8065 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
8066 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8067 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
8069 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8070 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
8071 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8072 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
8073 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8074 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
8075 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8076 VENDOR_CHIPIO_8051_DATA_WRITE, 0x40);
8078 snd_hda_codec_write(codec, 0x11, 0,
8079 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
8083 * These are sent before the DSP is downloaded. Not sure
8084 * what they do, or if they're necessary. Could possibly
8085 * be removed. Figure they're better to leave in.
8087 static void ca0132_mmio_init(struct hda_codec *codec)
8089 struct ca0132_spec *spec = codec->spec;
8091 if (spec->quirk == QUIRK_AE5)
8092 writel(0x00000001, spec->mem_base + 0x400);
8094 writel(0x00000000, spec->mem_base + 0x400);
8096 if (spec->quirk == QUIRK_AE5)
8097 writel(0x00000001, spec->mem_base + 0x408);
8099 writel(0x00000000, spec->mem_base + 0x408);
8101 if (spec->quirk == QUIRK_AE5)
8102 writel(0x00000001, spec->mem_base + 0x40c);
8104 writel(0x00000000, spec->mem_base + 0x40C);
8106 if (spec->quirk == QUIRK_ZXR)
8107 writel(0x00880640, spec->mem_base + 0x01C);
8109 writel(0x00880680, spec->mem_base + 0x01C);
8111 if (spec->quirk == QUIRK_AE5)
8112 writel(0x00000080, spec->mem_base + 0xC0C);
8114 writel(0x00000083, spec->mem_base + 0xC0C);
8116 writel(0x00000030, spec->mem_base + 0xC00);
8117 writel(0x00000000, spec->mem_base + 0xC04);
8119 if (spec->quirk == QUIRK_AE5)
8120 writel(0x00000000, spec->mem_base + 0xC0C);
8122 writel(0x00000003, spec->mem_base + 0xC0C);
8124 writel(0x00000003, spec->mem_base + 0xC0C);
8125 writel(0x00000003, spec->mem_base + 0xC0C);
8126 writel(0x00000003, spec->mem_base + 0xC0C);
8128 if (spec->quirk == QUIRK_AE5)
8129 writel(0x00000001, spec->mem_base + 0xC08);
8131 writel(0x000000C1, spec->mem_base + 0xC08);
8133 writel(0x000000F1, spec->mem_base + 0xC08);
8134 writel(0x00000001, spec->mem_base + 0xC08);
8135 writel(0x000000C7, spec->mem_base + 0xC08);
8136 writel(0x000000C1, spec->mem_base + 0xC08);
8137 writel(0x00000080, spec->mem_base + 0xC04);
8139 if (spec->quirk == QUIRK_AE5) {
8140 writel(0x00000000, spec->mem_base + 0x42c);
8141 writel(0x00000000, spec->mem_base + 0x46c);
8142 writel(0x00000000, spec->mem_base + 0x4ac);
8143 writel(0x00000000, spec->mem_base + 0x4ec);
8144 writel(0x00000000, spec->mem_base + 0x43c);
8145 writel(0x00000000, spec->mem_base + 0x47c);
8146 writel(0x00000000, spec->mem_base + 0x4bc);
8147 writel(0x00000000, spec->mem_base + 0x4fc);
8148 writel(0x00000600, spec->mem_base + 0x100);
8149 writel(0x00000014, spec->mem_base + 0x410);
8150 writel(0x0000060f, spec->mem_base + 0x100);
8151 writel(0x0000070f, spec->mem_base + 0x100);
8152 writel(0x00000aff, spec->mem_base + 0x830);
8153 writel(0x00000000, spec->mem_base + 0x86c);
8154 writel(0x0000006b, spec->mem_base + 0x800);
8155 writel(0x00000001, spec->mem_base + 0x86c);
8156 writel(0x0000006b, spec->mem_base + 0x800);
8157 writel(0x00000057, spec->mem_base + 0x804);
8158 writel(0x00800000, spec->mem_base + 0x20c);
8163 * This function writes to some SFR's, does some region2 writes, and then
8164 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
8167 static void ae5_register_set(struct hda_codec *codec)
8169 struct ca0132_spec *spec = codec->spec;
8171 chipio_8051_write_direct(codec, 0x93, 0x10);
8172 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8173 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
8174 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8175 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
8177 writeb(0x0f, spec->mem_base + 0x304);
8178 writeb(0x0f, spec->mem_base + 0x304);
8179 writeb(0x0f, spec->mem_base + 0x304);
8180 writeb(0x0f, spec->mem_base + 0x304);
8181 writeb(0x0e, spec->mem_base + 0x100);
8182 writeb(0x1f, spec->mem_base + 0x304);
8183 writeb(0x0c, spec->mem_base + 0x100);
8184 writeb(0x3f, spec->mem_base + 0x304);
8185 writeb(0x08, spec->mem_base + 0x100);
8186 writeb(0x7f, spec->mem_base + 0x304);
8187 writeb(0x00, spec->mem_base + 0x100);
8188 writeb(0xff, spec->mem_base + 0x304);
8190 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
8192 chipio_8051_write_direct(codec, 0x90, 0x00);
8193 chipio_8051_write_direct(codec, 0x90, 0x10);
8195 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8197 chipio_write(codec, 0x18b0a4, 0x000000c2);
8199 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
8200 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
8204 * Extra init functions for alternative ca0132 codecs. Done
8205 * here so they don't clutter up the main ca0132_init function
8206 * anymore than they have to.
8208 static void ca0132_alt_init(struct hda_codec *codec)
8210 struct ca0132_spec *spec = codec->spec;
8212 ca0132_alt_vol_setup(codec);
8214 switch (spec->quirk) {
8216 codec_dbg(codec, "SBZ alt_init");
8217 ca0132_gpio_init(codec);
8218 sbz_pre_dsp_setup(codec);
8219 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8220 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8223 codec_dbg(codec, "R3DI alt_init");
8224 ca0132_gpio_init(codec);
8225 ca0132_gpio_setup(codec);
8226 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
8227 r3di_pre_dsp_setup(codec);
8228 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8229 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
8232 r3d_pre_dsp_setup(codec);
8233 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8234 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8237 ca0132_gpio_init(codec);
8238 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8239 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x49);
8240 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8241 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x88);
8242 chipio_write(codec, 0x18b030, 0x00000020);
8243 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8244 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8245 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8248 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8249 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8254 static int ca0132_init(struct hda_codec *codec)
8256 struct ca0132_spec *spec = codec->spec;
8257 struct auto_pin_cfg *cfg = &spec->autocfg;
8262 * If the DSP is already downloaded, and init has been entered again,
8263 * there's only two reasons for it. One, the codec has awaken from a
8264 * suspended state, and in that case dspload_is_loaded will return
8265 * false, and the init will be ran again. The other reason it gets
8266 * re entered is on startup for some reason it triggers a suspend and
8267 * resume state. In this case, it will check if the DSP is downloaded,
8268 * and not run the init function again. For codecs using alt_functions,
8269 * it will check if the DSP is loaded properly.
8271 if (spec->dsp_state == DSP_DOWNLOADED) {
8272 dsp_loaded = dspload_is_loaded(codec);
8274 spec->dsp_reload = true;
8275 spec->dsp_state = DSP_DOWNLOAD_INIT;
8277 if (spec->quirk == QUIRK_SBZ)
8278 sbz_dsp_startup_check(codec);
8283 if (spec->dsp_state != DSP_DOWNLOAD_FAILED)
8284 spec->dsp_state = DSP_DOWNLOAD_INIT;
8285 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
8287 if (spec->use_pci_mmio)
8288 ca0132_mmio_init(codec);
8290 snd_hda_power_up_pm(codec);
8292 if (spec->quirk == QUIRK_AE5)
8293 ae5_register_set(codec);
8295 ca0132_init_unsol(codec);
8296 ca0132_init_params(codec);
8297 ca0132_init_flags(codec);
8299 snd_hda_sequence_write(codec, spec->base_init_verbs);
8301 if (spec->use_alt_functions)
8302 ca0132_alt_init(codec);
8304 ca0132_download_dsp(codec);
8306 ca0132_refresh_widget_caps(codec);
8308 switch (spec->quirk) {
8311 r3d_setup_defaults(codec);
8315 sbz_setup_defaults(codec);
8318 ae5_setup_defaults(codec);
8321 ca0132_setup_defaults(codec);
8322 ca0132_init_analog_mic2(codec);
8323 ca0132_init_dmic(codec);
8327 for (i = 0; i < spec->num_outputs; i++)
8328 init_output(codec, spec->out_pins[i], spec->dacs[0]);
8330 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
8332 for (i = 0; i < spec->num_inputs; i++)
8333 init_input(codec, spec->input_pins[i], spec->adcs[i]);
8335 init_input(codec, cfg->dig_in_pin, spec->dig_in);
8337 if (!spec->use_alt_functions) {
8338 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8339 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8340 VENDOR_CHIPIO_PARAM_EX_ID_SET, 0x0D);
8341 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8342 VENDOR_CHIPIO_PARAM_EX_VALUE_SET, 0x20);
8345 if (spec->quirk == QUIRK_SBZ)
8346 ca0132_gpio_setup(codec);
8348 snd_hda_sequence_write(codec, spec->spec_init_verbs);
8349 if (spec->use_alt_functions) {
8350 ca0132_alt_select_out(codec);
8351 ca0132_alt_select_in(codec);
8353 ca0132_select_out(codec);
8354 ca0132_select_mic(codec);
8357 snd_hda_jack_report_sync(codec);
8360 * Re set the PlayEnhancement switch on a resume event, because the
8361 * controls will not be reloaded.
8363 if (spec->dsp_reload) {
8364 spec->dsp_reload = false;
8365 ca0132_pe_switch_set(codec);
8368 snd_hda_power_down_pm(codec);
8373 static int dbpro_init(struct hda_codec *codec)
8375 struct ca0132_spec *spec = codec->spec;
8376 struct auto_pin_cfg *cfg = &spec->autocfg;
8379 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
8380 init_input(codec, cfg->dig_in_pin, spec->dig_in);
8382 for (i = 0; i < spec->num_inputs; i++)
8383 init_input(codec, spec->input_pins[i], spec->adcs[i]);
8388 static void ca0132_free(struct hda_codec *codec)
8390 struct ca0132_spec *spec = codec->spec;
8392 cancel_delayed_work_sync(&spec->unsol_hp_work);
8393 snd_hda_power_up(codec);
8394 switch (spec->quirk) {
8396 sbz_exit_chip(codec);
8399 zxr_exit_chip(codec);
8402 r3d_exit_chip(codec);
8405 ae5_exit_chip(codec);
8408 r3di_gpio_shutdown(codec);
8412 snd_hda_sequence_write(codec, spec->base_exit_verbs);
8413 ca0132_exit_chip(codec);
8415 snd_hda_power_down(codec);
8417 pci_iounmap(codec->bus->pci, spec->mem_base);
8418 kfree(spec->spec_init_verbs);
8422 static void dbpro_free(struct hda_codec *codec)
8424 struct ca0132_spec *spec = codec->spec;
8426 zxr_dbpro_power_state_shutdown(codec);
8428 kfree(spec->spec_init_verbs);
8432 static void ca0132_reboot_notify(struct hda_codec *codec)
8434 codec->patch_ops.free(codec);
8437 static const struct hda_codec_ops ca0132_patch_ops = {
8438 .build_controls = ca0132_build_controls,
8439 .build_pcms = ca0132_build_pcms,
8440 .init = ca0132_init,
8441 .free = ca0132_free,
8442 .unsol_event = snd_hda_jack_unsol_event,
8443 .reboot_notify = ca0132_reboot_notify,
8446 static const struct hda_codec_ops dbpro_patch_ops = {
8447 .build_controls = dbpro_build_controls,
8448 .build_pcms = dbpro_build_pcms,
8453 static void ca0132_config(struct hda_codec *codec)
8455 struct ca0132_spec *spec = codec->spec;
8457 spec->dacs[0] = 0x2;
8458 spec->dacs[1] = 0x3;
8459 spec->dacs[2] = 0x4;
8461 spec->multiout.dac_nids = spec->dacs;
8462 spec->multiout.num_dacs = 3;
8464 if (!spec->use_alt_functions)
8465 spec->multiout.max_channels = 2;
8467 spec->multiout.max_channels = 6;
8469 switch (spec->quirk) {
8470 case QUIRK_ALIENWARE:
8471 codec_dbg(codec, "%s: QUIRK_ALIENWARE applied.\n", __func__);
8472 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
8475 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
8476 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
8479 codec_dbg(codec, "%s: QUIRK_ZXR applied.\n", __func__);
8480 snd_hda_apply_pincfgs(codec, zxr_pincfgs);
8483 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
8484 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
8487 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
8488 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
8491 codec_dbg(codec, "%s: QUIRK_AE5 applied.\n", __func__);
8492 snd_hda_apply_pincfgs(codec, ae5_pincfgs);
8496 switch (spec->quirk) {
8497 case QUIRK_ALIENWARE:
8498 spec->num_outputs = 2;
8499 spec->out_pins[0] = 0x0b; /* speaker out */
8500 spec->out_pins[1] = 0x0f;
8501 spec->shared_out_nid = 0x2;
8502 spec->unsol_tag_hp = 0x0f;
8504 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
8505 spec->adcs[1] = 0x8; /* analog mic2 */
8506 spec->adcs[2] = 0xa; /* what u hear */
8508 spec->num_inputs = 3;
8509 spec->input_pins[0] = 0x12;
8510 spec->input_pins[1] = 0x11;
8511 spec->input_pins[2] = 0x13;
8512 spec->shared_mic_nid = 0x7;
8513 spec->unsol_tag_amic1 = 0x11;
8517 spec->num_outputs = 2;
8518 spec->out_pins[0] = 0x0B; /* Line out */
8519 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8520 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8521 spec->out_pins[3] = 0x11; /* Rear surround */
8522 spec->shared_out_nid = 0x2;
8523 spec->unsol_tag_hp = spec->out_pins[1];
8524 spec->unsol_tag_front_hp = spec->out_pins[2];
8526 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8527 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
8528 spec->adcs[2] = 0xa; /* what u hear */
8530 spec->num_inputs = 2;
8531 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8532 spec->input_pins[1] = 0x13; /* What U Hear */
8533 spec->shared_mic_nid = 0x7;
8534 spec->unsol_tag_amic1 = spec->input_pins[0];
8537 spec->dig_out = 0x05;
8538 spec->multiout.dig_out_nid = spec->dig_out;
8539 spec->dig_in = 0x09;
8542 spec->num_outputs = 2;
8543 spec->out_pins[0] = 0x0B; /* Line out */
8544 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8545 spec->out_pins[2] = 0x10; /* Center/LFE */
8546 spec->out_pins[3] = 0x11; /* Rear surround */
8547 spec->shared_out_nid = 0x2;
8548 spec->unsol_tag_hp = spec->out_pins[1];
8549 spec->unsol_tag_front_hp = spec->out_pins[2];
8551 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8552 spec->adcs[1] = 0x8; /* Not connected, no front mic */
8553 spec->adcs[2] = 0xa; /* what u hear */
8555 spec->num_inputs = 2;
8556 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8557 spec->input_pins[1] = 0x13; /* What U Hear */
8558 spec->shared_mic_nid = 0x7;
8559 spec->unsol_tag_amic1 = spec->input_pins[0];
8561 case QUIRK_ZXR_DBPRO:
8562 spec->adcs[0] = 0x8; /* ZxR DBPro Aux In */
8564 spec->num_inputs = 1;
8565 spec->input_pins[0] = 0x11; /* RCA Line-in */
8567 spec->dig_out = 0x05;
8568 spec->multiout.dig_out_nid = spec->dig_out;
8570 spec->dig_in = 0x09;
8573 spec->num_outputs = 2;
8574 spec->out_pins[0] = 0x0B; /* Line out */
8575 spec->out_pins[1] = 0x11; /* Rear headphone out */
8576 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8577 spec->out_pins[3] = 0x0F; /* Rear surround */
8578 spec->shared_out_nid = 0x2;
8579 spec->unsol_tag_hp = spec->out_pins[1];
8580 spec->unsol_tag_front_hp = spec->out_pins[2];
8582 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8583 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
8584 spec->adcs[2] = 0xa; /* what u hear */
8586 spec->num_inputs = 2;
8587 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8588 spec->input_pins[1] = 0x13; /* What U Hear */
8589 spec->shared_mic_nid = 0x7;
8590 spec->unsol_tag_amic1 = spec->input_pins[0];
8593 spec->dig_out = 0x05;
8594 spec->multiout.dig_out_nid = spec->dig_out;
8597 spec->num_outputs = 2;
8598 spec->out_pins[0] = 0x0B; /* Line out */
8599 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8600 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8601 spec->out_pins[3] = 0x11; /* Rear surround */
8602 spec->shared_out_nid = 0x2;
8603 spec->unsol_tag_hp = spec->out_pins[1];
8604 spec->unsol_tag_front_hp = spec->out_pins[2];
8606 spec->adcs[0] = 0x07; /* Rear Mic / Line-in */
8607 spec->adcs[1] = 0x08; /* Front Mic, but only if no DSP */
8608 spec->adcs[2] = 0x0a; /* what u hear */
8610 spec->num_inputs = 2;
8611 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8612 spec->input_pins[1] = 0x13; /* What U Hear */
8613 spec->shared_mic_nid = 0x7;
8614 spec->unsol_tag_amic1 = spec->input_pins[0];
8617 spec->dig_out = 0x05;
8618 spec->multiout.dig_out_nid = spec->dig_out;
8621 spec->num_outputs = 2;
8622 spec->out_pins[0] = 0x0b; /* speaker out */
8623 spec->out_pins[1] = 0x10; /* headphone out */
8624 spec->shared_out_nid = 0x2;
8625 spec->unsol_tag_hp = spec->out_pins[1];
8627 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
8628 spec->adcs[1] = 0x8; /* analog mic2 */
8629 spec->adcs[2] = 0xa; /* what u hear */
8631 spec->num_inputs = 3;
8632 spec->input_pins[0] = 0x12;
8633 spec->input_pins[1] = 0x11;
8634 spec->input_pins[2] = 0x13;
8635 spec->shared_mic_nid = 0x7;
8636 spec->unsol_tag_amic1 = spec->input_pins[0];
8639 spec->dig_out = 0x05;
8640 spec->multiout.dig_out_nid = spec->dig_out;
8641 spec->dig_in = 0x09;
8646 static int ca0132_prepare_verbs(struct hda_codec *codec)
8648 /* Verbs + terminator (an empty element) */
8649 #define NUM_SPEC_VERBS 2
8650 struct ca0132_spec *spec = codec->spec;
8652 spec->chip_init_verbs = ca0132_init_verbs0;
8654 * Since desktop cards use pci_mmio, this can be used to determine
8655 * whether or not to use these verbs instead of a separate bool.
8657 if (spec->use_pci_mmio)
8658 spec->desktop_init_verbs = ca0132_init_verbs1;
8659 spec->spec_init_verbs = kcalloc(NUM_SPEC_VERBS,
8660 sizeof(struct hda_verb),
8662 if (!spec->spec_init_verbs)
8666 spec->spec_init_verbs[0].nid = 0x0b;
8667 spec->spec_init_verbs[0].param = 0x78D;
8668 spec->spec_init_verbs[0].verb = 0x00;
8670 /* Previously commented configuration */
8672 spec->spec_init_verbs[2].nid = 0x0b;
8673 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
8674 spec->spec_init_verbs[2].verb = 0x02;
8676 spec->spec_init_verbs[3].nid = 0x10;
8677 spec->spec_init_verbs[3].param = 0x78D;
8678 spec->spec_init_verbs[3].verb = 0x02;
8680 spec->spec_init_verbs[4].nid = 0x10;
8681 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
8682 spec->spec_init_verbs[4].verb = 0x02;
8685 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
8690 * The Sound Blaster ZxR shares the same PCI subsystem ID as some regular
8691 * Sound Blaster Z cards. However, they have different HDA codec subsystem
8692 * ID's. So, we check for the ZxR's subsystem ID, as well as the DBPro
8693 * daughter boards ID.
8695 static void sbz_detect_quirk(struct hda_codec *codec)
8697 struct ca0132_spec *spec = codec->spec;
8699 switch (codec->core.subsystem_id) {
8701 spec->quirk = QUIRK_ZXR;
8704 spec->quirk = QUIRK_ZXR_DBPRO;
8707 spec->quirk = QUIRK_SBZ;
8712 static int patch_ca0132(struct hda_codec *codec)
8714 struct ca0132_spec *spec;
8716 const struct snd_pci_quirk *quirk;
8718 codec_dbg(codec, "patch_ca0132\n");
8720 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8724 spec->codec = codec;
8726 /* Detect codec quirk */
8727 quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks);
8729 spec->quirk = quirk->value;
8731 spec->quirk = QUIRK_NONE;
8733 if (spec->quirk == QUIRK_SBZ)
8734 sbz_detect_quirk(codec);
8736 if (spec->quirk == QUIRK_ZXR_DBPRO)
8737 codec->patch_ops = dbpro_patch_ops;
8739 codec->patch_ops = ca0132_patch_ops;
8741 codec->pcm_format_first = 1;
8742 codec->no_sticky_stream = 1;
8745 spec->dsp_state = DSP_DOWNLOAD_INIT;
8746 spec->num_mixers = 1;
8748 /* Set which mixers each quirk uses. */
8749 switch (spec->quirk) {
8751 spec->mixers[0] = desktop_mixer;
8752 snd_hda_codec_set_name(codec, "Sound Blaster Z");
8755 spec->mixers[0] = desktop_mixer;
8756 snd_hda_codec_set_name(codec, "Sound Blaster ZxR");
8758 case QUIRK_ZXR_DBPRO:
8761 spec->mixers[0] = desktop_mixer;
8762 snd_hda_codec_set_name(codec, "Recon3D");
8765 spec->mixers[0] = r3di_mixer;
8766 snd_hda_codec_set_name(codec, "Recon3Di");
8769 spec->mixers[0] = desktop_mixer;
8770 snd_hda_codec_set_name(codec, "Sound BlasterX AE-5");
8773 spec->mixers[0] = ca0132_mixer;
8777 /* Setup whether or not to use alt functions/controls/pci_mmio */
8778 switch (spec->quirk) {
8783 spec->use_alt_controls = true;
8784 spec->use_alt_functions = true;
8785 spec->use_pci_mmio = true;
8788 spec->use_alt_controls = true;
8789 spec->use_alt_functions = true;
8790 spec->use_pci_mmio = false;
8793 spec->use_alt_controls = false;
8794 spec->use_alt_functions = false;
8795 spec->use_pci_mmio = false;
8799 if (spec->use_pci_mmio) {
8800 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
8801 if (spec->mem_base == NULL) {
8802 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
8803 spec->quirk = QUIRK_NONE;
8807 spec->base_init_verbs = ca0132_base_init_verbs;
8808 spec->base_exit_verbs = ca0132_base_exit_verbs;
8810 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
8812 ca0132_init_chip(codec);
8814 ca0132_config(codec);
8816 err = ca0132_prepare_verbs(codec);
8820 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
8834 static struct hda_device_id snd_hda_id_ca0132[] = {
8835 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132),
8838 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132);
8840 MODULE_LICENSE("GPL");
8841 MODULE_DESCRIPTION("Creative Sound Core3D codec");
8843 static struct hda_codec_driver ca0132_driver = {
8844 .id = snd_hda_id_ca0132,
8847 module_hda_codec_driver(ca0132_driver);