Lines Matching full:codec
3 * HD audio codec driver for Creative CA0132 chip
1135 struct hda_codec *codec;
1181 #define ca0132_quirk(spec) ((spec)->codec->fixup_id)
1525 * CA0132 codec access
1527 static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
1531 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
1537 static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
1540 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
1544 static int codec_set_converter_stream_channel(struct hda_codec *codec,
1551 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
1556 static int chipio_send(struct hda_codec *codec,
1565 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1578 static int chipio_write_address(struct hda_codec *codec,
1581 struct ca0132_spec *spec = codec->spec;
1588 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
1593 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
1605 static int chipio_write_data(struct hda_codec *codec, unsigned int data)
1607 struct ca0132_spec *spec = codec->spec;
1611 res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff);
1615 res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH,
1629 static int chipio_write_data_multiple(struct hda_codec *codec,
1636 codec_dbg(codec, "chipio_write_data null ptr\n");
1641 status = chipio_write_data(codec, *data++);
1650 static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
1652 struct ca0132_spec *spec = codec->spec;
1656 res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0);
1660 res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1665 *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1681 static int chipio_write(struct hda_codec *codec,
1684 struct ca0132_spec *spec = codec->spec;
1690 err = chipio_write_address(codec, chip_addx);
1694 return chipio_write_data(codec, data);
1701 static int chipio_write_no_mutex(struct hda_codec *codec,
1708 err = chipio_write_address(codec, chip_addx);
1712 err = chipio_write_data(codec, data);
1724 static int chipio_write_multiple(struct hda_codec *codec,
1729 struct ca0132_spec *spec = codec->spec;
1733 status = chipio_write_address(codec, chip_addx);
1737 return chipio_write_data_multiple(codec, data, count);
1744 static int chipio_read(struct hda_codec *codec,
1747 struct ca0132_spec *spec = codec->spec;
1753 err = chipio_write_address(codec, chip_addx);
1757 return chipio_read_data(codec, data);
1763 static void chipio_set_control_flag(struct hda_codec *codec,
1772 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1779 static void chipio_set_control_param(struct hda_codec *codec,
1782 struct ca0132_spec *spec = codec->spec;
1787 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1791 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1792 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1795 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1805 static void chipio_set_control_param_no_mutex(struct hda_codec *codec,
1812 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1815 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1816 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1819 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1829 static void chipio_set_stream_source_dest(struct hda_codec *codec,
1832 chipio_set_control_param_no_mutex(codec,
1834 chipio_set_control_param_no_mutex(codec,
1836 chipio_set_control_param_no_mutex(codec,
1843 static void chipio_set_stream_channels(struct hda_codec *codec,
1846 chipio_set_control_param_no_mutex(codec,
1848 chipio_set_control_param_no_mutex(codec,
1855 static void chipio_set_stream_control(struct hda_codec *codec,
1858 chipio_set_control_param_no_mutex(codec,
1860 chipio_set_control_param_no_mutex(codec,
1867 static void chipio_get_stream_control(struct hda_codec *codec,
1870 chipio_set_control_param_no_mutex(codec,
1872 *enable = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1880 static void chipio_set_conn_rate_no_mutex(struct hda_codec *codec,
1883 chipio_set_control_param_no_mutex(codec,
1885 chipio_set_control_param_no_mutex(codec,
1892 static void chipio_set_conn_rate(struct hda_codec *codec,
1895 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1896 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1905 static void chipio_8051_write_direct(struct hda_codec *codec,
1911 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
1922 static void chipio_8051_set_address(struct hda_codec *codec, unsigned int addr)
1928 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1933 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1937 static void chipio_8051_set_data(struct hda_codec *codec, unsigned int data)
1940 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1944 static unsigned int chipio_8051_get_data(struct hda_codec *codec)
1946 return snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1951 static void chipio_8051_set_data_pll(struct hda_codec *codec, unsigned int data)
1954 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1958 static void chipio_8051_write_exram(struct hda_codec *codec,
1961 struct ca0132_spec *spec = codec->spec;
1965 chipio_8051_set_address(codec, addr);
1966 chipio_8051_set_data(codec, data);
1969 static void chipio_8051_write_exram_no_mutex(struct hda_codec *codec,
1972 chipio_8051_set_address(codec, addr);
1973 chipio_8051_set_data(codec, data);
1977 static void chipio_8051_read_exram(struct hda_codec *codec,
1980 chipio_8051_set_address(codec, addr);
1981 *data = chipio_8051_get_data(codec);
1984 static void chipio_8051_write_pll_pmu(struct hda_codec *codec,
1987 struct ca0132_spec *spec = codec->spec;
1991 chipio_8051_set_address(codec, addr & 0xff);
1992 chipio_8051_set_data_pll(codec, data);
1995 static void chipio_8051_write_pll_pmu_no_mutex(struct hda_codec *codec,
1998 chipio_8051_set_address(codec, addr & 0xff);
1999 chipio_8051_set_data_pll(codec, data);
2005 static void chipio_enable_clocks(struct hda_codec *codec)
2007 struct ca0132_spec *spec = codec->spec;
2011 chipio_8051_write_pll_pmu_no_mutex(codec, 0x00, 0xff);
2012 chipio_8051_write_pll_pmu_no_mutex(codec, 0x05, 0x0b);
2013 chipio_8051_write_pll_pmu_no_mutex(codec, 0x06, 0xff);
2019 static int dspio_send(struct hda_codec *codec, unsigned int reg,
2027 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
2039 static void dspio_write_wait(struct hda_codec *codec)
2045 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2057 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
2059 struct ca0132_spec *spec = codec->spec;
2062 dspio_write_wait(codec);
2065 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
2070 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
2076 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2086 static int dspio_write_multiple(struct hda_codec *codec,
2097 status = dspio_write(codec, *buffer++);
2106 static int dspio_read(struct hda_codec *codec, unsigned int *data)
2110 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
2114 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
2119 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
2125 static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
2139 status = dspio_read(codec, buffer++);
2148 status = dspio_read(codec, &dummy);
2218 static void dspio_clear_response_queue(struct hda_codec *codec)
2226 status = dspio_read(codec, &dummy);
2230 static int dspio_get_response_data(struct hda_codec *codec)
2232 struct ca0132_spec *spec = codec->spec;
2236 if (dspio_read(codec, &data) < 0)
2243 dspio_read_multiple(codec, spec->scp_resp_data,
2254 static int dspio_send_scp_message(struct hda_codec *codec,
2261 struct ca0132_spec *spec = codec->spec;
2300 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
2332 * @codec: the HDA codec
2344 static int dspio_scp(struct hda_codec *codec,
2361 codec_dbg(codec, "dspio_scp get but has no buffer\n");
2366 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
2379 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
2384 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
2403 codec_dbg(codec, "reply too long for buf\n");
2406 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
2409 codec_dbg(codec, "NULL reply\n");
2416 codec_dbg(codec, "reply ill-formed or errflag set\n");
2426 static int dspio_set_param(struct hda_codec *codec, int mod_id,
2429 return dspio_scp(codec, mod_id, src_id, req, SCP_SET, data, len, NULL,
2433 static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
2436 return dspio_set_param(codec, mod_id, 0x20, req, &data,
2443 static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
2448 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
2449 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2454 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
2459 codec_dbg(codec, "no free dma channels to allocate\n");
2463 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
2464 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
2472 static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
2477 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
2478 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
2480 status = dspio_scp(codec, MASTERCONTROL, 0x20,
2485 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
2489 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
2497 static int dsp_set_run_state(struct hda_codec *codec)
2503 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
2513 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2520 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
2532 static int dsp_reset(struct hda_codec *codec)
2537 codec_dbg(codec, "dsp_reset\n");
2539 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
2544 codec_dbg(codec, "dsp_reset timeout\n");
2575 static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
2579 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
2585 static int dsp_dma_setup_common(struct hda_codec *codec,
2597 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
2600 codec_dbg(codec, "dma chan num invalid\n");
2604 if (dsp_is_dma_active(codec, dma_chan)) {
2605 codec_dbg(codec, "dma already active\n");
2612 codec_dbg(codec, "invalid chip addr\n");
2619 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
2622 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
2626 codec_dbg(codec, "read CHNLPROP Reg fail\n");
2629 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
2639 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
2641 codec_dbg(codec, "write CHNLPROP Reg fail\n");
2644 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
2647 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
2651 codec_dbg(codec, "read ACTIVE Reg fail\n");
2654 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
2660 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
2662 codec_dbg(codec, "write ACTIVE Reg fail\n");
2666 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
2668 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
2671 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
2674 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
2676 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
2679 codec_dbg(codec, "write IRQCNT Reg fail\n");
2682 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
2684 codec_dbg(codec,
2690 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
2698 static int dsp_dma_setup(struct hda_codec *codec,
2716 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
2719 codec_dbg(codec, "count too big\n");
2725 codec_dbg(codec, "invalid chip addr\n");
2729 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
2743 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
2746 codec_dbg(codec, "write DMACFG Reg fail\n");
2749 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
2754 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
2757 codec_dbg(codec, "write DSPADROFS Reg fail\n");
2760 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
2768 status = chipio_write(codec,
2771 codec_dbg(codec, "write XFRCNT Reg fail\n");
2774 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
2776 codec_dbg(codec,
2781 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
2789 static int dsp_dma_start(struct hda_codec *codec,
2795 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
2798 status = chipio_read(codec,
2802 codec_dbg(codec, "read CHNLSTART reg fail\n");
2805 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
2811 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2814 codec_dbg(codec, "write CHNLSTART reg fail\n");
2817 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
2825 static int dsp_dma_stop(struct hda_codec *codec,
2831 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
2834 status = chipio_read(codec,
2838 codec_dbg(codec, "read CHNLSTART reg fail\n");
2841 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
2846 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
2849 codec_dbg(codec, "write CHNLSTART reg fail\n");
2852 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
2860 * @codec: the HDA codec
2868 static int dsp_allocate_router_ports(struct hda_codec *codec,
2878 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2886 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2890 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2894 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2898 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
2909 static int dsp_free_router_ports(struct hda_codec *codec)
2913 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2917 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
2921 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
2929 static int dsp_allocate_ports(struct hda_codec *codec,
2935 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
2938 codec_dbg(codec, "bad rate multiple\n");
2942 status = dsp_allocate_router_ports(codec, num_chans,
2945 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
2950 static int dsp_allocate_ports_format(struct hda_codec *codec,
2961 codec_dbg(codec, "bad rate multiple\n");
2967 return dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2973 static int dsp_free_ports(struct hda_codec *codec)
2977 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2979 status = dsp_free_router_ports(codec);
2981 codec_dbg(codec, "free router ports fail\n");
2984 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2993 struct hda_codec *codec;
3005 static int dma_convert_to_hda_format(struct hda_codec *codec,
3025 struct hda_codec *codec = dma->codec;
3026 struct ca0132_spec *spec = codec->spec;
3030 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
3032 status = snd_hda_codec_load_dsp_prepare(codec,
3057 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
3089 struct ca0132_spec *spec = dma->codec->spec;
3140 static int dspxfr_hci_write(struct hda_codec *codec,
3148 codec_dbg(codec, "hci_write invalid params\n");
3155 status = chipio_write(codec, data[0], data[1]);
3157 codec_dbg(codec, "hci_write chipio failed\n");
3169 * @codec: the HDA codec
3180 static int dspxfr_one_seg(struct hda_codec *codec,
3216 codec_dbg(codec, "hci_write\n");
3217 return dspxfr_hci_write(codec, hci_write);
3221 codec_dbg(codec, "Invalid Params\n");
3230 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
3237 codec_dbg(codec, "Invalid chip_addx Params\n");
3247 codec_dbg(codec, "dma_engine buffer NULL\n");
3260 codec_dbg(codec, "frmsz zero\n");
3268 codec_dbg(codec,
3275 codec_dbg(codec, "dspxfr_one_seg:failed\n");
3289 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
3293 status = dsp_dma_stop(codec, dma_chan, ovly);
3296 status = dsp_dma_setup_common(codec, chip_addx,
3303 status = dsp_dma_setup(codec, chip_addx,
3307 status = dsp_dma_start(codec, dma_chan, ovly);
3310 if (!dsp_is_dma_active(codec, dma_chan)) {
3311 codec_dbg(codec, "dspxfr:DMA did not start\n");
3318 status = chipio_write_multiple(codec,
3327 status = dspxfr_hci_write(codec, hci_write);
3335 dma_active = dsp_is_dma_active(codec, dma_chan);
3343 codec_dbg(codec, "+++++ DMA complete\n");
3356 status = chipio_write_multiple(codec, chip_addx_remainder,
3366 * @codec: the HDA codec
3376 static int dspxfr_image(struct hda_codec *codec,
3383 struct ca0132_spec *spec = codec->spec;
3405 dma_engine->codec = codec;
3406 dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format);
3413 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
3417 codec_dbg(codec, "set converter format fail\n");
3421 status = snd_hda_codec_load_dsp_prepare(codec,
3430 status = dspio_alloc_dma_chan(codec, &dma_chan);
3432 codec_dbg(codec, "alloc dmachan fail\n");
3439 status = dsp_allocate_ports_format(codec, hda_format,
3442 codec_dbg(codec, "alloc ports fail\n");
3447 status = codec_set_converter_stream_channel(codec,
3450 codec_dbg(codec, "set stream chan fail\n");
3456 codec_dbg(codec, "FLS check fail\n");
3460 status = dspxfr_one_seg(codec, fls_data, reloc,
3474 status = dsp_free_ports(codec);
3479 status = codec_set_converter_stream_channel(codec,
3484 dspio_free_dma_chan(codec, dma_chan);
3487 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
3497 static void dspload_post_setup(struct hda_codec *codec)
3499 struct ca0132_spec *spec = codec->spec;
3500 codec_dbg(codec, "---- dspload_post_setup ------\n");
3503 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
3504 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
3507 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
3514 * @codec: the HDA codec
3529 static int dspload_image(struct hda_codec *codec,
3540 codec_dbg(codec, "---- dspload_image begin ------\n");
3557 codec_dbg(codec, "Ready to program DMA\n");
3559 status = dsp_reset(codec);
3564 codec_dbg(codec, "dsp_reset() complete\n");
3565 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
3571 codec_dbg(codec, "dspxfr_image() complete\n");
3573 dspload_post_setup(codec);
3574 status = dsp_set_run_state(codec);
3577 codec_dbg(codec, "LOAD FINISHED\n");
3584 static bool dspload_is_loaded(struct hda_codec *codec)
3589 status = chipio_read(codec, 0x40004, &data);
3596 #define dspload_is_loaded(codec) false
3599 static bool dspload_wait_loaded(struct hda_codec *codec)
3604 if (dspload_is_loaded(codec)) {
3605 codec_info(codec, "ca0132 DSP downloaded and running\n");
3611 codec_err(codec, "ca0132 failed to download DSP\n");
3630 static void ca0113_mmio_gpio_set(struct hda_codec *codec, unsigned int gpio_pin,
3633 struct ca0132_spec *spec = codec->spec;
3650 static void ca0113_mmio_command_set(struct hda_codec *codec, unsigned int group,
3653 struct ca0132_spec *spec = codec->spec;
3689 static void ca0113_mmio_command_set_type2(struct hda_codec *codec,
3692 struct ca0132_spec *spec = codec->spec;
3729 static void ca0132_gpio_init(struct hda_codec *codec)
3731 struct ca0132_spec *spec = codec->spec;
3737 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3738 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
3739 snd_hda_codec_write(codec, 0x01, 0, 0x790, 0x23);
3742 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
3743 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5B);
3752 static void ca0132_gpio_setup(struct hda_codec *codec)
3754 struct ca0132_spec *spec = codec->spec;
3758 snd_hda_codec_write(codec, 0x01, 0,
3760 snd_hda_codec_write(codec, 0x01, 0,
3762 snd_hda_codec_write(codec, 0x01, 0,
3764 snd_hda_codec_write(codec, 0x01, 0,
3768 snd_hda_codec_write(codec, 0x01, 0,
3770 snd_hda_codec_write(codec, 0x01, 0,
3772 snd_hda_codec_write(codec, 0x01, 0,
3822 static void r3di_gpio_mic_set(struct hda_codec *codec,
3828 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3838 snd_hda_codec_write(codec, codec->core.afg, 0,
3842 static void r3di_gpio_dsp_status_set(struct hda_codec *codec,
3848 cur_gpio = snd_hda_codec_read(codec, 0x01, 0, AC_VERB_GET_GPIO_DATA, 0);
3853 snd_hda_codec_write(codec, codec->core.afg, 0,
3860 snd_hda_codec_write(codec, codec->core.afg, 0,
3867 snd_hda_codec_write(codec, codec->core.afg, 0,
3875 struct hda_codec *codec,
3880 struct ca0132_spec *spec = codec->spec;
3882 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
3888 struct hda_codec *codec,
3891 struct ca0132_spec *spec = codec->spec;
3901 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
3907 struct hda_codec *codec,
3910 struct ca0132_spec *spec = codec->spec;
3935 struct hda_codec *codec,
3938 struct ca0132_spec *spec = codec->spec;
3939 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3943 struct hda_codec *codec,
3948 struct ca0132_spec *spec = codec->spec;
3949 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3954 struct hda_codec *codec,
3957 struct ca0132_spec *spec = codec->spec;
3958 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3962 struct hda_codec *codec,
3965 struct ca0132_spec *spec = codec->spec;
3966 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3973 struct hda_codec *codec,
3978 snd_hda_codec_setup_stream(codec, hinfo->nid,
3985 struct hda_codec *codec,
3988 struct ca0132_spec *spec = codec->spec;
3993 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3998 struct hda_codec *codec,
4001 struct ca0132_spec *spec = codec->spec;
4211 static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
4218 CLASS(snd_hda_power, pm)(codec);
4219 dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20,
4232 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4233 struct ca0132_spec *spec = codec->spec;
4258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4259 struct ca0132_spec *spec = codec->spec;
4272 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
4293 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4294 struct ca0132_spec *spec = codec->spec;
4307 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
4328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4329 struct ca0132_spec *spec = codec->spec;
4342 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
4350 static int add_tuning_control(struct hda_codec *codec,
4387 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
4390 static int add_tuning_ctls(struct hda_codec *codec)
4396 err = add_tuning_control(codec,
4408 static void ca0132_init_tuning_defaults(struct hda_codec *codec)
4410 struct ca0132_spec *spec = codec->spec;
4430 static int ca0132_select_out(struct hda_codec *codec)
4432 struct ca0132_spec *spec = codec->spec;
4439 codec_dbg(codec, "ca0132_select_out\n");
4441 CLASS(snd_hda_power_pm, pm)(codec);
4446 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp);
4457 codec_dbg(codec, "ca0132_select_out speaker\n");
4460 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4465 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4470 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4472 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4474 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4476 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4480 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4482 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4485 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4487 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4490 codec_dbg(codec, "ca0132_select_out hp\n");
4493 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4498 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
4503 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4505 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4507 snd_hda_codec_write(codec, spec->out_pins[1], 0,
4509 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4513 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
4515 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
4518 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
4520 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
4527 static int ae5_headphone_gain_set(struct hda_codec *codec, long val);
4528 static int zxr_headphone_gain_set(struct hda_codec *codec, long val);
4529 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
4531 static void ae5_mmio_select_out(struct hda_codec *codec)
4533 struct ca0132_spec *spec = codec->spec;
4543 ca0113_mmio_command_set(codec, out_cmds->group[i],
4548 static int ca0132_alt_set_full_range_speaker(struct hda_codec *codec)
4550 struct ca0132_spec *spec = codec->spec;
4562 err = dspio_set_uint_param(codec, 0x96,
4569 err = dspio_set_uint_param(codec, 0x96,
4574 err = dspio_set_uint_param(codec, 0x96,
4584 err = dspio_set_uint_param(codec, 0x96,
4593 static int ca0132_alt_surround_set_bass_redirection(struct hda_codec *codec,
4596 struct ca0132_spec *spec = codec->spec;
4606 err = dspio_set_uint_param(codec, 0x96, SPEAKER_BASS_REDIRECT, tmp);
4613 err = dspio_set_uint_param(codec, 0x96,
4626 static void ca0132_alt_select_out_get_quirk_data(struct hda_codec *codec,
4629 struct ca0132_spec *spec = codec->spec;
4642 static int ca0132_alt_select_out_quirk_set(struct hda_codec *codec)
4646 struct ca0132_spec *spec = codec->spec;
4650 ca0132_alt_select_out_get_quirk_data(codec, &quirk_data);
4656 ae5_mmio_select_out(codec);
4659 gpio_data = snd_hda_codec_read(codec, codec->core.afg, 0,
4667 snd_hda_codec_write(codec, codec->core.afg, 0,
4673 ca0113_mmio_gpio_set(codec, out_info->mmio_gpio_pin[i],
4680 err = dspio_set_uint_param(codec,
4689 chipio_set_control_param(codec, 0x0d, out_info->dac2port);
4692 chipio_write(codec, out_info->chipio_write_addr,
4699 ae5_headphone_gain_set(codec, 2);
4701 zxr_headphone_gain_set(codec, 0);
4704 ae5_headphone_gain_set(codec,
4707 zxr_headphone_gain_set(codec,
4715 static void ca0132_set_out_node_pincfg(struct hda_codec *codec, hda_nid_t nid,
4720 pin_ctl = snd_hda_codec_read(codec, nid, 0,
4725 snd_hda_set_pin_ctl(codec, nid, pin_ctl);
4736 static int ca0132_alt_select_out(struct hda_codec *codec)
4738 struct ca0132_spec *spec = codec->spec;
4746 codec_dbg(codec, "%s\n", __func__);
4748 CLASS(snd_hda_power_pm, pm)(codec);
4758 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp) ||
4759 snd_hda_jack_detect(codec, spec->unsol_tag_front_hp);
4771 err = dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_MUTE, FLOAT_ONE);
4775 err = ca0132_alt_select_out_quirk_set(codec);
4781 codec_dbg(codec, "%s speaker\n", __func__);
4784 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4788 ca0132_set_out_node_pincfg(codec, spec->out_pins[1], 0, 0);
4790 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 1, 0);
4792 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 1, 0);
4794 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 1, 0);
4806 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
4812 codec_dbg(codec, "%s hp\n", __func__);
4813 snd_hda_codec_write(codec, spec->out_pins[0], 0,
4817 ca0132_set_out_node_pincfg(codec, spec->out_pins[0], 0, 0);
4818 ca0132_set_out_node_pincfg(codec, spec->out_pins[2], 0, 0);
4819 ca0132_set_out_node_pincfg(codec, spec->out_pins[3], 0, 0);
4822 if (snd_hda_jack_detect(codec, spec->unsol_tag_front_hp))
4824 else if (snd_hda_jack_detect(codec, spec->unsol_tag_hp))
4827 ca0132_set_out_node_pincfg(codec, headphone_nid, 1, 1);
4830 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ONE);
4832 err = dspio_set_uint_param(codec, 0x80, 0x04, FLOAT_ZERO);
4844 ca0132_effects_set(codec, X_BASS,
4848 err = dspio_set_uint_param(codec, 0x8f, 0x01, FLOAT_ZERO);
4856 err = dspio_set_uint_param(codec, 0x96,
4862 err = ca0132_alt_surround_set_bass_redirection(codec,
4865 err = ca0132_alt_surround_set_bass_redirection(codec, 0);
4870 err = dspio_set_uint_param(codec, 0x96,
4876 err = ca0132_alt_set_full_range_speaker(codec);
4891 ca0132_alt_select_out(spec->codec);
4893 ca0132_select_out(spec->codec);
4895 jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp);
4898 snd_hda_jack_report_sync(spec->codec);
4902 static void ca0132_set_dmic(struct hda_codec *codec, int enable);
4903 static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
4904 static void resume_mic1(struct hda_codec *codec, unsigned int oldval);
4905 static int stop_mic1(struct hda_codec *codec);
4906 static int ca0132_cvoice_switch_set(struct hda_codec *codec);
4907 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val);
4912 static int ca0132_set_vipsource(struct hda_codec *codec, int val)
4914 struct ca0132_spec *spec = codec->spec;
4923 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4924 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4925 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4930 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4932 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4934 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4935 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4940 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4942 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4944 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
4950 static int ca0132_alt_set_vipsource(struct hda_codec *codec, int val)
4952 struct ca0132_spec *spec = codec->spec;
4958 codec_dbg(codec, "%s\n", __func__);
4960 chipio_set_stream_control(codec, 0x03, 0);
4961 chipio_set_stream_control(codec, 0x04, 0);
4966 codec_dbg(codec, "%s: off.", __func__);
4967 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
4970 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4972 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4973 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4975 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
4987 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4990 codec_dbg(codec, "%s: on.", __func__);
4991 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
4992 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
4994 chipio_set_conn_rate(codec, 0x0F, SR_16_000);
5000 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5003 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
5006 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
5009 chipio_set_stream_control(codec, 0x03, 1);
5010 chipio_set_stream_control(codec, 0x04, 1);
5021 static int ca0132_select_mic(struct hda_codec *codec)
5023 struct ca0132_spec *spec = codec->spec;
5027 codec_dbg(codec, "ca0132_select_mic\n");
5029 CLASS(snd_hda_power_pm, pm)(codec);
5034 jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1);
5046 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
5047 ca0132_set_dmic(codec, 1);
5048 ca0132_mic_boost_set(codec, 0);
5050 ca0132_effects_set(codec, VOICE_FOCUS,
5055 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
5056 ca0132_set_dmic(codec, 0);
5057 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
5059 ca0132_effects_set(codec, VOICE_FOCUS, 0);
5071 static int ca0132_alt_select_in(struct hda_codec *codec)
5073 struct ca0132_spec *spec = codec->spec;
5076 codec_dbg(codec, "%s\n", __func__);
5078 CLASS(snd_hda_power_pm, pm)(codec);
5080 chipio_set_stream_control(codec, 0x03, 0);
5081 chipio_set_stream_control(codec, 0x04, 0);
5090 ca0113_mmio_gpio_set(codec, 0, false);
5097 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
5101 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5105 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5107 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5109 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5111 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5118 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5119 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5121 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5123 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5125 chipio_set_stream_control(codec, 0x03, 1);
5126 chipio_set_stream_control(codec, 0x04, 1);
5129 chipio_write(codec, 0x18B098, 0x0000000C);
5130 chipio_write(codec, 0x18B09C, 0x0000000C);
5133 chipio_write(codec, 0x18B098, 0x0000000C);
5134 chipio_write(codec, 0x18B09C, 0x000000CC);
5137 chipio_write(codec, 0x18B098, 0x0000000C);
5138 chipio_write(codec, 0x18B09C, 0x0000004C);
5143 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5146 ca0132_mic_boost_set(codec, 0);
5150 ca0113_mmio_gpio_set(codec, 0, false);
5153 r3di_gpio_mic_set(codec, R3DI_REAR_MIC);
5156 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
5159 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5160 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2,
5162 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2,
5164 dspio_set_uint_param(codec, 0x80, 0x01, FLOAT_ZERO);
5170 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5171 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5173 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5179 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5184 chipio_write(codec, 0x18B098, 0x00000000);
5185 chipio_write(codec, 0x18B09C, 0x00000000);
5190 chipio_set_stream_control(codec, 0x03, 1);
5191 chipio_set_stream_control(codec, 0x04, 1);
5197 ca0113_mmio_gpio_set(codec, 0, true);
5198 ca0113_mmio_gpio_set(codec, 5, false);
5202 r3di_gpio_mic_set(codec, R3DI_FRONT_MIC);
5206 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x3f);
5214 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
5215 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
5217 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
5219 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5221 chipio_set_stream_control(codec, 0x03, 1);
5222 chipio_set_stream_control(codec, 0x04, 1);
5226 chipio_write(codec, 0x18B098, 0x0000000C);
5227 chipio_write(codec, 0x18B09C, 0x000000CC);
5230 chipio_write(codec, 0x18B098, 0x0000000C);
5231 chipio_write(codec, 0x18B09C, 0x0000004C);
5236 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5239 ca0132_cvoice_switch_set(codec);
5247 static bool ca0132_is_vnode_effective(struct hda_codec *codec,
5251 struct ca0132_spec *spec = codec->spec;
5275 static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
5277 struct ca0132_spec *spec = codec->spec;
5288 dspio_set_uint_param(codec, ca0132_voicefx.mid,
5297 static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
5299 struct ca0132_spec *spec = codec->spec;
5344 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
5363 dspio_set_uint_param(codec, 0x47, 0x00, tmp);
5372 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
5376 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
5388 static int ca0132_pe_switch_set(struct hda_codec *codec)
5390 struct ca0132_spec *spec = codec->spec;
5394 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
5398 ca0132_alt_select_out(codec);
5404 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5410 static int stop_mic1(struct hda_codec *codec)
5412 struct ca0132_spec *spec = codec->spec;
5413 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
5416 snd_hda_codec_write(codec, spec->adcs[0], 0,
5423 static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
5425 struct ca0132_spec *spec = codec->spec;
5428 snd_hda_codec_write(codec, spec->adcs[0], 0,
5436 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
5438 struct ca0132_spec *spec = codec->spec;
5443 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
5450 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
5453 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
5456 oldval = stop_mic1(codec);
5458 ret |= ca0132_alt_set_vipsource(codec, 1);
5460 ret |= ca0132_set_vipsource(codec, 1);
5461 resume_mic1(codec, oldval);
5465 static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
5467 struct ca0132_spec *spec = codec->spec;
5471 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5474 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5480 static int ca0132_alt_mic_boost_set(struct hda_codec *codec, long val)
5482 struct ca0132_spec *spec = codec->spec;
5485 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
5490 static int ae5_headphone_gain_set(struct hda_codec *codec, long val)
5495 ca0113_mmio_command_set(codec, 0x48, 0x11 + i,
5504 static int zxr_headphone_gain_set(struct hda_codec *codec, long val)
5506 ca0113_mmio_gpio_set(codec, 1, val);
5514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5519 struct ca0132_spec *spec = codec->spec;
5527 ca0132_alt_select_out(codec);
5529 ca0132_select_out(codec);
5538 ca0132_select_mic(codec);
5544 ca0132_alt_select_out(codec);
5546 ca0132_select_out(codec);
5551 ca0132_select_mic(codec);
5556 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
5562 guard(mutex)(&codec->control_mutex);
5574 static void ca0132_alt_bass_redirection_xover_set(struct hda_codec *codec,
5577 CLASS(snd_hda_power, pm)(codec);
5579 dspio_set_param(codec, 0x96, 0x20, SPEAKER_BASS_REDIRECT_XOVER_FREQ,
5592 static int ca0132_alt_slider_ctl_set(struct hda_codec *codec, hda_nid_t nid,
5606 CLASS(snd_hda_power, pm)(codec);
5612 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5621 dspio_set_param(codec, ca0132_effects[i].mid, 0x20,
5632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5633 struct ca0132_spec *spec = codec->spec;
5648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5649 struct ca0132_spec *spec = codec->spec;
5691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5692 struct ca0132_spec *spec = codec->spec;
5711 ca0132_alt_bass_redirection_xover_set(codec, *cur_val);
5713 ca0132_alt_slider_ctl_set(codec, nid, float_xbass_xover_lookup, idx);
5721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5722 struct ca0132_spec *spec = codec->spec;
5735 ca0132_alt_slider_ctl_set(codec, nid, float_zero_to_one_lookup, idx);
5768 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5769 struct ca0132_spec *spec = codec->spec;
5778 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5779 struct ca0132_spec *spec = codec->spec;
5786 codec_dbg(codec, "ca0132_alt_mic_boost: boost=%d\n",
5792 ca0132_alt_mic_boost_set(codec, spec->mic_boost_enum_val);
5822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5823 struct ca0132_spec *spec = codec->spec;
5832 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5833 struct ca0132_spec *spec = codec->spec;
5840 codec_dbg(codec, "ae5_headphone_gain: boost=%d\n",
5846 ae5_headphone_gain_set(codec, spec->ae5_headphone_gain_val);
5875 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5876 struct ca0132_spec *spec = codec->spec;
5885 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5886 struct ca0132_spec *spec = codec->spec;
5893 codec_dbg(codec, "ae5_sound_filter: %s\n",
5898 ca0113_mmio_command_set_type2(codec, 0x48, 0x07,
5925 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5926 struct ca0132_spec *spec = codec->spec;
5935 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5936 struct ca0132_spec *spec = codec->spec;
5950 codec_dbg(codec, "ca0132_alt_input_select: sel=%d, preset=%s\n",
5955 ca0132_alt_select_in(codec);
5977 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5978 struct ca0132_spec *spec = codec->spec;
5987 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5988 struct ca0132_spec *spec = codec->spec;
5996 codec_dbg(codec, "ca0132_alt_output_select: sel=%d, preset=%s\n",
6004 ca0132_alt_select_out(codec);
6028 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6029 struct ca0132_spec *spec = codec->spec;
6038 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6039 struct ca0132_spec *spec = codec->spec;
6046 codec_dbg(codec, "ca0132_alt_speaker_channels: sel=%d, channels=%s\n",
6052 ca0132_alt_select_out(codec);
6081 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6082 struct ca0132_spec *spec = codec->spec;
6091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6092 struct ca0132_spec *spec = codec->spec;
6101 codec_dbg(codec, "ca0132_alt_svm_setting: sel=%d, preset=%s\n",
6121 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
6145 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6146 struct ca0132_spec *spec = codec->spec;
6155 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6156 struct ca0132_spec *spec = codec->spec;
6164 codec_dbg(codec, "%s: sel=%d, preset=%s\n", __func__, sel,
6171 err = dspio_set_uint_param(codec, ca0132_alt_eq_enum.mid,
6202 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6203 struct ca0132_spec *spec = codec->spec;
6212 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6213 struct ca0132_spec *spec = codec->spec;
6220 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
6228 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
6238 ca0132_voicefx_set(codec, (sel ? 1 : 0));
6247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6248 struct ca0132_spec *spec = codec->spec;
6299 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6300 struct ca0132_spec *spec = codec->spec;
6305 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
6308 CLASS(snd_hda_power, pm)(codec);
6325 return ca0132_pe_switch_set(codec);
6331 return ca0132_cvoice_switch_set(codec);
6338 return ca0132_effects_set(codec, nid, *valp);
6346 return ca0132_mic_boost_set(codec, *valp);
6350 return ca0132_mic_boost_set(codec, *valp);
6359 return zxr_headphone_gain_set(codec, *valp);
6367 ca0132_alt_set_full_range_speaker(codec);
6375 ca0132_alt_surround_set_bass_redirection(codec, *valp);
6391 static void ca0132_alt_dsp_volume_put(struct hda_codec *codec, hda_nid_t nid)
6393 struct ca0132_spec *spec = codec->spec;
6404 dspio_set_uint_param(codec,
6411 dspio_set_uint_param(codec,
6416 dspio_set_uint_param(codec,
6424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6425 struct ca0132_spec *spec = codec->spec;
6436 scoped_guard(mutex, &codec->control_mutex) {
6446 scoped_guard(mutex, &codec->control_mutex) {
6462 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6463 struct ca0132_spec *spec = codec->spec;
6483 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6484 struct ca0132_spec *spec = codec->spec;
6503 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
6508 CLASS(snd_hda_power, pm)(codec);
6509 guard(mutex)(&codec->control_mutex);
6528 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6529 struct ca0132_spec *spec = codec->spec;
6554 CLASS(snd_hda_power, pm)(codec);
6555 ca0132_alt_dsp_volume_put(codec, vnid);
6556 guard(mutex)(&codec->control_mutex);
6563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6564 struct ca0132_spec *spec = codec->spec;
6575 scoped_guard(mutex, &codec->control_mutex) {
6585 scoped_guard(mutex, &codec->control_mutex) {
6599 static int ca0132_alt_add_effect_slider(struct hda_codec *codec, hda_nid_t nid,
6626 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6634 static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
6637 struct ca0132_spec *spec = codec->spec;
6650 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
6653 static int add_voicefx(struct hda_codec *codec)
6661 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
6665 static int add_ca0132_alt_eq_presets(struct hda_codec *codec)
6673 return snd_hda_ctl_add(codec, EQ_PRESET_ENUM,
6674 snd_ctl_new1(&knew, codec));
6682 static int ca0132_alt_add_svm_enum(struct hda_codec *codec)
6690 return snd_hda_ctl_add(codec, SMART_VOLUME_ENUM,
6691 snd_ctl_new1(&knew, codec));
6699 static int ca0132_alt_add_output_enum(struct hda_codec *codec)
6707 return snd_hda_ctl_add(codec, OUTPUT_SOURCE_ENUM,
6708 snd_ctl_new1(&knew, codec));
6716 static int ca0132_alt_add_speaker_channel_cfg_enum(struct hda_codec *codec)
6724 return snd_hda_ctl_add(codec, SPEAKER_CHANNEL_CFG_ENUM,
6725 snd_ctl_new1(&knew, codec));
6733 static int ca0132_alt_add_front_full_range_switch(struct hda_codec *codec)
6739 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_FRONT,
6740 snd_ctl_new1(&knew, codec));
6743 static int ca0132_alt_add_rear_full_range_switch(struct hda_codec *codec)
6749 return snd_hda_ctl_add(codec, SPEAKER_FULL_RANGE_REAR,
6750 snd_ctl_new1(&knew, codec));
6759 static int ca0132_alt_add_bass_redirection_crossover(struct hda_codec *codec)
6771 return snd_hda_ctl_add(codec, BASS_REDIRECTION_XOVER,
6772 snd_ctl_new1(&knew, codec));
6775 static int ca0132_alt_add_bass_redirection_switch(struct hda_codec *codec)
6782 return snd_hda_ctl_add(codec, BASS_REDIRECTION,
6783 snd_ctl_new1(&knew, codec));
6791 static int ca0132_alt_add_input_enum(struct hda_codec *codec)
6799 return snd_hda_ctl_add(codec, INPUT_SOURCE_ENUM,
6800 snd_ctl_new1(&knew, codec));
6807 static int ca0132_alt_add_mic_boost_enum(struct hda_codec *codec)
6815 return snd_hda_ctl_add(codec, MIC_BOOST_ENUM,
6816 snd_ctl_new1(&knew, codec));
6825 static int ae5_add_headphone_gain_enum(struct hda_codec *codec)
6833 return snd_hda_ctl_add(codec, AE5_HEADPHONE_GAIN_ENUM,
6834 snd_ctl_new1(&knew, codec));
6842 static int ae5_add_sound_filter_enum(struct hda_codec *codec)
6850 return snd_hda_ctl_add(codec, AE5_SOUND_FILTER_ENUM,
6851 snd_ctl_new1(&knew, codec));
6854 static int zxr_add_headphone_gain_switch(struct hda_codec *codec)
6860 return snd_hda_ctl_add(codec, ZXR_HEADPHONE_GAIN,
6861 snd_ctl_new1(&knew, codec));
6891 static void ca0132_alt_add_chmap_ctls(struct hda_codec *codec)
6896 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
6908 codec_dbg(codec, "snd_pcm_add_chmap_ctls failed!");
6984 static int ca0132_build_controls(struct hda_codec *codec)
6986 struct ca0132_spec *spec = codec->spec;
6992 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
6998 snd_hda_set_vmaster_tlv(codec, spec->dacs[0], HDA_OUTPUT,
7000 snd_hda_add_vmaster(codec, "Master Playback Volume",
7003 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
7023 err = add_fx_switch(codec, ca0132_effects[i].nid,
7030 * If codec has use_alt_controls set to true, add effect level sliders,
7035 err = ca0132_alt_add_svm_enum(codec);
7039 err = add_ca0132_alt_eq_presets(codec);
7043 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
7048 err = add_fx_switch(codec, CRYSTAL_VOICE,
7055 err = ca0132_alt_add_effect_slider(codec,
7063 err = ca0132_alt_add_effect_slider(codec, XBASS_XOVER,
7069 err = add_fx_switch(codec, PLAY_ENHANCEMENT,
7074 err = add_fx_switch(codec, CRYSTAL_VOICE,
7079 err = add_voicefx(codec);
7084 * If the codec uses alt_functions, you need the enumerated controls
7089 err = ca0132_alt_add_output_enum(codec);
7092 err = ca0132_alt_add_speaker_channel_cfg_enum(codec);
7095 err = ca0132_alt_add_front_full_range_switch(codec);
7098 err = ca0132_alt_add_rear_full_range_switch(codec);
7101 err = ca0132_alt_add_bass_redirection_crossover(codec);
7104 err = ca0132_alt_add_bass_redirection_switch(codec);
7107 err = ca0132_alt_add_mic_boost_enum(codec);
7115 err = ca0132_alt_add_input_enum(codec);
7124 err = ae5_add_headphone_gain_enum(codec);
7127 err = ae5_add_sound_filter_enum(codec);
7132 err = zxr_add_headphone_gain_switch(codec);
7141 add_tuning_ctls(codec);
7144 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
7149 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7153 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
7160 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7166 ca0132_alt_add_chmap_ctls(codec);
7171 static int dbpro_build_controls(struct hda_codec *codec)
7173 struct ca0132_spec *spec = codec->spec;
7177 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
7184 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
7235 static int ca0132_build_pcms(struct hda_codec *codec)
7237 struct ca0132_spec *spec = codec->spec;
7240 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
7258 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
7267 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
7277 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7295 static int dbpro_build_pcms(struct hda_codec *codec)
7297 struct ca0132_spec *spec = codec->spec;
7300 info = snd_hda_codec_pcm_new(codec, "CA0132 Alt Analog");
7311 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
7329 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
7332 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
7333 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
7334 snd_hda_codec_write(codec, pin, 0,
7338 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
7339 snd_hda_codec_write(codec, dac, 0,
7343 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
7346 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
7347 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
7348 snd_hda_codec_write(codec, pin, 0,
7352 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
7353 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7357 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7359 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
7364 static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
7368 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
7370 snd_hda_override_amp_caps(codec, nid, dir, caps);
7376 static void ca0132_set_dmic(struct hda_codec *codec, int enable)
7378 struct ca0132_spec *spec = codec->spec;
7383 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
7385 oldval = stop_mic1(codec);
7386 ca0132_set_vipsource(codec, 0);
7390 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7394 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7398 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
7402 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7407 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7411 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
7413 ca0132_set_vipsource(codec, 1);
7414 resume_mic1(codec, oldval);
7420 static void ca0132_init_dmic(struct hda_codec *codec)
7422 struct ca0132_spec *spec = codec->spec;
7435 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7445 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7461 snd_hda_codec_write(codec, spec->input_pins[0], 0,
7468 static void ca0132_init_analog_mic2(struct hda_codec *codec)
7470 struct ca0132_spec *spec = codec->spec;
7474 chipio_8051_write_exram_no_mutex(codec, 0x1920, 0x00);
7475 chipio_8051_write_exram_no_mutex(codec, 0x192d, 0x00);
7478 static void ca0132_refresh_widget_caps(struct hda_codec *codec)
7480 struct ca0132_spec *spec = codec->spec;
7483 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
7484 snd_hda_codec_update_widgets(codec);
7487 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
7490 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
7493 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
7494 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
7500 static void ca0132_alt_free_active_dma_channels(struct hda_codec *codec)
7506 status = chipio_read(codec, DSPDMAC_CHNLSTART_MODULE_OFFSET, &tmp);
7515 codec_dbg(codec, "%s: Failed to read active DSP DMA channel register.\n",
7525 if (dsp_is_dma_active(codec, i)) {
7526 status = dspio_free_dma_chan(codec, i);
7528 codec_dbg(codec, "%s: Failed to free active DSP DMA channel %d.\n",
7555 static void ca0132_alt_start_dsp_audio_streams(struct hda_codec *codec)
7558 struct ca0132_spec *spec = codec->spec;
7567 chipio_get_stream_control(codec, dsp_dma_stream_ids[i], &tmp);
7570 chipio_set_stream_control(codec,
7581 ca0132_alt_free_active_dma_channels(codec);
7586 chipio_set_stream_channels(codec, 0x0c, 6);
7589 chipio_set_stream_control(codec,
7641 static void chipio_remap_stream(struct hda_codec *codec,
7647 chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
7659 chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
7668 codec_info(codec, "%s: Stream 0x%02x ports aren't allocated, remap failed!\n",
7678 chipio_write_no_mutex(codec,
7684 chipio_write_no_mutex(codec, 0x19042c, 0x00000001);
7708 static void ca0132_alt_init_speaker_tuning(struct hda_codec *codec)
7710 struct ca0132_spec *spec = codec->spec;
7731 dspio_set_uint_param(codec, 0x96, SPEAKER_TUNING_ENABLE_CENTER_EQ, tmp);
7736 dspio_set_uint_param(codec, 0x96, i, tmp);
7741 dspio_set_uint_param(codec, 0x96, i, tmp);
7745 dspio_set_uint_param(codec, 0x96,
7752 static void ca0132_alt_init_analog_mics(struct hda_codec *codec)
7754 struct ca0132_spec *spec = codec->spec;
7758 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7759 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7761 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7765 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7768 chipio_set_conn_rate(codec, MEM_CONNID_MICIN2, SR_96_000);
7769 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT2, SR_96_000);
7771 chipio_set_conn_rate(codec, 0x0F, SR_96_000);
7773 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
7782 static void sbz_connect_streams(struct hda_codec *codec)
7784 struct ca0132_spec *spec = codec->spec;
7788 codec_dbg(codec, "Connect Streams entered, mutex locked and loaded.\n");
7791 chipio_write_no_mutex(codec, 0x18a020, 0x00000043);
7794 chipio_set_stream_source_dest(codec, 0x14, 0x48, 0x91);
7795 chipio_set_conn_rate_no_mutex(codec, 0x48, SR_96_000);
7796 chipio_set_conn_rate_no_mutex(codec, 0x91, SR_96_000);
7797 chipio_set_stream_channels(codec, 0x14, 2);
7798 chipio_set_stream_control(codec, 0x14, 1);
7800 codec_dbg(codec, "Connect Streams exited, mutex released.\n");
7809 static void sbz_chipio_startup_data(struct hda_codec *codec)
7812 struct ca0132_spec *spec = codec->spec;
7815 codec_dbg(codec, "Startup Data entered, mutex locked and loaded.\n");
7818 chipio_remap_stream(codec, &stream_remap_data[0]);
7836 chipio_remap_stream(codec, dsp_out_remap_data);
7838 codec_dbg(codec, "Startup Data exited, mutex released.\n");
7841 static void ca0132_alt_dsp_initial_mic_setup(struct hda_codec *codec)
7843 struct ca0132_spec *spec = codec->spec;
7846 chipio_set_stream_control(codec, 0x03, 0);
7847 chipio_set_stream_control(codec, 0x04, 0);
7849 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
7850 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
7853 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
7855 chipio_set_stream_control(codec, 0x03, 1);
7856 chipio_set_stream_control(codec, 0x04, 1);
7860 chipio_write(codec, 0x18b098, 0x0000000c);
7861 chipio_write(codec, 0x18b09C, 0x0000000c);
7864 chipio_write(codec, 0x18b098, 0x0000000c);
7865 chipio_write(codec, 0x18b09c, 0x0000004c);
7872 static void ae5_post_dsp_register_set(struct hda_codec *codec)
7874 struct ca0132_spec *spec = codec->spec;
7876 chipio_8051_write_direct(codec, 0x93, 0x10);
7877 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
7892 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x3f);
7893 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
7894 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7897 static void ae5_post_dsp_param_setup(struct hda_codec *codec)
7904 chipio_set_control_param(codec, 3, 0);
7909 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
7911 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
7912 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
7914 chipio_8051_write_exram(codec, 0xfa92, 0x22);
7917 static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
7919 chipio_8051_write_pll_pmu(codec, 0x41, 0xc8);
7920 chipio_8051_write_pll_pmu(codec, 0x45, 0xcc);
7921 chipio_8051_write_pll_pmu(codec, 0x40, 0xcb);
7922 chipio_8051_write_pll_pmu(codec, 0x43, 0xc7);
7923 chipio_8051_write_pll_pmu(codec, 0x51, 0x8d);
7926 static void ae5_post_dsp_stream_setup(struct hda_codec *codec)
7928 struct ca0132_spec *spec = codec->spec;
7932 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
7934 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
7936 chipio_set_stream_source_dest(codec, 0x5, 0x43, 0x0);
7938 chipio_set_stream_source_dest(codec, 0x18, 0x9, 0xd0);
7939 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
7940 chipio_set_stream_channels(codec, 0x18, 6);
7941 chipio_set_stream_control(codec, 0x18, 1);
7943 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
7945 chipio_8051_write_pll_pmu_no_mutex(codec, 0x43, 0xc7);
7947 ca0113_mmio_command_set(codec, 0x48, 0x01, 0x80);
7950 static void ae5_post_dsp_startup_data(struct hda_codec *codec)
7952 struct ca0132_spec *spec = codec->spec;
7956 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
7957 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
7958 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
7959 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
7961 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7962 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
7963 ca0113_mmio_command_set(codec, 0x48, 0x0b, 0x12);
7964 ca0113_mmio_command_set(codec, 0x48, 0x04, 0x00);
7965 ca0113_mmio_command_set(codec, 0x48, 0x06, 0x48);
7966 ca0113_mmio_command_set(codec, 0x48, 0x0a, 0x05);
7967 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
7968 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7969 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7970 ca0113_mmio_gpio_set(codec, 0, true);
7971 ca0113_mmio_gpio_set(codec, 1, true);
7972 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x80);
7974 chipio_write_no_mutex(codec, 0x18b03c, 0x00000012);
7976 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
7977 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
7980 static void ae7_post_dsp_setup_ports(struct hda_codec *codec)
7982 struct ca0132_spec *spec = codec->spec;
7987 chipio_remap_stream(codec, &stream_remap_data[1]);
7989 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
7990 ca0113_mmio_command_set(codec, 0x48, 0x0d, 0x40);
7991 ca0113_mmio_command_set(codec, 0x48, 0x17, 0x00);
7992 ca0113_mmio_command_set(codec, 0x48, 0x19, 0x00);
7993 ca0113_mmio_command_set(codec, 0x48, 0x11, 0xff);
7994 ca0113_mmio_command_set(codec, 0x48, 0x12, 0xff);
7995 ca0113_mmio_command_set(codec, 0x48, 0x13, 0xff);
7996 ca0113_mmio_command_set(codec, 0x48, 0x14, 0x7f);
7999 static void ae7_post_dsp_asi_stream_setup(struct hda_codec *codec)
8001 struct ca0132_spec *spec = codec->spec;
8005 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x81);
8006 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8008 chipio_set_conn_rate_no_mutex(codec, 0x70, SR_96_000);
8010 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
8011 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
8013 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
8014 chipio_set_stream_channels(codec, 0x18, 6);
8015 chipio_set_stream_control(codec, 0x18, 1);
8017 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 4);
8020 static void ae7_post_dsp_pll_setup(struct hda_codec *codec)
8031 chipio_8051_write_pll_pmu_no_mutex(codec, addr[i], data[i]);
8034 static void ae7_post_dsp_asi_setup_ports(struct hda_codec *codec)
8036 struct ca0132_spec *spec = codec->spec;
8047 chipio_8051_write_pll_pmu_no_mutex(codec, 0x43, 0xc7);
8049 chipio_write_no_mutex(codec, 0x189000, 0x0001f101);
8050 chipio_write_no_mutex(codec, 0x189004, 0x0001f101);
8051 chipio_write_no_mutex(codec, 0x189024, 0x00014004);
8052 chipio_write_no_mutex(codec, 0x189028, 0x0002000f);
8054 ae7_post_dsp_pll_setup(codec);
8055 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8058 ca0113_mmio_command_set(codec, 0x48, target[i], data[i]);
8060 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8061 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8062 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8064 chipio_set_stream_source_dest(codec, 0x21, 0x64, 0x56);
8065 chipio_set_stream_channels(codec, 0x21, 2);
8066 chipio_set_conn_rate_no_mutex(codec, 0x56, SR_8_000);
8068 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_NODE_ID, 0x09);
8074 chipio_set_control_param_no_mutex(codec, 0x20, 0x21);
8076 chipio_write_no_mutex(codec, 0x18b038, 0x00000088);
8087 ca0113_mmio_gpio_set(codec, 0, 1);
8088 ca0113_mmio_gpio_set(codec, 1, 1);
8090 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8091 chipio_write_no_mutex(codec, 0x18b03c, 0x00000000);
8092 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x00);
8093 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x00);
8095 chipio_set_stream_source_dest(codec, 0x05, 0x43, 0x00);
8096 chipio_set_stream_source_dest(codec, 0x18, 0x09, 0xd0);
8098 chipio_set_conn_rate_no_mutex(codec, 0xd0, SR_96_000);
8099 chipio_set_stream_channels(codec, 0x18, 6);
8105 ae7_post_dsp_pll_setup(codec);
8106 chipio_set_control_param_no_mutex(codec, CONTROL_PARAM_ASI, 7);
8114 static void ae7_post_dsp_asi_setup(struct hda_codec *codec)
8116 chipio_8051_write_direct(codec, 0x93, 0x10);
8118 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
8120 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8121 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8123 chipio_set_control_param(codec, 3, 3);
8124 chipio_set_control_flag(codec, CONTROL_FLAG_ASI_96KHZ, 1);
8126 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
8127 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8128 snd_hda_codec_write(codec, 0x17, 0, 0x794, 0x00);
8130 chipio_8051_write_exram(codec, 0xfa92, 0x22);
8132 ae7_post_dsp_pll_setup(codec);
8133 ae7_post_dsp_asi_stream_setup(codec);
8135 chipio_8051_write_pll_pmu(codec, 0x43, 0xc7);
8137 ae7_post_dsp_asi_setup_ports(codec);
8143 static void ca0132_setup_defaults(struct hda_codec *codec)
8145 struct ca0132_spec *spec = codec->spec;
8157 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
8165 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8168 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
8172 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
8173 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
8177 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
8181 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8188 static void r3d_setup_defaults(struct hda_codec *codec)
8190 struct ca0132_spec *spec = codec->spec;
8198 ca0132_alt_init_analog_mics(codec);
8199 ca0132_alt_start_dsp_audio_streams(codec);
8203 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8207 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8208 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8211 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8214 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADED);
8218 ca0113_mmio_gpio_set(codec, 2, false);
8219 ca0113_mmio_gpio_set(codec, 4, true);
8226 dspio_set_uint_param(codec,
8238 static void sbz_setup_defaults(struct hda_codec *codec)
8240 struct ca0132_spec *spec = codec->spec;
8248 ca0132_alt_init_analog_mics(codec);
8249 ca0132_alt_start_dsp_audio_streams(codec);
8250 sbz_connect_streams(codec);
8251 sbz_chipio_startup_data(codec);
8258 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8259 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8263 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8267 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8268 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8271 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8273 ca0132_alt_dsp_initial_mic_setup(codec);
8279 dspio_set_uint_param(codec,
8286 ca0132_alt_init_speaker_tuning(codec);
8292 static void ae5_setup_defaults(struct hda_codec *codec)
8294 struct ca0132_spec *spec = codec->spec;
8302 ca0132_alt_init_analog_mics(codec);
8303 ca0132_alt_start_dsp_audio_streams(codec);
8307 dspio_set_uint_param(codec, 0x96, 0x29, tmp);
8308 dspio_set_uint_param(codec, 0x96, 0x2a, tmp);
8309 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8310 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8312 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8313 ca0113_mmio_gpio_set(codec, 0, false);
8314 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8318 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8319 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8323 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8327 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8328 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8331 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8333 ca0132_alt_dsp_initial_mic_setup(codec);
8334 ae5_post_dsp_register_set(codec);
8335 ae5_post_dsp_param_setup(codec);
8336 ae5_post_dsp_pll_setup(codec);
8337 ae5_post_dsp_stream_setup(codec);
8338 ae5_post_dsp_startup_data(codec);
8344 dspio_set_uint_param(codec,
8351 ca0132_alt_init_speaker_tuning(codec);
8357 static void ae7_setup_defaults(struct hda_codec *codec)
8359 struct ca0132_spec *spec = codec->spec;
8367 ca0132_alt_init_analog_mics(codec);
8368 ca0132_alt_start_dsp_audio_streams(codec);
8369 ae7_post_dsp_setup_ports(codec);
8372 dspio_set_uint_param(codec, 0x96,
8374 dspio_set_uint_param(codec, 0x96,
8377 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
8380 dspio_set_uint_param(codec, 0x80, 0x0d, tmp);
8381 dspio_set_uint_param(codec, 0x80, 0x0e, tmp);
8383 ca0113_mmio_gpio_set(codec, 0, false);
8387 dspio_set_uint_param(codec, 0x37, 0x08, tmp);
8388 dspio_set_uint_param(codec, 0x37, 0x10, tmp);
8392 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
8396 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
8397 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8400 dspio_set_uint_param(codec, 0x32, 0x00, tmp);
8401 ca0113_mmio_command_set(codec, 0x30, 0x28, 0x00);
8407 ca0132_alt_init_analog_mics(codec);
8409 ae7_post_dsp_asi_setup(codec);
8415 ca0113_mmio_gpio_set(codec, 0, true);
8416 ca0113_mmio_gpio_set(codec, 1, true);
8419 ca0113_mmio_command_set(codec, 0x48, 0x0f, 0x04);
8420 ca0113_mmio_command_set(codec, 0x48, 0x10, 0x04);
8421 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x80);
8427 dspio_set_uint_param(codec,
8434 ca0132_alt_init_speaker_tuning(codec);
8440 static void ca0132_init_flags(struct hda_codec *codec)
8442 struct ca0132_spec *spec = codec->spec;
8445 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, 1);
8446 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, 1);
8447 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, 1);
8448 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, 1);
8449 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, 1);
8450 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8451 chipio_set_control_flag(codec, CONTROL_FLAG_SPDIF2OUT, 0);
8452 chipio_set_control_flag(codec,
8454 chipio_set_control_flag(codec,
8457 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8458 chipio_set_control_flag(codec,
8460 chipio_set_control_flag(codec,
8462 chipio_set_control_flag(codec,
8464 chipio_set_control_flag(codec,
8466 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
8473 static void ca0132_init_params(struct hda_codec *codec)
8475 struct ca0132_spec *spec = codec->spec;
8478 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8479 chipio_set_conn_rate(codec, 0x0B, SR_48_000);
8480 chipio_set_control_param(codec, CONTROL_PARAM_SPDIF1_SOURCE, 0);
8481 chipio_set_control_param(codec, 0, 0);
8482 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
8485 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
8486 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
8489 static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
8491 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
8492 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
8493 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
8494 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
8495 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
8496 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
8498 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
8499 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
8500 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
8503 static bool ca0132_download_dsp_images(struct hda_codec *codec)
8506 struct ca0132_spec *spec = codec->spec;
8519 codec->card->dev) != 0)
8520 codec_dbg(codec, "Desktop firmware not found.");
8522 codec_dbg(codec, "Desktop firmware selected.");
8526 codec->card->dev) != 0)
8527 codec_dbg(codec, "Recon3Di alt firmware not detected.");
8529 codec_dbg(codec, "Recon3Di firmware selected.");
8536 * exists for your particular codec.
8539 codec_dbg(codec, "Default firmware selected.");
8541 codec->card->dev) != 0)
8546 if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) {
8547 codec_err(codec, "ca0132 DSP load image failed\n");
8551 dsp_loaded = dspload_wait_loaded(codec);
8559 static void ca0132_download_dsp(struct hda_codec *codec)
8561 struct ca0132_spec *spec = codec->spec;
8570 chipio_enable_clocks(codec);
8574 if (!ca0132_download_dsp_images(codec))
8582 ca0132_set_dsp_msr(codec, true);
8585 static void ca0132_process_dsp_response(struct hda_codec *codec,
8588 struct ca0132_spec *spec = codec->spec;
8590 codec_dbg(codec, "ca0132_process_dsp_response\n");
8591 CLASS(snd_hda_power_pm, pm)(codec);
8593 if (dspio_get_response_data(codec) >= 0)
8597 dspio_clear_response_queue(codec);
8600 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8602 struct ca0132_spec *spec = codec->spec;
8608 tbl = snd_hda_jack_tbl_get(codec, cb->nid);
8614 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
8616 struct ca0132_spec *spec = codec->spec;
8619 ca0132_alt_select_in(codec);
8621 ca0132_select_mic(codec);
8624 static void ca0132_setup_unsol(struct hda_codec *codec)
8626 struct ca0132_spec *spec = codec->spec;
8627 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback);
8628 snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1,
8630 snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP,
8634 snd_hda_jack_detect_enable_callback(codec,
8713 static void ca0132_init_chip(struct hda_codec *codec)
8715 struct ca0132_spec *spec = codec->spec;
8729 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
8730 chipio_write_no_mutex(codec, 0x18b0a4, 0x000000c2);
8732 snd_hda_codec_write(codec, codec->core.afg, 0,
8734 snd_hda_codec_write(codec, codec->core.afg, 0,
8790 ca0132_init_tuning_defaults(codec);
8798 static void r3di_gpio_shutdown(struct hda_codec *codec)
8800 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0x00);
8806 static void sbz_region2_exit(struct hda_codec *codec)
8808 struct ca0132_spec *spec = codec->spec;
8816 ca0113_mmio_gpio_set(codec, 0, false);
8817 ca0113_mmio_gpio_set(codec, 1, false);
8818 ca0113_mmio_gpio_set(codec, 4, true);
8819 ca0113_mmio_gpio_set(codec, 5, false);
8820 ca0113_mmio_gpio_set(codec, 7, false);
8823 static void sbz_set_pin_ctl_default(struct hda_codec *codec)
8828 snd_hda_codec_write(codec, 0x11, 0,
8832 snd_hda_codec_write(codec, pins[i], 0,
8836 static void ca0132_clear_unsolicited(struct hda_codec *codec)
8842 snd_hda_codec_write(codec, pins[i], 0,
8848 static void sbz_gpio_shutdown_commands(struct hda_codec *codec, int dir,
8852 snd_hda_codec_write(codec, 0x01, 0,
8855 snd_hda_codec_write(codec, 0x01, 0,
8859 snd_hda_codec_write(codec, 0x01, 0,
8863 static void zxr_dbpro_power_state_shutdown(struct hda_codec *codec)
8869 snd_hda_codec_write(codec, pins[i], 0,
8873 static void sbz_exit_chip(struct hda_codec *codec)
8875 chipio_set_stream_control(codec, 0x03, 0);
8876 chipio_set_stream_control(codec, 0x04, 0);
8879 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, -1);
8880 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x05);
8881 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x01);
8883 chipio_set_stream_control(codec, 0x14, 0);
8884 chipio_set_stream_control(codec, 0x0C, 0);
8886 chipio_set_conn_rate(codec, 0x41, SR_192_000);
8887 chipio_set_conn_rate(codec, 0x91, SR_192_000);
8889 chipio_write(codec, 0x18a020, 0x00000083);
8891 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x03);
8892 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x07);
8893 sbz_gpio_shutdown_commands(codec, 0x07, 0x07, 0x06);
8895 chipio_set_stream_control(codec, 0x0C, 0);
8897 chipio_set_control_param(codec, 0x0D, 0x24);
8899 ca0132_clear_unsolicited(codec);
8900 sbz_set_pin_ctl_default(codec);
8902 snd_hda_codec_write(codec, 0x0B, 0,
8905 sbz_region2_exit(codec);
8908 static void r3d_exit_chip(struct hda_codec *codec)
8910 ca0132_clear_unsolicited(codec);
8911 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8912 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x5b);
8915 static void ae5_exit_chip(struct hda_codec *codec)
8917 chipio_set_stream_control(codec, 0x03, 0);
8918 chipio_set_stream_control(codec, 0x04, 0);
8920 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8921 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8922 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
8923 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8924 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8925 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x00);
8926 ca0113_mmio_gpio_set(codec, 0, false);
8927 ca0113_mmio_gpio_set(codec, 1, false);
8929 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8930 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8932 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8934 chipio_set_stream_control(codec, 0x18, 0);
8935 chipio_set_stream_control(codec, 0x0c, 0);
8937 snd_hda_codec_write(codec, 0x01, 0, 0x724, 0x83);
8940 static void ae7_exit_chip(struct hda_codec *codec)
8942 chipio_set_stream_control(codec, 0x18, 0);
8943 chipio_set_stream_source_dest(codec, 0x21, 0xc8, 0xc8);
8944 chipio_set_stream_channels(codec, 0x21, 0);
8945 chipio_set_control_param(codec, CONTROL_PARAM_NODE_ID, 0x09);
8946 chipio_set_control_param(codec, 0x20, 0x01);
8948 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
8950 chipio_set_stream_control(codec, 0x18, 0);
8951 chipio_set_stream_control(codec, 0x0c, 0);
8953 ca0113_mmio_command_set(codec, 0x30, 0x2b, 0x00);
8954 snd_hda_codec_write(codec, 0x15, 0, 0x724, 0x83);
8955 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
8956 ca0113_mmio_command_set(codec, 0x30, 0x30, 0x00);
8957 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x00);
8958 ca0113_mmio_gpio_set(codec, 0, false);
8959 ca0113_mmio_gpio_set(codec, 1, false);
8960 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
8962 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8963 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8966 static void zxr_exit_chip(struct hda_codec *codec)
8968 chipio_set_stream_control(codec, 0x03, 0);
8969 chipio_set_stream_control(codec, 0x04, 0);
8970 chipio_set_stream_control(codec, 0x14, 0);
8971 chipio_set_stream_control(codec, 0x0C, 0);
8973 chipio_set_conn_rate(codec, 0x41, SR_192_000);
8974 chipio_set_conn_rate(codec, 0x91, SR_192_000);
8976 chipio_write(codec, 0x18a020, 0x00000083);
8978 snd_hda_codec_write(codec, 0x01, 0, 0x793, 0x00);
8979 snd_hda_codec_write(codec, 0x01, 0, 0x794, 0x53);
8981 ca0132_clear_unsolicited(codec);
8982 sbz_set_pin_ctl_default(codec);
8983 snd_hda_codec_write(codec, 0x0B, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x00);
8985 ca0113_mmio_gpio_set(codec, 5, false);
8986 ca0113_mmio_gpio_set(codec, 2, false);
8987 ca0113_mmio_gpio_set(codec, 3, false);
8988 ca0113_mmio_gpio_set(codec, 0, false);
8989 ca0113_mmio_gpio_set(codec, 4, true);
8990 ca0113_mmio_gpio_set(codec, 0, true);
8991 ca0113_mmio_gpio_set(codec, 5, true);
8992 ca0113_mmio_gpio_set(codec, 2, false);
8993 ca0113_mmio_gpio_set(codec, 3, false);
8996 static void ca0132_exit_chip(struct hda_codec *codec)
9000 if (dspload_is_loaded(codec))
9001 dsp_reset(codec);
9012 static void sbz_dsp_startup_check(struct hda_codec *codec)
9014 struct ca0132_spec *spec = codec->spec;
9027 chipio_read(codec, cur_address, &dsp_data_check[i]);
9035 codec_dbg(codec, "Startup Check: %d ", failure);
9037 codec_info(codec, "DSP not initialized properly. Attempting to fix.");
9044 codec_info(codec, "Reloading... Tries left: %d", reload);
9045 sbz_exit_chip(codec);
9047 snd_hda_codec_init(codec);
9050 chipio_read(codec, cur_address, &dsp_data_check[i]);
9061 codec_info(codec, "DSP fixed.");
9066 codec_info(codec, "DSP failed to initialize properly. Either try a full shutdown or a suspend to clear the internal memory.");
9077 static void ca0132_alt_vol_setup(struct hda_codec *codec)
9079 snd_hda_codec_write(codec, 0x02, 0, 0x797, 0x00);
9080 snd_hda_codec_write(codec, 0x02, 0, 0x798, 0x00);
9081 snd_hda_codec_write(codec, 0x03, 0, 0x797, 0x00);
9082 snd_hda_codec_write(codec, 0x03, 0, 0x798, 0x00);
9083 snd_hda_codec_write(codec, 0x04, 0, 0x797, 0x00);
9084 snd_hda_codec_write(codec, 0x04, 0, 0x798, 0x00);
9085 snd_hda_codec_write(codec, 0x07, 0, 0x797, 0x00);
9086 snd_hda_codec_write(codec, 0x07, 0, 0x798, 0x00);
9092 static void sbz_pre_dsp_setup(struct hda_codec *codec)
9094 struct ca0132_spec *spec = codec->spec;
9099 chipio_write(codec, 0x18b0a4, 0x000000c2);
9101 snd_hda_codec_write(codec, 0x11, 0,
9105 static void r3d_pre_dsp_setup(struct hda_codec *codec)
9107 chipio_write(codec, 0x18b0a4, 0x000000c2);
9109 chipio_8051_write_exram(codec, 0x1c1e, 0x5b);
9111 snd_hda_codec_write(codec, 0x11, 0,
9115 static void r3di_pre_dsp_setup(struct hda_codec *codec)
9117 chipio_write(codec, 0x18b0a4, 0x000000c2);
9119 chipio_8051_write_exram(codec, 0x1c1e, 0x5b);
9120 chipio_8051_write_exram(codec, 0x1920, 0x00);
9121 chipio_8051_write_exram(codec, 0x1921, 0x40);
9123 snd_hda_codec_write(codec, 0x11, 0,
9132 static void zxr_pre_dsp_setup(struct hda_codec *codec)
9138 chipio_write(codec, 0x189000, 0x0001f100);
9140 chipio_write(codec, 0x18900c, 0x0001f100);
9149 chipio_8051_write_exram(codec, 0xfa92, 0x22);
9151 chipio_8051_write_pll_pmu(codec, 0x51, 0x98);
9153 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x725, 0x82);
9154 chipio_set_control_param(codec, CONTROL_PARAM_ASI, 3);
9156 chipio_write(codec, 0x18902c, 0x00000000);
9158 chipio_write(codec, 0x18902c, 0x00000003);
9162 chipio_8051_write_pll_pmu(codec, addr[i], data[i]);
9205 static void ca0132_mmio_init_sbz(struct hda_codec *codec)
9207 struct ca0132_spec *spec = codec->spec;
9255 static void ca0132_mmio_init_ae5(struct hda_codec *codec)
9257 struct ca0132_spec *spec = codec->spec;
9287 static void ca0132_mmio_init(struct hda_codec *codec)
9289 struct ca0132_spec *spec = codec->spec;
9295 ca0132_mmio_init_sbz(codec);
9298 ca0132_mmio_init_ae5(codec);
9317 * eventually resets the codec with the 0x7ff verb. Not quite sure why it does
9320 static void ae5_register_set(struct hda_codec *codec)
9322 struct ca0132_spec *spec = codec->spec;
9330 chipio_8051_write_pll_pmu(codec, 0x41, 0xc8);
9332 chipio_8051_write_direct(codec, 0x93, 0x10);
9333 chipio_8051_write_pll_pmu(codec, 0x44, 0xc2);
9361 ca0113_mmio_command_set_type2(codec, 0x48, 0x07, 0x83);
9362 ca0113_mmio_command_set(codec, 0x30, 0x2e, 0x3f);
9364 ca0113_mmio_command_set(codec, 0x30, 0x2d, 0x3f);
9367 chipio_8051_write_direct(codec, 0x90, 0x00);
9368 chipio_8051_write_direct(codec, 0x90, 0x10);
9371 ca0113_mmio_command_set(codec, 0x48, 0x07, 0x83);
9379 static void ca0132_alt_init(struct hda_codec *codec)
9381 struct ca0132_spec *spec = codec->spec;
9383 ca0132_alt_vol_setup(codec);
9387 codec_dbg(codec, "SBZ alt_init");
9388 ca0132_gpio_init(codec);
9389 sbz_pre_dsp_setup(codec);
9390 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9391 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9394 codec_dbg(codec, "R3DI alt_init");
9395 ca0132_gpio_init(codec);
9396 ca0132_gpio_setup(codec);
9397 r3di_gpio_dsp_status_set(codec, R3DI_DSP_DOWNLOADING);
9398 r3di_pre_dsp_setup(codec);
9399 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9400 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x6FF, 0xC4);
9403 r3d_pre_dsp_setup(codec);
9404 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9405 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9408 ca0132_gpio_init(codec);
9409 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9410 chipio_write(codec, 0x18b030, 0x00000020);
9411 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9412 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9413 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9416 ca0132_gpio_init(codec);
9417 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9418 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9419 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9420 chipio_write(codec, 0x18b008, 0x000000f8);
9421 chipio_write(codec, 0x18b008, 0x000000f0);
9422 chipio_write(codec, 0x18b030, 0x00000020);
9423 ca0113_mmio_command_set(codec, 0x30, 0x32, 0x3f);
9426 chipio_8051_write_pll_pmu(codec, 0x49, 0x88);
9427 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9428 snd_hda_sequence_write(codec, spec->desktop_init_verbs);
9429 zxr_pre_dsp_setup(codec);
9436 static int ca0132_init(struct hda_codec *codec)
9438 struct ca0132_spec *spec = codec->spec;
9445 * there's only two reasons for it. One, the codec has awaken from a
9454 dsp_loaded = dspload_is_loaded(codec);
9460 sbz_dsp_startup_check(codec);
9470 ca0132_mmio_init(codec);
9472 CLASS(snd_hda_power_pm, pm)(codec);
9475 ae5_register_set(codec);
9477 ca0132_init_params(codec);
9478 ca0132_init_flags(codec);
9480 snd_hda_sequence_write(codec, spec->base_init_verbs);
9483 ca0132_alt_init(codec);
9485 ca0132_download_dsp(codec);
9487 ca0132_refresh_widget_caps(codec);
9492 r3d_setup_defaults(codec);
9496 sbz_setup_defaults(codec);
9499 ae5_setup_defaults(codec);
9502 ae7_setup_defaults(codec);
9505 ca0132_setup_defaults(codec);
9506 ca0132_init_analog_mic2(codec);
9507 ca0132_init_dmic(codec);
9512 init_output(codec, spec->out_pins[i], spec->dacs[0]);
9514 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9517 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9519 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9522 snd_hda_sequence_write(codec, spec->chip_init_verbs);
9523 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9525 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
9530 ca0132_gpio_setup(codec);
9532 snd_hda_sequence_write(codec, spec->spec_init_verbs);
9534 ca0132_alt_select_out(codec);
9535 ca0132_alt_select_in(codec);
9537 ca0132_select_out(codec);
9538 ca0132_select_mic(codec);
9541 snd_hda_jack_report_sync(codec);
9549 ca0132_pe_switch_set(codec);
9555 static int dbpro_init(struct hda_codec *codec)
9557 struct ca0132_spec *spec = codec->spec;
9561 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
9562 init_input(codec, cfg->dig_in_pin, spec->dig_in);
9565 init_input(codec, spec->input_pins[i], spec->adcs[i]);
9570 static void ca0132_free(struct hda_codec *codec)
9572 struct ca0132_spec *spec = codec->spec;
9575 snd_hda_power_up(codec);
9578 sbz_exit_chip(codec);
9581 zxr_exit_chip(codec);
9584 r3d_exit_chip(codec);
9587 ae5_exit_chip(codec);
9590 ae7_exit_chip(codec);
9593 r3di_gpio_shutdown(codec);
9599 snd_hda_sequence_write(codec, spec->base_exit_verbs);
9600 ca0132_exit_chip(codec);
9602 snd_hda_power_down(codec);
9605 pci_iounmap(codec->bus->pci, spec->mem_base);
9608 kfree(codec->spec);
9611 static void dbpro_free(struct hda_codec *codec)
9613 struct ca0132_spec *spec = codec->spec;
9615 zxr_dbpro_power_state_shutdown(codec);
9618 kfree(codec->spec);
9621 static void ca0132_config(struct hda_codec *codec)
9623 struct ca0132_spec *spec = codec->spec;
9639 codec_dbg(codec, "%s: QUIRK_ALIENWARE applied.\n", __func__);
9640 snd_hda_apply_pincfgs(codec, alienware_pincfgs);
9643 codec_dbg(codec, "%s: QUIRK_SBZ applied.\n", __func__);
9644 snd_hda_apply_pincfgs(codec, sbz_pincfgs);
9647 codec_dbg(codec, "%s: QUIRK_ZXR applied.\n", __func__);
9648 snd_hda_apply_pincfgs(codec, zxr_pincfgs);
9651 codec_dbg(codec, "%s: QUIRK_R3D applied.\n", __func__);
9652 snd_hda_apply_pincfgs(codec, r3d_pincfgs);
9655 codec_dbg(codec, "%s: QUIRK_R3DI applied.\n", __func__);
9656 snd_hda_apply_pincfgs(codec, r3di_pincfgs);
9659 codec_dbg(codec, "%s: QUIRK_AE5 applied.\n", __func__);
9660 snd_hda_apply_pincfgs(codec, ae5_pincfgs);
9663 codec_dbg(codec, "%s: QUIRK_AE7 applied.\n", __func__);
9664 snd_hda_apply_pincfgs(codec, ae7_pincfgs);
9821 static int ca0132_prepare_verbs(struct hda_codec *codec)
9825 struct ca0132_spec *spec = codec->spec;
9866 * Sound Blaster Z cards. However, they have different HDA codec subsystem
9870 static void sbz_detect_quirk(struct hda_codec *codec)
9872 switch (codec->core.subsystem_id) {
9874 codec->fixup_id = QUIRK_ZXR;
9877 codec->fixup_id = QUIRK_ZXR_DBPRO;
9880 codec->fixup_id = QUIRK_SBZ;
9885 static void ca0132_codec_remove(struct hda_codec *codec)
9887 struct ca0132_spec *spec = codec->spec;
9890 return dbpro_free(codec);
9892 return ca0132_free(codec);
9895 static int ca0132_codec_probe(struct hda_codec *codec,
9901 codec_dbg(codec, "%s\n", __func__);
9906 codec->spec = spec;
9907 spec->codec = codec;
9909 /* Detect codec quirk */
9910 snd_hda_pick_fixup(codec, ca0132_quirk_models, ca0132_quirks, NULL);
9912 sbz_detect_quirk(codec);
9914 codec->pcm_format_first = 1;
9915 codec->no_sticky_stream = 1;
9925 snd_hda_codec_set_name(codec, "Sound Blaster Z");
9929 snd_hda_codec_set_name(codec, "Sound Blaster ZxR");
9935 snd_hda_codec_set_name(codec, "Recon3D");
9939 snd_hda_codec_set_name(codec, "Recon3Di");
9943 snd_hda_codec_set_name(codec, "Sound BlasterX AE-5");
9947 snd_hda_codec_set_name(codec, "Sound Blaster AE-7");
9979 spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
9981 codec_warn(codec, "pci_iomap failed! Setting quirk to QUIRK_NONE.");
9982 codec->fixup_id = QUIRK_NONE;
9992 ca0132_init_chip(codec);
9994 ca0132_config(codec);
9996 err = ca0132_prepare_verbs(codec);
10000 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
10004 ca0132_setup_unsol(codec);
10009 ca0132_codec_remove(codec);
10013 static int ca0132_codec_build_controls(struct hda_codec *codec)
10015 struct ca0132_spec *spec = codec->spec;
10018 return dbpro_build_controls(codec);
10020 return ca0132_build_controls(codec);
10023 static int ca0132_codec_build_pcms(struct hda_codec *codec)
10025 struct ca0132_spec *spec = codec->spec;
10028 return dbpro_build_pcms(codec);
10030 return ca0132_build_pcms(codec);
10033 static int ca0132_codec_init(struct hda_codec *codec)
10035 struct ca0132_spec *spec = codec->spec;
10038 return dbpro_init(codec);
10040 return ca0132_init(codec);
10043 static int ca0132_codec_suspend(struct hda_codec *codec)
10045 struct ca0132_spec *spec = codec->spec;
10071 MODULE_DESCRIPTION("Creative Sound Core3D codec");