Meng Wang | 43bbb87 | 2018-12-10 12:32:05 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Vatsal Bucha | 39ead2c | 2018-12-14 12:22:46 +0530 | [diff] [blame] | 2 | /* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/clk.h> |
| 8 | #include <linux/io.h> |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/regmap.h> |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 11 | #include <linux/pm_runtime.h> |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 12 | #include <sound/soc.h> |
| 13 | #include <sound/soc-dapm.h> |
| 14 | #include <sound/tlv.h> |
Sudheer Papothi | a3e969d | 2018-10-27 06:22:10 +0530 | [diff] [blame] | 15 | #include <soc/swr-common.h> |
Laxminath Kasam | fb0d683 | 2018-09-22 01:49:52 +0530 | [diff] [blame] | 16 | #include <soc/swr-wcd.h> |
Meng Wang | 11a25cf | 2018-10-31 14:11:26 +0800 | [diff] [blame] | 17 | #include <asoc/msm-cdc-pinctrl.h> |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 18 | #include "bolero-cdc.h" |
| 19 | #include "bolero-cdc-registers.h" |
Vidyakumar Athota | 5d45f4c | 2019-03-10 22:35:07 -0700 | [diff] [blame] | 20 | #include "bolero-clk-rsc.h" |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 21 | |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 22 | #define AUTO_SUSPEND_DELAY 50 /* delay in msec */ |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 23 | #define TX_MACRO_MAX_OFFSET 0x1000 |
| 24 | |
| 25 | #define NUM_DECIMATORS 8 |
| 26 | |
| 27 | #define TX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 28 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 29 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) |
| 30 | #define TX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ |
| 31 | SNDRV_PCM_FMTBIT_S24_LE |\ |
| 32 | SNDRV_PCM_FMTBIT_S24_3LE) |
| 33 | |
| 34 | #define TX_HPF_CUT_OFF_FREQ_MASK 0x60 |
| 35 | #define CF_MIN_3DB_4HZ 0x0 |
| 36 | #define CF_MIN_3DB_75HZ 0x1 |
| 37 | #define CF_MIN_3DB_150HZ 0x2 |
| 38 | |
| 39 | #define TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0 |
| 40 | #define TX_MACRO_MCLK_FREQ 9600000 |
| 41 | #define TX_MACRO_TX_PATH_OFFSET 0x80 |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 42 | #define TX_MACRO_SWR_MIC_MUX_SEL_MASK 0xF |
| 43 | #define TX_MACRO_ADC_MUX_CFG_OFFSET 0x2 |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 44 | |
| 45 | #define TX_MACRO_TX_UNMUTE_DELAY_MS 40 |
| 46 | |
| 47 | static int tx_unmute_delay = TX_MACRO_TX_UNMUTE_DELAY_MS; |
| 48 | module_param(tx_unmute_delay, int, 0664); |
| 49 | MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path"); |
| 50 | |
| 51 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 52 | |
| 53 | static int tx_macro_hw_params(struct snd_pcm_substream *substream, |
| 54 | struct snd_pcm_hw_params *params, |
| 55 | struct snd_soc_dai *dai); |
| 56 | static int tx_macro_get_channel_map(struct snd_soc_dai *dai, |
| 57 | unsigned int *tx_num, unsigned int *tx_slot, |
| 58 | unsigned int *rx_num, unsigned int *rx_slot); |
| 59 | |
| 60 | #define TX_MACRO_SWR_STRING_LEN 80 |
| 61 | #define TX_MACRO_CHILD_DEVICES_MAX 3 |
| 62 | |
| 63 | /* Hold instance to soundwire platform device */ |
| 64 | struct tx_macro_swr_ctrl_data { |
| 65 | struct platform_device *tx_swr_pdev; |
| 66 | }; |
| 67 | |
| 68 | struct tx_macro_swr_ctrl_platform_data { |
| 69 | void *handle; /* holds codec private data */ |
| 70 | int (*read)(void *handle, int reg); |
| 71 | int (*write)(void *handle, int reg, int val); |
| 72 | int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len); |
| 73 | int (*clk)(void *handle, bool enable); |
| 74 | int (*handle_irq)(void *handle, |
| 75 | irqreturn_t (*swrm_irq_handler)(int irq, |
| 76 | void *data), |
| 77 | void *swrm_handle, |
| 78 | int action); |
| 79 | }; |
| 80 | |
| 81 | enum { |
Laxminath Kasam | 59c7a1d | 2018-08-09 16:11:17 +0530 | [diff] [blame] | 82 | TX_MACRO_AIF_INVALID = 0, |
| 83 | TX_MACRO_AIF1_CAP, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 84 | TX_MACRO_AIF2_CAP, |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 85 | TX_MACRO_AIF3_CAP, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 86 | TX_MACRO_MAX_DAIS |
| 87 | }; |
| 88 | |
| 89 | enum { |
| 90 | TX_MACRO_DEC0, |
| 91 | TX_MACRO_DEC1, |
| 92 | TX_MACRO_DEC2, |
| 93 | TX_MACRO_DEC3, |
| 94 | TX_MACRO_DEC4, |
| 95 | TX_MACRO_DEC5, |
| 96 | TX_MACRO_DEC6, |
| 97 | TX_MACRO_DEC7, |
| 98 | TX_MACRO_DEC_MAX, |
| 99 | }; |
| 100 | |
| 101 | enum { |
| 102 | TX_MACRO_CLK_DIV_2, |
| 103 | TX_MACRO_CLK_DIV_3, |
| 104 | TX_MACRO_CLK_DIV_4, |
| 105 | TX_MACRO_CLK_DIV_6, |
| 106 | TX_MACRO_CLK_DIV_8, |
| 107 | TX_MACRO_CLK_DIV_16, |
| 108 | }; |
| 109 | |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 110 | enum { |
| 111 | MSM_DMIC, |
| 112 | SWR_MIC, |
| 113 | ANC_FB_TUNE1 |
| 114 | }; |
| 115 | |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 116 | enum { |
| 117 | TX_MCLK, |
| 118 | VA_MCLK, |
| 119 | }; |
| 120 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 121 | struct tx_mute_work { |
| 122 | struct tx_macro_priv *tx_priv; |
| 123 | u32 decimator; |
| 124 | struct delayed_work dwork; |
| 125 | }; |
| 126 | |
| 127 | struct hpf_work { |
| 128 | struct tx_macro_priv *tx_priv; |
| 129 | u8 decimator; |
| 130 | u8 hpf_cut_off_freq; |
| 131 | struct delayed_work dwork; |
| 132 | }; |
| 133 | |
| 134 | struct tx_macro_priv { |
| 135 | struct device *dev; |
| 136 | bool dec_active[NUM_DECIMATORS]; |
| 137 | int tx_mclk_users; |
| 138 | int swr_clk_users; |
Ramprasad Katkam | 452772a | 2019-01-07 17:30:36 +0530 | [diff] [blame] | 139 | bool dapm_mclk_enable; |
Ramprasad Katkam | a4c747b | 2018-12-11 19:15:53 +0530 | [diff] [blame] | 140 | bool reset_swr; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 141 | struct mutex mclk_lock; |
| 142 | struct mutex swr_clk_lock; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 143 | struct snd_soc_component *component; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 144 | struct device_node *tx_swr_gpio_p; |
| 145 | struct tx_macro_swr_ctrl_data *swr_ctrl_data; |
| 146 | struct tx_macro_swr_ctrl_platform_data swr_plat_data; |
| 147 | struct work_struct tx_macro_add_child_devices_work; |
| 148 | struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 149 | struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS]; |
| 150 | s32 dmic_0_1_clk_cnt; |
| 151 | s32 dmic_2_3_clk_cnt; |
| 152 | s32 dmic_4_5_clk_cnt; |
| 153 | s32 dmic_6_7_clk_cnt; |
| 154 | u16 dmic_clk_div; |
| 155 | unsigned long active_ch_mask[TX_MACRO_MAX_DAIS]; |
| 156 | unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS]; |
| 157 | char __iomem *tx_io_base; |
| 158 | struct platform_device *pdev_child_devices |
| 159 | [TX_MACRO_CHILD_DEVICES_MAX]; |
| 160 | int child_count; |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 161 | int tx_swr_clk_cnt; |
| 162 | int va_swr_clk_cnt; |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 163 | int va_clk_status; |
| 164 | int tx_clk_status; |
Karthikeyan Mani | 765eaab | 2019-07-18 16:27:01 -0700 | [diff] [blame] | 165 | bool bcs_enable; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 166 | }; |
| 167 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 168 | static bool tx_macro_get_data(struct snd_soc_component *component, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 169 | struct device **tx_dev, |
| 170 | struct tx_macro_priv **tx_priv, |
| 171 | const char *func_name) |
| 172 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 173 | *tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 174 | if (!(*tx_dev)) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 175 | dev_err(component->dev, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 176 | "%s: null device for macro!\n", func_name); |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | *tx_priv = dev_get_drvdata((*tx_dev)); |
| 181 | if (!(*tx_priv)) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 182 | dev_err(component->dev, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 183 | "%s: priv is null for macro!\n", func_name); |
| 184 | return false; |
| 185 | } |
| 186 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 187 | if (!(*tx_priv)->component) { |
| 188 | dev_err(component->dev, |
| 189 | "%s: tx_priv->component not initialized!\n", func_name); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 190 | return false; |
| 191 | } |
| 192 | |
| 193 | return true; |
| 194 | } |
| 195 | |
| 196 | static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv, |
| 197 | bool mclk_enable) |
| 198 | { |
| 199 | struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL); |
| 200 | int ret = 0; |
| 201 | |
Tanya Dixit | 8530fb9 | 2018-09-14 16:01:25 +0530 | [diff] [blame] | 202 | if (regmap == NULL) { |
| 203 | dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__); |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | |
Laxminath Kasam | b7f823c | 2018-08-02 13:23:11 +0530 | [diff] [blame] | 207 | dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n", |
| 208 | __func__, mclk_enable, tx_priv->tx_mclk_users); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 209 | |
| 210 | mutex_lock(&tx_priv->mclk_lock); |
| 211 | if (mclk_enable) { |
| 212 | if (tx_priv->tx_mclk_users == 0) { |
Vidyakumar Athota | 5d45f4c | 2019-03-10 22:35:07 -0700 | [diff] [blame] | 213 | ret = bolero_clk_rsc_request_clock(tx_priv->dev, |
| 214 | TX_CORE_CLK, |
| 215 | TX_CORE_CLK, |
| 216 | true); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 217 | if (ret < 0) { |
Ramprasad Katkam | 14efed6 | 2019-03-07 13:16:50 +0530 | [diff] [blame] | 218 | dev_err_ratelimited(tx_priv->dev, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 219 | "%s: request clock enable failed\n", |
| 220 | __func__); |
| 221 | goto exit; |
| 222 | } |
Vidyakumar Athota | 5d45f4c | 2019-03-10 22:35:07 -0700 | [diff] [blame] | 223 | bolero_clk_rsc_fs_gen_request(tx_priv->dev, |
| 224 | true); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 225 | regcache_mark_dirty(regmap); |
| 226 | regcache_sync_region(regmap, |
| 227 | TX_START_OFFSET, |
| 228 | TX_MAX_OFFSET); |
| 229 | /* 9.6MHz MCLK, set value 0x00 if other frequency */ |
| 230 | regmap_update_bits(regmap, |
| 231 | BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01); |
| 232 | regmap_update_bits(regmap, |
| 233 | BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL, |
| 234 | 0x01, 0x01); |
| 235 | regmap_update_bits(regmap, |
| 236 | BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL, |
| 237 | 0x01, 0x01); |
| 238 | } |
| 239 | tx_priv->tx_mclk_users++; |
| 240 | } else { |
| 241 | if (tx_priv->tx_mclk_users <= 0) { |
| 242 | dev_err(tx_priv->dev, "%s: clock already disabled\n", |
| 243 | __func__); |
| 244 | tx_priv->tx_mclk_users = 0; |
| 245 | goto exit; |
| 246 | } |
| 247 | tx_priv->tx_mclk_users--; |
| 248 | if (tx_priv->tx_mclk_users == 0) { |
| 249 | regmap_update_bits(regmap, |
| 250 | BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL, |
| 251 | 0x01, 0x00); |
| 252 | regmap_update_bits(regmap, |
| 253 | BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL, |
| 254 | 0x01, 0x00); |
Vidyakumar Athota | 5d45f4c | 2019-03-10 22:35:07 -0700 | [diff] [blame] | 255 | bolero_clk_rsc_fs_gen_request(tx_priv->dev, |
| 256 | false); |
| 257 | |
| 258 | bolero_clk_rsc_request_clock(tx_priv->dev, |
| 259 | TX_CORE_CLK, |
| 260 | TX_CORE_CLK, |
| 261 | false); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | exit: |
| 265 | mutex_unlock(&tx_priv->mclk_lock); |
| 266 | return ret; |
| 267 | } |
| 268 | |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 269 | static int tx_macro_va_swr_clk_event(struct snd_soc_dapm_widget *w, |
| 270 | struct snd_kcontrol *kcontrol, int event) |
| 271 | { |
| 272 | struct device *tx_dev = NULL; |
| 273 | struct tx_macro_priv *tx_priv = NULL; |
| 274 | struct snd_soc_component *component = |
| 275 | snd_soc_dapm_to_component(w->dapm); |
| 276 | |
| 277 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
| 278 | return -EINVAL; |
| 279 | |
| 280 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 281 | ++tx_priv->va_swr_clk_cnt; |
| 282 | if (SND_SOC_DAPM_EVENT_OFF(event)) |
| 283 | --tx_priv->va_swr_clk_cnt; |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | static int tx_macro_tx_swr_clk_event(struct snd_soc_dapm_widget *w, |
| 289 | struct snd_kcontrol *kcontrol, int event) |
| 290 | { |
| 291 | struct device *tx_dev = NULL; |
| 292 | struct tx_macro_priv *tx_priv = NULL; |
| 293 | struct snd_soc_component *component = |
| 294 | snd_soc_dapm_to_component(w->dapm); |
| 295 | |
| 296 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
| 297 | return -EINVAL; |
| 298 | |
| 299 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 300 | ++tx_priv->tx_swr_clk_cnt; |
| 301 | if (SND_SOC_DAPM_EVENT_OFF(event)) |
| 302 | --tx_priv->tx_swr_clk_cnt; |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 307 | static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w, |
| 308 | struct snd_kcontrol *kcontrol, int event) |
| 309 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 310 | struct snd_soc_component *component = |
| 311 | snd_soc_dapm_to_component(w->dapm); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 312 | int ret = 0; |
| 313 | struct device *tx_dev = NULL; |
| 314 | struct tx_macro_priv *tx_priv = NULL; |
| 315 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 316 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 317 | return -EINVAL; |
| 318 | |
| 319 | dev_dbg(tx_dev, "%s: event = %d\n", __func__, event); |
| 320 | switch (event) { |
| 321 | case SND_SOC_DAPM_PRE_PMU: |
| 322 | ret = tx_macro_mclk_enable(tx_priv, 1); |
Ramprasad Katkam | 452772a | 2019-01-07 17:30:36 +0530 | [diff] [blame] | 323 | if (ret) |
| 324 | tx_priv->dapm_mclk_enable = false; |
| 325 | else |
| 326 | tx_priv->dapm_mclk_enable = true; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 327 | break; |
| 328 | case SND_SOC_DAPM_POST_PMD: |
Ramprasad Katkam | 452772a | 2019-01-07 17:30:36 +0530 | [diff] [blame] | 329 | if (tx_priv->dapm_mclk_enable) |
| 330 | ret = tx_macro_mclk_enable(tx_priv, 0); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 331 | break; |
| 332 | default: |
| 333 | dev_err(tx_priv->dev, |
| 334 | "%s: invalid DAPM event %d\n", __func__, event); |
| 335 | ret = -EINVAL; |
| 336 | } |
| 337 | return ret; |
| 338 | } |
| 339 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 340 | static int tx_macro_event_handler(struct snd_soc_component *component, |
| 341 | u16 event, u32 data) |
Laxminath Kasam | fb0d683 | 2018-09-22 01:49:52 +0530 | [diff] [blame] | 342 | { |
| 343 | struct device *tx_dev = NULL; |
| 344 | struct tx_macro_priv *tx_priv = NULL; |
| 345 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 346 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | fb0d683 | 2018-09-22 01:49:52 +0530 | [diff] [blame] | 347 | return -EINVAL; |
| 348 | |
| 349 | switch (event) { |
| 350 | case BOLERO_MACRO_EVT_SSR_DOWN: |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 351 | if (tx_priv->swr_ctrl_data) { |
| 352 | swrm_wcd_notify( |
| 353 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 354 | SWR_DEVICE_DOWN, NULL); |
| 355 | swrm_wcd_notify( |
| 356 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 357 | SWR_DEVICE_SSR_DOWN, NULL); |
| 358 | } |
Meng Wang | bf1fe8f | 2019-06-26 15:39:41 +0800 | [diff] [blame] | 359 | if (!pm_runtime_status_suspended(tx_dev)) |
| 360 | bolero_runtime_suspend(tx_dev); |
Laxminath Kasam | fb0d683 | 2018-09-22 01:49:52 +0530 | [diff] [blame] | 361 | break; |
| 362 | case BOLERO_MACRO_EVT_SSR_UP: |
Ramprasad Katkam | a4c747b | 2018-12-11 19:15:53 +0530 | [diff] [blame] | 363 | /* reset swr after ssr/pdr */ |
| 364 | tx_priv->reset_swr = true; |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 365 | if (tx_priv->swr_ctrl_data) |
| 366 | swrm_wcd_notify( |
| 367 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 368 | SWR_DEVICE_SSR_UP, NULL); |
Laxminath Kasam | fb0d683 | 2018-09-22 01:49:52 +0530 | [diff] [blame] | 369 | break; |
Meng Wang | 8ef0cc2 | 2019-05-08 15:12:56 +0800 | [diff] [blame] | 370 | case BOLERO_MACRO_EVT_CLK_RESET: |
| 371 | bolero_rsc_clk_reset(tx_dev, TX_CORE_CLK); |
| 372 | break; |
Laxminath Kasam | fb0d683 | 2018-09-22 01:49:52 +0530 | [diff] [blame] | 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 377 | static int tx_macro_reg_wake_irq(struct snd_soc_component *component, |
Aditya Bavanari | c4e9612 | 2018-11-14 14:46:38 +0530 | [diff] [blame] | 378 | u32 data) |
| 379 | { |
| 380 | struct device *tx_dev = NULL; |
| 381 | struct tx_macro_priv *tx_priv = NULL; |
| 382 | u32 ipc_wakeup = data; |
| 383 | int ret = 0; |
| 384 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 385 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Aditya Bavanari | c4e9612 | 2018-11-14 14:46:38 +0530 | [diff] [blame] | 386 | return -EINVAL; |
| 387 | |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 388 | if (tx_priv->swr_ctrl_data) |
| 389 | ret = swrm_wcd_notify( |
| 390 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 391 | SWR_REGISTER_WAKE_IRQ, &ipc_wakeup); |
Aditya Bavanari | c4e9612 | 2018-11-14 14:46:38 +0530 | [diff] [blame] | 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 396 | static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work) |
| 397 | { |
| 398 | struct delayed_work *hpf_delayed_work = NULL; |
| 399 | struct hpf_work *hpf_work = NULL; |
| 400 | struct tx_macro_priv *tx_priv = NULL; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 401 | struct snd_soc_component *component = NULL; |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 402 | u16 dec_cfg_reg = 0, hpf_gate_reg = 0; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 403 | u8 hpf_cut_off_freq = 0; |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 404 | u16 adc_mux_reg = 0, adc_n = 0, adc_reg = 0; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 405 | |
| 406 | hpf_delayed_work = to_delayed_work(work); |
| 407 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 408 | tx_priv = hpf_work->tx_priv; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 409 | component = tx_priv->component; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 410 | hpf_cut_off_freq = hpf_work->hpf_cut_off_freq; |
| 411 | |
| 412 | dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 + |
| 413 | TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator; |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 414 | hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 + |
| 415 | TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 416 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 417 | dev_dbg(component->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n", |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 418 | __func__, hpf_work->decimator, hpf_cut_off_freq); |
| 419 | |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 420 | adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 + |
| 421 | TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 422 | if (snd_soc_component_read32(component, adc_mux_reg) & SWR_MIC) { |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 423 | adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 + |
| 424 | TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 425 | adc_n = snd_soc_component_read32(component, adc_reg) & |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 426 | TX_MACRO_SWR_MIC_MUX_SEL_MASK; |
| 427 | if (adc_n >= BOLERO_ADC_MAX) |
| 428 | goto tx_hpf_set; |
| 429 | /* analog mic clear TX hold */ |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 430 | bolero_clear_amic_tx_hold(component->dev, adc_n); |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 431 | } |
| 432 | tx_hpf_set: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 433 | snd_soc_component_update_bits(component, |
| 434 | dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK, |
| 435 | hpf_cut_off_freq << 5); |
| 436 | snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x02); |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 437 | /* Minimum 1 clk cycle delay is required as per HW spec */ |
| 438 | usleep_range(1000, 1010); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 439 | snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x01); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static void tx_macro_mute_update_callback(struct work_struct *work) |
| 443 | { |
| 444 | struct tx_mute_work *tx_mute_dwork = NULL; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 445 | struct snd_soc_component *component = NULL; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 446 | struct tx_macro_priv *tx_priv = NULL; |
| 447 | struct delayed_work *delayed_work = NULL; |
Xiaojun Sang | d155fdc | 2018-10-11 15:11:59 +0800 | [diff] [blame] | 448 | u16 tx_vol_ctl_reg = 0; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 449 | u8 decimator = 0; |
| 450 | |
| 451 | delayed_work = to_delayed_work(work); |
| 452 | tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork); |
| 453 | tx_priv = tx_mute_dwork->tx_priv; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 454 | component = tx_priv->component; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 455 | decimator = tx_mute_dwork->decimator; |
| 456 | |
| 457 | tx_vol_ctl_reg = |
| 458 | BOLERO_CDC_TX0_TX_PATH_CTL + |
| 459 | TX_MACRO_TX_PATH_OFFSET * decimator; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 460 | snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 461 | dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n", |
| 462 | __func__, decimator); |
| 463 | } |
| 464 | |
| 465 | static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 466 | struct snd_ctl_elem_value *ucontrol) |
| 467 | { |
| 468 | struct snd_soc_dapm_widget *widget = |
| 469 | snd_soc_dapm_kcontrol_widget(kcontrol); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 470 | struct snd_soc_component *component = |
| 471 | snd_soc_dapm_to_component(widget->dapm); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 472 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 473 | unsigned int val = 0; |
| 474 | u16 mic_sel_reg = 0; |
Laxminath Kasam | 549d11d | 2019-07-18 13:44:17 +0530 | [diff] [blame] | 475 | u16 dmic_clk_reg = 0; |
| 476 | struct device *tx_dev = NULL; |
| 477 | struct tx_macro_priv *tx_priv = NULL; |
| 478 | |
| 479 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
| 480 | return -EINVAL; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 481 | |
| 482 | val = ucontrol->value.enumerated.item[0]; |
| 483 | if (val > e->items - 1) |
| 484 | return -EINVAL; |
| 485 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 486 | dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 487 | widget->name, val); |
| 488 | |
| 489 | switch (e->reg) { |
| 490 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0: |
| 491 | mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0; |
| 492 | break; |
| 493 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0: |
| 494 | mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0; |
| 495 | break; |
| 496 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0: |
| 497 | mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0; |
| 498 | break; |
| 499 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0: |
| 500 | mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0; |
| 501 | break; |
| 502 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0: |
| 503 | mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0; |
| 504 | break; |
| 505 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0: |
| 506 | mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0; |
| 507 | break; |
| 508 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0: |
| 509 | mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0; |
| 510 | break; |
| 511 | case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0: |
| 512 | mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0; |
| 513 | break; |
| 514 | default: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 515 | dev_err(component->dev, "%s: e->reg: 0x%x not expected\n", |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 516 | __func__, e->reg); |
| 517 | return -EINVAL; |
| 518 | } |
Laxminath Kasam | 497a651 | 2018-09-17 16:11:52 +0530 | [diff] [blame] | 519 | if (strnstr(widget->name, "SMIC", strlen(widget->name))) { |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 520 | if (val != 0) { |
Laxminath Kasam | 549d11d | 2019-07-18 13:44:17 +0530 | [diff] [blame] | 521 | if (val < 5) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 522 | snd_soc_component_update_bits(component, |
| 523 | mic_sel_reg, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 524 | 1 << 7, 0x0 << 7); |
Laxminath Kasam | 549d11d | 2019-07-18 13:44:17 +0530 | [diff] [blame] | 525 | } else { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 526 | snd_soc_component_update_bits(component, |
| 527 | mic_sel_reg, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 528 | 1 << 7, 0x1 << 7); |
Laxminath Kasam | 549d11d | 2019-07-18 13:44:17 +0530 | [diff] [blame] | 529 | snd_soc_component_update_bits(component, |
| 530 | BOLERO_CDC_VA_TOP_CSR_DMIC_CFG, |
| 531 | 0x80, 0x00); |
| 532 | dmic_clk_reg = |
| 533 | BOLERO_CDC_TX_TOP_CSR_SWR_DMIC0_CTL + |
| 534 | ((val - 5)/2) * 4; |
| 535 | snd_soc_component_update_bits(component, |
| 536 | dmic_clk_reg, |
| 537 | 0x0E, tx_priv->dmic_clk_div << 0x1); |
| 538 | } |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 539 | } |
| 540 | } else { |
| 541 | /* DMIC selected */ |
| 542 | if (val != 0) |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 543 | snd_soc_component_update_bits(component, mic_sel_reg, |
| 544 | 1 << 7, 1 << 7); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | return snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 548 | } |
| 549 | |
| 550 | static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol, |
| 551 | struct snd_ctl_elem_value *ucontrol) |
| 552 | { |
| 553 | struct snd_soc_dapm_widget *widget = |
| 554 | snd_soc_dapm_kcontrol_widget(kcontrol); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 555 | struct snd_soc_component *component = |
| 556 | snd_soc_dapm_to_component(widget->dapm); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 557 | struct soc_multi_mixer_control *mixer = |
| 558 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 559 | u32 dai_id = widget->shift; |
| 560 | u32 dec_id = mixer->shift; |
| 561 | struct device *tx_dev = NULL; |
| 562 | struct tx_macro_priv *tx_priv = NULL; |
| 563 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 564 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 565 | return -EINVAL; |
| 566 | |
| 567 | if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id])) |
| 568 | ucontrol->value.integer.value[0] = 1; |
| 569 | else |
| 570 | ucontrol->value.integer.value[0] = 0; |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol, |
| 575 | struct snd_ctl_elem_value *ucontrol) |
| 576 | { |
| 577 | struct snd_soc_dapm_widget *widget = |
| 578 | snd_soc_dapm_kcontrol_widget(kcontrol); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 579 | struct snd_soc_component *component = |
| 580 | snd_soc_dapm_to_component(widget->dapm); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 581 | struct snd_soc_dapm_update *update = NULL; |
| 582 | struct soc_multi_mixer_control *mixer = |
| 583 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 584 | u32 dai_id = widget->shift; |
| 585 | u32 dec_id = mixer->shift; |
| 586 | u32 enable = ucontrol->value.integer.value[0]; |
| 587 | struct device *tx_dev = NULL; |
| 588 | struct tx_macro_priv *tx_priv = NULL; |
| 589 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 590 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 591 | return -EINVAL; |
| 592 | |
| 593 | if (enable) { |
| 594 | set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]); |
| 595 | tx_priv->active_ch_cnt[dai_id]++; |
| 596 | } else { |
| 597 | tx_priv->active_ch_cnt[dai_id]--; |
| 598 | clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]); |
| 599 | } |
| 600 | snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update); |
| 601 | |
| 602 | return 0; |
| 603 | } |
Karthikeyan Mani | 765eaab | 2019-07-18 16:27:01 -0700 | [diff] [blame] | 604 | static int tx_macro_get_bcs(struct snd_kcontrol *kcontrol, |
| 605 | struct snd_ctl_elem_value *ucontrol) |
| 606 | { |
| 607 | struct snd_soc_component *component = |
| 608 | snd_soc_kcontrol_component(kcontrol); |
| 609 | struct tx_macro_priv *tx_priv = NULL; |
| 610 | struct device *tx_dev = NULL; |
| 611 | |
| 612 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
| 613 | return -EINVAL; |
| 614 | |
| 615 | ucontrol->value.integer.value[0] = tx_priv->bcs_enable; |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int tx_macro_set_bcs(struct snd_kcontrol *kcontrol, |
| 621 | struct snd_ctl_elem_value *ucontrol) |
| 622 | { |
| 623 | struct snd_soc_component *component = |
| 624 | snd_soc_kcontrol_component(kcontrol); |
| 625 | struct tx_macro_priv *tx_priv = NULL; |
| 626 | struct device *tx_dev = NULL; |
| 627 | int value = ucontrol->value.integer.value[0]; |
| 628 | |
| 629 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
| 630 | return -EINVAL; |
| 631 | |
| 632 | tx_priv->bcs_enable = value; |
| 633 | |
| 634 | return 0; |
| 635 | } |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 636 | |
| 637 | static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w, |
| 638 | struct snd_kcontrol *kcontrol, int event) |
| 639 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 640 | struct snd_soc_component *component = |
| 641 | snd_soc_dapm_to_component(w->dapm); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 642 | u8 dmic_clk_en = 0x01; |
| 643 | u16 dmic_clk_reg = 0; |
| 644 | s32 *dmic_clk_cnt = NULL; |
| 645 | unsigned int dmic = 0; |
| 646 | int ret = 0; |
| 647 | char *wname = NULL; |
| 648 | struct device *tx_dev = NULL; |
| 649 | struct tx_macro_priv *tx_priv = NULL; |
| 650 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 651 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 652 | return -EINVAL; |
| 653 | |
| 654 | wname = strpbrk(w->name, "01234567"); |
| 655 | if (!wname) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 656 | dev_err(component->dev, "%s: widget not found\n", __func__); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 657 | return -EINVAL; |
| 658 | } |
| 659 | |
| 660 | ret = kstrtouint(wname, 10, &dmic); |
| 661 | if (ret < 0) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 662 | dev_err(component->dev, "%s: Invalid DMIC line on the codec\n", |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 663 | __func__); |
| 664 | return -EINVAL; |
| 665 | } |
| 666 | |
| 667 | switch (dmic) { |
| 668 | case 0: |
| 669 | case 1: |
| 670 | dmic_clk_cnt = &(tx_priv->dmic_0_1_clk_cnt); |
| 671 | dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL; |
| 672 | break; |
| 673 | case 2: |
| 674 | case 3: |
| 675 | dmic_clk_cnt = &(tx_priv->dmic_2_3_clk_cnt); |
| 676 | dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL; |
| 677 | break; |
| 678 | case 4: |
| 679 | case 5: |
| 680 | dmic_clk_cnt = &(tx_priv->dmic_4_5_clk_cnt); |
| 681 | dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL; |
| 682 | break; |
| 683 | case 6: |
| 684 | case 7: |
| 685 | dmic_clk_cnt = &(tx_priv->dmic_6_7_clk_cnt); |
| 686 | dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL; |
| 687 | break; |
| 688 | default: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 689 | dev_err(component->dev, "%s: Invalid DMIC Selection\n", |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 690 | __func__); |
| 691 | return -EINVAL; |
| 692 | } |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 693 | dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n", |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 694 | __func__, event, dmic, *dmic_clk_cnt); |
| 695 | |
| 696 | switch (event) { |
| 697 | case SND_SOC_DAPM_PRE_PMU: |
| 698 | (*dmic_clk_cnt)++; |
| 699 | if (*dmic_clk_cnt == 1) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 700 | snd_soc_component_update_bits(component, |
| 701 | BOLERO_CDC_VA_TOP_CSR_DMIC_CFG, |
Ramprasad Katkam | 9c2394a | 2018-08-23 13:13:48 +0530 | [diff] [blame] | 702 | 0x80, 0x00); |
| 703 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 704 | snd_soc_component_update_bits(component, dmic_clk_reg, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 705 | 0x0E, tx_priv->dmic_clk_div << 0x1); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 706 | snd_soc_component_update_bits(component, dmic_clk_reg, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 707 | dmic_clk_en, dmic_clk_en); |
| 708 | } |
| 709 | break; |
| 710 | case SND_SOC_DAPM_POST_PMD: |
| 711 | (*dmic_clk_cnt)--; |
| 712 | if (*dmic_clk_cnt == 0) |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 713 | snd_soc_component_update_bits(component, dmic_clk_reg, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 714 | dmic_clk_en, 0); |
| 715 | break; |
| 716 | } |
| 717 | |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w, |
| 722 | struct snd_kcontrol *kcontrol, int event) |
| 723 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 724 | struct snd_soc_component *component = |
| 725 | snd_soc_dapm_to_component(w->dapm); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 726 | unsigned int decimator = 0; |
| 727 | u16 tx_vol_ctl_reg = 0; |
| 728 | u16 dec_cfg_reg = 0; |
| 729 | u16 hpf_gate_reg = 0; |
| 730 | u16 tx_gain_ctl_reg = 0; |
| 731 | u8 hpf_cut_off_freq = 0; |
| 732 | struct device *tx_dev = NULL; |
| 733 | struct tx_macro_priv *tx_priv = NULL; |
| 734 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 735 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 736 | return -EINVAL; |
| 737 | |
| 738 | decimator = w->shift; |
| 739 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 740 | dev_dbg(component->dev, "%s(): widget = %s decimator = %u\n", __func__, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 741 | w->name, decimator); |
| 742 | |
| 743 | tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL + |
| 744 | TX_MACRO_TX_PATH_OFFSET * decimator; |
| 745 | hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 + |
| 746 | TX_MACRO_TX_PATH_OFFSET * decimator; |
| 747 | dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 + |
| 748 | TX_MACRO_TX_PATH_OFFSET * decimator; |
| 749 | tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL + |
| 750 | TX_MACRO_TX_PATH_OFFSET * decimator; |
| 751 | |
| 752 | switch (event) { |
| 753 | case SND_SOC_DAPM_PRE_PMU: |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 754 | /* Enable TX PGA Mute */ |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 755 | snd_soc_component_update_bits(component, |
| 756 | tx_vol_ctl_reg, 0x10, 0x10); |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 757 | break; |
| 758 | case SND_SOC_DAPM_POST_PMU: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 759 | snd_soc_component_update_bits(component, |
| 760 | tx_vol_ctl_reg, 0x20, 0x20); |
| 761 | snd_soc_component_update_bits(component, |
| 762 | hpf_gate_reg, 0x01, 0x00); |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 763 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 764 | hpf_cut_off_freq = ( |
| 765 | snd_soc_component_read32(component, dec_cfg_reg) & |
| 766 | TX_HPF_CUT_OFF_FREQ_MASK) >> 5; |
| 767 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 768 | tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq = |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 769 | hpf_cut_off_freq; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 770 | |
| 771 | if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 772 | snd_soc_component_update_bits(component, dec_cfg_reg, |
| 773 | TX_HPF_CUT_OFF_FREQ_MASK, |
| 774 | CF_MIN_3DB_150HZ << 5); |
| 775 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 776 | /* schedule work queue to Remove Mute */ |
| 777 | schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork, |
| 778 | msecs_to_jiffies(tx_unmute_delay)); |
| 779 | if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq != |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 780 | CF_MIN_3DB_150HZ) { |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 781 | schedule_delayed_work( |
| 782 | &tx_priv->tx_hpf_work[decimator].dwork, |
Karthikeyan Mani | 6bd895e | 2019-07-26 15:34:50 -0700 | [diff] [blame] | 783 | msecs_to_jiffies(300)); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 784 | snd_soc_component_update_bits(component, |
| 785 | hpf_gate_reg, 0x02, 0x02); |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 786 | /* |
| 787 | * Minimum 1 clk cycle delay is required as per HW spec |
| 788 | */ |
| 789 | usleep_range(1000, 1010); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 790 | snd_soc_component_update_bits(component, |
| 791 | hpf_gate_reg, 0x02, 0x00); |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 792 | } |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 793 | /* apply gain after decimator is enabled */ |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 794 | snd_soc_component_write(component, tx_gain_ctl_reg, |
| 795 | snd_soc_component_read32(component, |
| 796 | tx_gain_ctl_reg)); |
Karthikeyan Mani | 765eaab | 2019-07-18 16:27:01 -0700 | [diff] [blame] | 797 | if (tx_priv->bcs_enable) { |
| 798 | snd_soc_component_update_bits(component, dec_cfg_reg, |
| 799 | 0x01, 0x01); |
| 800 | snd_soc_component_update_bits(component, |
| 801 | BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, 0x40); |
| 802 | } |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 803 | break; |
| 804 | case SND_SOC_DAPM_PRE_PMD: |
| 805 | hpf_cut_off_freq = |
| 806 | tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 807 | snd_soc_component_update_bits(component, |
| 808 | tx_vol_ctl_reg, 0x10, 0x10); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 809 | if (cancel_delayed_work_sync( |
| 810 | &tx_priv->tx_hpf_work[decimator].dwork)) { |
| 811 | if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 812 | snd_soc_component_update_bits( |
| 813 | component, dec_cfg_reg, |
| 814 | TX_HPF_CUT_OFF_FREQ_MASK, |
| 815 | hpf_cut_off_freq << 5); |
| 816 | snd_soc_component_update_bits(component, |
| 817 | hpf_gate_reg, |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 818 | 0x02, 0x02); |
| 819 | /* |
| 820 | * Minimum 1 clk cycle delay is required |
| 821 | * as per HW spec |
| 822 | */ |
| 823 | usleep_range(1000, 1010); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 824 | snd_soc_component_update_bits(component, |
| 825 | hpf_gate_reg, |
Laxminath Kasam | 9eb8022 | 2018-08-29 21:53:14 +0530 | [diff] [blame] | 826 | 0x02, 0x00); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | cancel_delayed_work_sync( |
| 830 | &tx_priv->tx_mute_dwork[decimator].dwork); |
| 831 | break; |
| 832 | case SND_SOC_DAPM_POST_PMD: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 833 | snd_soc_component_update_bits(component, tx_vol_ctl_reg, |
| 834 | 0x20, 0x00); |
| 835 | snd_soc_component_update_bits(component, tx_vol_ctl_reg, |
| 836 | 0x10, 0x00); |
Karthikeyan Mani | 765eaab | 2019-07-18 16:27:01 -0700 | [diff] [blame] | 837 | if (tx_priv->bcs_enable) { |
| 838 | snd_soc_component_update_bits(component, dec_cfg_reg, |
| 839 | 0x01, 0x00); |
| 840 | snd_soc_component_update_bits(component, |
| 841 | BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, 0x00); |
| 842 | } |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 843 | break; |
| 844 | } |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w, |
| 849 | struct snd_kcontrol *kcontrol, int event) |
| 850 | { |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | static int tx_macro_hw_params(struct snd_pcm_substream *substream, |
| 855 | struct snd_pcm_hw_params *params, |
| 856 | struct snd_soc_dai *dai) |
| 857 | { |
| 858 | int tx_fs_rate = -EINVAL; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 859 | struct snd_soc_component *component = dai->component; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 860 | u32 decimator = 0; |
Laxminath Kasam | b7f823c | 2018-08-02 13:23:11 +0530 | [diff] [blame] | 861 | u32 sample_rate = 0; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 862 | u16 tx_fs_reg = 0; |
| 863 | struct device *tx_dev = NULL; |
| 864 | struct tx_macro_priv *tx_priv = NULL; |
| 865 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 866 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 867 | return -EINVAL; |
| 868 | |
| 869 | pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__, |
| 870 | dai->name, dai->id, params_rate(params), |
| 871 | params_channels(params)); |
| 872 | |
| 873 | sample_rate = params_rate(params); |
| 874 | switch (sample_rate) { |
| 875 | case 8000: |
| 876 | tx_fs_rate = 0; |
| 877 | break; |
| 878 | case 16000: |
| 879 | tx_fs_rate = 1; |
| 880 | break; |
| 881 | case 32000: |
| 882 | tx_fs_rate = 3; |
| 883 | break; |
| 884 | case 48000: |
| 885 | tx_fs_rate = 4; |
| 886 | break; |
| 887 | case 96000: |
| 888 | tx_fs_rate = 5; |
| 889 | break; |
| 890 | case 192000: |
| 891 | tx_fs_rate = 6; |
| 892 | break; |
| 893 | case 384000: |
| 894 | tx_fs_rate = 7; |
| 895 | break; |
| 896 | default: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 897 | dev_err(component->dev, "%s: Invalid TX sample rate: %d\n", |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 898 | __func__, params_rate(params)); |
| 899 | return -EINVAL; |
| 900 | } |
| 901 | for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id], |
| 902 | TX_MACRO_DEC_MAX) { |
| 903 | if (decimator >= 0) { |
| 904 | tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL + |
| 905 | TX_MACRO_TX_PATH_OFFSET * decimator; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 906 | dev_dbg(component->dev, "%s: set DEC%u rate to %u\n", |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 907 | __func__, decimator, sample_rate); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 908 | snd_soc_component_update_bits(component, tx_fs_reg, |
| 909 | 0x0F, tx_fs_rate); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 910 | } else { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 911 | dev_err(component->dev, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 912 | "%s: ERROR: Invalid decimator: %d\n", |
| 913 | __func__, decimator); |
| 914 | return -EINVAL; |
| 915 | } |
| 916 | } |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static int tx_macro_get_channel_map(struct snd_soc_dai *dai, |
| 921 | unsigned int *tx_num, unsigned int *tx_slot, |
| 922 | unsigned int *rx_num, unsigned int *rx_slot) |
| 923 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 924 | struct snd_soc_component *component = dai->component; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 925 | struct device *tx_dev = NULL; |
| 926 | struct tx_macro_priv *tx_priv = NULL; |
| 927 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 928 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 929 | return -EINVAL; |
| 930 | |
| 931 | switch (dai->id) { |
| 932 | case TX_MACRO_AIF1_CAP: |
| 933 | case TX_MACRO_AIF2_CAP: |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 934 | case TX_MACRO_AIF3_CAP: |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 935 | *tx_slot = tx_priv->active_ch_mask[dai->id]; |
| 936 | *tx_num = tx_priv->active_ch_cnt[dai->id]; |
| 937 | break; |
| 938 | default: |
| 939 | dev_err(tx_dev, "%s: Invalid AIF\n", __func__); |
| 940 | break; |
| 941 | } |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | static struct snd_soc_dai_ops tx_macro_dai_ops = { |
| 946 | .hw_params = tx_macro_hw_params, |
| 947 | .get_channel_map = tx_macro_get_channel_map, |
| 948 | }; |
| 949 | |
| 950 | static struct snd_soc_dai_driver tx_macro_dai[] = { |
| 951 | { |
| 952 | .name = "tx_macro_tx1", |
| 953 | .id = TX_MACRO_AIF1_CAP, |
| 954 | .capture = { |
| 955 | .stream_name = "TX_AIF1 Capture", |
| 956 | .rates = TX_MACRO_RATES, |
| 957 | .formats = TX_MACRO_FORMATS, |
| 958 | .rate_max = 192000, |
| 959 | .rate_min = 8000, |
| 960 | .channels_min = 1, |
| 961 | .channels_max = 8, |
| 962 | }, |
| 963 | .ops = &tx_macro_dai_ops, |
| 964 | }, |
| 965 | { |
| 966 | .name = "tx_macro_tx2", |
| 967 | .id = TX_MACRO_AIF2_CAP, |
| 968 | .capture = { |
| 969 | .stream_name = "TX_AIF2 Capture", |
| 970 | .rates = TX_MACRO_RATES, |
| 971 | .formats = TX_MACRO_FORMATS, |
| 972 | .rate_max = 192000, |
| 973 | .rate_min = 8000, |
| 974 | .channels_min = 1, |
| 975 | .channels_max = 8, |
| 976 | }, |
| 977 | .ops = &tx_macro_dai_ops, |
| 978 | }, |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 979 | { |
| 980 | .name = "tx_macro_tx3", |
| 981 | .id = TX_MACRO_AIF3_CAP, |
| 982 | .capture = { |
| 983 | .stream_name = "TX_AIF3 Capture", |
| 984 | .rates = TX_MACRO_RATES, |
| 985 | .formats = TX_MACRO_FORMATS, |
| 986 | .rate_max = 192000, |
| 987 | .rate_min = 8000, |
| 988 | .channels_min = 1, |
| 989 | .channels_max = 8, |
| 990 | }, |
| 991 | .ops = &tx_macro_dai_ops, |
| 992 | }, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 993 | }; |
| 994 | |
| 995 | #define STRING(name) #name |
| 996 | #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \ |
| 997 | static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \ |
| 998 | static const struct snd_kcontrol_new name##_mux = \ |
| 999 | SOC_DAPM_ENUM(STRING(name), name##_enum) |
| 1000 | |
| 1001 | #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \ |
| 1002 | static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \ |
| 1003 | static const struct snd_kcontrol_new name##_mux = \ |
| 1004 | SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname) |
| 1005 | |
| 1006 | #define TX_MACRO_DAPM_MUX(name, shift, kctl) \ |
| 1007 | SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux) |
| 1008 | |
| 1009 | static const char * const adc_mux_text[] = { |
| 1010 | "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1" |
| 1011 | }; |
| 1012 | |
| 1013 | TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1, |
| 1014 | 0, adc_mux_text); |
| 1015 | TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1, |
| 1016 | 0, adc_mux_text); |
| 1017 | TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1, |
| 1018 | 0, adc_mux_text); |
| 1019 | TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1, |
| 1020 | 0, adc_mux_text); |
| 1021 | TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1, |
| 1022 | 0, adc_mux_text); |
| 1023 | TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1, |
| 1024 | 0, adc_mux_text); |
| 1025 | TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1, |
| 1026 | 0, adc_mux_text); |
| 1027 | TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1, |
| 1028 | 0, adc_mux_text); |
| 1029 | |
| 1030 | |
| 1031 | static const char * const dmic_mux_text[] = { |
| 1032 | "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", |
| 1033 | "DMIC4", "DMIC5", "DMIC6", "DMIC7" |
| 1034 | }; |
| 1035 | |
| 1036 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0, |
| 1037 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1038 | tx_macro_put_dec_enum); |
| 1039 | |
| 1040 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0, |
| 1041 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1042 | tx_macro_put_dec_enum); |
| 1043 | |
| 1044 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0, |
| 1045 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1046 | tx_macro_put_dec_enum); |
| 1047 | |
| 1048 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0, |
| 1049 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1050 | tx_macro_put_dec_enum); |
| 1051 | |
| 1052 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0, |
| 1053 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1054 | tx_macro_put_dec_enum); |
| 1055 | |
| 1056 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0, |
| 1057 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1058 | tx_macro_put_dec_enum); |
| 1059 | |
| 1060 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0, |
| 1061 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1062 | tx_macro_put_dec_enum); |
| 1063 | |
| 1064 | TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0, |
| 1065 | 4, dmic_mux_text, snd_soc_dapm_get_enum_double, |
| 1066 | tx_macro_put_dec_enum); |
| 1067 | |
| 1068 | static const char * const smic_mux_text[] = { |
Sudheer Papothi | 324b495 | 2019-06-11 04:14:51 +0530 | [diff] [blame] | 1069 | "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0", |
| 1070 | "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4", |
| 1071 | "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7" |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1072 | }; |
| 1073 | |
| 1074 | TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0, |
| 1075 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1076 | tx_macro_put_dec_enum); |
| 1077 | |
| 1078 | TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0, |
| 1079 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1080 | tx_macro_put_dec_enum); |
| 1081 | |
| 1082 | TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0, |
| 1083 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1084 | tx_macro_put_dec_enum); |
| 1085 | |
| 1086 | TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0, |
| 1087 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1088 | tx_macro_put_dec_enum); |
| 1089 | |
| 1090 | TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0, |
| 1091 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1092 | tx_macro_put_dec_enum); |
| 1093 | |
| 1094 | TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0, |
| 1095 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1096 | tx_macro_put_dec_enum); |
| 1097 | |
| 1098 | TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0, |
| 1099 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1100 | tx_macro_put_dec_enum); |
| 1101 | |
| 1102 | TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0, |
| 1103 | 0, smic_mux_text, snd_soc_dapm_get_enum_double, |
| 1104 | tx_macro_put_dec_enum); |
| 1105 | |
| 1106 | static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = { |
| 1107 | SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0, |
| 1108 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1109 | SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0, |
| 1110 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1111 | SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0, |
| 1112 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1113 | SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0, |
| 1114 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1115 | SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0, |
| 1116 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1117 | SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0, |
| 1118 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1119 | SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0, |
| 1120 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1121 | SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0, |
| 1122 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1123 | }; |
| 1124 | |
| 1125 | static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = { |
| 1126 | SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0, |
| 1127 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1128 | SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0, |
| 1129 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1130 | SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0, |
| 1131 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1132 | SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0, |
| 1133 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1134 | SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0, |
| 1135 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1136 | SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0, |
| 1137 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1138 | SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0, |
| 1139 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1140 | SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0, |
| 1141 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1142 | }; |
| 1143 | |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 1144 | static const struct snd_kcontrol_new tx_aif3_cap_mixer[] = { |
| 1145 | SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0, |
| 1146 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1147 | SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0, |
| 1148 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1149 | SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0, |
| 1150 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1151 | SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0, |
| 1152 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1153 | SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0, |
| 1154 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1155 | SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0, |
| 1156 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1157 | SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0, |
| 1158 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1159 | SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0, |
| 1160 | tx_macro_tx_mixer_get, tx_macro_tx_mixer_put), |
| 1161 | }; |
| 1162 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1163 | static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = { |
| 1164 | SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0, |
| 1165 | SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0), |
| 1166 | |
| 1167 | SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0, |
| 1168 | SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0), |
| 1169 | |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 1170 | SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0, |
| 1171 | SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0), |
| 1172 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1173 | SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0, |
| 1174 | tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)), |
| 1175 | |
| 1176 | SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0, |
| 1177 | tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)), |
| 1178 | |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 1179 | SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0, |
| 1180 | tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)), |
| 1181 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1182 | |
| 1183 | TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0), |
| 1184 | TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1), |
| 1185 | TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2), |
| 1186 | TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3), |
| 1187 | TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4), |
| 1188 | TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5), |
| 1189 | TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6), |
| 1190 | TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7), |
| 1191 | |
| 1192 | TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0), |
| 1193 | TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1), |
| 1194 | TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2), |
| 1195 | TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3), |
| 1196 | TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4), |
| 1197 | TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5), |
| 1198 | TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6), |
| 1199 | TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7), |
| 1200 | |
| 1201 | SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0, |
| 1202 | tx_macro_enable_micbias, |
| 1203 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1204 | SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0, |
| 1205 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1206 | SND_SOC_DAPM_POST_PMD), |
| 1207 | |
| 1208 | SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 1209 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1210 | SND_SOC_DAPM_POST_PMD), |
| 1211 | |
| 1212 | SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 1213 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1214 | SND_SOC_DAPM_POST_PMD), |
| 1215 | |
| 1216 | SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 1217 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1218 | SND_SOC_DAPM_POST_PMD), |
| 1219 | |
| 1220 | SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 1221 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1222 | SND_SOC_DAPM_POST_PMD), |
| 1223 | |
| 1224 | SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0, |
| 1225 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1226 | SND_SOC_DAPM_POST_PMD), |
| 1227 | |
| 1228 | SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0, |
| 1229 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1230 | SND_SOC_DAPM_POST_PMD), |
| 1231 | |
| 1232 | SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0, |
| 1233 | tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1234 | SND_SOC_DAPM_POST_PMD), |
| 1235 | |
| 1236 | SND_SOC_DAPM_INPUT("TX SWR_ADC0"), |
| 1237 | SND_SOC_DAPM_INPUT("TX SWR_ADC1"), |
| 1238 | SND_SOC_DAPM_INPUT("TX SWR_ADC2"), |
| 1239 | SND_SOC_DAPM_INPUT("TX SWR_ADC3"), |
| 1240 | SND_SOC_DAPM_INPUT("TX SWR_DMIC0"), |
| 1241 | SND_SOC_DAPM_INPUT("TX SWR_DMIC1"), |
| 1242 | SND_SOC_DAPM_INPUT("TX SWR_DMIC2"), |
| 1243 | SND_SOC_DAPM_INPUT("TX SWR_DMIC3"), |
| 1244 | SND_SOC_DAPM_INPUT("TX SWR_DMIC4"), |
| 1245 | SND_SOC_DAPM_INPUT("TX SWR_DMIC5"), |
| 1246 | SND_SOC_DAPM_INPUT("TX SWR_DMIC6"), |
| 1247 | SND_SOC_DAPM_INPUT("TX SWR_DMIC7"), |
| 1248 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1249 | SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1250 | TX_MACRO_DEC0, 0, |
| 1251 | &tx_dec0_mux, tx_macro_enable_dec, |
| 1252 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1253 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1254 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1255 | SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1256 | TX_MACRO_DEC1, 0, |
| 1257 | &tx_dec1_mux, tx_macro_enable_dec, |
| 1258 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1259 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1260 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1261 | SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1262 | TX_MACRO_DEC2, 0, |
| 1263 | &tx_dec2_mux, tx_macro_enable_dec, |
| 1264 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1265 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1266 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1267 | SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1268 | TX_MACRO_DEC3, 0, |
| 1269 | &tx_dec3_mux, tx_macro_enable_dec, |
| 1270 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1271 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1272 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1273 | SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1274 | TX_MACRO_DEC4, 0, |
| 1275 | &tx_dec4_mux, tx_macro_enable_dec, |
| 1276 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1277 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1278 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1279 | SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1280 | TX_MACRO_DEC5, 0, |
| 1281 | &tx_dec5_mux, tx_macro_enable_dec, |
| 1282 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1283 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1284 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1285 | SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1286 | TX_MACRO_DEC6, 0, |
| 1287 | &tx_dec6_mux, tx_macro_enable_dec, |
| 1288 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1289 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1290 | |
Ramprasad Katkam | f83acfb | 2018-08-11 23:28:57 +0530 | [diff] [blame] | 1291 | SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1292 | TX_MACRO_DEC7, 0, |
| 1293 | &tx_dec7_mux, tx_macro_enable_dec, |
| 1294 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1295 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1296 | |
| 1297 | SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0, |
| 1298 | tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1299 | |
| 1300 | SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0, |
| 1301 | tx_macro_tx_swr_clk_event, |
| 1302 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1303 | |
| 1304 | SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0, |
| 1305 | tx_macro_va_swr_clk_event, |
| 1306 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1307 | }; |
| 1308 | |
| 1309 | static const struct snd_soc_dapm_route tx_audio_map[] = { |
| 1310 | {"TX_AIF1 CAP", NULL, "TX_MCLK"}, |
| 1311 | {"TX_AIF2 CAP", NULL, "TX_MCLK"}, |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 1312 | {"TX_AIF3 CAP", NULL, "TX_MCLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1313 | |
| 1314 | {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"}, |
| 1315 | {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"}, |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 1316 | {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1317 | |
| 1318 | {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"}, |
| 1319 | {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"}, |
| 1320 | {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"}, |
| 1321 | {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"}, |
| 1322 | {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"}, |
| 1323 | {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"}, |
| 1324 | {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"}, |
| 1325 | {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"}, |
| 1326 | |
| 1327 | {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"}, |
| 1328 | {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"}, |
| 1329 | {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"}, |
| 1330 | {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"}, |
| 1331 | {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"}, |
| 1332 | {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"}, |
| 1333 | {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"}, |
| 1334 | {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"}, |
| 1335 | |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 1336 | {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"}, |
| 1337 | {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"}, |
| 1338 | {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"}, |
| 1339 | {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"}, |
| 1340 | {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"}, |
| 1341 | {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"}, |
| 1342 | {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"}, |
| 1343 | {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"}, |
| 1344 | |
Laxminath Kasam | fc281ad | 2018-08-06 20:19:40 +0530 | [diff] [blame] | 1345 | {"TX DEC0 MUX", NULL, "TX_MCLK"}, |
| 1346 | {"TX DEC1 MUX", NULL, "TX_MCLK"}, |
| 1347 | {"TX DEC2 MUX", NULL, "TX_MCLK"}, |
| 1348 | {"TX DEC3 MUX", NULL, "TX_MCLK"}, |
| 1349 | {"TX DEC4 MUX", NULL, "TX_MCLK"}, |
| 1350 | {"TX DEC5 MUX", NULL, "TX_MCLK"}, |
| 1351 | {"TX DEC6 MUX", NULL, "TX_MCLK"}, |
| 1352 | {"TX DEC7 MUX", NULL, "TX_MCLK"}, |
| 1353 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1354 | {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"}, |
| 1355 | {"TX DMIC MUX0", "DMIC0", "TX DMIC0"}, |
| 1356 | {"TX DMIC MUX0", "DMIC1", "TX DMIC1"}, |
| 1357 | {"TX DMIC MUX0", "DMIC2", "TX DMIC2"}, |
| 1358 | {"TX DMIC MUX0", "DMIC3", "TX DMIC3"}, |
| 1359 | {"TX DMIC MUX0", "DMIC4", "TX DMIC4"}, |
| 1360 | {"TX DMIC MUX0", "DMIC5", "TX DMIC5"}, |
| 1361 | {"TX DMIC MUX0", "DMIC6", "TX DMIC6"}, |
| 1362 | {"TX DMIC MUX0", "DMIC7", "TX DMIC7"}, |
| 1363 | |
| 1364 | {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1365 | {"TX SMIC MUX0", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1366 | {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"}, |
| 1367 | {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"}, |
| 1368 | {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"}, |
| 1369 | {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"}, |
| 1370 | {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1371 | {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1372 | {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1373 | {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1374 | {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1375 | {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1376 | {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1377 | {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1378 | |
| 1379 | {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"}, |
| 1380 | {"TX DMIC MUX1", "DMIC0", "TX DMIC0"}, |
| 1381 | {"TX DMIC MUX1", "DMIC1", "TX DMIC1"}, |
| 1382 | {"TX DMIC MUX1", "DMIC2", "TX DMIC2"}, |
| 1383 | {"TX DMIC MUX1", "DMIC3", "TX DMIC3"}, |
| 1384 | {"TX DMIC MUX1", "DMIC4", "TX DMIC4"}, |
| 1385 | {"TX DMIC MUX1", "DMIC5", "TX DMIC5"}, |
| 1386 | {"TX DMIC MUX1", "DMIC6", "TX DMIC6"}, |
| 1387 | {"TX DMIC MUX1", "DMIC7", "TX DMIC7"}, |
| 1388 | |
| 1389 | {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1390 | {"TX SMIC MUX1", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1391 | {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"}, |
| 1392 | {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"}, |
| 1393 | {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"}, |
| 1394 | {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"}, |
| 1395 | {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1396 | {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1397 | {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1398 | {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1399 | {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1400 | {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1401 | {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1402 | {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1403 | |
| 1404 | {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"}, |
| 1405 | {"TX DMIC MUX2", "DMIC0", "TX DMIC0"}, |
| 1406 | {"TX DMIC MUX2", "DMIC1", "TX DMIC1"}, |
| 1407 | {"TX DMIC MUX2", "DMIC2", "TX DMIC2"}, |
| 1408 | {"TX DMIC MUX2", "DMIC3", "TX DMIC3"}, |
| 1409 | {"TX DMIC MUX2", "DMIC4", "TX DMIC4"}, |
| 1410 | {"TX DMIC MUX2", "DMIC5", "TX DMIC5"}, |
| 1411 | {"TX DMIC MUX2", "DMIC6", "TX DMIC6"}, |
| 1412 | {"TX DMIC MUX2", "DMIC7", "TX DMIC7"}, |
| 1413 | |
| 1414 | {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1415 | {"TX SMIC MUX2", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1416 | {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"}, |
| 1417 | {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"}, |
| 1418 | {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"}, |
| 1419 | {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"}, |
| 1420 | {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1421 | {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1422 | {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1423 | {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1424 | {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1425 | {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1426 | {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1427 | {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1428 | |
| 1429 | {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"}, |
| 1430 | {"TX DMIC MUX3", "DMIC0", "TX DMIC0"}, |
| 1431 | {"TX DMIC MUX3", "DMIC1", "TX DMIC1"}, |
| 1432 | {"TX DMIC MUX3", "DMIC2", "TX DMIC2"}, |
| 1433 | {"TX DMIC MUX3", "DMIC3", "TX DMIC3"}, |
| 1434 | {"TX DMIC MUX3", "DMIC4", "TX DMIC4"}, |
| 1435 | {"TX DMIC MUX3", "DMIC5", "TX DMIC5"}, |
| 1436 | {"TX DMIC MUX3", "DMIC6", "TX DMIC6"}, |
| 1437 | {"TX DMIC MUX3", "DMIC7", "TX DMIC7"}, |
| 1438 | |
| 1439 | {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1440 | {"TX SMIC MUX3", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1441 | {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"}, |
| 1442 | {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"}, |
| 1443 | {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"}, |
| 1444 | {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"}, |
| 1445 | {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1446 | {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1447 | {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1448 | {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1449 | {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1450 | {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1451 | {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1452 | {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1453 | |
| 1454 | {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"}, |
| 1455 | {"TX DMIC MUX4", "DMIC0", "TX DMIC0"}, |
| 1456 | {"TX DMIC MUX4", "DMIC1", "TX DMIC1"}, |
| 1457 | {"TX DMIC MUX4", "DMIC2", "TX DMIC2"}, |
| 1458 | {"TX DMIC MUX4", "DMIC3", "TX DMIC3"}, |
| 1459 | {"TX DMIC MUX4", "DMIC4", "TX DMIC4"}, |
| 1460 | {"TX DMIC MUX4", "DMIC5", "TX DMIC5"}, |
| 1461 | {"TX DMIC MUX4", "DMIC6", "TX DMIC6"}, |
| 1462 | {"TX DMIC MUX4", "DMIC7", "TX DMIC7"}, |
| 1463 | |
| 1464 | {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1465 | {"TX SMIC MUX4", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1466 | {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"}, |
| 1467 | {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"}, |
| 1468 | {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"}, |
| 1469 | {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"}, |
| 1470 | {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1471 | {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1472 | {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1473 | {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1474 | {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1475 | {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1476 | {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1477 | {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1478 | |
| 1479 | {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"}, |
| 1480 | {"TX DMIC MUX5", "DMIC0", "TX DMIC0"}, |
| 1481 | {"TX DMIC MUX5", "DMIC1", "TX DMIC1"}, |
| 1482 | {"TX DMIC MUX5", "DMIC2", "TX DMIC2"}, |
| 1483 | {"TX DMIC MUX5", "DMIC3", "TX DMIC3"}, |
| 1484 | {"TX DMIC MUX5", "DMIC4", "TX DMIC4"}, |
| 1485 | {"TX DMIC MUX5", "DMIC5", "TX DMIC5"}, |
| 1486 | {"TX DMIC MUX5", "DMIC6", "TX DMIC6"}, |
| 1487 | {"TX DMIC MUX5", "DMIC7", "TX DMIC7"}, |
| 1488 | |
| 1489 | {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1490 | {"TX SMIC MUX5", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1491 | {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"}, |
| 1492 | {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"}, |
| 1493 | {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"}, |
| 1494 | {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"}, |
| 1495 | {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1496 | {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1497 | {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1498 | {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1499 | {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1500 | {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1501 | {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1502 | {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1503 | |
| 1504 | {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"}, |
| 1505 | {"TX DMIC MUX6", "DMIC0", "TX DMIC0"}, |
| 1506 | {"TX DMIC MUX6", "DMIC1", "TX DMIC1"}, |
| 1507 | {"TX DMIC MUX6", "DMIC2", "TX DMIC2"}, |
| 1508 | {"TX DMIC MUX6", "DMIC3", "TX DMIC3"}, |
| 1509 | {"TX DMIC MUX6", "DMIC4", "TX DMIC4"}, |
| 1510 | {"TX DMIC MUX6", "DMIC5", "TX DMIC5"}, |
| 1511 | {"TX DMIC MUX6", "DMIC6", "TX DMIC6"}, |
| 1512 | {"TX DMIC MUX6", "DMIC7", "TX DMIC7"}, |
| 1513 | |
| 1514 | {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1515 | {"TX SMIC MUX6", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1516 | {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"}, |
| 1517 | {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"}, |
| 1518 | {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"}, |
| 1519 | {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"}, |
| 1520 | {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1521 | {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1522 | {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1523 | {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1524 | {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1525 | {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1526 | {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1527 | {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1528 | |
| 1529 | {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"}, |
| 1530 | {"TX DMIC MUX7", "DMIC0", "TX DMIC0"}, |
| 1531 | {"TX DMIC MUX7", "DMIC1", "TX DMIC1"}, |
| 1532 | {"TX DMIC MUX7", "DMIC2", "TX DMIC2"}, |
| 1533 | {"TX DMIC MUX7", "DMIC3", "TX DMIC3"}, |
| 1534 | {"TX DMIC MUX7", "DMIC4", "TX DMIC4"}, |
| 1535 | {"TX DMIC MUX7", "DMIC5", "TX DMIC5"}, |
| 1536 | {"TX DMIC MUX7", "DMIC6", "TX DMIC6"}, |
| 1537 | {"TX DMIC MUX7", "DMIC7", "TX DMIC7"}, |
| 1538 | |
| 1539 | {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"}, |
Sudheer Papothi | e456c2c | 2019-03-05 07:08:45 +0530 | [diff] [blame] | 1540 | {"TX SMIC MUX7", NULL, "TX_SWR_CLK"}, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1541 | {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"}, |
| 1542 | {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"}, |
| 1543 | {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"}, |
| 1544 | {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"}, |
| 1545 | {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"}, |
| 1546 | {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"}, |
| 1547 | {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"}, |
| 1548 | {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"}, |
| 1549 | {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"}, |
| 1550 | {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"}, |
| 1551 | {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"}, |
| 1552 | {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"}, |
| 1553 | }; |
| 1554 | |
| 1555 | static const struct snd_kcontrol_new tx_macro_snd_controls[] = { |
| 1556 | SOC_SINGLE_SX_TLV("TX_DEC0 Volume", |
| 1557 | BOLERO_CDC_TX0_TX_VOL_CTL, |
| 1558 | 0, -84, 40, digital_gain), |
| 1559 | SOC_SINGLE_SX_TLV("TX_DEC1 Volume", |
| 1560 | BOLERO_CDC_TX1_TX_VOL_CTL, |
| 1561 | 0, -84, 40, digital_gain), |
| 1562 | SOC_SINGLE_SX_TLV("TX_DEC2 Volume", |
| 1563 | BOLERO_CDC_TX2_TX_VOL_CTL, |
| 1564 | 0, -84, 40, digital_gain), |
| 1565 | SOC_SINGLE_SX_TLV("TX_DEC3 Volume", |
| 1566 | BOLERO_CDC_TX3_TX_VOL_CTL, |
| 1567 | 0, -84, 40, digital_gain), |
| 1568 | SOC_SINGLE_SX_TLV("TX_DEC4 Volume", |
| 1569 | BOLERO_CDC_TX4_TX_VOL_CTL, |
| 1570 | 0, -84, 40, digital_gain), |
| 1571 | SOC_SINGLE_SX_TLV("TX_DEC5 Volume", |
| 1572 | BOLERO_CDC_TX5_TX_VOL_CTL, |
| 1573 | 0, -84, 40, digital_gain), |
| 1574 | SOC_SINGLE_SX_TLV("TX_DEC6 Volume", |
| 1575 | BOLERO_CDC_TX6_TX_VOL_CTL, |
| 1576 | 0, -84, 40, digital_gain), |
| 1577 | SOC_SINGLE_SX_TLV("TX_DEC7 Volume", |
| 1578 | BOLERO_CDC_TX7_TX_VOL_CTL, |
| 1579 | 0, -84, 40, digital_gain), |
Karthikeyan Mani | 765eaab | 2019-07-18 16:27:01 -0700 | [diff] [blame] | 1580 | |
| 1581 | SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0, |
| 1582 | tx_macro_get_bcs, tx_macro_set_bcs), |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1583 | }; |
| 1584 | |
Sudheer Papothi | 06a4c64 | 2019-08-08 05:17:46 +0530 | [diff] [blame^] | 1585 | static int tx_macro_register_event_listener(struct snd_soc_component *component, |
| 1586 | bool enable) |
| 1587 | { |
| 1588 | struct device *tx_dev = NULL; |
| 1589 | struct tx_macro_priv *tx_priv = NULL; |
| 1590 | int ret = 0; |
| 1591 | |
| 1592 | if (!component) |
| 1593 | return -EINVAL; |
| 1594 | |
| 1595 | tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO); |
| 1596 | if (!tx_dev) { |
| 1597 | dev_err(component->dev, |
| 1598 | "%s: null device for macro!\n", __func__); |
| 1599 | return -EINVAL; |
| 1600 | } |
| 1601 | tx_priv = dev_get_drvdata(tx_dev); |
| 1602 | if (!tx_priv) { |
| 1603 | dev_err(component->dev, |
| 1604 | "%s: priv is null for macro!\n", __func__); |
| 1605 | return -EINVAL; |
| 1606 | } |
| 1607 | if (tx_priv->swr_ctrl_data) { |
| 1608 | if (enable) |
| 1609 | ret = swrm_wcd_notify( |
| 1610 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 1611 | SWR_REGISTER_WAKEUP, NULL); |
| 1612 | else |
| 1613 | ret = swrm_wcd_notify( |
| 1614 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 1615 | SWR_DEREGISTER_WAKEUP, NULL); |
| 1616 | } |
| 1617 | |
| 1618 | return ret; |
| 1619 | } |
| 1620 | |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1621 | static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv, |
| 1622 | struct regmap *regmap, int clk_type, |
| 1623 | bool enable) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1624 | { |
Meng Wang | 69b55c8 | 2019-05-29 11:04:29 +0800 | [diff] [blame] | 1625 | int ret = 0, clk_tx_ret = 0; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1626 | |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 1627 | dev_dbg(tx_priv->dev, |
| 1628 | "%s: clock type %s, enable: %s tx_mclk_users: %d\n", |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1629 | __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"), |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 1630 | (enable ? "enable" : "disable"), tx_priv->tx_mclk_users); |
Tanya Dixit | 8530fb9 | 2018-09-14 16:01:25 +0530 | [diff] [blame] | 1631 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1632 | if (enable) { |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1633 | if (tx_priv->swr_clk_users == 0) |
Karthikeyan Mani | 01f1ba4 | 2019-02-26 18:48:15 -0800 | [diff] [blame] | 1634 | msm_cdc_pinctrl_select_active_state( |
| 1635 | tx_priv->tx_swr_gpio_p); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1636 | |
Meng Wang | 69b55c8 | 2019-05-29 11:04:29 +0800 | [diff] [blame] | 1637 | clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev, |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1638 | TX_CORE_CLK, |
| 1639 | TX_CORE_CLK, |
| 1640 | true); |
| 1641 | if (clk_type == TX_MCLK) { |
| 1642 | ret = tx_macro_mclk_enable(tx_priv, 1); |
| 1643 | if (ret < 0) { |
| 1644 | if (tx_priv->swr_clk_users == 0) |
| 1645 | msm_cdc_pinctrl_select_sleep_state( |
| 1646 | tx_priv->tx_swr_gpio_p); |
| 1647 | dev_err_ratelimited(tx_priv->dev, |
| 1648 | "%s: request clock enable failed\n", |
| 1649 | __func__); |
| 1650 | goto done; |
| 1651 | } |
| 1652 | } |
| 1653 | if (clk_type == VA_MCLK) { |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1654 | ret = bolero_clk_rsc_request_clock(tx_priv->dev, |
| 1655 | TX_CORE_CLK, |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1656 | VA_CORE_CLK, |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1657 | true); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1658 | if (ret < 0) { |
| 1659 | if (tx_priv->swr_clk_users == 0) |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1660 | msm_cdc_pinctrl_select_sleep_state( |
| 1661 | tx_priv->tx_swr_gpio_p); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1662 | dev_err_ratelimited(tx_priv->dev, |
| 1663 | "%s: swr request clk failed\n", |
| 1664 | __func__); |
| 1665 | goto done; |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1666 | } |
Sudheer Papothi | 296867b | 2019-06-20 09:24:09 +0530 | [diff] [blame] | 1667 | bolero_clk_rsc_fs_gen_request(tx_priv->dev, |
| 1668 | true); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1669 | if (tx_priv->tx_mclk_users == 0) { |
| 1670 | regmap_update_bits(regmap, |
| 1671 | BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, |
| 1672 | 0x01, 0x01); |
| 1673 | regmap_update_bits(regmap, |
| 1674 | BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL, |
| 1675 | 0x01, 0x01); |
| 1676 | regmap_update_bits(regmap, |
| 1677 | BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL, |
| 1678 | 0x01, 0x01); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1679 | } |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1680 | } |
| 1681 | if (tx_priv->swr_clk_users == 0) { |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 1682 | dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n", |
| 1683 | __func__, tx_priv->reset_swr); |
Ramprasad Katkam | a4c747b | 2018-12-11 19:15:53 +0530 | [diff] [blame] | 1684 | if (tx_priv->reset_swr) |
| 1685 | regmap_update_bits(regmap, |
| 1686 | BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL, |
| 1687 | 0x02, 0x02); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1688 | regmap_update_bits(regmap, |
| 1689 | BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL, |
| 1690 | 0x01, 0x01); |
Ramprasad Katkam | a4c747b | 2018-12-11 19:15:53 +0530 | [diff] [blame] | 1691 | if (tx_priv->reset_swr) |
| 1692 | regmap_update_bits(regmap, |
| 1693 | BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL, |
| 1694 | 0x02, 0x00); |
| 1695 | tx_priv->reset_swr = false; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1696 | } |
Meng Wang | 69b55c8 | 2019-05-29 11:04:29 +0800 | [diff] [blame] | 1697 | if (!clk_tx_ret) |
| 1698 | ret = bolero_clk_rsc_request_clock(tx_priv->dev, |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1699 | TX_CORE_CLK, |
| 1700 | TX_CORE_CLK, |
| 1701 | false); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1702 | tx_priv->swr_clk_users++; |
| 1703 | } else { |
| 1704 | if (tx_priv->swr_clk_users <= 0) { |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1705 | dev_err_ratelimited(tx_priv->dev, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1706 | "tx swrm clock users already 0\n"); |
| 1707 | tx_priv->swr_clk_users = 0; |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1708 | return 0; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1709 | } |
Meng Wang | 69b55c8 | 2019-05-29 11:04:29 +0800 | [diff] [blame] | 1710 | clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev, |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1711 | TX_CORE_CLK, |
| 1712 | TX_CORE_CLK, |
| 1713 | true); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1714 | tx_priv->swr_clk_users--; |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1715 | if (tx_priv->swr_clk_users == 0) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1716 | regmap_update_bits(regmap, |
| 1717 | BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL, |
| 1718 | 0x01, 0x00); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1719 | if (clk_type == TX_MCLK) |
| 1720 | tx_macro_mclk_enable(tx_priv, 0); |
| 1721 | if (clk_type == VA_MCLK) { |
| 1722 | if (tx_priv->tx_mclk_users == 0) { |
| 1723 | regmap_update_bits(regmap, |
| 1724 | BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL, |
| 1725 | 0x01, 0x00); |
| 1726 | regmap_update_bits(regmap, |
| 1727 | BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL, |
| 1728 | 0x01, 0x00); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1729 | } |
Sudheer Papothi | 296867b | 2019-06-20 09:24:09 +0530 | [diff] [blame] | 1730 | bolero_clk_rsc_fs_gen_request(tx_priv->dev, |
| 1731 | false); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1732 | ret = bolero_clk_rsc_request_clock(tx_priv->dev, |
| 1733 | TX_CORE_CLK, |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1734 | VA_CORE_CLK, |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1735 | false); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1736 | if (ret < 0) { |
| 1737 | dev_err_ratelimited(tx_priv->dev, |
| 1738 | "%s: swr request clk failed\n", |
| 1739 | __func__); |
| 1740 | goto done; |
| 1741 | } |
| 1742 | } |
Meng Wang | 69b55c8 | 2019-05-29 11:04:29 +0800 | [diff] [blame] | 1743 | if (!clk_tx_ret) |
| 1744 | ret = bolero_clk_rsc_request_clock(tx_priv->dev, |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1745 | TX_CORE_CLK, |
| 1746 | TX_CORE_CLK, |
| 1747 | false); |
| 1748 | if (tx_priv->swr_clk_users == 0) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1749 | msm_cdc_pinctrl_select_sleep_state( |
| 1750 | tx_priv->tx_swr_gpio_p); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1751 | } |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1752 | return 0; |
| 1753 | |
| 1754 | done: |
Meng Wang | 69b55c8 | 2019-05-29 11:04:29 +0800 | [diff] [blame] | 1755 | if (!clk_tx_ret) |
| 1756 | bolero_clk_rsc_request_clock(tx_priv->dev, |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1757 | TX_CORE_CLK, |
| 1758 | TX_CORE_CLK, |
| 1759 | false); |
| 1760 | return ret; |
| 1761 | } |
| 1762 | |
Sudheer Papothi | 6cc7f52 | 2019-06-28 11:04:03 +0530 | [diff] [blame] | 1763 | static int tx_macro_clk_switch(struct snd_soc_component *component) |
| 1764 | { |
| 1765 | struct device *tx_dev = NULL; |
| 1766 | struct tx_macro_priv *tx_priv = NULL; |
| 1767 | int ret = 0; |
| 1768 | |
| 1769 | if (!component) |
| 1770 | return -EINVAL; |
| 1771 | |
| 1772 | tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO); |
| 1773 | if (!tx_dev) { |
| 1774 | dev_err(component->dev, |
| 1775 | "%s: null device for macro!\n", __func__); |
| 1776 | return -EINVAL; |
| 1777 | } |
| 1778 | tx_priv = dev_get_drvdata(tx_dev); |
| 1779 | if (!tx_priv) { |
| 1780 | dev_err(component->dev, |
| 1781 | "%s: priv is null for macro!\n", __func__); |
| 1782 | return -EINVAL; |
| 1783 | } |
| 1784 | if (tx_priv->swr_ctrl_data) { |
| 1785 | ret = swrm_wcd_notify( |
| 1786 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 1787 | SWR_REQ_CLK_SWITCH, NULL); |
| 1788 | } |
| 1789 | |
| 1790 | return ret; |
| 1791 | } |
| 1792 | |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1793 | static int tx_macro_swrm_clock(void *handle, bool enable) |
| 1794 | { |
| 1795 | struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle; |
| 1796 | struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL); |
| 1797 | int ret = 0; |
| 1798 | |
| 1799 | if (regmap == NULL) { |
| 1800 | dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__); |
| 1801 | return -EINVAL; |
| 1802 | } |
| 1803 | |
| 1804 | mutex_lock(&tx_priv->swr_clk_lock); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1805 | dev_dbg(tx_priv->dev, |
| 1806 | "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n", |
| 1807 | __func__, (enable ? "enable" : "disable"), |
| 1808 | tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1809 | |
| 1810 | if (enable) { |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 1811 | pm_runtime_get_sync(tx_priv->dev); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1812 | if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt) { |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1813 | ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap, |
| 1814 | VA_MCLK, enable); |
| 1815 | if (ret) |
| 1816 | goto done; |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1817 | tx_priv->va_clk_status++; |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1818 | } else { |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1819 | ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap, |
| 1820 | TX_MCLK, enable); |
| 1821 | if (ret) |
| 1822 | goto done; |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1823 | tx_priv->tx_clk_status++; |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1824 | } |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 1825 | pm_runtime_mark_last_busy(tx_priv->dev); |
| 1826 | pm_runtime_put_autosuspend(tx_priv->dev); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1827 | } else { |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1828 | if (tx_priv->va_clk_status && !tx_priv->tx_clk_status) { |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1829 | ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap, |
| 1830 | VA_MCLK, enable); |
| 1831 | if (ret) |
| 1832 | goto done; |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1833 | --tx_priv->va_clk_status; |
| 1834 | } else if (!tx_priv->va_clk_status && tx_priv->tx_clk_status) { |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1835 | ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap, |
| 1836 | TX_MCLK, enable); |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1837 | if (ret) |
| 1838 | goto done; |
| 1839 | --tx_priv->tx_clk_status; |
| 1840 | } else if (tx_priv->va_clk_status && tx_priv->tx_clk_status) { |
| 1841 | if (!tx_priv->va_swr_clk_cnt && tx_priv->tx_swr_clk_cnt) { |
| 1842 | ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap, |
| 1843 | VA_MCLK, enable); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1844 | if (ret) |
| 1845 | goto done; |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1846 | --tx_priv->va_clk_status; |
| 1847 | } else { |
| 1848 | ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap, |
| 1849 | TX_MCLK, enable); |
| 1850 | if (ret) |
| 1851 | goto done; |
| 1852 | --tx_priv->tx_clk_status; |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1853 | } |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1854 | |
| 1855 | } else { |
| 1856 | dev_dbg(tx_priv->dev, |
| 1857 | "%s: Both clocks are disabled\n", __func__); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1858 | } |
| 1859 | } |
Sudheer Papothi | cf3b406 | 2019-05-10 10:48:43 +0530 | [diff] [blame] | 1860 | |
| 1861 | dev_dbg(tx_priv->dev, |
| 1862 | "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n", |
| 1863 | __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status, |
| 1864 | tx_priv->va_clk_status); |
Sudheer Papothi | a739794 | 2019-03-19 03:14:23 +0530 | [diff] [blame] | 1865 | done: |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1866 | mutex_unlock(&tx_priv->swr_clk_lock); |
| 1867 | return ret; |
| 1868 | } |
| 1869 | |
| 1870 | static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate, |
| 1871 | struct tx_macro_priv *tx_priv) |
| 1872 | { |
| 1873 | u32 div_factor = TX_MACRO_CLK_DIV_2; |
| 1874 | u32 mclk_rate = TX_MACRO_MCLK_FREQ; |
| 1875 | |
| 1876 | if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED || |
| 1877 | mclk_rate % dmic_sample_rate != 0) |
| 1878 | goto undefined_rate; |
| 1879 | |
| 1880 | div_factor = mclk_rate / dmic_sample_rate; |
| 1881 | |
| 1882 | switch (div_factor) { |
| 1883 | case 2: |
| 1884 | tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2; |
| 1885 | break; |
| 1886 | case 3: |
| 1887 | tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3; |
| 1888 | break; |
| 1889 | case 4: |
| 1890 | tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4; |
| 1891 | break; |
| 1892 | case 6: |
| 1893 | tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6; |
| 1894 | break; |
| 1895 | case 8: |
| 1896 | tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8; |
| 1897 | break; |
| 1898 | case 16: |
| 1899 | tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16; |
| 1900 | break; |
| 1901 | default: |
| 1902 | /* Any other DIV factor is invalid */ |
| 1903 | goto undefined_rate; |
| 1904 | } |
| 1905 | |
| 1906 | /* Valid dmic DIV factors */ |
| 1907 | dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n", |
| 1908 | __func__, div_factor, mclk_rate); |
| 1909 | |
| 1910 | return dmic_sample_rate; |
| 1911 | |
| 1912 | undefined_rate: |
| 1913 | dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n", |
| 1914 | __func__, dmic_sample_rate, mclk_rate); |
| 1915 | dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED; |
| 1916 | |
| 1917 | return dmic_sample_rate; |
| 1918 | } |
| 1919 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1920 | static int tx_macro_init(struct snd_soc_component *component) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1921 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1922 | struct snd_soc_dapm_context *dapm = |
| 1923 | snd_soc_component_get_dapm(component); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1924 | int ret = 0, i = 0; |
| 1925 | struct device *tx_dev = NULL; |
| 1926 | struct tx_macro_priv *tx_priv = NULL; |
| 1927 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1928 | tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1929 | if (!tx_dev) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1930 | dev_err(component->dev, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1931 | "%s: null device for macro!\n", __func__); |
| 1932 | return -EINVAL; |
| 1933 | } |
| 1934 | tx_priv = dev_get_drvdata(tx_dev); |
| 1935 | if (!tx_priv) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1936 | dev_err(component->dev, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1937 | "%s: priv is null for macro!\n", __func__); |
| 1938 | return -EINVAL; |
| 1939 | } |
| 1940 | ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets, |
| 1941 | ARRAY_SIZE(tx_macro_dapm_widgets)); |
| 1942 | if (ret < 0) { |
| 1943 | dev_err(tx_dev, "%s: Failed to add controls\n", __func__); |
| 1944 | return ret; |
| 1945 | } |
| 1946 | |
| 1947 | ret = snd_soc_dapm_add_routes(dapm, tx_audio_map, |
| 1948 | ARRAY_SIZE(tx_audio_map)); |
| 1949 | if (ret < 0) { |
| 1950 | dev_err(tx_dev, "%s: Failed to add routes\n", __func__); |
| 1951 | return ret; |
| 1952 | } |
| 1953 | |
| 1954 | ret = snd_soc_dapm_new_widgets(dapm->card); |
| 1955 | if (ret < 0) { |
| 1956 | dev_err(tx_dev, "%s: Failed to add widgets\n", __func__); |
| 1957 | return ret; |
| 1958 | } |
| 1959 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1960 | ret = snd_soc_add_component_controls(component, tx_macro_snd_controls, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1961 | ARRAY_SIZE(tx_macro_snd_controls)); |
| 1962 | if (ret < 0) { |
| 1963 | dev_err(tx_dev, "%s: Failed to add snd_ctls\n", __func__); |
| 1964 | return ret; |
| 1965 | } |
Laxminath Kasam | 638b560 | 2018-09-24 13:19:52 +0530 | [diff] [blame] | 1966 | |
| 1967 | snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture"); |
| 1968 | snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture"); |
Karthikeyan Mani | f3bb818 | 2019-07-11 14:38:54 -0700 | [diff] [blame] | 1969 | snd_soc_dapm_ignore_suspend(dapm, "TX_AIF3 Capture"); |
Laxminath Kasam | 638b560 | 2018-09-24 13:19:52 +0530 | [diff] [blame] | 1970 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0"); |
| 1971 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1"); |
| 1972 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2"); |
| 1973 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3"); |
Vatsal Bucha | 39ead2c | 2018-12-14 12:22:46 +0530 | [diff] [blame] | 1974 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0"); |
| 1975 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1"); |
| 1976 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2"); |
| 1977 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3"); |
| 1978 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4"); |
| 1979 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5"); |
| 1980 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6"); |
| 1981 | snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7"); |
Laxminath Kasam | 638b560 | 2018-09-24 13:19:52 +0530 | [diff] [blame] | 1982 | snd_soc_dapm_sync(dapm); |
| 1983 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1984 | for (i = 0; i < NUM_DECIMATORS; i++) { |
| 1985 | tx_priv->tx_hpf_work[i].tx_priv = tx_priv; |
| 1986 | tx_priv->tx_hpf_work[i].decimator = i; |
| 1987 | INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork, |
| 1988 | tx_macro_tx_hpf_corner_freq_callback); |
| 1989 | } |
| 1990 | |
| 1991 | for (i = 0; i < NUM_DECIMATORS; i++) { |
| 1992 | tx_priv->tx_mute_dwork[i].tx_priv = tx_priv; |
| 1993 | tx_priv->tx_mute_dwork[i].decimator = i; |
| 1994 | INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork, |
| 1995 | tx_macro_mute_update_callback); |
| 1996 | } |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1997 | tx_priv->component = component; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 1998 | |
Karthikeyan Mani | 765eaab | 2019-07-18 16:27:01 -0700 | [diff] [blame] | 1999 | snd_soc_component_update_bits(component, |
| 2000 | BOLERO_CDC_TX0_TX_PATH_SEC7, 0x3F, 0x0E); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2001 | return 0; |
| 2002 | } |
| 2003 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 2004 | static int tx_macro_deinit(struct snd_soc_component *component) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2005 | { |
| 2006 | struct device *tx_dev = NULL; |
| 2007 | struct tx_macro_priv *tx_priv = NULL; |
| 2008 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 2009 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2010 | return -EINVAL; |
| 2011 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 2012 | tx_priv->component = NULL; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2013 | return 0; |
| 2014 | } |
| 2015 | |
| 2016 | static void tx_macro_add_child_devices(struct work_struct *work) |
| 2017 | { |
| 2018 | struct tx_macro_priv *tx_priv = NULL; |
| 2019 | struct platform_device *pdev = NULL; |
| 2020 | struct device_node *node = NULL; |
| 2021 | struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL; |
| 2022 | int ret = 0; |
| 2023 | u16 count = 0, ctrl_num = 0; |
| 2024 | struct tx_macro_swr_ctrl_platform_data *platdata = NULL; |
| 2025 | char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = ""; |
| 2026 | bool tx_swr_master_node = false; |
| 2027 | |
| 2028 | tx_priv = container_of(work, struct tx_macro_priv, |
| 2029 | tx_macro_add_child_devices_work); |
| 2030 | if (!tx_priv) { |
| 2031 | pr_err("%s: Memory for tx_priv does not exist\n", |
| 2032 | __func__); |
| 2033 | return; |
| 2034 | } |
| 2035 | |
| 2036 | if (!tx_priv->dev) { |
| 2037 | pr_err("%s: tx dev does not exist\n", __func__); |
| 2038 | return; |
| 2039 | } |
| 2040 | |
| 2041 | if (!tx_priv->dev->of_node) { |
| 2042 | dev_err(tx_priv->dev, |
| 2043 | "%s: DT node for tx_priv does not exist\n", __func__); |
| 2044 | return; |
| 2045 | } |
| 2046 | |
| 2047 | platdata = &tx_priv->swr_plat_data; |
| 2048 | tx_priv->child_count = 0; |
| 2049 | |
| 2050 | for_each_available_child_of_node(tx_priv->dev->of_node, node) { |
| 2051 | tx_swr_master_node = false; |
| 2052 | if (strnstr(node->name, "tx_swr_master", |
| 2053 | strlen("tx_swr_master")) != NULL) |
| 2054 | tx_swr_master_node = true; |
| 2055 | |
| 2056 | if (tx_swr_master_node) |
| 2057 | strlcpy(plat_dev_name, "tx_swr_ctrl", |
| 2058 | (TX_MACRO_SWR_STRING_LEN - 1)); |
| 2059 | else |
| 2060 | strlcpy(plat_dev_name, node->name, |
| 2061 | (TX_MACRO_SWR_STRING_LEN - 1)); |
| 2062 | |
| 2063 | pdev = platform_device_alloc(plat_dev_name, -1); |
| 2064 | if (!pdev) { |
| 2065 | dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n", |
| 2066 | __func__); |
| 2067 | ret = -ENOMEM; |
| 2068 | goto err; |
| 2069 | } |
| 2070 | pdev->dev.parent = tx_priv->dev; |
| 2071 | pdev->dev.of_node = node; |
| 2072 | |
| 2073 | if (tx_swr_master_node) { |
| 2074 | ret = platform_device_add_data(pdev, platdata, |
| 2075 | sizeof(*platdata)); |
| 2076 | if (ret) { |
| 2077 | dev_err(&pdev->dev, |
| 2078 | "%s: cannot add plat data ctrl:%d\n", |
| 2079 | __func__, ctrl_num); |
| 2080 | goto fail_pdev_add; |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | ret = platform_device_add(pdev); |
| 2085 | if (ret) { |
| 2086 | dev_err(&pdev->dev, |
| 2087 | "%s: Cannot add platform device\n", |
| 2088 | __func__); |
| 2089 | goto fail_pdev_add; |
| 2090 | } |
| 2091 | |
| 2092 | if (tx_swr_master_node) { |
| 2093 | temp = krealloc(swr_ctrl_data, |
| 2094 | (ctrl_num + 1) * sizeof( |
| 2095 | struct tx_macro_swr_ctrl_data), |
| 2096 | GFP_KERNEL); |
| 2097 | if (!temp) { |
| 2098 | ret = -ENOMEM; |
| 2099 | goto fail_pdev_add; |
| 2100 | } |
| 2101 | swr_ctrl_data = temp; |
| 2102 | swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev; |
| 2103 | ctrl_num++; |
| 2104 | dev_dbg(&pdev->dev, |
| 2105 | "%s: Added soundwire ctrl device(s)\n", |
| 2106 | __func__); |
| 2107 | tx_priv->swr_ctrl_data = swr_ctrl_data; |
| 2108 | } |
| 2109 | if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX) |
| 2110 | tx_priv->pdev_child_devices[ |
| 2111 | tx_priv->child_count++] = pdev; |
| 2112 | else |
| 2113 | goto err; |
| 2114 | } |
| 2115 | return; |
| 2116 | fail_pdev_add: |
| 2117 | for (count = 0; count < tx_priv->child_count; count++) |
| 2118 | platform_device_put(tx_priv->pdev_child_devices[count]); |
| 2119 | err: |
| 2120 | return; |
| 2121 | } |
| 2122 | |
Sudheer Papothi | a3e969d | 2018-10-27 06:22:10 +0530 | [diff] [blame] | 2123 | static int tx_macro_set_port_map(struct snd_soc_component *component, |
| 2124 | u32 usecase, u32 size, void *data) |
| 2125 | { |
| 2126 | struct device *tx_dev = NULL; |
| 2127 | struct tx_macro_priv *tx_priv = NULL; |
| 2128 | struct swrm_port_config port_cfg; |
| 2129 | int ret = 0; |
| 2130 | |
| 2131 | if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__)) |
| 2132 | return -EINVAL; |
| 2133 | |
| 2134 | memset(&port_cfg, 0, sizeof(port_cfg)); |
| 2135 | port_cfg.uc = usecase; |
| 2136 | port_cfg.size = size; |
| 2137 | port_cfg.params = data; |
| 2138 | |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 2139 | if (tx_priv->swr_ctrl_data) |
| 2140 | ret = swrm_wcd_notify( |
| 2141 | tx_priv->swr_ctrl_data[0].tx_swr_pdev, |
| 2142 | SWR_SET_PORT_MAP, &port_cfg); |
Sudheer Papothi | a3e969d | 2018-10-27 06:22:10 +0530 | [diff] [blame] | 2143 | |
| 2144 | return ret; |
| 2145 | } |
| 2146 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2147 | static void tx_macro_init_ops(struct macro_ops *ops, |
| 2148 | char __iomem *tx_io_base) |
| 2149 | { |
| 2150 | memset(ops, 0, sizeof(struct macro_ops)); |
| 2151 | ops->init = tx_macro_init; |
| 2152 | ops->exit = tx_macro_deinit; |
| 2153 | ops->io_base = tx_io_base; |
| 2154 | ops->dai_ptr = tx_macro_dai; |
| 2155 | ops->num_dais = ARRAY_SIZE(tx_macro_dai); |
Laxminath Kasam | fb0d683 | 2018-09-22 01:49:52 +0530 | [diff] [blame] | 2156 | ops->event_handler = tx_macro_event_handler; |
Aditya Bavanari | c4e9612 | 2018-11-14 14:46:38 +0530 | [diff] [blame] | 2157 | ops->reg_wake_irq = tx_macro_reg_wake_irq; |
Sudheer Papothi | a3e969d | 2018-10-27 06:22:10 +0530 | [diff] [blame] | 2158 | ops->set_port_map = tx_macro_set_port_map; |
Sudheer Papothi | 6cc7f52 | 2019-06-28 11:04:03 +0530 | [diff] [blame] | 2159 | ops->clk_switch = tx_macro_clk_switch; |
Sudheer Papothi | 06a4c64 | 2019-08-08 05:17:46 +0530 | [diff] [blame^] | 2160 | ops->reg_evt_listener = tx_macro_register_event_listener; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | static int tx_macro_probe(struct platform_device *pdev) |
| 2164 | { |
| 2165 | struct macro_ops ops = {0}; |
| 2166 | struct tx_macro_priv *tx_priv = NULL; |
| 2167 | u32 tx_base_addr = 0, sample_rate = 0; |
| 2168 | char __iomem *tx_io_base = NULL; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2169 | int ret = 0; |
| 2170 | const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate"; |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 2171 | u32 is_used_tx_swr_gpio = 1; |
| 2172 | const char *is_used_tx_swr_gpio_dt = "qcom,is-used-swr-gpio"; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2173 | |
| 2174 | tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv), |
| 2175 | GFP_KERNEL); |
| 2176 | if (!tx_priv) |
| 2177 | return -ENOMEM; |
| 2178 | platform_set_drvdata(pdev, tx_priv); |
| 2179 | |
| 2180 | tx_priv->dev = &pdev->dev; |
| 2181 | ret = of_property_read_u32(pdev->dev.of_node, "reg", |
| 2182 | &tx_base_addr); |
| 2183 | if (ret) { |
| 2184 | dev_err(&pdev->dev, "%s: could not find %s entry in dt\n", |
| 2185 | __func__, "reg"); |
| 2186 | return ret; |
| 2187 | } |
| 2188 | dev_set_drvdata(&pdev->dev, tx_priv); |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 2189 | if (of_find_property(pdev->dev.of_node, is_used_tx_swr_gpio_dt, |
| 2190 | NULL)) { |
| 2191 | ret = of_property_read_u32(pdev->dev.of_node, |
| 2192 | is_used_tx_swr_gpio_dt, |
| 2193 | &is_used_tx_swr_gpio); |
| 2194 | if (ret) { |
| 2195 | dev_err(&pdev->dev, "%s: error reading %s in dt\n", |
| 2196 | __func__, is_used_tx_swr_gpio_dt); |
| 2197 | is_used_tx_swr_gpio = 1; |
| 2198 | } |
| 2199 | } |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2200 | tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node, |
| 2201 | "qcom,tx-swr-gpios", 0); |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 2202 | if (!tx_priv->tx_swr_gpio_p && is_used_tx_swr_gpio) { |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2203 | dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n", |
| 2204 | __func__); |
| 2205 | return -EINVAL; |
| 2206 | } |
Karthikeyan Mani | 326536d | 2019-06-03 13:29:43 -0700 | [diff] [blame] | 2207 | if (msm_cdc_pinctrl_get_state(tx_priv->tx_swr_gpio_p) < 0) { |
| 2208 | dev_err(&pdev->dev, "%s: failed to get swr pin state\n", |
| 2209 | __func__); |
| 2210 | return -EPROBE_DEFER; |
| 2211 | } |
| 2212 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2213 | tx_io_base = devm_ioremap(&pdev->dev, |
| 2214 | tx_base_addr, TX_MACRO_MAX_OFFSET); |
| 2215 | if (!tx_io_base) { |
| 2216 | dev_err(&pdev->dev, "%s: ioremap failed\n", __func__); |
| 2217 | return -ENOMEM; |
| 2218 | } |
| 2219 | tx_priv->tx_io_base = tx_io_base; |
| 2220 | ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate, |
| 2221 | &sample_rate); |
| 2222 | if (ret) { |
| 2223 | dev_err(&pdev->dev, |
| 2224 | "%s: could not find sample_rate entry in dt\n", |
| 2225 | __func__); |
| 2226 | tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2; |
| 2227 | } else { |
| 2228 | if (tx_macro_validate_dmic_sample_rate( |
| 2229 | sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED) |
| 2230 | return -EINVAL; |
| 2231 | } |
Ramprasad Katkam | a4c747b | 2018-12-11 19:15:53 +0530 | [diff] [blame] | 2232 | tx_priv->reset_swr = true; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2233 | INIT_WORK(&tx_priv->tx_macro_add_child_devices_work, |
| 2234 | tx_macro_add_child_devices); |
| 2235 | tx_priv->swr_plat_data.handle = (void *) tx_priv; |
| 2236 | tx_priv->swr_plat_data.read = NULL; |
| 2237 | tx_priv->swr_plat_data.write = NULL; |
| 2238 | tx_priv->swr_plat_data.bulk_write = NULL; |
| 2239 | tx_priv->swr_plat_data.clk = tx_macro_swrm_clock; |
| 2240 | tx_priv->swr_plat_data.handle_irq = NULL; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2241 | |
| 2242 | mutex_init(&tx_priv->mclk_lock); |
| 2243 | mutex_init(&tx_priv->swr_clk_lock); |
| 2244 | tx_macro_init_ops(&ops, tx_io_base); |
Vidyakumar Athota | 5d45f4c | 2019-03-10 22:35:07 -0700 | [diff] [blame] | 2245 | ops.clk_id_req = TX_CORE_CLK; |
| 2246 | ops.default_clk_id = TX_CORE_CLK; |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2247 | ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops); |
| 2248 | if (ret) { |
| 2249 | dev_err(&pdev->dev, |
| 2250 | "%s: register macro failed\n", __func__); |
| 2251 | goto err_reg_macro; |
| 2252 | } |
Vidyakumar Athota | 5d45f4c | 2019-03-10 22:35:07 -0700 | [diff] [blame] | 2253 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2254 | schedule_work(&tx_priv->tx_macro_add_child_devices_work); |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 2255 | pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY); |
| 2256 | pm_runtime_use_autosuspend(&pdev->dev); |
| 2257 | pm_runtime_set_suspended(&pdev->dev); |
Sudheer Papothi | 296867b | 2019-06-20 09:24:09 +0530 | [diff] [blame] | 2258 | pm_suspend_ignore_children(&pdev->dev, true); |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 2259 | pm_runtime_enable(&pdev->dev); |
| 2260 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2261 | return 0; |
| 2262 | err_reg_macro: |
| 2263 | mutex_destroy(&tx_priv->mclk_lock); |
| 2264 | mutex_destroy(&tx_priv->swr_clk_lock); |
| 2265 | return ret; |
| 2266 | } |
| 2267 | |
| 2268 | static int tx_macro_remove(struct platform_device *pdev) |
| 2269 | { |
| 2270 | struct tx_macro_priv *tx_priv = NULL; |
| 2271 | u16 count = 0; |
| 2272 | |
| 2273 | tx_priv = platform_get_drvdata(pdev); |
| 2274 | |
| 2275 | if (!tx_priv) |
| 2276 | return -EINVAL; |
| 2277 | |
Karthikeyan Mani | 3bd80a5 | 2019-06-04 23:40:16 -0700 | [diff] [blame] | 2278 | if (tx_priv->swr_ctrl_data) |
| 2279 | kfree(tx_priv->swr_ctrl_data); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2280 | for (count = 0; count < tx_priv->child_count && |
| 2281 | count < TX_MACRO_CHILD_DEVICES_MAX; count++) |
| 2282 | platform_device_unregister(tx_priv->pdev_child_devices[count]); |
| 2283 | |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 2284 | pm_runtime_disable(&pdev->dev); |
| 2285 | pm_runtime_set_suspended(&pdev->dev); |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2286 | mutex_destroy(&tx_priv->mclk_lock); |
| 2287 | mutex_destroy(&tx_priv->swr_clk_lock); |
| 2288 | bolero_unregister_macro(&pdev->dev, TX_MACRO); |
| 2289 | return 0; |
| 2290 | } |
| 2291 | |
| 2292 | |
| 2293 | static const struct of_device_id tx_macro_dt_match[] = { |
| 2294 | {.compatible = "qcom,tx-macro"}, |
| 2295 | {} |
| 2296 | }; |
| 2297 | |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 2298 | static const struct dev_pm_ops bolero_dev_pm_ops = { |
| 2299 | SET_RUNTIME_PM_OPS( |
| 2300 | bolero_runtime_suspend, |
| 2301 | bolero_runtime_resume, |
| 2302 | NULL |
| 2303 | ) |
| 2304 | }; |
| 2305 | |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2306 | static struct platform_driver tx_macro_driver = { |
| 2307 | .driver = { |
| 2308 | .name = "tx_macro", |
| 2309 | .owner = THIS_MODULE, |
Sudheer Papothi | 7601cc6 | 2019-03-30 03:00:52 +0530 | [diff] [blame] | 2310 | .pm = &bolero_dev_pm_ops, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2311 | .of_match_table = tx_macro_dt_match, |
Xiaojun Sang | 53cd13a | 2018-06-29 15:14:37 +0800 | [diff] [blame] | 2312 | .suppress_bind_attrs = true, |
Laxminath Kasam | 989fccf | 2018-06-15 16:53:31 +0530 | [diff] [blame] | 2313 | }, |
| 2314 | .probe = tx_macro_probe, |
| 2315 | .remove = tx_macro_remove, |
| 2316 | }; |
| 2317 | |
| 2318 | module_platform_driver(tx_macro_driver); |
| 2319 | |
| 2320 | MODULE_DESCRIPTION("TX macro driver"); |
| 2321 | MODULE_LICENSE("GPL v2"); |