1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HD audio interface patch for Creative CA0132 chip
5 * Copyright (c) 2011, Creative Technology Ltd.
7 * Based on patch_ca0110.c
8 * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
14 #include <linux/mutex.h>
15 #include <linux/module.h>
16 #include <linux/firmware.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
20 #include <linux/pci.h>
22 #include <sound/core.h>
23 #include <sound/hda_codec.h>
24 #include "hda_local.h"
25 #include "hda_auto_parser.h"
28 #include "ca0132_regs.h"
30 /* Enable this to see controls for tuning purpose. */
31 /*#define ENABLE_TUNING_CONTROLS*/
33 #ifdef ENABLE_TUNING_CONTROLS
34 #include <sound/tlv.h>
37 #define FLOAT_ZERO 0x00000000
38 #define FLOAT_ONE 0x3f800000
39 #define FLOAT_TWO 0x40000000
40 #define FLOAT_THREE 0x40400000
41 #define FLOAT_EIGHT 0x41000000
42 #define FLOAT_MINUS_5 0xc0a00000
44 #define UNSOL_TAG_DSP 0x16
46 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
47 #define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
49 #define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
50 #define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
51 #define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
53 #define MASTERCONTROL 0x80
54 #define MASTERCONTROL_ALLOC_DMA_CHAN 10
55 #define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
57 #define WIDGET_CHIP_CTRL 0x15
58 #define WIDGET_DSP_CTRL 0x16
60 #define MEM_CONNID_MICIN1 3
61 #define MEM_CONNID_MICIN2 5
62 #define MEM_CONNID_MICOUT1 12
63 #define MEM_CONNID_MICOUT2 14
64 #define MEM_CONNID_WUH 10
65 #define MEM_CONNID_DSP 16
66 #define MEM_CONNID_DMIC 100
71 #define EFX_FILE "ctefx.bin"
72 #define DESKTOP_EFX_FILE "ctefx-desktop.bin"
73 #define R3DI_EFX_FILE "ctefx-r3di.bin"
75 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
76 MODULE_FIRMWARE(EFX_FILE);
77 MODULE_FIRMWARE(DESKTOP_EFX_FILE);
78 MODULE_FIRMWARE(R3DI_EFX_FILE);
81 static const char *const dirstr[2] = { "Playback", "Capture" };
83 #define NUM_OF_OUTPUTS 3
95 /* Strings for Input Source Enum Control */
96 static const char *const in_src_str[3] = {"Rear Mic", "Line", "Front Mic" };
97 #define IN_SRC_NUM_OF_INPUTS 3
105 #define VNODE_START_NID 0x80
106 VNID_SPK = VNODE_START_NID, /* Speaker vnid */
113 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
115 #define EFFECT_START_NID 0x90
116 #define OUT_EFFECT_START_NID EFFECT_START_NID
117 SURROUND = OUT_EFFECT_START_NID,
124 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
126 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
127 ECHO_CANCELLATION = IN_EFFECT_START_NID,
132 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
134 VOICEFX = IN_EFFECT_END_NID,
144 AE5_HEADPHONE_GAIN_ENUM,
145 AE5_SOUND_FILTER_ENUM,
147 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
150 /* Effects values size*/
151 #define EFFECT_VALS_MAX_COUNT 12
154 * Default values for the effect slider controls, they are in order of their
155 * effect NID's. Surround, Crystalizer, Dialog Plus, Smart Volume, and then
158 static const unsigned int effect_slider_defaults[] = {67, 65, 50, 74, 50};
159 /* Amount of effect level sliders for ca0132_alt controls. */
160 #define EFFECT_LEVEL_SLIDERS 5
162 /* Latency introduced by DSP blocks in milliseconds. */
163 #define DSP_CAPTURE_INIT_LATENCY 0
164 #define DSP_CRYSTAL_VOICE_LATENCY 124
165 #define DSP_PLAYBACK_INIT_LATENCY 13
166 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
167 #define DSP_SPEAKER_OUT_LATENCY 7
170 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
172 int mid; /*effect module ID*/
173 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
174 int direct; /* 0:output; 1:input*/
175 int params; /* number of default non-on/off params */
176 /*effect default values, 1st is on/off. */
177 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
180 #define EFX_DIR_OUT 0
183 static const struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
184 { .name = "Surround",
188 .direct = EFX_DIR_OUT,
190 .def_vals = {0x3F800000, 0x3F2B851F}
192 { .name = "Crystalizer",
196 .direct = EFX_DIR_OUT,
198 .def_vals = {0x3F800000, 0x3F266666}
200 { .name = "Dialog Plus",
204 .direct = EFX_DIR_OUT,
206 .def_vals = {0x00000000, 0x3F000000}
208 { .name = "Smart Volume",
212 .direct = EFX_DIR_OUT,
214 .def_vals = {0x3F800000, 0x3F3D70A4, 0x00000000}
219 .reqs = {24, 23, 25},
220 .direct = EFX_DIR_OUT,
222 .def_vals = {0x3F800000, 0x42A00000, 0x3F000000}
224 { .name = "Equalizer",
227 .reqs = {9, 10, 11, 12, 13, 14,
228 15, 16, 17, 18, 19, 20},
229 .direct = EFX_DIR_OUT,
231 .def_vals = {0x00000000, 0x00000000, 0x00000000, 0x00000000,
232 0x00000000, 0x00000000, 0x00000000, 0x00000000,
233 0x00000000, 0x00000000, 0x00000000, 0x00000000}
235 { .name = "Echo Cancellation",
236 .nid = ECHO_CANCELLATION,
238 .reqs = {0, 1, 2, 3},
239 .direct = EFX_DIR_IN,
241 .def_vals = {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
243 { .name = "Voice Focus",
246 .reqs = {6, 7, 8, 9},
247 .direct = EFX_DIR_IN,
249 .def_vals = {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
255 .direct = EFX_DIR_IN,
257 .def_vals = {0x00000000, 0x3F3D70A4}
259 { .name = "Noise Reduction",
260 .nid = NOISE_REDUCTION,
263 .direct = EFX_DIR_IN,
265 .def_vals = {0x3F800000, 0x3F000000}
270 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18},
271 .direct = EFX_DIR_IN,
273 .def_vals = {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
274 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
279 /* Tuning controls */
280 #ifdef ENABLE_TUNING_CONTROLS
283 #define TUNING_CTL_START_NID 0xC0
284 WEDGE_ANGLE = TUNING_CTL_START_NID,
297 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
300 struct ct_tuning_ctl {
301 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
302 hda_nid_t parent_nid;
304 int mid; /*effect module ID*/
305 int req; /*effect module request*/
306 int direct; /* 0:output; 1:input*/
307 unsigned int def_val;/*effect default values*/
310 static const struct ct_tuning_ctl ca0132_tuning_ctls[] = {
311 { .name = "Wedge Angle",
312 .parent_nid = VOICE_FOCUS,
316 .direct = EFX_DIR_IN,
317 .def_val = 0x41F00000
319 { .name = "SVM Level",
320 .parent_nid = MIC_SVM,
324 .direct = EFX_DIR_IN,
325 .def_val = 0x3F3D70A4
327 { .name = "EQ Band0",
328 .parent_nid = EQUALIZER,
329 .nid = EQUALIZER_BAND_0,
332 .direct = EFX_DIR_OUT,
333 .def_val = 0x00000000
335 { .name = "EQ Band1",
336 .parent_nid = EQUALIZER,
337 .nid = EQUALIZER_BAND_1,
340 .direct = EFX_DIR_OUT,
341 .def_val = 0x00000000
343 { .name = "EQ Band2",
344 .parent_nid = EQUALIZER,
345 .nid = EQUALIZER_BAND_2,
348 .direct = EFX_DIR_OUT,
349 .def_val = 0x00000000
351 { .name = "EQ Band3",
352 .parent_nid = EQUALIZER,
353 .nid = EQUALIZER_BAND_3,
356 .direct = EFX_DIR_OUT,
357 .def_val = 0x00000000
359 { .name = "EQ Band4",
360 .parent_nid = EQUALIZER,
361 .nid = EQUALIZER_BAND_4,
364 .direct = EFX_DIR_OUT,
365 .def_val = 0x00000000
367 { .name = "EQ Band5",
368 .parent_nid = EQUALIZER,
369 .nid = EQUALIZER_BAND_5,
372 .direct = EFX_DIR_OUT,
373 .def_val = 0x00000000
375 { .name = "EQ Band6",
376 .parent_nid = EQUALIZER,
377 .nid = EQUALIZER_BAND_6,
380 .direct = EFX_DIR_OUT,
381 .def_val = 0x00000000
383 { .name = "EQ Band7",
384 .parent_nid = EQUALIZER,
385 .nid = EQUALIZER_BAND_7,
388 .direct = EFX_DIR_OUT,
389 .def_val = 0x00000000
391 { .name = "EQ Band8",
392 .parent_nid = EQUALIZER,
393 .nid = EQUALIZER_BAND_8,
396 .direct = EFX_DIR_OUT,
397 .def_val = 0x00000000
399 { .name = "EQ Band9",
400 .parent_nid = EQUALIZER,
401 .nid = EQUALIZER_BAND_9,
404 .direct = EFX_DIR_OUT,
405 .def_val = 0x00000000
410 /* Voice FX Presets */
411 #define VOICEFX_MAX_PARAM_COUNT 9
417 int reqs[VOICEFX_MAX_PARAM_COUNT]; /*effect module request*/
420 struct ct_voicefx_preset {
421 char *name; /*preset name*/
422 unsigned int vals[VOICEFX_MAX_PARAM_COUNT];
425 static const struct ct_voicefx ca0132_voicefx = {
426 .name = "VoiceFX Capture Switch",
429 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18}
432 static const struct ct_voicefx_preset ca0132_voicefx_presets[] = {
434 .vals = { 0x00000000, 0x43C80000, 0x44AF0000,
435 0x44FA0000, 0x3F800000, 0x3F800000,
436 0x3F800000, 0x00000000, 0x00000000 }
438 { .name = "Female2Male",
439 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
440 0x44FA0000, 0x3F19999A, 0x3F866666,
441 0x3F800000, 0x00000000, 0x00000000 }
443 { .name = "Male2Female",
444 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
445 0x450AC000, 0x4017AE14, 0x3F6B851F,
446 0x3F800000, 0x00000000, 0x00000000 }
448 { .name = "ScrappyKid",
449 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
450 0x44FA0000, 0x40400000, 0x3F28F5C3,
451 0x3F800000, 0x00000000, 0x00000000 }
454 .vals = { 0x3F800000, 0x44324000, 0x44BB8000,
455 0x44E10000, 0x3FB33333, 0x3FB9999A,
456 0x3F800000, 0x3E3A2E43, 0x00000000 }
459 .vals = { 0x3F800000, 0x43EA0000, 0x44A52000,
460 0x45098000, 0x3F266666, 0x3FC00000,
461 0x3F800000, 0x00000000, 0x00000000 }
464 .vals = { 0x3F800000, 0x43C70000, 0x44AE6000,
465 0x45193000, 0x3F8E147B, 0x3F75C28F,
466 0x3F800000, 0x00000000, 0x00000000 }
469 .vals = { 0x3F800000, 0x43930000, 0x44BEE000,
470 0x45007000, 0x3F451EB8, 0x3F7851EC,
471 0x3F800000, 0x00000000, 0x00000000 }
473 { .name = "AlienBrute",
474 .vals = { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
475 0x451F6000, 0x3F266666, 0x3FA7D945,
476 0x3F800000, 0x3CF5C28F, 0x00000000 }
479 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
480 0x44FA0000, 0x3FB2718B, 0x3F800000,
481 0xBC07010E, 0x00000000, 0x00000000 }
484 .vals = { 0x3F800000, 0x43C20000, 0x44906000,
485 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
486 0x3F0A3D71, 0x00000000, 0x00000000 }
489 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
490 0x44FA0000, 0x3F800000, 0x3F800000,
491 0x3E4CCCCD, 0x00000000, 0x00000000 }
493 { .name = "DeepVoice",
494 .vals = { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
495 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
496 0x3F800000, 0x00000000, 0x00000000 }
498 { .name = "Munchkin",
499 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
500 0x44FA0000, 0x3F800000, 0x3F1A043C,
501 0x3F800000, 0x00000000, 0x00000000 }
505 /* ca0132 EQ presets, taken from Windows Sound Blaster Z Driver */
507 #define EQ_PRESET_MAX_PARAM_COUNT 11
513 int reqs[EQ_PRESET_MAX_PARAM_COUNT]; /*effect module request*/
516 struct ct_eq_preset {
517 char *name; /*preset name*/
518 unsigned int vals[EQ_PRESET_MAX_PARAM_COUNT];
521 static const struct ct_eq ca0132_alt_eq_enum = {
522 .name = "FX: Equalizer Preset Switch",
523 .nid = EQ_PRESET_ENUM,
525 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
529 static const struct ct_eq_preset ca0132_alt_eq_presets[] = {
531 .vals = { 0x00000000, 0x00000000, 0x00000000,
532 0x00000000, 0x00000000, 0x00000000,
533 0x00000000, 0x00000000, 0x00000000,
534 0x00000000, 0x00000000 }
536 { .name = "Acoustic",
537 .vals = { 0x00000000, 0x00000000, 0x3F8CCCCD,
538 0x40000000, 0x00000000, 0x00000000,
539 0x00000000, 0x00000000, 0x40000000,
540 0x40000000, 0x40000000 }
542 { .name = "Classical",
543 .vals = { 0x00000000, 0x00000000, 0x40C00000,
544 0x40C00000, 0x40466666, 0x00000000,
545 0x00000000, 0x00000000, 0x00000000,
546 0x40466666, 0x40466666 }
549 .vals = { 0x00000000, 0xBF99999A, 0x00000000,
550 0x3FA66666, 0x3FA66666, 0x3F8CCCCD,
551 0x00000000, 0x00000000, 0x40000000,
552 0x40466666, 0x40800000 }
555 .vals = { 0x00000000, 0xBF99999A, 0x40000000,
556 0x40466666, 0x40866666, 0xBF99999A,
557 0xBF99999A, 0x00000000, 0x00000000,
558 0x40800000, 0x40800000 }
561 .vals = { 0x00000000, 0x00000000, 0x00000000,
562 0x3F8CCCCD, 0x40800000, 0x40800000,
563 0x40800000, 0x00000000, 0x3F8CCCCD,
564 0x40466666, 0x40466666 }
567 .vals = { 0x00000000, 0x00000000, 0x40000000,
568 0x40000000, 0x00000000, 0x00000000,
569 0x00000000, 0x3F8CCCCD, 0x40000000,
570 0x40000000, 0x40000000 }
573 .vals = { 0x00000000, 0xBFCCCCCD, 0x00000000,
574 0x40000000, 0x40000000, 0x00000000,
575 0xBF99999A, 0xBF99999A, 0x00000000,
576 0x40466666, 0x40C00000 }
579 .vals = { 0x00000000, 0xBF99999A, 0xBF99999A,
580 0x3F8CCCCD, 0x40000000, 0xBF99999A,
581 0xBF99999A, 0x00000000, 0x00000000,
582 0x40800000, 0x40800000 }
585 .vals = { 0x00000000, 0xC0000000, 0xBF99999A,
586 0xBF99999A, 0x00000000, 0x40466666,
587 0x40800000, 0x40466666, 0x00000000,
588 0x00000000, 0x3F8CCCCD }
592 /* DSP command sequences for ca0132_alt_select_out */
593 #define ALT_OUT_SET_MAX_COMMANDS 9 /* Max number of commands in sequence */
594 struct ca0132_alt_out_set {
595 char *name; /*preset name*/
596 unsigned char commands;
597 unsigned int mids[ALT_OUT_SET_MAX_COMMANDS];
598 unsigned int reqs[ALT_OUT_SET_MAX_COMMANDS];
599 unsigned int vals[ALT_OUT_SET_MAX_COMMANDS];
602 static const struct ca0132_alt_out_set alt_out_presets[] = {
603 { .name = "Line Out",
605 .mids = { 0x96, 0x96, 0x96, 0x8F,
607 .reqs = { 0x19, 0x17, 0x18, 0x01,
609 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
610 0x00000000, 0x00000000, 0x00000000,
613 { .name = "Headphone",
615 .mids = { 0x96, 0x96, 0x96, 0x8F,
617 .reqs = { 0x19, 0x17, 0x18, 0x01,
619 .vals = { 0x3F000000, 0x42A00000, 0x00000000,
620 0x00000000, 0x00000000, 0x00000000,
623 { .name = "Surround",
625 .mids = { 0x96, 0x8F, 0x96, 0x96,
626 0x96, 0x96, 0x96, 0x96 },
627 .reqs = { 0x18, 0x01, 0x1F, 0x15,
628 0x3A, 0x1A, 0x1B, 0x1C },
629 .vals = { 0x00000000, 0x00000000, 0x00000000,
630 0x00000000, 0x00000000, 0x00000000,
631 0x00000000, 0x00000000 }
636 * DSP volume setting structs. Req 1 is left volume, req 2 is right volume,
637 * and I don't know what the third req is, but it's always zero. I assume it's
638 * some sort of update or set command to tell the DSP there's new volume info.
640 #define DSP_VOL_OUT 0
643 struct ct_dsp_volume_ctl {
645 int mid; /* module ID*/
646 unsigned int reqs[3]; /* scp req ID */
649 static const struct ct_dsp_volume_ctl ca0132_alt_vol_ctls[] = {
660 /* Values for ca0113_mmio_command_set for selecting output. */
661 #define AE5_CA0113_OUT_SET_COMMANDS 6
662 struct ae5_ca0113_output_set {
663 unsigned int group[AE5_CA0113_OUT_SET_COMMANDS];
664 unsigned int target[AE5_CA0113_OUT_SET_COMMANDS];
665 unsigned int vals[AE5_CA0113_OUT_SET_COMMANDS];
668 static const struct ae5_ca0113_output_set ae5_ca0113_output_presets[] = {
669 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
670 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
671 .vals = { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f }
673 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
674 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
675 .vals = { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 }
677 { .group = { 0x30, 0x30, 0x48, 0x48, 0x48, 0x30 },
678 .target = { 0x2e, 0x30, 0x0d, 0x17, 0x19, 0x32 },
679 .vals = { 0x00, 0x00, 0x40, 0x00, 0x00, 0x3f }
683 /* ae5 ca0113 command sequences to set headphone gain levels. */
684 #define AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS 4
685 struct ae5_headphone_gain_set {
687 unsigned int vals[AE5_HEADPHONE_GAIN_PRESET_MAX_COMMANDS];
690 static const struct ae5_headphone_gain_set ae5_headphone_gain_presets[] = {
691 { .name = "Low (16-31",
692 .vals = { 0xff, 0x2c, 0xf5, 0x32 }
694 { .name = "Medium (32-149",
695 .vals = { 0x38, 0xa8, 0x3e, 0x4c }
697 { .name = "High (150-600",
698 .vals = { 0xff, 0xff, 0xff, 0x7f }
702 struct ae5_filter_set {
707 static const struct ae5_filter_set ae5_filter_presets[] = {
708 { .name = "Slow Roll Off",
711 { .name = "Minimum Phase",
714 { .name = "Fast Roll Off",
719 enum hda_cmd_vendor_io {
721 VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000,
722 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100,
724 VENDOR_DSPIO_STATUS = 0xF01,
725 VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702,
726 VENDOR_DSPIO_SCP_READ_DATA = 0xF02,
727 VENDOR_DSPIO_DSP_INIT = 0x703,
728 VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704,
729 VENDOR_DSPIO_SCP_READ_COUNT = 0xF04,
731 /* for ChipIO node */
732 VENDOR_CHIPIO_ADDRESS_LOW = 0x000,
733 VENDOR_CHIPIO_ADDRESS_HIGH = 0x100,
734 VENDOR_CHIPIO_STREAM_FORMAT = 0x200,
735 VENDOR_CHIPIO_DATA_LOW = 0x300,
736 VENDOR_CHIPIO_DATA_HIGH = 0x400,
738 VENDOR_CHIPIO_8051_WRITE_DIRECT = 0x500,
739 VENDOR_CHIPIO_8051_READ_DIRECT = 0xD00,
741 VENDOR_CHIPIO_GET_PARAMETER = 0xF00,
742 VENDOR_CHIPIO_STATUS = 0xF01,
743 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
744 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
746 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
747 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
748 VENDOR_CHIPIO_8051_PMEM_READ = 0xF08,
749 VENDOR_CHIPIO_8051_IRAM_WRITE = 0x709,
750 VENDOR_CHIPIO_8051_IRAM_READ = 0xF09,
752 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
753 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
755 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
756 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
757 VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D,
758 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
759 VENDOR_CHIPIO_FLAG_SET = 0x70F,
760 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
761 VENDOR_CHIPIO_PARAM_SET = 0x710,
762 VENDOR_CHIPIO_PARAM_GET = 0xF10,
764 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
765 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
766 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
767 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
769 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
770 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
771 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
772 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
774 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
775 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
776 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
777 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
778 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
779 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
781 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
787 enum control_flag_id {
788 /* Connection manager stream setup is bypassed/enabled */
789 CONTROL_FLAG_C_MGR = 0,
790 /* DSP DMA is bypassed/enabled */
791 CONTROL_FLAG_DMA = 1,
792 /* 8051 'idle' mode is disabled/enabled */
793 CONTROL_FLAG_IDLE_ENABLE = 2,
794 /* Tracker for the SPDIF-in path is bypassed/enabled */
795 CONTROL_FLAG_TRACKER = 3,
796 /* DigitalOut to Spdif2Out connection is disabled/enabled */
797 CONTROL_FLAG_SPDIF2OUT = 4,
798 /* Digital Microphone is disabled/enabled */
799 CONTROL_FLAG_DMIC = 5,
800 /* ADC_B rate is 48 kHz/96 kHz */
801 CONTROL_FLAG_ADC_B_96KHZ = 6,
802 /* ADC_C rate is 48 kHz/96 kHz */
803 CONTROL_FLAG_ADC_C_96KHZ = 7,
804 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
805 CONTROL_FLAG_DAC_96KHZ = 8,
806 /* DSP rate is 48 kHz/96 kHz */
807 CONTROL_FLAG_DSP_96KHZ = 9,
808 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
809 CONTROL_FLAG_SRC_CLOCK_196MHZ = 10,
810 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
811 CONTROL_FLAG_SRC_RATE_96KHZ = 11,
812 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
813 CONTROL_FLAG_DECODE_LOOP = 12,
814 /* De-emphasis filter on DAC-1 disabled/enabled */
815 CONTROL_FLAG_DAC1_DEEMPHASIS = 13,
816 /* De-emphasis filter on DAC-2 disabled/enabled */
817 CONTROL_FLAG_DAC2_DEEMPHASIS = 14,
818 /* De-emphasis filter on DAC-3 disabled/enabled */
819 CONTROL_FLAG_DAC3_DEEMPHASIS = 15,
820 /* High-pass filter on ADC_B disabled/enabled */
821 CONTROL_FLAG_ADC_B_HIGH_PASS = 16,
822 /* High-pass filter on ADC_C disabled/enabled */
823 CONTROL_FLAG_ADC_C_HIGH_PASS = 17,
824 /* Common mode on Port_A disabled/enabled */
825 CONTROL_FLAG_PORT_A_COMMON_MODE = 18,
826 /* Common mode on Port_D disabled/enabled */
827 CONTROL_FLAG_PORT_D_COMMON_MODE = 19,
828 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
829 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
830 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
831 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
832 /* ASI rate is 48kHz/96kHz */
833 CONTROL_FLAG_ASI_96KHZ = 22,
834 /* DAC power settings able to control attached ports no/yes */
835 CONTROL_FLAG_DACS_CONTROL_PORTS = 23,
836 /* Clock Stop OK reporting is disabled/enabled */
837 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24,
838 /* Number of control flags */
839 CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1)
843 * Control parameter IDs
845 enum control_param_id {
846 /* 0: None, 1: Mic1In*/
847 CONTROL_PARAM_VIP_SOURCE = 1,
848 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
849 CONTROL_PARAM_SPDIF1_SOURCE = 2,
850 /* Port A output stage gain setting to use when 16 Ohm output
851 * impedance is selected*/
852 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
853 /* Port D output stage gain setting to use when 16 Ohm output
854 * impedance is selected*/
855 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
858 * This control param name was found in the 8051 memory, and makes
859 * sense given the fact the AE-5 uses it and has the ASI flag set.
861 CONTROL_PARAM_ASI = 23,
865 /* Select stream with the given ID */
866 CONTROL_PARAM_STREAM_ID = 24,
867 /* Source connection point for the selected stream */
868 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25,
869 /* Destination connection point for the selected stream */
870 CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26,
871 /* Number of audio channels in the selected stream */
872 CONTROL_PARAM_STREAMS_CHANNELS = 27,
873 /*Enable control for the selected stream */
874 CONTROL_PARAM_STREAM_CONTROL = 28,
876 /* Connection Point Control */
878 /* Select connection point with the given ID */
879 CONTROL_PARAM_CONN_POINT_ID = 29,
880 /* Connection point sample rate */
881 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30,
885 /* Select HDA node with the given ID */
886 CONTROL_PARAM_NODE_ID = 31
890 * Dsp Io Status codes
892 enum hda_vendor_status_dspio {
894 VENDOR_STATUS_DSPIO_OK = 0x00,
895 /* Busy, unable to accept new command, the host must retry */
896 VENDOR_STATUS_DSPIO_BUSY = 0x01,
897 /* SCP command queue is full */
898 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02,
899 /* SCP response queue is empty */
900 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03
904 * Chip Io Status codes
906 enum hda_vendor_status_chipio {
908 VENDOR_STATUS_CHIPIO_OK = 0x00,
909 /* Busy, unable to accept new command, the host must retry */
910 VENDOR_STATUS_CHIPIO_BUSY = 0x01
916 enum ca0132_sample_rate {
936 SR_RATE_UNKNOWN = 0x1F
939 enum dsp_download_state {
940 DSP_DOWNLOAD_FAILED = -1,
941 DSP_DOWNLOAD_INIT = 0,
946 /* retrieve parameters from hda format */
947 #define get_hdafmt_chs(fmt) (fmt & 0xf)
948 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
949 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
950 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
957 const struct snd_kcontrol_new *mixers[5];
958 unsigned int num_mixers;
959 const struct hda_verb *base_init_verbs;
960 const struct hda_verb *base_exit_verbs;
961 const struct hda_verb *chip_init_verbs;
962 const struct hda_verb *desktop_init_verbs;
963 struct hda_verb *spec_init_verbs;
964 struct auto_pin_cfg autocfg;
966 /* Nodes configurations */
967 struct hda_multi_out multiout;
968 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
969 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
970 unsigned int num_outputs;
971 hda_nid_t input_pins[AUTO_PIN_LAST];
972 hda_nid_t adcs[AUTO_PIN_LAST];
975 unsigned int num_inputs;
976 hda_nid_t shared_mic_nid;
977 hda_nid_t shared_out_nid;
978 hda_nid_t unsol_tag_hp;
979 hda_nid_t unsol_tag_front_hp; /* for desktop ca0132 codecs */
980 hda_nid_t unsol_tag_amic1;
983 struct mutex chipio_mutex; /* chip access mutex */
986 /* DSP download related */
987 enum dsp_download_state dsp_state;
988 unsigned int dsp_stream_id;
989 unsigned int wait_scp;
990 unsigned int wait_scp_header;
991 unsigned int wait_num_data;
992 unsigned int scp_resp_header;
993 unsigned int scp_resp_data[4];
994 unsigned int scp_resp_count;
995 bool startup_check_entered;
998 /* mixer and effects related */
999 unsigned char dmic_ctl;
1002 long vnode_lvol[VNODES_COUNT];
1003 long vnode_rvol[VNODES_COUNT];
1004 long vnode_lswitch[VNODES_COUNT];
1005 long vnode_rswitch[VNODES_COUNT];
1006 long effects_switch[EFFECTS_COUNT];
1009 /* ca0132_alt control related values */
1010 unsigned char in_enum_val;
1011 unsigned char out_enum_val;
1012 unsigned char mic_boost_enum_val;
1013 unsigned char smart_volume_setting;
1014 long fx_ctl_val[EFFECT_LEVEL_SLIDERS];
1015 long xbass_xover_freq;
1017 unsigned int tlv[4];
1018 struct hda_vmaster_mute_hook vmaster_mute;
1019 /* AE-5 Control values */
1020 unsigned char ae5_headphone_gain_val;
1021 unsigned char ae5_filter_val;
1022 /* ZxR Control Values */
1023 unsigned char zxr_gain_set;
1025 struct hda_codec *codec;
1026 struct delayed_work unsol_hp_work;
1029 #ifdef ENABLE_TUNING_CONTROLS
1030 long cur_ctl_vals[TUNING_CTLS_COUNT];
1033 * The Recon3D, Sound Blaster Z, Sound Blaster ZxR, and Sound Blaster
1034 * AE-5 all use PCI region 2 to toggle GPIO and other currently unknown
1038 void __iomem *mem_base;
1041 * Whether or not to use the alt functions like alt_select_out,
1042 * alt_select_in, etc. Only used on desktop codecs for now, because of
1043 * surround sound support.
1045 bool use_alt_functions;
1048 * Whether or not to use alt controls: volume effect sliders, EQ
1049 * presets, smart volume presets, and new control names with FX prefix.
1050 * Renames PlayEnhancement and CrystalVoice too.
1052 bool use_alt_controls;
1056 * CA0132 quirks table
1061 QUIRK_ALIENWARE_M17XR4,
1071 #define ca0132_quirk(spec) ((spec)->quirk)
1072 #define ca0132_use_pci_mmio(spec) ((spec)->use_pci_mmio)
1073 #define ca0132_use_alt_functions(spec) ((spec)->use_alt_functions)
1074 #define ca0132_use_alt_controls(spec) ((spec)->use_alt_controls)
1076 #define ca0132_quirk(spec) ({ (void)(spec); QUIRK_NONE; })
1077 #define ca0132_use_alt_functions(spec) ({ (void)(spec); false; })
1078 #define ca0132_use_pci_mmio(spec) ({ (void)(spec); false; })
1079 #define ca0132_use_alt_controls(spec) ({ (void)(spec); false; })
1082 static const struct hda_pintbl alienware_pincfgs[] = {
1083 { 0x0b, 0x90170110 }, /* Builtin Speaker */
1084 { 0x0c, 0x411111f0 }, /* N/A */
1085 { 0x0d, 0x411111f0 }, /* N/A */
1086 { 0x0e, 0x411111f0 }, /* N/A */
1087 { 0x0f, 0x0321101f }, /* HP */
1088 { 0x10, 0x411111f0 }, /* Headset? disabled for now */
1089 { 0x11, 0x03a11021 }, /* Mic */
1090 { 0x12, 0xd5a30140 }, /* Builtin Mic */
1091 { 0x13, 0x411111f0 }, /* N/A */
1092 { 0x18, 0x411111f0 }, /* N/A */
1096 /* Sound Blaster Z pin configs taken from Windows Driver */
1097 static const struct hda_pintbl sbz_pincfgs[] = {
1098 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1099 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1100 { 0x0d, 0x014510f0 }, /* Digital Out */
1101 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1102 { 0x0f, 0x0221701f }, /* Port A -- BackPanel HP */
1103 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1104 { 0x11, 0x01017014 }, /* Port B -- LineMicIn2 / Rear L/R */
1105 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1106 { 0x13, 0x908700f0 }, /* What U Hear In*/
1107 { 0x18, 0x50d000f0 }, /* N/A */
1111 /* Sound Blaster ZxR pin configs taken from Windows Driver */
1112 static const struct hda_pintbl zxr_pincfgs[] = {
1113 { 0x0b, 0x01047110 }, /* Port G -- Lineout FRONT L/R */
1114 { 0x0c, 0x414510f0 }, /* SPDIF Out 1 - Disabled*/
1115 { 0x0d, 0x014510f0 }, /* Digital Out */
1116 { 0x0e, 0x41c520f0 }, /* SPDIF In - Disabled*/
1117 { 0x0f, 0x0122711f }, /* Port A -- BackPanel HP */
1118 { 0x10, 0x01017111 }, /* Port D -- Center/LFE */
1119 { 0x11, 0x01017114 }, /* Port B -- LineMicIn2 / Rear L/R */
1120 { 0x12, 0x01a271f0 }, /* Port C -- LineIn1 */
1121 { 0x13, 0x908700f0 }, /* What U Hear In*/
1122 { 0x18, 0x50d000f0 }, /* N/A */
1126 /* Recon3D pin configs taken from Windows Driver */
1127 static const struct hda_pintbl r3d_pincfgs[] = {
1128 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1129 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1130 { 0x0d, 0x014510f0 }, /* Digital Out */
1131 { 0x0e, 0x01c520f0 }, /* SPDIF In */
1132 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1133 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1134 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1135 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1136 { 0x13, 0x908700f0 }, /* What U Hear In*/
1137 { 0x18, 0x50d000f0 }, /* N/A */
1141 /* Sound Blaster AE-5 pin configs taken from Windows Driver */
1142 static const struct hda_pintbl ae5_pincfgs[] = {
1143 { 0x0b, 0x01017010 }, /* Port G -- Lineout FRONT L/R */
1144 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1145 { 0x0d, 0x014510f0 }, /* Digital Out */
1146 { 0x0e, 0x01c510f0 }, /* SPDIF In */
1147 { 0x0f, 0x01017114 }, /* Port A -- Rear L/R. */
1148 { 0x10, 0x01017012 }, /* Port D -- Center/LFE or FP Hp */
1149 { 0x11, 0x01a170ff }, /* Port B -- LineMicIn2 / Rear Headphone */
1150 { 0x12, 0x01a170f0 }, /* Port C -- LineIn1 */
1151 { 0x13, 0x908700f0 }, /* What U Hear In*/
1152 { 0x18, 0x50d000f0 }, /* N/A */
1156 /* Recon3D integrated pin configs taken from Windows Driver */
1157 static const struct hda_pintbl r3di_pincfgs[] = {
1158 { 0x0b, 0x01014110 }, /* Port G -- Lineout FRONT L/R */
1159 { 0x0c, 0x014510f0 }, /* SPDIF Out 1 */
1160 { 0x0d, 0x014510f0 }, /* Digital Out */
1161 { 0x0e, 0x41c520f0 }, /* SPDIF In */
1162 { 0x0f, 0x0221401f }, /* Port A -- BackPanel HP */
1163 { 0x10, 0x01016011 }, /* Port D -- Center/LFE or FP Hp */
1164 { 0x11, 0x01011014 }, /* Port B -- LineMicIn2 / Rear L/R */
1165 { 0x12, 0x02a090f0 }, /* Port C -- LineIn1 */
1166 { 0x13, 0x908700f0 }, /* What U Hear In*/
1167 { 0x18, 0x500000f0 }, /* N/A */
1171 static const struct snd_pci_quirk ca0132_quirks[] = {
1172 SND_PCI_QUIRK(0x1028, 0x057b, "Alienware M17x R4", QUIRK_ALIENWARE_M17XR4),
1173 SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE),
1174 SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE),
1175 SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE),
1176 SND_PCI_QUIRK(0x1102, 0x0010, "Sound Blaster Z", QUIRK_SBZ),
1177 SND_PCI_QUIRK(0x1102, 0x0023, "Sound Blaster Z", QUIRK_SBZ),
1178 SND_PCI_QUIRK(0x1102, 0x0027, "Sound Blaster Z", QUIRK_SBZ),
1179 SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ),
1180 SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
1181 SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
1182 SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
1183 SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),
1184 SND_PCI_QUIRK(0x1102, 0x0051, "Sound Blaster AE-5", QUIRK_AE5),
1189 * CA0132 codec access
1191 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1192 unsigned int verb, unsigned int parm, unsigned int *res)
1194 unsigned int response;
1195 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1198 return ((response == -1) ? -1 : 0);
1201 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1202 unsigned short converter_format, unsigned int *res)
1204 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1205 converter_format & 0xffff, res);
1208 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1209 hda_nid_t nid, unsigned char stream,
1210 unsigned char channel, unsigned int *res)
1212 unsigned char converter_stream_channel = 0;
1214 converter_stream_channel = (stream << 4) | (channel & 0x0f);
1215 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1216 converter_stream_channel, res);
1219 /* Chip access helper function */
1220 static int chipio_send(struct hda_codec *codec,
1225 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1227 /* send bits of data specified by reg */
1229 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1231 if (res == VENDOR_STATUS_CHIPIO_OK)
1234 } while (time_before(jiffies, timeout));
1240 * Write chip address through the vendor widget -- NOT protected by the Mutex!
1242 static int chipio_write_address(struct hda_codec *codec,
1243 unsigned int chip_addx)
1245 struct ca0132_spec *spec = codec->spec;
1248 if (spec->curr_chip_addx == chip_addx)
1251 /* send low 16 bits of the address */
1252 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1253 chip_addx & 0xffff);
1256 /* send high 16 bits of the address */
1257 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1261 spec->curr_chip_addx = (res < 0) ? ~0U : chip_addx;
1267 * Write data through the vendor widget -- NOT protected by the Mutex!
1269 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1271 struct ca0132_spec *spec = codec->spec;
1274 /* send low 16 bits of the data */
1275 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1278 /* send high 16 bits of the data */
1279 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1283 /*If no error encountered, automatically increment the address
1284 as per chip behaviour*/
1285 spec->curr_chip_addx = (res != -EIO) ?
1286 (spec->curr_chip_addx + 4) : ~0U;
1291 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
1293 static int chipio_write_data_multiple(struct hda_codec *codec,
1300 codec_dbg(codec, "chipio_write_data null ptr\n");
1304 while ((count-- != 0) && (status == 0))
1305 status = chipio_write_data(codec, *data++);
1312 * Read data through the vendor widget -- NOT protected by the Mutex!
1314 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1316 struct ca0132_spec *spec = codec->spec;
1320 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1324 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1329 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1330 VENDOR_CHIPIO_HIC_READ_DATA,
1334 /*If no error encountered, automatically increment the address
1335 as per chip behaviour*/
1336 spec->curr_chip_addx = (res != -EIO) ?
1337 (spec->curr_chip_addx + 4) : ~0U;
1342 * Write given value to the given address through the chip I/O widget.
1343 * protected by the Mutex
1345 static int chipio_write(struct hda_codec *codec,
1346 unsigned int chip_addx, const unsigned int data)
1348 struct ca0132_spec *spec = codec->spec;
1351 mutex_lock(&spec->chipio_mutex);
1353 /* write the address, and if successful proceed to write data */
1354 err = chipio_write_address(codec, chip_addx);
1358 err = chipio_write_data(codec, data);
1363 mutex_unlock(&spec->chipio_mutex);
1368 * Write given value to the given address through the chip I/O widget.
1369 * not protected by the Mutex
1371 static int chipio_write_no_mutex(struct hda_codec *codec,
1372 unsigned int chip_addx, const unsigned int data)
1377 /* write the address, and if successful proceed to write data */
1378 err = chipio_write_address(codec, chip_addx);
1382 err = chipio_write_data(codec, data);
1391 * Write multiple values to the given address through the chip I/O widget.
1392 * protected by the Mutex
1394 static int chipio_write_multiple(struct hda_codec *codec,
1399 struct ca0132_spec *spec = codec->spec;
1402 mutex_lock(&spec->chipio_mutex);
1403 status = chipio_write_address(codec, chip_addx);
1407 status = chipio_write_data_multiple(codec, data, count);
1409 mutex_unlock(&spec->chipio_mutex);
1415 * Read the given address through the chip I/O widget
1416 * protected by the Mutex
1418 static int chipio_read(struct hda_codec *codec,
1419 unsigned int chip_addx, unsigned int *data)
1421 struct ca0132_spec *spec = codec->spec;
1424 mutex_lock(&spec->chipio_mutex);
1426 /* write the address, and if successful proceed to write data */
1427 err = chipio_write_address(codec, chip_addx);
1431 err = chipio_read_data(codec, data);
1436 mutex_unlock(&spec->chipio_mutex);
1441 * Set chip control flags through the chip I/O widget.
1443 static void chipio_set_control_flag(struct hda_codec *codec,
1444 enum control_flag_id flag_id,
1448 unsigned int flag_bit;
1450 flag_bit = (flag_state ? 1 : 0);
1451 val = (flag_bit << 7) | (flag_id);
1452 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1453 VENDOR_CHIPIO_FLAG_SET, val);
1457 * Set chip parameters through the chip I/O widget.
1459 static void chipio_set_control_param(struct hda_codec *codec,
1460 enum control_param_id param_id, int param_val)
1462 struct ca0132_spec *spec = codec->spec;
1465 if ((param_id < 32) && (param_val < 8)) {
1466 val = (param_val << 5) | (param_id);
1467 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1468 VENDOR_CHIPIO_PARAM_SET, val);
1470 mutex_lock(&spec->chipio_mutex);
1471 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1472 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1473 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1475 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1476 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1479 mutex_unlock(&spec->chipio_mutex);
1484 * Set chip parameters through the chip I/O widget. NO MUTEX.
1486 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1487 enum control_param_id param_id, int param_val)
1491 if ((param_id < 32) && (param_val < 8)) {
1492 val = (param_val << 5) | (param_id);
1493 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1494 VENDOR_CHIPIO_PARAM_SET, val);
1496 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1497 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1498 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1500 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1501 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1507 * Connect stream to a source point, and then connect
1508 * that source point to a destination point.
1510 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1511 int streamid, int source_point, int dest_point)
1513 chipio_set_control_param_no_mutex(codec,
1514 CONTROL_PARAM_STREAM_ID, streamid);
1515 chipio_set_control_param_no_mutex(codec,
1516 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT, source_point);
1517 chipio_set_control_param_no_mutex(codec,
1518 CONTROL_PARAM_STREAM_DEST_CONN_POINT, dest_point);
1522 * Set number of channels in the selected stream.
1524 static void chipio_set_stream_channels(struct hda_codec *codec,
1525 int streamid, unsigned int channels)
1527 chipio_set_control_param_no_mutex(codec,
1528 CONTROL_PARAM_STREAM_ID, streamid);
1529 chipio_set_control_param_no_mutex(codec,
1530 CONTROL_PARAM_STREAMS_CHANNELS, channels);
1534 * Enable/Disable audio stream.
1536 static void chipio_set_stream_control(struct hda_codec *codec,
1537 int streamid, int enable)
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_STREAM_CONTROL, enable);
1547 * Set sampling rate of the connection point. NO MUTEX.
1549 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1550 int connid, enum ca0132_sample_rate rate)
1552 chipio_set_control_param_no_mutex(codec,
1553 CONTROL_PARAM_CONN_POINT_ID, connid);
1554 chipio_set_control_param_no_mutex(codec,
1555 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE, rate);
1559 * Set sampling rate of the connection point.
1561 static void chipio_set_conn_rate(struct hda_codec *codec,
1562 int connid, enum ca0132_sample_rate rate)
1564 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1565 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1570 * Writes to the 8051's internal address space directly instead of indirectly,
1571 * giving access to the special function registers located at addresses
1574 static void chipio_8051_write_direct(struct hda_codec *codec,
1575 unsigned int addr, unsigned int data)
1579 verb = VENDOR_CHIPIO_8051_WRITE_DIRECT | data;
1580 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1586 static void chipio_enable_clocks(struct hda_codec *codec)
1588 struct ca0132_spec *spec = codec->spec;
1590 mutex_lock(&spec->chipio_mutex);
1591 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1592 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1593 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1594 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1595 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1596 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1597 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1598 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1599 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1600 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1601 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1602 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1603 mutex_unlock(&spec->chipio_mutex);
1607 * CA0132 DSP IO stuffs
1609 static int dspio_send(struct hda_codec *codec, unsigned int reg,
1613 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1615 /* send bits of data specified by reg to dsp */
1617 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1618 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1621 } while (time_before(jiffies, timeout));
1627 * Wait for DSP to be ready for commands
1629 static void dspio_write_wait(struct hda_codec *codec)
1632 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1635 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1636 VENDOR_DSPIO_STATUS, 0);
1637 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1638 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1641 } while (time_before(jiffies, timeout));
1645 * Write SCP data to DSP
1647 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1649 struct ca0132_spec *spec = codec->spec;
1652 dspio_write_wait(codec);
1654 mutex_lock(&spec->chipio_mutex);
1655 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1660 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1665 /* OK, now check if the write itself has executed*/
1666 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1667 VENDOR_DSPIO_STATUS, 0);
1669 mutex_unlock(&spec->chipio_mutex);
1671 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1676 * Write multiple SCP data to DSP
1678 static int dspio_write_multiple(struct hda_codec *codec,
1679 unsigned int *buffer, unsigned int size)
1688 while (count < size) {
1689 status = dspio_write(codec, *buffer++);
1698 static int dspio_read(struct hda_codec *codec, unsigned int *data)
1702 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1706 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1707 if (status == -EIO ||
1708 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
1711 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1712 VENDOR_DSPIO_SCP_READ_DATA, 0);
1717 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
1718 unsigned int *buf_size, unsigned int size_count)
1721 unsigned int size = *buf_size;
1723 unsigned int skip_count;
1730 while (count < size && count < size_count) {
1731 status = dspio_read(codec, buffer++);
1739 while (skip_count < size) {
1740 status = dspio_read(codec, &dummy);
1752 * Construct the SCP header using corresponding fields
1754 static inline unsigned int
1755 make_scp_header(unsigned int target_id, unsigned int source_id,
1756 unsigned int get_flag, unsigned int req,
1757 unsigned int device_flag, unsigned int resp_flag,
1758 unsigned int error_flag, unsigned int data_size)
1760 unsigned int header = 0;
1762 header = (data_size & 0x1f) << 27;
1763 header |= (error_flag & 0x01) << 26;
1764 header |= (resp_flag & 0x01) << 25;
1765 header |= (device_flag & 0x01) << 24;
1766 header |= (req & 0x7f) << 17;
1767 header |= (get_flag & 0x01) << 16;
1768 header |= (source_id & 0xff) << 8;
1769 header |= target_id & 0xff;
1775 * Extract corresponding fields from SCP header
1778 extract_scp_header(unsigned int header,
1779 unsigned int *target_id, unsigned int *source_id,
1780 unsigned int *get_flag, unsigned int *req,
1781 unsigned int *device_flag, unsigned int *resp_flag,
1782 unsigned int *error_flag, unsigned int *data_size)
1785 *data_size = (header >> 27) & 0x1f;
1787 *error_flag = (header >> 26) & 0x01;
1789 *resp_flag = (header >> 25) & 0x01;
1791 *device_flag = (header >> 24) & 0x01;
1793 *req = (header >> 17) & 0x7f;
1795 *get_flag = (header >> 16) & 0x01;
1797 *source_id = (header >> 8) & 0xff;
1799 *target_id = header & 0xff;
1802 #define SCP_MAX_DATA_WORDS (16)
1804 /* Structure to contain any SCP message */
1807 unsigned int data[SCP_MAX_DATA_WORDS];
1810 static void dspio_clear_response_queue(struct hda_codec *codec)
1812 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1813 unsigned int dummy = 0;
1816 /* clear all from the response queue */
1818 status = dspio_read(codec, &dummy);
1819 } while (status == 0 && time_before(jiffies, timeout));
1822 static int dspio_get_response_data(struct hda_codec *codec)
1824 struct ca0132_spec *spec = codec->spec;
1825 unsigned int data = 0;
1828 if (dspio_read(codec, &data) < 0)
1831 if ((data & 0x00ffffff) == spec->wait_scp_header) {
1832 spec->scp_resp_header = data;
1833 spec->scp_resp_count = data >> 27;
1834 count = spec->wait_num_data;
1835 dspio_read_multiple(codec, spec->scp_resp_data,
1836 &spec->scp_resp_count, count);
1844 * Send SCP message to DSP
1846 static int dspio_send_scp_message(struct hda_codec *codec,
1847 unsigned char *send_buf,
1848 unsigned int send_buf_size,
1849 unsigned char *return_buf,
1850 unsigned int return_buf_size,
1851 unsigned int *bytes_returned)
1853 struct ca0132_spec *spec = codec->spec;
1855 unsigned int scp_send_size = 0;
1856 unsigned int total_size;
1857 bool waiting_for_resp = false;
1858 unsigned int header;
1859 struct scp_msg *ret_msg;
1860 unsigned int resp_src_id, resp_target_id;
1861 unsigned int data_size, src_id, target_id, get_flag, device_flag;
1864 *bytes_returned = 0;
1866 /* get scp header from buffer */
1867 header = *((unsigned int *)send_buf);
1868 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
1869 &device_flag, NULL, NULL, &data_size);
1870 scp_send_size = data_size + 1;
1871 total_size = (scp_send_size * 4);
1873 if (send_buf_size < total_size)
1876 if (get_flag || device_flag) {
1877 if (!return_buf || return_buf_size < 4 || !bytes_returned)
1880 spec->wait_scp_header = *((unsigned int *)send_buf);
1882 /* swap source id with target id */
1883 resp_target_id = src_id;
1884 resp_src_id = target_id;
1885 spec->wait_scp_header &= 0xffff0000;
1886 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
1887 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
1889 waiting_for_resp = true;
1892 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
1899 if (waiting_for_resp) {
1900 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1901 memset(return_buf, 0, return_buf_size);
1904 } while (spec->wait_scp && time_before(jiffies, timeout));
1905 waiting_for_resp = false;
1906 if (!spec->wait_scp) {
1907 ret_msg = (struct scp_msg *)return_buf;
1908 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
1909 memcpy(&ret_msg->data, spec->scp_resp_data,
1910 spec->wait_num_data);
1911 *bytes_returned = (spec->scp_resp_count + 1) * 4;
1923 * Prepare and send the SCP message to DSP
1924 * @codec: the HDA codec
1925 * @mod_id: ID of the DSP module to send the command
1926 * @req: ID of request to send to the DSP module
1928 * @data: pointer to the data to send with the request, request specific
1929 * @len: length of the data, in bytes
1930 * @reply: point to the buffer to hold data returned for a reply
1931 * @reply_len: length of the reply buffer returned from GET
1933 * Returns zero or a negative error code.
1935 static int dspio_scp(struct hda_codec *codec,
1936 int mod_id, int src_id, int req, int dir, const void *data,
1937 unsigned int len, void *reply, unsigned int *reply_len)
1940 struct scp_msg scp_send, scp_reply;
1941 unsigned int ret_bytes, send_size, ret_size;
1942 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
1943 unsigned int reply_data_size;
1945 memset(&scp_send, 0, sizeof(scp_send));
1946 memset(&scp_reply, 0, sizeof(scp_reply));
1948 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
1951 if (dir == SCP_GET && reply == NULL) {
1952 codec_dbg(codec, "dspio_scp get but has no buffer\n");
1956 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
1957 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
1961 scp_send.hdr = make_scp_header(mod_id, src_id, (dir == SCP_GET), req,
1962 0, 0, 0, len/sizeof(unsigned int));
1963 if (data != NULL && len > 0) {
1964 len = min((unsigned int)(sizeof(scp_send.data)), len);
1965 memcpy(scp_send.data, data, len);
1969 send_size = sizeof(unsigned int) + len;
1970 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
1971 send_size, (unsigned char *)&scp_reply,
1972 sizeof(scp_reply), &ret_bytes);
1975 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
1979 /* extract send and reply headers members */
1980 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
1981 NULL, NULL, NULL, NULL, NULL);
1982 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
1983 &reply_resp_flag, &reply_error_flag,
1989 if (reply_resp_flag && !reply_error_flag) {
1990 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
1991 / sizeof(unsigned int);
1993 if (*reply_len < ret_size*sizeof(unsigned int)) {
1994 codec_dbg(codec, "reply too long for buf\n");
1996 } else if (ret_size != reply_data_size) {
1997 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
1999 } else if (!reply) {
2000 codec_dbg(codec, "NULL reply\n");
2003 *reply_len = ret_size*sizeof(unsigned int);
2004 memcpy(reply, scp_reply.data, *reply_len);
2007 codec_dbg(codec, "reply ill-formed or errflag set\n");
2015 * Set DSP parameters
2017 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2018 int src_id, int req, const void *data, unsigned int len)
2020 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2024 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2025 int req, const unsigned int data)
2027 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2028 sizeof(unsigned int));
2031 static int dspio_set_uint_param_no_source(struct hda_codec *codec, int mod_id,
2032 int req, const unsigned int data)
2034 return dspio_set_param(codec, mod_id, 0x00, req, &data,
2035 sizeof(unsigned int));
2039 * Allocate a DSP DMA channel via an SCP message
2041 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2044 unsigned int size = sizeof(dma_chan);
2046 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2047 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2048 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0,
2052 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2056 if ((*dma_chan + 1) == 0) {
2057 codec_dbg(codec, "no free dma channels to allocate\n");
2061 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2062 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2068 * Free a DSP DMA via an SCP message
2070 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2073 unsigned int dummy = 0;
2075 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2076 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2078 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2079 MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan,
2080 sizeof(dma_chan), NULL, &dummy);
2083 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2087 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2095 static int dsp_set_run_state(struct hda_codec *codec)
2097 unsigned int dbg_ctrl_reg;
2098 unsigned int halt_state;
2101 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2105 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
2106 DSP_DBGCNTL_STATE_LOBIT;
2108 if (halt_state != 0) {
2109 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
2110 DSP_DBGCNTL_SS_MASK);
2111 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2116 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
2117 DSP_DBGCNTL_EXEC_MASK;
2118 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2130 static int dsp_reset(struct hda_codec *codec)
2135 codec_dbg(codec, "dsp_reset\n");
2137 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2139 } while (res == -EIO && retry);
2142 codec_dbg(codec, "dsp_reset timeout\n");
2150 * Convert chip address to DSP address
2152 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
2153 bool *code, bool *yram)
2155 *code = *yram = false;
2157 if (UC_RANGE(chip_addx, 1)) {
2159 return UC_OFF(chip_addx);
2160 } else if (X_RANGE_ALL(chip_addx, 1)) {
2161 return X_OFF(chip_addx);
2162 } else if (Y_RANGE_ALL(chip_addx, 1)) {
2164 return Y_OFF(chip_addx);
2167 return INVALID_CHIP_ADDRESS;
2171 * Check if the DSP DMA is active
2173 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2175 unsigned int dma_chnlstart_reg;
2177 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2179 return ((dma_chnlstart_reg & (1 <<
2180 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
2183 static int dsp_dma_setup_common(struct hda_codec *codec,
2184 unsigned int chip_addx,
2185 unsigned int dma_chan,
2186 unsigned int port_map_mask,
2190 unsigned int chnl_prop;
2191 unsigned int dsp_addx;
2192 unsigned int active;
2195 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2197 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
2198 codec_dbg(codec, "dma chan num invalid\n");
2202 if (dsp_is_dma_active(codec, dma_chan)) {
2203 codec_dbg(codec, "dma already active\n");
2207 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2209 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2210 codec_dbg(codec, "invalid chip addr\n");
2214 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
2217 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2220 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2224 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2227 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2231 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2233 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
2235 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
2237 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2239 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2242 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2245 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2249 codec_dbg(codec, "read ACTIVE Reg fail\n");
2252 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2255 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
2256 DSPDMAC_ACTIVE_AAR_MASK;
2258 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2260 codec_dbg(codec, "write ACTIVE Reg fail\n");
2264 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2266 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2269 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2272 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2274 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2275 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
2277 codec_dbg(codec, "write IRQCNT Reg fail\n");
2280 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2283 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
2284 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
2285 chip_addx, dsp_addx, dma_chan,
2286 port_map_mask, chnl_prop, active);
2288 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2294 * Setup the DSP DMA per-transfer-specific registers
2296 static int dsp_dma_setup(struct hda_codec *codec,
2297 unsigned int chip_addx,
2299 unsigned int dma_chan)
2303 unsigned int dsp_addx;
2304 unsigned int addr_field;
2305 unsigned int incr_field;
2306 unsigned int base_cnt;
2307 unsigned int cur_cnt;
2308 unsigned int dma_cfg = 0;
2309 unsigned int adr_ofs = 0;
2310 unsigned int xfr_cnt = 0;
2311 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
2312 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
2314 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2316 if (count > max_dma_count) {
2317 codec_dbg(codec, "count too big\n");
2321 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
2322 if (dsp_addx == INVALID_CHIP_ADDRESS) {
2323 codec_dbg(codec, "invalid chip addr\n");
2327 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2329 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
2335 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
2337 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
2340 dma_cfg = addr_field + incr_field;
2341 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2344 codec_dbg(codec, "write DMACFG Reg fail\n");
2347 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2349 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
2352 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2355 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2358 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2360 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
2362 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
2364 xfr_cnt = base_cnt | cur_cnt;
2366 status = chipio_write(codec,
2367 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
2369 codec_dbg(codec, "write XFRCNT Reg fail\n");
2372 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2375 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
2376 "ADROFS=0x%x, XFRCNT=0x%x\n",
2377 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
2379 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2387 static int dsp_dma_start(struct hda_codec *codec,
2388 unsigned int dma_chan, bool ovly)
2390 unsigned int reg = 0;
2393 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2396 status = chipio_read(codec,
2397 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2400 codec_dbg(codec, "read CHNLSTART reg fail\n");
2403 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2405 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2406 DSPDMAC_CHNLSTART_DIS_MASK);
2409 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2410 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
2412 codec_dbg(codec, "write CHNLSTART reg fail\n");
2415 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2423 static int dsp_dma_stop(struct hda_codec *codec,
2424 unsigned int dma_chan, bool ovly)
2426 unsigned int reg = 0;
2429 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2432 status = chipio_read(codec,
2433 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
2436 codec_dbg(codec, "read CHNLSTART reg fail\n");
2439 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2440 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
2441 DSPDMAC_CHNLSTART_DIS_MASK);
2444 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2445 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
2447 codec_dbg(codec, "write CHNLSTART reg fail\n");
2450 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2456 * Allocate router ports
2458 * @codec: the HDA codec
2459 * @num_chans: number of channels in the stream
2460 * @ports_per_channel: number of ports per channel
2461 * @start_device: start device
2462 * @port_map: pointer to the port list to hold the allocated ports
2464 * Returns zero or a negative error code.
2466 static int dsp_allocate_router_ports(struct hda_codec *codec,
2467 unsigned int num_chans,
2468 unsigned int ports_per_channel,
2469 unsigned int start_device,
2470 unsigned int *port_map)
2476 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2480 val = start_device << 6;
2481 val |= (ports_per_channel - 1) << 4;
2482 val |= num_chans - 1;
2484 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2485 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
2488 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2489 VENDOR_CHIPIO_PORT_ALLOC_SET,
2492 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2496 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2497 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
2501 return (res < 0) ? res : 0;
2507 static int dsp_free_router_ports(struct hda_codec *codec)
2511 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2515 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2516 VENDOR_CHIPIO_PORT_FREE_SET,
2519 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2525 * Allocate DSP ports for the download stream
2527 static int dsp_allocate_ports(struct hda_codec *codec,
2528 unsigned int num_chans,
2529 unsigned int rate_multi, unsigned int *port_map)
2533 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2535 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2536 codec_dbg(codec, "bad rate multiple\n");
2540 status = dsp_allocate_router_ports(codec, num_chans,
2541 rate_multi, 0, port_map);
2543 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2548 static int dsp_allocate_ports_format(struct hda_codec *codec,
2549 const unsigned short fmt,
2550 unsigned int *port_map)
2553 unsigned int num_chans;
2555 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
2556 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
2557 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2559 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2560 codec_dbg(codec, "bad rate multiple\n");
2564 num_chans = get_hdafmt_chs(fmt) + 1;
2566 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2574 static int dsp_free_ports(struct hda_codec *codec)
2578 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2580 status = dsp_free_router_ports(codec);
2582 codec_dbg(codec, "free router ports fail\n");
2585 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2591 * HDA DMA engine stuffs for DSP code download
2594 struct hda_codec *codec;
2595 unsigned short m_converter_format;
2596 struct snd_dma_buffer *dmab;
2597 unsigned int buf_size;
2606 static int dma_convert_to_hda_format(struct hda_codec *codec,
2607 unsigned int sample_rate,
2608 unsigned short channels,
2609 unsigned short *hda_format)
2611 unsigned int format_val;
2613 format_val = snd_hdac_calc_stream_format(sample_rate,
2614 channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
2617 *hda_format = (unsigned short)format_val;
2623 * Reset DMA for DSP download
2625 static int dma_reset(struct dma_engine *dma)
2627 struct hda_codec *codec = dma->codec;
2628 struct ca0132_spec *spec = codec->spec;
2631 if (dma->dmab->area)
2632 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2634 status = snd_hda_codec_load_dsp_prepare(codec,
2635 dma->m_converter_format,
2640 spec->dsp_stream_id = status;
2644 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2649 case DMA_STATE_STOP:
2659 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2663 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2665 return dma->dmab->bytes;
2668 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2670 return dma->dmab->area;
2673 static int dma_xfer(struct dma_engine *dma,
2674 const unsigned int *data,
2677 memcpy(dma->dmab->area, data, count);
2681 static void dma_get_converter_format(
2682 struct dma_engine *dma,
2683 unsigned short *format)
2686 *format = dma->m_converter_format;
2689 static unsigned int dma_get_stream_id(struct dma_engine *dma)
2691 struct ca0132_spec *spec = dma->codec->spec;
2693 return spec->dsp_stream_id;
2696 struct dsp_image_seg {
2703 static const u32 g_magic_value = 0x4c46584d;
2704 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2706 static bool is_valid(const struct dsp_image_seg *p)
2708 return p->magic == g_magic_value;
2711 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
2713 return g_chip_addr_magic_value == p->chip_addr;
2716 static bool is_last(const struct dsp_image_seg *p)
2718 return p->count == 0;
2721 static size_t dsp_sizeof(const struct dsp_image_seg *p)
2723 return struct_size(p, data, p->count);
2726 static const struct dsp_image_seg *get_next_seg_ptr(
2727 const struct dsp_image_seg *p)
2729 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
2733 * CA0132 chip DSP transfer stuffs. For DSP download.
2735 #define INVALID_DMA_CHANNEL (~0U)
2738 * Program a list of address/data pairs via the ChipIO widget.
2739 * The segment data is in the format of successive pairs of words.
2740 * These are repeated as indicated by the segment's count field.
2742 static int dspxfr_hci_write(struct hda_codec *codec,
2743 const struct dsp_image_seg *fls)
2749 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
2750 codec_dbg(codec, "hci_write invalid params\n");
2755 data = (u32 *)(fls->data);
2756 while (count >= 2) {
2757 status = chipio_write(codec, data[0], data[1]);
2759 codec_dbg(codec, "hci_write chipio failed\n");
2769 * Write a block of data into DSP code or data RAM using pre-allocated
2772 * @codec: the HDA codec
2773 * @fls: pointer to a fast load image
2774 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2776 * @dma_engine: pointer to DMA engine to be used for DSP download
2777 * @dma_chan: The number of DMA channels used for DSP download
2778 * @port_map_mask: port mapping
2779 * @ovly: TRUE if overlay format is required
2781 * Returns zero or a negative error code.
2783 static int dspxfr_one_seg(struct hda_codec *codec,
2784 const struct dsp_image_seg *fls,
2786 struct dma_engine *dma_engine,
2787 unsigned int dma_chan,
2788 unsigned int port_map_mask,
2792 bool comm_dma_setup_done = false;
2793 const unsigned int *data;
2794 unsigned int chip_addx;
2795 unsigned int words_to_write;
2796 unsigned int buffer_size_words;
2797 unsigned char *buffer_addx;
2798 unsigned short hda_format;
2799 unsigned int sample_rate_div;
2800 unsigned int sample_rate_mul;
2801 unsigned int num_chans;
2802 unsigned int hda_frame_size_words;
2803 unsigned int remainder_words;
2804 const u32 *data_remainder;
2805 u32 chip_addx_remainder;
2806 unsigned int run_size_words;
2807 const struct dsp_image_seg *hci_write = NULL;
2808 unsigned long timeout;
2813 if (is_hci_prog_list_seg(fls)) {
2815 fls = get_next_seg_ptr(fls);
2818 if (hci_write && (!fls || is_last(fls))) {
2819 codec_dbg(codec, "hci_write\n");
2820 return dspxfr_hci_write(codec, hci_write);
2823 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2824 codec_dbg(codec, "Invalid Params\n");
2829 chip_addx = fls->chip_addr,
2830 words_to_write = fls->count;
2832 if (!words_to_write)
2833 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
2835 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
2837 if (!UC_RANGE(chip_addx, words_to_write) &&
2838 !X_RANGE_ALL(chip_addx, words_to_write) &&
2839 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2840 codec_dbg(codec, "Invalid chip_addx Params\n");
2844 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
2847 buffer_addx = dma_get_buffer_addr(dma_engine);
2849 if (buffer_addx == NULL) {
2850 codec_dbg(codec, "dma_engine buffer NULL\n");
2854 dma_get_converter_format(dma_engine, &hda_format);
2855 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
2856 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
2857 num_chans = get_hdafmt_chs(hda_format) + 1;
2859 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
2860 (num_chans * sample_rate_mul / sample_rate_div));
2862 if (hda_frame_size_words == 0) {
2863 codec_dbg(codec, "frmsz zero\n");
2867 buffer_size_words = min(buffer_size_words,
2868 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2870 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2872 "chpadr=0x%08x frmsz=%u nchan=%u "
2873 "rate_mul=%u div=%u bufsz=%u\n",
2874 chip_addx, hda_frame_size_words, num_chans,
2875 sample_rate_mul, sample_rate_div, buffer_size_words);
2877 if (buffer_size_words < hda_frame_size_words) {
2878 codec_dbg(codec, "dspxfr_one_seg:failed\n");
2882 remainder_words = words_to_write % hda_frame_size_words;
2883 data_remainder = data;
2884 chip_addx_remainder = chip_addx;
2886 data += remainder_words;
2887 chip_addx += remainder_words*sizeof(u32);
2888 words_to_write -= remainder_words;
2890 while (words_to_write != 0) {
2891 run_size_words = min(buffer_size_words, words_to_write);
2892 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2893 words_to_write, run_size_words, remainder_words);
2894 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2895 if (!comm_dma_setup_done) {
2896 status = dsp_dma_stop(codec, dma_chan, ovly);
2899 status = dsp_dma_setup_common(codec, chip_addx,
2900 dma_chan, port_map_mask, ovly);
2903 comm_dma_setup_done = true;
2906 status = dsp_dma_setup(codec, chip_addx,
2907 run_size_words, dma_chan);
2910 status = dsp_dma_start(codec, dma_chan, ovly);
2913 if (!dsp_is_dma_active(codec, dma_chan)) {
2914 codec_dbg(codec, "dspxfr:DMA did not start\n");
2917 status = dma_set_state(dma_engine, DMA_STATE_RUN);
2920 if (remainder_words != 0) {
2921 status = chipio_write_multiple(codec,
2922 chip_addx_remainder,
2927 remainder_words = 0;
2930 status = dspxfr_hci_write(codec, hci_write);
2936 timeout = jiffies + msecs_to_jiffies(2000);
2938 dma_active = dsp_is_dma_active(codec, dma_chan);
2942 } while (time_before(jiffies, timeout));
2946 codec_dbg(codec, "+++++ DMA complete\n");
2947 dma_set_state(dma_engine, DMA_STATE_STOP);
2948 status = dma_reset(dma_engine);
2953 data += run_size_words;
2954 chip_addx += run_size_words*sizeof(u32);
2955 words_to_write -= run_size_words;
2958 if (remainder_words != 0) {
2959 status = chipio_write_multiple(codec, chip_addx_remainder,
2960 data_remainder, remainder_words);
2967 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2969 * @codec: the HDA codec
2970 * @fls_data: pointer to a fast load image
2971 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2973 * @sample_rate: sampling rate of the stream used for DSP download
2974 * @channels: channels of the stream used for DSP download
2975 * @ovly: TRUE if overlay format is required
2977 * Returns zero or a negative error code.
2979 static int dspxfr_image(struct hda_codec *codec,
2980 const struct dsp_image_seg *fls_data,
2982 unsigned int sample_rate,
2983 unsigned short channels,
2986 struct ca0132_spec *spec = codec->spec;
2988 unsigned short hda_format = 0;
2989 unsigned int response;
2990 unsigned char stream_id = 0;
2991 struct dma_engine *dma_engine;
2992 unsigned int dma_chan;
2993 unsigned int port_map_mask;
2995 if (fls_data == NULL)
2998 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
3002 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
3003 if (!dma_engine->dmab) {
3008 dma_engine->codec = codec;
3009 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3010 dma_engine->m_converter_format = hda_format;
3011 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
3012 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
3014 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
3016 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3017 hda_format, &response);
3020 codec_dbg(codec, "set converter format fail\n");
3024 status = snd_hda_codec_load_dsp_prepare(codec,
3025 dma_engine->m_converter_format,
3026 dma_engine->buf_size,
3030 spec->dsp_stream_id = status;
3033 status = dspio_alloc_dma_chan(codec, &dma_chan);
3035 codec_dbg(codec, "alloc dmachan fail\n");
3036 dma_chan = INVALID_DMA_CHANNEL;
3042 status = dsp_allocate_ports_format(codec, hda_format,
3045 codec_dbg(codec, "alloc ports fail\n");
3049 stream_id = dma_get_stream_id(dma_engine);
3050 status = codec_set_converter_stream_channel(codec,
3051 WIDGET_CHIP_CTRL, stream_id, 0, &response);
3053 codec_dbg(codec, "set stream chan fail\n");
3057 while ((fls_data != NULL) && !is_last(fls_data)) {
3058 if (!is_valid(fls_data)) {
3059 codec_dbg(codec, "FLS check fail\n");
3063 status = dspxfr_one_seg(codec, fls_data, reloc,
3064 dma_engine, dma_chan,
3065 port_map_mask, ovly);
3069 if (is_hci_prog_list_seg(fls_data))
3070 fls_data = get_next_seg_ptr(fls_data);
3072 if ((fls_data != NULL) && !is_last(fls_data))
3073 fls_data = get_next_seg_ptr(fls_data);
3076 if (port_map_mask != 0)
3077 status = dsp_free_ports(codec);
3082 status = codec_set_converter_stream_channel(codec,
3083 WIDGET_CHIP_CTRL, 0, 0, &response);
3086 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
3087 dspio_free_dma_chan(codec, dma_chan);
3089 if (dma_engine->dmab->area)
3090 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3091 kfree(dma_engine->dmab);
3098 * CA0132 DSP download stuffs.
3100 static void dspload_post_setup(struct hda_codec *codec)
3102 struct ca0132_spec *spec = codec->spec;
3103 codec_dbg(codec, "---- dspload_post_setup ------\n");
3104 if (!ca0132_use_alt_functions(spec)) {
3105 /*set DSP speaker to 2.0 configuration*/
3106 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3107 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3109 /*update write pointer*/
3110 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3115 * dspload_image - Download DSP from a DSP Image Fast Load structure.
3117 * @codec: the HDA codec
3118 * @fls: pointer to a fast load image
3119 * @ovly: TRUE if overlay format is required
3120 * @reloc: Relocation address for loading single-segment overlays, or 0 for
3122 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
3123 * @router_chans: number of audio router channels to be allocated (0 means use
3124 * internal defaults; max is 32)
3126 * Download DSP from a DSP Image Fast Load structure. This structure is a
3127 * linear, non-constant sized element array of structures, each of which
3128 * contain the count of the data to be loaded, the data itself, and the
3129 * corresponding starting chip address of the starting data location.
3130 * Returns zero or a negative error code.
3132 static int dspload_image(struct hda_codec *codec,
3133 const struct dsp_image_seg *fls,
3140 unsigned int sample_rate;
3141 unsigned short channels;
3143 codec_dbg(codec, "---- dspload_image begin ------\n");
3144 if (router_chans == 0) {
3146 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
3148 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
3151 sample_rate = 48000;
3152 channels = (unsigned short)router_chans;
3154 while (channels > 16) {
3160 codec_dbg(codec, "Ready to program DMA\n");
3162 status = dsp_reset(codec);
3167 codec_dbg(codec, "dsp_reset() complete\n");
3168 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3174 codec_dbg(codec, "dspxfr_image() complete\n");
3175 if (autostart && !ovly) {
3176 dspload_post_setup(codec);
3177 status = dsp_set_run_state(codec);
3180 codec_dbg(codec, "LOAD FINISHED\n");
3186 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
3187 static bool dspload_is_loaded(struct hda_codec *codec)
3189 unsigned int data = 0;
3192 status = chipio_read(codec, 0x40004, &data);
3193 if ((status < 0) || (data != 1))
3199 #define dspload_is_loaded(codec) false
3202 static bool dspload_wait_loaded(struct hda_codec *codec)
3204 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
3207 if (dspload_is_loaded(codec)) {
3208 codec_info(codec, "ca0132 DSP downloaded and running\n");
3212 } while (time_before(jiffies, timeout));
3214 codec_err(codec, "ca0132 failed to download DSP\n");
3219 * ca0113 related functions. The ca0113 acts as the HDA bus for the pci-e
3220 * based cards, and has a second mmio region, region2, that's used for special
3225 * For cards with PCI-E region2 (Sound Blaster Z/ZxR, Recon3D, and AE-5)
3226 * the mmio address 0x320 is used to set GPIO pins. The format for the data
3227 * The first eight bits are just the number of the pin. So far, I've only seen
3228 * this number go to 7.
3229 * AE-5 note: The AE-5 seems to use pins 2 and 3 to somehow set the color value
3230 * of the on-card LED. It seems to use pin 2 for data, then toggles 3 to on and
3231 * then off to send that bit.
3233 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3236 struct ca0132_spec *spec = codec->spec;
3237 unsigned short gpio_data;
3239 gpio_data = gpio_pin & 0xF;
3240 gpio_data |= ((enable << 8) & 0x100);
3242 writew(gpio_data, spec->mem_base + 0x320);
3246 * Special pci region2 commands that are only used by the AE-5. They follow
3247 * a set format, and require reads at certain points to seemingly 'clear'
3248 * the response data. My first tests didn't do these reads, and would cause
3249 * the card to get locked up until the memory was read. These commands
3250 * seem to work with three distinct values that I've taken to calling group,
3251 * target-id, and value.
3253 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3254 unsigned int target, unsigned int value)
3256 struct ca0132_spec *spec = codec->spec;
3257 unsigned int write_val;
3259 writel(0x0000007e, spec->mem_base + 0x210);
3260 readl(spec->mem_base + 0x210);
3261 writel(0x0000005a, spec->mem_base + 0x210);
3262 readl(spec->mem_base + 0x210);
3263 readl(spec->mem_base + 0x210);
3265 writel(0x00800005, spec->mem_base + 0x20c);
3266 writel(group, spec->mem_base + 0x804);
3268 writel(0x00800005, spec->mem_base + 0x20c);
3269 write_val = (target & 0xff);
3270 write_val |= (value << 8);
3273 writel(write_val, spec->mem_base + 0x204);
3275 * Need delay here or else it goes too fast and works inconsistently.
3279 readl(spec->mem_base + 0x860);
3280 readl(spec->mem_base + 0x854);
3281 readl(spec->mem_base + 0x840);
3283 writel(0x00800004, spec->mem_base + 0x20c);
3284 writel(0x00000000, spec->mem_base + 0x210);
3285 readl(spec->mem_base + 0x210);
3286 readl(spec->mem_base + 0x210);
3290 * This second type of command is used for setting the sound filter type.
3292 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3293 unsigned int group, unsigned int target, unsigned int value)
3295 struct ca0132_spec *spec = codec->spec;
3296 unsigned int write_val;
3298 writel(0x0000007e, spec->mem_base + 0x210);
3299 readl(spec->mem_base + 0x210);
3300 writel(0x0000005a, spec->mem_base + 0x210);
3301 readl(spec->mem_base + 0x210);
3302 readl(spec->mem_base + 0x210);
3304 writel(0x00800003, spec->mem_base + 0x20c);
3305 writel(group, spec->mem_base + 0x804);
3307 writel(0x00800005, spec->mem_base + 0x20c);
3308 write_val = (target & 0xff);
3309 write_val |= (value << 8);
3312 writel(write_val, spec->mem_base + 0x204);
3314 readl(spec->mem_base + 0x860);
3315 readl(spec->mem_base + 0x854);
3316 readl(spec->mem_base + 0x840);
3318 writel(0x00800004, spec->mem_base + 0x20c);
3319 writel(0x00000000, spec->mem_base + 0x210);
3320 readl(spec->mem_base + 0x210);
3321 readl(spec->mem_base + 0x210);
3325 * Setup GPIO for the other variants of Core3D.
3329 * Sets up the GPIO pins so that they are discoverable. If this isn't done,
3330 * the card shows as having no GPIO pins.
3332 static void ca0132_gpio_init(struct hda_codec *codec)
3334 struct ca0132_spec *spec = codec->spec;
3336 switch (ca0132_quirk(spec)) {
3339 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3340 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3341 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3344 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3345 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3353 /* Sets the GPIO for audio output. */
3354 static void ca0132_gpio_setup(struct hda_codec *codec)
3356 struct ca0132_spec *spec = codec->spec;
3358 switch (ca0132_quirk(spec)) {
3360 snd_hda_codec_write(codec, 0x01, 0,
3361 AC_VERB_SET_GPIO_DIRECTION, 0x07);
3362 snd_hda_codec_write(codec, 0x01, 0,
3363 AC_VERB_SET_GPIO_MASK, 0x07);
3364 snd_hda_codec_write(codec, 0x01, 0,
3365 AC_VERB_SET_GPIO_DATA, 0x04);
3366 snd_hda_codec_write(codec, 0x01, 0,
3367 AC_VERB_SET_GPIO_DATA, 0x06);
3370 snd_hda_codec_write(codec, 0x01, 0,
3371 AC_VERB_SET_GPIO_DIRECTION, 0x1E);
3372 snd_hda_codec_write(codec, 0x01, 0,
3373 AC_VERB_SET_GPIO_MASK, 0x1F);
3374 snd_hda_codec_write(codec, 0x01, 0,
3375 AC_VERB_SET_GPIO_DATA, 0x0C);
3383 * GPIO control functions for the Recon3D integrated.
3386 enum r3di_gpio_bit {
3387 /* Bit 1 - Switch between front/rear mic. 0 = rear, 1 = front */
3388 R3DI_MIC_SELECT_BIT = 1,
3389 /* Bit 2 - Switch between headphone/line out. 0 = Headphone, 1 = Line */
3390 R3DI_OUT_SELECT_BIT = 2,
3392 * I dunno what this actually does, but it stays on until the dsp
3395 R3DI_GPIO_DSP_DOWNLOADING = 3,
3397 * Same as above, no clue what it does, but it comes on after the dsp
3400 R3DI_GPIO_DSP_DOWNLOADED = 4
3403 enum r3di_mic_select {
3404 /* Set GPIO bit 1 to 0 for rear mic */
3406 /* Set GPIO bit 1 to 1 for front microphone*/
3410 enum r3di_out_select {
3411 /* Set GPIO bit 2 to 0 for headphone */
3412 R3DI_HEADPHONE_OUT = 0,
3413 /* Set GPIO bit 2 to 1 for speaker */
3416 enum r3di_dsp_status {
3417 /* Set GPIO bit 3 to 1 until DSP is downloaded */
3418 R3DI_DSP_DOWNLOADING = 0,
3419 /* Set GPIO bit 4 to 1 once DSP is downloaded */
3420 R3DI_DSP_DOWNLOADED = 1
3424 static void r3di_gpio_mic_set(struct hda_codec *codec,
3425 enum r3di_mic_select cur_mic)
3427 unsigned int cur_gpio;
3429 /* Get the current GPIO Data setup */
3430 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3434 cur_gpio &= ~(1 << R3DI_MIC_SELECT_BIT);
3436 case R3DI_FRONT_MIC:
3437 cur_gpio |= (1 << R3DI_MIC_SELECT_BIT);
3440 snd_hda_codec_write(codec, codec->core.afg, 0,
3441 AC_VERB_SET_GPIO_DATA, cur_gpio);
3444 static void r3di_gpio_out_set(struct hda_codec *codec,
3445 enum r3di_out_select cur_out)
3447 unsigned int cur_gpio;
3449 /* Get the current GPIO Data setup */
3450 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3453 case R3DI_HEADPHONE_OUT:
3454 cur_gpio &= ~(1 << R3DI_OUT_SELECT_BIT);
3457 cur_gpio |= (1 << R3DI_OUT_SELECT_BIT);
3460 snd_hda_codec_write(codec, codec->core.afg, 0,
3461 AC_VERB_SET_GPIO_DATA, cur_gpio);
3464 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3465 enum r3di_dsp_status dsp_status)
3467 unsigned int cur_gpio;
3469 /* Get the current GPIO Data setup */
3470 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3472 switch (dsp_status) {
3473 case R3DI_DSP_DOWNLOADING:
3474 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADING);
3475 snd_hda_codec_write(codec, codec->core.afg, 0,
3476 AC_VERB_SET_GPIO_DATA, cur_gpio);
3478 case R3DI_DSP_DOWNLOADED:
3479 /* Set DOWNLOADING bit to 0. */
3480 cur_gpio &= ~(1 << R3DI_GPIO_DSP_DOWNLOADING);
3482 snd_hda_codec_write(codec, codec->core.afg, 0,
3483 AC_VERB_SET_GPIO_DATA, cur_gpio);
3485 cur_gpio |= (1 << R3DI_GPIO_DSP_DOWNLOADED);
3489 snd_hda_codec_write(codec, codec->core.afg, 0,
3490 AC_VERB_SET_GPIO_DATA, cur_gpio);
3496 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3497 struct hda_codec *codec,
3498 unsigned int stream_tag,
3499 unsigned int format,
3500 struct snd_pcm_substream *substream)
3502 struct ca0132_spec *spec = codec->spec;
3504 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3509 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3510 struct hda_codec *codec,
3511 struct snd_pcm_substream *substream)
3513 struct ca0132_spec *spec = codec->spec;
3515 if (spec->dsp_state == DSP_DOWNLOADING)
3518 /*If Playback effects are on, allow stream some time to flush
3520 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3523 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3528 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
3529 struct hda_codec *codec,
3530 struct snd_pcm_substream *substream)
3532 struct ca0132_spec *spec = codec->spec;
3533 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
3534 struct snd_pcm_runtime *runtime = substream->runtime;
3536 if (spec->dsp_state != DSP_DOWNLOADED)
3539 /* Add latency if playback enhancement and either effect is enabled. */
3540 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
3541 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
3542 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
3543 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
3546 /* Applying Speaker EQ adds latency as well. */
3547 if (spec->cur_out_type == SPEAKER_OUT)
3548 latency += DSP_SPEAKER_OUT_LATENCY;
3550 return (latency * runtime->rate) / 1000;
3556 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3557 struct hda_codec *codec,
3558 struct snd_pcm_substream *substream)
3560 struct ca0132_spec *spec = codec->spec;
3561 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3564 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3565 struct hda_codec *codec,
3566 unsigned int stream_tag,
3567 unsigned int format,
3568 struct snd_pcm_substream *substream)
3570 struct ca0132_spec *spec = codec->spec;
3571 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3572 stream_tag, format, substream);
3575 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3576 struct hda_codec *codec,
3577 struct snd_pcm_substream *substream)
3579 struct ca0132_spec *spec = codec->spec;
3580 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3583 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3584 struct hda_codec *codec,
3585 struct snd_pcm_substream *substream)
3587 struct ca0132_spec *spec = codec->spec;
3588 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3594 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3595 struct hda_codec *codec,
3596 unsigned int stream_tag,
3597 unsigned int format,
3598 struct snd_pcm_substream *substream)
3600 snd_hda_codec_setup_stream(codec, hinfo->nid,
3601 stream_tag, 0, format);
3606 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3607 struct hda_codec *codec,
3608 struct snd_pcm_substream *substream)
3610 struct ca0132_spec *spec = codec->spec;
3612 if (spec->dsp_state == DSP_DOWNLOADING)
3615 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3619 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
3620 struct hda_codec *codec,
3621 struct snd_pcm_substream *substream)
3623 struct ca0132_spec *spec = codec->spec;
3624 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
3625 struct snd_pcm_runtime *runtime = substream->runtime;
3627 if (spec->dsp_state != DSP_DOWNLOADED)
3630 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3631 latency += DSP_CRYSTAL_VOICE_LATENCY;
3633 return (latency * runtime->rate) / 1000;
3641 * Mixer controls helpers.
3643 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
3644 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3646 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3647 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3648 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3649 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3650 .info = ca0132_volume_info, \
3651 .get = ca0132_volume_get, \
3652 .put = ca0132_volume_put, \
3653 .tlv = { .c = ca0132_volume_tlv }, \
3654 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3657 * Creates a mixer control that uses defaults of HDA_CODEC_VOL except for the
3658 * volume put, which is used for setting the DSP volume. This was done because
3659 * the ca0132 functions were taking too much time and causing lag.
3661 #define CA0132_ALT_CODEC_VOL_MONO(xname, nid, channel, dir) \
3662 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3664 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3665 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3666 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3667 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3668 .info = snd_hda_mixer_amp_volume_info, \
3669 .get = snd_hda_mixer_amp_volume_get, \
3670 .put = ca0132_alt_volume_put, \
3671 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
3672 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3674 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
3675 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3677 .subdevice = HDA_SUBDEV_AMP_FLAG, \
3678 .info = snd_hda_mixer_amp_switch_info, \
3679 .get = ca0132_switch_get, \
3680 .put = ca0132_switch_put, \
3681 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
3684 #define CA0132_CODEC_VOL(xname, nid, dir) \
3685 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
3686 #define CA0132_ALT_CODEC_VOL(xname, nid, dir) \
3687 CA0132_ALT_CODEC_VOL_MONO(xname, nid, 3, dir)
3688 #define CA0132_CODEC_MUTE(xname, nid, dir) \
3689 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
3693 * Lookup table with decibel values for the DSP. When volume is changed in
3694 * Windows, the DSP is also sent the dB value in floating point. In Windows,
3695 * these values have decimal points, probably because the Windows driver
3696 * actually uses floating point. We can't here, so I made a lookup table of
3697 * values -90 to 9. -90 is the lowest decibel value for both the ADC's and the
3698 * DAC's, and 9 is the maximum.
3700 static const unsigned int float_vol_db_lookup[] = {
3701 0xC2B40000, 0xC2B20000, 0xC2B00000, 0xC2AE0000, 0xC2AC0000, 0xC2AA0000,
3702 0xC2A80000, 0xC2A60000, 0xC2A40000, 0xC2A20000, 0xC2A00000, 0xC29E0000,
3703 0xC29C0000, 0xC29A0000, 0xC2980000, 0xC2960000, 0xC2940000, 0xC2920000,
3704 0xC2900000, 0xC28E0000, 0xC28C0000, 0xC28A0000, 0xC2880000, 0xC2860000,
3705 0xC2840000, 0xC2820000, 0xC2800000, 0xC27C0000, 0xC2780000, 0xC2740000,
3706 0xC2700000, 0xC26C0000, 0xC2680000, 0xC2640000, 0xC2600000, 0xC25C0000,
3707 0xC2580000, 0xC2540000, 0xC2500000, 0xC24C0000, 0xC2480000, 0xC2440000,
3708 0xC2400000, 0xC23C0000, 0xC2380000, 0xC2340000, 0xC2300000, 0xC22C0000,
3709 0xC2280000, 0xC2240000, 0xC2200000, 0xC21C0000, 0xC2180000, 0xC2140000,
3710 0xC2100000, 0xC20C0000, 0xC2080000, 0xC2040000, 0xC2000000, 0xC1F80000,
3711 0xC1F00000, 0xC1E80000, 0xC1E00000, 0xC1D80000, 0xC1D00000, 0xC1C80000,
3712 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3713 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3714 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3715 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3716 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3717 0x40C00000, 0x40E00000, 0x41000000, 0x41100000
3721 * This table counts from float 0 to 1 in increments of .01, which is
3722 * useful for a few different sliders.
3724 static const unsigned int float_zero_to_one_lookup[] = {
3725 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3726 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3727 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3728 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3729 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3730 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3731 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3732 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3733 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3734 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3735 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3736 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3737 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3738 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3739 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3740 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3741 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3745 * This table counts from float 10 to 1000, which is the range of the x-bass
3746 * crossover slider in Windows.
3748 static const unsigned int float_xbass_xover_lookup[] = {
3749 0x41200000, 0x41A00000, 0x41F00000, 0x42200000, 0x42480000, 0x42700000,
3750 0x428C0000, 0x42A00000, 0x42B40000, 0x42C80000, 0x42DC0000, 0x42F00000,
3751 0x43020000, 0x430C0000, 0x43160000, 0x43200000, 0x432A0000, 0x43340000,
3752 0x433E0000, 0x43480000, 0x43520000, 0x435C0000, 0x43660000, 0x43700000,
3753 0x437A0000, 0x43820000, 0x43870000, 0x438C0000, 0x43910000, 0x43960000,
3754 0x439B0000, 0x43A00000, 0x43A50000, 0x43AA0000, 0x43AF0000, 0x43B40000,
3755 0x43B90000, 0x43BE0000, 0x43C30000, 0x43C80000, 0x43CD0000, 0x43D20000,
3756 0x43D70000, 0x43DC0000, 0x43E10000, 0x43E60000, 0x43EB0000, 0x43F00000,
3757 0x43F50000, 0x43FA0000, 0x43FF0000, 0x44020000, 0x44048000, 0x44070000,
3758 0x44098000, 0x440C0000, 0x440E8000, 0x44110000, 0x44138000, 0x44160000,
3759 0x44188000, 0x441B0000, 0x441D8000, 0x44200000, 0x44228000, 0x44250000,
3760 0x44278000, 0x442A0000, 0x442C8000, 0x442F0000, 0x44318000, 0x44340000,
3761 0x44368000, 0x44390000, 0x443B8000, 0x443E0000, 0x44408000, 0x44430000,
3762 0x44458000, 0x44480000, 0x444A8000, 0x444D0000, 0x444F8000, 0x44520000,
3763 0x44548000, 0x44570000, 0x44598000, 0x445C0000, 0x445E8000, 0x44610000,
3764 0x44638000, 0x44660000, 0x44688000, 0x446B0000, 0x446D8000, 0x44700000,
3765 0x44728000, 0x44750000, 0x44778000, 0x447A0000
3768 /* The following are for tuning of products */
3769 #ifdef ENABLE_TUNING_CONTROLS
3771 static unsigned int voice_focus_vals_lookup[] = {
3772 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
3773 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
3774 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
3775 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
3776 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
3777 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
3778 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
3779 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
3780 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
3781 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
3782 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
3783 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
3784 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
3785 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
3786 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
3787 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
3788 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
3789 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
3790 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
3791 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
3792 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
3793 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
3794 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
3795 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
3796 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
3797 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
3798 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
3801 static unsigned int mic_svm_vals_lookup[] = {
3802 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
3803 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
3804 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
3805 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
3806 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
3807 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
3808 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
3809 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
3810 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
3811 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
3812 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
3813 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
3814 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
3815 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
3816 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
3817 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
3818 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
3821 static unsigned int equalizer_vals_lookup[] = {
3822 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
3823 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
3824 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
3825 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
3826 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
3827 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
3828 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
3829 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
3833 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
3834 unsigned int *lookup, int idx)
3838 for (i = 0; i < TUNING_CTLS_COUNT; i++)
3839 if (nid == ca0132_tuning_ctls[i].nid)
3842 snd_hda_power_up(codec);
3843 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
3844 ca0132_tuning_ctls[i].req,
3845 &(lookup[idx]), sizeof(unsigned int));
3846 snd_hda_power_down(codec);
3851 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
3852 struct snd_ctl_elem_value *ucontrol)
3854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3855 struct ca0132_spec *spec = codec->spec;
3856 hda_nid_t nid = get_amp_nid(kcontrol);
3857 long *valp = ucontrol->value.integer.value;
3858 int idx = nid - TUNING_CTL_START_NID;
3860 *valp = spec->cur_ctl_vals[idx];
3864 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
3865 struct snd_ctl_elem_info *uinfo)
3867 int chs = get_amp_channels(kcontrol);
3868 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3869 uinfo->count = chs == 3 ? 2 : 1;
3870 uinfo->value.integer.min = 20;
3871 uinfo->value.integer.max = 180;
3872 uinfo->value.integer.step = 1;
3877 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
3878 struct snd_ctl_elem_value *ucontrol)
3880 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3881 struct ca0132_spec *spec = codec->spec;
3882 hda_nid_t nid = get_amp_nid(kcontrol);
3883 long *valp = ucontrol->value.integer.value;
3886 idx = nid - TUNING_CTL_START_NID;
3888 if (spec->cur_ctl_vals[idx] == *valp)
3891 spec->cur_ctl_vals[idx] = *valp;
3894 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
3899 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
3900 struct snd_ctl_elem_info *uinfo)
3902 int chs = get_amp_channels(kcontrol);
3903 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3904 uinfo->count = chs == 3 ? 2 : 1;
3905 uinfo->value.integer.min = 0;
3906 uinfo->value.integer.max = 100;
3907 uinfo->value.integer.step = 1;
3912 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
3913 struct snd_ctl_elem_value *ucontrol)
3915 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3916 struct ca0132_spec *spec = codec->spec;
3917 hda_nid_t nid = get_amp_nid(kcontrol);
3918 long *valp = ucontrol->value.integer.value;
3921 idx = nid - TUNING_CTL_START_NID;
3923 if (spec->cur_ctl_vals[idx] == *valp)
3926 spec->cur_ctl_vals[idx] = *valp;
3929 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
3934 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
3935 struct snd_ctl_elem_info *uinfo)
3937 int chs = get_amp_channels(kcontrol);
3938 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3939 uinfo->count = chs == 3 ? 2 : 1;
3940 uinfo->value.integer.min = 0;
3941 uinfo->value.integer.max = 48;
3942 uinfo->value.integer.step = 1;
3947 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
3948 struct snd_ctl_elem_value *ucontrol)
3950 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3951 struct ca0132_spec *spec = codec->spec;
3952 hda_nid_t nid = get_amp_nid(kcontrol);
3953 long *valp = ucontrol->value.integer.value;
3956 idx = nid - TUNING_CTL_START_NID;
3958 if (spec->cur_ctl_vals[idx] == *valp)
3961 spec->cur_ctl_vals[idx] = *valp;
3964 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
3969 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
3970 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(eq_db_scale, -2400, 100, 0);
3972 static int add_tuning_control(struct hda_codec *codec,
3973 hda_nid_t pnid, hda_nid_t nid,
3974 const char *name, int dir)
3976 char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3977 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3978 struct snd_kcontrol_new knew =
3979 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
3981 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3982 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3987 knew.info = voice_focus_ctl_info;
3988 knew.get = tuning_ctl_get;
3989 knew.put = voice_focus_ctl_put;
3990 knew.tlv.p = voice_focus_db_scale;