2 * HD audio interface patch for Creative CA0132 chip
4 * Copyright (c) 2011, Creative Technology Ltd.
6 * Based on patch_ca0110.c
7 * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/mutex.h>
28 #include <linux/module.h>
29 #include <linux/firmware.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
33 #include <linux/pci.h>
35 #include <sound/core.h>
36 #include <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 startup_check_entered;
1011 /* mixer and effects related */
1012 unsigned char dmic_ctl;
1015 long vnode_lvol[VNODES_COUNT];
1016 long vnode_rvol[VNODES_COUNT];
1017 long vnode_lswitch[VNODES_COUNT];
1018 long vnode_rswitch[VNODES_COUNT];
1019 long effects_switch[EFFECTS_COUNT];
1022 /* ca0132_alt control related values */
1023 unsigned char in_enum_val;
1024 unsigned char out_enum_val;
1025 unsigned char mic_boost_enum_val;
1026 unsigned char smart_volume_setting;
1027 long fx_ctl_val[EFFECT_LEVEL_SLIDERS];
1028 long xbass_xover_freq;
1030 unsigned int tlv[4];
1031 struct hda_vmaster_mute_hook vmaster_mute;
1032 /* AE-5 Control values */
1033 unsigned char ae5_headphone_gain_val;
1034 unsigned char ae5_filter_val;
1035 /* ZxR Control Values */
1036 unsigned char zxr_gain_set;
1038 struct hda_codec *codec;
1039 struct delayed_work unsol_hp_work;
1042 #ifdef ENABLE_TUNING_CONTROLS
1043 long cur_ctl_vals[TUNING_CTLS_COUNT];
1046 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
1047 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
1051 void __iomem *mem_base;
1054 * Whether or not to use the alt functions like alt_select_out,
1055 * alt_select_in, etc. Only used on desktop codecs for now, because of
1056 * surround sound support.
1058 bool use_alt_functions;
1061 * Whether or not to use alt controls: volume effect sliders, EQ
1062 * presets, smart volume presets, and new control names with FX prefix.
1063 * Renames PlayEnhancement and CrystalVoice too.
1065 bool use_alt_controls;
1069 * CA0132 quirks table
1074 QUIRK_ALIENWARE_M17XR4,
1084 #define ca0132_quirk(spec) ((spec)->quirk)
1085 #define ca0132_use_pci_mmio(spec) ((spec)->use_pci_mmio)
1086 #define ca0132_use_alt_functions(spec) ((spec)->use_alt_functions)
1087 #define ca0132_use_alt_controls(spec) ((spec)->use_alt_controls)
1089 #define ca0132_quirk(spec) ({ (void)(spec); QUIRK_NONE; })
1090 #define ca0132_use_alt_functions(spec) ({ (void)(spec); false; })
1091 #define ca0132_use_pci_mmio(spec) ({ (void)(spec); false; })
1092 #define ca0132_use_alt_controls(spec) ({ (void)(spec); false; })
1095 static const struct hda_pintbl alienware_pincfgs[] = {
1096 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1097 { 0x0c, 0x411111f0 }, /* N/A */
1098 { 0x0d, 0x411111f0 }, /* N/A */
1099 { 0x0e, 0x411111f0 }, /* N/A */
1100 { 0x0f, 0x0321101f }, /* HP */
1101 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1102 { 0x11, 0x03a11021 }, /* Mic */
1103 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1104 { 0x13, 0x411111f0 }, /* N/A */
1105 { 0x18, 0x411111f0 }, /* N/A */
1109 /* Sound Blaster Z pin configs taken from Windows Driver */
1110 static const struct hda_pintbl sbz_pincfgs[] = {
1111 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1112 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1113 { 0x0d, 0x014510f0 }, /* Digital Out */
1114 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1115 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1116 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1117 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1118 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1119 { 0x13, 0x908700f0 }, /* What U Hear In*/
1120 { 0x18, 0x50d000f0 }, /* N/A */
1124 /* Sound Blaster ZxR pin configs taken from Windows Driver */
1125 static const struct hda_pintbl zxr_pincfgs[] = {
1126 { 0x0b, 0x01047110 }, /* Port G -- Lineout FRONT L/R */
1127 { 0x0c, 0x414510f0 }, /* SPDIF Out 1 - Disabled*/
1128 { 0x0d, 0x014510f0 }, /* Digital Out */
1129 { 0x0e, 0x41c520f0 }, /* SPDIF In - Disabled*/
1130 { 0x0f, 0x0122711f }, /* Port A -- BackPanel HP */
1131 { 0x10, 0x01017111 }, /* Port D -- Center/LFE */
1132 { 0x11, 0x01017114 }, /* Port B -- LineMicIn2 / Rear L/R */
1133 { 0x12, 0x01a271f0 }, /* Port C -- LineIn1 */
1134 { 0x13, 0x908700f0 }, /* What U Hear In*/
1135 { 0x18, 0x50d000f0 }, /* N/A */
1139 /* Recon3D pin configs taken from Windows Driver */
1140 static const struct hda_pintbl r3d_pincfgs[] = {
1141 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1142 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1143 { 0x0d, 0x014510f0 }, /* Digital Out */
1144 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1145 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1146 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1147 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1148 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1149 { 0x13, 0x908700f0 }, /* What U Hear In*/
1150 { 0x18, 0x50d000f0 }, /* N/A */
1154 /* Sound Blaster AE-5 pin configs taken from Windows Driver */
1155 static const struct hda_pintbl ae5_pincfgs[] = {
1156 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1157 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1158 { 0x0d, 0x014510f0 }, /* Digital Out */
1159 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1160 { 0x0f, 0x01017114 }, /* Port A -- Rear L/R. */
1161 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1162 { 0x11, 0x01a170ff }, /* Port B -- LineMicIn2 / Rear Headphone */
1163 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1164 { 0x13, 0x908700f0 }, /* What U Hear In*/
1165 { 0x18, 0x50d000f0 }, /* N/A */
1169 /* Recon3D integrated pin configs taken from Windows Driver */
1170 static const struct hda_pintbl r3di_pincfgs[] = {
1171 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1172 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1173 { 0x0d, 0x014510f0 }, /* Digital Out */
1174 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1175 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1176 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1177 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1178 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1179 { 0x13, 0x908700f0 }, /* What U Hear In*/
1180 { 0x18, 0x500000f0 }, /* N/A */
1184 static const struct snd_pci_quirk ca0132_quirks[] = {
1185 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4),
1186 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE),
1187 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE),
1188 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE),
1189 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ),
1190 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ),
1191 SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ),
1192 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
1193 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
1194 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
1195 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1196 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5),
1201 * CA0132 codec access
1203 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1204 unsigned int verb, unsigned int parm, unsigned int *res)
1206 unsigned int response;
1207 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1210 return ((response == -1) ? -1 : 0);
1213 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1214 unsigned short converter_format, unsigned int *res)
1216 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1217 converter_format & 0xffff, res);
1220 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1221 hda_nid_t nid, unsigned char stream,
1222 unsigned char channel, unsigned int *res)
1224 unsigned char converter_stream_channel = 0;
1226 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1227 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1228 converter_stream_channel, res);
1231 /* Chip access helper function */
1232 static int chipio_send(struct hda_codec *codec,
1237 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1239 /* send bits of data specified by reg */
1241 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1243 if (res == VENDOR_STATUS_CHIPIO_OK)
1246 } while (time_before(jiffies, timeout));
1252 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1254 static int chipio_write_address(struct hda_codec *codec,
1255 unsigned int chip_addx)
1257 struct ca0132_spec *spec = codec->spec;
1260 if (spec->curr_chip_addx == chip_addx)
1263 /* send low 16 bits of the address */
1264 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1265 chip_addx & 0xffff);
1268 /* send high 16 bits of the address */
1269 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1273 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1279 * Write data through the vendor widget -- NOT protected by the Mutex!
1281 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1283 struct ca0132_spec *spec = codec->spec;
1286 /* send low 16 bits of the data */
1287 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1290 /* send high 16 bits of the data */
1291 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1295 /*If no error encountered, automatically increment the address
1296 as per chip behaviour*/
1297 spec->curr_chip_addx = (res != -EIO) ?
1298 (spec->curr_chip_addx + 4) : ~0U;
1303 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1305 static int chipio_write_data_multiple(struct hda_codec *codec,
1312 codec_dbg(codec, "chipio_write_data null ptr\n");
1316 while ((count-- != 0) && (status == 0))
1317 status = chipio_write_data(codec, *data++);
1324 * Read data through the vendor widget -- NOT protected by the Mutex!
1326 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1328 struct ca0132_spec *spec = codec->spec;
1332 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1336 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1341 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1342 VENDOR_CHIPIO_HIC_READ_DATA,
1346 /*If no error encountered, automatically increment the address
1347 as per chip behaviour*/
1348 spec->curr_chip_addx = (res != -EIO) ?
1349 (spec->curr_chip_addx + 4) : ~0U;
1354 * Write given value to the given address through the chip I/O widget.
1355 * protected by the Mutex
1357 static int chipio_write(struct hda_codec *codec,
1358 unsigned int chip_addx, const unsigned int data)
1360 struct ca0132_spec *spec = codec->spec;
1363 mutex_lock(&spec->chipio_mutex);
1365 /* write the address, and if successful proceed to write data */
1366 err = chipio_write_address(codec, chip_addx);
1370 err = chipio_write_data(codec, data);
1375 mutex_unlock(&spec->chipio_mutex);
1380 * Write given value to the given address through the chip I/O widget.
1381 * not protected by the Mutex
1383 static int chipio_write_no_mutex(struct hda_codec *codec,
1384 unsigned int chip_addx, const unsigned int data)
1389 /* write the address, and if successful proceed to write data */
1390 err = chipio_write_address(codec, chip_addx);
1394 err = chipio_write_data(codec, data);
1403 * Write multiple values to the given address through the chip I/O widget.
1404 * protected by the Mutex
1406 static int chipio_write_multiple(struct hda_codec *codec,
1411 struct ca0132_spec *spec = codec->spec;
1414 mutex_lock(&spec->chipio_mutex);
1415 status = chipio_write_address(codec, chip_addx);
1419 status = chipio_write_data_multiple(codec, data, count);
1421 mutex_unlock(&spec->chipio_mutex);
1427 * Read the given address through the chip I/O widget
1428 * protected by the Mutex
1430 static int chipio_read(struct hda_codec *codec,
1431 unsigned int chip_addx, unsigned int *data)
1433 struct ca0132_spec *spec = codec->spec;
1436 mutex_lock(&spec->chipio_mutex);
1438 /* write the address, and if successful proceed to write data */
1439 err = chipio_write_address(codec, chip_addx);
1443 err = chipio_read_data(codec, data);
1448 mutex_unlock(&spec->chipio_mutex);
1453 * Set chip control flags through the chip I/O widget.
1455 static void chipio_set_control_flag(struct hda_codec *codec,
1456 enum control_flag_id flag_id,
1460 unsigned int flag_bit;
1462 flag_bit = (flag_state ? 1 : 0);
1463 val = (flag_bit << 7) | (flag_id);
1464 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1465 VENDOR_CHIPIO_FLAG_SET, val);
1469 * Set chip parameters through the chip I/O widget.
1471 static void chipio_set_control_param(struct hda_codec *codec,
1472 enum control_param_id param_id, int param_val)
1474 struct ca0132_spec *spec = codec->spec;
1477 if ((param_id < 32) && (param_val < 8)) {
1478 val = (param_val << 5) | (param_id);
1479 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1480 VENDOR_CHIPIO_PARAM_SET, val);
1482 mutex_lock(&spec->chipio_mutex);
1483 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1484 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1485 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1487 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1488 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1491 mutex_unlock(&spec->chipio_mutex);
1496 * Set chip parameters through the chip I/O widget. NO MUTEX.
1498 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1499 enum control_param_id param_id, int param_val)
1503 if ((param_id < 32) && (param_val < 8)) {
1504 val = (param_val << 5) | (param_id);
1505 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1506 VENDOR_CHIPIO_PARAM_SET, val);
1508 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1509 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1510 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1512 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1513 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1519 * Connect stream to a source point, and then connect
1520 * that source point to a destination point.
1522 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1523 int streamid, int source_point, int dest_point)
1525 chipio_set_control_param_no_mutex(codec,
1526 CONTROL_PARAM_STREAM_ID, streamid);
1527 chipio_set_control_param_no_mutex(codec,
1528 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1529 chipio_set_control_param_no_mutex(codec,
1530 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1534 * Set number of channels in the selected stream.
1536 static void chipio_set_stream_channels(struct hda_codec *codec,
1537 int streamid, unsigned int channels)
1539 chipio_set_control_param_no_mutex(codec,
1540 CONTROL_PARAM_STREAM_ID, streamid);
1541 chipio_set_control_param_no_mutex(codec,
1542 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1546 * Enable/Disable audio stream.
1548 static void chipio_set_stream_control(struct hda_codec *codec,
1549 int streamid, int enable)
1551 chipio_set_control_param_no_mutex(codec,
1552 CONTROL_PARAM_STREAM_ID, streamid);
1553 chipio_set_control_param_no_mutex(codec,
1554 CONTROL_PARAM_STREAM_CONTROL, enable);
1559 * Set sampling rate of the connection point. NO MUTEX.
1561 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1562 int connid, enum ca0132_sample_rate rate)
1564 chipio_set_control_param_no_mutex(codec,
1565 CONTROL_PARAM_CONN_POINT_ID, connid);
1566 chipio_set_control_param_no_mutex(codec,
1567 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1571 * Set sampling rate of the connection point.
1573 static void chipio_set_conn_rate(struct hda_codec *codec,
1574 int connid, enum ca0132_sample_rate rate)
1576 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1577 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1582 * Writes to the 8051's internal address space directly instead of indirectly,
1583 * giving access to the special function registers located at addresses
1586 static void chipio_8051_write_direct(struct hda_codec *codec,
1587 unsigned int addr, unsigned int data)
1591 verb = VENDOR_CHIPIO_8051_WRITE_DIRECT | data;
1592 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1598 static void chipio_enable_clocks(struct hda_codec *codec)
1600 struct ca0132_spec *spec = codec->spec;
1602 mutex_lock(&spec->chipio_mutex);
1603 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1604 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1605 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1606 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1607 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1608 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1609 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1610 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1611 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1612 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1613 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1614 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1615 mutex_unlock(&spec->chipio_mutex);
1619 * CA0132 DSP IO stuffs
1621 static int dspio_send(struct hda_codec *codec, unsigned int reg,
1625 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1627 /* send bits of data specified by reg to dsp */
1629 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1630 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1633 } while (time_before(jiffies, timeout));
1639 * Wait for DSP to be ready for commands
1641 static void dspio_write_wait(struct hda_codec *codec)
1644 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1647 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1648 VENDOR_DSPIO_STATUS, 0);
1649 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1650 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1653 } while (time_before(jiffies, timeout));
1657 * Write SCP data to DSP
1659 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1661 struct ca0132_spec *spec = codec->spec;
1664 dspio_write_wait(codec);
1666 mutex_lock(&spec->chipio_mutex);
1667 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1672 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1677 /* OK, now check if the write itself has executed*/
1678 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1679 VENDOR_DSPIO_STATUS, 0);
1681 mutex_unlock(&spec->chipio_mutex);
1683 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1688 * Write multiple SCP data to DSP
1690 static int dspio_write_multiple(struct hda_codec *codec,
1691 unsigned int *buffer, unsigned int size)
1700 while (count < size) {
1701 status = dspio_write(codec, *buffer++);
1710 static int dspio_read(struct hda_codec *codec, unsigned int *data)
1714 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1718 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1719 if (status == -EIO ||
1720 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
1723 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1724 VENDOR_DSPIO_SCP_READ_DATA, 0);
1729 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
1730 unsigned int *buf_size, unsigned int size_count)
1733 unsigned int size = *buf_size;
1735 unsigned int skip_count;
1742 while (count < size && count < size_count) {
1743 status = dspio_read(codec, buffer++);
1751 while (skip_count < size) {
1752 status = dspio_read(codec, &dummy);
1764 * Construct the SCP header using corresponding fields
1766 static inline unsigned int
1767 make_scp_header(unsigned int target_id, unsigned int source_id,
1768 unsigned int get_flag, unsigned int req,
1769 unsigned int device_flag, unsigned int resp_flag,
1770 unsigned int error_flag, unsigned int data_size)
1772 unsigned int header = 0;
1774 header = (data_size & 0x1f) << 27;
1775 header |= (error_flag & 0x01) << 26;
1776 header |= (resp_flag & 0x01) << 25;
1777 header |= (device_flag & 0x01) << 24;
1778 header |= (req & 0x7f) << 17;
1779 header |= (get_flag & 0x01) << 16;
1780 header |= (source_id & 0xff) << 8;
1781 header |= target_id & 0xff;
1787 * Extract corresponding fields from SCP header
1790 extract_scp_header(unsigned int header,
1791 unsigned int *target_id, unsigned int *source_id,
1792 unsigned int *get_flag, unsigned int *req,
1793 unsigned int *device_flag, unsigned int *resp_flag,
1794 unsigned int *error_flag, unsigned int *data_size)
1797 *data_size = (header >> 27) & 0x1f;
1799 *error_flag = (header >> 26) & 0x01;
1801 *resp_flag = (header >> 25) & 0x01;
1803 *device_flag = (header >> 24) & 0x01;
1805 *req = (header >> 17) & 0x7f;
1807 *get_flag = (header >> 16) & 0x01;
1809 *source_id = (header >> 8) & 0xff;
1811 *target_id = header & 0xff;
1814 #define SCP_MAX_DATA_WORDS (16)
1816 /* Structure to contain any SCP message */
1819 unsigned int data[SCP_MAX_DATA_WORDS];
1822 static void dspio_clear_response_queue(struct hda_codec *codec)
1824 unsigned int dummy = 0;
1827 /* clear all from the response queue */
1829 status = dspio_read(codec, &dummy);
1830 } while (status == 0);
1833 static int dspio_get_response_data(struct hda_codec *codec)
1835 struct ca0132_spec *spec = codec->spec;
1836 unsigned int data = 0;
1839 if (dspio_read(codec, &data) < 0)
1842 if ((data & 0x00ffffff) == spec->wait_scp_header) {
1843 spec->scp_resp_header = data;
1844 spec->scp_resp_count = data >> 27;
1845 count = spec->wait_num_data;
1846 dspio_read_multiple(codec, spec->scp_resp_data,
1847 &spec->scp_resp_count, count);
1855 * Send SCP message to DSP
1857 static int dspio_send_scp_message(struct hda_codec *codec,
1858 unsigned char *send_buf,
1859 unsigned int send_buf_size,
1860 unsigned char *return_buf,
1861 unsigned int return_buf_size,
1862 unsigned int *bytes_returned)
1864 struct ca0132_spec *spec = codec->spec;
1866 unsigned int scp_send_size = 0;
1867 unsigned int total_size;
1868 bool waiting_for_resp = false;
1869 unsigned int header;
1870 struct scp_msg *ret_msg;
1871 unsigned int resp_src_id, resp_target_id;
1872 unsigned int data_size, src_id, target_id, get_flag, device_flag;
1875 *bytes_returned = 0;
1877 /* get scp header from buffer */
1878 header = *((unsigned int *)send_buf);
1879 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
1880 &device_flag, NULL, NULL, &data_size);
1881 scp_send_size = data_size + 1;
1882 total_size = (scp_send_size * 4);
1884 if (send_buf_size < total_size)
1887 if (get_flag || device_flag) {
1888 if (!return_buf || return_buf_size < 4 || !bytes_returned)
1891 spec->wait_scp_header = *((unsigned int *)send_buf);
1893 /* swap source id with target id */
1894 resp_target_id = src_id;
1895 resp_src_id = target_id;
1896 spec->wait_scp_header &= 0xffff0000;
1897 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
1898 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
1900 waiting_for_resp = true;
1903 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
1910 if (waiting_for_resp) {
1911 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1912 memset(return_buf, 0, return_buf_size);
1915 } while (spec->wait_scp && time_before(jiffies, timeout));
1916 waiting_for_resp = false;
1917 if (!spec->wait_scp) {
1918 ret_msg = (struct scp_msg *)return_buf;
1919 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
1920 memcpy(&ret_msg->data, spec->scp_resp_data,
1921 spec->wait_num_data);
1922 *bytes_returned = (spec->scp_resp_count + 1) * 4;
1934 * Prepare and send the SCP message to DSP
1935 * @codec: the HDA codec
1936 * @mod_id: ID of the DSP module to send the command
1937 * @req: ID of request to send to the DSP module
1939 * @data: pointer to the data to send with the request, request specific
1940 * @len: length of the data, in bytes
1941 * @reply: point to the buffer to hold data returned for a reply
1942 * @reply_len: length of the reply buffer returned from GET
1944 * Returns zero or a negative error code.
1946 static int dspio_scp(struct hda_codec *codec,
1947 int mod_id, int src_id, int req, int dir, const void *data,
1948 unsigned int len, void *reply, unsigned int *reply_len)
1951 struct scp_msg scp_send, scp_reply;
1952 unsigned int ret_bytes, send_size, ret_size;
1953 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
1954 unsigned int reply_data_size;
1956 memset(&scp_send, 0, sizeof(scp_send));
1957 memset(&scp_reply, 0, sizeof(scp_reply));
1959 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
1962 if (dir == SCP_GET && reply == NULL) {
1963 codec_dbg(codec, "dspio_scp get but has no buffer\n");
1967 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
1968 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
1972 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
1973 0, 0, 0, len/sizeof(unsigned int));
1974 if (data != NULL && len > 0) {
1975 len = min((unsigned int)(sizeof(scp_send.data)), len);
1976 memcpy(scp_send.data, data, len);
1980 send_size = sizeof(unsigned int) + len;
1981 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
1982 send_size, (unsigned char *)&scp_reply,
1983 sizeof(scp_reply), &ret_bytes);
1986 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
1990 /* extract send and reply headers members */
1991 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
1992 NULL, NULL, NULL, NULL, NULL);
1993 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
1994 &reply_resp_flag, &reply_error_flag,
2000 if (reply_resp_flag && !reply_error_flag) {
2001 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
2002 / sizeof(unsigned int);
2004 if (*reply_len < ret_size*sizeof(unsigned int)) {
2005 codec_dbg(codec, "reply too long for buf\n");
2007 } else if (ret_size != reply_data_size) {
2008 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
2010 } else if (!reply) {
2011 codec_dbg(codec, "NULL reply\n");
2014 *reply_len = ret_size*sizeof(unsigned int);
2015 memcpy(reply, scp_reply.data, *reply_len);
2018 codec_dbg(codec, "reply ill-formed or errflag set\n");
2026 * Set DSP parameters
2028 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2029 int src_id, int req, const void *data, unsigned int len)
2031 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2035 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2036 int req, const unsigned int data)
2038 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2039 sizeof(unsigned int));
2042 static int dspio_set_uint_param_no_source(struct hda_codec *codec, int mod_id,
2043 int req, const unsigned int data)
2045 return dspio_set_param(codec, mod_id, 0x00, req, &data,
2046 sizeof(unsigned int));
2050 * Allocate a DSP DMA channel via an SCP message
2052 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2055 unsigned int size = sizeof(dma_chan);
2057 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2058 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2059 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
2063 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2067 if ((*dma_chan + 1) == 0) {
2068 codec_dbg(codec, "no free dma channels to allocate\n");
2072 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2073 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2079 * Free a DSP DMA via an SCP message
2081 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2084 unsigned int dummy = 0;
2086 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2087 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2089 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2090 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
2091 sizeof(dma_chan), NULL, &dummy);
2094 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2098 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2106 static int dsp_set_run_state(struct hda_codec *codec)
2108 unsigned int dbg_ctrl_reg;
2109 unsigned int halt_state;
2112 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2116 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
2117 DSP_DBGCNTL_STATE_LOBIT;
2119 if (halt_state != 0) {
2120 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
2121 DSP_DBGCNTL_SS_MASK);
2122 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2127 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
2128 DSP_DBGCNTL_EXEC_MASK;
2129 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2141 static int dsp_reset(struct hda_codec *codec)
2146 codec_dbg(codec, "dsp_reset\n");
2148 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2150 } while (res == -EIO && retry);
2153 codec_dbg(codec, "dsp_reset timeout\n");
2161 * Convert chip address to DSP address
2163 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2164 bool *code, bool *yram)
2166 *code = *yram = false;
2168 if (UC_RANGE(chip_addx, 1)) {
2170 return UC_OFF(chip_addx);
2171 } else if (X_RANGE_ALL(chip_addx, 1)) {
2172 return X_OFF(chip_addx);
2173 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2175 return Y_OFF(chip_addx);
2178 return INVALID_CHIP_ADDRESS;
2182 * Check if the DSP DMA is active
2184 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2186 unsigned int dma_chnlstart_reg;
2188 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2190 return ((dma_chnlstart_reg & (1 <<
2191 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2194 static int dsp_dma_setup_common(struct hda_codec *codec,
2195 unsigned int chip_addx,
2196 unsigned int dma_chan,
2197 unsigned int port_map_mask,
2201 unsigned int chnl_prop;
2202 unsigned int dsp_addx;
2203 unsigned int active;
2206 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2208 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2209 codec_dbg(codec, "dma chan num invalid\n");
2213 if (dsp_is_dma_active(codec, dma_chan)) {
2214 codec_dbg(codec, "dma already active\n");
2218 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2220 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2221 codec_dbg(codec, "invalid chip addr\n");
2225 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2228 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2231 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2235 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2238 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2242 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2244 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2246 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2248 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2250 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2253 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2256 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2260 codec_dbg(codec, "read ACTIVE Reg fail\n");
2263 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2266 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2267 DSPDMAC_ACTIVE_AAR_MASK;
2269 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2271 codec_dbg(codec, "write ACTIVE Reg fail\n");
2275 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2277 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2280 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2283 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2285 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2286 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2288 codec_dbg(codec, "write IRQCNT Reg fail\n");
2291 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2294 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2295 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2296 chip_addx, dsp_addx, dma_chan,
2297 port_map_mask, chnl_prop, active);
2299 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2305 * Setup the DSP DMA per-transfer-specific registers
2307 static int dsp_dma_setup(struct hda_codec *codec,
2308 unsigned int chip_addx,
2310 unsigned int dma_chan)
2314 unsigned int dsp_addx;
2315 unsigned int addr_field;
2316 unsigned int incr_field;
2317 unsigned int base_cnt;
2318 unsigned int cur_cnt;
2319 unsigned int dma_cfg = 0;
2320 unsigned int adr_ofs = 0;
2321 unsigned int xfr_cnt = 0;
2322 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2323 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2325 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2327 if (count > max_dma_count) {
2328 codec_dbg(codec, "count too big\n");
2332 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2333 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2334 codec_dbg(codec, "invalid chip addr\n");
2338 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2340 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2346 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2348 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2351 dma_cfg = addr_field + incr_field;
2352 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2355 codec_dbg(codec, "write DMACFG Reg fail\n");
2358 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2360 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2363 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2366 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2369 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2371 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2373 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2375 xfr_cnt = base_cnt | cur_cnt;
2377 status = chipio_write(codec,
2378 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2380 codec_dbg(codec, "write XFRCNT Reg fail\n");
2383 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2386 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2387 "ADROFS=0x%x, XFRCNT=0x%x\n",
2388 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2390 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2398 static int dsp_dma_start(struct hda_codec *codec,
2399 unsigned int dma_chan, bool ovly)
2401 unsigned int reg = 0;
2404 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2407 status = chipio_read(codec,
2408 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2411 codec_dbg(codec, "read CHNLSTART reg fail\n");
2414 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2416 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2417 DSPDMAC_CHNLSTART_DIS_MASK);
2420 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2421 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2423 codec_dbg(codec, "write CHNLSTART reg fail\n");
2426 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2434 static int dsp_dma_stop(struct hda_codec *codec,
2435 unsigned int dma_chan, bool ovly)
2437 unsigned int reg = 0;
2440 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2443 status = chipio_read(codec,
2444 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2447 codec_dbg(codec, "read CHNLSTART reg fail\n");
2450 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2451 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2452 DSPDMAC_CHNLSTART_DIS_MASK);
2455 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2456 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2458 codec_dbg(codec, "write CHNLSTART reg fail\n");
2461 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2467 * Allocate router ports
2469 * @codec: the HDA codec
2470 * @num_chans: number of channels in the stream
2471 * @ports_per_channel: number of ports per channel
2472 * @start_device: start device
2473 * @port_map: pointer to the port list to hold the allocated ports
2475 * Returns zero or a negative error code.
2477 static int dsp_allocate_router_ports(struct hda_codec *codec,
2478 unsigned int num_chans,
2479 unsigned int ports_per_channel,
2480 unsigned int start_device,
2481 unsigned int *port_map)
2487 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2491 val = start_device << 6;
2492 val |= (ports_per_channel - 1) << 4;
2493 val |= num_chans - 1;
2495 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2496 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2499 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2500 VENDOR_CHIPIO_PORT_ALLOC_SET,
2503 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2507 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2508 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2512 return (res < 0) ? res : 0;
2518 static int dsp_free_router_ports(struct hda_codec *codec)
2522 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2526 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2527 VENDOR_CHIPIO_PORT_FREE_SET,
2530 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2536 * Allocate DSP ports for the download stream
2538 static int dsp_allocate_ports(struct hda_codec *codec,
2539 unsigned int num_chans,
2540 unsigned int rate_multi, unsigned int *port_map)
2544 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2546 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2547 codec_dbg(codec, "bad rate multiple\n");
2551 status = dsp_allocate_router_ports(codec, num_chans,
2552 rate_multi, 0, port_map);
2554 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2559 static int dsp_allocate_ports_format(struct hda_codec *codec,
2560 const unsigned short fmt,
2561 unsigned int *port_map)
2564 unsigned int num_chans;
2566 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2567 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2568 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2570 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2571 codec_dbg(codec, "bad rate multiple\n");
2575 num_chans = get_hdafmt_chs(fmt) + 1;
2577 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2585 static int dsp_free_ports(struct hda_codec *codec)
2589 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2591 status = dsp_free_router_ports(codec);
2593 codec_dbg(codec, "free router ports fail\n");
2596 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2602 * HDA DMA engine stuffs for DSP code download
2605 struct hda_codec *codec;
2606 unsigned short m_converter_format;
2607 struct snd_dma_buffer *dmab;
2608 unsigned int buf_size;
2617 static int dma_convert_to_hda_format(struct hda_codec *codec,
2618 unsigned int sample_rate,
2619 unsigned short channels,
2620 unsigned short *hda_format)
2622 unsigned int format_val;
2624 format_val = snd_hdac_calc_stream_format(sample_rate,
2625 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
2628 *hda_format = (unsigned short)format_val;
2634 * Reset DMA for DSP download
2636 static int dma_reset(struct dma_engine *dma)
2638 struct hda_codec *codec = dma->codec;
2639 struct ca0132_spec *spec = codec->spec;
2642 if (dma->dmab->area)
2643 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2645 status = snd_hda_codec_load_dsp_prepare(codec,
2646 dma->m_converter_format,
2651 spec->dsp_stream_id = status;
2655 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2660 case DMA_STATE_STOP:
2670 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2674 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2676 return dma->dmab->bytes;
2679 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2681 return dma->dmab->area;
2684 static int dma_xfer(struct dma_engine *dma,
2685 const unsigned int *data,
2688 memcpy(dma->dmab->area, data, count);
2692 static void dma_get_converter_format(
2693 struct dma_engine *dma,
2694 unsigned short *format)
2697 *format = dma->m_converter_format;
2700 static unsigned int dma_get_stream_id(struct dma_engine *dma)
2702 struct ca0132_spec *spec = dma->codec->spec;
2704 return spec->dsp_stream_id;
2707 struct dsp_image_seg {
2714 static const u32 g_magic_value = 0x4c46584d;
2715 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2717 static bool is_valid(const struct dsp_image_seg *p)
2719 return p->magic == g_magic_value;
2722 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
2724 return g_chip_addr_magic_value == p->chip_addr;
2727 static bool is_last(const struct dsp_image_seg *p)
2729 return p->count == 0;
2732 static size_t dsp_sizeof(const struct dsp_image_seg *p)
2734 return sizeof(*p) + p->count*sizeof(u32);
2737 static const struct dsp_image_seg *get_next_seg_ptr(
2738 const struct dsp_image_seg *p)
2740 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
2744 * CA0132 chip DSP transfer stuffs. For DSP download.
2746 #define INVALID_DMA_CHANNEL (~0U)
2749 * Program a list of address/data pairs via the ChipIO widget.
2750 * The segment data is in the format of successive pairs of words.
2751 * These are repeated as indicated by the segment's count field.
2753 static int dspxfr_hci_write(struct hda_codec *codec,
2754 const struct dsp_image_seg *fls)
2760 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
2761 codec_dbg(codec, "hci_write invalid params\n");
2766 data = (u32 *)(fls->data);
2767 while (count >= 2) {
2768 status = chipio_write(codec, data[0], data[1]);
2770 codec_dbg(codec, "hci_write chipio failed\n");
2780 * Write a block of data into DSP code or data RAM using pre-allocated
2783 * @codec: the HDA codec
2784 * @fls: pointer to a fast load image
2785 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2787 * @dma_engine: pointer to DMA engine to be used for DSP download
2788 * @dma_chan: The number of DMA channels used for DSP download
2789 * @port_map_mask: port mapping
2790 * @ovly: TRUE if overlay format is required
2792 * Returns zero or a negative error code.
2794 static int dspxfr_one_seg(struct hda_codec *codec,
2795 const struct dsp_image_seg *fls,
2797 struct dma_engine *dma_engine,
2798 unsigned int dma_chan,
2799 unsigned int port_map_mask,
2803 bool comm_dma_setup_done = false;
2804 const unsigned int *data;
2805 unsigned int chip_addx;
2806 unsigned int words_to_write;
2807 unsigned int buffer_size_words;
2808 unsigned char *buffer_addx;
2809 unsigned short hda_format;
2810 unsigned int sample_rate_div;
2811 unsigned int sample_rate_mul;
2812 unsigned int num_chans;
2813 unsigned int hda_frame_size_words;
2814 unsigned int remainder_words;
2815 const u32 *data_remainder;
2816 u32 chip_addx_remainder;
2817 unsigned int run_size_words;
2818 const struct dsp_image_seg *hci_write = NULL;
2819 unsigned long timeout;
2824 if (is_hci_prog_list_seg(fls)) {
2826 fls = get_next_seg_ptr(fls);
2829 if (hci_write && (!fls || is_last(fls))) {
2830 codec_dbg(codec, "hci_write\n");
2831 return dspxfr_hci_write(codec, hci_write);
2834 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2835 codec_dbg(codec, "Invalid Params\n");
2840 chip_addx = fls->chip_addr,
2841 words_to_write = fls->count;
2843 if (!words_to_write)
2844 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
2846 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
2848 if (!UC_RANGE(chip_addx, words_to_write) &&
2849 !X_RANGE_ALL(chip_addx, words_to_write) &&
2850 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2851 codec_dbg(codec, "Invalid chip_addx Params\n");
2855 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
2858 buffer_addx = dma_get_buffer_addr(dma_engine);
2860 if (buffer_addx == NULL) {
2861 codec_dbg(codec, "dma_engine buffer NULL\n");
2865 dma_get_converter_format(dma_engine, &hda_format);
2866 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
2867 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
2868 num_chans = get_hdafmt_chs(hda_format) + 1;
2870 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
2871 (num_chans * sample_rate_mul / sample_rate_div));
2873 if (hda_frame_size_words == 0) {
2874 codec_dbg(codec, "frmsz zero\n");
2878 buffer_size_words = min(buffer_size_words,
2879 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2881 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2883 "chpadr=0x%08x frmsz=%u nchan=%u "
2884 "rate_mul=%u div=%u bufsz=%u\n",
2885 chip_addx, hda_frame_size_words, num_chans,
2886 sample_rate_mul, sample_rate_div, buffer_size_words);
2888 if (buffer_size_words < hda_frame_size_words) {
2889 codec_dbg(codec, "dspxfr_one_seg:failed\n");
2893 remainder_words = words_to_write % hda_frame_size_words;
2894 data_remainder = data;
2895 chip_addx_remainder = chip_addx;
2897 data += remainder_words;
2898 chip_addx += remainder_words*sizeof(u32);
2899 words_to_write -= remainder_words;
2901 while (words_to_write != 0) {
2902 run_size_words = min(buffer_size_words, words_to_write);
2903 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2904 words_to_write, run_size_words, remainder_words);
2905 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2906 if (!comm_dma_setup_done) {
2907 status = dsp_dma_stop(codec, dma_chan, ovly);
2910 status = dsp_dma_setup_common(codec, chip_addx,
2911 dma_chan, port_map_mask, ovly);
2914 comm_dma_setup_done = true;
2917 status = dsp_dma_setup(codec, chip_addx,
2918 run_size_words, dma_chan);
2921 status = dsp_dma_start(codec, dma_chan, ovly);
2924 if (!dsp_is_dma_active(codec, dma_chan)) {
2925 codec_dbg(codec, "dspxfr:DMA did not start\n");
2928 status = dma_set_state(dma_engine, DMA_STATE_RUN);
2931 if (remainder_words != 0) {
2932 status = chipio_write_multiple(codec,
2933 chip_addx_remainder,
2938 remainder_words = 0;
2941 status = dspxfr_hci_write(codec, hci_write);
2947 timeout = jiffies + msecs_to_jiffies(2000);
2949 dma_active = dsp_is_dma_active(codec, dma_chan);
2953 } while (time_before(jiffies, timeout));
2957 codec_dbg(codec, "+++++ DMA complete\n");
2958 dma_set_state(dma_engine, DMA_STATE_STOP);
2959 status = dma_reset(dma_engine);
2964 data += run_size_words;
2965 chip_addx += run_size_words*sizeof(u32);
2966 words_to_write -= run_size_words;
2969 if (remainder_words != 0) {
2970 status = chipio_write_multiple(codec, chip_addx_remainder,
2971 data_remainder, remainder_words);
2978 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2980 * @codec: the HDA codec
2981 * @fls_data: pointer to a fast load image
2982 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2984 * @sample_rate: sampling rate of the stream used for DSP download
2985 * @channels: channels of the stream used for DSP download
2986 * @ovly: TRUE if overlay format is required
2988 * Returns zero or a negative error code.
2990 static int dspxfr_image(struct hda_codec *codec,
2991 const struct dsp_image_seg *fls_data,
2993 unsigned int sample_rate,
2994 unsigned short channels,
2997 struct ca0132_spec *spec = codec->spec;
2999 unsigned short hda_format = 0;
3000 unsigned int response;
3001 unsigned char stream_id = 0;
3002 struct dma_engine *dma_engine;
3003 unsigned int dma_chan;
3004 unsigned int port_map_mask;
3006 if (fls_data == NULL)
3009 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
3013 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
3014 if (!dma_engine->dmab) {
3019 dma_engine->codec = codec;
3020 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3021 dma_engine->m_converter_format = hda_format;
3022 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
3023 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
3025 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
3027 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3028 hda_format, &response);
3031 codec_dbg(codec, "set converter format fail\n");
3035 status = snd_hda_codec_load_dsp_prepare(codec,
3036 dma_engine->m_converter_format,
3037 dma_engine->buf_size,
3041 spec->dsp_stream_id = status;
3044 status = dspio_alloc_dma_chan(codec, &dma_chan);
3046 codec_dbg(codec, "alloc dmachan fail\n");
3047 dma_chan = INVALID_DMA_CHANNEL;
3053 status = dsp_allocate_ports_format(codec, hda_format,
3056 codec_dbg(codec, "alloc ports fail\n");
3060 stream_id = dma_get_stream_id(dma_engine);
3061 status = codec_set_converter_stream_channel(codec,
3062 WIDGET_CHIP_CTRL, stream_id, 0, &response);
3064 codec_dbg(codec, "set stream chan fail\n");
3068 while ((fls_data != NULL) && !is_last(fls_data)) {
3069 if (!is_valid(fls_data)) {
3070 codec_dbg(codec, "FLS check fail\n");
3074 status = dspxfr_one_seg(codec, fls_data, reloc,
3075 dma_engine, dma_chan,
3076 port_map_mask, ovly);
3080 if (is_hci_prog_list_seg(fls_data))
3081 fls_data = get_next_seg_ptr(fls_data);
3083 if ((fls_data != NULL) && !is_last(fls_data))
3084 fls_data = get_next_seg_ptr(fls_data);
3087 if (port_map_mask != 0)
3088 status = dsp_free_ports(codec);
3093 status = codec_set_converter_stream_channel(codec,
3094 WIDGET_CHIP_CTRL, 0, 0, &response);
3097 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
3098 dspio_free_dma_chan(codec, dma_chan);
3100 if (dma_engine->dmab->area)
3101 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3102 kfree(dma_engine->dmab);
3109 * CA0132 DSP download stuffs.
3111 static void dspload_post_setup(struct hda_codec *codec)
3113 struct ca0132_spec *spec = codec->spec;
3114 codec_dbg(codec, "---- dspload_post_setup ------\n");
3115 if (!ca0132_use_alt_functions(spec)) {
3116 /*set DSP speaker to 2.0 configuration*/
3117 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3118 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3120 /*update write pointer*/
3121 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3126 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3128 * @codec: the HDA codec
3129 * @fls: pointer to a fast load image
3130 * @ovly: TRUE if overlay format is required
3131 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3133 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3134 * @router_chans: number of audio router channels to be allocated (0 means use
3135 * internal defaults; max is 32)
3137 * Download DSP from a DSP Image Fast Load structure. This structure is a
3138 * linear, non-constant sized element array of structures, each of which
3139 * contain the count of the data to be loaded, the data itself, and the
3140 * corresponding starting chip address of the starting data location.
3141 * Returns zero or a negative error code.
3143 static int dspload_image(struct hda_codec *codec,
3144 const struct dsp_image_seg *fls,
3151 unsigned int sample_rate;
3152 unsigned short channels;
3154 codec_dbg(codec, "---- dspload_image begin ------\n");
3155 if (router_chans == 0) {
3157 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3159 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3162 sample_rate = 48000;
3163 channels = (unsigned short)router_chans;
3165 while (channels > 16) {
3171 codec_dbg(codec, "Ready to program DMA\n");
3173 status = dsp_reset(codec);
3178 codec_dbg(codec, "dsp_reset() complete\n");
3179 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3185 codec_dbg(codec, "dspxfr_image() complete\n");
3186 if (autostart && !ovly) {
3187 dspload_post_setup(codec);
3188 status = dsp_set_run_state(codec);
3191 codec_dbg(codec, "LOAD FINISHED\n");
3197 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3198 static bool dspload_is_loaded(struct hda_codec *codec)
3200 unsigned int data = 0;
3203 status = chipio_read(codec, 0x40004, &data);
3204 if ((status < 0) || (data != 1))
3210 #define dspload_is_loaded(codec) false
3213 static bool dspload_wait_loaded(struct hda_codec *codec)
3215 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3218 if (dspload_is_loaded(codec)) {
3219 codec_info(codec, "ca0132 DSP downloaded and running\n");
3223 } while (time_before(jiffies, timeout));
3225 codec_err(codec, "ca0132 failed to download DSP\n");
3230 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3231 * based cards, and has a second mmio region, region2, that's used for special
3236 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3237 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3238 * The first eight bits are just the number of the pin. So far, I've only seen
3239 * this number go to 7.
3240 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3241 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3242 * then off to send that bit.
3244 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3247 struct ca0132_spec *spec = codec->spec;
3248 unsigned short gpio_data;
3250 gpio_data = gpio_pin & 0xF;
3251 gpio_data |= ((enable << 8) & 0x100);
3253 writew(gpio_data, spec->mem_base + 0x320);
3257 * Special pci region2 commands that are only used by the AE-5. They follow
3258 * a set format, and require reads at certain points to seemingly 'clear'
3259 * the response data. My first tests didn't do these reads, and would cause
3260 * the card to get locked up until the memory was read. These commands
3261 * seem to work with three distinct values that I've taken to calling group,
3262 * target-id, and value.
3264 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3265 unsigned int target, unsigned int value)
3267 struct ca0132_spec *spec = codec->spec;
3268 unsigned int write_val;
3270 writel(0x0000007e, spec->mem_base + 0x210);
3271 readl(spec->mem_base + 0x210);
3272 writel(0x0000005a, spec->mem_base + 0x210);
3273 readl(spec->mem_base + 0x210);
3274 readl(spec->mem_base + 0x210);
3276 writel(0x00800005, spec->mem_base + 0x20c);
3277 writel(group, spec->mem_base + 0x804);
3279 writel(0x00800005, spec->mem_base + 0x20c);
3280 write_val = (target & 0xff);
3281 write_val |= (value << 8);
3284 writel(write_val, spec->mem_base + 0x204);
3286 * Need delay here or else it goes too fast and works inconsistently.
3290 readl(spec->mem_base + 0x860);
3291 readl(spec->mem_base + 0x854);
3292 readl(spec->mem_base + 0x840);
3294 writel(0x00800004, spec->mem_base + 0x20c);
3295 writel(0x00000000, spec->mem_base + 0x210);
3296 readl(spec->mem_base + 0x210);
3297 readl(spec->mem_base + 0x210);
3301 * This second type of command is used for setting the sound filter type.
3303 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3304 unsigned int group, unsigned int target, unsigned int value)
3306 struct ca0132_spec *spec = codec->spec;
3307 unsigned int write_val;
3309 writel(0x0000007e, spec->mem_base + 0x210);
3310 readl(spec->mem_base + 0x210);
3311 writel(0x0000005a, spec->mem_base + 0x210);
3312 readl(spec->mem_base + 0x210);
3313 readl(spec->mem_base + 0x210);
3315 writel(0x00800003, spec->mem_base + 0x20c);
3316 writel(group, spec->mem_base + 0x804);
3318 writel(0x00800005, spec->mem_base + 0x20c);
3319 write_val = (target & 0xff);
3320 write_val |= (value << 8);
3323 writel(write_val, spec->mem_base + 0x204);
3325 readl(spec->mem_base + 0x860);
3326 readl(spec->mem_base + 0x854);
3327 readl(spec->mem_base + 0x840);
3329 writel(0x00800004, spec->mem_base + 0x20c);
3330 writel(0x00000000, spec->mem_base + 0x210);
3331 readl(spec->mem_base + 0x210);
3332 readl(spec->mem_base + 0x210);
3336 * Setup GPIO for the other variants of Core3D.
3340 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3341 * the card shows as having no GPIO pins.
3343 static void ca0132_gpio_init(struct hda_codec *codec)
3345 struct ca0132_spec *spec = codec->spec;
3347 switch (ca0132_quirk(spec)) {
3350 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3351 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3352 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3355 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3356 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3364 /* Sets the GPIO for audio output. */
3365 static void ca0132_gpio_setup(struct hda_codec *codec)
3367 struct ca0132_spec *spec = codec->spec;
3369 switch (ca0132_quirk(spec)) {
3371 snd_hda_codec_write(codec, 0x01, 0,
3372 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3373 snd_hda_codec_write(codec, 0x01, 0,
3374 AC_VERB_SET_GPIO_MASK, 0x07);
3375 snd_hda_codec_write(codec, 0x01, 0,
3376 AC_VERB_SET_GPIO_DATA, 0x04);
3377 snd_hda_codec_write(codec, 0x01, 0,
3378 AC_VERB_SET_GPIO_DATA, 0x06);
3381 snd_hda_codec_write(codec, 0x01, 0,
3382 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3383 snd_hda_codec_write(codec, 0x01, 0,
3384 AC_VERB_SET_GPIO_MASK, 0x1F);
3385 snd_hda_codec_write(codec, 0x01, 0,
3386 AC_VERB_SET_GPIO_DATA, 0x0C);
3394 * GPIO control functions for the Recon3D integrated.
3397 enum r3di_gpio_bit {
3398 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3399 R3DI_MIC_SELECT_BIT = 1,
3400 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3401 R3DI_OUT_SELECT_BIT = 2,
3403 * I dunno what this actually does, but it stays on until the dsp
3406 R3DI_GPIO_DSP_DOWNLOADING = 3,
3408 * Same as above, no clue what it does, but it comes on after the dsp
3411 R3DI_GPIO_DSP_DOWNLOADED = 4
3414 enum r3di_mic_select {
3415 /* Set GPIO bit 1 to 0 for rear mic */
3417 /* Set GPIO bit 1 to 1 for front microphone*/
3421 enum r3di_out_select {
3422 /* Set GPIO bit 2 to 0 for headphone */
3423 R3DI_HEADPHONE_OUT = 0,
3424 /* Set GPIO bit 2 to 1 for speaker */
3427 enum r3di_dsp_status {
3428 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3429 R3DI_DSP_DOWNLOADING = 0,
3430 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3431 R3DI_DSP_DOWNLOADED = 1
3435 static void r3di_gpio_mic_set(struct hda_codec *codec,
3436 enum r3di_mic_select cur_mic)
3438 unsigned int cur_gpio;
3440 /* Get the current GPIO Data setup */
3441 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3445 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3447 case R3DI_FRONT_MIC:
3448 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3451 snd_hda_codec_write(codec, codec->core.afg, 0,
3452 AC_VERB_SET_GPIO_DATA, cur_gpio);
3455 static void r3di_gpio_out_set(struct hda_codec *codec,
3456 enum r3di_out_select cur_out)
3458 unsigned int cur_gpio;
3460 /* Get the current GPIO Data setup */
3461 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3464 case R3DI_HEADPHONE_OUT:
3465 cur_gpio &= ~(1 << R3DI_OUT_SELECT_BIT);
3468 cur_gpio |= (1 << R3DI_OUT_SELECT_BIT);
3471 snd_hda_codec_write(codec, codec->core.afg, 0,
3472 AC_VERB_SET_GPIO_DATA, cur_gpio);
3475 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3476 enum r3di_dsp_status dsp_status)
3478 unsigned int cur_gpio;
3480 /* Get the current GPIO Data setup */
3481 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3483 switch (dsp_status) {
3484 case R3DI_DSP_DOWNLOADING:
3485 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3486 snd_hda_codec_write(codec, codec->core.afg, 0,
3487 AC_VERB_SET_GPIO_DATA, cur_gpio);
3489 case R3DI_DSP_DOWNLOADED:
3490 /* Set DOWNLOADING bit to 0. */
3491 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3493 snd_hda_codec_write(codec, codec->core.afg, 0,
3494 AC_VERB_SET_GPIO_DATA, cur_gpio);
3496 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3500 snd_hda_codec_write(codec, codec->core.afg, 0,
3501 AC_VERB_SET_GPIO_DATA, cur_gpio);
3507 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3508 struct hda_codec *codec,
3509 unsigned int stream_tag,
3510 unsigned int format,
3511 struct snd_pcm_substream *substream)
3513 struct ca0132_spec *spec = codec->spec;
3515 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3520 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3521 struct hda_codec *codec,
3522 struct snd_pcm_substream *substream)
3524 struct ca0132_spec *spec = codec->spec;
3526 if (spec->dsp_state == DSP_DOWNLOADING)
3529 /*If Playback effects are on, allow stream some time to flush
3531 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3534 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3539 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3540 struct hda_codec *codec,
3541 struct snd_pcm_substream *substream)
3543 struct ca0132_spec *spec = codec->spec;
3544 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3545 struct snd_pcm_runtime *runtime = substream->runtime;
3547 if (spec->dsp_state != DSP_DOWNLOADED)
3550 /* Add latency if playback enhancement and either effect is enabled. */
3551 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3552 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3553 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3554 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3557 /* Applying Speaker EQ adds latency as well. */
3558 if (spec->cur_out_type == SPEAKER_OUT)
3559 latency += DSP_SPEAKER_OUT_LATENCY;
3561 return (latency * runtime->rate) / 1000;
3567 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3568 struct hda_codec *codec,
3569 struct snd_pcm_substream *substream)
3571 struct ca0132_spec *spec = codec->spec;
3572 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3575 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3576 struct hda_codec *codec,
3577 unsigned int stream_tag,
3578 unsigned int format,
3579 struct snd_pcm_substream *substream)
3581 struct ca0132_spec *spec = codec->spec;
3582 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3583 stream_tag, format, substream);
3586 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3587 struct hda_codec *codec,
3588 struct snd_pcm_substream *substream)
3590 struct ca0132_spec *spec = codec->spec;
3591 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3594 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3595 struct hda_codec *codec,
3596 struct snd_pcm_substream *substream)
3598 struct ca0132_spec *spec = codec->spec;
3599 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3605 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3606 struct hda_codec *codec,
3607 unsigned int stream_tag,
3608 unsigned int format,
3609 struct snd_pcm_substream *substream)
3611 snd_hda_codec_setup_stream(codec, hinfo->nid,
3612 stream_tag, 0, format);
3617 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3618 struct hda_codec *codec,
3619 struct snd_pcm_substream *substream)
3621 struct ca0132_spec *spec = codec->spec;
3623 if (spec->dsp_state == DSP_DOWNLOADING)
3626 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3630 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
3631 struct hda_codec *codec,
3632 struct snd_pcm_substream *substream)
3634 struct ca0132_spec *spec = codec->spec;
3635 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
3636 struct snd_pcm_runtime *runtime = substream->runtime;
3638 if (spec->dsp_state != DSP_DOWNLOADED)
3641 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3642 latency += DSP_CRYSTAL_VOICE_LATENCY;
3644 return (latency * runtime->rate) / 1000;
3652 * Mixer controls helpers.
3654 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
3655 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3657 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3658 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3659 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3660 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3661 .info = ca0132_volume_info, \
3662 .get = ca0132_volume_get, \
3663 .put = ca0132_volume_put, \
3664 .tlv = { .c = ca0132_volume_tlv }, \
3665 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3668 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
3669 * volume put, which is used for setting the DSP volume. This was done because
3670 * the ca0132 functions were taking too much time and causing lag.
3672 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
3673 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3675 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3676 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3677 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3678 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3679 .info = snd_hda_mixer_amp_volume_info, \
3680 .get = snd_hda_mixer_amp_volume_get, \
3681 .put = ca0132_alt_volume_put, \
3682 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
3683 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3685 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
3686 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3688 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3689 .info = snd_hda_mixer_amp_switch_info, \
3690 .get = ca0132_switch_get, \
3691 .put = ca0132_switch_put, \
3692 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3695 #define CA0132_CODEC_VOL(xname, nid, dir) \
3696 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
3697 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
3698 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
3699 #define CA0132_CODEC_MUTE(xname, nid, dir) \
3700 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
3704 * Lookup table with decibel values for the DSP. When volume is changed in
3705 * Windows, the DSP is also sent the dB value in floating point. In Windows,
3706 * these values have decimal points, probably because the Windows driver
3707 * actually uses floating point. We can't here, so I made a lookup table of
3708 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
3709 * DAC's, and 9 is the maximum.
3711 static const unsigned int float_vol_db_lookup[] = {
3712 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
3713 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
3714 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
3715 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
3716 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
3717 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
3718 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
3719 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
3720 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
3721 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
3722 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
3723 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3724 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3725 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3726 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3727 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3728 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
3732 * This table counts from float 0 to 1 in increments of .01, which is
3733 * useful for a few different sliders.
3735 static const unsigned int float_zero_to_one_lookup[] = {
3736 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3737 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3738 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3739 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3740 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3741 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3742 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3743 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3744 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3745 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3746 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3747 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3748 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3749 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3750 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3751 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3752 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3756 * This table counts from float 10 to 1000, which is the range of the x-bass
3757 * crossover slider in Windows.
3759 static const unsigned int float_xbass_xover_lookup[] = {
3760 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
3761 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
3762 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
3763 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
3764 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
3765 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
3766 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
3767 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
3768 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
3769 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
3770 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
3771 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
3772 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
3773 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
3774 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
3775 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
3776 0x44728000, 0x44750000, 0x44778000, 0x447A0000
3779 /* The following are for tuning of products */
3780 #ifdef ENABLE_TUNING_CONTROLS
3782 static unsigned int voice_focus_vals_lookup[] = {
3783 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
3784 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
3785 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
3786 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
3787 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
3788 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
3789 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
3790 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
3791 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
3792 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
3793 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
3794 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
3795 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
3796 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
3797 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
3798 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
3799 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
3800 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
3801 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
3802 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
3803 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
3804 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
3805 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
3806 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
3807 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
3808 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
3809 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
3812 static unsigned int mic_svm_vals_lookup[] = {
3813 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3814 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3815 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3816 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3817 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3818 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3819 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3820 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3821 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3822 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3823 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3824 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3825 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3826 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3827 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3828 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3829 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3832 static unsigned int equalizer_vals_lookup[] = {
3833 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3834 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3835 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3836 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3837 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3838 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
3839 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
3840 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
3844 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
3845 unsigned int *lookup, int idx)
3849 for (i = 0; i < TUNING_CTLS_COUNT; i++)
3850 if (nid == ca0132_tuning_ctls[i].nid)
3853 snd_hda_power_up(codec);
3854 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
3855 ca0132_tuning_ctls[i].req,
3856 &(lookup[idx]), sizeof(unsigned int));
3857 snd_hda_power_down(codec);
3862 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
3863 struct snd_ctl_elem_value *ucontrol)
3865 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3866 struct ca0132_spec *spec = codec->spec;
3867 hda_nid_t nid = get_amp_nid(kcontrol);
3868 long *valp = ucontrol->value.integer.value;
3869 int idx = nid - TUNING_CTL_START_NID;
3871 *valp = spec->cur_ctl_vals[idx];
3875 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
3876 struct snd_ctl_elem_info *uinfo)
3878 int chs = get_amp_channels(kcontrol);
3879 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3880 uinfo->count = chs == 3 ? 2 : 1;
3881 uinfo->value.integer.min = 20;
3882 uinfo->value.integer.max = 180;
3883 uinfo->value.integer.step = 1;
3888 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
3889 struct snd_ctl_elem_value *ucontrol)
3891 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3892 struct ca0132_spec *spec = codec->spec;
3893 hda_nid_t nid = get_amp_nid(kcontrol);
3894 long *valp = ucontrol->value.integer.value;
3897 idx = nid - TUNING_CTL_START_NID;
3899 if (spec->cur_ctl_vals[idx] == *valp)
3902 spec->cur_ctl_vals[idx] = *valp;
3905 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
3910 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
3911 struct snd_ctl_elem_info *uinfo)
3913 int chs = get_amp_channels(kcontrol);
3914 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3915 uinfo->count = chs == 3 ? 2 : 1;
3916 uinfo->value.integer.min = 0;
3917 uinfo->value.integer.max = 100;
3918 uinfo->value.integer.step = 1;
3923 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
3924 struct snd_ctl_elem_value *ucontrol)
3926 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3927 struct ca0132_spec *spec = codec->spec;
3928 hda_nid_t nid = get_amp_nid(kcontrol);
3929 long *valp = ucontrol->value.integer.value;
3932 idx = nid - TUNING_CTL_START_NID;
3934 if (spec->cur_ctl_vals[idx] == *valp)
3937 spec->cur_ctl_vals[idx] = *valp;
3940 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
3945 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
3946 struct snd_ctl_elem_info *uinfo)
3948 int chs = get_amp_channels(kcontrol);
3949 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3950 uinfo->count = chs == 3 ? 2 : 1;
3951 uinfo->value.integer.min = 0;
3952 uinfo->value.integer.max = 48;
3953 uinfo->value.integer.step = 1;
3958 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
3959 struct snd_ctl_elem_value *ucontrol)
3961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3962 struct ca0132_spec *spec = codec->spec;
3963 hda_nid_t nid = get_amp_nid(kcontrol);
3964 long *valp = ucontrol->value.integer.value;
3967 idx = nid - TUNING_CTL_START_NID;
3969 if (spec->cur_ctl_vals[idx] == *valp)
3972 spec->cur_ctl_vals[idx] = *valp;
3975 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
3980 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
3981 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
3983 static int add_tuning_control(struct hda_codec *codec,
3984 hda_nid_t pnid, hda_nid_t nid,
3985 const char *name, int dir)
3987 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3988 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3989 struct snd_kcontrol_new knew =
3990 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
3992 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3993 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3998 knew.info = voice_focus_ctl_info;
3999 knew.get = tuning_ctl_get;
4000 knew.put = voice_focus_ctl_put;
4001 knew.tlv.p = voice_focus_db_scale;
4004 knew.info = mic_svm_ctl_info;
4005 knew.get = tuning_ctl_get;
4006 knew.put = mic_svm_ctl_put;
4009 knew.info = equalizer_ctl_info;
4010 knew.get = tuning_ctl_get;
4011 knew.put = equalizer_ctl_put;
4012 knew.tlv.p = eq_db_scale;
4017 knew.private_value =
4018 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
4019 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
4020 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
4023 static int add_tuning_ctls(struct hda_codec *codec)
4028 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
4029 err = add_tuning_control(codec,
4030 ca0132_tuning_ctls[i].parent_nid,
4031 ca0132_tuning_ctls[i].nid,
4032 ca0132_tuning_ctls[i].name,
4033 ca0132_tuning_ctls[i].direct);
4041 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
4043 struct ca0132_spec *spec = codec->spec;
4046 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
4047 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
4048 /* SVM level defaults to 0.74. */
4049 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
4051 /* EQ defaults to 0dB. */
4052 for (i = 2; i < TUNING_CTLS_COUNT; i++)
4053 spec->cur_ctl_vals[i] = 24;
4055 #endif /*ENABLE_TUNING_CONTROLS*/
4058 * Select the active output.
4059 * If autodetect is enabled, output will be selected based on jack detection.
4060 * If jack inserted, headphone will be selected, else built-in speakers
4061 * If autodetect is disabled, output will be selected based on selection.
4063 static int ca0132_select_out(struct hda_codec *codec)
4065 struct ca0132_spec *spec = codec->spec;
4066 unsigned int pin_ctl;
4072 codec_dbg(codec, "ca0132_select_out\n");
4074 snd_hda_power_up_pm(codec);
4076 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4079 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
4082 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
4085 spec->cur_out_type = HEADPHONE_OUT;
4087 spec->cur_out_type = SPEAKER_OUT;
4089 if (spec->cur_out_type == SPEAKER_OUT) {
4090 codec_dbg(codec, "ca0132_select_out speaker\n");
4091 /*speaker out config*/
4093 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4096 /*enable speaker EQ*/
4098 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4103 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4104 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4105 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4106 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4107 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4108 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4109 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4110 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4112 /* disable headphone node */
4113 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4114 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4115 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4117 /* enable speaker node */
4118 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4119 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4120 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4123 codec_dbg(codec, "ca0132_select_out hp\n");
4124 /*headphone out config*/
4126 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4129 /*disable speaker EQ*/
4131 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4136 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4137 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
4138 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4139 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4140 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4141 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
4142 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4143 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
4145 /* disable speaker*/
4146 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4147 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4148 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4150 /* enable headphone*/
4151 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4152 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4153 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4158 snd_hda_power_down_pm(codec);
4160 return err < 0 ? err : 0;
4163 static int ae5_headphone_gain_set(struct hda_codec *codec, long val);
4164 static int zxr_headphone_gain_set(struct hda_codec *codec, long val);
4165 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4167 static void ae5_mmio_select_out(struct hda_codec *codec)
4169 struct ca0132_spec *spec = codec->spec;
4172 for (i = 0; i < AE5_CA0113_OUT_SET_COMMANDS; i++)
4173 ca0113_mmio_command_set(codec,
4174 ae5_ca0113_output_presets[spec->cur_out_type].group[i],
4175 ae5_ca0113_output_presets[spec->cur_out_type].target[i],
4176 ae5_ca0113_output_presets[spec->cur_out_type].vals[i]);
4180 * These are the commands needed to setup output on each of the different card
4183 static void ca0132_alt_select_out_quirk_handler(struct hda_codec *codec)
4185 struct ca0132_spec *spec = codec->spec;
4188 switch (spec->cur_out_type) {
4190 switch (ca0132_quirk(spec)) {
4192 ca0113_mmio_gpio_set(codec, 7, false);
4193 ca0113_mmio_gpio_set(codec, 4, true);
4194 ca0113_mmio_gpio_set(codec, 1, true);
4195 chipio_set_control_param(codec, 0x0d, 0x18);
4198 ca0113_mmio_gpio_set(codec, 2, true);
4199 ca0113_mmio_gpio_set(codec, 3, true);
4200 ca0113_mmio_gpio_set(codec, 5, false);
4201 zxr_headphone_gain_set(codec, 0);
4202 chipio_set_control_param(codec, 0x0d, 0x24);
4205 chipio_set_control_param(codec, 0x0d, 0x24);
4206 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
4209 chipio_set_control_param(codec, 0x0d, 0x24);
4210 ca0113_mmio_gpio_set(codec, 1, true);
4213 ae5_mmio_select_out(codec);
4214 ae5_headphone_gain_set(codec, 2);
4216 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4217 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4218 chipio_set_control_param(codec, 0x0d, 0xa4);
4219 chipio_write(codec, 0x18b03c, 0x00000012);
4226 switch (ca0132_quirk(spec)) {
4228 ca0113_mmio_gpio_set(codec, 7, true);
4229 ca0113_mmio_gpio_set(codec, 4, true);
4230 ca0113_mmio_gpio_set(codec, 1, false);
4231 chipio_set_control_param(codec, 0x0d, 0x12);
4234 ca0113_mmio_gpio_set(codec, 2, false);
4235 ca0113_mmio_gpio_set(codec, 3, false);
4236 ca0113_mmio_gpio_set(codec, 5, true);
4237 zxr_headphone_gain_set(codec, spec->zxr_gain_set);
4238 chipio_set_control_param(codec, 0x0d, 0x21);
4241 chipio_set_control_param(codec, 0x0d, 0x21);
4242 r3di_gpio_out_set(codec, R3DI_HEADPHONE_OUT);
4245 chipio_set_control_param(codec, 0x0d, 0x21);
4246 ca0113_mmio_gpio_set(codec, 0x1, false);
4249 ae5_mmio_select_out(codec);
4250 ae5_headphone_gain_set(codec,
4251 spec->ae5_headphone_gain_val);
4253 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4254 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4255 chipio_set_control_param(codec, 0x0d, 0xa1);
4256 chipio_write(codec, 0x18b03c, 0x00000012);
4263 switch (ca0132_quirk(spec)) {
4265 ca0113_mmio_gpio_set(codec, 7, false);
4266 ca0113_mmio_gpio_set(codec, 4, true);
4267 ca0113_mmio_gpio_set(codec, 1, true);
4268 chipio_set_control_param(codec, 0x0d, 0x18);
4271 ca0113_mmio_gpio_set(codec, 2, true);
4272 ca0113_mmio_gpio_set(codec, 3, true);
4273 ca0113_mmio_gpio_set(codec, 5, false);
4274 zxr_headphone_gain_set(codec, 0);
4275 chipio_set_control_param(codec, 0x0d, 0x24);
4278 chipio_set_control_param(codec, 0x0d, 0x24);
4279 r3di_gpio_out_set(codec, R3DI_LINE_OUT);
4282 ca0113_mmio_gpio_set(codec, 1, true);
4283 chipio_set_control_param(codec, 0x0d, 0x24);
4286 ae5_mmio_select_out(codec);
4287 ae5_headphone_gain_set(codec, 2);
4289 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
4290 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
4291 chipio_set_control_param(codec, 0x0d, 0xa4);
4292 chipio_write(codec, 0x18b03c, 0x00000012);
4302 * This function behaves similarly to the ca0132_select_out funciton above,
4303 * except with a few differences. It adds the ability to select the current
4304 * output with an enumerated control "output source" if the auto detect
4305 * mute switch is set to off. If the auto detect mute switch is enabled, it
4306 * will detect either headphone or lineout(SPEAKER_OUT) from jack detection.
4307 * It also adds the ability to auto-detect the front headphone port. The only
4308 * way to select surround is to disable auto detect, and set Surround with the
4309 * enumerated control.
4311 static int ca0132_alt_select_out(struct hda_codec *codec)
4313 struct ca0132_spec *spec = codec->spec;
4314 unsigned int pin_ctl;
4320 /* Default Headphone is rear headphone */
4321 hda_nid_t headphone_nid = spec->out_pins[1];
4323 codec_dbg(codec, "%s\n", __func__);
4325 snd_hda_power_up_pm(codec);
4327 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
4330 * If headphone rear or front is plugged in, set to headphone.
4331 * If neither is plugged in, set to rear line out. Only if
4332 * hp/speaker auto detect is enabled.
4335 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
4336 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
4339 spec->cur_out_type = HEADPHONE_OUT;
4341 spec->cur_out_type = SPEAKER_OUT;
4343 spec->cur_out_type = spec->out_enum_val;
4345 /* Begin DSP output switch */
4347 err = dspio_set_uint_param(codec, 0x96, 0x3A, tmp);
4351 ca0132_alt_select_out_quirk_handler(codec);
4353 switch (spec->cur_out_type) {
4355 codec_dbg(codec, "%s speaker\n", __func__);
4357 /* disable headphone node */
4358 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4359 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4360 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4362 /* enable line-out node */
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 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4369 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4371 /* If PlayEnhancement is enabled, set different source */
4372 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4373 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4375 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4378 codec_dbg(codec, "%s hp\n", __func__);
4380 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4381 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
4383 /* disable speaker*/
4384 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4385 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4386 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4389 /* enable headphone, either front or rear */
4391 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4392 headphone_nid = spec->out_pins[2];
4393 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4394 headphone_nid = spec->out_pins[1];
4396 pin_ctl = snd_hda_codec_read(codec, headphone_nid, 0,
4397 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4398 snd_hda_set_pin_ctl(codec, headphone_nid,
4401 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4402 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4404 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4407 codec_dbg(codec, "%s surround\n", __func__);
4409 /* enable line out node */
4410 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4411 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4412 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4414 /* Disable headphone out */
4415 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4416 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4417 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4419 /* Enable EAPD on line out */
4420 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4421 AC_VERB_SET_EAPD_BTLENABLE, 0x01);
4422 /* enable center/lfe out node */
4423 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[2], 0,
4424 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4425 snd_hda_set_pin_ctl(codec, spec->out_pins[2],
4427 /* Now set rear surround node as out. */
4428 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[3], 0,
4429 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4430 snd_hda_set_pin_ctl(codec, spec->out_pins[3],
4433 dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_EIGHT);
4437 * Surround always sets it's scp command to req 0x04 to FLOAT_EIGHT.
4438 * With this set though, X_BASS cannot be enabled. So, if we have OutFX
4439 * enabled, we need to make sure X_BASS is off, otherwise everything
4440 * sounds all muffled. Running ca0132_effects_set with X_BASS as the
4441 * effect should sort this out.
4443 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4444 ca0132_effects_set(codec, X_BASS,
4445 spec->effects_switch[X_BASS - EFFECT_START_NID]);
4447 /* run through the output dsp commands for the selected output. */
4448 for (i = 0; i < alt_out_presets[spec->cur_out_type].commands; i++) {
4449 err = dspio_set_uint_param(codec,
4450 alt_out_presets[spec->cur_out_type].mids[i],
4451 alt_out_presets[spec->cur_out_type].reqs[i],
4452 alt_out_presets[spec->cur_out_type].vals[i]);
4459 snd_hda_power_down_pm(codec);
4461 return err < 0 ? err : 0;
4464 static void ca0132_unsol_hp_delayed(struct work_struct *work)
4466 struct ca0132_spec *spec = container_of(
4467 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
4468 struct hda_jack_tbl *jack;
4470 if (ca0132_use_alt_functions(spec))
4471 ca0132_alt_select_out(spec->codec);
4473 ca0132_select_out(spec->codec);
4475 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4477 jack->block_report = 0;
4478 snd_hda_jack_report_sync(spec->codec);
4482 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4483 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4484 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4485 static int stop_mic1(struct hda_codec *codec);
4486 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4487 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4490 * Select the active VIP source
4492 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4494 struct ca0132_spec *spec = codec->spec;
4497 if (spec->dsp_state != DSP_DOWNLOADED)
4500 /* if CrystalVoice if off, vipsource should be 0 */
4501 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4503 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4504 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4505 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4506 if (spec->cur_mic_type == DIGITAL_MIC)
4510 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4512 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4514 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4515 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4516 if (spec->cur_mic_type == DIGITAL_MIC)
4520 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4522 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4524 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4530 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4532 struct ca0132_spec *spec = codec->spec;
4535 if (spec->dsp_state != DSP_DOWNLOADED)
4538 codec_dbg(codec, "%s\n", __func__);
4540 chipio_set_stream_control(codec, 0x03, 0);
4541 chipio_set_stream_control(codec, 0x04, 0);
4543 /* if CrystalVoice is off, vipsource should be 0 */
4544 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
4545 (val == 0) || spec->in_enum_val == REAR_LINE_IN) {
4546 codec_dbg(codec, "%s: off.", __func__);
4547 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4550 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4552 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4553 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4554 if (ca0132_quirk(spec) == QUIRK_R3DI)
4555 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4558 if (spec->in_enum_val == REAR_LINE_IN)
4561 if (ca0132_quirk(spec) == QUIRK_SBZ)
4567 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4570 codec_dbg(codec, "%s: on.", __func__);
4571 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4572 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4573 if (ca0132_quirk(spec) == QUIRK_R3DI)
4574 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
4576 if (spec->effects_switch[VOICE_FOCUS - EFFECT_START_NID])
4580 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4583 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4586 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4589 chipio_set_stream_control(codec, 0x03, 1);
4590 chipio_set_stream_control(codec, 0x04, 1);
4596 * Select the active microphone.
4597 * If autodetect is enabled, mic will be selected based on jack detection.
4598 * If jack inserted, ext.mic will be selected, else built-in mic
4599 * If autodetect is disabled, mic will be selected based on selection.
4601 static int ca0132_select_mic(struct hda_codec *codec)
4603 struct ca0132_spec *spec = codec->spec;
4607 codec_dbg(codec, "ca0132_select_mic\n");
4609 snd_hda_power_up_pm(codec);
4611 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
4614 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
4617 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
4620 spec->cur_mic_type = LINE_MIC_IN;
4622 spec->cur_mic_type = DIGITAL_MIC;
4624 if (spec->cur_mic_type == DIGITAL_MIC) {
4625 /* enable digital Mic */
4626 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
4627 ca0132_set_dmic(codec, 1);
4628 ca0132_mic_boost_set(codec, 0);
4629 /* set voice focus */
4630 ca0132_effects_set(codec, VOICE_FOCUS,
4631 spec->effects_switch
4632 [VOICE_FOCUS - EFFECT_START_NID]);
4634 /* disable digital Mic */
4635 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
4636 ca0132_set_dmic(codec, 0);
4637 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
4638 /* disable voice focus */
4639 ca0132_effects_set(codec, VOICE_FOCUS, 0);
4642 snd_hda_power_down_pm(codec);
4648 * Select the active input.
4649 * Mic detection isn't used, because it's kind of pointless on the SBZ.
4650 * The front mic has no jack-detection, so the only way to switch to it
4651 * is to do it manually in alsamixer.
4653 static int ca0132_alt_select_in(struct hda_codec *codec)
4655 struct ca0132_spec *spec = codec->spec;
4658 codec_dbg(codec, "%s\n", __func__);
4660 snd_hda_power_up_pm(codec);
4662 chipio_set_stream_control(codec, 0x03, 0);
4663 chipio_set_stream_control(codec, 0x04, 0);
4665 spec->cur_mic_type = spec->in_enum_val;
4667 switch (spec->cur_mic_type) {
4669 switch (ca0132_quirk(spec)) {
4672 ca0113_mmio_gpio_set(codec, 0, false);
4679 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4683 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x00);
4691 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4692 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4693 if (ca0132_quirk(spec) == QUIRK_R3DI)
4694 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4696 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4698 chipio_set_stream_control(codec, 0x03, 1);
4699 chipio_set_stream_control(codec, 0x04, 1);
4700 switch (ca0132_quirk(spec)) {
4702 chipio_write(codec, 0x18B098, 0x0000000C);
4703 chipio_write(codec, 0x18B09C, 0x0000000C);
4706 chipio_write(codec, 0x18B098, 0x0000000C);
4707 chipio_write(codec, 0x18B09C, 0x000000CC);
4710 chipio_write(codec, 0x18B098, 0x0000000C);
4711 chipio_write(codec, 0x18B09C, 0x0000004C);
4716 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4719 ca0132_mic_boost_set(codec, 0);
4720 switch (ca0132_quirk(spec)) {
4723 ca0113_mmio_gpio_set(codec, 0, false);
4726 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
4729 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x00);
4735 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4736 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4737 if (ca0132_quirk(spec) == QUIRK_R3DI)
4738 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4741 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4743 switch (ca0132_quirk(spec)) {
4746 chipio_write(codec, 0x18B098, 0x00000000);
4747 chipio_write(codec, 0x18B09C, 0x00000000);
4752 chipio_set_stream_control(codec, 0x03, 1);
4753 chipio_set_stream_control(codec, 0x04, 1);
4756 switch (ca0132_quirk(spec)) {
4759 ca0113_mmio_gpio_set(codec, 0, true);
4760 ca0113_mmio_gpio_set(codec, 5, false);
4764 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
4768 ca0113_mmio_command_set(codec, 0x48, 0x28, 0x3f);
4776 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4777 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4778 if (ca0132_quirk(spec) == QUIRK_R3DI)
4779 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4781 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4783 chipio_set_stream_control(codec, 0x03, 1);
4784 chipio_set_stream_control(codec, 0x04, 1);
4786 switch (ca0132_quirk(spec)) {
4788 chipio_write(codec, 0x18B098, 0x0000000C);
4789 chipio_write(codec, 0x18B09C, 0x000000CC);
4792 chipio_write(codec, 0x18B098, 0x0000000C);
4793 chipio_write(codec, 0x18B09C, 0x0000004C);
4798 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
4801 ca0132_cvoice_switch_set(codec);
4803 snd_hda_power_down_pm(codec);
4808 * Check if VNODE settings take effect immediately.
4810 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
4812 hda_nid_t *shared_nid)
4814 struct ca0132_spec *spec = codec->spec;
4819 nid = spec->shared_out_nid;
4822 nid = spec->shared_mic_nid;
4835 * The following functions are control change helpers.
4836 * They return 0 if no changed. Return 1 if changed.
4838 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
4840 struct ca0132_spec *spec = codec->spec;
4843 /* based on CrystalVoice state to enable VoiceFX. */
4845 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
4846 FLOAT_ONE : FLOAT_ZERO;
4851 dspio_set_uint_param(codec, ca0132_voicefx.mid,
4852 ca0132_voicefx.reqs[0], tmp);
4858 * Set the effects parameters
4860 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
4862 struct ca0132_spec *spec = codec->spec;
4863 unsigned int on, tmp;
4864 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
4866 int idx = nid - EFFECT_START_NID;
4868 if ((idx < 0) || (idx >= num_fx))
4869 return 0; /* no changed */
4871 /* for out effect, qualify with PE */
4872 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
4873 /* if PE if off, turn off out effects. */
4874 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
4876 if (spec->cur_out_type == SURROUND_OUT && nid == X_BASS)
4880 /* for in effect, qualify with CrystalVoice */
4881 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
4882 /* if CrystalVoice if off, turn off in effects. */
4883 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
4886 /* Voice Focus applies to 2-ch Mic, Digital Mic */
4887 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
4890 /* If Voice Focus on SBZ, set to two channel. */
4891 if ((nid == VOICE_FOCUS) && ca0132_use_pci_mmio(spec)
4892 && (spec->cur_mic_type != REAR_LINE_IN)) {
4893 if (spec->effects_switch[CRYSTAL_VOICE -
4894 EFFECT_START_NID]) {
4896 if (spec->effects_switch[VOICE_FOCUS -
4897 EFFECT_START_NID]) {
4903 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4907 * For SBZ noise reduction, there's an extra command
4908 * to module ID 0x47. No clue why.
4910 if ((nid == NOISE_REDUCTION) && ca0132_use_pci_mmio(spec)
4911 && (spec->cur_mic_type != REAR_LINE_IN)) {
4912 if (spec->effects_switch[CRYSTAL_VOICE -
4913 EFFECT_START_NID]) {
4914 if (spec->effects_switch[NOISE_REDUCTION -
4922 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
4925 /* If rear line in disable effects. */
4926 if (ca0132_use_alt_functions(spec) &&
4927 spec->in_enum_val == REAR_LINE_IN)
4931 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
4934 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
4935 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
4936 ca0132_effects[idx].reqs[0], on);
4939 return 0; /* no changed */
4945 * Turn on/off Playback Enhancements
4947 static int ca0132_pe_switch_set(struct hda_codec *codec)
4949 struct ca0132_spec *spec = codec->spec;
4953 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
4954 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
4956 if (ca0132_use_alt_functions(spec))
4957 ca0132_alt_select_out(codec);
4959 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
4960 nid = OUT_EFFECT_START_NID;
4961 /* PE affects all out effects */
4962 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
4963 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
4968 /* Check if Mic1 is streaming, if so, stop streaming */
4969 static int stop_mic1(struct hda_codec *codec)
4971 struct ca0132_spec *spec = codec->spec;
4972 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
4973 AC_VERB_GET_CONV, 0);
4975 snd_hda_codec_write(codec, spec->adcs[0], 0,
4976 AC_VERB_SET_CHANNEL_STREAMID,
4981 /* Resume Mic1 streaming if it was stopped. */
4982 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
4984 struct ca0132_spec *spec = codec->spec;
4985 /* Restore the previous stream and channel */
4987 snd_hda_codec_write(codec, spec->adcs[0], 0,
4988 AC_VERB_SET_CHANNEL_STREAMID,
4993 * Turn on/off CrystalVoice
4995 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
4997 struct ca0132_spec *spec = codec->spec;
5000 unsigned int oldval;
5002 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
5003 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
5005 i = IN_EFFECT_START_NID - EFFECT_START_NID;
5006 nid = IN_EFFECT_START_NID;
5007 /* CrystalVoice affects all in effects */
5008 for (; nid < IN_EFFECT_END_NID; nid++, i++)
5009 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5011 /* including VoiceFX */
5012 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
5014 /* set correct vipsource */
5015 oldval = stop_mic1(codec);
5016 if (ca0132_use_alt_functions(spec))
5017 ret |= ca0132_alt_set_vipsource(codec, 1);
5019 ret |= ca0132_set_vipsource(codec, 1);
5020 resume_mic1(codec, oldval);
5024 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
5026 struct ca0132_spec *spec = codec->spec;
5030 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5031 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
5033 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5034 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
5039 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
5041 struct ca0132_spec *spec = codec->spec;
5044 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5045 HDA_INPUT, 0, HDA_AMP_VOLMASK, val);
5049 static int ae5_headphone_gain_set(struct hda_codec *codec, long val)
5053 for (i = 0; i < 4; i++)
5054 ca0113_mmio_command_set(codec, 0x48, 0x11 + i,
5055 ae5_headphone_gain_presets[val].vals[i]);
5060 * gpio pin 1 is a relay that switches on/off, apparently setting the headphone
5061 * amplifier to handle a 600 ohm load.
5063 static int zxr_headphone_gain_set(struct hda_codec *codec, long val)
5065 ca0113_mmio_gpio_set(codec, 1, val);
5070 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
5071 struct snd_ctl_elem_value *ucontrol)
5073 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5074 hda_nid_t nid = get_amp_nid(kcontrol);
5075 hda_nid_t shared_nid = 0;
5078 struct ca0132_spec *spec = codec->spec;
5081 if (nid == VNID_HP_SEL) {
5083 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5085 if (ca0132_use_alt_functions(spec))
5086 ca0132_alt_select_out(codec);
5088 ca0132_select_out(codec);
5093 if (nid == VNID_AMIC1_SEL) {
5095 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
5097 ca0132_select_mic(codec);
5101 if (nid == VNID_HP_ASEL) {
5102 if (ca0132_use_alt_functions(spec))
5103 ca0132_alt_select_out(codec);
5105 ca0132_select_out(codec);
5109 if (nid == VNID_AMIC1_ASEL) {
5110 ca0132_select_mic(codec);
5114 /* if effective conditions, then update hw immediately. */
5115 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5117 int dir = get_amp_direction(kcontrol);
5118 int ch = get_amp_channels(kcontrol);
5121 mutex_lock(&codec->control_mutex);
5122 pval = kcontrol->private_value;
5123 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5125 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
5126 kcontrol->private_value = pval;
5127 mutex_unlock(&codec->control_mutex);
5132 /* End of control change helpers. */
5134 * Below I've added controls to mess with the effect levels, I've only enabled
5135 * them on the Sound Blaster Z, but they would probably also work on the
5136 * Chromebook. I figured they were probably tuned specifically for it, and left
5140 /* Sets DSP effect level from the sliders above the controls */
5141 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
5142 const unsigned int *lookup, int idx)
5147 * For X_BASS, req 2 is actually crossover freq instead of
5155 snd_hda_power_up(codec);
5156 if (nid == XBASS_XOVER) {
5157 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5158 if (ca0132_effects[i].nid == X_BASS)
5161 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5162 ca0132_effects[i].reqs[1],
5163 &(lookup[idx - 1]), sizeof(unsigned int));
5165 /* Find the actual effect structure */
5166 for (i = 0; i < OUT_EFFECTS_COUNT; i++)
5167 if (nid == ca0132_effects[i].nid)
5170 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5171 ca0132_effects[i].reqs[y],
5172 &(lookup[idx]), sizeof(unsigned int));
5175 snd_hda_power_down(codec);
5180 static int ca0132_alt_xbass_xover_slider_ctl_get(struct snd_kcontrol *kcontrol,
5181 struct snd_ctl_elem_value *ucontrol)
5183 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5184 struct ca0132_spec *spec = codec->spec;
5185 long *valp = ucontrol->value.integer.value;
5187 *valp = spec->xbass_xover_freq;
5191 static int ca0132_alt_slider_ctl_get(struct snd_kcontrol *kcontrol,
5192 struct snd_ctl_elem_value *ucontrol)
5194 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5195 struct ca0132_spec *spec = codec->spec;
5196 hda_nid_t nid = get_amp_nid(kcontrol);
5197 long *valp = ucontrol->value.integer.value;
5198 int idx = nid - OUT_EFFECT_START_NID;
5200 *valp = spec->fx_ctl_val[idx];
5205 * The X-bass crossover starts at 10hz, so the min is 1. The
5206 * frequency is set in multiples of 10.
5208 static int ca0132_alt_xbass_xover_slider_info(struct snd_kcontrol *kcontrol,
5209 struct snd_ctl_elem_info *uinfo)
5211 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5213 uinfo->value.integer.min = 1;
5214 uinfo->value.integer.max = 100;
5215 uinfo->value.integer.step = 1;
5220 static int ca0132_alt_effect_slider_info(struct snd_kcontrol *kcontrol,
5221 struct snd_ctl_elem_info *uinfo)
5223 int chs = get_amp_channels(kcontrol);
5225 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5226 uinfo->count = chs == 3 ? 2 : 1;
5227 uinfo->value.integer.min = 0;
5228 uinfo->value.integer.max = 100;
5229 uinfo->value.integer.step = 1;
5234 static int ca0132_alt_xbass_xover_slider_put(struct snd_kcontrol *kcontrol,
5235 struct snd_ctl_elem_value *ucontrol)
5237 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5238 struct ca0132_spec *spec = codec->spec;
5239 hda_nid_t nid = get_amp_nid(kcontrol);
5240 long *valp = ucontrol->value.integer.value;
5244 if (spec->xbass_xover_freq == *valp)
5247 spec->xbass_xover_freq = *valp;
5250 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
5255 static int ca0132_alt_effect_slider_put(struct snd_kcontrol *kcontrol,
5256 struct snd_ctl_elem_value *ucontrol)
5258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5259 struct ca0132_spec *spec = codec->spec;
5260 hda_nid_t nid = get_amp_nid(kcontrol);
5261 long *valp = ucontrol->value.integer.value;
5264 idx = nid - EFFECT_START_NID;
5266 if (spec->fx_ctl_val[idx] == *valp)
5269 spec->fx_ctl_val[idx] = *valp;
5272 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
5279 * Mic Boost Enum for alternative ca0132 codecs. I didn't like that the original
5280 * only has off or full 30 dB, and didn't like making a volume slider that has
5281 * traditional 0-100 in alsamixer that goes in big steps. I like enum better.
5283 #define MIC_BOOST_NUM_OF_STEPS 4
5284 #define MIC_BOOST_ENUM_MAX_STRLEN 10
5286 static int ca0132_alt_mic_boost_info(struct snd_kcontrol *kcontrol,
5287 struct snd_ctl_elem_info *uinfo)
5290 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5292 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5294 uinfo->value.enumerated.items = MIC_BOOST_NUM_OF_STEPS;
5295 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS)
5296 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1;
5297 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx);
5298 strcpy(uinfo->value.enumerated.name, namestr);
5302 static int ca0132_alt_mic_boost_get(struct snd_kcontrol *kcontrol,
5303 struct snd_ctl_elem_value *ucontrol)
5305 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5306 struct ca0132_spec *spec = codec->spec;
5308 ucontrol->value.enumerated.item[0] = spec->mic_boost_enum_val;
5312 static int ca0132_alt_mic_boost_put(struct snd_kcontrol *kcontrol,
5313 struct snd_ctl_elem_value *ucontrol)
5315 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5316 struct ca0132_spec *spec = codec->spec;
5317 int sel = ucontrol->value.enumerated.item[0];
5318 unsigned int items = MIC_BOOST_NUM_OF_STEPS;
5323 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
5326 spec->mic_boost_enum_val = sel;
5328 if (spec->in_enum_val != REAR_LINE_IN)
5329 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5335 * Sound BlasterX AE-5 Headphone Gain Controls.
5337 #define AE5_HEADPHONE_GAIN_MAX 3
5338 static int ae5_headphone_gain_info(struct snd_kcontrol *kcontrol,
5339 struct snd_ctl_elem_info *uinfo)
5341 char *sfx = " Ohms)";
5342 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5344 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5346 uinfo->value.enumerated.items = AE5_HEADPHONE_GAIN_MAX;
5347 if (uinfo->value.enumerated.item >= AE5_HEADPHONE_GAIN_MAX)
5348 uinfo->value.enumerated.item = AE5_HEADPHONE_GAIN_MAX - 1;
5349 sprintf(namestr, "%s %s",
5350 ae5_headphone_gain_presets[uinfo->value.enumerated.item].name,
5352 strcpy(uinfo->value.enumerated.name, namestr);
5356 static int ae5_headphone_gain_get(struct snd_kcontrol *kcontrol,
5357 struct snd_ctl_elem_value *ucontrol)
5359 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5360 struct ca0132_spec *spec = codec->spec;
5362 ucontrol->value.enumerated.item[0] = spec->ae5_headphone_gain_val;
5366 static int ae5_headphone_gain_put(struct snd_kcontrol *kcontrol,
5367 struct snd_ctl_elem_value *ucontrol)
5369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5370 struct ca0132_spec *spec = codec->spec;
5371 int sel = ucontrol->value.enumerated.item[0];
5372 unsigned int items = AE5_HEADPHONE_GAIN_MAX;
5377 codec_dbg(codec, "ae5_headphone_gain: boost=%d\n",
5380 spec->ae5_headphone_gain_val = sel;
5382 if (spec->out_enum_val == HEADPHONE_OUT)
5383 ae5_headphone_gain_set(codec, spec->ae5_headphone_gain_val);
5389 * Sound BlasterX AE-5 sound filter enumerated control.
5391 #define AE5_SOUND_FILTER_MAX 3
5393 static int ae5_sound_filter_info(struct snd_kcontrol *kcontrol,
5394 struct snd_ctl_elem_info *uinfo)
5396 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
5398 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5400 uinfo->value.enumerated.items = AE5_SOUND_FILTER_MAX;
5401 if (uinfo->value.enumerated.item >= AE5_SOUND_FILTER_MAX)
5402 uinfo->value.enumerated.item = AE5_SOUND_FILTER_MAX - 1;
5403 sprintf(namestr, "%s",
5404 ae5_filter_presets[uinfo->value.enumerated.item].name);
5405 strcpy(uinfo->value.enumerated.name, namestr);
5409 static int ae5_sound_filter_get(struct snd_kcontrol *kcontrol,
5410 struct snd_ctl_elem_value *ucontrol)
5412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5413 struct ca0132_spec *spec = codec->spec;
5415 ucontrol->value.enumerated.item[0] = spec->ae5_filter_val;
5419 static int ae5_sound_filter_put(struct snd_kcontrol *kcontrol,
5420 struct snd_ctl_elem_value *ucontrol)
5422 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5423 struct ca0132_spec *spec = codec->spec;
5424 int sel = ucontrol->value.enumerated.item[0];
5425 unsigned int items = AE5_SOUND_FILTER_MAX;
5430 codec_dbg(codec, "ae5_sound_filter: %s\n",
5431 ae5_filter_presets[sel].name);
5433 spec->ae5_filter_val = sel;
5435 ca0113_mmio_command_set_type2(codec, 0x48, 0x07,
5436 ae5_filter_presets[sel].val);
5442 * Input Select Control for alternative ca0132 codecs. This exists because
5443 * front microphone has no auto-detect, and we need a way to set the rear
5446 static int ca0132_alt_input_source_info(struct snd_kcontrol *kcontrol,
5447 struct snd_ctl_elem_info *uinfo)
5449 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5451 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS;
5452 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS)
5453 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1;
5454 strcpy(uinfo->value.enumerated.name,
5455 in_src_str[uinfo->value.enumerated.item]);
5459 static int ca0132_alt_input_source_get(struct snd_kcontrol *kcontrol,
5460 struct snd_ctl_elem_value *ucontrol)
5462 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5463 struct ca0132_spec *spec = codec->spec;
5465 ucontrol->value.enumerated.item[0] = spec->in_enum_val;
5469 static int ca0132_alt_input_source_put(struct snd_kcontrol *kcontrol,
5470 struct snd_ctl_elem_value *ucontrol)
5472 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5473 struct ca0132_spec *spec = codec->spec;
5474 int sel = ucontrol->value.enumerated.item[0];
5475 unsigned int items = IN_SRC_NUM_OF_INPUTS;
5480 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5481 sel, in_src_str[sel]);
5483 spec->in_enum_val = sel;
5485 ca0132_alt_select_in(codec);
5490 /* Sound Blaster Z Output Select Control */
5491 static int ca0132_alt_output_select_get_info(struct snd_kcontrol *kcontrol,
5492 struct snd_ctl_elem_info *uinfo)
5494 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5496 uinfo->value.enumerated.items = NUM_OF_OUTPUTS;
5497 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS)
5498 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1;
5499 strcpy(uinfo->value.enumerated.name,
5500 alt_out_presets[uinfo->value.enumerated.item].name);
5504 static int ca0132_alt_output_select_get(struct snd_kcontrol *kcontrol,
5505 struct snd_ctl_elem_value *ucontrol)
5507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5508 struct ca0132_spec *spec = codec->spec;
5510 ucontrol->value.enumerated.item[0] = spec->out_enum_val;
5514 static int ca0132_alt_output_select_put(struct snd_kcontrol *kcontrol,
5515 struct snd_ctl_elem_value *ucontrol)
5517 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5518 struct ca0132_spec *spec = codec->spec;
5519 int sel = ucontrol->value.enumerated.item[0];
5520 unsigned int items = NUM_OF_OUTPUTS;
5521 unsigned int auto_jack;
5526 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
5527 sel, alt_out_presets[sel].name);
5529 spec->out_enum_val = sel;
5531 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
5534 ca0132_alt_select_out(codec);
5540 * Smart Volume output setting control. Three different settings, Normal,
5541 * which takes the value from the smart volume slider. The two others, loud
5542 * and night, disregard the slider value and have uneditable values.
5544 #define NUM_OF_SVM_SETTINGS 3
5545 static const char *const out_svm_set_enum_str[3] = {"Normal", "Loud", "Night" };
5547 static int ca0132_alt_svm_setting_info(struct snd_kcontrol *kcontrol,
5548 struct snd_ctl_elem_info *uinfo)
5550 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5552 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS;
5553 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS)
5554 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1;
5555 strcpy(uinfo->value.enumerated.name,
5556 out_svm_set_enum_str[uinfo->value.enumerated.item]);
5560 static int ca0132_alt_svm_setting_get(struct snd_kcontrol *kcontrol,
5561 struct snd_ctl_elem_value *ucontrol)
5563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5564 struct ca0132_spec *spec = codec->spec;
5566 ucontrol->value.enumerated.item[0] = spec->smart_volume_setting;
5570 static int ca0132_alt_svm_setting_put(struct snd_kcontrol *kcontrol,
5571 struct snd_ctl_elem_value *ucontrol)
5573 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5574 struct ca0132_spec *spec = codec->spec;
5575 int sel = ucontrol->value.enumerated.item[0];
5576 unsigned int items = NUM_OF_SVM_SETTINGS;
5577 unsigned int idx = SMART_VOLUME - EFFECT_START_NID;
5583 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
5584 sel, out_svm_set_enum_str[sel]);
5586 spec->smart_volume_setting = sel;
5602 /* Req 2 is the Smart Volume Setting req. */
5603 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5604 ca0132_effects[idx].reqs[2], tmp);
5608 /* Sound Blaster Z EQ preset controls */
5609 static int ca0132_alt_eq_preset_info(struct snd_kcontrol *kcontrol,
5610 struct snd_ctl_elem_info *uinfo)
5612 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5614 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5616 uinfo->value.enumerated.items = items;
5617 if (uinfo->value.enumerated.item >= items)
5618 uinfo->value.enumerated.item = items - 1;
5619 strcpy(uinfo->value.enumerated.name,
5620 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name);
5624 static int ca0132_alt_eq_preset_get(struct snd_kcontrol *kcontrol,
5625 struct snd_ctl_elem_value *ucontrol)
5627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5628 struct ca0132_spec *spec = codec->spec;
5630 ucontrol->value.enumerated.item[0] = spec->eq_preset_val;
5634 static int ca0132_alt_eq_preset_put(struct snd_kcontrol *kcontrol,
5635 struct snd_ctl_elem_value *ucontrol)
5637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5638 struct ca0132_spec *spec = codec->spec;
5640 int sel = ucontrol->value.enumerated.item[0];
5641 unsigned int items = ARRAY_SIZE(ca0132_alt_eq_presets);
5646 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
5647 ca0132_alt_eq_presets[sel].name);
5650 * Default needs to qualify with CrystalVoice state.
5652 for (i = 0; i < EQ_PRESET_MAX_PARAM_COUNT; i++) {
5653 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
5654 ca0132_alt_eq_enum.reqs[i],
5655 ca0132_alt_eq_presets[sel].vals[i]);
5661 spec->eq_preset_val = sel;
5666 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
5667 struct snd_ctl_elem_info *uinfo)
5669 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
5671 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5673 uinfo->value.enumerated.items = items;
5674 if (uinfo->value.enumerated.item >= items)
5675 uinfo->value.enumerated.item = items - 1;
5676 strcpy(uinfo->value.enumerated.name,
5677 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
5681 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
5682 struct snd_ctl_elem_value *ucontrol)
5684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5685 struct ca0132_spec *spec = codec->spec;
5687 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
5691 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
5692 struct snd_ctl_elem_value *ucontrol)
5694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5695 struct ca0132_spec *spec = codec->spec;
5697 int sel = ucontrol->value.enumerated.item[0];
5699 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
5702 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
5703 sel, ca0132_voicefx_presets[sel].name);
5707 * Default needs to qualify with CrystalVoice state.
5709 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
5710 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
5711 ca0132_voicefx.reqs[i],
5712 ca0132_voicefx_presets[sel].vals[i]);
5718 spec->voicefx_val = sel;
5719 /* enable voice fx */
5720 ca0132_voicefx_set(codec, (sel ? 1 : 0));
5726 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
5727 struct snd_ctl_elem_value *ucontrol)
5729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5730 struct ca0132_spec *spec = codec->spec;
5731 hda_nid_t nid = get_amp_nid(kcontrol);
5732 int ch = get_amp_channels(kcontrol);
5733 long *valp = ucontrol->value.integer.value;
5736 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5738 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
5742 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
5748 /* effects, include PE and CrystalVoice */
5749 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
5750 *valp = spec->effects_switch[nid - EFFECT_START_NID];
5755 if (nid == spec->input_pins[0]) {
5756 *valp = spec->cur_mic_boost;
5763 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
5764 struct snd_ctl_elem_value *ucontrol)
5766 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5767 struct ca0132_spec *spec = codec->spec;
5768 hda_nid_t nid = get_amp_nid(kcontrol);
5769 int ch = get_amp_channels(kcontrol);
5770 long *valp = ucontrol->value.integer.value;
5773 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
5776 snd_hda_power_up(codec);
5778 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
5780 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
5784 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
5787 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
5792 if (nid == PLAY_ENHANCEMENT) {
5793 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5794 changed = ca0132_pe_switch_set(codec);
5799 if (nid == CRYSTAL_VOICE) {
5800 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5801 changed = ca0132_cvoice_switch_set(codec);
5805 /* out and in effects */
5806 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
5807 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
5808 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
5809 changed = ca0132_effects_set(codec, nid, *valp);
5814 if (nid == spec->input_pins[0]) {
5815 spec->cur_mic_boost = *valp;
5816 if (ca0132_use_alt_functions(spec)) {
5817 if (spec->in_enum_val != REAR_LINE_IN)
5818 changed = ca0132_mic_boost_set(codec, *valp);
5820 /* Mic boost does not apply to Digital Mic */
5821 if (spec->cur_mic_type != DIGITAL_MIC)
5822 changed = ca0132_mic_boost_set(codec, *valp);
5828 if (nid == ZXR_HEADPHONE_GAIN) {
5829 spec->zxr_gain_set = *valp;
5830 if (spec->cur_out_type == HEADPHONE_OUT)
5831 changed = zxr_headphone_gain_set(codec, *valp);
5839 snd_hda_power_down(codec);
5847 * Sets the internal DSP decibel level to match the DAC for output, and the
5848 * ADC for input. Currently only the SBZ sets dsp capture volume level, and
5849 * all alternative codecs set DSP playback volume.
5851 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
5853 struct ca0132_spec *spec = codec->spec;
5854 unsigned int dsp_dir;
5855 unsigned int lookup_val;
5857 if (nid == VNID_SPK)
5858 dsp_dir = DSP_VOL_OUT;
5860 dsp_dir = DSP_VOL_IN;
5862 lookup_val = spec->vnode_lvol[nid - VNODE_START_NID];
5864 dspio_set_uint_param(codec,
5865 ca0132_alt_vol_ctls[dsp_dir].mid,
5866 ca0132_alt_vol_ctls[dsp_dir].reqs[0],
5867 float_vol_db_lookup[lookup_val]);
5869 lookup_val = spec->vnode_rvol[nid - VNODE_START_NID];
5871 dspio_set_uint_param(codec,
5872 ca0132_alt_vol_ctls[dsp_dir].mid,
5873 ca0132_alt_vol_ctls[dsp_dir].reqs[1],
5874 float_vol_db_lookup[lookup_val]);
5876 dspio_set_uint_param(codec,
5877 ca0132_alt_vol_ctls[dsp_dir].mid,
5878 ca0132_alt_vol_ctls[dsp_dir].reqs[2], FLOAT_ZERO);
5881 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
5882 struct snd_ctl_elem_info *uinfo)
5884 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5885 struct ca0132_spec *spec = codec->spec;
5886 hda_nid_t nid = get_amp_nid(kcontrol);
5887 int ch = get_amp_channels(kcontrol);
5888 int dir = get_amp_direction(kcontrol);
5894 /* follow shared_out info */
5895 nid = spec->shared_out_nid;
5896 mutex_lock(&codec->control_mutex);
5897 pval = kcontrol->private_value;
5898 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5899 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5900 kcontrol->private_value = pval;
5901 mutex_unlock(&codec->control_mutex);
5904 /* follow shared_mic info */
5905 nid = spec->shared_mic_nid;
5906 mutex_lock(&codec->control_mutex);
5907 pval = kcontrol->private_value;
5908 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
5909 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5910 kcontrol->private_value = pval;
5911 mutex_unlock(&codec->control_mutex);
5914 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5919 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
5920 struct snd_ctl_elem_value *ucontrol)
5922 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5923 struct ca0132_spec *spec = codec->spec;
5924 hda_nid_t nid = get_amp_nid(kcontrol);
5925 int ch = get_amp_channels(kcontrol);
5926 long *valp = ucontrol->value.integer.value;
5928 /* store the left and right volume */
5930 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
5934 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
5940 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
5941 struct snd_ctl_elem_value *ucontrol)
5943 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5944 struct ca0132_spec *spec = codec->spec;
5945 hda_nid_t nid = get_amp_nid(kcontrol);
5946 int ch = get_amp_channels(kcontrol);
5947 long *valp = ucontrol->value.integer.value;
5948 hda_nid_t shared_nid = 0;
5952 /* store the left and right volume */
5954 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
5958 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
5962 /* if effective conditions, then update hw immediately. */
5963 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5965 int dir = get_amp_direction(kcontrol);
5968 snd_hda_power_up(codec);
5969 mutex_lock(&codec->control_mutex);
5970 pval = kcontrol->private_value;
5971 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
5973 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
5974 kcontrol->private_value = pval;
5975 mutex_unlock(&codec->control_mutex);
5976 snd_hda_power_down(codec);
5983 * This function is the same as the one above, because using an if statement
5984 * inside of the above volume control for the DSP volume would cause too much
5985 * lag. This is a lot more smooth.
5987 static int ca0132_alt_volume_put(struct snd_kcontrol *kcontrol,
5988 struct snd_ctl_elem_value *ucontrol)
5990 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5991 struct ca0132_spec *spec = codec->spec;
5992 hda_nid_t nid = get_amp_nid(kcontrol);
5993 int ch = get_amp_channels(kcontrol);
5994 long *valp = ucontrol->value.integer.value;
6007 /* store the left and right volume */
6009 spec->vnode_lvol[vnid - VNODE_START_NID] = *valp;
6013 spec->vnode_rvol[vnid - VNODE_START_NID] = *valp;
6017 snd_hda_power_up(codec);
6018 ca0132_alt_dsp_volume_put(codec, vnid);
6019 mutex_lock(&codec->control_mutex);
6020 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
6021 mutex_unlock(&codec->control_mutex);
6022 snd_hda_power_down(codec);
6027 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
6028 unsigned int size, unsigned int __user *tlv)
6030 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6031 struct ca0132_spec *spec = codec->spec;
6032 hda_nid_t nid = get_amp_nid(kcontrol);
6033 int ch = get_amp_channels(kcontrol);
6034 int dir = get_amp_direction(kcontrol);
6040 /* follow shared_out tlv */
6041 nid = spec->shared_out_nid;
6042 mutex_lock(&codec->control_mutex);
6043 pval = kcontrol->private_value;
6044 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6045 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6046 kcontrol->private_value = pval;
6047 mutex_unlock(&codec->control_mutex);
6050 /* follow shared_mic tlv */
6051 nid = spec->shared_mic_nid;
6052 mutex_lock(&codec->control_mutex);
6053 pval = kcontrol->private_value;
6054 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
6055 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6056 kcontrol->private_value = pval;
6057 mutex_unlock(&codec->control_mutex);
6060 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
6065 /* Add volume slider control for effect level */
6066 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
6067 const char *pfx, int dir)
6069 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6070 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6071 struct snd_kcontrol_new knew =
6072 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
6074 sprintf(namestr, "FX: %s %s Volume", pfx, dirstr[dir]);
6080 knew.info = ca0132_alt_xbass_xover_slider_info;
6081 knew.get = ca0132_alt_xbass_xover_slider_ctl_get;
6082 knew.put = ca0132_alt_xbass_xover_slider_put;
6085 knew.info = ca0132_alt_effect_slider_info;
6086 knew.get = ca0132_alt_slider_ctl_get;
6087 knew.put = ca0132_alt_effect_slider_put;
6088 knew.private_value =
6089 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
6093 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6097 * Added FX: prefix for the alternative codecs, because otherwise the surround
6098 * effect would conflict with the Surround sound volume control. Also seems more
6099 * clear as to what the switches do. Left alone for others.
6101 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
6102 const char *pfx, int dir)
6104 struct ca0132_spec *spec = codec->spec;
6105 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
6106 int type = dir ? HDA_INPUT : HDA_OUTPUT;
6107 struct snd_kcontrol_new knew =
6108 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
6109 /* If using alt_controls, add FX: prefix. But, don't add FX:
6110 * prefix to OutFX or InFX enable controls.
6112 if (ca0132_use_alt_controls(spec) && (nid <= IN_EFFECT_END_NID))
6113 sprintf(namestr, "FX: %s %s Switch", pfx, dirstr[dir]);
6115 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
6117 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6120 static int add_voicefx(struct hda_codec *codec)
6122 struct snd_kcontrol_new knew =
6123 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
6124 VOICEFX, 1, 0, HDA_INPUT);
6125 knew.info = ca0132_voicefx_info;
6126 knew.get = ca0132_voicefx_get;
6127 knew.put = ca0132_voicefx_put;
6128 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
6131 /* Create the EQ Preset control */
6132 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
6134 struct snd_kcontrol_new knew =
6135 HDA_CODEC_MUTE_MONO(ca0132_alt_eq_enum.name,
6136 EQ_PRESET_ENUM, 1, 0, HDA_OUTPUT);
6137 knew.info = ca0132_alt_eq_preset_info;
6138 knew.get = ca0132_alt_eq_preset_get;
6139 knew.put = ca0132_alt_eq_preset_put;
6140 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
6141 snd_ctl_new1(&knew, codec));
6145 * Add enumerated control for the three different settings of the smart volume
6146 * output effect. Normal just uses the slider value, and loud and night are
6147 * their own things that ignore that value.
6149 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
6151 struct snd_kcontrol_new knew =
6152 HDA_CODEC_MUTE_MONO("FX: Smart Volume Setting",
6153 SMART_VOLUME_ENUM, 1, 0, HDA_OUTPUT);
6154 knew.info = ca0132_alt_svm_setting_info;
6155 knew.get = ca0132_alt_svm_setting_get;
6156 knew.put = ca0132_alt_svm_setting_put;
6157 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
6158 snd_ctl_new1(&knew, codec));
6163 * Create an Output Select enumerated control for codecs with surround
6166 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
6168 struct snd_kcontrol_new knew =
6169 HDA_CODEC_MUTE_MONO("Output Select",
6170 OUTPUT_SOURCE_ENUM, 1, 0, HDA_OUTPUT);
6171 knew.info = ca0132_alt_output_select_get_info;
6172 knew.get = ca0132_alt_output_select_get;
6173 knew.put = ca0132_alt_output_select_put;
6174 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
6175 snd_ctl_new1(&knew, codec));
6179 * Create an Input Source enumerated control for the alternate ca0132 codecs
6180 * because the front microphone has no auto-detect, and Line-in has to be set
6183 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
6185 struct snd_kcontrol_new knew =
6186 HDA_CODEC_MUTE_MONO("Input Source",
6187 INPUT_SOURCE_ENUM, 1, 0, HDA_INPUT);
6188 knew.info = ca0132_alt_input_source_info;
6189 knew.get = ca0132_alt_input_source_get;
6190 knew.put = ca0132_alt_input_source_put;
6191 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
6192 snd_ctl_new1(&knew, codec));
6196 * Add mic boost enumerated control. Switches through 0dB to 30dB. This adds
6197 * more control than the original mic boost, which is either full 30dB or off.
6199 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
6201 struct snd_kcontrol_new knew =
6202 HDA_CODEC_MUTE_MONO("Mic Boost Capture Switch",
6203 MIC_BOOST_ENUM, 1, 0, HDA_INPUT);
6204 knew.info = ca0132_alt_mic_boost_info;
6205 knew.get = ca0132_alt_mic_boost_get;
6206 knew.put = ca0132_alt_mic_boost_put;
6207 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
6208 snd_ctl_new1(&knew, codec));
6213 * Add headphone gain enumerated control for the AE-5. This switches between
6214 * three modes, low, medium, and high. When non-headphone outputs are selected,
6215 * it is automatically set to high. This is the same behavior as Windows.
6217 static int ae5_add_headphone_gain_enum(struct hda_codec *codec)
6219 struct snd_kcontrol_new knew =
6220 HDA_CODEC_MUTE_MONO("AE-5: Headphone Gain",
6221 AE5_HEADPHONE_GAIN_ENUM, 1, 0, HDA_OUTPUT);
6222 knew.info = ae5_headphone_gain_info;
6223 knew.get = ae5_headphone_gain_get;
6224 knew.put = ae5_headphone_gain_put;
6225 return snd_hda_ctl_add(codec, AE5_HEADPHONE_GAIN_ENUM,
6226 snd_ctl_new1(&knew, codec));
6230 * Add sound filter enumerated control for the AE-5. This adds three different
6231 * settings: Slow Roll Off, Minimum Phase, and Fast Roll Off. From what I've
6232 * read into it, it changes the DAC's interpolation filter.
6234 static int ae5_add_sound_filter_enum(struct hda_codec *codec)
6236 struct snd_kcontrol_new knew =
6237 HDA_CODEC_MUTE_MONO("AE-5: Sound Filter",
6238 AE5_SOUND_FILTER_ENUM, 1, 0, HDA_OUTPUT);
6239 knew.info = ae5_sound_filter_info;
6240 knew.get = ae5_sound_filter_get;
6241 knew.put = ae5_sound_filter_put;
6242 return snd_hda_ctl_add(codec, AE5_SOUND_FILTER_ENUM,
6243 snd_ctl_new1(&knew, codec));
6246 static int zxr_add_headphone_gain_switch(struct hda_codec *codec)
6248 struct snd_kcontrol_new knew =
6249 CA0132_CODEC_MUTE_MONO("ZxR: 600 Ohm Gain",
6250 ZXR_HEADPHONE_GAIN, 1, HDA_OUTPUT);
6252 return snd_hda_ctl_add(codec, ZXR_HEADPHONE_GAIN,
6253 snd_ctl_new1(&knew, codec));
6257 * Need to create slave controls for the alternate codecs that have surround
6260 static const char * const ca0132_alt_slave_pfxs[] = {
6261 "Front", "Surround", "Center", "LFE", NULL,
6265 * Also need special channel map, because the default one is incorrect.
6266 * I think this has to do with the pin for rear surround being 0x11,
6267 * and the center/lfe being 0x10. Usually the pin order is the opposite.
6269 static const struct snd_pcm_chmap_elem ca0132_alt_chmaps[] = {
6271 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
6273 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6274 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6276 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
6277 SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE,
6278 SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
6282 /* Add the correct chmap for streams with 6 channels. */
6283 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
6286 struct hda_pcm *pcm;
6288 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
6289 struct hda_pcm_stream *hinfo =
6290 &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
6291 struct snd_pcm_chmap *chmap;
6292 const struct snd_pcm_chmap_elem *elem;
6294 elem = ca0132_alt_chmaps;
6295 if (hinfo->channels_max == 6) {
6296 err = snd_pcm_add_chmap_ctls(pcm->pcm,
6297 SNDRV_PCM_STREAM_PLAYBACK,
6298 elem, hinfo->channels_max, 0, &chmap);
6300 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
6306 * When changing Node IDs for Mixer Controls below, make sure to update
6307 * Node IDs in ca0132_config() as well.
6309 static const struct snd_kcontrol_new ca0132_mixer[] = {
6310 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
6311 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
6312 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6313 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6314 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
6315 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
6316 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6317 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6318 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
6319 0x12, 1, HDA_INPUT),
6320 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
6321 VNID_HP_SEL, 1, HDA_OUTPUT),
6322 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
6323 VNID_AMIC1_SEL, 1, HDA_INPUT),
6324 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6325 VNID_HP_ASEL, 1, HDA_OUTPUT),
6326 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
6327 VNID_AMIC1_ASEL, 1, HDA_INPUT),
6332 * Desktop specific control mixer. Removes auto-detect for mic, and adds
6333 * surround controls. Also sets both the Front Playback and Capture Volume
6334 * controls to alt so they set the DSP's decibel level.
6336 static const struct snd_kcontrol_new desktop_mixer[] = {
6337 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6338 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6339 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6340 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6341 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6342 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6343 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6344 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6345 CA0132_ALT_CODEC_VOL("Capture Volume", 0x07, HDA_INPUT),
6346 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6347 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6348 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6349 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6350 VNID_HP_ASEL, 1, HDA_OUTPUT),
6355 * Same as the Sound Blaster Z, except doesn't use the alt volume for capture
6356 * because it doesn't set decibel levels for the DSP for capture.
6358 static const struct snd_kcontrol_new r3di_mixer[] = {
6359 CA0132_ALT_CODEC_VOL("Front Playback Volume", 0x02, HDA_OUTPUT),
6360 CA0132_CODEC_MUTE("Front Playback Switch", VNID_SPK, HDA_OUTPUT),
6361 HDA_CODEC_VOLUME("Surround Playback Volume", 0x04, 0, HDA_OUTPUT),
6362 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0, HDA_OUTPUT),
6363 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x03, 1, 0, HDA_OUTPUT),
6364 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x03, 1, 0, HDA_OUTPUT),
6365 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x03, 2, 0, HDA_OUTPUT),
6366 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x03, 2, 0, HDA_OUTPUT),
6367 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
6368 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
6369 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
6370 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
6371 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
6372 VNID_HP_ASEL, 1, HDA_OUTPUT),
6376 static int ca0132_build_controls(struct hda_codec *codec)
6378 struct ca0132_spec *spec = codec->spec;
6379 int i, num_fx, num_sliders;
6382 /* Add Mixer controls */
6383 for (i = 0; i < spec->num_mixers; i++) {
6384 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
6388 /* Setup vmaster with surround slaves for desktop ca0132 devices */
6389 if (ca0132_use_alt_functions(spec)) {
6390 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
6392 snd_hda_add_vmaster(codec, "Master Playback Volume",
6393 spec->tlv, ca0132_alt_slave_pfxs,
6395 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
6396 NULL, ca0132_alt_slave_pfxs,
6398 true, &spec->vmaster_mute.sw_kctl);
6403 /* Add in and out effects controls.
6404 * VoiceFX, PE and CrystalVoice are added separately.
6406 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
6407 for (i = 0; i < num_fx; i++) {
6408 /* Desktop cards break if Echo Cancellation is used. */
6409 if (ca0132_use_pci_mmio(spec)) {
6410 if (i == (ECHO_CANCELLATION - IN_EFFECT_START_NID +
6415 err = add_fx_switch(codec, ca0132_effects[i].nid,
6416 ca0132_effects[i].name,
6417 ca0132_effects[i].direct);
6422 * If codec has use_alt_controls set to true, add effect level sliders,
6423 * EQ presets, and Smart Volume presets. Also, change names to add FX
6424 * prefix, and change PlayEnhancement and CrystalVoice to match.
6426 if (ca0132_use_alt_controls(spec)) {
6427 err = ca0132_alt_add_svm_enum(codec);
6431 err = add_ca0132_alt_eq_presets(codec);
6435 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6440 err = add_fx_switch(codec, CRYSTAL_VOICE,
6445 num_sliders = OUT_EFFECTS_COUNT - 1;
6446 for (i = 0; i < num_sliders; i++) {
6447 err = ca0132_alt_add_effect_slider(codec,
6448 ca0132_effects[i].nid,
6449 ca0132_effects[i].name,
6450 ca0132_effects[i].direct);
6455 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
6456 "X-Bass Crossover", EFX_DIR_OUT);
6461 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
6462 "PlayEnhancement", 0);
6466 err = add_fx_switch(codec, CRYSTAL_VOICE,
6471 err = add_voicefx(codec);
6476 * If the codec uses alt_functions, you need the enumerated controls
6477 * to select the new outputs and inputs, plus add the new mic boost
6480 if (ca0132_use_alt_functions(spec)) {
6481 err = ca0132_alt_add_output_enum(codec);
6484 err = ca0132_alt_add_mic_boost_enum(codec);
6488 * ZxR only has microphone input, there is no front panel
6489 * header on the card, and aux-in is handled by the DBPro board.
6491 if (ca0132_quirk(spec) != QUIRK_ZXR) {
6492 err = ca0132_alt_add_input_enum(codec);
6498 if (ca0132_quirk(spec) == QUIRK_AE5) {
6499 err = ae5_add_headphone_gain_enum(codec);
6502 err = ae5_add_sound_filter_enum(codec);
6507 if (ca0132_quirk(spec) == QUIRK_ZXR) {
6508 err = zxr_add_headphone_gain_switch(codec);
6512 #ifdef ENABLE_TUNING_CONTROLS
6513 add_tuning_ctls(codec);
6516 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
6520 if (spec->dig_out) {
6521 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
6525 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
6528 /* spec->multiout.share_spdif = 1; */
6532 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
6537 if (ca0132_use_alt_functions(spec))
6538 ca0132_alt_add_chmap_ctls(codec);
6543 static int dbpro_build_controls(struct hda_codec *codec)
6545 struct ca0132_spec *spec = codec->spec;
6548 if (spec->dig_out) {
6549 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
6556 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
6567 static const struct hda_pcm_stream ca0132_pcm_analog_playback = {
6572 .prepare = ca0132_playback_pcm_prepare,
6573 .cleanup = ca0132_playback_pcm_cleanup,
6574 .get_delay = ca0132_playback_pcm_delay,
6578 static const struct hda_pcm_stream ca0132_pcm_analog_capture = {
6583 .prepare = ca0132_capture_pcm_prepare,
6584 .cleanup = ca0132_capture_pcm_cleanup,
6585 .get_delay = ca0132_capture_pcm_delay,
6589 static const struct hda_pcm_stream ca0132_pcm_digital_playback = {
6594 .open = ca0132_dig_playback_pcm_open,
6595 .close = ca0132_dig_playback_pcm_close,
6596 .prepare = ca0132_dig_playback_pcm_prepare,
6597 .cleanup = ca0132_dig_playback_pcm_cleanup
6601 static const struct hda_pcm_stream ca0132_pcm_digital_capture = {
6607 static int ca0132_build_pcms(struct hda_codec *codec)
6609 struct ca0132_spec *spec = codec->spec;
6610 struct hda_pcm *info;
6612 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
6615 if (ca0132_use_alt_functions(spec)) {
6616 info->own_chmap = true;
6617 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap
6618 = ca0132_alt_chmaps;
6620 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
6621 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
6622 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
6623 spec->multiout.max_channels;
6624 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6625 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6626 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
6628 /* With the DSP enabled, desktops don't use this ADC. */
6629 if (!ca0132_use_alt_functions(spec)) {
6630 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
6633 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6634 ca0132_pcm_analog_capture;
6635 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6636 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
6639 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
6642 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6643 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6644 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
6646 if (!spec->dig_out && !spec->dig_in)
6649 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
6652 info->pcm_type = HDA_PCM_TYPE_SPDIF;
6653 if (spec->dig_out) {
6654 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
6655 ca0132_pcm_digital_playback;
6656 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
6659 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6660 ca0132_pcm_digital_capture;
6661 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
6667 static int dbpro_build_pcms(struct hda_codec *codec)
6669 struct ca0132_spec *spec = codec->spec;
6670 struct hda_pcm *info;
6672 info = snd_hda_codec_pcm_new(codec, "CA0132 Alt Analog");
6675 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
6676 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
6677 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
6680 if (!spec->dig_out && !spec->dig_in)
6683 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
6686 info->pcm_type = HDA_PCM_TYPE_SPDIF;
6687 if (spec->dig_out) {
6688 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
6689 ca0132_pcm_digital_playback;
6690 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
6693 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
6694 ca0132_pcm_digital_capture;
6695 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
6701 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
6704 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
6705 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
6706 snd_hda_codec_write(codec, pin, 0,
6707 AC_VERB_SET_AMP_GAIN_MUTE,
6710 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
6711 snd_hda_codec_write(codec, dac, 0,
6712 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
6715 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
6718 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
6719 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
6720 snd_hda_codec_write(codec, pin, 0,
6721 AC_VERB_SET_AMP_GAIN_MUTE,
6724 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
6725 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6728 /* init to 0 dB and unmute. */
6729 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6730 HDA_AMP_VOLMASK, 0x5a);
6731 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
6736 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
6740 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
6741 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
6742 snd_hda_override_amp_caps(codec, nid, dir, caps);
6746 * Switch between Digital built-in mic and analog mic.
6748 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
6750 struct ca0132_spec *spec = codec->spec;
6753 unsigned int oldval;
6755 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
6757 oldval = stop_mic1(codec);
6758 ca0132_set_vipsource(codec, 0);
6760 /* set DMic input as 2-ch */
6762 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6764 val = spec->dmic_ctl;
6766 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6767 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6769 if (!(spec->dmic_ctl & 0x20))
6770 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
6772 /* set AMic input as mono */
6774 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6776 val = spec->dmic_ctl;
6777 /* clear bit7 and bit5 to disable dmic */
6779 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6780 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6782 if (!(spec->dmic_ctl & 0x20))
6783 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
6785 ca0132_set_vipsource(codec, 1);
6786 resume_mic1(codec, oldval);
6790 * Initialization for Digital Mic.
6792 static void ca0132_init_dmic(struct hda_codec *codec)
6794 struct ca0132_spec *spec = codec->spec;
6797 /* Setup Digital Mic here, but don't enable.
6798 * Enable based on jack detect.
6801 /* MCLK uses MPIO1, set to enable.
6802 * Bit 2-0: MPIO select
6803 * Bit 3: set to disable
6807 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6808 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
6810 /* Data1 uses MPIO3. Data2 not use
6811 * Bit 2-0: Data1 MPIO select
6812 * Bit 3: set disable Data1
6813 * Bit 6-4: Data2 MPIO select
6814 * Bit 7: set disable Data2
6817 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6818 VENDOR_CHIPIO_DMIC_PIN_SET, val);
6820 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
6821 * Bit 3-0: Channel mask
6822 * Bit 4: set for 48KHz, clear for 32KHz
6824 * Bit 6: set to select Data2, clear for Data1
6825 * Bit 7: set to enable DMic, clear for AMic
6827 if (ca0132_quirk(spec) == QUIRK_ALIENWARE_M17XR4)
6831 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
6832 spec->dmic_ctl = val;
6833 snd_hda_codec_write(codec, spec->input_pins[0], 0,
6834 VENDOR_CHIPIO_DMIC_CTL_SET, val);
6838 * Initialization for Analog Mic 2
6840 static void ca0132_init_analog_mic2(struct hda_codec *codec)
6842 struct ca0132_spec *spec = codec->spec;
6844 mutex_lock(&spec->chipio_mutex);
6845 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6846 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
6847 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6848 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6849 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6850 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6851 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6852 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
6853 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6854 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
6855 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
6856 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
6857 mutex_unlock(&spec->chipio_mutex);
6860 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
6862 struct ca0132_spec *spec = codec->spec;
6865 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
6866 snd_hda_codec_update_widgets(codec);
6868 for (i = 0; i < spec->multiout.num_dacs; i++)
6869 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
6871 for (i = 0; i < spec->num_outputs; i++)
6872 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
6874 for (i = 0; i < spec->num_inputs; i++) {
6875 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
6876 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
6881 * Creates a dummy stream to bind the output to. This seems to have to be done
6882 * after changing the main outputs source and destination streams.
6884 static void ca0132_alt_create_dummy_stream(struct hda_codec *codec)
6886 struct ca0132_spec *spec = codec->spec;
6887 unsigned int stream_format;
6889 stream_format = snd_hdac_calc_stream_format(48000, 2,
6890 SNDRV_PCM_FORMAT_S32_LE, 32, 0);
6892 snd_hda_codec_setup_stream(codec, spec->dacs[0], spec->dsp_stream_id,
6895 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
6899 * Initialize mic for non-chromebook ca0132 implementations.
6901 static void ca0132_alt_init_analog_mics(struct hda_codec *codec)
6903 struct ca0132_spec *spec = codec->spec;
6907 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
6908 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
6909 if (ca0132_quirk(spec) == QUIRK_R3DI) {
6910 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6914 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
6916 /* Mic 2 setup (not present on desktop cards) */
6917 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
6918 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
6919 if (ca0132_quirk(spec) == QUIRK_R3DI)
6920 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
6922 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
6926 * Sets the source of stream 0x14 to connpointID 0x48, and the destination
6927 * connpointID to 0x91. If this isn't done, the destination is 0x71, and
6928 * you get no sound. I'm guessing this has to do with the Sound Blaster Z
6929 * having an updated DAC, which changes the destination to that DAC.
6931 static void sbz_connect_streams(struct hda_codec *codec)
6933 struct ca0132_spec *spec = codec->spec;
6935 mutex_lock(&spec->chipio_mutex);
6937 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
6939 chipio_set_stream_channels(codec, 0x0C, 6);
6940 chipio_set_stream_control(codec, 0x0C, 1);
6942 /* This value is 0x43 for 96khz, and 0x83 for 192khz. */
6943 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
6945 /* Setup stream 0x14 with it's source and destination points */
6946 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
6947 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
6948 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
6949 chipio_set_stream_channels(codec, 0x14, 2);
6950 chipio_set_stream_control(codec, 0x14, 1);
6952 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
6954 mutex_unlock(&spec->chipio_mutex);
6958 * Write data through ChipIO to setup proper stream destinations.
6959 * Not sure how it exactly works, but it seems to direct data
6960 * to different destinations. Example is f8 to c0, e0 to c0.
6961 * All I know is, if you don't set these, you get no sound.
6963 static void sbz_chipio_startup_data(struct hda_codec *codec)
6965 struct ca0132_spec *spec = codec->spec;
6967 mutex_lock(&spec->chipio_mutex);
6968 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
6970 /* These control audio output */
6971 chipio_write_no_mutex(codec, 0x190060, 0x0001f8c0);
6972 chipio_write_no_mutex(codec, 0x190064, 0x0001f9c1);
6973 chipio_write_no_mutex(codec, 0x190068, 0x0001fac6);
6974 chipio_write_no_mutex(codec, 0x19006c, 0x0001fbc7);
6975 /* Signal to update I think */
6976 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
6978 chipio_set_stream_channels(codec, 0x0C, 6);
6979 chipio_set_stream_control(codec, 0x0C, 1);
6980 /* No clue what these control */
6981 if (ca0132_quirk(spec) == QUIRK_SBZ) {
6982 chipio_write_no_mutex(codec, 0x190030, 0x0001e0c0);
6983 chipio_write_no_mutex(codec, 0x190034, 0x0001e1c1);
6984 chipio_write_no_mutex(codec, 0x190038, 0x0001e4c2);
6985 chipio_write_no_mutex(codec, 0x19003c, 0x0001e5c3);
6986 chipio_write_no_mutex(codec, 0x190040, 0x0001e2c4);
6987 chipio_write_no_mutex(codec, 0x190044, 0x0001e3c5);
6988 chipio_write_no_mutex(codec, 0x190048, 0x0001e8c6);
6989 chipio_write_no_mutex(codec, 0x19004c, 0x0001e9c7);
6990 chipio_write_no_mutex(codec, 0x190050, 0x0001ecc8);
6991 chipio_write_no_mutex(codec, 0x190054, 0x0001edc9);
6992 chipio_write_no_mutex(codec, 0x190058, 0x0001eaca);
6993 chipio_write_no_mutex(codec, 0x19005c, 0x0001ebcb);
6994 } else if (ca0132_quirk(spec) == QUIRK_ZXR) {
6995 chipio_write_no_mutex(codec, 0x190038, 0x000140c2);
6996 chipio_write_no_mutex(codec, 0x19003c, 0x000141c3);
6997 chipio_write_no_mutex(codec, 0x190040, 0x000150c4);
6998 chipio_write_no_mutex(codec, 0x190044, 0x000151c5);
6999 chipio_write_no_mutex(codec, 0x190050, 0x000142c8);
7000 chipio_write_no_mutex(codec, 0x190054, 0x000143c9);
7001 chipio_write_no_mutex(codec, 0x190058, 0x000152ca);
7002 chipio_write_no_mutex(codec, 0x19005c, 0x000153cb);
7004 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
7006 codec_dbg(codec, "Startup Data exited, mutex released.\n");
7007 mutex_unlock(&spec->chipio_mutex);
7011 * Custom DSP SCP commands where the src value is 0x00 instead of 0x20. This is
7012 * done after the DSP is loaded.
7014 static void ca0132_alt_dsp_scp_startup(struct hda_codec *codec)
7016 struct ca0132_spec *spec = codec->spec;
7017 unsigned int tmp, i;
7020 * Gotta run these twice, or else mic works inconsistently. Not clear
7021 * why this is, but multiple tests have confirmed it.
7023 for (i = 0; i < 2; i++) {
7024 switch (ca0132_quirk(spec)) {
7028 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7030 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7032 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7034 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7036 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7038 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7043 dspio_set_uint_param_no_source(codec, 0x80, 0x0A, tmp);
7045 dspio_set_uint_param_no_source(codec, 0x80, 0x0B, tmp);
7047 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7049 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7051 dspio_set_uint_param_no_source(codec, 0x80, 0x0C, tmp);
7060 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec *codec)
7062 struct ca0132_spec *spec = codec->spec;
7065 chipio_set_stream_control(codec, 0x03, 0);
7066 chipio_set_stream_control(codec, 0x04, 0);
7068 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7069 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7072 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7074 chipio_set_stream_control(codec, 0x03, 1);
7075 chipio_set_stream_control(codec, 0x04, 1);
7077 switch (ca0132_quirk(spec)) {
7079 chipio_write(codec, 0x18b098, 0x0000000c);
7080 chipio_write(codec, 0x18b09C, 0x0000000c);
7083 chipio_write(codec, 0x18b098, 0x0000000c);
7084 chipio_write(codec, 0x18b09c, 0x0000004c);
7091 static void ae5_post_dsp_register_set(struct hda_codec *codec)
7093 struct ca0132_spec *spec = codec->spec;
7095 chipio_8051_write_direct(codec, 0x93, 0x10);
7096 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7097 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
7098 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7099 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
7101 writeb(0xff, spec->mem_base + 0x304);
7102 writeb(0xff, spec->mem_base + 0x304);
7103 writeb(0xff, spec->mem_base + 0x304);
7104 writeb(0xff, spec->mem_base + 0x304);
7105 writeb(0x00, spec->mem_base + 0x100);
7106 writeb(0xff, spec->mem_base + 0x304);
7107 writeb(0x00, spec->mem_base + 0x100);
7108 writeb(0xff, spec->mem_base + 0x304);
7109 writeb(0x00, spec->mem_base + 0x100);
7110 writeb(0xff, spec->mem_base + 0x304);
7111 writeb(0x00, spec->mem_base + 0x100);
7112 writeb(0xff, spec->mem_base + 0x304);
7114 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x3f);
7115 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
7116 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7119 static void ae5_post_dsp_param_setup(struct hda_codec *codec)
7122 * Param3 in the 8051's memory is represented by the ascii string 'mch'
7123 * which seems to be 'multichannel'. This is also mentioned in the
7124 * AE-5's registry values in Windows.
7126 chipio_set_control_param(codec, 3, 0);
7128 * I believe ASI is 'audio serial interface' and that it's used to
7129 * change colors on the external LED strip connected to the AE-5.
7131 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
7133 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
7134 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7136 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7137 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x92);
7138 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7139 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0xfa);
7140 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7141 VENDOR_CHIPIO_8051_DATA_WRITE, 0x22);
7144 static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
7146 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7147 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x41);
7148 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7149 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc8);
7151 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7152 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x45);
7153 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7154 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcc);
7156 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7157 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x40);
7158 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7159 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xcb);
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 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7167 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x51);
7168 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7169 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x8d);
7172 static void ae5_post_dsp_stream_setup(struct hda_codec *codec)
7174 struct ca0132_spec *spec = codec->spec;
7176 mutex_lock(&spec->chipio_mutex);
7178 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7180 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7182 chipio_set_stream_channels(codec, 0x0C, 6);
7183 chipio_set_stream_control(codec, 0x0C, 1);
7185 chipio_set_stream_source_dest(codec, 0x5, 0x43, 0x0);
7187 chipio_set_stream_source_dest(codec, 0x18, 0x9, 0xd0);
7188 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7189 chipio_set_stream_channels(codec, 0x18, 6);
7190 chipio_set_stream_control(codec, 0x18, 1);
7192 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7194 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7195 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x43);
7196 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
7197 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc7);
7199 ca0113_mmio_command_set(codec, 0x48, 0x01, 0x80);
7201 mutex_unlock(&spec->chipio_mutex);
7204 static void ae5_post_dsp_startup_data(struct hda_codec *codec)
7206 struct ca0132_spec *spec = codec->spec;
7208 mutex_lock(&spec->chipio_mutex);
7210 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
7211 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
7212 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
7213 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
7215 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7216 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
7217 ca0113_mmio_command_set(codec, 0x48, 0x0b, 0x12);
7218 ca0113_mmio_command_set(codec, 0x48, 0x04, 0x00);
7219 ca0113_mmio_command_set(codec, 0x48, 0x06, 0x48);
7220 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7221 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7222 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7223 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7224 ca0113_mmio_gpio_set(codec, 0, true);
7225 ca0113_mmio_gpio_set(codec, 1, true);
7226 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x80);
7228 chipio_write_no_mutex(codec, 0x18b03c, 0x00000012);
7230 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7231 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7233 mutex_unlock(&spec->chipio_mutex);
7237 * Setup default parameters for DSP
7239 static void ca0132_setup_defaults(struct hda_codec *codec)
7241 struct ca0132_spec *spec = codec->spec;
7246 if (spec->dsp_state != DSP_DOWNLOADED)
7249 /* out, in effects + voicefx */
7250 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7251 for (idx = 0; idx < num_fx; idx++) {
7252 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7253 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
7254 ca0132_effects[idx].reqs[i],
7255 ca0132_effects[idx].def_vals[i]);
7259 /*remove DSP headroom*/
7261 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7263 /*set speaker EQ bypass attenuation*/
7264 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
7266 /* set AMic1 and AMic2 as mono mic */
7268 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7269 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
7271 /* set AMic1 as CrystalVoice input */
7273 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
7275 /* set WUH source */
7277 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7281 * Setup default parameters for Recon3D/Recon3Di DSP.
7284 static void r3d_setup_defaults(struct hda_codec *codec)
7286 struct ca0132_spec *spec = codec->spec;
7291 if (spec->dsp_state != DSP_DOWNLOADED)
7294 ca0132_alt_dsp_scp_startup(codec);
7295 ca0132_alt_init_analog_mics(codec);
7297 /*remove DSP headroom*/
7299 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7301 /* set WUH source */
7303 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7304 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7306 /* Set speaker source? */
7307 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7309 if (ca0132_quirk(spec) == QUIRK_R3DI)
7310 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
7312 /* Setup effect defaults */
7313 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7314 for (idx = 0; idx < num_fx; idx++) {
7315 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7316 dspio_set_uint_param(codec,
7317 ca0132_effects[idx].mid,
7318 ca0132_effects[idx].reqs[i],
7319 ca0132_effects[idx].def_vals[i]);
7325 * Setup default parameters for the Sound Blaster Z DSP. A lot more going on
7326 * than the Chromebook setup.
7328 static void sbz_setup_defaults(struct hda_codec *codec)
7330 struct ca0132_spec *spec = codec->spec;
7335 if (spec->dsp_state != DSP_DOWNLOADED)
7338 ca0132_alt_dsp_scp_startup(codec);
7339 ca0132_alt_init_analog_mics(codec);
7340 sbz_connect_streams(codec);
7341 sbz_chipio_startup_data(codec);
7343 chipio_set_stream_control(codec, 0x03, 1);
7344 chipio_set_stream_control(codec, 0x04, 1);
7347 * Sets internal input loopback to off, used to have a switch to
7348 * enable input loopback, but turned out to be way too buggy.
7351 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
7352 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
7354 /*remove DSP headroom*/
7356 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7358 /* set WUH source */
7360 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7361 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7363 /* Set speaker source? */
7364 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7366 ca0132_alt_dsp_initial_mic_setup(codec);
7368 /* out, in effects + voicefx */
7369 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7370 for (idx = 0; idx < num_fx; idx++) {
7371 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7372 dspio_set_uint_param(codec,
7373 ca0132_effects[idx].mid,
7374 ca0132_effects[idx].reqs[i],
7375 ca0132_effects[idx].def_vals[i]);
7379 ca0132_alt_create_dummy_stream(codec);
7383 * Setup default parameters for the Sound BlasterX AE-5 DSP.
7385 static void ae5_setup_defaults(struct hda_codec *codec)
7387 struct ca0132_spec *spec = codec->spec;
7392 if (spec->dsp_state != DSP_DOWNLOADED)
7395 ca0132_alt_dsp_scp_startup(codec);
7396 ca0132_alt_init_analog_mics(codec);
7397 chipio_set_stream_control(codec, 0x03, 1);
7398 chipio_set_stream_control(codec, 0x04, 1);
7400 /* New, unknown SCP req's */
7402 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
7403 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
7404 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
7405 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
7407 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
7408 ca0113_mmio_gpio_set(codec, 0, false);
7409 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
7411 /* Internal loopback off */
7413 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
7414 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
7416 /*remove DSP headroom*/
7418 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
7420 /* set WUH source */
7422 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
7423 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7425 /* Set speaker source? */
7426 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
7428 ca0132_alt_dsp_initial_mic_setup(codec);
7429 ae5_post_dsp_register_set(codec);
7430 ae5_post_dsp_param_setup(codec);
7431 ae5_post_dsp_pll_setup(codec);
7432 ae5_post_dsp_stream_setup(codec);
7433 ae5_post_dsp_startup_data(codec);
7435 /* out, in effects + voicefx */
7436 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
7437 for (idx = 0; idx < num_fx; idx++) {
7438 for (i = 0; i <= ca0132_effects[idx].params; i++) {
7439 dspio_set_uint_param(codec,
7440 ca0132_effects[idx].mid,
7441 ca0132_effects[idx].reqs[i],
7442 ca0132_effects[idx].def_vals[i]);
7446 ca0132_alt_create_dummy_stream(codec);
7450 * Initialization of flags in chip
7452 static void ca0132_init_flags(struct hda_codec *codec)
7454 struct ca0132_spec *spec = codec->spec;
7456 if (ca0132_use_alt_functions(spec)) {
7457 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
7458 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
7459 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
7460 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
7461 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
7462 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
7463 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
7464 chipio_set_control_flag(codec,
7465 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
7466 chipio_set_control_flag(codec,
7467 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 1);
7469 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
7470 chipio_set_control_flag(codec,
7471 CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
7472 chipio_set_control_flag(codec,
7473 CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
7474 chipio_set_control_flag(codec,
7475 CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
7476 chipio_set_control_flag(codec,
7477 CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
7478 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
7483 * Initialization of parameters in chip
7485 static void ca0132_init_params(struct hda_codec *codec)
7487 struct ca0132_spec *spec = codec->spec;
7489 if (ca0132_use_alt_functions(spec)) {
7490 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7491 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
7492 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
7493 chipio_set_control_param(codec, 0, 0);
7494 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
7497 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
7498 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
7501 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
7503 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
7504 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
7505 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
7506 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
7507 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
7508 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
7510 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7511 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7512 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
7515 static bool ca0132_download_dsp_images(struct hda_codec *codec)
7517 bool dsp_loaded = false;
7518 struct ca0132_spec *spec = codec->spec;
7519 const struct dsp_image_seg *dsp_os_image;
7520 const struct firmware *fw_entry = NULL;
7522 * Alternate firmwares for different variants. The Recon3Di apparently
7523 * can use the default firmware, but I'll leave the option in case
7524 * it needs it again.
7526 switch (ca0132_quirk(spec)) {
7530 if (request_firmware(&fw_entry, DESKTOP_EFX_FILE,
7531 codec->card->dev) != 0)
7532 codec_dbg(codec, "Desktop firmware not found.");
7534 codec_dbg(codec, "Desktop firmware selected.");
7537 if (request_firmware(&fw_entry, R3DI_EFX_FILE,
7538 codec->card->dev) != 0)
7539 codec_dbg(codec, "Recon3Di alt firmware not detected.");
7541 codec_dbg(codec, "Recon3Di firmware selected.");
7547 * Use default ctefx.bin if no alt firmware is detected, or if none
7548 * exists for your particular codec.
7551 codec_dbg(codec, "Default firmware selected.");
7552 if (request_firmware(&fw_entry, EFX_FILE,
7553 codec->card->dev) != 0)
7557 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
7558 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
7559 codec_err(codec, "ca0132 DSP load image failed\n");
7563 dsp_loaded = dspload_wait_loaded(codec);
7566 release_firmware(fw_entry);
7571 static void ca0132_download_dsp(struct hda_codec *codec)
7573 struct ca0132_spec *spec = codec->spec;
7575 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
7579 if (spec->dsp_state == DSP_DOWNLOAD_FAILED)
7580 return; /* don't retry failures */
7582 chipio_enable_clocks(codec);
7583 if (spec->dsp_state != DSP_DOWNLOADED) {
7584 spec->dsp_state = DSP_DOWNLOADING;
7586 if (!ca0132_download_dsp_images(codec))
7587 spec->dsp_state = DSP_DOWNLOAD_FAILED;
7589 spec->dsp_state = DSP_DOWNLOADED;
7592 /* For codecs using alt functions, this is already done earlier */
7593 if (spec->dsp_state == DSP_DOWNLOADED && !ca0132_use_alt_functions(spec))
7594 ca0132_set_dsp_msr(codec, true);
7597 static void ca0132_process_dsp_response(struct hda_codec *codec,
7598 struct hda_jack_callback *callback)
7600 struct ca0132_spec *spec = codec->spec;
7602 codec_dbg(codec, "ca0132_process_dsp_response\n");
7603 if (spec->wait_scp) {
7604 if (dspio_get_response_data(codec) >= 0)
7608 dspio_clear_response_queue(codec);
7611 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
7613 struct ca0132_spec *spec = codec->spec;
7614 struct hda_jack_tbl *tbl;
7616 /* Delay enabling the HP amp, to let the mic-detection
7617 * state machine run.
7619 cancel_delayed_work_sync(&spec->unsol_hp_work);
7620 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
7621 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
7623 tbl->block_report = 1;
7626 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
7628 struct ca0132_spec *spec = codec->spec;
7630 if (ca0132_use_alt_functions(spec))
7631 ca0132_alt_select_in(codec);
7633 ca0132_select_mic(codec);
7636 static void ca0132_init_unsol(struct hda_codec *codec)
7638 struct ca0132_spec *spec = codec->spec;
7639 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
7640 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
7642 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
7643 ca0132_process_dsp_response);
7644 /* Front headphone jack detection */
7645 if (ca0132_use_alt_functions(spec))
7646 snd_hda_jack_detect_enable_callback(codec,
7647 spec->unsol_tag_front_hp, hp_callback);
7654 /* Sends before DSP download. */
7655 static struct hda_verb ca0132_base_init_verbs[] = {
7656 /*enable ct extension*/
7657 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
7662 static struct hda_verb ca0132_base_exit_verbs[] = {
7664 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
7665 /*disable ct extension*/
7666 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
7670 /* Other verbs tables. Sends after DSP download. */
7672 static struct hda_verb ca0132_init_verbs0[] = {
7673 /* chip init verbs */
7674 {0x15, 0x70D, 0xF0},
7675 {0x15, 0x70E, 0xFE},
7676 {0x15, 0x707, 0x75},
7677 {0x15, 0x707, 0xD3},
7678 {0x15, 0x707, 0x09},
7679 {0x15, 0x707, 0x53},
7680 {0x15, 0x707, 0xD4},
7681 {0x15, 0x707, 0xEF},
7682 {0x15, 0x707, 0x75},
7683 {0x15, 0x707, 0xD3},
7684 {0x15, 0x707, 0x09},
7685 {0x15, 0x707, 0x02},
7686 {0x15, 0x707, 0x37},
7687 {0x15, 0x707, 0x78},
7688 {0x15, 0x53C, 0xCE},
7689 {0x15, 0x575, 0xC9},
7690 {0x15, 0x53D, 0xCE},
7691 {0x15, 0x5B7, 0xC9},
7692 {0x15, 0x70D, 0xE8},
7693 {0x15, 0x70E, 0xFE},
7694 {0x15, 0x707, 0x02},
7695 {0x15, 0x707, 0x68},
7696 {0x15, 0x707, 0x62},
7697 {0x15, 0x53A, 0xCE},
7698 {0x15, 0x546, 0xC9},
7699 {0x15, 0x53B, 0xCE},
7700 {0x15, 0x5E8, 0xC9},
7704 /* Extra init verbs for desktop cards. */
7705 static struct hda_verb ca0132_init_verbs1[] = {
7706 {0x15, 0x70D, 0x20},
7707 {0x15, 0x70E, 0x19},
7708 {0x15, 0x707, 0x00},
7709 {0x15, 0x539, 0xCE},
7710 {0x15, 0x546, 0xC9},
7711 {0x15, 0x70D, 0xB7},
7712 {0x15, 0x70E, 0x09},
7713 {0x15, 0x707, 0x10},
7714 {0x15, 0x70D, 0xAF},
7715 {0x15, 0x70E, 0x09},
7716 {0x15, 0x707, 0x01},
7717 {0x15, 0x707, 0x05},
7718 {0x15, 0x70D, 0x73},
7719 {0x15, 0x70E, 0x09},
7720 {0x15, 0x707, 0x14},
7721 {0x15, 0x6FF, 0xC4},
7725 static void ca0132_init_chip(struct hda_codec *codec)
7727 struct ca0132_spec *spec = codec->spec;
7732 mutex_init(&spec->chipio_mutex);
7734 spec->cur_out_type = SPEAKER_OUT;
7735 if (!ca0132_use_alt_functions(spec))
7736 spec->cur_mic_type = DIGITAL_MIC;
7738 spec->cur_mic_type = REAR_MIC;
7740 spec->cur_mic_boost = 0;
7742 for (i = 0; i < VNODES_COUNT; i++) {
7743 spec->vnode_lvol[i] = 0x5a;
7744 spec->vnode_rvol[i] = 0x5a;
7745 spec->vnode_lswitch[i] = 0;
7746 spec->vnode_rswitch[i] = 0;
7750 * Default states for effects are in ca0132_effects[].
7752 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
7753 for (i = 0; i < num_fx; i++) {
7754 on = (unsigned int)ca0132_effects[i].reqs[0];
7755 spec->effects_switch[i] = on ? 1 : 0;
7758 * Sets defaults for the effect slider controls, only for alternative
7759 * ca0132 codecs. Also sets x-bass crossover frequency to 80hz.
7761 if (ca0132_use_alt_controls(spec)) {
7762 spec->xbass_xover_freq = 8;
7763 for (i = 0; i < EFFECT_LEVEL_SLIDERS; i++)
7764 spec->fx_ctl_val[i] = effect_slider_defaults[i];
7767 spec->voicefx_val = 0;
7768 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
7769 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
7772 * The ZxR doesn't have a front panel header, and it's line-in is on
7773 * the daughter board. So, there is no input enum control, and we need
7774 * to make sure that spec->in_enum_val is set properly.
7776 if (ca0132_quirk(spec) == QUIRK_ZXR)
7777 spec->in_enum_val = REAR_MIC;
7779 #ifdef ENABLE_TUNING_CONTROLS
7780 ca0132_init_tuning_defaults(codec);
7785 * Recon3Di exit specific commands.
7787 /* prevents popping noise on shutdown */
7788 static void r3di_gpio_shutdown(struct hda_codec *codec)
7790 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
7794 * Sound Blaster Z exit specific commands.
7796 static void sbz_region2_exit(struct hda_codec *codec)
7798 struct ca0132_spec *spec = codec->spec;
7801 for (i = 0; i < 4; i++)
7802 writeb(0x0, spec->mem_base + 0x100);
7803 for (i = 0; i < 8; i++)
7804 writeb(0xb3, spec->mem_base + 0x304);
7806 ca0113_mmio_gpio_set(codec, 0, false);
7807 ca0113_mmio_gpio_set(codec, 1, false);
7808 ca0113_mmio_gpio_set(codec, 4, true);
7809 ca0113_mmio_gpio_set(codec, 5, false);
7810 ca0113_mmio_gpio_set(codec, 7, false);
7813 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
7815 hda_nid_t pins[5] = {0x0B, 0x0C, 0x0E, 0x12, 0x13};
7818 snd_hda_codec_write(codec, 0x11, 0,
7819 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40);
7821 for (i = 0; i < 5; i++)
7822 snd_hda_codec_write(codec, pins[i], 0,
7823 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00);
7826 static void ca0132_clear_unsolicited(struct hda_codec *codec)
7828 hda_nid_t pins[7] = {0x0B, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
7831 for (i = 0; i < 7; i++) {
7832 snd_hda_codec_write(codec, pins[i], 0,
7833 AC_VERB_SET_UNSOLICITED_ENABLE, 0x00);
7837 /* On shutdown, sends commands in sets of three */
7838 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
7842 snd_hda_codec_write(codec, 0x01, 0,
7843 AC_VERB_SET_GPIO_DIRECTION, dir);
7845 snd_hda_codec_write(codec, 0x01, 0,
7846 AC_VERB_SET_GPIO_MASK, mask);
7849 snd_hda_codec_write(codec, 0x01, 0,
7850 AC_VERB_SET_GPIO_DATA, data);
7853 static void zxr_dbpro_power_state_shutdown(struct hda_codec *codec)
7855 hda_nid_t pins[7] = {0x05, 0x0c, 0x09, 0x0e, 0x08, 0x11, 0x01};
7858 for (i = 0; i < 7; i++)
7859 snd_hda_codec_write(codec, pins[i], 0,
7860 AC_VERB_SET_POWER_STATE, 0x03);
7863 static void sbz_exit_chip(struct hda_codec *codec)
7865 chipio_set_stream_control(codec, 0x03, 0);
7866 chipio_set_stream_control(codec, 0x04, 0);
7868 /* Mess with GPIO */
7869 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
7870 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
7871 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
7873 chipio_set_stream_control(codec, 0x14, 0);
7874 chipio_set_stream_control(codec, 0x0C, 0);
7876 chipio_set_conn_rate(codec, 0x41, SR_192_000);
7877 chipio_set_conn_rate(codec, 0x91, SR_192_000);
7879 chipio_write(codec, 0x18a020, 0x00000083);
7881 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
7882 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
7883 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
7885 chipio_set_stream_control(codec, 0x0C, 0);
7887 chipio_set_control_param(codec, 0x0D, 0x24);
7889 ca0132_clear_unsolicited(codec);
7890 sbz_set_pin_ctl_default(codec);
7892 snd_hda_codec_write(codec, 0x0B, 0,
7893 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
7895 sbz_region2_exit(codec);
7898 static void r3d_exit_chip(struct hda_codec *codec)
7900 ca0132_clear_unsolicited(codec);
7901 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7902 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
7905 static void ae5_exit_chip(struct hda_codec *codec)
7907 chipio_set_stream_control(codec, 0x03, 0);
7908 chipio_set_stream_control(codec, 0x04, 0);
7910 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
7911 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7912 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7913 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
7914 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
7915 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x00);
7916 ca0113_mmio_gpio_set(codec, 0, false);
7917 ca0113_mmio_gpio_set(codec, 1, false);
7919 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7920 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
7922 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7924 chipio_set_stream_control(codec, 0x18, 0);
7925 chipio_set_stream_control(codec, 0x0c, 0);
7927 snd_hda_codec_write(codec, 0x01, 0, 0x724, 0x83);
7930 static void zxr_exit_chip(struct hda_codec *codec)
7932 chipio_set_stream_control(codec, 0x03, 0);
7933 chipio_set_stream_control(codec, 0x04, 0);
7934 chipio_set_stream_control(codec, 0x14, 0);
7935 chipio_set_stream_control(codec, 0x0C, 0);
7937 chipio_set_conn_rate(codec, 0x41, SR_192_000);
7938 chipio_set_conn_rate(codec, 0x91, SR_192_000);
7940 chipio_write(codec, 0x18a020, 0x00000083);
7942 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
7943 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
7945 ca0132_clear_unsolicited(codec);
7946 sbz_set_pin_ctl_default(codec);
7947 snd_hda_codec_write(codec, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x00);
7949 ca0113_mmio_gpio_set(codec, 5, false);
7950 ca0113_mmio_gpio_set(codec, 2, false);
7951 ca0113_mmio_gpio_set(codec, 3, false);
7952 ca0113_mmio_gpio_set(codec, 0, false);
7953 ca0113_mmio_gpio_set(codec, 4, true);
7954 ca0113_mmio_gpio_set(codec, 0, true);
7955 ca0113_mmio_gpio_set(codec, 5, true);
7956 ca0113_mmio_gpio_set(codec, 2, false);
7957 ca0113_mmio_gpio_set(codec, 3, false);
7960 static void ca0132_exit_chip(struct hda_codec *codec)
7962 /* put any chip cleanup stuffs here. */
7964 if (dspload_is_loaded(codec))
7969 * This fixes a problem that was hard to reproduce. Very rarely, I would
7970 * boot up, and there would be no sound, but the DSP indicated it had loaded
7971 * properly. I did a few memory dumps to see if anything was different, and
7972 * there were a few areas of memory uninitialized with a1a2a3a4. This function
7973 * checks if those areas are uninitialized, and if they are, it'll attempt to
7974 * reload the card 3 times. Usually it fixes by the second.
7976 static void sbz_dsp_startup_check(struct hda_codec *codec)
7978 struct ca0132_spec *spec = codec->spec;
7979 unsigned int dsp_data_check[4];
7980 unsigned int cur_address = 0x390;
7982 unsigned int failure = 0;
7983 unsigned int reload = 3;
7985 if (spec->startup_check_entered)
7988 spec->startup_check_entered = true;
7990 for (i = 0; i < 4; i++) {
7991 chipio_read(codec, cur_address, &dsp_data_check[i]);
7994 for (i = 0; i < 4; i++) {
7995 if (dsp_data_check[i] == 0xa1a2a3a4)
7999 codec_dbg(codec, "Startup Check: %d ", failure);
8001 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
8003 * While the failure condition is true, and we haven't reached our
8004 * three reload limit, continue trying to reload the driver and
8007 while (failure && (reload != 0)) {
8008 codec_info(codec, "Reloading... Tries left: %d", reload);
8009 sbz_exit_chip(codec);
8010 spec->dsp_state = DSP_DOWNLOAD_INIT;
8011 codec->patch_ops.init(codec);
8013 for (i = 0; i < 4; i++) {
8014 chipio_read(codec, cur_address, &dsp_data_check[i]);
8017 for (i = 0; i < 4; i++) {
8018 if (dsp_data_check[i] == 0xa1a2a3a4)
8024 if (!failure && reload < 3)
8025 codec_info(codec, "DSP fixed.");
8030 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
8034 * This is for the extra volume verbs 0x797 (left) and 0x798 (right). These add
8035 * extra precision for decibel values. If you had the dB value in floating point
8036 * you would take the value after the decimal point, multiply by 64, and divide
8037 * by 2. So for 8.59, it's (59 * 64) / 100. Useful if someone wanted to
8038 * implement fixed point or floating point dB volumes. For now, I'll set them
8039 * to 0 just incase a value has lingered from a boot into Windows.
8041 static void ca0132_alt_vol_setup(struct hda_codec *codec)
8043 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
8044 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
8045 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
8046 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
8047 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
8048 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
8049 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
8050 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
8054 * Extra commands that don't really fit anywhere else.
8056 static void sbz_pre_dsp_setup(struct hda_codec *codec)
8058 struct ca0132_spec *spec = codec->spec;
8060 writel(0x00820680, spec->mem_base + 0x01C);
8061 writel(0x00820680, spec->mem_base + 0x01C);
8063 chipio_write(codec, 0x18b0a4, 0x000000c2);
8065 snd_hda_codec_write(codec, 0x11, 0,
8066 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
8069 static void r3d_pre_dsp_setup(struct hda_codec *codec)
8071 chipio_write(codec, 0x18b0a4, 0x000000c2);
8073 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8074 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
8075 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8076 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
8077 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8078 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
8080 snd_hda_codec_write(codec, 0x11, 0,
8081 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
8084 static void r3di_pre_dsp_setup(struct hda_codec *codec)
8086 chipio_write(codec, 0x18b0a4, 0x000000c2);
8088 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8089 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
8090 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8091 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
8092 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8093 VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
8095 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8096 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
8097 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8098 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
8099 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8100 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
8101 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8102 VENDOR_CHIPIO_8051_DATA_WRITE, 0x40);
8104 snd_hda_codec_write(codec, 0x11, 0,
8105 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
8109 * These are sent before the DSP is downloaded. Not sure
8110 * what they do, or if they're necessary. Could possibly
8111 * be removed. Figure they're better to leave in.
8113 static void ca0132_mmio_init(struct hda_codec *codec)
8115 struct ca0132_spec *spec = codec->spec;
8117 if (ca0132_quirk(spec) == QUIRK_AE5)
8118 writel(0x00000001, spec->mem_base + 0x400);
8120 writel(0x00000000, spec->mem_base + 0x400);
8122 if (ca0132_quirk(spec) == QUIRK_AE5)
8123 writel(0x00000001, spec->mem_base + 0x408);
8125 writel(0x00000000, spec->mem_base + 0x408);
8127 if (ca0132_quirk(spec) == QUIRK_AE5)
8128 writel(0x00000001, spec->mem_base + 0x40c);
8130 writel(0x00000000, spec->mem_base + 0x40C);
8132 if (ca0132_quirk(spec) == QUIRK_ZXR)
8133 writel(0x00880640, spec->mem_base + 0x01C);
8135 writel(0x00880680, spec->mem_base + 0x01C);
8137 if (ca0132_quirk(spec) == QUIRK_AE5)
8138 writel(0x00000080, spec->mem_base + 0xC0C);
8140 writel(0x00000083, spec->mem_base + 0xC0C);
8142 writel(0x00000030, spec->mem_base + 0xC00);
8143 writel(0x00000000, spec->mem_base + 0xC04);
8145 if (ca0132_quirk(spec) == QUIRK_AE5)
8146 writel(0x00000000, spec->mem_base + 0xC0C);
8148 writel(0x00000003, spec->mem_base + 0xC0C);
8150 writel(0x00000003, spec->mem_base + 0xC0C);
8151 writel(0x00000003, spec->mem_base + 0xC0C);
8152 writel(0x00000003, spec->mem_base + 0xC0C);
8154 if (ca0132_quirk(spec) == QUIRK_AE5)
8155 writel(0x00000001, spec->mem_base + 0xC08);
8157 writel(0x000000C1, spec->mem_base + 0xC08);
8159 writel(0x000000F1, spec->mem_base + 0xC08);
8160 writel(0x00000001, spec->mem_base + 0xC08);
8161 writel(0x000000C7, spec->mem_base + 0xC08);
8162 writel(0x000000C1, spec->mem_base + 0xC08);
8163 writel(0x00000080, spec->mem_base + 0xC04);
8165 if (ca0132_quirk(spec) == QUIRK_AE5) {
8166 writel(0x00000000, spec->mem_base + 0x42c);
8167 writel(0x00000000, spec->mem_base + 0x46c);
8168 writel(0x00000000, spec->mem_base + 0x4ac);
8169 writel(0x00000000, spec->mem_base + 0x4ec);
8170 writel(0x00000000, spec->mem_base + 0x43c);
8171 writel(0x00000000, spec->mem_base + 0x47c);
8172 writel(0x00000000, spec->mem_base + 0x4bc);
8173 writel(0x00000000, spec->mem_base + 0x4fc);
8174 writel(0x00000600, spec->mem_base + 0x100);
8175 writel(0x00000014, spec->mem_base + 0x410);
8176 writel(0x0000060f, spec->mem_base + 0x100);
8177 writel(0x0000070f, spec->mem_base + 0x100);
8178 writel(0x00000aff, spec->mem_base + 0x830);
8179 writel(0x00000000, spec->mem_base + 0x86c);
8180 writel(0x0000006b, spec->mem_base + 0x800);
8181 writel(0x00000001, spec->mem_base + 0x86c);
8182 writel(0x0000006b, spec->mem_base + 0x800);
8183 writel(0x00000057, spec->mem_base + 0x804);
8184 writel(0x00800000, spec->mem_base + 0x20c);
8189 * This function writes to some SFR's, does some region2 writes, and then
8190 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
8193 static void ae5_register_set(struct hda_codec *codec)
8195 struct ca0132_spec *spec = codec->spec;
8197 chipio_8051_write_direct(codec, 0x93, 0x10);
8198 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8199 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x44);
8200 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8201 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xc2);
8203 writeb(0x0f, spec->mem_base + 0x304);
8204 writeb(0x0f, spec->mem_base + 0x304);
8205 writeb(0x0f, spec->mem_base + 0x304);
8206 writeb(0x0f, spec->mem_base + 0x304);
8207 writeb(0x0e, spec->mem_base + 0x100);
8208 writeb(0x1f, spec->mem_base + 0x304);
8209 writeb(0x0c, spec->mem_base + 0x100);
8210 writeb(0x3f, spec->mem_base + 0x304);
8211 writeb(0x08, spec->mem_base + 0x100);
8212 writeb(0x7f, spec->mem_base + 0x304);
8213 writeb(0x00, spec->mem_base + 0x100);
8214 writeb(0xff, spec->mem_base + 0x304);
8216 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
8218 chipio_8051_write_direct(codec, 0x90, 0x00);
8219 chipio_8051_write_direct(codec, 0x90, 0x10);
8221 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8223 chipio_write(codec, 0x18b0a4, 0x000000c2);
8225 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
8226 snd_hda_codec_write(codec, 0x01, 0, 0x7ff, 0x00);
8230 * Extra init functions for alternative ca0132 codecs. Done
8231 * here so they don't clutter up the main ca0132_init function
8232 * anymore than they have to.
8234 static void ca0132_alt_init(struct hda_codec *codec)
8236 struct ca0132_spec *spec = codec->spec;
8238 ca0132_alt_vol_setup(codec);
8240 switch (ca0132_quirk(spec)) {
8242 codec_dbg(codec, "SBZ alt_init");
8243 ca0132_gpio_init(codec);
8244 sbz_pre_dsp_setup(codec);
8245 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8246 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8249 codec_dbg(codec, "R3DI alt_init");
8250 ca0132_gpio_init(codec);
8251 ca0132_gpio_setup(codec);
8252 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
8253 r3di_pre_dsp_setup(codec);
8254 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8255 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
8258 r3d_pre_dsp_setup(codec);
8259 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8260 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8263 ca0132_gpio_init(codec);
8264 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8265 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x49);
8266 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8267 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x88);
8268 chipio_write(codec, 0x18b030, 0x00000020);
8269 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8270 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8271 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8274 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8275 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
8282 static int ca0132_init(struct hda_codec *codec)
8284 struct ca0132_spec *spec = codec->spec;
8285 struct auto_pin_cfg *cfg = &spec->autocfg;
8290 * If the DSP is already downloaded, and init has been entered again,
8291 * there's only two reasons for it. One, the codec has awaken from a
8292 * suspended state, and in that case dspload_is_loaded will return
8293 * false, and the init will be ran again. The other reason it gets
8294 * re entered is on startup for some reason it triggers a suspend and
8295 * resume state. In this case, it will check if the DSP is downloaded,
8296 * and not run the init function again. For codecs using alt_functions,
8297 * it will check if the DSP is loaded properly.
8299 if (spec->dsp_state == DSP_DOWNLOADED) {
8300 dsp_loaded = dspload_is_loaded(codec);
8302 spec->dsp_reload = true;
8303 spec->dsp_state = DSP_DOWNLOAD_INIT;
8305 if (ca0132_quirk(spec) == QUIRK_SBZ)
8306 sbz_dsp_startup_check(codec);
8311 if (spec->dsp_state != DSP_DOWNLOAD_FAILED)
8312 spec->dsp_state = DSP_DOWNLOAD_INIT;
8313 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
8315 if (ca0132_use_pci_mmio(spec))
8316 ca0132_mmio_init(codec);
8318 snd_hda_power_up_pm(codec);
8320 if (ca0132_quirk(spec) == QUIRK_AE5)
8321 ae5_register_set(codec);
8323 ca0132_init_unsol(codec);
8324 ca0132_init_params(codec);
8325 ca0132_init_flags(codec);
8327 snd_hda_sequence_write(codec, spec->base_init_verbs);
8329 if (ca0132_use_alt_functions(spec))
8330 ca0132_alt_init(codec);
8332 ca0132_download_dsp(codec);
8334 ca0132_refresh_widget_caps(codec);
8336 switch (ca0132_quirk(spec)) {
8339 r3d_setup_defaults(codec);
8343 sbz_setup_defaults(codec);
8346 ae5_setup_defaults(codec);
8349 ca0132_setup_defaults(codec);
8350 ca0132_init_analog_mic2(codec);
8351 ca0132_init_dmic(codec);
8355 for (i = 0; i < spec->num_outputs; i++)
8356 init_output(codec, spec->out_pins[i], spec->dacs[0]);
8358 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
8360 for (i = 0; i < spec->num_inputs; i++)
8361 init_input(codec, spec->input_pins[i], spec->adcs[i]);
8363 init_input(codec, cfg->dig_in_pin, spec->dig_in);
8365 if (!ca0132_use_alt_functions(spec)) {
8366 snd_hda_sequence_write(codec, spec->chip_init_verbs);
8367 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8368 VENDOR_CHIPIO_PARAM_EX_ID_SET, 0x0D);
8369 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
8370 VENDOR_CHIPIO_PARAM_EX_VALUE_SET, 0x20);
8373 if (ca0132_quirk(spec) == QUIRK_SBZ)
8374 ca0132_gpio_setup(codec);
8376 snd_hda_sequence_write(codec, spec->spec_init_verbs);
8377 if (ca0132_use_alt_functions(spec)) {
8378 ca0132_alt_select_out(codec);
8379 ca0132_alt_select_in(codec);
8381 ca0132_select_out(codec);
8382 ca0132_select_mic(codec);
8385 snd_hda_jack_report_sync(codec);
8388 * Re set the PlayEnhancement switch on a resume event, because the
8389 * controls will not be reloaded.
8391 if (spec->dsp_reload) {
8392 spec->dsp_reload = false;
8393 ca0132_pe_switch_set(codec);
8396 snd_hda_power_down_pm(codec);
8401 static int dbpro_init(struct hda_codec *codec)
8403 struct ca0132_spec *spec = codec->spec;
8404 struct auto_pin_cfg *cfg = &spec->autocfg;
8407 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
8408 init_input(codec, cfg->dig_in_pin, spec->dig_in);
8410 for (i = 0; i < spec->num_inputs; i++)
8411 init_input(codec, spec->input_pins[i], spec->adcs[i]);
8416 static void ca0132_free(struct hda_codec *codec)
8418 struct ca0132_spec *spec = codec->spec;
8420 cancel_delayed_work_sync(&spec->unsol_hp_work);
8421 snd_hda_power_up(codec);
8422 switch (ca0132_quirk(spec)) {
8424 sbz_exit_chip(codec);
8427 zxr_exit_chip(codec);
8430 r3d_exit_chip(codec);
8433 ae5_exit_chip(codec);
8436 r3di_gpio_shutdown(codec);
8442 snd_hda_sequence_write(codec, spec->base_exit_verbs);
8443 ca0132_exit_chip(codec);
8445 snd_hda_power_down(codec);
8448 pci_iounmap(codec->bus->pci, spec->mem_base);
8450 kfree(spec->spec_init_verbs);
8454 static void dbpro_free(struct hda_codec *codec)
8456 struct ca0132_spec *spec = codec->spec;
8458 zxr_dbpro_power_state_shutdown(codec);
8460 kfree(spec->spec_init_verbs);
8464 static void ca0132_reboot_notify(struct hda_codec *codec)
8466 codec->patch_ops.free(codec);
8469 static const struct hda_codec_ops ca0132_patch_ops = {
8470 .build_controls = ca0132_build_controls,
8471 .build_pcms = ca0132_build_pcms,
8472 .init = ca0132_init,
8473 .free = ca0132_free,
8474 .unsol_event = snd_hda_jack_unsol_event,
8475 .reboot_notify = ca0132_reboot_notify,
8478 static const struct hda_codec_ops dbpro_patch_ops = {
8479 .build_controls = dbpro_build_controls,
8480 .build_pcms = dbpro_build_pcms,
8485 static void ca0132_config(struct hda_codec *codec)
8487 struct ca0132_spec *spec = codec->spec;
8489 spec->dacs[0] = 0x2;
8490 spec->dacs[1] = 0x3;
8491 spec->dacs[2] = 0x4;
8493 spec->multiout.dac_nids = spec->dacs;
8494 spec->multiout.num_dacs = 3;
8496 if (!ca0132_use_alt_functions(spec))
8497 spec->multiout.max_channels = 2;
8499 spec->multiout.max_channels = 6;
8501 switch (ca0132_quirk(spec)) {
8502 case QUIRK_ALIENWARE:
8503 codec_dbg(codec, "%s: QUIRK_ALIENWARE applied.\n", __func__);
8504 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
8507 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
8508 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
8511 codec_dbg(codec, "%s: QUIRK_ZXR applied.\n", __func__);
8512 snd_hda_apply_pincfgs(codec, zxr_pincfgs);
8515 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
8516 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
8519 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
8520 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
8523 codec_dbg(codec, "%s: QUIRK_AE5 applied.\n", __func__);
8524 snd_hda_apply_pincfgs(codec, ae5_pincfgs);
8530 switch (ca0132_quirk(spec)) {
8531 case QUIRK_ALIENWARE:
8532 spec->num_outputs = 2;
8533 spec->out_pins[0] = 0x0b; /* speaker out */
8534 spec->out_pins[1] = 0x0f;
8535 spec->shared_out_nid = 0x2;
8536 spec->unsol_tag_hp = 0x0f;
8538 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
8539 spec->adcs[1] = 0x8; /* analog mic2 */
8540 spec->adcs[2] = 0xa; /* what u hear */
8542 spec->num_inputs = 3;
8543 spec->input_pins[0] = 0x12;
8544 spec->input_pins[1] = 0x11;
8545 spec->input_pins[2] = 0x13;
8546 spec->shared_mic_nid = 0x7;
8547 spec->unsol_tag_amic1 = 0x11;
8551 spec->num_outputs = 2;
8552 spec->out_pins[0] = 0x0B; /* Line out */
8553 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8554 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8555 spec->out_pins[3] = 0x11; /* Rear surround */
8556 spec->shared_out_nid = 0x2;
8557 spec->unsol_tag_hp = spec->out_pins[1];
8558 spec->unsol_tag_front_hp = spec->out_pins[2];
8560 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8561 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
8562 spec->adcs[2] = 0xa; /* what u hear */
8564 spec->num_inputs = 2;
8565 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8566 spec->input_pins[1] = 0x13; /* What U Hear */
8567 spec->shared_mic_nid = 0x7;
8568 spec->unsol_tag_amic1 = spec->input_pins[0];
8571 spec->dig_out = 0x05;
8572 spec->multiout.dig_out_nid = spec->dig_out;
8573 spec->dig_in = 0x09;
8576 spec->num_outputs = 2;
8577 spec->out_pins[0] = 0x0B; /* Line out */
8578 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8579 spec->out_pins[2] = 0x10; /* Center/LFE */
8580 spec->out_pins[3] = 0x11; /* Rear surround */
8581 spec->shared_out_nid = 0x2;
8582 spec->unsol_tag_hp = spec->out_pins[1];
8583 spec->unsol_tag_front_hp = spec->out_pins[2];
8585 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8586 spec->adcs[1] = 0x8; /* Not connected, no front mic */
8587 spec->adcs[2] = 0xa; /* what u hear */
8589 spec->num_inputs = 2;
8590 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8591 spec->input_pins[1] = 0x13; /* What U Hear */
8592 spec->shared_mic_nid = 0x7;
8593 spec->unsol_tag_amic1 = spec->input_pins[0];
8595 case QUIRK_ZXR_DBPRO:
8596 spec->adcs[0] = 0x8; /* ZxR DBPro Aux In */
8598 spec->num_inputs = 1;
8599 spec->input_pins[0] = 0x11; /* RCA Line-in */
8601 spec->dig_out = 0x05;
8602 spec->multiout.dig_out_nid = spec->dig_out;
8604 spec->dig_in = 0x09;
8607 spec->num_outputs = 2;
8608 spec->out_pins[0] = 0x0B; /* Line out */
8609 spec->out_pins[1] = 0x11; /* Rear headphone out */
8610 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8611 spec->out_pins[3] = 0x0F; /* Rear surround */
8612 spec->shared_out_nid = 0x2;
8613 spec->unsol_tag_hp = spec->out_pins[1];
8614 spec->unsol_tag_front_hp = spec->out_pins[2];
8616 spec->adcs[0] = 0x7; /* Rear Mic / Line-in */
8617 spec->adcs[1] = 0x8; /* Front Mic, but only if no DSP */
8618 spec->adcs[2] = 0xa; /* what u hear */
8620 spec->num_inputs = 2;
8621 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8622 spec->input_pins[1] = 0x13; /* What U Hear */
8623 spec->shared_mic_nid = 0x7;
8624 spec->unsol_tag_amic1 = spec->input_pins[0];
8627 spec->dig_out = 0x05;
8628 spec->multiout.dig_out_nid = spec->dig_out;
8631 spec->num_outputs = 2;
8632 spec->out_pins[0] = 0x0B; /* Line out */
8633 spec->out_pins[1] = 0x0F; /* Rear headphone out */
8634 spec->out_pins[2] = 0x10; /* Front Headphone / Center/LFE*/
8635 spec->out_pins[3] = 0x11; /* Rear surround */
8636 spec->shared_out_nid = 0x2;
8637 spec->unsol_tag_hp = spec->out_pins[1];
8638 spec->unsol_tag_front_hp = spec->out_pins[2];
8640 spec->adcs[0] = 0x07; /* Rear Mic / Line-in */
8641 spec->adcs[1] = 0x08; /* Front Mic, but only if no DSP */
8642 spec->adcs[2] = 0x0a; /* what u hear */
8644 spec->num_inputs = 2;
8645 spec->input_pins[0] = 0x12; /* Rear Mic / Line-in */
8646 spec->input_pins[1] = 0x13; /* What U Hear */
8647 spec->shared_mic_nid = 0x7;
8648 spec->unsol_tag_amic1 = spec->input_pins[0];
8651 spec->dig_out = 0x05;
8652 spec->multiout.dig_out_nid = spec->dig_out;
8655 spec->num_outputs = 2;
8656 spec->out_pins[0] = 0x0b; /* speaker out */
8657 spec->out_pins[1] = 0x10; /* headphone out */
8658 spec->shared_out_nid = 0x2;
8659 spec->unsol_tag_hp = spec->out_pins[1];
8661 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
8662 spec->adcs[1] = 0x8; /* analog mic2 */
8663 spec->adcs[2] = 0xa; /* what u hear */
8665 spec->num_inputs = 3;
8666 spec->input_pins[0] = 0x12;
8667 spec->input_pins[1] = 0x11;
8668 spec->input_pins[2] = 0x13;
8669 spec->shared_mic_nid = 0x7;
8670 spec->unsol_tag_amic1 = spec->input_pins[0];
8673 spec->dig_out = 0x05;
8674 spec->multiout.dig_out_nid = spec->dig_out;
8675 spec->dig_in = 0x09;
8680 static int ca0132_prepare_verbs(struct hda_codec *codec)
8682 /* Verbs + terminator (an empty element) */
8683 #define NUM_SPEC_VERBS 2
8684 struct ca0132_spec *spec = codec->spec;
8686 spec->chip_init_verbs = ca0132_init_verbs0;
8688 * Since desktop cards use pci_mmio, this can be used to determine
8689 * whether or not to use these verbs instead of a separate bool.
8691 if (ca0132_use_pci_mmio(spec))
8692 spec->desktop_init_verbs = ca0132_init_verbs1;
8693 spec->spec_init_verbs = kcalloc(NUM_SPEC_VERBS,
8694 sizeof(struct hda_verb),
8696 if (!spec->spec_init_verbs)
8700 spec->spec_init_verbs[0].nid = 0x0b;
8701 spec->spec_init_verbs[0].param = 0x78D;
8702 spec->spec_init_verbs[0].verb = 0x00;
8704 /* Previously commented configuration */
8706 spec->spec_init_verbs[2].nid = 0x0b;
8707 spec->spec_init_verbs[2].param = AC_VERB_SET_EAPD_BTLENABLE;
8708 spec->spec_init_verbs[2].verb = 0x02;
8710 spec->spec_init_verbs[3].nid = 0x10;
8711 spec->spec_init_verbs[3].param = 0x78D;
8712 spec->spec_init_verbs[3].verb = 0x02;
8714 spec->spec_init_verbs[4].nid = 0x10;
8715 spec->spec_init_verbs[4].param = AC_VERB_SET_EAPD_BTLENABLE;
8716 spec->spec_init_verbs[4].verb = 0x02;
8719 /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */
8724 * The Sound Blaster ZxR shares the same PCI subsystem ID as some regular
8725 * Sound Blaster Z cards. However, they have different HDA codec subsystem
8726 * ID's. So, we check for the ZxR's subsystem ID, as well as the DBPro
8727 * daughter boards ID.
8729 static void sbz_detect_quirk(struct hda_codec *codec)
8731 struct ca0132_spec *spec = codec->spec;
8733 switch (codec->core.subsystem_id) {
8735 spec->quirk = QUIRK_ZXR;
8738 spec->quirk = QUIRK_ZXR_DBPRO;
8741 spec->quirk = QUIRK_SBZ;
8746 static int patch_ca0132(struct hda_codec *codec)
8748 struct ca0132_spec *spec;
8750 const struct snd_pci_quirk *quirk;
8752 codec_dbg(codec, "patch_ca0132\n");
8754 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8758 spec->codec = codec;
8760 /* Detect codec quirk */
8761 quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks);
8763 spec->quirk = quirk->value;
8765 spec->quirk = QUIRK_NONE;
8766 if (ca0132_quirk(spec) == QUIRK_SBZ)
8767 sbz_detect_quirk(codec);
8769 if (ca0132_quirk(spec) == QUIRK_ZXR_DBPRO)
8770 codec->patch_ops = dbpro_patch_ops;
8772 codec->patch_ops = ca0132_patch_ops;
8774 codec->pcm_format_first = 1;
8775 codec->no_sticky_stream = 1;
8778 spec->dsp_state = DSP_DOWNLOAD_INIT;
8779 spec->num_mixers = 1;
8781 /* Set which mixers each quirk uses. */
8782 switch (ca0132_quirk(spec)) {
8784 spec->mixers[0] = desktop_mixer;
8785 snd_hda_codec_set_name(codec, "Sound Blaster Z");
8788 spec->mixers[0] = desktop_mixer;
8789 snd_hda_codec_set_name(codec, "Sound Blaster ZxR");
8791 case QUIRK_ZXR_DBPRO:
8794 spec->mixers[0] = desktop_mixer;
8795 snd_hda_codec_set_name(codec, "Recon3D");
8798 spec->mixers[0] = r3di_mixer;
8799 snd_hda_codec_set_name(codec, "Recon3Di");
8802 spec->mixers[0] = desktop_mixer;
8803 snd_hda_codec_set_name(codec, "Sound BlasterX AE-5");
8806 spec->mixers[0] = ca0132_mixer;
8810 /* Setup whether or not to use alt functions/controls/pci_mmio */
8811 switch (ca0132_quirk(spec)) {
8816 spec->use_alt_controls = true;
8817 spec->use_alt_functions = true;
8818 spec->use_pci_mmio = true;
8821 spec->use_alt_controls = true;
8822 spec->use_alt_functions = true;
8823 spec->use_pci_mmio = false;
8826 spec->use_alt_controls = false;
8827 spec->use_alt_functions = false;
8828 spec->use_pci_mmio = false;
8833 if (spec->use_pci_mmio) {
8834 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
8835 if (spec->mem_base == NULL) {
8836 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
8837 spec->quirk = QUIRK_NONE;
8842 spec->base_init_verbs = ca0132_base_init_verbs;
8843 spec->base_exit_verbs = ca0132_base_exit_verbs;
8845 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
8847 ca0132_init_chip(codec);
8849 ca0132_config(codec);
8851 err = ca0132_prepare_verbs(codec);
8855 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
8869 static struct hda_device_id snd_hda_id_ca0132[] = {
8870 HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132),
8873 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132);
8875 MODULE_LICENSE("GPL");
8876 MODULE_DESCRIPTION("Creative Sound Core3D codec");
8878 static struct hda_codec_driver ca0132_driver = {
8879 .id = snd_hda_id_ca0132,
8882 module_hda_codec_driver(ca0132_driver);