2 * HD audio interface patch for Creative Sound Core3D chip
4 * Copyright (c) 2011, Creative Technology Ltd.
6 * Based on patch_ca0110.c
7 * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/module.h>
29 #include <linux/firmware.h>
30 #include <sound/core.h>
31 #include <sound/tlv.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
36 #include "ca0132_regs.h"
38 /* Enable this to see more debug messages. */
39 /*#define ENABLE_CA0132_DEBUG*/
40 /* Enable this to see controls for tuning purpose. */
41 /*#define ENABLE_TUNING_CONTROLS*/
43 #define FLOAT_ZERO 0x00000000
44 #define FLOAT_ONE 0x3f800000
45 #define FLOAT_TWO 0x40000000
46 #define FLOAT_MINUS_5 0xc0a00000
48 #define UNSOL_TAG_HP 0x10
49 #define UNSOL_TAG_AMIC1 0x12
50 #define UNSOL_TAG_DSP 0x16
52 #define SUCCEEDED(_x) (((int)(_x)) >= 0)
53 #define FAILED(_x) (((int)(_x)) < 0)
55 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
56 #define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
58 #define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
59 #define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
60 #define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
62 #define MASTERCONTROL 0x80
63 #define MASTERCONTROL_ALLOC_DMA_CHAN 10
64 #define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
66 #define WIDGET_CHIP_CTRL 0x15
67 #define WIDGET_DSP_CTRL 0x16
69 #define MEM_CONNID_MICIN1 3
70 #define MEM_CONNID_MICIN2 5
71 #define MEM_CONNID_MICOUT1 12
72 #define MEM_CONNID_MICOUT2 14
73 #define MEM_CONNID_WUH 10
74 #define MEM_CONNID_DSP 16
75 #define MEM_CONNID_DMIC 100
80 #define SPEQ_FILE "ctspeq.bin"
81 #define EFX_FILE "ctefx.bin"
83 MODULE_FIRMWARE(SPEQ_FILE);
84 MODULE_FIRMWARE(EFX_FILE);
86 /* Debug message controls */
87 #ifdef ENABLE_CA0132_DEBUG
90 { if (!(x)) snd_printdd(KERN_ERR "CTASSERT failed.\n"); }
92 #define CA0132_LOG(fmt, args...) snd_printdd(fmt, ##args)
93 #define CA0132_DSP_LOG(msg) snd_printdd(KERN_INFO "[%s]\n", msg)
94 #define FAIL_MSG(n, s) fail_debug_out(n, s)
96 static int fail_debug_out(int status, const char *s)
98 snd_printdd(KERN_ERR "[%s]\n", s);
103 #define CTASSERT(x) do { } while (0)
104 #define CA0132_LOG(fmt, args...) do { } while (0)
105 #define CA0132_DSP_LOG(msg) do { } while (0)
106 #define FAIL_MSG(n, s) fail_debug_out(n, s)
108 static int fail_debug_out(int status, const char *s)
114 static char *dirstr[2] = { "Playback", "Capture" };
127 #define VNODE_START_NID 0x80
128 VNID_SPK = VNODE_START_NID, /* Speaker vnid */
135 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
137 #define EFFECT_START_NID 0x90
138 #define OUT_EFFECT_START_NID EFFECT_START_NID
139 SURROUND = OUT_EFFECT_START_NID,
146 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
148 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
149 ECHO_CANCELLATION = IN_EFFECT_START_NID,
154 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
156 VOICEFX = IN_EFFECT_END_NID,
160 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
163 /* Effects values size*/
164 #define EFFECT_VALS_MAX_COUNT 12
166 #define DSP_CAPTURE_INIT_LATENCY 0
167 #define DSP_CRYSTAL_VOICE_LATENCY 124
168 #define DSP_PLAYBACK_INIT_LATENCY 13
169 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
170 #define DSP_SPEAKER_OUT_LATENCY 7
175 int mid; /*effect module ID*/
176 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
177 int direct; /* 0:output; 1:input*/
178 int params; /* number of default non-on/off params */
179 /*effect default values, 1st is on/off. */
180 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
183 static struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
190 {0x3F800000, 0x3F2B851F}
198 {0x3F800000, 0x3F266666}
206 {0x00000000, 0x3F000000}
214 {0x3F800000, 0x3F3D70A4, 0x00000000}
222 {0x3F800000, 0x42A00000, 0x3F000000}
227 {9, 10, 11, 12, 13, 14,
228 15, 16, 17, 18, 19, 20},
231 {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
232 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
233 0x00000000, 0x00000000}
235 { "Echo Cancellation",
241 {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
249 {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
257 {0x00000000, 0x3F3D70A4}
265 {0x3F800000, 0x3F000000}
270 {10, 11, 12, 13, 14, 15, 16, 17, 18},
273 {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000, 0x3F800000,
274 0x3F800000, 0x3F800000, 0x00000000, 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 {
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 struct ct_tuning_ctl ca0132_tuning_ctls[] = {
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 struct ct_voicefx ca0132_voicefx = {
426 "VoiceFX Capture Switch",
429 {10, 11, 12, 13, 14, 15, 16, 17, 18}
432 struct ct_voicefx_preset ca0132_voicefx_presets[] = {
434 { 0x00000000, 0x43C80000, 0x44AF0000,
435 0x44FA0000, 0x3F800000, 0x3F800000,
436 0x3F800000, 0x00000000, 0x00000000 }
439 { 0x3F800000, 0x43C80000, 0x44AF0000,
440 0x44FA0000, 0x3F19999A, 0x3F866666,
441 0x3F800000, 0x00000000, 0x00000000 }
444 { 0x3F800000, 0x43C80000, 0x44AF0000,
445 0x450AC000, 0x4017AE14, 0x3F6B851F,
446 0x3F800000, 0x00000000, 0x00000000 }
449 { 0x3F800000, 0x43C80000, 0x44AF0000,
450 0x44FA0000, 0x40400000, 0x3F28F5C3,
451 0x3F800000, 0x00000000, 0x00000000 }
454 { 0x3F800000, 0x44324000, 0x44BB8000,
455 0x44E10000, 0x3FB33333, 0x3FB9999A,
456 0x3F800000, 0x3E3A2E43, 0x00000000 }
459 { 0x3F800000, 0x43EA0000, 0x44A52000,
460 0x45098000, 0x3F266666, 0x3FC00000,
461 0x3F800000, 0x00000000, 0x00000000 }
464 { 0x3F800000, 0x43C70000, 0x44AE6000,
465 0x45193000, 0x3F8E147B, 0x3F75C28F,
466 0x3F800000, 0x00000000, 0x00000000 }
469 { 0x3F800000, 0x43930000, 0x44BEE000,
470 0x45007000, 0x3F451EB8, 0x3F7851EC,
471 0x3F800000, 0x00000000, 0x00000000 }
474 { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
475 0x451F6000, 0x3F266666, 0x3FA7D945,
476 0x3F800000, 0x3CF5C28F, 0x00000000 }
479 { 0x3F800000, 0x43C80000, 0x44AF0000,
480 0x44FA0000, 0x3FB2718B, 0x3F800000,
481 0xBC07010E, 0x00000000, 0x00000000 }
484 { 0x3F800000, 0x43C20000, 0x44906000,
485 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
486 0x3F0A3D71, 0x00000000, 0x00000000 }
489 { 0x3F800000, 0x43C80000, 0x44AF0000,
490 0x44FA0000, 0x3F800000, 0x3F800000,
491 0x3E4CCCCD, 0x00000000, 0x00000000 }
494 { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
495 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
496 0x3F800000, 0x00000000, 0x00000000 }
499 { 0x3F800000, 0x43C80000, 0x44AF0000,
500 0x44FA0000, 0x3F1A043C, 0x3F800000,
501 0x3F800000, 0x00000000, 0x00000000 }
505 enum hda_cmd_vendor_io {
507 VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000,
508 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100,
510 VENDOR_DSPIO_STATUS = 0xF01,
511 VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702,
512 VENDOR_DSPIO_SCP_READ_DATA = 0xF02,
513 VENDOR_DSPIO_DSP_INIT = 0x703,
514 VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704,
515 VENDOR_DSPIO_SCP_READ_COUNT = 0xF04,
517 /* for ChipIO node */
518 VENDOR_CHIPIO_ADDRESS_LOW = 0x000,
519 VENDOR_CHIPIO_ADDRESS_HIGH = 0x100,
520 VENDOR_CHIPIO_STREAM_FORMAT = 0x200,
521 VENDOR_CHIPIO_DATA_LOW = 0x300,
522 VENDOR_CHIPIO_DATA_HIGH = 0x400,
524 VENDOR_CHIPIO_GET_PARAMETER = 0xF00,
525 VENDOR_CHIPIO_STATUS = 0xF01,
526 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
527 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
529 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
530 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
532 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
533 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
535 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
536 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
537 VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D,
538 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
539 VENDOR_CHIPIO_FLAG_SET = 0x70F,
540 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
541 VENDOR_CHIPIO_PARAM_SET = 0x710,
542 VENDOR_CHIPIO_PARAM_GET = 0xF10,
544 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
545 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
546 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
547 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
549 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
550 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
551 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
552 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
554 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
555 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
556 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
557 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
558 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
559 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
561 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
564 enum control_flag_id {
565 /* Connection manager stream setup is bypassed/enabled */
566 CONTROL_FLAG_C_MGR = 0,
567 /* DSP DMA is bypassed/enabled */
568 CONTROL_FLAG_DMA = 1,
569 /* 8051 'idle' mode is disabled/enabled */
570 CONTROL_FLAG_IDLE_ENABLE = 2,
571 /* Tracker for the SPDIF-in path is bypassed/enabled */
572 CONTROL_FLAG_TRACKER = 3,
573 /* DigitalOut to Spdif2Out connection is disabled/enabled */
574 CONTROL_FLAG_SPDIF2OUT = 4,
575 /* Digital Microphone is disabled/enabled */
576 CONTROL_FLAG_DMIC = 5,
577 /* ADC_B rate is 48 kHz/96 kHz */
578 CONTROL_FLAG_ADC_B_96KHZ = 6,
579 /* ADC_C rate is 48 kHz/96 kHz */
580 CONTROL_FLAG_ADC_C_96KHZ = 7,
581 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
582 CONTROL_FLAG_DAC_96KHZ = 8,
583 /* DSP rate is 48 kHz/96 kHz */
584 CONTROL_FLAG_DSP_96KHZ = 9,
585 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
586 CONTROL_FLAG_SRC_CLOCK_196MHZ = 10,
587 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
588 CONTROL_FLAG_SRC_RATE_96KHZ = 11,
589 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
590 CONTROL_FLAG_DECODE_LOOP = 12,
591 /* De-emphasis filter on DAC-1 disabled/enabled */
592 CONTROL_FLAG_DAC1_DEEMPHASIS = 13,
593 /* De-emphasis filter on DAC-2 disabled/enabled */
594 CONTROL_FLAG_DAC2_DEEMPHASIS = 14,
595 /* De-emphasis filter on DAC-3 disabled/enabled */
596 CONTROL_FLAG_DAC3_DEEMPHASIS = 15,
597 /* High-pass filter on ADC_B disabled/enabled */
598 CONTROL_FLAG_ADC_B_HIGH_PASS = 16,
599 /* High-pass filter on ADC_C disabled/enabled */
600 CONTROL_FLAG_ADC_C_HIGH_PASS = 17,
601 /* Common mode on Port_A disabled/enabled */
602 CONTROL_FLAG_PORT_A_COMMON_MODE = 18,
603 /* Common mode on Port_D disabled/enabled */
604 CONTROL_FLAG_PORT_D_COMMON_MODE = 19,
605 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
606 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
607 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
608 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
609 /* ASI rate is 48kHz/96kHz */
610 CONTROL_FLAG_ASI_96KHZ = 22,
611 /* DAC power settings able to control attached ports no/yes */
612 CONTROL_FLAG_DACS_CONTROL_PORTS = 23,
613 /* Clock Stop OK reporting is disabled/enabled */
614 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24,
615 /* Number of control flags */
616 CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1)
619 enum control_param_id {
620 /* 0: None, 1: Mic1In*/
621 CONTROL_PARAM_VIP_SOURCE = 1,
622 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
623 CONTROL_PARAM_SPDIF1_SOURCE = 2,
624 /* Port A output stage gain setting to use when 16 Ohm output
625 * impedance is selected*/
626 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
627 /* Port D output stage gain setting to use when 16 Ohm output
628 * impedance is selected*/
629 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
633 /* Select stream with the given ID */
634 CONTROL_PARAM_STREAM_ID = 24,
635 /* Source connection point for the selected stream */
636 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25,
637 /* Destination connection point for the selected stream */
638 CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26,
639 /* Number of audio channels in the selected stream */
640 CONTROL_PARAM_STREAMS_CHANNELS = 27,
641 /*Enable control for the selected stream */
642 CONTROL_PARAM_STREAM_CONTROL = 28,
644 /* Connection Point Control */
646 /* Select connection point with the given ID */
647 CONTROL_PARAM_CONN_POINT_ID = 29,
648 /* Connection point sample rate */
649 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30,
653 /* Select HDA node with the given ID */
654 CONTROL_PARAM_NODE_ID = 31
657 enum hda_vendor_status_dspio {
659 VENDOR_STATUS_DSPIO_OK = 0x00,
660 /* Busy, unable to accept new command, the host must retry */
661 VENDOR_STATUS_DSPIO_BUSY = 0x01,
662 /* SCP command queue is full */
663 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02,
664 /* SCP response queue is empty */
665 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03
668 enum hda_vendor_status_chipio {
670 VENDOR_STATUS_CHIPIO_OK = 0x00,
671 /* Busy, unable to accept new command, the host must retry */
672 VENDOR_STATUS_CHIPIO_BUSY = 0x01
675 enum ca0132_sample_rate {
695 SR_RATE_UNKNOWN = 0x1F
698 enum dsp_download_state {
699 DSP_DOWNLOAD_FAILED = -1,
700 DSP_DOWNLOAD_INIT = 0,
705 struct hda_stream_format {
706 unsigned int sample_rate;
707 unsigned short valid_bits_per_sample;
708 unsigned short container_size;
709 unsigned short number_channels;
712 /* retrieve parameters from hda format */
713 #define get_hdafmt_chs(fmt) (fmt & 0xf)
714 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
715 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
716 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
719 struct snd_kcontrol_new *mixers[5];
720 unsigned int num_mixers;
721 const struct hda_verb *base_init_verbs;
722 const struct hda_verb *base_exit_verbs;
723 const struct hda_verb *init_verbs[5];
724 unsigned int num_init_verbs; /* exclude base init verbs */
725 struct auto_pin_cfg autocfg;
727 /* Nodes configurations */
728 struct hda_multi_out multiout;
729 hda_nid_t out_pins[5];
731 unsigned int num_outputs;
732 hda_nid_t input_pins[5];
734 unsigned int num_inputs;
735 hda_nid_t shared_mic_nid;
736 hda_nid_t shared_out_nid;
737 struct hda_pcm pcm_rec[5]; /* PCM information */
740 struct mutex chipio_mutex; /* chip access mutex */
743 /* DSP download related */
744 enum dsp_download_state dsp_state;
745 unsigned int dsp_stream_id;
746 unsigned int wait_scp;
747 unsigned int wait_scp_header;
748 unsigned int wait_num_data;
749 unsigned int scp_resp_header;
750 unsigned int scp_resp_data[4];
751 unsigned int scp_resp_count;
753 /* mixer and effects related */
754 unsigned char dmic_ctl;
757 long vnode_lvol[VNODES_COUNT];
758 long vnode_rvol[VNODES_COUNT];
759 long vnode_lswitch[VNODES_COUNT];
760 long vnode_rswitch[VNODES_COUNT];
761 long effects_switch[EFFECTS_COUNT];
765 #ifdef ENABLE_TUNING_CONTROLS
766 long cur_ctl_vals[TUNING_CTLS_COUNT];
771 * CA0132 codec access
773 unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
774 unsigned int verb, unsigned int parm, unsigned int *res)
776 unsigned int response;
777 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
780 return ((response == -1) ? -1 : 0);
783 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
784 unsigned short converter_format, unsigned int *res)
786 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
787 converter_format & 0xffff, res);
790 static int codec_set_converter_stream_channel(struct hda_codec *codec,
791 hda_nid_t nid, unsigned char stream,
792 unsigned char channel, unsigned int *res)
794 unsigned char converter_stream_channel = 0;
796 converter_stream_channel = (stream << 4) | (channel & 0x0f);
797 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
798 converter_stream_channel, res);
802 * CA0132 chip access stuffs
804 static int chipio_send(struct hda_codec *codec,
809 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
811 /* send bits of data specified by reg */
813 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
815 if (res == VENDOR_STATUS_CHIPIO_OK)
818 } while (time_before(jiffies, timeout));
824 static int chipio_write_addx(struct hda_codec *codec, u32 chip_addx)
826 struct ca0132_spec *spec = codec->spec;
829 if (spec->curr_chip_addx == chip_addx)
832 /* send low 16 bits of the address */
833 status = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
836 if (SUCCEEDED(status)) {
837 /* send high 16 bits of the address */
838 status = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
842 CTASSERT(SUCCEEDED(status));
843 spec->curr_chip_addx = SUCCEEDED(status) ? chip_addx : ~0UL;
848 static int chipio_write_data(struct hda_codec *codec, u32 data)
850 struct ca0132_spec *spec = codec->spec;
853 /* send low 16 bits of the data */
854 status = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
856 if (SUCCEEDED(status)) {
857 /* send high 16 bits of the data */
858 status = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
862 CTASSERT(SUCCEEDED(status));
863 spec->curr_chip_addx = SUCCEEDED(status) ?
864 (spec->curr_chip_addx + 4) : ~0UL;
869 static int chipio_write_data_multiple(struct hda_codec *codec,
876 return FAIL_MSG(-1, "chipio_write_data null ptr");
878 while ((count-- != 0) && (status == 0))
879 status = chipio_write_data(codec, *data++);
884 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
886 struct ca0132_spec *spec = codec->spec;
890 status = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
892 if (SUCCEEDED(status)) {
894 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
897 if (SUCCEEDED(status)) {
899 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
900 VENDOR_CHIPIO_HIC_READ_DATA, 0);
903 CTASSERT(SUCCEEDED(status));
904 spec->curr_chip_addx = SUCCEEDED(status) ?
905 (spec->curr_chip_addx + 4) : ~0UL;
910 static int chipio_write(struct hda_codec *codec, u32 chip_addx,
913 struct ca0132_spec *spec = codec->spec;
916 mutex_lock(&spec->chipio_mutex);
917 status = chipio_write_addx(codec, chip_addx);
918 if (SUCCEEDED(status))
919 status = chipio_write_data(codec, data);
920 mutex_unlock(&spec->chipio_mutex);
925 static int chipio_write_multiple(struct hda_codec *codec,
930 struct ca0132_spec *spec = codec->spec;
933 mutex_lock(&spec->chipio_mutex);
934 status = chipio_write_addx(codec, chip_addx);
935 if (SUCCEEDED(status))
936 status = chipio_write_data_multiple(codec, data, count);
937 mutex_unlock(&spec->chipio_mutex);
942 static int chipio_read(struct hda_codec *codec, u32 chip_addx,
945 struct ca0132_spec *spec = codec->spec;
948 mutex_lock(&spec->chipio_mutex);
949 status = chipio_write_addx(codec, chip_addx);
950 if (SUCCEEDED(status))
951 status = chipio_read_data(codec, data);
952 mutex_unlock(&spec->chipio_mutex);
957 static void chipio_set_control_flag(struct hda_codec *codec,
958 enum control_flag_id flag_id,
962 unsigned int flag_bit;
964 flag_bit = (flag_state ? 1 : 0);
965 val = (flag_bit << 7) | (flag_id);
966 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
967 VENDOR_CHIPIO_FLAG_SET, val);
970 static void chipio_set_control_param(struct hda_codec *codec,
971 enum control_param_id param_id, int param_val)
973 struct ca0132_spec *spec = codec->spec;
976 if ((param_id < 32) && (param_val < 8)) {
977 val = (param_val << 5) | (param_id);
978 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
979 VENDOR_CHIPIO_PARAM_SET, val);
981 mutex_lock(&spec->chipio_mutex);
982 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
983 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
984 VENDOR_CHIPIO_PARAM_EX_ID_SET,
986 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
987 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
990 CA0132_LOG("set_control_param:FAIL! id=0x%x, val=%d\n",
991 param_id, param_val);
992 mutex_unlock(&spec->chipio_mutex);
996 static void chipio_set_conn_rate(struct hda_codec *codec,
997 int connid, enum ca0132_sample_rate rate)
999 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1000 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1004 static void chipio_enable_clocks(struct hda_codec *codec)
1006 struct ca0132_spec *spec = codec->spec;
1008 mutex_lock(&spec->chipio_mutex);
1009 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1010 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1011 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1012 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1013 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1014 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1015 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1016 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1017 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1018 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1019 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1020 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1021 mutex_unlock(&spec->chipio_mutex);
1026 * CA0132 DSP IO stuffs
1028 static int dspio_send(struct hda_codec *codec, unsigned int reg,
1032 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1034 /* send bits of data specified by reg to dsp */
1036 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1037 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1040 } while (time_before(jiffies, timeout));
1046 static void dspio_write_wait(struct hda_codec *codec)
1049 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1052 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1053 VENDOR_DSPIO_STATUS, 0);
1054 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1055 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1058 } while (time_before(jiffies, timeout));
1061 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1063 struct ca0132_spec *spec = codec->spec;
1066 dspio_write_wait(codec);
1068 mutex_lock(&spec->chipio_mutex);
1069 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1071 if (SUCCEEDED(status))
1072 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1074 mutex_unlock(&spec->chipio_mutex);
1076 /* OK, now check if the write itself has executed*/
1077 if (SUCCEEDED(status))
1078 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1079 VENDOR_DSPIO_STATUS, 0);
1081 if (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL)
1082 CA0132_LOG("dspio_write: SCP_COMMAND_QUEUE_FULL!!!\n\n");
1084 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1088 static int dspio_write_multiple(struct hda_codec *codec,
1089 unsigned int *buffer, unsigned int size)
1094 if ((buffer == NULL))
1098 while (count < size) {
1099 status = dspio_write(codec, *buffer++);
1108 static int dspio_read(struct hda_codec *codec, unsigned int *data)
1112 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1113 if (SUCCEEDED(status))
1114 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1116 if (FAILED(status) ||
1117 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1120 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1121 VENDOR_DSPIO_SCP_READ_DATA, 0);
1126 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
1127 unsigned int *buf_size, unsigned int size_count)
1130 unsigned int size = *buf_size;
1132 unsigned int skip_count;
1135 if ((buffer == NULL))
1139 while (count < size && count < size_count) {
1140 status = dspio_read(codec, buffer++);
1147 if (SUCCEEDED(status)) {
1148 while (skip_count < size) {
1149 status = dspio_read(codec, &dummy);
1160 static inline unsigned int
1161 make_scp_header(unsigned int target_id, unsigned int source_id,
1162 unsigned int get_flag, unsigned int req,
1163 unsigned int device_flag, unsigned int resp_flag,
1164 unsigned int error_flag, unsigned int data_size)
1166 unsigned int header = 0;
1168 header = (data_size & 0x1f) << 27;
1169 header |= (error_flag & 0x01) << 26;
1170 header |= (resp_flag & 0x01) << 25;
1171 header |= (device_flag & 0x01) << 24;
1172 header |= (req & 0x7f) << 17;
1173 header |= (get_flag & 0x01) << 16;
1174 header |= (source_id & 0xff) << 8;
1175 header |= target_id & 0xff;
1181 extract_scp_header(unsigned int header,
1182 unsigned int *target_id, unsigned int *source_id,
1183 unsigned int *get_flag, unsigned int *req,
1184 unsigned int *device_flag, unsigned int *resp_flag,
1185 unsigned int *error_flag, unsigned int *data_size)
1188 *data_size = (header >> 27) & 0x1f;
1190 *error_flag = (header >> 26) & 0x01;
1192 *resp_flag = (header >> 25) & 0x01;
1194 *device_flag = (header >> 24) & 0x01;
1196 *req = (header >> 17) & 0x7f;
1198 *get_flag = (header >> 16) & 0x01;
1200 *source_id = (header >> 8) & 0xff;
1202 *target_id = header & 0xff;
1205 #define SCP_MAX_DATA_WORDS (16)
1207 /* Structure to contain any SCP message */
1210 unsigned int data[SCP_MAX_DATA_WORDS];
1213 static void dspio_clear_response_queue(struct hda_codec *codec)
1215 unsigned int dummy = 0;
1218 /* clear all from the response queue */
1220 status = dspio_read(codec, &dummy);
1221 } while (status == 0);
1224 static int dspio_get_response_data(struct hda_codec *codec)
1226 struct ca0132_spec *spec = codec->spec;
1227 unsigned int data = 0;
1230 if (FAILED(dspio_read(codec, &data)))
1233 CA0132_LOG("dspio_get_response_data: 0x%08x\n", data);
1234 if ((data & 0x00ffffff) == spec->wait_scp_header) {
1235 spec->scp_resp_header = data;
1236 spec->scp_resp_count = data >> 27;
1237 count = spec->wait_num_data;
1238 dspio_read_multiple(codec, spec->scp_resp_data,
1239 &spec->scp_resp_count, count);
1246 static int dspio_send_scp_message(struct hda_codec *codec,
1247 unsigned char *send_buf,
1248 unsigned int send_buf_size,
1249 unsigned char *return_buf,
1250 unsigned int return_buf_size,
1251 unsigned int *bytes_returned)
1253 struct ca0132_spec *spec = codec->spec;
1256 unsigned int scp_send_size = 0;
1257 unsigned int total_size;
1258 bool waiting_for_resp = false;
1259 unsigned int header;
1260 struct scp_msg *ret_msg;
1261 unsigned int resp_src_id, resp_target_id;
1262 unsigned int data_size, src_id, target_id, get_flag, device_flag;
1265 *bytes_returned = 0;
1267 /* get scp header from buffer */
1268 header = *((unsigned int *)send_buf);
1269 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
1270 &device_flag, NULL, NULL, &data_size);
1271 scp_send_size = data_size + 1;
1272 total_size = (scp_send_size * 4);
1274 CTASSERT(send_buf_size >= total_size);
1275 if (send_buf_size < total_size)
1278 if (get_flag || device_flag) {
1279 if (!return_buf || return_buf_size < 4 || !bytes_returned) {
1283 spec->wait_scp_header = *((unsigned int *)send_buf);
1285 /* swap source id with target id */
1286 resp_target_id = src_id;
1287 resp_src_id = target_id;
1288 spec->wait_scp_header &= 0xffff0000;
1289 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
1290 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
1292 waiting_for_resp = true;
1295 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
1297 if (FAILED(status)) {
1303 if (waiting_for_resp) {
1304 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1305 memset(return_buf, 0, return_buf_size);
1308 } while (spec->wait_scp && time_before(jiffies, timeout));
1309 waiting_for_resp = false;
1310 if (!spec->wait_scp) {
1311 ret_msg = (struct scp_msg *)return_buf;
1312 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
1313 memcpy(&ret_msg->data, spec->scp_resp_data,
1314 spec->wait_num_data);
1315 *bytes_returned = (spec->scp_resp_count + 1) * 4;
1318 CTASSERT(*bytes_returned == 0);
1327 static int dspio_scp(struct hda_codec *codec,
1328 int mod_id, int req, int dir, void *data, unsigned int len,
1329 void *reply, unsigned int *reply_len)
1332 struct scp_msg scp_send, scp_reply;
1333 unsigned int ret_bytes, send_size, ret_size;
1334 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
1335 unsigned int reply_data_size;
1337 memset(&scp_send, 0, sizeof(scp_send));
1338 memset(&scp_reply, 0, sizeof(scp_reply));
1340 CTASSERT((len == 0 || data != NULL) && len <= SCP_MAX_DATA_WORDS);
1341 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
1344 CTASSERT(dir != SCP_GET || reply != NULL);
1345 if (dir == SCP_GET && reply == NULL)
1346 return FAIL_MSG(-1, "dspio_scp get but has no buffer");
1348 CTASSERT((reply == NULL) || (reply_len != NULL && (*reply_len > 0)));
1349 if (reply != NULL && (reply_len == NULL || (*reply_len == 0)))
1350 return FAIL_MSG(-1, "dspio_scp bad resp buf len parms");
1352 scp_send.hdr = make_scp_header(mod_id, 0x20, (dir == SCP_GET), req,
1353 0, 0, 0, len/sizeof(unsigned int));
1354 if (data != NULL && len > 0) {
1355 len = min((unsigned int)(sizeof(scp_send.data)), len);
1356 memcpy(scp_send.data, data, len);
1360 send_size = sizeof(unsigned int) + len;
1361 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
1362 send_size, (unsigned char *)&scp_reply,
1363 sizeof(scp_reply), &ret_bytes);
1366 #ifdef ENABLE_CA0132_DEBUG
1368 unsigned int x, *p, i;
1369 unsigned int source_id;
1370 unsigned int target_id;
1372 unsigned int get_flag;
1373 unsigned int resp_flag;
1374 unsigned int device_flag;
1375 unsigned int error_flag;
1376 unsigned int data_size;
1378 memcpy(&x, &scp_send.hdr, sizeof(unsigned int));
1379 extract_scp_header(x, &target_id, &source_id,
1380 &get_flag, &req, &device_flag, &resp_flag,
1381 &error_flag, &data_size);
1384 "ScpDispatch ----- REQ: "
1401 for (x = 0; x < data_size; x++)
1402 snd_printdd("0x%08x ", scp_send.data[x].ui);
1407 if (ret_bytes >= sizeof(scp_reply.hdr)) {
1408 memcpy(&x, &scp_reply.hdr, sizeof(unsigned int));
1409 extract_scp_header(x, &target_id, &source_id,
1410 &get_flag, &req, &device_flag,
1411 &resp_flag, &error_flag, &data_size);
1431 for (x = 0; x < data_size; x++)
1432 snd_printdd("0x%08x ", scp_reply.data[x].ui);
1434 snd_printdd("REP: (too short,nbytes=%d) [", ret_bytes);
1436 for (p = (unsigned int *)&scp_reply, i = 0;
1437 i < ret_bytes; p++, i++) {
1438 snd_printdd("0x%04x ", *p);
1447 return FAIL_MSG(status, "dspio_scp: send scp msg failed");
1449 /* extract send and reply headers members */
1450 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
1451 NULL, NULL, NULL, NULL, NULL);
1452 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
1453 &reply_resp_flag, &reply_error_flag,
1459 if (reply_resp_flag && !reply_error_flag) {
1460 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
1461 / sizeof(unsigned int);
1463 CTASSERT(dir == SCP_GET && reply != NULL && reply_len != NULL);
1465 if (*reply_len < ret_size*sizeof(unsigned int)) {
1466 status = FAIL_MSG(-1, "reply too long for buf");
1467 } else if (ret_size != reply_data_size) {
1468 status = FAIL_MSG(-1, "RetLen and HdrLen .NE.");
1470 *reply_len = ret_size*sizeof(unsigned int);
1471 memcpy(reply, scp_reply.data, *reply_len);
1474 status = FAIL_MSG(-1, "reply ill-formed or errflag set");
1480 static int dspio_set_param(struct hda_codec *codec, int mod_id,
1481 int req, void *data, unsigned int len)
1483 return dspio_scp(codec, mod_id, req, SCP_SET, data, len, NULL, NULL);
1486 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
1489 unsigned int size = sizeof(dma_chan);
1491 CA0132_DSP_LOG(" dspio_alloc_dma_chan() -- begin");
1492 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN,
1493 SCP_GET, NULL, 0, dma_chan, &size);
1495 if (FAILED(status)) {
1496 CA0132_DSP_LOG("dspio_alloc_dma_chan: SCP Failed");
1500 if ((*dma_chan + 1) == 0) {
1501 CA0132_DSP_LOG("no free dma channels to allocate");
1505 CA0132_LOG("dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
1506 CA0132_DSP_LOG(" dspio_alloc_dma_chan() -- complete");
1511 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
1514 unsigned int dummy = 0;
1516 CA0132_DSP_LOG(" dspio_free_dma_chan() -- begin");
1517 CA0132_LOG("dspio_free_dma_chan: chan=%d\n", dma_chan);
1519 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN,
1520 SCP_SET, &dma_chan, sizeof(dma_chan), NULL, &dummy);
1522 if (FAILED(status)) {
1523 CA0132_DSP_LOG("dspio_free_dma_chan: SCP Failed");
1527 CA0132_DSP_LOG(" dspio_free_dma_chan() -- complete");
1533 * CA0132 DSP access stuffs
1535 static int dsp_set_run_state(struct hda_codec *codec)
1537 unsigned int dbg_ctrl_reg;
1538 unsigned int halt_state;
1541 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
1545 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
1546 DSP_DBGCNTL_STATE_LOBIT;
1548 if (halt_state != 0) {
1549 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
1550 DSP_DBGCNTL_SS_MASK);
1551 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
1556 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
1557 DSP_DBGCNTL_EXEC_MASK;
1558 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
1567 static int dsp_reset(struct hda_codec *codec)
1572 CA0132_LOG("dsp_reset\n");
1574 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
1576 } while (res == -1 && retry);
1579 CA0132_LOG("dsp_reset timeout\n");
1586 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
1587 bool *code, bool *yram)
1589 *code = *yram = false;
1591 if (UC_RANGE(chip_addx, 1)) {
1593 return UC_OFF(chip_addx);
1594 } else if (X_RANGE_ALL(chip_addx, 1)) {
1595 return X_OFF(chip_addx);
1596 } else if (Y_RANGE_ALL(chip_addx, 1)) {
1598 return Y_OFF(chip_addx);
1601 return (unsigned int)INVALID_CHIP_ADDRESS;
1604 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
1606 unsigned int dma_chnlstart_reg;
1608 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
1610 return ((dma_chnlstart_reg & (1 <<
1611 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
1614 static int dsp_dma_setup_common(struct hda_codec *codec,
1615 unsigned int chip_addx,
1616 unsigned int dma_chan,
1617 unsigned int port_map_mask,
1621 unsigned int chnl_prop;
1622 unsigned int dsp_addx;
1623 unsigned int active;
1626 CA0132_DSP_LOG("-- dsp_dma_setup_common() -- Begin ---------");
1628 CTASSERT(dma_chan < DSPDMAC_DMA_CFG_CHANNEL_COUNT);
1629 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT)
1630 return FAIL_MSG(-1, "dma chan num invalid");
1632 if (dsp_is_dma_active(codec, dma_chan))
1633 return FAIL_MSG(-1, "dma already active");
1635 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
1637 if (dsp_addx == INVALID_CHIP_ADDRESS)
1638 return FAIL_MSG(-1, "invalid chip addr");
1640 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
1643 CA0132_DSP_LOG(" dsp_dma_setup_common() start reg pgm");
1646 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
1650 return FAIL_MSG(-1, "read CHNLPROP Reg fail");
1652 CA0132_DSP_LOG(" dsp_dma_setup_common() Read CHNLPROP");
1656 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
1658 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
1660 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
1662 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
1664 return FAIL_MSG(-1, "write CHNLPROP Reg fail");
1666 CA0132_DSP_LOG(" dsp_dma_setup_common() Write CHNLPROP");
1669 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
1673 return FAIL_MSG(-1, "read ACTIVE Reg fail");
1675 CA0132_DSP_LOG(" dsp_dma_setup_common() Read ACTIVE");
1678 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
1679 DSPDMAC_ACTIVE_AAR_MASK;
1681 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
1683 return FAIL_MSG(-1, "write ACTIVE Reg fail");
1685 CA0132_DSP_LOG(" dsp_dma_setup_common() Write ACTIVE");
1687 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
1690 return FAIL_MSG(-1, "write AUDCHSEL Reg fail");
1692 CA0132_DSP_LOG(" dsp_dma_setup_common() Write AUDCHSEL");
1694 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
1695 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
1697 return FAIL_MSG(-1, "write IRQCNT Reg fail");
1699 CA0132_DSP_LOG(" dsp_dma_setup_common() Write IRQCNT");
1702 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
1703 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
1704 chip_addx, dsp_addx, dma_chan,
1705 port_map_mask, chnl_prop, active);
1707 CA0132_DSP_LOG("-- dsp_dma_setup_common() -- Complete ---------");
1712 static int dsp_dma_setup(struct hda_codec *codec,
1713 unsigned int chip_addx,
1715 unsigned int dma_chan)
1719 unsigned int dsp_addx;
1720 unsigned int addr_field;
1721 unsigned int incr_field;
1722 unsigned int base_cnt;
1723 unsigned int cur_cnt;
1724 unsigned int dma_cfg = 0;
1725 unsigned int adr_ofs = 0;
1726 unsigned int xfr_cnt = 0;
1727 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
1728 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
1730 CA0132_DSP_LOG("-- dsp_dma_setup() -- Begin ---------");
1732 CTASSERT(count <= max_dma_count);
1733 if (count > max_dma_count)
1734 return FAIL_MSG(-1, "count too big");
1736 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
1737 if (dsp_addx == INVALID_CHIP_ADDRESS)
1738 return FAIL_MSG(-1, "invalid chip addr");
1740 CA0132_DSP_LOG(" dsp_dma_setup() start reg pgm");
1742 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
1748 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
1750 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
1753 CTASSERT((addr_field & DSPDMAC_DMACFG_DBADR_MASK) == addr_field);
1754 dma_cfg = addr_field + incr_field;
1755 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
1758 return FAIL_MSG(-1, "write DMACFG Reg fail");
1760 CA0132_DSP_LOG(" dsp_dma_setup() Write DMACFG");
1762 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
1764 CTASSERT((adr_ofs & DSPDMAC_DSPADROFS_BOFS_MASK) == adr_ofs);
1766 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
1769 return FAIL_MSG(-1, "write DSPADROFS Reg fail");
1771 CA0132_DSP_LOG(" dsp_dma_setup() Write DSPADROFS");
1773 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
1774 CTASSERT((base_cnt & DSPDMAC_XFRCNT_BCNT_MASK) == base_cnt);
1776 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
1777 CTASSERT((cur_cnt & DSPDMAC_XFRCNT_CCNT_MASK) == cur_cnt);
1779 xfr_cnt = base_cnt | cur_cnt;
1781 status = chipio_write(codec,
1782 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
1784 return FAIL_MSG(-1, "write XFRCNT Reg fail");
1786 CA0132_DSP_LOG(" dsp_dma_setup() Write XFRCNT");
1789 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
1790 "ADROFS=0x%x, XFRCNT=0x%x\n",
1791 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
1793 CA0132_DSP_LOG("-- dsp_dma_setup() -- Complete ---------");
1798 static int dsp_dma_start(struct hda_codec *codec,
1799 unsigned int dma_chan, bool ovly)
1801 unsigned int reg = 0;
1804 CA0132_DSP_LOG("-- dsp_dma_start() -- Begin ---------");
1807 status = chipio_read(codec,
1808 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
1811 return FAIL_MSG(-1, "read CHNLSTART reg fail");
1813 CA0132_DSP_LOG("-- dsp_dma_start() Read CHNLSTART");
1815 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
1816 DSPDMAC_CHNLSTART_DIS_MASK);
1819 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
1820 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
1822 return FAIL_MSG(-1, "write CHNLSTART reg fail");
1824 CA0132_DSP_LOG("-- dsp_dma_start() -- Complete ---------");
1829 static int dsp_dma_stop(struct hda_codec *codec,
1830 unsigned int dma_chan, bool ovly)
1832 unsigned int reg = 0;
1835 CA0132_DSP_LOG("-- dsp_dma_stop() -- Begin ---------");
1838 status = chipio_read(codec,
1839 DSPDMAC_CHNLSTART_INST_OFFSET, ®);
1842 return FAIL_MSG(-1, "read CHNLSTART reg fail");
1844 CA0132_DSP_LOG("-- dsp_dma_stop() Read CHNLSTART");
1845 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
1846 DSPDMAC_CHNLSTART_DIS_MASK);
1849 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
1850 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
1852 return FAIL_MSG(-1, "write CHNLSTART reg fail");
1854 CA0132_DSP_LOG("-- dsp_dma_stop() -- Complete ---------");
1859 static int dsp_allocate_router_ports(struct hda_codec *codec,
1860 unsigned int num_chans,
1861 unsigned int ports_per_channel,
1862 unsigned int start_device,
1863 unsigned int *port_map)
1869 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1873 val = start_device << 6;
1874 val |= (ports_per_channel - 1) << 4;
1875 val |= num_chans - 1;
1877 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1878 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
1881 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1882 VENDOR_CHIPIO_PORT_ALLOC_SET,
1885 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1889 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1890 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
1894 return (res < 0) ? -1 : 0;
1897 static int dsp_free_router_ports(struct hda_codec *codec)
1901 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1905 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1906 VENDOR_CHIPIO_PORT_FREE_SET,
1909 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1914 static int dsp_allocate_ports(struct hda_codec *codec,
1915 unsigned int num_chans,
1916 unsigned int rate_multi, unsigned int *port_map)
1920 CA0132_DSP_LOG(" dsp_allocate_ports() -- begin");
1922 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4))
1923 return FAIL_MSG(status, "bad rate multiple");
1925 status = dsp_allocate_router_ports(codec, num_chans,
1926 rate_multi, 0, port_map);
1928 CA0132_DSP_LOG(" dsp_allocate_ports() -- complete");
1933 static int dsp_free_ports(struct hda_codec *codec)
1937 CA0132_DSP_LOG(" dsp_free_ports() -- begin");
1939 status = dsp_free_router_ports(codec);
1941 return FAIL_MSG(-1, "free router ports fail");
1943 CA0132_DSP_LOG(" dsp_free_ports() -- complete");
1948 static int dsp_allocate_ports_format(struct hda_codec *codec,
1949 const unsigned short fmt,
1950 unsigned int *port_map)
1953 unsigned int num_chans;
1955 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
1956 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
1957 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
1959 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4))
1960 return FAIL_MSG(-1, "bad rate multiple");
1962 num_chans = get_hdafmt_chs(fmt) + 1;
1964 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
1970 * HDA DMA engine stuffs for DSP code download
1973 struct hda_codec *codec;
1974 unsigned short m_converter_format;
1975 struct snd_dma_buffer *dmab;
1976 unsigned int buf_size;
1984 static int dma_convert_to_hda_format(
1985 struct hda_stream_format *stream_format,
1986 unsigned short *hda_format)
1988 unsigned int format_val;
1990 format_val = snd_hda_calc_stream_format(
1991 stream_format->sample_rate,
1992 stream_format->number_channels,
1993 SNDRV_PCM_FORMAT_S32_LE,
1994 stream_format->container_size, 0);
1997 *hda_format = (unsigned short)format_val;
2002 static int dma_reset(struct dma_engine *dma)
2004 struct hda_codec *codec = dma->codec;
2005 struct ca0132_spec *spec = codec->spec;
2008 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2010 status = snd_hda_codec_load_dsp_prepare(codec,
2011 dma->m_converter_format,
2016 spec->dsp_stream_id = status;
2021 static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2025 CA0132_LOG("dma_set_state state=%d\n", state);
2028 case DMA_STATE_STOP:
2038 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2042 static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2044 return dma->dmab->bytes;
2047 static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2049 return dma->dmab->area;
2052 static int dma_xfer(struct dma_engine *dma,
2053 const unsigned int *data,
2056 memcpy(dma->dmab->area, data, count);
2060 static void dma_get_converter_format(
2061 struct dma_engine *dma,
2062 unsigned short *format)
2065 *format = dma->m_converter_format;
2068 static unsigned int dma_get_stream_id(struct dma_engine *dma)
2070 struct ca0132_spec *spec = dma->codec->spec;
2072 return spec->dsp_stream_id;
2077 * CA0132 chip DSP image segment stuffs
2079 struct dsp_image_seg {
2086 static const u32 g_magic_value = 0x4c46584d;
2087 static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2089 static bool is_valid(const struct dsp_image_seg *p)
2091 return p->magic == g_magic_value;
2094 static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
2096 return g_chip_addr_magic_value == p->chip_addr;
2099 static bool is_last(const struct dsp_image_seg *p)
2101 return p->count == 0;
2104 static size_t dsp_sizeof(const struct dsp_image_seg *p)
2106 return sizeof(*p) + p->count*sizeof(u32);
2109 static const struct dsp_image_seg *get_next_seg_ptr(
2110 const struct dsp_image_seg *p)
2112 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
2116 * CA0132 chip DSP trannsfer stuffs. For DSP download.
2118 #define INVALID_DMA_CHANNEL (~0UL)
2120 static int dspxfr_hci_write(struct hda_codec *codec,
2121 const struct dsp_image_seg *fls)
2127 CTASSERT(fls != NULL && fls->chip_addr == g_chip_addr_magic_value);
2128 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value)
2129 return FAIL_MSG(-1, "hci_write invalid params");
2132 data = (u32 *)(fls->data);
2133 while (SUCCEEDED(status) && count >= 2) {
2134 status = chipio_write(codec, data[0], data[1]);
2136 status = FAIL_MSG(status, "hci_write chipio failed");
2143 static int dspxfr_one_seg(struct hda_codec *codec,
2144 const struct dsp_image_seg *fls,
2146 struct dma_engine *dma_engine,
2147 unsigned int dma_chan,
2148 unsigned int port_map_mask,
2152 bool comm_dma_setup_done = false;
2153 const unsigned int *data;
2154 unsigned int chip_addx;
2155 unsigned int words_to_write;
2156 unsigned int buffer_size_words;
2157 unsigned char *buffer_addx;
2158 unsigned short hda_format;
2159 unsigned int sample_rate_div;
2160 unsigned int sample_rate_mul;
2161 unsigned int num_chans;
2162 unsigned int hda_frame_size_words;
2163 unsigned int remainder_words;
2164 const u32 *data_remainder;
2165 u32 chip_addx_remainder;
2166 unsigned int run_size_words;
2167 const struct dsp_image_seg *hci_write = NULL;
2168 unsigned long timeout;
2171 CTASSERT(fls != NULL);
2174 if (is_hci_prog_list_seg(fls)) {
2176 fls = get_next_seg_ptr(fls);
2179 if (hci_write && (!fls || is_last(fls))) {
2180 CA0132_LOG("hci_write\n");
2181 return dspxfr_hci_write(codec, hci_write);
2184 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2185 CA0132_LOG("Invalid Params\n");
2190 chip_addx = fls->chip_addr,
2191 words_to_write = fls->count;
2193 if (!words_to_write)
2194 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
2196 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
2198 if (!UC_RANGE(chip_addx, words_to_write) &&
2199 !X_RANGE_ALL(chip_addx, words_to_write) &&
2200 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2201 CA0132_LOG("Invalid chip_addx Params\n");
2205 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
2208 buffer_addx = dma_get_buffer_addr(dma_engine);
2210 if (buffer_addx == NULL)
2211 status = FAIL_MSG(-1, "dma_engine buffer NULL");
2213 dma_get_converter_format(dma_engine, &hda_format);
2214 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
2215 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
2216 num_chans = get_hdafmt_chs(hda_format) + 1;
2218 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
2219 (num_chans * sample_rate_mul / sample_rate_div));
2221 buffer_size_words = min(buffer_size_words,
2222 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2224 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2226 "chpadr=0x%08x frmsz=%u nchan=%u "
2227 "rate_mul=%u div=%u bufsz=%u\n",
2228 chip_addx, hda_frame_size_words, num_chans,
2229 sample_rate_mul, sample_rate_div, buffer_size_words);
2231 CTASSERT(SUCCEEDED(status));
2232 CTASSERT(buffer_addx != NULL);
2233 CTASSERT(buffer_size_words >= hda_frame_size_words);
2234 CTASSERT(hda_frame_size_words > 0);
2236 if ((buffer_addx == NULL) || (hda_frame_size_words == 0) ||
2237 (buffer_size_words < hda_frame_size_words)) {
2238 status = FAIL_MSG(-1, "dspxfr_one_seg:failed");
2244 remainder_words = words_to_write % hda_frame_size_words;
2245 data_remainder = data;
2246 chip_addx_remainder = chip_addx;
2248 data += remainder_words;
2249 chip_addx += remainder_words*sizeof(u32);
2250 words_to_write -= remainder_words;
2252 while ((words_to_write != 0) && SUCCEEDED(status)) {
2253 run_size_words = min(buffer_size_words, words_to_write);
2254 CA0132_LOG("dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2255 words_to_write, run_size_words, remainder_words);
2256 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2257 if (!comm_dma_setup_done && SUCCEEDED(status)) {
2258 status = dsp_dma_stop(codec, dma_chan, ovly);
2259 if (SUCCEEDED(status))
2260 status = dsp_dma_setup_common(codec, chip_addx,
2261 dma_chan, port_map_mask, ovly);
2262 comm_dma_setup_done = true;
2265 if (SUCCEEDED(status))
2266 status = dsp_dma_setup(codec, chip_addx,
2267 run_size_words, dma_chan);
2268 if (SUCCEEDED(status))
2269 status = dsp_dma_start(codec, dma_chan, ovly);
2270 if (SUCCEEDED(status) && !dsp_is_dma_active(codec, dma_chan))
2271 status = FAIL_MSG(-1, "dspxfr:DMA did not start");
2272 if (SUCCEEDED(status))
2273 status = dma_set_state(dma_engine, DMA_STATE_RUN);
2274 if (SUCCEEDED(status)) {
2275 if (remainder_words != 0) {
2276 status = chipio_write_multiple(codec,
2277 chip_addx_remainder,
2280 remainder_words = 0;
2283 status = dspxfr_hci_write(codec, hci_write);
2287 timeout = jiffies + msecs_to_jiffies(2000);
2289 dma_active = dsp_is_dma_active(codec, dma_chan);
2293 } while (time_before(jiffies, timeout));
2296 CA0132_DSP_LOG("+++++ DMA complete");
2297 dma_set_state(dma_engine, DMA_STATE_STOP);
2298 status = dma_reset(dma_engine);
2303 CTASSERT(run_size_words <= words_to_write);
2304 data += run_size_words;
2305 chip_addx += run_size_words*sizeof(u32);
2306 words_to_write -= run_size_words;
2309 if (SUCCEEDED(status) && (remainder_words != 0)) {
2310 status = chipio_write_multiple(codec, chip_addx_remainder,
2311 data_remainder, remainder_words);
2317 static int dspxfr_image(struct hda_codec *codec,
2318 const struct dsp_image_seg *fls_data,
2319 unsigned int reloc, struct hda_stream_format *format,
2322 struct ca0132_spec *spec = codec->spec;
2324 unsigned short hda_format = 0;
2325 unsigned int response;
2326 unsigned char stream_id = 0;
2327 struct dma_engine *dma_engine;
2328 unsigned int dma_chan;
2329 unsigned int port_map_mask;
2331 CTASSERT(fls_data != NULL);
2332 if (fls_data == NULL)
2335 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
2341 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
2342 if (!dma_engine->dmab) {
2344 goto free_dma_engine;
2347 dma_engine->codec = codec;
2348 dma_convert_to_hda_format(format, &hda_format);
2349 dma_engine->m_converter_format = hda_format;
2350 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
2351 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
2355 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
2356 hda_format, &response);
2358 if (FAILED(status)) {
2359 status = FAIL_MSG(status, "set converter format fail");
2360 goto free_dma_engine_and_dmab;
2363 status = snd_hda_codec_load_dsp_prepare(codec,
2364 dma_engine->m_converter_format,
2365 dma_engine->buf_size,
2369 spec->dsp_stream_id = status;
2372 status = dspio_alloc_dma_chan(codec, &dma_chan);
2373 if (FAILED(status)) {
2374 status = FAIL_MSG(status, "alloc dmachan fail");
2375 dma_chan = (unsigned int)INVALID_DMA_CHANNEL;
2381 status = dsp_allocate_ports_format(codec, hda_format,
2383 if (FAILED(status)) {
2384 status = FAIL_MSG(status, "alloc parts fail");
2388 stream_id = dma_get_stream_id(dma_engine);
2389 status = codec_set_converter_stream_channel(codec,
2390 WIDGET_CHIP_CTRL, stream_id, 0, &response);
2391 if (FAILED(status)) {
2392 status = FAIL_MSG(status, "set stream chan fail");
2396 while (SUCCEEDED(status) && (fls_data != NULL) &&
2397 !is_last(fls_data)) {
2398 if (!is_valid(fls_data)) {
2399 status = FAIL_MSG(-1, "FLS check fail");
2402 status = dspxfr_one_seg(codec, fls_data, reloc,
2403 dma_engine, dma_chan,
2404 port_map_mask, ovly);
2405 if (is_hci_prog_list_seg(fls_data))
2406 fls_data = get_next_seg_ptr(fls_data);
2408 CTASSERT(fls_data != NULL);
2409 if ((fls_data != NULL) && !is_last(fls_data))
2410 fls_data = get_next_seg_ptr(fls_data);
2412 CTASSERT(fls_data != NULL);
2415 if (port_map_mask != 0)
2416 status = dsp_free_ports(codec);
2421 status = codec_set_converter_stream_channel(codec,
2422 WIDGET_CHIP_CTRL, 0, 0, &response);
2425 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
2426 status = dspio_free_dma_chan(codec, dma_chan);
2428 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
2429 free_dma_engine_and_dmab:
2430 kfree(dma_engine->dmab);
2438 * CA0132 DSP download stuffs.
2440 static void dspload_post_setup(struct hda_codec *codec)
2442 CA0132_DSP_LOG("---- dspload_post_setup ------");
2444 /*set DSP speaker to 2.0 configuration*/
2445 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
2446 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
2448 /*update write pointer*/
2449 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
2452 static int dspload_image(struct hda_codec *codec,
2453 const struct dsp_image_seg *fls,
2460 struct hda_stream_format stream_format;
2462 CA0132_DSP_LOG("---- dspload_image begin ------");
2463 if (router_chans == 0) {
2465 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
2467 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
2470 stream_format.sample_rate = 48000;
2471 stream_format.number_channels = (unsigned short)router_chans;
2473 while (stream_format.number_channels > 16) {
2474 stream_format.sample_rate *= 2;
2475 stream_format.number_channels /= 2;
2478 stream_format.container_size = 32;
2479 stream_format.valid_bits_per_sample = 32;
2482 CA0132_DSP_LOG("Ready to program DMA");
2484 status = dsp_reset(codec);
2489 CA0132_DSP_LOG("dsp_reset() complete");
2490 status = dspxfr_image(codec, fls, reloc, &stream_format, ovly);
2495 CA0132_DSP_LOG("dspxfr_image() complete");
2496 if (autostart && !ovly) {
2497 dspload_post_setup(codec);
2498 status = dsp_set_run_state(codec);
2501 CA0132_DSP_LOG("LOAD FINISHED");
2507 static int dspload_get_speakereq_addx(struct hda_codec *codec,
2512 struct { unsigned short y, x; } speakereq_info;
2513 unsigned int size = sizeof(speakereq_info);
2515 CA0132_DSP_LOG("dspload_get_speakereq_addx() -- begin");
2516 status = dspio_scp(codec, MASTERCONTROL,
2517 MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS,
2518 SCP_GET, NULL, 0, &speakereq_info, &size);
2520 if (FAILED(status)) {
2521 CA0132_DSP_LOG("dspload_get_speakereq_addx: SCP Failed");
2525 *x = speakereq_info.x;
2526 *y = speakereq_info.y;
2527 CA0132_LOG("dspload_get_speakereq_addx: X=0x%x Y=0x%x\n", *x, *y);
2529 CA0132_DSP_LOG("dspload_get_speakereq_addx() -- complete");
2534 static const struct firmware *fw_speq;
2535 static const struct firmware *fw_efx;
2537 static int request_firmware_cached(const struct firmware **firmware_p,
2538 const char *name, struct device *device)
2541 return 0; /* already loaded */
2542 return request_firmware(firmware_p, name, device);
2545 static void release_cached_firmware(void)
2548 release_firmware(fw_speq);
2552 release_firmware(fw_efx);
2557 static int dspload_speakereq(struct hda_codec *codec)
2560 const struct dsp_image_seg *image;
2563 CA0132_DSP_LOG("dspload_speakereq() -- begin");
2565 if (request_firmware_cached(&fw_speq, SPEQ_FILE,
2566 codec->bus->card->dev) != 0)
2569 image = (struct dsp_image_seg *)(fw_speq->data);
2571 status = dspload_get_speakereq_addx(codec, &x, &y);
2575 status = dspload_image(codec, image, 1, y, 0, 8);
2578 CA0132_DSP_LOG("dspload_speakereq() -- complete");
2583 static bool dspload_is_loaded(struct hda_codec *codec)
2585 unsigned int data = 0;
2588 status = chipio_read(codec, 0x40004, &data);
2589 if (FAILED(status) || (data != 1))
2595 static bool dspload_wait_loaded(struct hda_codec *codec)
2597 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
2600 if (dspload_is_loaded(codec)) {
2601 pr_info("DOWNLOAD OK :-) DSP IS RUNNING.\n");
2605 } while (time_before(jiffies, timeout));
2607 pr_err("DOWNLOAD FAILED!!! DSP IS NOT RUNNING.\n");
2614 static void ca0132_setup_stream(struct hda_codec *codec, hda_nid_t nid,
2616 int channel_id, int format)
2618 unsigned int oldval, newval;
2624 "ca0132_setup_stream: NID=0x%x, stream=0x%x, "
2625 "channel=%d, format=0x%x\n",
2626 nid, stream_tag, channel_id, format);
2628 /* update the format-id if changed */
2629 oldval = snd_hda_codec_read(codec, nid, 0,
2630 AC_VERB_GET_STREAM_FORMAT, 0);
2631 if (oldval != format) {
2633 snd_hda_codec_write(codec, nid, 0,
2634 AC_VERB_SET_STREAM_FORMAT,
2638 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
2639 newval = (stream_tag << 4) | channel_id;
2640 if (oldval != newval) {
2641 snd_hda_codec_write(codec, nid, 0,
2642 AC_VERB_SET_CHANNEL_STREAMID,
2647 static void ca0132_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
2654 CA0132_LOG("ca0132_cleanup_stream: NID=0x%x\n", nid);
2656 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
2660 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
2661 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2667 static unsigned int ca0132_get_playback_latency(struct hda_codec *codec)
2669 struct ca0132_spec *spec = codec->spec;
2670 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
2672 if (!dspload_is_loaded(codec))
2675 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
2676 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
2677 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
2678 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
2680 if (spec->cur_out_type == SPEAKER_OUT)
2681 latency += DSP_SPEAKER_OUT_LATENCY;
2686 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2687 struct hda_codec *codec,
2688 unsigned int stream_tag,
2689 unsigned int format,
2690 struct snd_pcm_substream *substream)
2692 struct ca0132_spec *spec = codec->spec;
2693 struct snd_pcm_runtime *runtime = substream->runtime;
2694 unsigned int latency = ca0132_get_playback_latency(codec);
2696 if (spec->dsp_state == DSP_DOWNLOADING) {
2697 spec->dsp_stream_id = stream_tag;
2701 runtime->delay = bytes_to_frames(runtime, (latency * runtime->rate *
2702 runtime->byte_align) / 1000);
2704 ca0132_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
2708 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2709 struct hda_codec *codec,
2710 struct snd_pcm_substream *substream)
2712 struct ca0132_spec *spec = codec->spec;
2714 if (spec->dsp_state == DSP_DOWNLOADING)
2717 /*Allow stream some time to flush effects tail*/
2720 ca0132_cleanup_stream(codec, spec->dacs[0]);
2728 static unsigned int ca0132_get_capture_latency(struct hda_codec *codec)
2730 struct ca0132_spec *spec = codec->spec;
2731 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
2733 if (!dspload_is_loaded(codec))
2736 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
2737 latency += DSP_CRYSTAL_VOICE_LATENCY;
2741 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2742 struct hda_codec *codec,
2743 unsigned int stream_tag,
2744 unsigned int format,
2745 struct snd_pcm_substream *substream)
2747 struct ca0132_spec *spec = codec->spec;
2748 struct snd_pcm_runtime *runtime = substream->runtime;
2749 unsigned int latency = ca0132_get_capture_latency(codec);
2751 if (spec->dsp_state == DSP_DOWNLOADING)
2754 runtime->delay = bytes_to_frames(runtime, (latency * runtime->rate *
2755 runtime->byte_align) / 1000);
2757 ca0132_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
2761 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2762 struct hda_codec *codec,
2763 struct snd_pcm_substream *substream)
2765 struct ca0132_spec *spec = codec->spec;
2767 if (spec->dsp_state == DSP_DOWNLOADING)
2770 ca0132_cleanup_stream(codec, hinfo->nid);
2780 * Mixer controls helpers.
2782 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
2783 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2785 .subdevice = HDA_SUBDEV_AMP_FLAG, \
2786 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2787 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2788 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2789 .info = ca0132_volume_info, \
2790 .get = ca0132_volume_get, \
2791 .put = ca0132_volume_put, \
2792 .tlv = { .c = ca0132_volume_tlv }, \
2793 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
2795 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
2796 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2798 .subdevice = HDA_SUBDEV_AMP_FLAG, \
2799 .info = snd_hda_mixer_amp_switch_info, \
2800 .get = ca0132_switch_get, \
2801 .put = ca0132_switch_put, \
2802 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
2805 #define CA0132_CODEC_VOL(xname, nid, dir) \
2806 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
2807 #define CA0132_CODEC_MUTE(xname, nid, dir) \
2808 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
2811 /* The followings are for tuning of products */
2812 #ifdef ENABLE_TUNING_CONTROLS
2814 static unsigned int voice_focus_vals_lookup[] = {
2815 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
2816 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
2817 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
2818 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
2819 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
2820 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
2821 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
2822 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
2823 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
2824 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
2825 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
2826 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
2827 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
2828 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
2829 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
2830 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
2831 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
2832 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
2833 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
2834 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
2835 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
2836 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
2837 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
2838 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
2839 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
2840 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
2841 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
2844 static unsigned int mic_svm_vals_lookup[] = {
2845 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
2846 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
2847 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
2848 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
2849 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
2850 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
2851 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
2852 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
2853 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
2854 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
2855 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
2856 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
2857 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
2858 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
2859 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
2860 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
2861 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
2864 static unsigned int equalizer_vals_lookup[] = {
2865 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
2866 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
2867 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
2868 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
2869 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
2870 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
2871 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
2872 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
2876 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
2877 unsigned int *lookup, int idx)
2881 for (i = 0; i < TUNING_CTLS_COUNT; i++)
2882 if (nid == ca0132_tuning_ctls[i].nid)
2885 snd_hda_power_up(codec);
2886 dspio_set_param(codec, ca0132_tuning_ctls[i].mid,
2887 ca0132_tuning_ctls[i].req,
2888 &(lookup[idx]), sizeof(unsigned int));
2889 snd_hda_power_down(codec);
2894 static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
2895 struct snd_ctl_elem_value *ucontrol)
2897 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2898 struct ca0132_spec *spec = codec->spec;
2899 hda_nid_t nid = get_amp_nid(kcontrol);
2900 long *valp = ucontrol->value.integer.value;
2901 int idx = nid - TUNING_CTL_START_NID;
2903 *valp = spec->cur_ctl_vals[idx];
2907 static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
2908 struct snd_ctl_elem_info *uinfo)
2910 int chs = get_amp_channels(kcontrol);
2911 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2912 uinfo->count = chs == 3 ? 2 : 1;
2913 uinfo->value.integer.min = 20;
2914 uinfo->value.integer.max = 180;
2915 uinfo->value.integer.step = 1;
2920 static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
2921 struct snd_ctl_elem_value *ucontrol)
2923 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2924 struct ca0132_spec *spec = codec->spec;
2925 hda_nid_t nid = get_amp_nid(kcontrol);
2926 long *valp = ucontrol->value.integer.value;
2929 idx = nid - TUNING_CTL_START_NID;
2931 if (spec->cur_ctl_vals[idx] == *valp)
2934 spec->cur_ctl_vals[idx] = *valp;
2937 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
2942 static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
2943 struct snd_ctl_elem_info *uinfo)
2945 int chs = get_amp_channels(kcontrol);
2946 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2947 uinfo->count = chs == 3 ? 2 : 1;
2948 uinfo->value.integer.min = 0;
2949 uinfo->value.integer.max = 100;
2950 uinfo->value.integer.step = 1;
2955 static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
2956 struct snd_ctl_elem_value *ucontrol)
2958 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2959 struct ca0132_spec *spec = codec->spec;
2960 hda_nid_t nid = get_amp_nid(kcontrol);
2961 long *valp = ucontrol->value.integer.value;
2964 idx = nid - TUNING_CTL_START_NID;
2966 if (spec->cur_ctl_vals[idx] == *valp)
2969 spec->cur_ctl_vals[idx] = *valp;
2972 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
2977 static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
2978 struct snd_ctl_elem_info *uinfo)
2980 int chs = get_amp_channels(kcontrol);
2981 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2982 uinfo->count = chs == 3 ? 2 : 1;
2983 uinfo->value.integer.min = 0;
2984 uinfo->value.integer.max = 48;
2985 uinfo->value.integer.step = 1;
2990 static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
2991 struct snd_ctl_elem_value *ucontrol)
2993 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2994 struct ca0132_spec *spec = codec->spec;
2995 hda_nid_t nid = get_amp_nid(kcontrol);
2996 long *valp = ucontrol->value.integer.value;
2999 idx = nid - TUNING_CTL_START_NID;
3001 if (spec->cur_ctl_vals[idx] == *valp)
3004 spec->cur_ctl_vals[idx] = *valp;
3007 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
3012 DECLARE_TLV_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
3013 DECLARE_TLV_DB_SCALE(eq_db_scale, -2400, 100, 0);
3015 static int add_tuning_control(struct hda_codec *codec,
3016 hda_nid_t pnid, hda_nid_t nid,
3017 const char *name, int dir)
3020 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3021 struct snd_kcontrol_new knew =
3022 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
3024 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3025 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3030 knew.info = voice_focus_ctl_info;
3031 knew.get = tuning_ctl_get;
3032 knew.put = voice_focus_ctl_put;
3033 knew.tlv.p = voice_focus_db_scale;
3036 knew.info = mic_svm_ctl_info;
3037 knew.get = tuning_ctl_get;
3038 knew.put = mic_svm_ctl_put;
3041 knew.info = equalizer_ctl_info;
3042 knew.get = tuning_ctl_get;
3043 knew.put = equalizer_ctl_put;
3044 knew.tlv.p = eq_db_scale;
3049 knew.private_value =
3050 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
3051 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
3052 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
3055 static int add_tuning_ctls(struct hda_codec *codec)
3060 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
3061 err = add_tuning_control(codec,
3062 ca0132_tuning_ctls[i].parent_nid,
3063 ca0132_tuning_ctls[i].nid,
3064 ca0132_tuning_ctls[i].name,
3065 ca0132_tuning_ctls[i].direct);
3073 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
3075 struct ca0132_spec *spec = codec->spec;
3078 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
3079 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
3080 /* SVM level defaults to 0.74. */
3081 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
3083 /* EQ defaults to 0dB. */
3084 for (i = 2; i < TUNING_CTLS_COUNT; i++)
3085 spec->cur_ctl_vals[i] = 24;
3089 static int ca0132_select_out(struct hda_codec *codec)
3091 struct ca0132_spec *spec = codec->spec;
3092 unsigned int pin_ctl;
3098 CA0132_LOG("ca0132_select_out\n");
3100 snd_hda_power_up(codec);
3102 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
3105 jack_present = snd_hda_jack_detect(codec, spec->out_pins[1]);
3108 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
3111 spec->cur_out_type = HEADPHONE_OUT;
3113 spec->cur_out_type = SPEAKER_OUT;
3115 if (spec->cur_out_type == SPEAKER_OUT) {
3116 CA0132_LOG("ca0132_select_out speaker\n");
3117 /*speaker out config*/
3119 err = dspio_set_param(codec, 0x80, 0x04,
3120 &tmp, sizeof(unsigned int));
3123 /*enable speaker EQ*/
3125 err = dspio_set_param(codec, 0x8f, 0x00,
3126 &tmp, sizeof(unsigned int));
3130 /* disable headphone node */
3131 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
3132 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3133 snd_hda_codec_write(codec, spec->out_pins[1], 0,
3134 AC_VERB_SET_PIN_WIDGET_CONTROL,
3136 /* disable headphone EAPD */
3137 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3138 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
3139 /* enable speaker node */
3140 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
3141 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3142 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3143 AC_VERB_SET_PIN_WIDGET_CONTROL,
3145 /* enable speaker EAPD */
3146 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3147 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
3148 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3149 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3151 CA0132_LOG("ca0132_select_out hp\n");
3152 /*headphone out config*/
3154 err = dspio_set_param(codec, 0x80, 0x04,
3155 &tmp, sizeof(unsigned int));
3158 /*disable speaker EQ*/
3160 err = dspio_set_param(codec, 0x8f, 0x00,
3161 &tmp, sizeof(unsigned int));
3165 /* disable speaker*/
3166 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
3167 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3168 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3169 AC_VERB_SET_PIN_WIDGET_CONTROL,
3171 /* disable speaker EAPD */
3172 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3173 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
3174 /* enable headphone*/
3175 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
3176 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3177 snd_hda_codec_write(codec, spec->out_pins[1], 0,
3178 AC_VERB_SET_PIN_WIDGET_CONTROL,
3180 /* enable headphone EAPD */
3181 snd_hda_codec_write(codec, spec->out_pins[1], 0,
3182 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
3183 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3184 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3188 snd_hda_power_down(codec);
3190 return err < 0 ? err : 0;
3193 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
3194 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
3195 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
3197 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
3199 struct ca0132_spec *spec = codec->spec;
3202 if (!dspload_is_loaded(codec))
3205 /* if CrystalVoice if off, vipsource should be 0 */
3206 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]
3208 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
3209 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
3210 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
3211 if (spec->cur_mic_type == DIGITAL_MIC)
3215 dspio_set_param(codec, 0x80, 0x00, &tmp, sizeof(unsigned int));
3217 dspio_set_param(codec, 0x80, 0x05, &tmp, sizeof(unsigned int));
3219 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
3220 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
3221 if (spec->cur_mic_type == DIGITAL_MIC)
3225 dspio_set_param(codec, 0x80, 0x00, &tmp, sizeof(unsigned int));
3227 dspio_set_param(codec, 0x80, 0x05, &tmp, sizeof(unsigned int));
3229 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
3235 static int ca0132_select_mic(struct hda_codec *codec)
3237 struct ca0132_spec *spec = codec->spec;
3241 CA0132_LOG("ca0132_select_mic\n");
3243 snd_hda_power_up(codec);
3245 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
3248 jack_present = snd_hda_jack_detect(codec, spec->input_pins[0]);
3251 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
3254 spec->cur_mic_type = LINE_MIC_IN;
3256 spec->cur_mic_type = DIGITAL_MIC;
3258 if (spec->cur_mic_type == DIGITAL_MIC) {
3259 /* enable digital Mic */
3260 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
3261 ca0132_set_dmic(codec, 1);
3262 ca0132_mic_boost_set(codec, 0);
3263 /* set voice focus */
3264 ca0132_effects_set(codec, VOICE_FOCUS,
3265 spec->effects_switch
3266 [VOICE_FOCUS - EFFECT_START_NID]);
3268 /* disable digital Mic */
3269 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
3270 ca0132_set_dmic(codec, 0);
3271 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
3272 /* disable voice focus */
3273 ca0132_effects_set(codec, VOICE_FOCUS, 0);
3276 snd_hda_power_down(codec);
3282 * Check if VNODE settings take effect immediately.
3284 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
3286 hda_nid_t *shared_nid)
3288 struct ca0132_spec *spec = codec->spec;
3290 bool effective = false;
3294 nid = spec->shared_out_nid;
3298 nid = spec->shared_mic_nid;
3305 if (effective && shared_nid)
3312 * The following functions are control change helpers.
3313 * They return 0 if no changed. Return 1 if changed.
3315 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
3317 struct ca0132_spec *spec = codec->spec;
3320 /* based on CrystalVoice state to enable VoiceFX. */
3322 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
3323 FLOAT_ONE : FLOAT_ZERO;
3328 dspio_set_param(codec, ca0132_voicefx.mid,
3329 ca0132_voicefx.reqs[0], &tmp, sizeof(unsigned int));
3334 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
3336 struct ca0132_spec *spec = codec->spec;
3338 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
3340 int idx = nid - EFFECT_START_NID;
3342 if ((idx < 0) || (idx >= num_fx))
3343 return 0; /* no changed */
3345 /* for out effect, qualify with PE */
3346 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
3347 /* if PE if off, turn off out effects. */
3348 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3352 /* for in effect, qualify with CrystalVoice */
3353 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
3354 /* if CrystalVoice if off, turn off in effects. */
3355 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3358 /* Voice Focus applies to 2-ch Mic, Digital Mic */
3359 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
3363 CA0132_LOG("ca0132_effect_set: nid=0x%x, val=%ld\n", nid, val);
3365 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
3366 err = dspio_set_param(codec, ca0132_effects[idx].mid,
3367 ca0132_effects[idx].reqs[0],
3368 &on, sizeof(unsigned int));
3370 return 0; /* no changed */
3375 static int ca0132_pe_switch_set(struct hda_codec *codec)
3377 struct ca0132_spec *spec = codec->spec;
3381 CA0132_LOG("ca0132_pe_switch_set: val=%ld\n",
3382 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
3384 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
3385 nid = OUT_EFFECT_START_NID;
3386 /* PE affects all out effects */
3387 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
3388 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
3393 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
3395 struct ca0132_spec *spec = codec->spec;
3399 CA0132_LOG("ca0132_cvoice_switch_set: val=%ld\n",
3400 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
3402 i = IN_EFFECT_START_NID - EFFECT_START_NID;
3403 nid = IN_EFFECT_START_NID;
3404 /* CrystalVoice affects all in effects */
3405 for (; nid < IN_EFFECT_END_NID; nid++, i++)
3406 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
3408 /* including VoiceFX */
3409 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
3411 /* set correct vipsource */
3412 ret |= ca0132_set_vipsource(codec, 1);
3416 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
3418 struct ca0132_spec *spec = codec->spec;
3422 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
3423 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
3425 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
3426 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
3431 static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
3432 struct snd_ctl_elem_value *ucontrol)
3434 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3435 hda_nid_t nid = get_amp_nid(kcontrol);
3436 hda_nid_t shared_nid = 0;
3439 struct ca0132_spec *spec = codec->spec;
3442 if (nid == VNID_HP_SEL) {
3444 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
3446 ca0132_select_out(codec);
3450 if (nid == VNID_AMIC1_SEL) {
3452 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
3454 ca0132_select_mic(codec);
3458 if (nid == VNID_HP_ASEL) {
3459 ca0132_select_out(codec);
3463 if (nid == VNID_AMIC1_ASEL) {
3464 ca0132_select_mic(codec);
3468 /* if effective conditions, then update hw immediately. */
3469 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
3471 int dir = get_amp_direction(kcontrol);
3472 int ch = get_amp_channels(kcontrol);
3475 mutex_lock(&codec->control_mutex);
3476 pval = kcontrol->private_value;
3477 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
3479 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3480 kcontrol->private_value = pval;
3481 mutex_unlock(&codec->control_mutex);
3486 /* End of control change helpers. */
3488 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
3489 struct snd_ctl_elem_info *uinfo)
3491 unsigned int items = sizeof(ca0132_voicefx_presets)
3492 / sizeof(struct ct_voicefx_preset);
3494 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3496 uinfo->value.enumerated.items = items;
3497 if (uinfo->value.enumerated.item >= items)
3498 uinfo->value.enumerated.item = items - 1;
3499 strcpy(uinfo->value.enumerated.name,
3500 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
3504 static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
3505 struct snd_ctl_elem_value *ucontrol)
3507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3508 struct ca0132_spec *spec = codec->spec;
3510 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
3514 static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
3515 struct snd_ctl_elem_value *ucontrol)
3517 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3518 struct ca0132_spec *spec = codec->spec;
3520 int sel = ucontrol->value.enumerated.item[0];
3521 unsigned int items = sizeof(ca0132_voicefx_presets)
3522 / sizeof(struct ct_voicefx_preset);
3527 CA0132_LOG("ca0132_voicefx_put: sel=%d, preset=%s\n",
3528 sel, ca0132_voicefx_presets[sel].name);
3532 * Default needs to qualify with CrystalVoice state.
3534 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
3535 err = dspio_set_param(codec, ca0132_voicefx.mid,
3536 ca0132_voicefx.reqs[i],
3537 &(ca0132_voicefx_presets[sel].vals[i]),
3538 sizeof(unsigned int));
3544 spec->voicefx_val = sel;
3545 /* enable voice fx */
3546 ca0132_voicefx_set(codec, (sel ? 1 : 0));
3552 static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
3553 struct snd_ctl_elem_value *ucontrol)
3555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3556 struct ca0132_spec *spec = codec->spec;
3557 hda_nid_t nid = get_amp_nid(kcontrol);
3558 int ch = get_amp_channels(kcontrol);
3559 long *valp = ucontrol->value.integer.value;
3562 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
3564 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
3568 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
3574 /* effects, include PE and CrystalVoice */
3575 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
3576 *valp = spec->effects_switch[nid - EFFECT_START_NID];
3581 if (nid == spec->input_pins[0]) {
3582 *valp = spec->cur_mic_boost;
3589 static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
3590 struct snd_ctl_elem_value *ucontrol)
3592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3593 struct ca0132_spec *spec = codec->spec;
3594 hda_nid_t nid = get_amp_nid(kcontrol);
3595 int ch = get_amp_channels(kcontrol);
3596 long *valp = ucontrol->value.integer.value;
3599 CA0132_LOG("ca0132_switch_put: nid=0x%x, val=%ld\n", nid, *valp);
3601 snd_hda_power_up(codec);
3603 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
3605 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
3609 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
3612 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
3617 if (nid == PLAY_ENHANCEMENT) {
3618 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
3619 changed = ca0132_pe_switch_set(codec);
3624 if (nid == CRYSTAL_VOICE) {
3625 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
3626 changed = ca0132_cvoice_switch_set(codec);
3630 /* out and in effects */
3631 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
3632 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
3633 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
3634 changed = ca0132_effects_set(codec, nid, *valp);
3639 if (nid == spec->input_pins[0]) {
3640 spec->cur_mic_boost = *valp;
3642 /* Mic boost does not apply to Digital Mic */
3643 if (spec->cur_mic_type != DIGITAL_MIC)
3644 changed = ca0132_mic_boost_set(codec, *valp);
3649 snd_hda_power_down(codec);
3656 static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
3657 struct snd_ctl_elem_info *uinfo)
3659 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3660 struct ca0132_spec *spec = codec->spec;
3661 hda_nid_t nid = get_amp_nid(kcontrol);
3662 int ch = get_amp_channels(kcontrol);
3663 int dir = get_amp_direction(kcontrol);
3669 /* follow shared_out info */
3670 nid = spec->shared_out_nid;
3671 mutex_lock(&codec->control_mutex);
3672 pval = kcontrol->private_value;
3673 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3674 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
3675 kcontrol->private_value = pval;
3676 mutex_unlock(&codec->control_mutex);
3679 /* follow shared_mic info */
3680 nid = spec->shared_mic_nid;
3681 mutex_lock(&codec->control_mutex);
3682 pval = kcontrol->private_value;
3683 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3684 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
3685 kcontrol->private_value = pval;
3686 mutex_unlock(&codec->control_mutex);
3689 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
3694 static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
3695 struct snd_ctl_elem_value *ucontrol)
3697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3698 struct ca0132_spec *spec = codec->spec;
3699 hda_nid_t nid = get_amp_nid(kcontrol);
3700 int ch = get_amp_channels(kcontrol);
3701 long *valp = ucontrol->value.integer.value;
3703 /* store the left and right volume */
3705 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
3709 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
3715 static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
3716 struct snd_ctl_elem_value *ucontrol)
3718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3719 struct ca0132_spec *spec = codec->spec;
3720 hda_nid_t nid = get_amp_nid(kcontrol);
3721 int ch = get_amp_channels(kcontrol);
3722 long *valp = ucontrol->value.integer.value;
3723 hda_nid_t shared_nid = 0;
3727 /* store the left and right volume */
3729 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
3733 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
3737 /* if effective conditions, then update hw immediately. */
3738 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
3740 int dir = get_amp_direction(kcontrol);
3743 snd_hda_power_up(codec);
3744 mutex_lock(&codec->control_mutex);
3745 pval = kcontrol->private_value;
3746 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
3748 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
3749 kcontrol->private_value = pval;
3750 mutex_unlock(&codec->control_mutex);
3751 snd_hda_power_down(codec);
3757 static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
3758 unsigned int size, unsigned int __user *tlv)
3760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3761 struct ca0132_spec *spec = codec->spec;
3762 hda_nid_t nid = get_amp_nid(kcontrol);
3763 int ch = get_amp_channels(kcontrol);
3764 int dir = get_amp_direction(kcontrol);
3770 /* follow shared_out tlv */
3771 nid = spec->shared_out_nid;
3772 mutex_lock(&codec->control_mutex);
3773 pval = kcontrol->private_value;
3774 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3775 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
3776 kcontrol->private_value = pval;
3777 mutex_unlock(&codec->control_mutex);
3780 /* follow shared_mic tlv */
3781 nid = spec->shared_mic_nid;
3782 mutex_lock(&codec->control_mutex);
3783 pval = kcontrol->private_value;
3784 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3785 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
3786 kcontrol->private_value = pval;
3787 mutex_unlock(&codec->control_mutex);
3790 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
3795 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
3796 const char *pfx, int dir)
3799 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3800 struct snd_kcontrol_new knew =
3801 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
3802 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
3803 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
3806 static int add_voicefx(struct hda_codec *codec)
3808 struct snd_kcontrol_new knew =
3809 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
3810 VOICEFX, 1, 0, HDA_INPUT);
3811 knew.info = ca0132_voicefx_info;
3812 knew.get = ca0132_voicefx_get;
3813 knew.put = ca0132_voicefx_put;
3814 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
3818 * When changing Node IDs for Mixer Controls below, make sure to update
3819 * Node IDs in ca0132_config() as well.
3821 static struct snd_kcontrol_new ca0132_mixer[] = {
3822 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
3823 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
3824 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
3825 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
3826 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
3827 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
3828 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
3829 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
3830 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
3831 0x12, 1, HDA_INPUT),
3832 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
3833 VNID_HP_SEL, 1, HDA_OUTPUT),
3834 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
3835 VNID_AMIC1_SEL, 1, HDA_INPUT),
3836 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
3837 VNID_HP_ASEL, 1, HDA_OUTPUT),
3838 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
3839 VNID_AMIC1_ASEL, 1, HDA_INPUT),
3843 static int ca0132_build_controls(struct hda_codec *codec)
3845 struct ca0132_spec *spec = codec->spec;
3849 /* Add Mixer controls */
3850 for (i = 0; i < spec->num_mixers; i++) {
3851 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
3856 /* Add in and out effects controls.
3857 * VoiceFX, PE and CrystalVoice are added separately.
3859 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
3860 for (i = 0; i < num_fx; i++) {
3861 err = add_fx_switch(codec, ca0132_effects[i].nid,
3862 ca0132_effects[i].name,
3863 ca0132_effects[i].direct);
3868 err = add_fx_switch(codec, PLAY_ENHANCEMENT, "PlayEnhancement", 0);
3872 err = add_fx_switch(codec, CRYSTAL_VOICE, "CrystalVoice", 1);
3878 #ifdef ENABLE_TUNING_CONTROLS
3879 add_tuning_ctls(codec);
3882 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
3892 static struct hda_pcm_stream ca0132_pcm_analog_playback = {
3897 .prepare = ca0132_playback_pcm_prepare,
3898 .cleanup = ca0132_playback_pcm_cleanup
3902 static struct hda_pcm_stream ca0132_pcm_analog_capture = {
3907 .prepare = ca0132_capture_pcm_prepare,
3908 .cleanup = ca0132_capture_pcm_cleanup
3912 static int ca0132_build_pcms(struct hda_codec *codec)
3914 struct ca0132_spec *spec = codec->spec;
3915 struct hda_pcm *info = spec->pcm_rec;
3917 codec->pcm_info = info;
3918 codec->num_pcms = 0;
3920 info->name = "CA0132 Analog";
3921 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
3922 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
3923 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
3924 spec->multiout.max_channels;
3925 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
3926 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
3927 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
3931 info->name = "CA0132 Analog Mic-In2";
3932 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
3933 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
3934 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
3938 info->name = "CA0132 What U Hear";
3939 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
3940 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
3941 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
3947 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
3950 snd_hda_codec_write(codec, pin, 0,
3951 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3952 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
3953 snd_hda_codec_write(codec, pin, 0,
3954 AC_VERB_SET_AMP_GAIN_MUTE,
3958 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3962 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
3965 snd_hda_codec_write(codec, pin, 0,
3966 AC_VERB_SET_PIN_WIDGET_CONTROL,
3968 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
3969 snd_hda_codec_write(codec, pin, 0,
3970 AC_VERB_SET_AMP_GAIN_MUTE,
3974 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3977 /* init to 0 dB and unmute. */
3978 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
3979 HDA_AMP_VOLMASK, 0x5a);
3980 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
3985 static void ca0132_init_unsol(struct hda_codec *codec)
3987 snd_hda_jack_detect_enable(codec, UNSOL_TAG_HP, UNSOL_TAG_HP);
3988 snd_hda_jack_detect_enable(codec, UNSOL_TAG_AMIC1, UNSOL_TAG_AMIC1);
3991 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
3995 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
3996 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
3997 snd_hda_override_amp_caps(codec, nid, dir, caps);
4000 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
4002 struct ca0132_spec *spec = codec->spec;
4006 CA0132_LOG("ca0132_set_dmic: enable=%d\n", enable);
4008 ca0132_set_vipsource(codec, 0);
4010 /* set DMic input as 2-ch */
4012 dspio_set_param(codec, 0x80, 0x00, &tmp, sizeof(unsigned int));
4014 val = spec->dmic_ctl;
4016 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4017 VENDOR_CHIPIO_DMIC_CTL_SET, val);
4019 if (!(spec->dmic_ctl & 0x20))
4020 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
4022 /* set AMic input as mono */
4024 dspio_set_param(codec, 0x80, 0x00, &tmp, sizeof(unsigned int));
4026 val = spec->dmic_ctl;
4027 /* clear bit7 and bit5 to disable dmic */
4029 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4030 VENDOR_CHIPIO_DMIC_CTL_SET, val);
4032 if (!(spec->dmic_ctl & 0x20))
4033 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
4035 ca0132_set_vipsource(codec, 1);
4038 static void ca0132_init_dmic(struct hda_codec *codec)
4040 struct ca0132_spec *spec = codec->spec;
4043 /* Setup Digital Mic here, but don't enable.
4044 * Enable based on jack detect.
4047 /* MCLK uses MPIO1, set to enable.
4048 * Bit 2-0: MPIO select
4049 * Bit 3: set to disable
4053 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4054 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
4056 /* Data1 uses MPIO3. Data2 not use
4057 * Bit 2-0: Data1 MPIO select
4058 * Bit 3: set disable Data1
4059 * Bit 6-4: Data2 MPIO select
4060 * Bit 7: set disable Data2
4063 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4064 VENDOR_CHIPIO_DMIC_PIN_SET, val);
4066 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
4067 * Bit 3-0: Channel mask
4068 * Bit 4: set for 48KHz, clear for 32KHz
4070 * Bit 6: set to select Data2, clear for Data1
4071 * Bit 7: set to enable DMic, clear for AMic
4074 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
4075 spec->dmic_ctl = val;
4076 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4077 VENDOR_CHIPIO_DMIC_CTL_SET, val);
4080 static void ca0132_init_analog_mic2(struct hda_codec *codec)
4082 struct ca0132_spec *spec = codec->spec;
4084 mutex_lock(&spec->chipio_mutex);
4085 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4086 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
4087 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4088 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
4089 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4090 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
4091 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4092 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
4093 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4094 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
4095 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4096 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
4097 mutex_unlock(&spec->chipio_mutex);
4100 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
4102 struct ca0132_spec *spec = codec->spec;
4106 CA0132_LOG("ca0132_refresh_widget_caps.\n");
4107 nid = codec->start_nid;
4108 for (i = 0; i < codec->num_nodes; i++, nid++)
4109 codec->wcaps[i] = snd_hda_param_read(codec, nid,
4110 AC_PAR_AUDIO_WIDGET_CAP);
4112 for (i = 0; i < spec->multiout.num_dacs; i++)
4113 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
4115 for (i = 0; i < spec->num_outputs; i++)
4116 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
4118 for (i = 0; i < spec->num_inputs; i++) {
4119 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
4120 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
4124 static void ca0132_setup_defaults(struct hda_codec *codec)
4130 if (!dspload_is_loaded(codec))
4133 /* out, in effects + voicefx */
4134 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
4135 for (idx = 0; idx < num_fx; idx++) {
4136 for (i = 0; i <= ca0132_effects[idx].params; i++) {
4137 dspio_set_param(codec, ca0132_effects[idx].mid,
4138 ca0132_effects[idx].reqs[i],
4139 &(ca0132_effects[idx].def_vals[i]),
4140 sizeof(unsigned int));
4144 /*remove DSP headroom*/
4146 dspio_set_param(codec, 0x96, 0x3C, &tmp, sizeof(unsigned int));
4148 /*set speaker EQ bypass attenuation*/
4149 dspio_set_param(codec, 0x8f, 0x01, &tmp, sizeof(unsigned int));
4151 /* set AMic1 and AMic2 as mono mic */
4153 dspio_set_param(codec, 0x80, 0x00, &tmp, sizeof(unsigned int));
4154 dspio_set_param(codec, 0x80, 0x01, &tmp, sizeof(unsigned int));
4156 /* set AMic1 as CrystalVoice input */
4158 dspio_set_param(codec, 0x80, 0x05, &tmp, sizeof(unsigned int));
4161 static void ca0132_init_flags(struct hda_codec *codec)
4163 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
4164 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
4165 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
4166 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
4167 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
4168 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
4171 static void ca0132_init_params(struct hda_codec *codec)
4173 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
4174 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
4177 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
4179 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
4180 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
4181 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
4182 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
4183 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
4184 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
4186 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4187 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4188 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
4191 static bool ca0132_download_dsp_images(struct hda_codec *codec)
4193 bool dsp_loaded = false;
4194 const struct dsp_image_seg *dsp_os_image;
4196 if (request_firmware_cached(&fw_efx, EFX_FILE,
4197 codec->bus->card->dev) != 0)
4200 dsp_os_image = (struct dsp_image_seg *)(fw_efx->data);
4201 dspload_image(codec, dsp_os_image, 0, 0, true, 0);
4202 dsp_loaded = dspload_wait_loaded(codec);
4205 dspload_speakereq(codec);
4210 static void ca0132_download_dsp(struct hda_codec *codec)
4212 struct ca0132_spec *spec = codec->spec;
4214 spec->dsp_state = DSP_DOWNLOAD_INIT;
4216 if (spec->dsp_state == DSP_DOWNLOAD_INIT) {
4217 chipio_enable_clocks(codec);
4218 spec->dsp_state = DSP_DOWNLOADING;
4219 if (!ca0132_download_dsp_images(codec))
4220 spec->dsp_state = DSP_DOWNLOAD_FAILED;
4222 spec->dsp_state = DSP_DOWNLOADED;
4225 if (spec->dsp_state == DSP_DOWNLOADED)
4226 ca0132_set_dsp_msr(codec, true);
4229 static void ca0132_process_dsp_response(struct hda_codec *codec)
4231 struct ca0132_spec *spec = codec->spec;
4233 CA0132_LOG("ca0132_process_dsp_response\n");
4234 if (spec->wait_scp) {
4235 if (dspio_get_response_data(codec) >= 0)
4239 dspio_clear_response_queue(codec);
4242 static void ca0132_unsol_event(struct hda_codec *codec, unsigned int res)
4244 CA0132_LOG("ca0132_unsol_event: 0x%x\n", res);
4247 if (((res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f) == UNSOL_TAG_DSP) {
4248 ca0132_process_dsp_response(codec);
4250 res = snd_hda_jack_get_action(codec,
4251 (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f);
4253 CA0132_LOG("snd_hda_jack_get_action: 0x%x\n", res);
4257 ca0132_select_out(codec);
4259 case UNSOL_TAG_AMIC1:
4260 ca0132_select_mic(codec);
4265 snd_hda_jack_report_sync(codec);
4273 /* Sends before DSP download. */
4274 static struct hda_verb ca0132_base_init_verbs[] = {
4275 /*enable ct extension*/
4276 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
4277 /*enable DSP node unsol, needed for DSP download*/
4278 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_DSP},
4283 static struct hda_verb ca0132_base_exit_verbs[] = {
4285 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
4286 /*disable ct extension*/
4287 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
4291 /* Other verbs tables. Sends after DSP download. */
4292 static struct hda_verb ca0132_init_verbs0[] = {
4293 /* chip init verbs */
4294 {0x15, 0x70D, 0xF0},
4295 {0x15, 0x70E, 0xFE},
4296 {0x15, 0x707, 0x75},
4297 {0x15, 0x707, 0xD3},
4298 {0x15, 0x707, 0x09},
4299 {0x15, 0x707, 0x53},
4300 {0x15, 0x707, 0xD4},
4301 {0x15, 0x707, 0xEF},
4302 {0x15, 0x707, 0x75},
4303 {0x15, 0x707, 0xD3},
4304 {0x15, 0x707, 0x09},
4305 {0x15, 0x707, 0x02},
4306 {0x15, 0x707, 0x37},
4307 {0x15, 0x707, 0x78},
4308 {0x15, 0x53C, 0xCE},
4309 {0x15, 0x575, 0xC9},
4310 {0x15, 0x53D, 0xCE},
4311 {0x15, 0x5B7, 0xC9},
4312 {0x15, 0x70D, 0xE8},
4313 {0x15, 0x70E, 0xFE},
4314 {0x15, 0x707, 0x02},
4315 {0x15, 0x707, 0x68},
4316 {0x15, 0x707, 0x62},
4317 {0x15, 0x53A, 0xCE},
4318 {0x15, 0x546, 0xC9},
4319 {0x15, 0x53B, 0xCE},
4320 {0x15, 0x5E8, 0xC9},
4321 {0x15, 0x717, 0x0D},
4322 {0x15, 0x718, 0x20},
4326 static struct hda_verb ca0132_init_verbs1[] = {
4327 {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_HP},
4328 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_AMIC1},
4329 /* Set the default configuration for the mic pin because the
4330 * value set in BIOS will be reset after ct extension is enabled.
4332 {0x12, AC_VERB_SET_CONFIG_DEFAULT_BYTES_0, 0xf0},
4333 {0x12, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0x10},
4334 {0x12, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0xa1},
4335 {0x12, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x03},
4337 {0x0b, 0x78D, 0x00},
4338 /*{0x0b, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/
4339 /*{0x10, 0x78D, 0x02},*/
4340 /*{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/
4344 static void ca0132_init_chip(struct hda_codec *codec)
4346 struct ca0132_spec *spec = codec->spec;
4351 mutex_init(&spec->chipio_mutex);
4353 spec->cur_out_type = SPEAKER_OUT;
4354 spec->cur_mic_type = DIGITAL_MIC;
4355 spec->cur_mic_boost = 0;
4357 for (i = 0; i < VNODES_COUNT; i++) {
4358 spec->vnode_lvol[i] = 0x5a;
4359 spec->vnode_rvol[i] = 0x5a;
4360 spec->vnode_lswitch[i] = 0;
4361 spec->vnode_rswitch[i] = 0;
4365 * Default states for effects are in ca0132_effects[].
4367 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
4368 for (i = 0; i < num_fx; i++) {
4369 on = (unsigned int)ca0132_effects[i].reqs[0];
4370 spec->effects_switch[i] = on ? 1 : 0;
4373 spec->voicefx_val = 0;
4374 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
4375 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
4377 #ifdef ENABLE_TUNING_CONTROLS
4378 ca0132_init_tuning_defaults(codec);
4382 static void ca0132_exit_chip(struct hda_codec *codec)
4384 /* put any chip cleanup stuffs here. */
4386 if (dspload_is_loaded(codec))
4390 static int ca0132_init(struct hda_codec *codec)
4392 struct ca0132_spec *spec = codec->spec;
4395 spec->dsp_state = DSP_DOWNLOAD_INIT;
4396 spec->curr_chip_addx = (unsigned int)INVALID_CHIP_ADDRESS;
4398 snd_hda_power_up(codec);
4400 ca0132_init_params(codec);
4401 ca0132_init_flags(codec);
4402 snd_hda_sequence_write(codec, spec->base_init_verbs);
4403 ca0132_download_dsp(codec);
4404 ca0132_refresh_widget_caps(codec);
4405 ca0132_setup_defaults(codec);
4406 ca0132_init_analog_mic2(codec);
4407 ca0132_init_dmic(codec);
4409 for (i = 0; i < spec->num_outputs; i++)
4410 init_output(codec, spec->out_pins[i], spec->dacs[0]);
4412 for (i = 0; i < spec->num_inputs; i++)
4413 init_input(codec, spec->input_pins[i], spec->adcs[i]);
4415 for (i = 0; i < spec->num_init_verbs; i++)
4416 snd_hda_sequence_write(codec, spec->init_verbs[i]);
4418 ca0132_init_unsol(codec);
4420 ca0132_select_out(codec);
4421 ca0132_select_mic(codec);
4423 snd_hda_jack_report_sync(codec);
4425 snd_hda_power_down(codec);
4430 static void ca0132_free(struct hda_codec *codec)
4432 struct ca0132_spec *spec = codec->spec;
4434 snd_hda_power_up(codec);
4435 snd_hda_sequence_write(codec, spec->base_exit_verbs);
4436 ca0132_exit_chip(codec);
4437 snd_hda_power_down(codec);
4442 static struct hda_codec_ops ca0132_patch_ops = {
4443 .build_controls = ca0132_build_controls,
4444 .build_pcms = ca0132_build_pcms,
4445 .init = ca0132_init,
4446 .free = ca0132_free,
4447 .unsol_event = ca0132_unsol_event,
4450 static void ca0132_config(struct hda_codec *codec)
4452 struct ca0132_spec *spec = codec->spec;
4454 spec->dacs[0] = 0x2;
4455 spec->dacs[1] = 0x3;
4456 spec->dacs[2] = 0x4;
4458 spec->multiout.dac_nids = spec->dacs;
4459 spec->multiout.num_dacs = 3;
4460 spec->multiout.max_channels = 2;
4462 spec->num_outputs = 2;
4463 spec->out_pins[0] = 0x0b; /* speaker out */
4464 spec->out_pins[1] = 0x10; /* headphone out */
4465 spec->shared_out_nid = 0x2;
4467 spec->num_inputs = 3;
4468 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
4469 spec->adcs[1] = 0x8; /* analog mic2 */
4470 spec->adcs[2] = 0xa; /* what u hear */
4471 spec->shared_mic_nid = 0x7;
4473 spec->input_pins[0] = 0x12;
4474 spec->input_pins[1] = 0x11;
4475 spec->input_pins[2] = 0x13;
4478 static int patch_ca0132(struct hda_codec *codec)
4480 struct ca0132_spec *spec;
4483 snd_printdd("patch_ca0132\n");
4485 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4490 spec->num_mixers = 1;
4491 spec->mixers[0] = ca0132_mixer;
4493 spec->base_init_verbs = ca0132_base_init_verbs;
4494 spec->base_exit_verbs = ca0132_base_exit_verbs;
4495 spec->init_verbs[0] = ca0132_init_verbs0;
4496 spec->init_verbs[1] = ca0132_init_verbs1;
4497 spec->num_init_verbs = 2;
4499 ca0132_init_chip(codec);
4501 ca0132_config(codec);
4503 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4507 codec->patch_ops = ca0132_patch_ops;
4516 static struct hda_codec_preset snd_hda_preset_ca0132[] = {
4517 { .id = 0x11020011, .name = "CA0132", .patch = patch_ca0132 },
4521 MODULE_ALIAS("snd-hda-codec-id:11020011");
4523 MODULE_LICENSE("GPL");
4524 MODULE_DESCRIPTION("Creative Sound Core3D codec");
4526 static struct hda_codec_preset_list ca0132_list = {
4527 .preset = snd_hda_preset_ca0132,
4528 .owner = THIS_MODULE,
4531 static int __init patch_ca0132_init(void)
4533 return snd_hda_add_codec_preset(&ca0132_list);
4536 static void __exit patch_ca0132_exit(void)
4538 release_cached_firmware();
4539 snd_hda_delete_codec_preset(&ca0132_list);
4542 module_init(patch_ca0132_init)
4543 module_exit(patch_ca0132_exit)