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