Lines Matching +full:comp +full:- +full:int
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
3 // Copyright (c) 2017-2018, Linaro Limited
19 #include <sound/soc-dapm.h>
26 #include "wcd-clsh-v2.h"
28 #include <dt-bindings/sound/qcom,wcd9335.h>
99 #define WCD9335_CALCULATE_VOUT_D(req_mv) (((req_mv - 650) * 10) / 25)
102 {"RX INT" #id "_1 MIX1 INP0", "RX0", "SLIM RX0"}, \
103 {"RX INT" #id "_1 MIX1 INP0", "RX1", "SLIM RX1"}, \
104 {"RX INT" #id "_1 MIX1 INP0", "RX2", "SLIM RX2"}, \
105 {"RX INT" #id "_1 MIX1 INP0", "RX3", "SLIM RX3"}, \
106 {"RX INT" #id "_1 MIX1 INP0", "RX4", "SLIM RX4"}, \
107 {"RX INT" #id "_1 MIX1 INP0", "RX5", "SLIM RX5"}, \
108 {"RX INT" #id "_1 MIX1 INP0", "RX6", "SLIM RX6"}, \
109 {"RX INT" #id "_1 MIX1 INP0", "RX7", "SLIM RX7"}, \
110 {"RX INT" #id "_1 MIX1 INP1", "RX0", "SLIM RX0"}, \
111 {"RX INT" #id "_1 MIX1 INP1", "RX1", "SLIM RX1"}, \
112 {"RX INT" #id "_1 MIX1 INP1", "RX2", "SLIM RX2"}, \
113 {"RX INT" #id "_1 MIX1 INP1", "RX3", "SLIM RX3"}, \
114 {"RX INT" #id "_1 MIX1 INP1", "RX4", "SLIM RX4"}, \
115 {"RX INT" #id "_1 MIX1 INP1", "RX5", "SLIM RX5"}, \
116 {"RX INT" #id "_1 MIX1 INP1", "RX6", "SLIM RX6"}, \
117 {"RX INT" #id "_1 MIX1 INP1", "RX7", "SLIM RX7"}, \
118 {"RX INT" #id "_1 MIX1 INP2", "RX0", "SLIM RX0"}, \
119 {"RX INT" #id "_1 MIX1 INP2", "RX1", "SLIM RX1"}, \
120 {"RX INT" #id "_1 MIX1 INP2", "RX2", "SLIM RX2"}, \
121 {"RX INT" #id "_1 MIX1 INP2", "RX3", "SLIM RX3"}, \
122 {"RX INT" #id "_1 MIX1 INP2", "RX4", "SLIM RX4"}, \
123 {"RX INT" #id "_1 MIX1 INP2", "RX5", "SLIM RX5"}, \
124 {"RX INT" #id "_1 MIX1 INP2", "RX6", "SLIM RX6"}, \
125 {"RX INT" #id "_1 MIX1 INP2", "RX7", "SLIM RX7"}, \
126 {"RX INT" #id "_2 MUX", "RX0", "SLIM RX0"}, \
127 {"RX INT" #id "_2 MUX", "RX1", "SLIM RX1"}, \
128 {"RX INT" #id "_2 MUX", "RX2", "SLIM RX2"}, \
129 {"RX INT" #id "_2 MUX", "RX3", "SLIM RX3"}, \
130 {"RX INT" #id "_2 MUX", "RX4", "SLIM RX4"}, \
131 {"RX INT" #id "_2 MUX", "RX5", "SLIM RX5"}, \
132 {"RX INT" #id "_2 MUX", "RX6", "SLIM RX6"}, \
133 {"RX INT" #id "_2 MUX", "RX7", "SLIM RX7"}, \
134 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP0"}, \
135 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP1"}, \
136 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP2"}, \
137 {"RX INT" #id " SEC MIX", NULL, "RX INT" #id "_2 MUX"}, \
138 {"RX INT" #id " SEC MIX", NULL, "RX INT" #id "_1 MIX1"}, \
139 {"RX INT" #id " MIX2", NULL, "RX INT" #id " SEC MIX"}, \
140 {"RX INT" #id " INTERP", NULL, "RX INT" #id " MIX2"}
313 int sido_input_src;
319 int master_bias_users;
320 int clk_mclk_users;
321 int clk_rco_users;
322 int sido_ccl_cnt;
327 int prim_int_users[WCD9335_NUM_INTERPOLATORS];
329 int comp_enabled[COMPANDER_MAX];
331 int intr1;
332 int reset_gpio;
335 unsigned int rx_port_value[WCD9335_RX_MAX];
336 unsigned int tx_port_value[WCD9335_TX_MAX];
337 int hph_l_gain;
338 int hph_r_gain;
342 int micb_ref[WCD9335_MAX_MICBIAS];
343 int pullup_ref[WCD9335_MAX_MICBIAS];
345 int dmic_0_1_clk_cnt;
346 int dmic_2_3_clk_cnt;
347 int dmic_4_5_clk_cnt;
351 int irq;
352 irqreturn_t (*handler)(int irq, void *data);
392 int rate;
393 int rate_val;
405 {24000, -EINVAL},/* 24K */
547 "Class H Invalid", "Class-H Hi-Fi", "Class-H Low Power", "Class-AB",
548 "Class-H Hi-Fi Low Power"
608 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
1256 static int slim_rx_mux_get(struct snd_kcontrol *kc, in slim_rx_mux_get()
1260 struct wcd9335_codec *wcd = dev_get_drvdata(w->dapm->dev); in slim_rx_mux_get()
1261 u32 port_id = w->shift; in slim_rx_mux_get()
1263 ucontrol->value.enumerated.item[0] = wcd->rx_port_value[port_id]; in slim_rx_mux_get()
1268 static int slim_rx_mux_put(struct snd_kcontrol *kc, in slim_rx_mux_put()
1272 struct wcd9335_codec *wcd = dev_get_drvdata(w->dapm->dev); in slim_rx_mux_put()
1273 struct soc_enum *e = (struct soc_enum *)kc->private_value; in slim_rx_mux_put()
1275 u32 port_id = w->shift; in slim_rx_mux_put()
1277 if (wcd->rx_port_value[port_id] == ucontrol->value.enumerated.item[0]) in slim_rx_mux_put()
1280 wcd->rx_port_value[port_id] = ucontrol->value.enumerated.item[0]; in slim_rx_mux_put()
1283 list_del_init(&wcd->rx_chs[port_id].list); in slim_rx_mux_put()
1285 switch (wcd->rx_port_value[port_id]) { in slim_rx_mux_put()
1290 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1291 &wcd->dai[AIF1_PB].slim_ch_list); in slim_rx_mux_put()
1294 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1295 &wcd->dai[AIF2_PB].slim_ch_list); in slim_rx_mux_put()
1298 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1299 &wcd->dai[AIF3_PB].slim_ch_list); in slim_rx_mux_put()
1302 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1303 &wcd->dai[AIF4_PB].slim_ch_list); in slim_rx_mux_put()
1306 dev_err(wcd->dev, "Unknown AIF %d\n", wcd->rx_port_value[port_id]); in slim_rx_mux_put()
1310 snd_soc_dapm_mux_update_power(w->dapm, kc, wcd->rx_port_value[port_id], in slim_rx_mux_put()
1315 return -EINVAL; in slim_rx_mux_put()
1318 static int slim_tx_mixer_get(struct snd_kcontrol *kc, in slim_tx_mixer_get()
1323 struct wcd9335_codec *wcd = dev_get_drvdata(dapm->dev); in slim_tx_mixer_get()
1326 (struct soc_mixer_control *)kc->private_value; in slim_tx_mixer_get()
1327 int dai_id = widget->shift; in slim_tx_mixer_get()
1328 int port_id = mixer->shift; in slim_tx_mixer_get()
1330 ucontrol->value.integer.value[0] = wcd->tx_port_value[port_id] == dai_id; in slim_tx_mixer_get()
1335 static int slim_tx_mixer_put(struct snd_kcontrol *kc, in slim_tx_mixer_put()
1340 struct wcd9335_codec *wcd = dev_get_drvdata(widget->dapm->dev); in slim_tx_mixer_put()
1343 (struct soc_mixer_control *)kc->private_value; in slim_tx_mixer_put()
1344 int enable = ucontrol->value.integer.value[0]; in slim_tx_mixer_put()
1345 int dai_id = widget->shift; in slim_tx_mixer_put()
1346 int port_id = mixer->shift; in slim_tx_mixer_put()
1353 if (enable && wcd->tx_port_value[port_id] != dai_id) { in slim_tx_mixer_put()
1354 wcd->tx_port_value[port_id] = dai_id; in slim_tx_mixer_put()
1355 list_add_tail(&wcd->tx_chs[port_id].list, in slim_tx_mixer_put()
1356 &wcd->dai[dai_id].slim_ch_list); in slim_tx_mixer_put()
1357 } else if (!enable && wcd->tx_port_value[port_id] == dai_id) { in slim_tx_mixer_put()
1358 wcd->tx_port_value[port_id] = -1; in slim_tx_mixer_put()
1359 list_del_init(&wcd->tx_chs[port_id].list); in slim_tx_mixer_put()
1363 dev_err(wcd->dev, "Unknown AIF %d\n", dai_id); in slim_tx_mixer_put()
1364 return -EINVAL; in slim_tx_mixer_put()
1367 snd_soc_dapm_mixer_update_power(widget->dapm, kc, enable, update); in slim_tx_mixer_put()
1470 static int wcd9335_put_dec_enum(struct snd_kcontrol *kc, in wcd9335_put_dec_enum()
1475 struct soc_enum *e = (struct soc_enum *)kc->private_value; in wcd9335_put_dec_enum()
1476 unsigned int val, reg, sel; in wcd9335_put_dec_enum()
1478 val = ucontrol->value.enumerated.item[0]; in wcd9335_put_dec_enum()
1480 switch (e->reg) { in wcd9335_put_dec_enum()
1509 return -EINVAL; in wcd9335_put_dec_enum()
1521 static int wcd9335_int_dem_inp_mux_put(struct snd_kcontrol *kc, in wcd9335_int_dem_inp_mux_put()
1524 struct soc_enum *e = (struct soc_enum *)kc->private_value; in wcd9335_int_dem_inp_mux_put()
1526 int reg, val; in wcd9335_int_dem_inp_mux_put()
1529 val = ucontrol->value.enumerated.item[0]; in wcd9335_int_dem_inp_mux_put()
1531 if (e->reg == WCD9335_CDC_RX0_RX_PATH_SEC0) in wcd9335_int_dem_inp_mux_put()
1533 else if (e->reg == WCD9335_CDC_RX1_RX_PATH_SEC0) in wcd9335_int_dem_inp_mux_put()
1535 else if (e->reg == WCD9335_CDC_RX2_RX_PATH_SEC0) in wcd9335_int_dem_inp_mux_put()
1538 return -EINVAL; in wcd9335_int_dem_inp_mux_put()
1608 static int wcd9335_set_mix_interpolator_rate(struct snd_soc_dai *dai, in wcd9335_set_mix_interpolator_rate()
1609 int rate_val, in wcd9335_set_mix_interpolator_rate()
1612 struct snd_soc_component *component = dai->component; in wcd9335_set_mix_interpolator_rate()
1613 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_set_mix_interpolator_rate()
1615 int val, j; in wcd9335_set_mix_interpolator_rate()
1617 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { in wcd9335_set_mix_interpolator_rate()
1623 if (val == (ch->shift + INTn_2_INP_SEL_RX0)) in wcd9335_set_mix_interpolator_rate()
1634 static int wcd9335_set_prim_interpolator_rate(struct snd_soc_dai *dai, in wcd9335_set_prim_interpolator_rate()
1638 struct snd_soc_component *comp = dai->component; in wcd9335_set_prim_interpolator_rate() local
1639 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_set_prim_interpolator_rate()
1642 int inp, j; in wcd9335_set_prim_interpolator_rate()
1644 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { in wcd9335_set_prim_interpolator_rate()
1645 inp = ch->shift + INTn_1_MIX_INP_SEL_RX0; in wcd9335_set_prim_interpolator_rate()
1652 cfg0 = snd_soc_component_read(comp, in wcd9335_set_prim_interpolator_rate()
1654 cfg1 = snd_soc_component_read(comp, in wcd9335_set_prim_interpolator_rate()
1668 dev_info(wcd->dev, in wcd9335_set_prim_interpolator_rate()
1671 snd_soc_component_update_bits(comp, in wcd9335_set_prim_interpolator_rate()
1682 static int wcd9335_set_interpolator_rate(struct snd_soc_dai *dai, u32 rate) in wcd9335_set_interpolator_rate()
1684 int i; in wcd9335_set_interpolator_rate()
1707 static int wcd9335_slim_set_hw_params(struct wcd9335_codec *wcd, in wcd9335_slim_set_hw_params()
1709 int direction) in wcd9335_slim_set_hw_params()
1711 struct list_head *slim_ch_list = &dai_data->slim_ch_list; in wcd9335_slim_set_hw_params()
1712 struct slim_stream_config *cfg = &dai_data->sconfig; in wcd9335_slim_set_hw_params()
1715 int ret, i; in wcd9335_slim_set_hw_params()
1717 cfg->ch_count = 0; in wcd9335_slim_set_hw_params()
1718 cfg->direction = direction; in wcd9335_slim_set_hw_params()
1719 cfg->port_mask = 0; in wcd9335_slim_set_hw_params()
1723 cfg->ch_count++; in wcd9335_slim_set_hw_params()
1724 payload |= 1 << ch->shift; in wcd9335_slim_set_hw_params()
1725 cfg->port_mask |= BIT(ch->port); in wcd9335_slim_set_hw_params()
1728 cfg->chs = kcalloc(cfg->ch_count, sizeof(unsigned int), GFP_KERNEL); in wcd9335_slim_set_hw_params()
1729 if (!cfg->chs) in wcd9335_slim_set_hw_params()
1730 return -ENOMEM; in wcd9335_slim_set_hw_params()
1734 cfg->chs[i++] = ch->ch_num; in wcd9335_slim_set_hw_params()
1737 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1738 WCD9335_SLIM_PGD_RX_PORT_MULTI_CHNL_0(ch->port), in wcd9335_slim_set_hw_params()
1745 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1746 WCD9335_SLIM_PGD_RX_PORT_CFG(ch->port), in wcd9335_slim_set_hw_params()
1751 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1752 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_0(ch->port), in wcd9335_slim_set_hw_params()
1758 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1759 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_1(ch->port), in wcd9335_slim_set_hw_params()
1765 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1766 WCD9335_SLIM_PGD_TX_PORT_CFG(ch->port), in wcd9335_slim_set_hw_params()
1774 dai_data->sruntime = slim_stream_allocate(wcd->slim, "WCD9335-SLIM"); in wcd9335_slim_set_hw_params()
1779 dev_err(wcd->dev, "Error Setting slim hw params\n"); in wcd9335_slim_set_hw_params()
1780 kfree(cfg->chs); in wcd9335_slim_set_hw_params()
1781 cfg->chs = NULL; in wcd9335_slim_set_hw_params()
1786 static int wcd9335_set_decimator_rate(struct snd_soc_dai *dai, in wcd9335_set_decimator_rate()
1789 struct snd_soc_component *comp = dai->component; in wcd9335_set_decimator_rate() local
1790 struct wcd9335_codec *wcd = snd_soc_component_get_drvdata(comp); in wcd9335_set_decimator_rate()
1793 int tx_port, tx_port_reg; in wcd9335_set_decimator_rate()
1794 int decimator = -1; in wcd9335_set_decimator_rate()
1796 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { in wcd9335_set_decimator_rate()
1797 tx_port = ch->port; in wcd9335_set_decimator_rate()
1799 dev_err(wcd->dev, "Invalid SLIM TX%u port DAI ID:%d\n", in wcd9335_set_decimator_rate()
1800 tx_port, dai->id); in wcd9335_set_decimator_rate()
1801 return -EINVAL; in wcd9335_set_decimator_rate()
1803 /* Find the SB TX MUX input - which decimator is connected */ in wcd9335_set_decimator_rate()
1810 shift = ((tx_port - 4) << 1); in wcd9335_set_decimator_rate()
1814 shift = ((tx_port - 8) << 1); in wcd9335_set_decimator_rate()
1826 tx_mux_sel = snd_soc_component_read(comp, tx_port_reg) & in wcd9335_set_decimator_rate()
1838 decimator = tx_mux_sel - 1; in wcd9335_set_decimator_rate()
1845 snd_soc_component_update_bits(comp, in wcd9335_set_decimator_rate()
1851 dev_err(wcd->dev, "RX_MIX_TX%u going to SLIM TX%u\n", in wcd9335_set_decimator_rate()
1854 dev_err(wcd->dev, "ERROR: Invalid decimator: %d\n", in wcd9335_set_decimator_rate()
1856 return -EINVAL; in wcd9335_set_decimator_rate()
1863 static int wcd9335_hw_params(struct snd_pcm_substream *substream, in wcd9335_hw_params()
1868 int ret, tx_fs_rate = 0; in wcd9335_hw_params()
1870 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_hw_params()
1872 switch (substream->stream) { in wcd9335_hw_params()
1876 dev_err(wcd->dev, "cannot set sample rate: %u\n", in wcd9335_hw_params()
1882 wcd->dai[dai->id].sconfig.bps = params_width(params); in wcd9335_hw_params()
1885 dev_err(wcd->dev, "%s: Invalid format 0x%x\n", in wcd9335_hw_params()
1887 return -EINVAL; in wcd9335_hw_params()
1915 dev_err(wcd->dev, "%s: Invalid TX sample rate: %d\n", in wcd9335_hw_params()
1917 return -EINVAL; in wcd9335_hw_params()
1924 dev_err(wcd->dev, "Cannot set TX Decimator rate\n"); in wcd9335_hw_params()
1929 wcd->dai[dai->id].sconfig.bps = params_width(params); in wcd9335_hw_params()
1932 dev_err(wcd->dev, "%s: Invalid format 0x%x\n", in wcd9335_hw_params()
1934 return -EINVAL; in wcd9335_hw_params()
1938 dev_err(wcd->dev, "Invalid stream type %d\n", in wcd9335_hw_params()
1939 substream->stream); in wcd9335_hw_params()
1940 return -EINVAL; in wcd9335_hw_params()
1943 wcd->dai[dai->id].sconfig.rate = params_rate(params); in wcd9335_hw_params()
1944 wcd9335_slim_set_hw_params(wcd, &wcd->dai[dai->id], substream->stream); in wcd9335_hw_params()
1949 static int wcd9335_trigger(struct snd_pcm_substream *substream, int cmd, in wcd9335_trigger()
1956 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_trigger()
1958 dai_data = &wcd->dai[dai->id]; in wcd9335_trigger()
1964 cfg = &dai_data->sconfig; in wcd9335_trigger()
1965 slim_stream_prepare(dai_data->sruntime, cfg); in wcd9335_trigger()
1966 slim_stream_enable(dai_data->sruntime); in wcd9335_trigger()
1971 slim_stream_disable(dai_data->sruntime); in wcd9335_trigger()
1972 slim_stream_unprepare(dai_data->sruntime); in wcd9335_trigger()
1981 static int wcd9335_set_channel_map(struct snd_soc_dai *dai, in wcd9335_set_channel_map()
1982 unsigned int tx_num, in wcd9335_set_channel_map()
1983 const unsigned int *tx_slot, in wcd9335_set_channel_map()
1984 unsigned int rx_num, in wcd9335_set_channel_map()
1985 const unsigned int *rx_slot) in wcd9335_set_channel_map()
1988 int i; in wcd9335_set_channel_map()
1990 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_set_channel_map()
1993 dev_err(wcd->dev, "Invalid tx_slot=%p, rx_slot=%p\n", in wcd9335_set_channel_map()
1995 return -EINVAL; in wcd9335_set_channel_map()
1998 wcd->num_rx_port = rx_num; in wcd9335_set_channel_map()
2000 wcd->rx_chs[i].ch_num = rx_slot[i]; in wcd9335_set_channel_map()
2001 INIT_LIST_HEAD(&wcd->rx_chs[i].list); in wcd9335_set_channel_map()
2004 wcd->num_tx_port = tx_num; in wcd9335_set_channel_map()
2006 wcd->tx_chs[i].ch_num = tx_slot[i]; in wcd9335_set_channel_map()
2007 INIT_LIST_HEAD(&wcd->tx_chs[i].list); in wcd9335_set_channel_map()
2013 static int wcd9335_get_channel_map(const struct snd_soc_dai *dai, in wcd9335_get_channel_map()
2014 unsigned int *tx_num, unsigned int *tx_slot, in wcd9335_get_channel_map()
2015 unsigned int *rx_num, unsigned int *rx_slot) in wcd9335_get_channel_map()
2019 int i = 0; in wcd9335_get_channel_map()
2021 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_get_channel_map()
2023 switch (dai->id) { in wcd9335_get_channel_map()
2029 dev_err(wcd->dev, "Invalid rx_slot %p or rx_num %p\n", in wcd9335_get_channel_map()
2031 return -EINVAL; in wcd9335_get_channel_map()
2034 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) in wcd9335_get_channel_map()
2035 rx_slot[i++] = ch->ch_num; in wcd9335_get_channel_map()
2043 dev_err(wcd->dev, "Invalid tx_slot %p or tx_num %p\n", in wcd9335_get_channel_map()
2045 return -EINVAL; in wcd9335_get_channel_map()
2047 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) in wcd9335_get_channel_map()
2048 tx_slot[i++] = ch->ch_num; in wcd9335_get_channel_map()
2053 dev_err(wcd->dev, "Invalid DAI ID %x\n", dai->id); in wcd9335_get_channel_map()
2172 static int wcd9335_get_compander(struct snd_kcontrol *kc, in wcd9335_get_compander()
2177 int comp = ((struct soc_mixer_control *)kc->private_value)->shift; in wcd9335_get_compander() local
2178 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_get_compander()
2180 ucontrol->value.integer.value[0] = wcd->comp_enabled[comp]; in wcd9335_get_compander()
2184 static int wcd9335_set_compander(struct snd_kcontrol *kc, in wcd9335_set_compander()
2188 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_set_compander()
2189 int comp = ((struct soc_mixer_control *) kc->private_value)->shift; in wcd9335_set_compander() local
2190 int value = ucontrol->value.integer.value[0]; in wcd9335_set_compander()
2191 int sel; in wcd9335_set_compander()
2193 wcd->comp_enabled[comp] = value; in wcd9335_set_compander()
2198 switch (comp) { in wcd9335_set_compander()
2223 static int wcd9335_rx_hph_mode_get(struct snd_kcontrol *kc, in wcd9335_rx_hph_mode_get()
2227 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_rx_hph_mode_get()
2229 ucontrol->value.enumerated.item[0] = wcd->hph_mode; in wcd9335_rx_hph_mode_get()
2234 static int wcd9335_rx_hph_mode_put(struct snd_kcontrol *kc, in wcd9335_rx_hph_mode_put()
2238 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_rx_hph_mode_put()
2241 mode_val = ucontrol->value.enumerated.item[0]; in wcd9335_rx_hph_mode_put()
2244 dev_err(wcd->dev, "Invalid HPH Mode, default to ClSH HiFi\n"); in wcd9335_rx_hph_mode_put()
2247 wcd->hph_mode = mode_val; in wcd9335_rx_hph_mode_put()
2253 /* -84dB min - 40dB max */
2255 -84, 40, digital_gain),
2257 -84, 40, digital_gain),
2259 -84, 40, digital_gain),
2261 -84, 40, digital_gain),
2263 -84, 40, digital_gain),
2265 -84, 40, digital_gain),
2267 -84, 40, digital_gain),
2269 -84, 40, digital_gain),
2271 -84, 40, digital_gain),
2273 -84, 40, digital_gain),
2275 -84, 40, digital_gain),
2277 -84, 40, digital_gain),
2279 -84, 40, digital_gain),
2281 -84, 40, digital_gain),
2283 -84, 40, digital_gain),
2285 -84, 40, digital_gain),
2287 -84, 40, digital_gain),
2289 -84, 40, digital_gain),
2493 static int wcd9335_micbias_control(struct snd_soc_component *component, in wcd9335_micbias_control()
2494 int micb_num, int req, bool is_dapm) in wcd9335_micbias_control()
2497 int micb_index = micb_num - 1; in wcd9335_micbias_control()
2500 if ((micb_index < 0) || (micb_index > WCD9335_MAX_MICBIAS - 1)) { in wcd9335_micbias_control()
2501 dev_err(wcd->dev, "Invalid micbias index, micb_ind:%d\n", in wcd9335_micbias_control()
2503 return -EINVAL; in wcd9335_micbias_control()
2520 dev_err(component->dev, "%s: Invalid micbias number: %d\n", in wcd9335_micbias_control()
2522 return -EINVAL; in wcd9335_micbias_control()
2527 wcd->pullup_ref[micb_index]++; in wcd9335_micbias_control()
2528 if ((wcd->pullup_ref[micb_index] == 1) && in wcd9335_micbias_control()
2529 (wcd->micb_ref[micb_index] == 0)) in wcd9335_micbias_control()
2534 wcd->pullup_ref[micb_index]--; in wcd9335_micbias_control()
2535 if ((wcd->pullup_ref[micb_index] == 0) && in wcd9335_micbias_control()
2536 (wcd->micb_ref[micb_index] == 0)) in wcd9335_micbias_control()
2541 wcd->micb_ref[micb_index]++; in wcd9335_micbias_control()
2542 if (wcd->micb_ref[micb_index] == 1) in wcd9335_micbias_control()
2547 wcd->micb_ref[micb_index]--; in wcd9335_micbias_control()
2548 if ((wcd->micb_ref[micb_index] == 0) && in wcd9335_micbias_control()
2549 (wcd->pullup_ref[micb_index] > 0)) in wcd9335_micbias_control()
2552 else if ((wcd->micb_ref[micb_index] == 0) && in wcd9335_micbias_control()
2553 (wcd->pullup_ref[micb_index] == 0)) { in wcd9335_micbias_control()
2563 static int __wcd9335_codec_enable_micbias(struct snd_soc_dapm_widget *w, in __wcd9335_codec_enable_micbias()
2564 int event) in __wcd9335_codec_enable_micbias()
2566 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in __wcd9335_codec_enable_micbias() local
2567 int micb_num; in __wcd9335_codec_enable_micbias()
2569 if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) in __wcd9335_codec_enable_micbias()
2571 else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) in __wcd9335_codec_enable_micbias()
2573 else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) in __wcd9335_codec_enable_micbias()
2575 else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4"))) in __wcd9335_codec_enable_micbias()
2578 return -EINVAL; in __wcd9335_codec_enable_micbias()
2587 wcd9335_micbias_control(comp, micb_num, MICB_ENABLE, true); in __wcd9335_codec_enable_micbias()
2594 wcd9335_micbias_control(comp, micb_num, MICB_DISABLE, true); in __wcd9335_codec_enable_micbias()
2601 static int wcd9335_codec_enable_micbias(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_micbias()
2602 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_micbias()
2607 static void wcd9335_codec_set_tx_hold(struct snd_soc_component *comp, in wcd9335_codec_set_tx_hold() argument
2622 snd_soc_component_update_bits(comp, WCD9335_ANA_AMIC2, mask, in wcd9335_codec_set_tx_hold()
2627 snd_soc_component_update_bits(comp, WCD9335_ANA_AMIC4, mask, in wcd9335_codec_set_tx_hold()
2632 snd_soc_component_update_bits(comp, WCD9335_ANA_AMIC6, mask, in wcd9335_codec_set_tx_hold()
2636 dev_err(comp->dev, "%s: invalid amic: %d\n", in wcd9335_codec_set_tx_hold()
2642 static int wcd9335_codec_enable_adc(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_adc()
2643 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_adc()
2645 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_adc() local
2649 wcd9335_codec_set_tx_hold(comp, w->reg, true); in wcd9335_codec_enable_adc()
2658 static int wcd9335_codec_find_amic_input(struct snd_soc_component *comp, in wcd9335_codec_find_amic_input() argument
2659 int adc_mux_n) in wcd9335_codec_find_amic_input()
2661 int mux_sel, reg, mreg; in wcd9335_codec_find_amic_input()
2671 mux_sel = snd_soc_component_read(comp, reg) & 0x3; in wcd9335_codec_find_amic_input()
2673 reg = WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + adc_mux_n - 4; in wcd9335_codec_find_amic_input()
2675 mux_sel = snd_soc_component_read(comp, reg) >> 6; in wcd9335_codec_find_amic_input()
2681 return snd_soc_component_read(comp, mreg) & 0x07; in wcd9335_codec_find_amic_input()
2684 static u16 wcd9335_codec_get_amic_pwlvl_reg(struct snd_soc_component *comp, in wcd9335_codec_get_amic_pwlvl_reg() argument
2685 int amic) in wcd9335_codec_get_amic_pwlvl_reg()
2705 dev_err(comp->dev, "invalid amic: %d\n", amic); in wcd9335_codec_get_amic_pwlvl_reg()
2712 static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_dec()
2713 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_dec()
2715 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_dec() local
2716 unsigned int decimator; in wcd9335_codec_enable_dec()
2719 int ret = 0, amic_n; in wcd9335_codec_enable_dec()
2725 char *wname __free(kfree) = kmemdup_nul(w->name, 15, GFP_KERNEL); in wcd9335_codec_enable_dec()
2727 return -ENOMEM; in wcd9335_codec_enable_dec()
2732 dev_err(comp->dev, "%s: Invalid decimator = %s\n", in wcd9335_codec_enable_dec()
2733 __func__, w->name); in wcd9335_codec_enable_dec()
2734 return -EINVAL; in wcd9335_codec_enable_dec()
2740 dev_err(comp->dev, "%s: decimator index not found\n", in wcd9335_codec_enable_dec()
2742 return -EINVAL; in wcd9335_codec_enable_dec()
2747 dev_err(comp->dev, "%s: Invalid decimator = %s\n", in wcd9335_codec_enable_dec()
2749 return -EINVAL; in wcd9335_codec_enable_dec()
2759 amic_n = wcd9335_codec_find_amic_input(comp, decimator); in wcd9335_codec_enable_dec()
2761 pwr_level_reg = wcd9335_codec_get_amic_pwlvl_reg(comp, in wcd9335_codec_enable_dec()
2765 switch ((snd_soc_component_read(comp, pwr_level_reg) & in wcd9335_codec_enable_dec()
2769 snd_soc_component_update_bits(comp, dec_cfg_reg, in wcd9335_codec_enable_dec()
2775 snd_soc_component_update_bits(comp, dec_cfg_reg, in wcd9335_codec_enable_dec()
2781 snd_soc_component_update_bits(comp, dec_cfg_reg, in wcd9335_codec_enable_dec()
2787 hpf_coff_freq = (snd_soc_component_read(comp, dec_cfg_reg) & in wcd9335_codec_enable_dec()
2791 snd_soc_component_update_bits(comp, dec_cfg_reg, in wcd9335_codec_enable_dec()
2795 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, in wcd9335_codec_enable_dec()
2798 snd_soc_component_update_bits(comp, dec_cfg_reg, 0x08, 0x08); in wcd9335_codec_enable_dec()
2801 snd_soc_component_update_bits(comp, hpf_gate_reg, 0x01, 0x00); in wcd9335_codec_enable_dec()
2804 snd_soc_component_write(comp, in wcd9335_codec_enable_dec()
2806 snd_soc_component_write(comp, in wcd9335_codec_enable_dec()
2808 snd_soc_component_write(comp, in wcd9335_codec_enable_dec()
2810 snd_soc_component_write(comp, in wcd9335_codec_enable_dec()
2814 snd_soc_component_update_bits(comp, hpf_gate_reg, in wcd9335_codec_enable_dec()
2816 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, in wcd9335_codec_enable_dec()
2818 snd_soc_component_write(comp, tx_gain_ctl_reg, in wcd9335_codec_enable_dec()
2819 snd_soc_component_read(comp, tx_gain_ctl_reg)); in wcd9335_codec_enable_dec()
2822 hpf_coff_freq = (snd_soc_component_read(comp, dec_cfg_reg) & in wcd9335_codec_enable_dec()
2824 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 0x10, 0x10); in wcd9335_codec_enable_dec()
2825 snd_soc_component_update_bits(comp, dec_cfg_reg, 0x08, 0x00); in wcd9335_codec_enable_dec()
2827 snd_soc_component_update_bits(comp, dec_cfg_reg, in wcd9335_codec_enable_dec()
2833 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 0x10, 0x00); in wcd9335_codec_enable_dec()
2853 static int wcd9335_codec_enable_dmic(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_dmic()
2854 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_dmic()
2856 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_dmic() local
2857 struct wcd9335_codec *wcd = snd_soc_component_get_drvdata(comp); in wcd9335_codec_enable_dmic()
2862 unsigned int dmic; in wcd9335_codec_enable_dmic()
2863 int ret; in wcd9335_codec_enable_dmic()
2866 wname = strpbrk(w->name, "012345"); in wcd9335_codec_enable_dmic()
2868 dev_err(comp->dev, "%s: widget not found\n", __func__); in wcd9335_codec_enable_dmic()
2869 return -EINVAL; in wcd9335_codec_enable_dmic()
2874 dev_err(comp->dev, "%s: Invalid DMIC line on the codec\n", in wcd9335_codec_enable_dmic()
2876 return -EINVAL; in wcd9335_codec_enable_dmic()
2882 dmic_clk_cnt = &(wcd->dmic_0_1_clk_cnt); in wcd9335_codec_enable_dmic()
2887 dmic_clk_cnt = &(wcd->dmic_2_3_clk_cnt); in wcd9335_codec_enable_dmic()
2892 dmic_clk_cnt = &(wcd->dmic_4_5_clk_cnt); in wcd9335_codec_enable_dmic()
2896 dev_err(comp->dev, "%s: Invalid DMIC Selection\n", in wcd9335_codec_enable_dmic()
2898 return -EINVAL; in wcd9335_codec_enable_dmic()
2903 dmic_rate_val = wcd9335_get_dmic_clk_val(comp, wcd->mclk_rate); in wcd9335_codec_enable_dmic()
2906 snd_soc_component_update_bits(comp, dmic_clk_reg, in wcd9335_codec_enable_dmic()
2909 snd_soc_component_update_bits(comp, dmic_clk_reg, in wcd9335_codec_enable_dmic()
2915 dmic_rate_val = wcd9335_get_dmic_clk_val(comp, wcd->mclk_rate); in wcd9335_codec_enable_dmic()
2916 (*dmic_clk_cnt)--; in wcd9335_codec_enable_dmic()
2918 snd_soc_component_update_bits(comp, dmic_clk_reg, in wcd9335_codec_enable_dmic()
2920 snd_soc_component_update_bits(comp, dmic_clk_reg, in wcd9335_codec_enable_dmic()
2933 int port_num = 0; in wcd9335_codec_enable_int_port()
2935 unsigned int val = 0; in wcd9335_codec_enable_int_port()
2936 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_enable_int_port()
2939 list_for_each_entry(ch, &dai->slim_ch_list, list) { in wcd9335_codec_enable_int_port()
2940 if (ch->port >= WCD9335_RX_START) { in wcd9335_codec_enable_int_port()
2941 port_num = ch->port - WCD9335_RX_START; in wcd9335_codec_enable_int_port()
2944 port_num = ch->port; in wcd9335_codec_enable_int_port()
2948 regmap_read(wcd->if_regmap, reg, &val); in wcd9335_codec_enable_int_port()
2950 regmap_write(wcd->if_regmap, reg, in wcd9335_codec_enable_int_port()
2955 static int wcd9335_codec_enable_slim(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_slim()
2957 int event) in wcd9335_codec_enable_slim()
2959 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_slim() local
2960 struct wcd9335_codec *wcd = snd_soc_component_get_drvdata(comp); in wcd9335_codec_enable_slim()
2961 struct wcd_slim_codec_dai_data *dai = &wcd->dai[w->shift]; in wcd9335_codec_enable_slim()
2965 wcd9335_codec_enable_int_port(dai, comp); in wcd9335_codec_enable_slim()
2968 kfree(dai->sconfig.chs); in wcd9335_codec_enable_slim()
2976 static int wcd9335_codec_enable_mix_path(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_mix_path()
2977 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_mix_path()
2979 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_mix_path() local
2981 int val = 0; in wcd9335_codec_enable_mix_path()
2983 switch (w->reg) { in wcd9335_codec_enable_mix_path()
3012 dev_err(comp->dev, "%s: No gain register avail for %s\n", in wcd9335_codec_enable_mix_path()
3013 __func__, w->name); in wcd9335_codec_enable_mix_path()
3019 val = snd_soc_component_read(comp, gain_reg); in wcd9335_codec_enable_mix_path()
3020 snd_soc_component_write(comp, gain_reg, val); in wcd9335_codec_enable_mix_path()
3085 u16 prim_int_reg, int event) in wcd9335_codec_hd2_control()
3124 static int wcd9335_codec_enable_prim_interpolator( in wcd9335_codec_enable_prim_interpolator()
3125 struct snd_soc_component *comp, in wcd9335_codec_enable_prim_interpolator() argument
3126 u16 reg, int event) in wcd9335_codec_enable_prim_interpolator()
3128 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_prim_interpolator()
3130 int prim_int_reg = wcd9335_interp_get_primary_reg(reg, &ind); in wcd9335_codec_enable_prim_interpolator()
3134 wcd->prim_int_users[ind]++; in wcd9335_codec_enable_prim_interpolator()
3135 if (wcd->prim_int_users[ind] == 1) { in wcd9335_codec_enable_prim_interpolator()
3136 snd_soc_component_update_bits(comp, prim_int_reg, in wcd9335_codec_enable_prim_interpolator()
3139 wcd9335_codec_hd2_control(comp, prim_int_reg, event); in wcd9335_codec_enable_prim_interpolator()
3140 snd_soc_component_update_bits(comp, prim_int_reg, in wcd9335_codec_enable_prim_interpolator()
3146 ((snd_soc_component_read(comp, prim_int_reg)) & in wcd9335_codec_enable_prim_interpolator()
3148 snd_soc_component_update_bits(comp, reg, in wcd9335_codec_enable_prim_interpolator()
3153 wcd->prim_int_users[ind]--; in wcd9335_codec_enable_prim_interpolator()
3154 if (wcd->prim_int_users[ind] == 0) { in wcd9335_codec_enable_prim_interpolator()
3155 snd_soc_component_update_bits(comp, prim_int_reg, in wcd9335_codec_enable_prim_interpolator()
3158 snd_soc_component_update_bits(comp, prim_int_reg, in wcd9335_codec_enable_prim_interpolator()
3161 snd_soc_component_update_bits(comp, prim_int_reg, in wcd9335_codec_enable_prim_interpolator()
3164 wcd9335_codec_hd2_control(comp, prim_int_reg, event); in wcd9335_codec_enable_prim_interpolator()
3172 static int wcd9335_config_compander(struct snd_soc_component *component, in wcd9335_config_compander()
3173 int interp_n, int event) in wcd9335_config_compander()
3175 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_config_compander()
3176 int comp; in wcd9335_config_compander() local
3183 comp = interp_n - 1; in wcd9335_config_compander()
3184 if (!wcd->comp_enabled[comp]) in wcd9335_config_compander()
3187 comp_ctl0_reg = WCD9335_CDC_COMPANDER1_CTL(comp); in wcd9335_config_compander()
3188 rx_path_cfg0_reg = WCD9335_CDC_RX1_RX_PATH_CFG(comp); in wcd9335_config_compander()
3233 static int wcd9335_codec_enable_interpolator(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_interpolator()
3234 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_interpolator()
3236 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_interpolator() local
3239 int val; in wcd9335_codec_enable_interpolator()
3269 dev_err(comp->dev, "%s: Interpolator reg not found\n", in wcd9335_codec_enable_interpolator()
3271 return -EINVAL; in wcd9335_codec_enable_interpolator()
3277 wcd9335_codec_enable_prim_interpolator(comp, reg, event); in wcd9335_codec_enable_interpolator()
3280 wcd9335_config_compander(comp, w->shift, event); in wcd9335_codec_enable_interpolator()
3281 val = snd_soc_component_read(comp, gain_reg); in wcd9335_codec_enable_interpolator()
3282 snd_soc_component_write(comp, gain_reg, val); in wcd9335_codec_enable_interpolator()
3285 wcd9335_config_compander(comp, w->shift, event); in wcd9335_codec_enable_interpolator()
3286 wcd9335_codec_enable_prim_interpolator(comp, reg, event); in wcd9335_codec_enable_interpolator()
3296 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_hph_mode_gain_opt()
3320 wcd->hph_l_gain = hph_l_en & 0x1F; in wcd9335_codec_hph_mode_gain_opt()
3325 wcd->hph_r_gain = hph_r_en & 0x1F; in wcd9335_codec_hph_mode_gain_opt()
3329 static void wcd9335_codec_hph_lohifi_config(struct snd_soc_component *comp, in wcd9335_codec_hph_lohifi_config() argument
3330 int event) in wcd9335_codec_hph_lohifi_config()
3333 snd_soc_component_update_bits(comp, WCD9335_RX_BIAS_HPH_PA, in wcd9335_codec_hph_lohifi_config()
3336 snd_soc_component_update_bits(comp, in wcd9335_codec_hph_lohifi_config()
3339 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, in wcd9335_codec_hph_lohifi_config()
3342 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lohifi_config()
3345 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL1, in wcd9335_codec_hph_lohifi_config()
3348 wcd9335_codec_hph_mode_gain_opt(comp, 0x11); in wcd9335_codec_hph_lohifi_config()
3352 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lohifi_config()
3355 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, in wcd9335_codec_hph_lohifi_config()
3358 snd_soc_component_write(comp, WCD9335_RX_BIAS_HPH_RDACBUFF_CNP2, in wcd9335_codec_hph_lohifi_config()
3360 snd_soc_component_update_bits(comp, WCD9335_RX_BIAS_HPH_PA, in wcd9335_codec_hph_lohifi_config()
3366 static void wcd9335_codec_hph_lp_config(struct snd_soc_component *comp, in wcd9335_codec_hph_lp_config() argument
3367 int event) in wcd9335_codec_hph_lp_config()
3370 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL1, in wcd9335_codec_hph_lp_config()
3373 wcd9335_codec_hph_mode_gain_opt(comp, 0x10); in wcd9335_codec_hph_lp_config()
3374 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, in wcd9335_codec_hph_lp_config()
3377 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lp_config()
3380 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lp_config()
3383 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lp_config()
3386 snd_soc_component_update_bits(comp, WCD9335_HPH_RDAC_LDO_CTL, in wcd9335_codec_hph_lp_config()
3389 snd_soc_component_update_bits(comp, WCD9335_HPH_RDAC_LDO_CTL, in wcd9335_codec_hph_lp_config()
3392 snd_soc_component_update_bits(comp, in wcd9335_codec_hph_lp_config()
3394 snd_soc_component_update_bits(comp, in wcd9335_codec_hph_lp_config()
3399 snd_soc_component_write(comp, WCD9335_RX_BIAS_HPH_RDAC_LDO, in wcd9335_codec_hph_lp_config()
3401 snd_soc_component_write(comp, WCD9335_HPH_RDAC_LDO_CTL, in wcd9335_codec_hph_lp_config()
3403 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lp_config()
3406 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lp_config()
3409 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_lp_config()
3412 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, in wcd9335_codec_hph_lp_config()
3415 snd_soc_component_update_bits(comp, WCD9335_HPH_R_EN, in wcd9335_codec_hph_lp_config()
3418 snd_soc_component_update_bits(comp, WCD9335_HPH_L_EN, in wcd9335_codec_hph_lp_config()
3424 static void wcd9335_codec_hph_hifi_config(struct snd_soc_component *comp, in wcd9335_codec_hph_hifi_config() argument
3425 int event) in wcd9335_codec_hph_hifi_config()
3428 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, in wcd9335_codec_hph_hifi_config()
3431 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_hifi_config()
3434 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL1, in wcd9335_codec_hph_hifi_config()
3437 wcd9335_codec_hph_mode_gain_opt(comp, 0x11); in wcd9335_codec_hph_hifi_config()
3441 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, in wcd9335_codec_hph_hifi_config()
3444 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, in wcd9335_codec_hph_hifi_config()
3451 int event, int mode) in wcd9335_codec_hph_mode_config()
3466 static int wcd9335_codec_hphl_dac_event(struct snd_soc_dapm_widget *w, in wcd9335_codec_hphl_dac_event()
3468 int event) in wcd9335_codec_hphl_dac_event()
3470 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_hphl_dac_event() local
3471 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_hphl_dac_event()
3472 int hph_mode = wcd->hph_mode; in wcd9335_codec_hphl_dac_event()
3478 dem_inp = snd_soc_component_read(comp, in wcd9335_codec_hphl_dac_event()
3482 dev_err(comp->dev, "Incorrect DEM Input\n"); in wcd9335_codec_hphl_dac_event()
3483 return -EINVAL; in wcd9335_codec_hphl_dac_event()
3485 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, in wcd9335_codec_hphl_dac_event()
3490 wcd9335_codec_hph_mode_config(comp, event, hph_mode); in wcd9335_codec_hphl_dac_event()
3502 if (!(wcd_clsh_ctrl_get_state(wcd->clsh_ctrl) & in wcd9335_codec_hphl_dac_event()
3504 wcd9335_codec_hph_mode_config(comp, event, hph_mode); in wcd9335_codec_hphl_dac_event()
3506 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_hphl_dac_event()
3516 static int wcd9335_codec_lineout_dac_event(struct snd_soc_dapm_widget *w, in wcd9335_codec_lineout_dac_event()
3517 struct snd_kcontrol *kc, int event) in wcd9335_codec_lineout_dac_event()
3519 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_lineout_dac_event() local
3520 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_lineout_dac_event()
3524 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, in wcd9335_codec_lineout_dac_event()
3528 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_lineout_dac_event()
3536 static int wcd9335_codec_ear_dac_event(struct snd_soc_dapm_widget *w, in wcd9335_codec_ear_dac_event()
3537 struct snd_kcontrol *kc, int event) in wcd9335_codec_ear_dac_event()
3539 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_ear_dac_event() local
3540 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_ear_dac_event()
3544 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, in wcd9335_codec_ear_dac_event()
3549 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_ear_dac_event()
3558 int mode, int event) in wcd9335_codec_hph_post_pa_config()
3579 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3584 if (wcd->comp_enabled[COMPANDER_1] || in wcd9335_codec_hph_post_pa_config()
3585 wcd->comp_enabled[COMPANDER_2]) { in wcd9335_codec_hph_post_pa_config()
3587 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3591 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3595 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3600 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3603 wcd->hph_l_gain); in wcd9335_codec_hph_post_pa_config()
3604 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3607 wcd->hph_r_gain); in wcd9335_codec_hph_post_pa_config()
3611 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3617 static int wcd9335_codec_hphr_dac_event(struct snd_soc_dapm_widget *w, in wcd9335_codec_hphr_dac_event()
3619 int event) in wcd9335_codec_hphr_dac_event()
3621 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_hphr_dac_event() local
3622 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_hphr_dac_event()
3623 int hph_mode = wcd->hph_mode; in wcd9335_codec_hphr_dac_event()
3630 dem_inp = snd_soc_component_read(comp, in wcd9335_codec_hphr_dac_event()
3635 dev_err(comp->dev, "DEM Input not set correctly, hph_mode: %d\n", in wcd9335_codec_hphr_dac_event()
3637 return -EINVAL; in wcd9335_codec_hphr_dac_event()
3640 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, in wcd9335_codec_hphr_dac_event()
3646 wcd9335_codec_hph_mode_config(comp, event, hph_mode); in wcd9335_codec_hphr_dac_event()
3653 if (!(wcd_clsh_ctrl_get_state(wcd->clsh_ctrl) & in wcd9335_codec_hphr_dac_event()
3655 wcd9335_codec_hph_mode_config(comp, event, hph_mode); in wcd9335_codec_hphr_dac_event()
3657 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_hphr_dac_event()
3666 static int wcd9335_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_hphl_pa()
3668 int event) in wcd9335_codec_enable_hphl_pa()
3670 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_hphl_pa() local
3671 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_hphl_pa()
3672 int hph_mode = wcd->hph_mode; in wcd9335_codec_enable_hphl_pa()
3685 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_hphl_pa()
3691 if ((snd_soc_component_read(comp, in wcd9335_codec_enable_hphl_pa()
3694 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_hphl_pa()
3714 static int wcd9335_codec_enable_lineout_pa(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_lineout_pa()
3716 int event) in wcd9335_codec_enable_lineout_pa()
3718 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_lineout_pa() local
3719 int vol_reg = 0, mix_vol_reg = 0; in wcd9335_codec_enable_lineout_pa()
3721 if (w->reg == WCD9335_ANA_LO_1_2) { in wcd9335_codec_enable_lineout_pa()
3722 if (w->shift == 7) { in wcd9335_codec_enable_lineout_pa()
3725 } else if (w->shift == 6) { in wcd9335_codec_enable_lineout_pa()
3729 } else if (w->reg == WCD9335_ANA_LO_3_4) { in wcd9335_codec_enable_lineout_pa()
3730 if (w->shift == 7) { in wcd9335_codec_enable_lineout_pa()
3733 } else if (w->shift == 6) { in wcd9335_codec_enable_lineout_pa()
3738 dev_err(comp->dev, "Error enabling lineout PA\n"); in wcd9335_codec_enable_lineout_pa()
3739 return -EINVAL; in wcd9335_codec_enable_lineout_pa()
3748 snd_soc_component_update_bits(comp, vol_reg, in wcd9335_codec_enable_lineout_pa()
3753 if ((snd_soc_component_read(comp, mix_vol_reg)) & in wcd9335_codec_enable_lineout_pa()
3755 snd_soc_component_update_bits(comp, mix_vol_reg, in wcd9335_codec_enable_lineout_pa()
3786 static int wcd9335_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_rx_bias()
3787 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_rx_bias()
3789 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_rx_bias() local
3790 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_rx_bias()
3794 wcd->rx_bias_count++; in wcd9335_codec_enable_rx_bias()
3795 if (wcd->rx_bias_count == 1) { in wcd9335_codec_enable_rx_bias()
3796 wcd9335_codec_init_flyback(comp); in wcd9335_codec_enable_rx_bias()
3797 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_rx_bias()
3804 wcd->rx_bias_count--; in wcd9335_codec_enable_rx_bias()
3805 if (!wcd->rx_bias_count) in wcd9335_codec_enable_rx_bias()
3806 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_rx_bias()
3816 static int wcd9335_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_hphr_pa()
3817 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_hphr_pa()
3819 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_hphr_pa() local
3820 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_hphr_pa()
3821 int hph_mode = wcd->hph_mode; in wcd9335_codec_enable_hphr_pa()
3833 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_hphr_pa()
3838 if ((snd_soc_component_read(comp, in wcd9335_codec_enable_hphr_pa()
3841 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_hphr_pa()
3862 static int wcd9335_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_ear_pa()
3863 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_ear_pa()
3865 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_ear_pa() local
3873 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_ear_pa()
3878 if ((snd_soc_component_read(comp, in wcd9335_codec_enable_ear_pa()
3881 snd_soc_component_update_bits(comp, in wcd9335_codec_enable_ear_pa()
3898 static irqreturn_t wcd9335_slimbus_irq(int irq, void *data) in wcd9335_slimbus_irq()
3902 int i, j, port_id; in wcd9335_slimbus_irq()
3903 unsigned int val, int_val = 0; in wcd9335_slimbus_irq()
3910 regmap_read(wcd->if_regmap, i, &val); in wcd9335_slimbus_irq()
3916 port_id = (tx ? j - 16 : j); in wcd9335_slimbus_irq()
3917 regmap_read(wcd->if_regmap, in wcd9335_slimbus_irq()
3927 wcd->if_regmap, reg, &int_val); in wcd9335_slimbus_irq()
3937 dev_err_ratelimited(wcd->dev, in wcd9335_slimbus_irq()
3942 dev_err_ratelimited(wcd->dev, in wcd9335_slimbus_irq()
3955 wcd->if_regmap, reg, &int_val); in wcd9335_slimbus_irq()
3958 regmap_write(wcd->if_regmap, in wcd9335_slimbus_irq()
3963 regmap_write(wcd->if_regmap, in wcd9335_slimbus_irq()
3980 static int wcd9335_setup_irqs(struct wcd9335_codec *wcd) in wcd9335_setup_irqs()
3982 int irq, ret, i; in wcd9335_setup_irqs()
3985 irq = regmap_irq_get_virq(wcd->irq_data, wcd9335_irqs[i].irq); in wcd9335_setup_irqs()
3987 dev_err(wcd->dev, "Failed to get %s\n", in wcd9335_setup_irqs()
3992 ret = devm_request_threaded_irq(wcd->dev, irq, NULL, in wcd9335_setup_irqs()
3998 dev_err(wcd->dev, "Failed to request %s\n", in wcd9335_setup_irqs()
4006 regmap_write(wcd->if_regmap, WCD9335_SLIM_PGD_PORT_INT_EN0 + i, in wcd9335_setup_irqs()
4014 int i; in wcd9335_teardown_irqs()
4018 regmap_write(wcd->if_regmap, WCD9335_SLIM_PGD_PORT_INT_EN0 + i, in wcd9335_teardown_irqs()
4025 struct snd_soc_component *comp = wcd->component; in wcd9335_cdc_sido_ccl_enable() local
4028 if (++wcd->sido_ccl_cnt == 1) in wcd9335_cdc_sido_ccl_enable()
4029 snd_soc_component_write(comp, WCD9335_SIDO_SIDO_CCL_10, in wcd9335_cdc_sido_ccl_enable()
4032 if (wcd->sido_ccl_cnt == 0) { in wcd9335_cdc_sido_ccl_enable()
4033 dev_err(wcd->dev, "sido_ccl already disabled\n"); in wcd9335_cdc_sido_ccl_enable()
4036 if (--wcd->sido_ccl_cnt == 0) in wcd9335_cdc_sido_ccl_enable()
4037 snd_soc_component_write(comp, WCD9335_SIDO_SIDO_CCL_10, in wcd9335_cdc_sido_ccl_enable()
4042 static int wcd9335_enable_master_bias(struct wcd9335_codec *wcd) in wcd9335_enable_master_bias()
4044 wcd->master_bias_users++; in wcd9335_enable_master_bias()
4045 if (wcd->master_bias_users == 1) { in wcd9335_enable_master_bias()
4046 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4049 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4053 * 1ms delay is required after pre-charge is enabled in wcd9335_enable_master_bias()
4057 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4060 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4068 static int wcd9335_enable_mclk(struct wcd9335_codec *wcd) in wcd9335_enable_mclk()
4071 if (wcd->master_bias_users <= 0) in wcd9335_enable_mclk()
4072 return -EINVAL; in wcd9335_enable_mclk()
4074 if (((wcd->clk_mclk_users == 0) && (wcd->clk_type == WCD_CLK_MCLK)) || in wcd9335_enable_mclk()
4075 ((wcd->clk_mclk_users > 0) && (wcd->clk_type != WCD_CLK_MCLK))) { in wcd9335_enable_mclk()
4076 dev_err(wcd->dev, "Error enabling MCLK, clk_type: %d\n", in wcd9335_enable_mclk()
4077 wcd->clk_type); in wcd9335_enable_mclk()
4078 return -EINVAL; in wcd9335_enable_mclk()
4081 if (++wcd->clk_mclk_users == 1) { in wcd9335_enable_mclk()
4082 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_enable_mclk()
4085 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_enable_mclk()
4088 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_enable_mclk()
4091 regmap_update_bits(wcd->regmap, in wcd9335_enable_mclk()
4095 regmap_update_bits(wcd->regmap, in wcd9335_enable_mclk()
4106 wcd->clk_type = WCD_CLK_MCLK; in wcd9335_enable_mclk()
4111 static int wcd9335_disable_mclk(struct wcd9335_codec *wcd) in wcd9335_disable_mclk()
4113 if (wcd->clk_mclk_users <= 0) in wcd9335_disable_mclk()
4114 return -EINVAL; in wcd9335_disable_mclk()
4116 if (--wcd->clk_mclk_users == 0) { in wcd9335_disable_mclk()
4117 if (wcd->clk_rco_users > 0) { in wcd9335_disable_mclk()
4119 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_disable_mclk()
4122 wcd->clk_type = WCD_CLK_RCO; in wcd9335_disable_mclk()
4124 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_disable_mclk()
4127 wcd->clk_type = WCD_CLK_OFF; in wcd9335_disable_mclk()
4130 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_disable_mclk()
4138 static int wcd9335_disable_master_bias(struct wcd9335_codec *wcd) in wcd9335_disable_master_bias()
4140 if (wcd->master_bias_users <= 0) in wcd9335_disable_master_bias()
4141 return -EINVAL; in wcd9335_disable_master_bias()
4143 wcd->master_bias_users--; in wcd9335_disable_master_bias()
4144 if (wcd->master_bias_users == 0) { in wcd9335_disable_master_bias()
4145 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_disable_master_bias()
4148 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_disable_master_bias()
4155 static int wcd9335_cdc_req_mclk_enable(struct wcd9335_codec *wcd, in wcd9335_cdc_req_mclk_enable()
4158 int ret = 0; in wcd9335_cdc_req_mclk_enable()
4162 ret = clk_prepare_enable(wcd->mclk); in wcd9335_cdc_req_mclk_enable()
4164 dev_err(wcd->dev, "%s: ext clk enable failed\n", in wcd9335_cdc_req_mclk_enable()
4178 clk_disable_unprepare(wcd->mclk); in wcd9335_cdc_req_mclk_enable()
4188 struct snd_soc_component *comp = wcd->component; in wcd9335_codec_apply_sido_voltage() local
4189 int vout_d_val; in wcd9335_codec_apply_sido_voltage()
4191 if (req_mv == wcd->sido_voltage) in wcd9335_codec_apply_sido_voltage()
4197 snd_soc_component_write(comp, WCD9335_ANA_BUCK_VOUT_D, vout_d_val); in wcd9335_codec_apply_sido_voltage()
4198 snd_soc_component_update_bits(comp, WCD9335_ANA_BUCK_CTL, in wcd9335_codec_apply_sido_voltage()
4204 wcd->sido_voltage = req_mv; in wcd9335_codec_apply_sido_voltage()
4205 snd_soc_component_update_bits(comp, WCD9335_ANA_BUCK_CTL, in wcd9335_codec_apply_sido_voltage()
4210 static int wcd9335_codec_update_sido_voltage(struct wcd9335_codec *wcd, in wcd9335_codec_update_sido_voltage()
4213 int ret = 0; in wcd9335_codec_update_sido_voltage()
4218 dev_err(wcd->dev, "Ext clk enable failed\n"); in wcd9335_codec_update_sido_voltage()
4229 static int _wcd9335_codec_enable_mclk(struct snd_soc_component *component, in _wcd9335_codec_enable_mclk()
4230 int enable) in _wcd9335_codec_enable_mclk()
4232 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in _wcd9335_codec_enable_mclk()
4233 int ret; in _wcd9335_codec_enable_mclk()
4244 wcd->sido_voltage); in _wcd9335_codec_enable_mclk()
4251 static int wcd9335_codec_enable_mclk(struct snd_soc_dapm_widget *w, in wcd9335_codec_enable_mclk()
4252 struct snd_kcontrol *kc, int event) in wcd9335_codec_enable_mclk()
4254 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_mclk() local
4258 return _wcd9335_codec_enable_mclk(comp, true); in wcd9335_codec_enable_mclk()
4260 return _wcd9335_codec_enable_mclk(comp, false); in wcd9335_codec_enable_mclk()
4723 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_enable_sido_buck()
4738 wcd->sido_input_src = SIDO_SOURCE_RCO_BG; in wcd9335_enable_sido_buck()
4741 static int wcd9335_enable_efuse_sensing(struct snd_soc_component *comp) in wcd9335_enable_efuse_sensing() argument
4743 _wcd9335_codec_enable_mclk(comp, true); in wcd9335_enable_efuse_sensing()
4744 snd_soc_component_update_bits(comp, in wcd9335_enable_efuse_sensing()
4754 if (!(snd_soc_component_read(comp, in wcd9335_enable_efuse_sensing()
4759 wcd9335_enable_sido_buck(comp); in wcd9335_enable_efuse_sensing()
4760 _wcd9335_codec_enable_mclk(comp, false); in wcd9335_enable_efuse_sensing()
4767 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_init()
4768 int i; in wcd9335_codec_init()
4771 regmap_update_bits(wcd->regmap, WCD9335_CODEC_RPM_CLK_GATE, in wcd9335_codec_init()
4774 regmap_update_bits(wcd->regmap, WCD9335_CODEC_RPM_CLK_MCLK_CFG, in wcd9335_codec_init()
4787 static int wcd9335_codec_probe(struct snd_soc_component *component) in wcd9335_codec_probe()
4789 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_probe()
4790 int ret; in wcd9335_codec_probe()
4791 int i; in wcd9335_codec_probe()
4793 snd_soc_component_init_regmap(component, wcd->regmap); in wcd9335_codec_probe()
4794 /* Class-H Init*/ in wcd9335_codec_probe()
4795 wcd->clsh_ctrl = wcd_clsh_ctrl_alloc(component, WCD9335); in wcd9335_codec_probe()
4796 if (IS_ERR(wcd->clsh_ctrl)) in wcd9335_codec_probe()
4797 return PTR_ERR(wcd->clsh_ctrl); in wcd9335_codec_probe()
4799 /* Default HPH Mode to Class-H HiFi */ in wcd9335_codec_probe()
4800 wcd->hph_mode = CLS_H_HIFI; in wcd9335_codec_probe()
4801 wcd->component = component; in wcd9335_codec_probe()
4806 INIT_LIST_HEAD(&wcd->dai[i].slim_ch_list); in wcd9335_codec_probe()
4815 wcd_clsh_ctrl_free(wcd->clsh_ctrl); in wcd9335_codec_probe()
4819 static void wcd9335_codec_remove(struct snd_soc_component *comp) in wcd9335_codec_remove() argument
4821 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_remove()
4823 wcd_clsh_ctrl_free(wcd->clsh_ctrl); in wcd9335_codec_remove()
4827 static int wcd9335_codec_set_sysclk(struct snd_soc_component *comp, in wcd9335_codec_set_sysclk() argument
4828 int clk_id, int source, in wcd9335_codec_set_sysclk()
4829 unsigned int freq, int dir) in wcd9335_codec_set_sysclk()
4831 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_set_sysclk()
4833 wcd->mclk_rate = freq; in wcd9335_codec_set_sysclk()
4835 if (wcd->mclk_rate == WCD9335_MCLK_CLK_12P288MHZ) in wcd9335_codec_set_sysclk()
4836 snd_soc_component_update_bits(comp, in wcd9335_codec_set_sysclk()
4840 else if (wcd->mclk_rate == WCD9335_MCLK_CLK_9P6MHZ) in wcd9335_codec_set_sysclk()
4841 snd_soc_component_update_bits(comp, in wcd9335_codec_set_sysclk()
4846 return clk_set_rate(wcd->mclk, freq); in wcd9335_codec_set_sysclk()
4862 static int wcd9335_probe(struct wcd9335_codec *wcd) in wcd9335_probe()
4864 struct device *dev = wcd->dev; in wcd9335_probe()
4866 memcpy(wcd->rx_chs, wcd9335_rx_chs, sizeof(wcd9335_rx_chs)); in wcd9335_probe()
4867 memcpy(wcd->tx_chs, wcd9335_tx_chs, sizeof(wcd9335_tx_chs)); in wcd9335_probe()
4869 wcd->sido_input_src = SIDO_SOURCE_INTERNAL; in wcd9335_probe()
4870 wcd->sido_voltage = SIDO_VOLTAGE_NOMINAL_MV; in wcd9335_probe()
4890 static bool wcd9335_is_volatile_register(struct device *dev, unsigned int reg) in wcd9335_is_volatile_register()
4922 .name = "WCD9335-IFC-DEV",
4955 static const unsigned int wcd9335_config_regs[] = {
4973 static int wcd9335_parse_dt(struct wcd9335_codec *wcd) in wcd9335_parse_dt()
4975 struct device *dev = wcd->dev; in wcd9335_parse_dt()
4976 struct device_node *np = dev->of_node; in wcd9335_parse_dt()
4977 int ret; in wcd9335_parse_dt()
4979 wcd->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0); in wcd9335_parse_dt()
4980 if (wcd->reset_gpio < 0) in wcd9335_parse_dt()
4981 return dev_err_probe(dev, wcd->reset_gpio, "Reset GPIO missing from DT\n"); in wcd9335_parse_dt()
4983 wcd->mclk = devm_clk_get(dev, "mclk"); in wcd9335_parse_dt()
4984 if (IS_ERR(wcd->mclk)) in wcd9335_parse_dt()
4985 return dev_err_probe(dev, PTR_ERR(wcd->mclk), "mclk not found\n"); in wcd9335_parse_dt()
4987 wcd->native_clk = devm_clk_get(dev, "slimbus"); in wcd9335_parse_dt()
4988 if (IS_ERR(wcd->native_clk)) in wcd9335_parse_dt()
4989 return dev_err_probe(dev, PTR_ERR(wcd->native_clk), "slimbus clock not found\n"); in wcd9335_parse_dt()
4991 wcd->supplies[0].supply = "vdd-buck"; in wcd9335_parse_dt()
4992 wcd->supplies[1].supply = "vdd-buck-sido"; in wcd9335_parse_dt()
4993 wcd->supplies[2].supply = "vdd-tx"; in wcd9335_parse_dt()
4994 wcd->supplies[3].supply = "vdd-rx"; in wcd9335_parse_dt()
4995 wcd->supplies[4].supply = "vdd-io"; in wcd9335_parse_dt()
4997 ret = regulator_bulk_get(dev, WCD9335_MAX_SUPPLY, wcd->supplies); in wcd9335_parse_dt()
5004 static int wcd9335_power_on_reset(struct wcd9335_codec *wcd) in wcd9335_power_on_reset()
5006 struct device *dev = wcd->dev; in wcd9335_power_on_reset()
5007 int ret; in wcd9335_power_on_reset()
5009 ret = regulator_bulk_enable(WCD9335_MAX_SUPPLY, wcd->supplies); in wcd9335_power_on_reset()
5024 gpio_direction_output(wcd->reset_gpio, 0); in wcd9335_power_on_reset()
5026 gpio_set_value(wcd->reset_gpio, 1); in wcd9335_power_on_reset()
5032 static int wcd9335_bring_up(struct wcd9335_codec *wcd) in wcd9335_bring_up()
5034 struct regmap *rm = wcd->regmap; in wcd9335_bring_up()
5035 int val, byte0; in wcd9335_bring_up()
5041 dev_err(wcd->dev, "WCD9335 CODEC version detection fail!\n"); in wcd9335_bring_up()
5042 return -EINVAL; in wcd9335_bring_up()
5046 dev_info(wcd->dev, "WCD9335 CODEC version is v2.0\n"); in wcd9335_bring_up()
5056 dev_err(wcd->dev, "WCD9335 CODEC version not supported\n"); in wcd9335_bring_up()
5057 return -EINVAL; in wcd9335_bring_up()
5063 static int wcd9335_irq_init(struct wcd9335_codec *wcd) in wcd9335_irq_init()
5065 int ret; in wcd9335_irq_init()
5072 wcd->intr1 = of_irq_get_byname(wcd->dev->of_node, "intr1"); in wcd9335_irq_init()
5073 if (wcd->intr1 < 0) in wcd9335_irq_init()
5074 return dev_err_probe(wcd->dev, wcd->intr1, in wcd9335_irq_init()
5077 ret = devm_regmap_add_irq_chip(wcd->dev, wcd->regmap, wcd->intr1, in wcd9335_irq_init()
5079 &wcd9335_regmap_irq1_chip, &wcd->irq_data); in wcd9335_irq_init()
5081 return dev_err_probe(wcd->dev, ret, "Failed to register IRQ chip\n"); in wcd9335_irq_init()
5086 static int wcd9335_slim_probe(struct slim_device *slim) in wcd9335_slim_probe()
5088 struct device *dev = &slim->dev; in wcd9335_slim_probe()
5090 int ret; in wcd9335_slim_probe()
5094 return -ENOMEM; in wcd9335_slim_probe()
5096 wcd->dev = dev; in wcd9335_slim_probe()
5110 static int wcd9335_slim_status(struct slim_device *sdev, in wcd9335_slim_status()
5113 struct device *dev = &sdev->dev; in wcd9335_slim_status()
5116 int ret; in wcd9335_slim_status()
5120 ifc_dev_np = of_parse_phandle(dev->of_node, "slim-ifc-dev", 0); in wcd9335_slim_status()
5123 return -EINVAL; in wcd9335_slim_status()
5126 wcd->slim = sdev; in wcd9335_slim_status()
5127 wcd->slim_ifc_dev = of_slim_get_device(sdev->ctrl, ifc_dev_np); in wcd9335_slim_status()
5129 if (!wcd->slim_ifc_dev) { in wcd9335_slim_status()
5131 return -EINVAL; in wcd9335_slim_status()
5134 slim_get_logical_addr(wcd->slim_ifc_dev); in wcd9335_slim_status()
5136 wcd->regmap = regmap_init_slimbus(sdev, &wcd9335_regmap_config); in wcd9335_slim_status()
5137 if (IS_ERR(wcd->regmap)) in wcd9335_slim_status()
5138 return dev_err_probe(dev, PTR_ERR(wcd->regmap), in wcd9335_slim_status()
5141 wcd->if_regmap = regmap_init_slimbus(wcd->slim_ifc_dev, in wcd9335_slim_status()
5143 if (IS_ERR(wcd->if_regmap)) in wcd9335_slim_status()
5144 return dev_err_probe(dev, PTR_ERR(wcd->if_regmap), in wcd9335_slim_status()
5170 .name = "wcd9335-slim",