blob: f32c43a57ff619ece185b633e861447d5faa5b7e [file] [log] [blame]
Meng Wang43bbb872018-12-10 12:32:05 +08001// SPDX-License-Identifier: GPL-2.0-only
Vatsal Bucha39ead2c2018-12-14 12:22:46 +05302/* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303 */
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 Papothi7601cc62019-03-30 03:00:52 +053011#include <linux/pm_runtime.h>
Laxminath Kasam989fccf2018-06-15 16:53:31 +053012#include <sound/soc.h>
13#include <sound/soc-dapm.h>
14#include <sound/tlv.h>
Sudheer Papothia3e969d2018-10-27 06:22:10 +053015#include <soc/swr-common.h>
Laxminath Kasamfb0d6832018-09-22 01:49:52 +053016#include <soc/swr-wcd.h>
Meng Wang11a25cf2018-10-31 14:11:26 +080017#include <asoc/msm-cdc-pinctrl.h>
Laxminath Kasam989fccf2018-06-15 16:53:31 +053018#include "bolero-cdc.h"
19#include "bolero-cdc-registers.h"
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -070020#include "bolero-clk-rsc.h"
Laxminath Kasam989fccf2018-06-15 16:53:31 +053021
Sudheer Papothi7601cc62019-03-30 03:00:52 +053022#define AUTO_SUSPEND_DELAY 50 /* delay in msec */
Laxminath Kasam989fccf2018-06-15 16:53:31 +053023#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 Kasam497a6512018-09-17 16:11:52 +053042#define TX_MACRO_SWR_MIC_MUX_SEL_MASK 0xF
43#define TX_MACRO_ADC_MUX_CFG_OFFSET 0x2
Karthikeyan Mani1dcd5a32019-08-22 14:37:13 -070044#define TX_MACRO_ADC_MODE_CFG0_SHIFT 1
Laxminath Kasam989fccf2018-06-15 16:53:31 +053045
46#define TX_MACRO_TX_UNMUTE_DELAY_MS 40
47
48static int tx_unmute_delay = TX_MACRO_TX_UNMUTE_DELAY_MS;
49module_param(tx_unmute_delay, int, 0664);
50MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
51
52static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
53
54static int tx_macro_hw_params(struct snd_pcm_substream *substream,
55 struct snd_pcm_hw_params *params,
56 struct snd_soc_dai *dai);
57static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
58 unsigned int *tx_num, unsigned int *tx_slot,
59 unsigned int *rx_num, unsigned int *rx_slot);
60
61#define TX_MACRO_SWR_STRING_LEN 80
62#define TX_MACRO_CHILD_DEVICES_MAX 3
63
64/* Hold instance to soundwire platform device */
65struct tx_macro_swr_ctrl_data {
66 struct platform_device *tx_swr_pdev;
67};
68
69struct tx_macro_swr_ctrl_platform_data {
70 void *handle; /* holds codec private data */
71 int (*read)(void *handle, int reg);
72 int (*write)(void *handle, int reg, int val);
73 int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
74 int (*clk)(void *handle, bool enable);
Karthikeyan Mani8d40a062019-09-05 16:44:49 -070075 int (*core_vote)(void *handle, bool enable);
Laxminath Kasam989fccf2018-06-15 16:53:31 +053076 int (*handle_irq)(void *handle,
77 irqreturn_t (*swrm_irq_handler)(int irq,
78 void *data),
79 void *swrm_handle,
80 int action);
81};
82
83enum {
Laxminath Kasam59c7a1d2018-08-09 16:11:17 +053084 TX_MACRO_AIF_INVALID = 0,
85 TX_MACRO_AIF1_CAP,
Laxminath Kasam989fccf2018-06-15 16:53:31 +053086 TX_MACRO_AIF2_CAP,
Karthikeyan Manif3bb8182019-07-11 14:38:54 -070087 TX_MACRO_AIF3_CAP,
Laxminath Kasam989fccf2018-06-15 16:53:31 +053088 TX_MACRO_MAX_DAIS
89};
90
91enum {
92 TX_MACRO_DEC0,
93 TX_MACRO_DEC1,
94 TX_MACRO_DEC2,
95 TX_MACRO_DEC3,
96 TX_MACRO_DEC4,
97 TX_MACRO_DEC5,
98 TX_MACRO_DEC6,
99 TX_MACRO_DEC7,
100 TX_MACRO_DEC_MAX,
101};
102
103enum {
104 TX_MACRO_CLK_DIV_2,
105 TX_MACRO_CLK_DIV_3,
106 TX_MACRO_CLK_DIV_4,
107 TX_MACRO_CLK_DIV_6,
108 TX_MACRO_CLK_DIV_8,
109 TX_MACRO_CLK_DIV_16,
110};
111
Laxminath Kasam497a6512018-09-17 16:11:52 +0530112enum {
113 MSM_DMIC,
114 SWR_MIC,
115 ANC_FB_TUNE1
116};
117
Sudheer Papothia7397942019-03-19 03:14:23 +0530118enum {
119 TX_MCLK,
120 VA_MCLK,
121};
122
Sudheer Papothi72fef482019-08-30 11:00:20 +0530123struct tx_macro_reg_mask_val {
124 u16 reg;
125 u8 mask;
126 u8 val;
127};
128
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530129struct tx_mute_work {
130 struct tx_macro_priv *tx_priv;
131 u32 decimator;
132 struct delayed_work dwork;
133};
134
135struct hpf_work {
136 struct tx_macro_priv *tx_priv;
137 u8 decimator;
138 u8 hpf_cut_off_freq;
139 struct delayed_work dwork;
140};
141
142struct tx_macro_priv {
143 struct device *dev;
144 bool dec_active[NUM_DECIMATORS];
145 int tx_mclk_users;
146 int swr_clk_users;
Ramprasad Katkam452772a2019-01-07 17:30:36 +0530147 bool dapm_mclk_enable;
Ramprasad Katkama4c747b2018-12-11 19:15:53 +0530148 bool reset_swr;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530149 struct mutex mclk_lock;
150 struct mutex swr_clk_lock;
Meng Wang15c825d2018-09-06 10:49:18 +0800151 struct snd_soc_component *component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530152 struct device_node *tx_swr_gpio_p;
153 struct tx_macro_swr_ctrl_data *swr_ctrl_data;
154 struct tx_macro_swr_ctrl_platform_data swr_plat_data;
155 struct work_struct tx_macro_add_child_devices_work;
156 struct hpf_work tx_hpf_work[NUM_DECIMATORS];
157 struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530158 u16 dmic_clk_div;
Laxminath Kasam4651dcb2019-10-10 23:45:21 +0530159 u32 version;
Laxminath Kasam2e13d642019-10-12 01:36:30 +0530160 u32 is_used_tx_swr_gpio;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530161 unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
162 unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
163 char __iomem *tx_io_base;
164 struct platform_device *pdev_child_devices
165 [TX_MACRO_CHILD_DEVICES_MAX];
166 int child_count;
Sudheer Papothie456c2c2019-03-05 07:08:45 +0530167 int tx_swr_clk_cnt;
168 int va_swr_clk_cnt;
Sudheer Papothicf3b4062019-05-10 10:48:43 +0530169 int va_clk_status;
170 int tx_clk_status;
Karthikeyan Mani765eaab2019-07-18 16:27:01 -0700171 bool bcs_enable;
Karthikeyan Mani1dcd5a32019-08-22 14:37:13 -0700172 int dec_mode[NUM_DECIMATORS];
Vatsal Buchad06525f2019-10-14 23:14:12 +0530173 bool bcs_clk_en;
174 bool hs_slow_insert_complete;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530175};
176
Meng Wang15c825d2018-09-06 10:49:18 +0800177static bool tx_macro_get_data(struct snd_soc_component *component,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530178 struct device **tx_dev,
179 struct tx_macro_priv **tx_priv,
180 const char *func_name)
181{
Meng Wang15c825d2018-09-06 10:49:18 +0800182 *tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530183 if (!(*tx_dev)) {
Meng Wang15c825d2018-09-06 10:49:18 +0800184 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530185 "%s: null device for macro!\n", func_name);
186 return false;
187 }
188
189 *tx_priv = dev_get_drvdata((*tx_dev));
190 if (!(*tx_priv)) {
Meng Wang15c825d2018-09-06 10:49:18 +0800191 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530192 "%s: priv is null for macro!\n", func_name);
193 return false;
194 }
195
Meng Wang15c825d2018-09-06 10:49:18 +0800196 if (!(*tx_priv)->component) {
197 dev_err(component->dev,
198 "%s: tx_priv->component not initialized!\n", func_name);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530199 return false;
200 }
201
202 return true;
203}
204
205static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv,
206 bool mclk_enable)
207{
208 struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
209 int ret = 0;
210
Tanya Dixit8530fb92018-09-14 16:01:25 +0530211 if (regmap == NULL) {
212 dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
213 return -EINVAL;
214 }
215
Laxminath Kasamb7f823c2018-08-02 13:23:11 +0530216 dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n",
217 __func__, mclk_enable, tx_priv->tx_mclk_users);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530218
219 mutex_lock(&tx_priv->mclk_lock);
220 if (mclk_enable) {
221 if (tx_priv->tx_mclk_users == 0) {
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -0700222 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
223 TX_CORE_CLK,
224 TX_CORE_CLK,
225 true);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530226 if (ret < 0) {
Ramprasad Katkam14efed62019-03-07 13:16:50 +0530227 dev_err_ratelimited(tx_priv->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530228 "%s: request clock enable failed\n",
229 __func__);
230 goto exit;
231 }
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -0700232 bolero_clk_rsc_fs_gen_request(tx_priv->dev,
233 true);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530234 regcache_mark_dirty(regmap);
235 regcache_sync_region(regmap,
236 TX_START_OFFSET,
237 TX_MAX_OFFSET);
238 /* 9.6MHz MCLK, set value 0x00 if other frequency */
239 regmap_update_bits(regmap,
240 BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
241 regmap_update_bits(regmap,
242 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
243 0x01, 0x01);
244 regmap_update_bits(regmap,
245 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
246 0x01, 0x01);
247 }
248 tx_priv->tx_mclk_users++;
249 } else {
250 if (tx_priv->tx_mclk_users <= 0) {
251 dev_err(tx_priv->dev, "%s: clock already disabled\n",
252 __func__);
253 tx_priv->tx_mclk_users = 0;
254 goto exit;
255 }
256 tx_priv->tx_mclk_users--;
257 if (tx_priv->tx_mclk_users == 0) {
258 regmap_update_bits(regmap,
259 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
260 0x01, 0x00);
261 regmap_update_bits(regmap,
262 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
263 0x01, 0x00);
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -0700264 bolero_clk_rsc_fs_gen_request(tx_priv->dev,
265 false);
266
267 bolero_clk_rsc_request_clock(tx_priv->dev,
268 TX_CORE_CLK,
269 TX_CORE_CLK,
270 false);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530271 }
272 }
273exit:
274 mutex_unlock(&tx_priv->mclk_lock);
275 return ret;
276}
277
Sudheer Papothifc3adb02019-11-24 10:14:21 +0530278static int __tx_macro_mclk_enable(struct snd_soc_component *component,
279 bool enable)
280{
281 struct device *tx_dev = NULL;
282 struct tx_macro_priv *tx_priv = NULL;
283
284 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
285 return -EINVAL;
286
287 return tx_macro_mclk_enable(tx_priv, enable);
288}
289
Sudheer Papothie456c2c2019-03-05 07:08:45 +0530290static int tx_macro_va_swr_clk_event(struct snd_soc_dapm_widget *w,
291 struct snd_kcontrol *kcontrol, int event)
292{
293 struct device *tx_dev = NULL;
294 struct tx_macro_priv *tx_priv = NULL;
295 struct snd_soc_component *component =
296 snd_soc_dapm_to_component(w->dapm);
297
298 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
299 return -EINVAL;
300
301 if (SND_SOC_DAPM_EVENT_ON(event))
302 ++tx_priv->va_swr_clk_cnt;
303 if (SND_SOC_DAPM_EVENT_OFF(event))
304 --tx_priv->va_swr_clk_cnt;
305
306 return 0;
307}
308
309static int tx_macro_tx_swr_clk_event(struct snd_soc_dapm_widget *w,
310 struct snd_kcontrol *kcontrol, int event)
311{
312 struct device *tx_dev = NULL;
313 struct tx_macro_priv *tx_priv = NULL;
314 struct snd_soc_component *component =
315 snd_soc_dapm_to_component(w->dapm);
316
317 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
318 return -EINVAL;
319
320 if (SND_SOC_DAPM_EVENT_ON(event))
321 ++tx_priv->tx_swr_clk_cnt;
322 if (SND_SOC_DAPM_EVENT_OFF(event))
323 --tx_priv->tx_swr_clk_cnt;
324
325 return 0;
326}
327
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530328static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
329 struct snd_kcontrol *kcontrol, int event)
330{
Meng Wang15c825d2018-09-06 10:49:18 +0800331 struct snd_soc_component *component =
332 snd_soc_dapm_to_component(w->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530333 int ret = 0;
334 struct device *tx_dev = NULL;
335 struct tx_macro_priv *tx_priv = NULL;
336
Meng Wang15c825d2018-09-06 10:49:18 +0800337 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530338 return -EINVAL;
339
340 dev_dbg(tx_dev, "%s: event = %d\n", __func__, event);
341 switch (event) {
342 case SND_SOC_DAPM_PRE_PMU:
343 ret = tx_macro_mclk_enable(tx_priv, 1);
Ramprasad Katkam452772a2019-01-07 17:30:36 +0530344 if (ret)
345 tx_priv->dapm_mclk_enable = false;
346 else
347 tx_priv->dapm_mclk_enable = true;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530348 break;
349 case SND_SOC_DAPM_POST_PMD:
Ramprasad Katkam452772a2019-01-07 17:30:36 +0530350 if (tx_priv->dapm_mclk_enable)
351 ret = tx_macro_mclk_enable(tx_priv, 0);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530352 break;
353 default:
354 dev_err(tx_priv->dev,
355 "%s: invalid DAPM event %d\n", __func__, event);
356 ret = -EINVAL;
357 }
358 return ret;
359}
360
Meng Wang15c825d2018-09-06 10:49:18 +0800361static int tx_macro_event_handler(struct snd_soc_component *component,
362 u16 event, u32 data)
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530363{
364 struct device *tx_dev = NULL;
365 struct tx_macro_priv *tx_priv = NULL;
Aditya Bavanari50ef13e2019-08-09 15:14:43 +0530366 int ret = 0;
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530367
Meng Wang15c825d2018-09-06 10:49:18 +0800368 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530369 return -EINVAL;
370
371 switch (event) {
372 case BOLERO_MACRO_EVT_SSR_DOWN:
Karthikeyan Mani3bd80a52019-06-04 23:40:16 -0700373 if (tx_priv->swr_ctrl_data) {
374 swrm_wcd_notify(
375 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
376 SWR_DEVICE_DOWN, NULL);
377 swrm_wcd_notify(
378 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
379 SWR_DEVICE_SSR_DOWN, NULL);
380 }
Aditya Bavanari50ef13e2019-08-09 15:14:43 +0530381 if ((!pm_runtime_enabled(tx_dev) ||
382 !pm_runtime_suspended(tx_dev))) {
383 ret = bolero_runtime_suspend(tx_dev);
384 if (!ret) {
385 pm_runtime_disable(tx_dev);
386 pm_runtime_set_suspended(tx_dev);
387 pm_runtime_enable(tx_dev);
388 }
389 }
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530390 break;
391 case BOLERO_MACRO_EVT_SSR_UP:
Ramprasad Katkama4c747b2018-12-11 19:15:53 +0530392 /* reset swr after ssr/pdr */
393 tx_priv->reset_swr = true;
Karthikeyan Mani3bd80a52019-06-04 23:40:16 -0700394 if (tx_priv->swr_ctrl_data)
395 swrm_wcd_notify(
396 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
397 SWR_DEVICE_SSR_UP, NULL);
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530398 break;
Meng Wang8ef0cc22019-05-08 15:12:56 +0800399 case BOLERO_MACRO_EVT_CLK_RESET:
400 bolero_rsc_clk_reset(tx_dev, TX_CORE_CLK);
401 break;
Vatsal Buchad06525f2019-10-14 23:14:12 +0530402 case BOLERO_MACRO_EVT_BCS_CLK_OFF:
403 if (tx_priv->bcs_clk_en)
404 snd_soc_component_update_bits(component,
405 BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, data << 6);
406 if (data)
407 tx_priv->hs_slow_insert_complete = true;
408 else
409 tx_priv->hs_slow_insert_complete = false;
410 break;
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530411 }
412 return 0;
413}
414
Meng Wang15c825d2018-09-06 10:49:18 +0800415static int tx_macro_reg_wake_irq(struct snd_soc_component *component,
Aditya Bavanaric4e96122018-11-14 14:46:38 +0530416 u32 data)
417{
418 struct device *tx_dev = NULL;
419 struct tx_macro_priv *tx_priv = NULL;
420 u32 ipc_wakeup = data;
421 int ret = 0;
422
Meng Wang15c825d2018-09-06 10:49:18 +0800423 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Aditya Bavanaric4e96122018-11-14 14:46:38 +0530424 return -EINVAL;
425
Karthikeyan Mani3bd80a52019-06-04 23:40:16 -0700426 if (tx_priv->swr_ctrl_data)
427 ret = swrm_wcd_notify(
428 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
429 SWR_REGISTER_WAKE_IRQ, &ipc_wakeup);
Aditya Bavanaric4e96122018-11-14 14:46:38 +0530430
431 return ret;
432}
433
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530434static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
435{
436 struct delayed_work *hpf_delayed_work = NULL;
437 struct hpf_work *hpf_work = NULL;
438 struct tx_macro_priv *tx_priv = NULL;
Meng Wang15c825d2018-09-06 10:49:18 +0800439 struct snd_soc_component *component = NULL;
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530440 u16 dec_cfg_reg = 0, hpf_gate_reg = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530441 u8 hpf_cut_off_freq = 0;
Laxminath Kasam497a6512018-09-17 16:11:52 +0530442 u16 adc_mux_reg = 0, adc_n = 0, adc_reg = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530443
444 hpf_delayed_work = to_delayed_work(work);
445 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
446 tx_priv = hpf_work->tx_priv;
Meng Wang15c825d2018-09-06 10:49:18 +0800447 component = tx_priv->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530448 hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
449
450 dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
451 TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530452 hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
453 TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530454
Meng Wang15c825d2018-09-06 10:49:18 +0800455 dev_dbg(component->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530456 __func__, hpf_work->decimator, hpf_cut_off_freq);
457
Laxminath Kasam497a6512018-09-17 16:11:52 +0530458 adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
459 TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
Meng Wang15c825d2018-09-06 10:49:18 +0800460 if (snd_soc_component_read32(component, adc_mux_reg) & SWR_MIC) {
Laxminath Kasam497a6512018-09-17 16:11:52 +0530461 adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
462 TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
Meng Wang15c825d2018-09-06 10:49:18 +0800463 adc_n = snd_soc_component_read32(component, adc_reg) &
Laxminath Kasam497a6512018-09-17 16:11:52 +0530464 TX_MACRO_SWR_MIC_MUX_SEL_MASK;
465 if (adc_n >= BOLERO_ADC_MAX)
466 goto tx_hpf_set;
467 /* analog mic clear TX hold */
Meng Wang15c825d2018-09-06 10:49:18 +0800468 bolero_clear_amic_tx_hold(component->dev, adc_n);
Laxminath Kasam497a6512018-09-17 16:11:52 +0530469 }
470tx_hpf_set:
Meng Wang15c825d2018-09-06 10:49:18 +0800471 snd_soc_component_update_bits(component,
472 dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
473 hpf_cut_off_freq << 5);
Karthikeyan Mani144659b2019-10-02 17:29:57 -0700474 snd_soc_component_update_bits(component, hpf_gate_reg, 0x02, 0x02);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530475 /* Minimum 1 clk cycle delay is required as per HW spec */
476 usleep_range(1000, 1010);
Karthikeyan Mani144659b2019-10-02 17:29:57 -0700477 snd_soc_component_update_bits(component, hpf_gate_reg, 0x02, 0x00);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530478}
479
480static void tx_macro_mute_update_callback(struct work_struct *work)
481{
482 struct tx_mute_work *tx_mute_dwork = NULL;
Meng Wang15c825d2018-09-06 10:49:18 +0800483 struct snd_soc_component *component = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530484 struct tx_macro_priv *tx_priv = NULL;
485 struct delayed_work *delayed_work = NULL;
Xiaojun Sangd155fdc2018-10-11 15:11:59 +0800486 u16 tx_vol_ctl_reg = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530487 u8 decimator = 0;
488
489 delayed_work = to_delayed_work(work);
490 tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
491 tx_priv = tx_mute_dwork->tx_priv;
Meng Wang15c825d2018-09-06 10:49:18 +0800492 component = tx_priv->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530493 decimator = tx_mute_dwork->decimator;
494
495 tx_vol_ctl_reg =
496 BOLERO_CDC_TX0_TX_PATH_CTL +
497 TX_MACRO_TX_PATH_OFFSET * decimator;
Meng Wang15c825d2018-09-06 10:49:18 +0800498 snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530499 dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
500 __func__, decimator);
501}
502
503static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
504 struct snd_ctl_elem_value *ucontrol)
505{
506 struct snd_soc_dapm_widget *widget =
507 snd_soc_dapm_kcontrol_widget(kcontrol);
Meng Wang15c825d2018-09-06 10:49:18 +0800508 struct snd_soc_component *component =
509 snd_soc_dapm_to_component(widget->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530510 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
511 unsigned int val = 0;
512 u16 mic_sel_reg = 0;
Laxminath Kasam549d11d2019-07-18 13:44:17 +0530513 u16 dmic_clk_reg = 0;
514 struct device *tx_dev = NULL;
515 struct tx_macro_priv *tx_priv = NULL;
516
517 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
518 return -EINVAL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530519
520 val = ucontrol->value.enumerated.item[0];
521 if (val > e->items - 1)
522 return -EINVAL;
523
Meng Wang15c825d2018-09-06 10:49:18 +0800524 dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530525 widget->name, val);
526
527 switch (e->reg) {
528 case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
529 mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
530 break;
531 case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
532 mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
533 break;
534 case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
535 mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
536 break;
537 case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
538 mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
539 break;
540 case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
541 mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
542 break;
543 case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
544 mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
545 break;
546 case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
547 mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
548 break;
549 case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
550 mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
551 break;
552 default:
Meng Wang15c825d2018-09-06 10:49:18 +0800553 dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530554 __func__, e->reg);
555 return -EINVAL;
556 }
Laxminath Kasam497a6512018-09-17 16:11:52 +0530557 if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530558 if (val != 0) {
Laxminath Kasam549d11d2019-07-18 13:44:17 +0530559 if (val < 5) {
Meng Wang15c825d2018-09-06 10:49:18 +0800560 snd_soc_component_update_bits(component,
561 mic_sel_reg,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530562 1 << 7, 0x0 << 7);
Laxminath Kasam549d11d2019-07-18 13:44:17 +0530563 } else {
Meng Wang15c825d2018-09-06 10:49:18 +0800564 snd_soc_component_update_bits(component,
565 mic_sel_reg,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530566 1 << 7, 0x1 << 7);
Laxminath Kasam549d11d2019-07-18 13:44:17 +0530567 snd_soc_component_update_bits(component,
568 BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
569 0x80, 0x00);
570 dmic_clk_reg =
571 BOLERO_CDC_TX_TOP_CSR_SWR_DMIC0_CTL +
572 ((val - 5)/2) * 4;
573 snd_soc_component_update_bits(component,
574 dmic_clk_reg,
575 0x0E, tx_priv->dmic_clk_div << 0x1);
576 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530577 }
578 } else {
579 /* DMIC selected */
580 if (val != 0)
Meng Wang15c825d2018-09-06 10:49:18 +0800581 snd_soc_component_update_bits(component, mic_sel_reg,
582 1 << 7, 1 << 7);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530583 }
584
585 return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
586}
587
588static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
589 struct snd_ctl_elem_value *ucontrol)
590{
591 struct snd_soc_dapm_widget *widget =
592 snd_soc_dapm_kcontrol_widget(kcontrol);
Meng Wang15c825d2018-09-06 10:49:18 +0800593 struct snd_soc_component *component =
594 snd_soc_dapm_to_component(widget->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530595 struct soc_multi_mixer_control *mixer =
596 ((struct soc_multi_mixer_control *)kcontrol->private_value);
597 u32 dai_id = widget->shift;
598 u32 dec_id = mixer->shift;
599 struct device *tx_dev = NULL;
600 struct tx_macro_priv *tx_priv = NULL;
601
Meng Wang15c825d2018-09-06 10:49:18 +0800602 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530603 return -EINVAL;
604
605 if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
606 ucontrol->value.integer.value[0] = 1;
607 else
608 ucontrol->value.integer.value[0] = 0;
609 return 0;
610}
611
612static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
614{
615 struct snd_soc_dapm_widget *widget =
616 snd_soc_dapm_kcontrol_widget(kcontrol);
Meng Wang15c825d2018-09-06 10:49:18 +0800617 struct snd_soc_component *component =
618 snd_soc_dapm_to_component(widget->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530619 struct snd_soc_dapm_update *update = NULL;
620 struct soc_multi_mixer_control *mixer =
621 ((struct soc_multi_mixer_control *)kcontrol->private_value);
622 u32 dai_id = widget->shift;
623 u32 dec_id = mixer->shift;
624 u32 enable = ucontrol->value.integer.value[0];
625 struct device *tx_dev = NULL;
626 struct tx_macro_priv *tx_priv = NULL;
627
Meng Wang15c825d2018-09-06 10:49:18 +0800628 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530629 return -EINVAL;
630
631 if (enable) {
632 set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
633 tx_priv->active_ch_cnt[dai_id]++;
634 } else {
635 tx_priv->active_ch_cnt[dai_id]--;
636 clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
637 }
638 snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
639
640 return 0;
641}
Karthikeyan Mani1dcd5a32019-08-22 14:37:13 -0700642
643static inline int tx_macro_path_get(const char *wname,
644 unsigned int *path_num)
645{
646 int ret = 0;
647 char *widget_name = NULL;
648 char *w_name = NULL;
649 char *path_num_char = NULL;
650 char *path_name = NULL;
651
652 widget_name = kstrndup(wname, 10, GFP_KERNEL);
653 if (!widget_name)
654 return -EINVAL;
655
656 w_name = widget_name;
657
658 path_name = strsep(&widget_name, " ");
659 if (!path_name) {
660 pr_err("%s: Invalid widget name = %s\n",
661 __func__, widget_name);
662 ret = -EINVAL;
663 goto err;
664 }
665 path_num_char = strpbrk(path_name, "01234567");
666 if (!path_num_char) {
667 pr_err("%s: tx path index not found\n",
668 __func__);
669 ret = -EINVAL;
670 goto err;
671 }
672 ret = kstrtouint(path_num_char, 10, path_num);
673 if (ret < 0)
674 pr_err("%s: Invalid tx path = %s\n",
675 __func__, w_name);
676
677err:
678 kfree(w_name);
679 return ret;
680}
681
682static int tx_macro_dec_mode_get(struct snd_kcontrol *kcontrol,
683 struct snd_ctl_elem_value *ucontrol)
684{
685 struct snd_soc_component *component =
686 snd_soc_kcontrol_component(kcontrol);
687 struct tx_macro_priv *tx_priv = NULL;
688 struct device *tx_dev = NULL;
689 int ret = 0;
690 int path = 0;
691
692 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
693 return -EINVAL;
694
695 ret = tx_macro_path_get(kcontrol->id.name, &path);
696 if (ret)
697 return ret;
698
699 ucontrol->value.integer.value[0] = tx_priv->dec_mode[path];
700
701 return 0;
702}
703
704static int tx_macro_dec_mode_put(struct snd_kcontrol *kcontrol,
705 struct snd_ctl_elem_value *ucontrol)
706{
707 struct snd_soc_component *component =
708 snd_soc_kcontrol_component(kcontrol);
709 struct tx_macro_priv *tx_priv = NULL;
710 struct device *tx_dev = NULL;
711 int value = ucontrol->value.integer.value[0];
712 int ret = 0;
713 int path = 0;
714
715 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
716 return -EINVAL;
717
718 ret = tx_macro_path_get(kcontrol->id.name, &path);
719 if (ret)
720 return ret;
721
722 tx_priv->dec_mode[path] = value;
723
724 return 0;
725}
726
Karthikeyan Mani765eaab2019-07-18 16:27:01 -0700727static int tx_macro_get_bcs(struct snd_kcontrol *kcontrol,
728 struct snd_ctl_elem_value *ucontrol)
729{
730 struct snd_soc_component *component =
731 snd_soc_kcontrol_component(kcontrol);
732 struct tx_macro_priv *tx_priv = NULL;
733 struct device *tx_dev = NULL;
734
735 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
736 return -EINVAL;
737
738 ucontrol->value.integer.value[0] = tx_priv->bcs_enable;
739
740 return 0;
741}
742
743static int tx_macro_set_bcs(struct snd_kcontrol *kcontrol,
744 struct snd_ctl_elem_value *ucontrol)
745{
746 struct snd_soc_component *component =
747 snd_soc_kcontrol_component(kcontrol);
748 struct tx_macro_priv *tx_priv = NULL;
749 struct device *tx_dev = NULL;
750 int value = ucontrol->value.integer.value[0];
751
752 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
753 return -EINVAL;
754
755 tx_priv->bcs_enable = value;
756
757 return 0;
758}
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530759
760static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
761 struct snd_kcontrol *kcontrol, int event)
762{
Meng Wang15c825d2018-09-06 10:49:18 +0800763 struct snd_soc_component *component =
764 snd_soc_dapm_to_component(w->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530765 unsigned int dmic = 0;
766 int ret = 0;
767 char *wname = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530768
769 wname = strpbrk(w->name, "01234567");
770 if (!wname) {
Meng Wang15c825d2018-09-06 10:49:18 +0800771 dev_err(component->dev, "%s: widget not found\n", __func__);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530772 return -EINVAL;
773 }
774
775 ret = kstrtouint(wname, 10, &dmic);
776 if (ret < 0) {
Meng Wang15c825d2018-09-06 10:49:18 +0800777 dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530778 __func__);
779 return -EINVAL;
780 }
781
Sudheer Papothid50a5812019-11-21 07:24:42 +0530782 dev_dbg(component->dev, "%s: event %d DMIC%d\n",
783 __func__, event, dmic);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530784
785 switch (event) {
786 case SND_SOC_DAPM_PRE_PMU:
Sudheer Papothid50a5812019-11-21 07:24:42 +0530787 bolero_dmic_clk_enable(component, dmic, DMIC_TX, true);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530788 break;
789 case SND_SOC_DAPM_POST_PMD:
Sudheer Papothid50a5812019-11-21 07:24:42 +0530790 bolero_dmic_clk_enable(component, dmic, DMIC_TX, false);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530791 break;
792 }
793
794 return 0;
795}
796
797static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
798 struct snd_kcontrol *kcontrol, int event)
799{
Meng Wang15c825d2018-09-06 10:49:18 +0800800 struct snd_soc_component *component =
801 snd_soc_dapm_to_component(w->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530802 unsigned int decimator = 0;
803 u16 tx_vol_ctl_reg = 0;
804 u16 dec_cfg_reg = 0;
805 u16 hpf_gate_reg = 0;
806 u16 tx_gain_ctl_reg = 0;
807 u8 hpf_cut_off_freq = 0;
808 struct device *tx_dev = NULL;
809 struct tx_macro_priv *tx_priv = NULL;
810
Meng Wang15c825d2018-09-06 10:49:18 +0800811 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530812 return -EINVAL;
813
814 decimator = w->shift;
815
Meng Wang15c825d2018-09-06 10:49:18 +0800816 dev_dbg(component->dev, "%s(): widget = %s decimator = %u\n", __func__,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530817 w->name, decimator);
818
819 tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
820 TX_MACRO_TX_PATH_OFFSET * decimator;
821 hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
822 TX_MACRO_TX_PATH_OFFSET * decimator;
823 dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
824 TX_MACRO_TX_PATH_OFFSET * decimator;
825 tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
826 TX_MACRO_TX_PATH_OFFSET * decimator;
827
828 switch (event) {
829 case SND_SOC_DAPM_PRE_PMU:
Karthikeyan Mani1dcd5a32019-08-22 14:37:13 -0700830 snd_soc_component_update_bits(component,
831 dec_cfg_reg, 0x06, tx_priv->dec_mode[decimator] <<
832 TX_MACRO_ADC_MODE_CFG0_SHIFT);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530833 /* Enable TX PGA Mute */
Meng Wang15c825d2018-09-06 10:49:18 +0800834 snd_soc_component_update_bits(component,
835 tx_vol_ctl_reg, 0x10, 0x10);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530836 break;
837 case SND_SOC_DAPM_POST_PMU:
Meng Wang15c825d2018-09-06 10:49:18 +0800838 snd_soc_component_update_bits(component,
839 tx_vol_ctl_reg, 0x20, 0x20);
840 snd_soc_component_update_bits(component,
841 hpf_gate_reg, 0x01, 0x00);
Karthikeyan Mani144659b2019-10-02 17:29:57 -0700842 /*
843 * Minimum 1 clk cycle delay is required as per HW spec
844 */
845 usleep_range(1000, 1010);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530846
Meng Wang15c825d2018-09-06 10:49:18 +0800847 hpf_cut_off_freq = (
848 snd_soc_component_read32(component, dec_cfg_reg) &
849 TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
850
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530851 tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
Meng Wang15c825d2018-09-06 10:49:18 +0800852 hpf_cut_off_freq;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530853
854 if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
Meng Wang15c825d2018-09-06 10:49:18 +0800855 snd_soc_component_update_bits(component, dec_cfg_reg,
856 TX_HPF_CUT_OFF_FREQ_MASK,
857 CF_MIN_3DB_150HZ << 5);
858
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530859 /* schedule work queue to Remove Mute */
860 schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork,
861 msecs_to_jiffies(tx_unmute_delay));
862 if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530863 CF_MIN_3DB_150HZ) {
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530864 schedule_delayed_work(
865 &tx_priv->tx_hpf_work[decimator].dwork,
Karthikeyan Mani6bd895e2019-07-26 15:34:50 -0700866 msecs_to_jiffies(300));
Meng Wang15c825d2018-09-06 10:49:18 +0800867 snd_soc_component_update_bits(component,
Karthikeyan Mani144659b2019-10-02 17:29:57 -0700868 hpf_gate_reg, 0x03, 0x03);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530869 /*
870 * Minimum 1 clk cycle delay is required as per HW spec
871 */
872 usleep_range(1000, 1010);
Meng Wang15c825d2018-09-06 10:49:18 +0800873 snd_soc_component_update_bits(component,
874 hpf_gate_reg, 0x02, 0x00);
Karthikeyan Mani9366ce62019-11-06 11:43:36 -0800875 snd_soc_component_update_bits(component,
876 hpf_gate_reg, 0x01, 0x01);
877 /*
878 * 6ms delay is required as per HW spec
879 */
880 usleep_range(6000, 6010);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530881 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530882 /* apply gain after decimator is enabled */
Meng Wang15c825d2018-09-06 10:49:18 +0800883 snd_soc_component_write(component, tx_gain_ctl_reg,
884 snd_soc_component_read32(component,
885 tx_gain_ctl_reg));
Karthikeyan Mani765eaab2019-07-18 16:27:01 -0700886 if (tx_priv->bcs_enable) {
887 snd_soc_component_update_bits(component, dec_cfg_reg,
888 0x01, 0x01);
Vatsal Buchad06525f2019-10-14 23:14:12 +0530889 tx_priv->bcs_clk_en = true;
890 if (tx_priv->hs_slow_insert_complete)
891 snd_soc_component_update_bits(component,
892 BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40,
893 0x40);
Karthikeyan Mani765eaab2019-07-18 16:27:01 -0700894 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530895 break;
896 case SND_SOC_DAPM_PRE_PMD:
897 hpf_cut_off_freq =
898 tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
Meng Wang15c825d2018-09-06 10:49:18 +0800899 snd_soc_component_update_bits(component,
900 tx_vol_ctl_reg, 0x10, 0x10);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530901 if (cancel_delayed_work_sync(
902 &tx_priv->tx_hpf_work[decimator].dwork)) {
903 if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
Meng Wang15c825d2018-09-06 10:49:18 +0800904 snd_soc_component_update_bits(
905 component, dec_cfg_reg,
906 TX_HPF_CUT_OFF_FREQ_MASK,
907 hpf_cut_off_freq << 5);
908 snd_soc_component_update_bits(component,
909 hpf_gate_reg,
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530910 0x02, 0x02);
911 /*
912 * Minimum 1 clk cycle delay is required
913 * as per HW spec
914 */
915 usleep_range(1000, 1010);
Meng Wang15c825d2018-09-06 10:49:18 +0800916 snd_soc_component_update_bits(component,
917 hpf_gate_reg,
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530918 0x02, 0x00);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530919 }
920 }
921 cancel_delayed_work_sync(
922 &tx_priv->tx_mute_dwork[decimator].dwork);
923 break;
924 case SND_SOC_DAPM_POST_PMD:
Meng Wang15c825d2018-09-06 10:49:18 +0800925 snd_soc_component_update_bits(component, tx_vol_ctl_reg,
926 0x20, 0x00);
Karthikeyan Mani1dcd5a32019-08-22 14:37:13 -0700927 snd_soc_component_update_bits(component,
928 dec_cfg_reg, 0x06, 0x00);
Meng Wang15c825d2018-09-06 10:49:18 +0800929 snd_soc_component_update_bits(component, tx_vol_ctl_reg,
930 0x10, 0x00);
Karthikeyan Mani765eaab2019-07-18 16:27:01 -0700931 if (tx_priv->bcs_enable) {
932 snd_soc_component_update_bits(component, dec_cfg_reg,
933 0x01, 0x00);
934 snd_soc_component_update_bits(component,
935 BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, 0x00);
Vatsal Buchad06525f2019-10-14 23:14:12 +0530936 tx_priv->bcs_clk_en = false;
Karthikeyan Mani765eaab2019-07-18 16:27:01 -0700937 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530938 break;
939 }
940 return 0;
941}
942
943static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
944 struct snd_kcontrol *kcontrol, int event)
945{
946 return 0;
947}
948
949static int tx_macro_hw_params(struct snd_pcm_substream *substream,
950 struct snd_pcm_hw_params *params,
951 struct snd_soc_dai *dai)
952{
953 int tx_fs_rate = -EINVAL;
Meng Wang15c825d2018-09-06 10:49:18 +0800954 struct snd_soc_component *component = dai->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530955 u32 decimator = 0;
Laxminath Kasamb7f823c2018-08-02 13:23:11 +0530956 u32 sample_rate = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530957 u16 tx_fs_reg = 0;
958 struct device *tx_dev = NULL;
959 struct tx_macro_priv *tx_priv = NULL;
960
Meng Wang15c825d2018-09-06 10:49:18 +0800961 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530962 return -EINVAL;
963
964 pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
965 dai->name, dai->id, params_rate(params),
966 params_channels(params));
967
968 sample_rate = params_rate(params);
969 switch (sample_rate) {
970 case 8000:
971 tx_fs_rate = 0;
972 break;
973 case 16000:
974 tx_fs_rate = 1;
975 break;
976 case 32000:
977 tx_fs_rate = 3;
978 break;
979 case 48000:
980 tx_fs_rate = 4;
981 break;
982 case 96000:
983 tx_fs_rate = 5;
984 break;
985 case 192000:
986 tx_fs_rate = 6;
987 break;
988 case 384000:
989 tx_fs_rate = 7;
990 break;
991 default:
Meng Wang15c825d2018-09-06 10:49:18 +0800992 dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530993 __func__, params_rate(params));
994 return -EINVAL;
995 }
996 for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
997 TX_MACRO_DEC_MAX) {
998 if (decimator >= 0) {
999 tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
1000 TX_MACRO_TX_PATH_OFFSET * decimator;
Meng Wang15c825d2018-09-06 10:49:18 +08001001 dev_dbg(component->dev, "%s: set DEC%u rate to %u\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301002 __func__, decimator, sample_rate);
Meng Wang15c825d2018-09-06 10:49:18 +08001003 snd_soc_component_update_bits(component, tx_fs_reg,
1004 0x0F, tx_fs_rate);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301005 } else {
Meng Wang15c825d2018-09-06 10:49:18 +08001006 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301007 "%s: ERROR: Invalid decimator: %d\n",
1008 __func__, decimator);
1009 return -EINVAL;
1010 }
1011 }
1012 return 0;
1013}
1014
1015static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
1016 unsigned int *tx_num, unsigned int *tx_slot,
1017 unsigned int *rx_num, unsigned int *rx_slot)
1018{
Meng Wang15c825d2018-09-06 10:49:18 +08001019 struct snd_soc_component *component = dai->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301020 struct device *tx_dev = NULL;
1021 struct tx_macro_priv *tx_priv = NULL;
1022
Meng Wang15c825d2018-09-06 10:49:18 +08001023 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301024 return -EINVAL;
1025
1026 switch (dai->id) {
1027 case TX_MACRO_AIF1_CAP:
1028 case TX_MACRO_AIF2_CAP:
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001029 case TX_MACRO_AIF3_CAP:
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301030 *tx_slot = tx_priv->active_ch_mask[dai->id];
1031 *tx_num = tx_priv->active_ch_cnt[dai->id];
1032 break;
1033 default:
1034 dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
1035 break;
1036 }
1037 return 0;
1038}
1039
1040static struct snd_soc_dai_ops tx_macro_dai_ops = {
1041 .hw_params = tx_macro_hw_params,
1042 .get_channel_map = tx_macro_get_channel_map,
1043};
1044
1045static struct snd_soc_dai_driver tx_macro_dai[] = {
1046 {
1047 .name = "tx_macro_tx1",
1048 .id = TX_MACRO_AIF1_CAP,
1049 .capture = {
1050 .stream_name = "TX_AIF1 Capture",
1051 .rates = TX_MACRO_RATES,
1052 .formats = TX_MACRO_FORMATS,
1053 .rate_max = 192000,
1054 .rate_min = 8000,
1055 .channels_min = 1,
1056 .channels_max = 8,
1057 },
1058 .ops = &tx_macro_dai_ops,
1059 },
1060 {
1061 .name = "tx_macro_tx2",
1062 .id = TX_MACRO_AIF2_CAP,
1063 .capture = {
1064 .stream_name = "TX_AIF2 Capture",
1065 .rates = TX_MACRO_RATES,
1066 .formats = TX_MACRO_FORMATS,
1067 .rate_max = 192000,
1068 .rate_min = 8000,
1069 .channels_min = 1,
1070 .channels_max = 8,
1071 },
1072 .ops = &tx_macro_dai_ops,
1073 },
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001074 {
1075 .name = "tx_macro_tx3",
1076 .id = TX_MACRO_AIF3_CAP,
1077 .capture = {
1078 .stream_name = "TX_AIF3 Capture",
1079 .rates = TX_MACRO_RATES,
1080 .formats = TX_MACRO_FORMATS,
1081 .rate_max = 192000,
1082 .rate_min = 8000,
1083 .channels_min = 1,
1084 .channels_max = 8,
1085 },
1086 .ops = &tx_macro_dai_ops,
1087 },
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301088};
1089
1090#define STRING(name) #name
1091#define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
1092static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
1093static const struct snd_kcontrol_new name##_mux = \
1094 SOC_DAPM_ENUM(STRING(name), name##_enum)
1095
1096#define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
1097static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
1098static const struct snd_kcontrol_new name##_mux = \
1099 SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
1100
1101#define TX_MACRO_DAPM_MUX(name, shift, kctl) \
1102 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
1103
1104static const char * const adc_mux_text[] = {
1105 "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
1106};
1107
1108TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
1109 0, adc_mux_text);
1110TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
1111 0, adc_mux_text);
1112TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
1113 0, adc_mux_text);
1114TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
1115 0, adc_mux_text);
1116TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
1117 0, adc_mux_text);
1118TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
1119 0, adc_mux_text);
1120TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
1121 0, adc_mux_text);
1122TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
1123 0, adc_mux_text);
1124
1125
1126static const char * const dmic_mux_text[] = {
1127 "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
1128 "DMIC4", "DMIC5", "DMIC6", "DMIC7"
1129};
1130
1131TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
1132 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1133 tx_macro_put_dec_enum);
1134
1135TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
1136 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1137 tx_macro_put_dec_enum);
1138
1139TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
1140 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1141 tx_macro_put_dec_enum);
1142
1143TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
1144 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1145 tx_macro_put_dec_enum);
1146
1147TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
1148 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1149 tx_macro_put_dec_enum);
1150
1151TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
1152 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1153 tx_macro_put_dec_enum);
1154
1155TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
1156 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1157 tx_macro_put_dec_enum);
1158
1159TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
1160 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
1161 tx_macro_put_dec_enum);
1162
1163static const char * const smic_mux_text[] = {
Sudheer Papothi324b4952019-06-11 04:14:51 +05301164 "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0",
1165 "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4",
1166 "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301167};
1168
1169TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
1170 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1171 tx_macro_put_dec_enum);
1172
1173TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
1174 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1175 tx_macro_put_dec_enum);
1176
1177TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
1178 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1179 tx_macro_put_dec_enum);
1180
1181TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
1182 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1183 tx_macro_put_dec_enum);
1184
1185TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
1186 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1187 tx_macro_put_dec_enum);
1188
1189TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
1190 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1191 tx_macro_put_dec_enum);
1192
1193TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
1194 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1195 tx_macro_put_dec_enum);
1196
1197TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
1198 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1199 tx_macro_put_dec_enum);
1200
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05301201static const char * const smic_mux_text_v2[] = {
1202 "ZERO", "SWR_MIC0", "SWR_MIC1", "SWR_MIC2", "SWR_MIC3",
1203 "SWR_MIC4", "SWR_MIC5", "SWR_MIC6", "SWR_MIC7",
1204 "SWR_MIC8", "SWR_MIC9", "SWR_MIC10", "SWR_MIC11"
1205};
1206
1207TX_MACRO_DAPM_ENUM_EXT(tx_smic0_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
1208 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1209 tx_macro_put_dec_enum);
1210
1211TX_MACRO_DAPM_ENUM_EXT(tx_smic1_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
1212 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1213 tx_macro_put_dec_enum);
1214
1215TX_MACRO_DAPM_ENUM_EXT(tx_smic2_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
1216 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1217 tx_macro_put_dec_enum);
1218
1219TX_MACRO_DAPM_ENUM_EXT(tx_smic3_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
1220 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1221 tx_macro_put_dec_enum);
1222
1223TX_MACRO_DAPM_ENUM_EXT(tx_smic4_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
1224 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1225 tx_macro_put_dec_enum);
1226
1227TX_MACRO_DAPM_ENUM_EXT(tx_smic5_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
1228 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1229 tx_macro_put_dec_enum);
1230
1231TX_MACRO_DAPM_ENUM_EXT(tx_smic6_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
1232 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1233 tx_macro_put_dec_enum);
1234
1235TX_MACRO_DAPM_ENUM_EXT(tx_smic7_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
1236 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
1237 tx_macro_put_dec_enum);
1238
Karthikeyan Mani1dcd5a32019-08-22 14:37:13 -07001239static const char * const dec_mode_mux_text[] = {
1240 "ADC_DEFAULT", "ADC_LOW_PWR", "ADC_HIGH_PERF",
1241};
1242
1243static const struct soc_enum dec_mode_mux_enum =
1244 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dec_mode_mux_text),
1245 dec_mode_mux_text);
1246
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301247static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
1248 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1249 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1250 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1251 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1252 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1253 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1254 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1255 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1256 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1257 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1258 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1259 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1260 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1261 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1262 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1263 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1264};
1265
1266static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
1267 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1268 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1269 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1270 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1271 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1272 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1273 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1274 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1275 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1276 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1277 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1278 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1279 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1280 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1281 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1282 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1283};
1284
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001285static const struct snd_kcontrol_new tx_aif3_cap_mixer[] = {
1286 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1287 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1288 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1289 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1290 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1291 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1292 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1293 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1294 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1295 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1296 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1297 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1298 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1299 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1300 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1301 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1302};
1303
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05301304static const struct snd_kcontrol_new tx_aif1_cap_mixer_v2[] = {
1305 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1306 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1307 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1308 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1309 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1310 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1311 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1312 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1313};
1314
1315static const struct snd_kcontrol_new tx_aif2_cap_mixer_v2[] = {
1316 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1317 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1318 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1319 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1320 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1321 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1322 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1323 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1324};
1325
1326static const struct snd_kcontrol_new tx_aif3_cap_mixer_v2[] = {
1327 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1328 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1329 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1330 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1331 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1332 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1333 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1334 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1335};
1336
1337static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_common[] = {
1338 SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
1339 SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
1340
1341 SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
1342 SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
1343
1344 SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
1345 SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
1346
1347 TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
1348 TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
1349 TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
1350 TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
1351
1352 TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0_v2),
1353 TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1_v2),
1354 TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2_v2),
1355 TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3_v2),
1356
1357 SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
1358 tx_macro_enable_micbias,
1359 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1360 SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
1361 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1362 SND_SOC_DAPM_POST_PMD),
1363
1364 SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
1365 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1366 SND_SOC_DAPM_POST_PMD),
1367
1368 SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
1369 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1370 SND_SOC_DAPM_POST_PMD),
1371
1372 SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
1373 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1374 SND_SOC_DAPM_POST_PMD),
1375
1376 SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
1377 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1378 SND_SOC_DAPM_POST_PMD),
1379
1380 SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
1381 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1382 SND_SOC_DAPM_POST_PMD),
1383
1384 SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
1385 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1386 SND_SOC_DAPM_POST_PMD),
1387
1388 SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
1389 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1390 SND_SOC_DAPM_POST_PMD),
1391
1392 SND_SOC_DAPM_INPUT("TX SWR_MIC0"),
1393 SND_SOC_DAPM_INPUT("TX SWR_MIC1"),
1394 SND_SOC_DAPM_INPUT("TX SWR_MIC2"),
1395 SND_SOC_DAPM_INPUT("TX SWR_MIC3"),
1396 SND_SOC_DAPM_INPUT("TX SWR_MIC4"),
1397 SND_SOC_DAPM_INPUT("TX SWR_MIC5"),
1398 SND_SOC_DAPM_INPUT("TX SWR_MIC6"),
1399 SND_SOC_DAPM_INPUT("TX SWR_MIC7"),
1400 SND_SOC_DAPM_INPUT("TX SWR_MIC8"),
1401 SND_SOC_DAPM_INPUT("TX SWR_MIC9"),
1402 SND_SOC_DAPM_INPUT("TX SWR_MIC10"),
1403 SND_SOC_DAPM_INPUT("TX SWR_MIC11"),
1404
1405 SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
1406 TX_MACRO_DEC0, 0,
1407 &tx_dec0_mux, tx_macro_enable_dec,
1408 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1409 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1410
1411 SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
1412 TX_MACRO_DEC1, 0,
1413 &tx_dec1_mux, tx_macro_enable_dec,
1414 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1415 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1416
1417 SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
1418 TX_MACRO_DEC2, 0,
1419 &tx_dec2_mux, tx_macro_enable_dec,
1420 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1421 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1422
1423 SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
1424 TX_MACRO_DEC3, 0,
1425 &tx_dec3_mux, tx_macro_enable_dec,
1426 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1427 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1428
1429 SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
1430 tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1431};
1432
1433static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v2[] = {
1434 SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
1435 TX_MACRO_AIF1_CAP, 0,
1436 tx_aif1_cap_mixer_v2, ARRAY_SIZE(tx_aif1_cap_mixer_v2)),
1437
1438 SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
1439 TX_MACRO_AIF2_CAP, 0,
1440 tx_aif2_cap_mixer_v2, ARRAY_SIZE(tx_aif2_cap_mixer_v2)),
1441
1442 SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
1443 TX_MACRO_AIF3_CAP, 0,
1444 tx_aif3_cap_mixer_v2, ARRAY_SIZE(tx_aif3_cap_mixer_v2)),
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05301445};
1446
1447static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v3[] = {
1448 SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
1449 TX_MACRO_AIF1_CAP, 0,
1450 tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
1451
1452 SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
1453 TX_MACRO_AIF2_CAP, 0,
1454 tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
1455
1456 SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
1457 TX_MACRO_AIF3_CAP, 0,
1458 tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
1459
1460 TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
1461 TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
1462 TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
1463 TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
1464
1465 TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4_v3),
1466 TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5_v3),
1467 TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6_v3),
1468 TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7_v3),
1469
1470 SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
1471 TX_MACRO_DEC4, 0,
1472 &tx_dec4_mux, tx_macro_enable_dec,
1473 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1474 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1475
1476 SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
1477 TX_MACRO_DEC5, 0,
1478 &tx_dec5_mux, tx_macro_enable_dec,
1479 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1480 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1481
1482 SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
1483 TX_MACRO_DEC6, 0,
1484 &tx_dec6_mux, tx_macro_enable_dec,
1485 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1486 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1487
1488 SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
1489 TX_MACRO_DEC7, 0,
1490 &tx_dec7_mux, tx_macro_enable_dec,
1491 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1492 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1493
Laxminath Kasamb03e82d2019-11-05 13:35:01 +05301494 SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
1495 tx_macro_tx_swr_clk_event,
1496 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1497
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05301498 SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
1499 tx_macro_va_swr_clk_event,
1500 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1501};
1502
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301503static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
1504 SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
1505 SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
1506
1507 SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
1508 SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
1509
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001510 SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
1511 SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
1512
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301513 SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
1514 tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
1515
1516 SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
1517 tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
1518
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001519 SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0,
1520 tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
1521
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301522
1523 TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
1524 TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
1525 TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
1526 TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
1527 TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
1528 TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
1529 TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
1530 TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
1531
1532 TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
1533 TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
1534 TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
1535 TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
1536 TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
1537 TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
1538 TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
1539 TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
1540
1541 SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
1542 tx_macro_enable_micbias,
1543 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1544 SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
1545 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1546 SND_SOC_DAPM_POST_PMD),
1547
1548 SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
1549 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1550 SND_SOC_DAPM_POST_PMD),
1551
1552 SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
1553 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1554 SND_SOC_DAPM_POST_PMD),
1555
1556 SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
1557 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1558 SND_SOC_DAPM_POST_PMD),
1559
1560 SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
1561 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1562 SND_SOC_DAPM_POST_PMD),
1563
1564 SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
1565 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1566 SND_SOC_DAPM_POST_PMD),
1567
1568 SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
1569 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1570 SND_SOC_DAPM_POST_PMD),
1571
1572 SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
1573 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1574 SND_SOC_DAPM_POST_PMD),
1575
1576 SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
1577 SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
1578 SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
1579 SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
1580 SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
1581 SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
1582 SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
1583 SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
1584 SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
1585 SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
1586 SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
1587 SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
1588
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301589 SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301590 TX_MACRO_DEC0, 0,
1591 &tx_dec0_mux, tx_macro_enable_dec,
1592 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1593 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1594
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301595 SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301596 TX_MACRO_DEC1, 0,
1597 &tx_dec1_mux, tx_macro_enable_dec,
1598 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1599 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1600
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301601 SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301602 TX_MACRO_DEC2, 0,
1603 &tx_dec2_mux, tx_macro_enable_dec,
1604 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1605 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1606
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301607 SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301608 TX_MACRO_DEC3, 0,
1609 &tx_dec3_mux, tx_macro_enable_dec,
1610 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1611 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1612
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301613 SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301614 TX_MACRO_DEC4, 0,
1615 &tx_dec4_mux, tx_macro_enable_dec,
1616 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1617 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1618
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301619 SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301620 TX_MACRO_DEC5, 0,
1621 &tx_dec5_mux, tx_macro_enable_dec,
1622 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1623 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1624
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301625 SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301626 TX_MACRO_DEC6, 0,
1627 &tx_dec6_mux, tx_macro_enable_dec,
1628 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1629 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1630
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301631 SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301632 TX_MACRO_DEC7, 0,
1633 &tx_dec7_mux, tx_macro_enable_dec,
1634 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1635 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1636
1637 SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
1638 tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301639
1640 SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
1641 tx_macro_tx_swr_clk_event,
1642 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1643
1644 SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
1645 tx_macro_va_swr_clk_event,
1646 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301647};
1648
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05301649static const struct snd_soc_dapm_route tx_audio_map_common[] = {
1650 {"TX_AIF1 CAP", NULL, "TX_MCLK"},
1651 {"TX_AIF2 CAP", NULL, "TX_MCLK"},
1652 {"TX_AIF3 CAP", NULL, "TX_MCLK"},
1653
1654 {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
1655 {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
1656 {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
1657
1658 {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1659 {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1660 {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1661 {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1662
1663 {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1664 {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1665 {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1666 {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1667
1668 {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1669 {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1670 {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1671 {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1672
1673 {"TX DEC0 MUX", NULL, "TX_MCLK"},
1674 {"TX DEC1 MUX", NULL, "TX_MCLK"},
1675 {"TX DEC2 MUX", NULL, "TX_MCLK"},
1676 {"TX DEC3 MUX", NULL, "TX_MCLK"},
1677
1678 {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
1679 {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
1680 {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
1681 {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
1682 {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
1683 {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
1684 {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
1685 {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
1686 {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
1687
1688 {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
1689 {"TX SMIC MUX0", "SWR_MIC0", "TX SWR_MIC0"},
1690 {"TX SMIC MUX0", "SWR_MIC1", "TX SWR_MIC1"},
1691 {"TX SMIC MUX0", "SWR_MIC2", "TX SWR_MIC2"},
1692 {"TX SMIC MUX0", "SWR_MIC3", "TX SWR_MIC3"},
1693 {"TX SMIC MUX0", "SWR_MIC4", "TX SWR_MIC4"},
1694 {"TX SMIC MUX0", "SWR_MIC5", "TX SWR_MIC5"},
1695 {"TX SMIC MUX0", "SWR_MIC6", "TX SWR_MIC6"},
1696 {"TX SMIC MUX0", "SWR_MIC7", "TX SWR_MIC7"},
1697 {"TX SMIC MUX0", "SWR_MIC8", "TX SWR_MIC8"},
1698 {"TX SMIC MUX0", "SWR_MIC9", "TX SWR_MIC9"},
1699 {"TX SMIC MUX0", "SWR_MIC10", "TX SWR_MIC10"},
1700 {"TX SMIC MUX0", "SWR_MIC11", "TX SWR_MIC11"},
1701
1702 {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
1703 {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
1704 {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
1705 {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
1706 {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
1707 {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
1708 {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
1709 {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
1710 {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
1711
1712 {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
1713 {"TX SMIC MUX1", "SWR_MIC0", "TX SWR_MIC0"},
1714 {"TX SMIC MUX1", "SWR_MIC1", "TX SWR_MIC1"},
1715 {"TX SMIC MUX1", "SWR_MIC2", "TX SWR_MIC2"},
1716 {"TX SMIC MUX1", "SWR_MIC3", "TX SWR_MIC3"},
1717 {"TX SMIC MUX1", "SWR_MIC4", "TX SWR_MIC4"},
1718 {"TX SMIC MUX1", "SWR_MIC5", "TX SWR_MIC5"},
1719 {"TX SMIC MUX1", "SWR_MIC6", "TX SWR_MIC6"},
1720 {"TX SMIC MUX1", "SWR_MIC7", "TX SWR_MIC7"},
1721 {"TX SMIC MUX1", "SWR_MIC8", "TX SWR_MIC8"},
1722 {"TX SMIC MUX1", "SWR_MIC9", "TX SWR_MIC9"},
1723 {"TX SMIC MUX1", "SWR_MIC10", "TX SWR_MIC10"},
1724 {"TX SMIC MUX1", "SWR_MIC11", "TX SWR_MIC11"},
1725
1726 {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
1727 {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
1728 {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
1729 {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
1730 {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
1731 {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
1732 {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
1733 {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
1734 {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
1735
1736 {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
1737 {"TX SMIC MUX2", "SWR_MIC0", "TX SWR_MIC0"},
1738 {"TX SMIC MUX2", "SWR_MIC1", "TX SWR_MIC1"},
1739 {"TX SMIC MUX2", "SWR_MIC2", "TX SWR_MIC2"},
1740 {"TX SMIC MUX2", "SWR_MIC3", "TX SWR_MIC3"},
1741 {"TX SMIC MUX2", "SWR_MIC4", "TX SWR_MIC4"},
1742 {"TX SMIC MUX2", "SWR_MIC5", "TX SWR_MIC5"},
1743 {"TX SMIC MUX2", "SWR_MIC6", "TX SWR_MIC6"},
1744 {"TX SMIC MUX2", "SWR_MIC7", "TX SWR_MIC7"},
1745 {"TX SMIC MUX2", "SWR_MIC8", "TX SWR_MIC8"},
1746 {"TX SMIC MUX2", "SWR_MIC9", "TX SWR_MIC9"},
1747 {"TX SMIC MUX2", "SWR_MIC10", "TX SWR_MIC10"},
1748 {"TX SMIC MUX2", "SWR_MIC11", "TX SWR_MIC11"},
1749
1750 {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
1751 {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
1752 {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
1753 {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
1754 {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
1755 {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
1756 {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
1757 {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
1758 {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
1759
1760 {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
1761 {"TX SMIC MUX3", "SWR_MIC0", "TX SWR_MIC0"},
1762 {"TX SMIC MUX3", "SWR_MIC1", "TX SWR_MIC1"},
1763 {"TX SMIC MUX3", "SWR_MIC2", "TX SWR_MIC2"},
1764 {"TX SMIC MUX3", "SWR_MIC3", "TX SWR_MIC3"},
1765 {"TX SMIC MUX3", "SWR_MIC4", "TX SWR_MIC4"},
1766 {"TX SMIC MUX3", "SWR_MIC5", "TX SWR_MIC5"},
1767 {"TX SMIC MUX3", "SWR_MIC6", "TX SWR_MIC6"},
1768 {"TX SMIC MUX3", "SWR_MIC7", "TX SWR_MIC7"},
1769 {"TX SMIC MUX3", "SWR_MIC8", "TX SWR_MIC8"},
1770 {"TX SMIC MUX3", "SWR_MIC9", "TX SWR_MIC9"},
1771 {"TX SMIC MUX3", "SWR_MIC10", "TX SWR_MIC10"},
1772 {"TX SMIC MUX3", "SWR_MIC11", "TX SWR_MIC11"},
1773};
1774
1775static const struct snd_soc_dapm_route tx_audio_map_v3[] = {
1776 {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1777 {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1778 {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1779 {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1780
1781 {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1782 {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1783 {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1784 {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1785
1786 {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1787 {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1788 {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1789 {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1790
1791 {"TX DEC4 MUX", NULL, "TX_MCLK"},
1792 {"TX DEC5 MUX", NULL, "TX_MCLK"},
1793 {"TX DEC6 MUX", NULL, "TX_MCLK"},
1794 {"TX DEC7 MUX", NULL, "TX_MCLK"},
1795
1796 {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
1797 {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
1798 {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
1799 {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
1800 {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
1801 {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
1802 {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
1803 {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
1804 {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
1805
1806 {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
1807 {"TX SMIC MUX4", "SWR_MIC0", "TX SWR_MIC0"},
1808 {"TX SMIC MUX4", "SWR_MIC1", "TX SWR_MIC1"},
1809 {"TX SMIC MUX4", "SWR_MIC2", "TX SWR_MIC2"},
1810 {"TX SMIC MUX4", "SWR_MIC3", "TX SWR_MIC3"},
1811 {"TX SMIC MUX4", "SWR_MIC4", "TX SWR_MIC4"},
1812 {"TX SMIC MUX4", "SWR_MIC5", "TX SWR_MIC5"},
1813 {"TX SMIC MUX4", "SWR_MIC6", "TX SWR_MIC6"},
1814 {"TX SMIC MUX4", "SWR_MIC7", "TX SWR_MIC7"},
1815 {"TX SMIC MUX4", "SWR_MIC8", "TX SWR_MIC8"},
1816 {"TX SMIC MUX4", "SWR_MIC9", "TX SWR_MIC9"},
1817 {"TX SMIC MUX4", "SWR_MIC10", "TX SWR_MIC10"},
1818 {"TX SMIC MUX4", "SWR_MIC11", "TX SWR_MIC11"},
1819
1820 {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
1821 {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
1822 {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
1823 {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
1824 {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
1825 {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
1826 {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
1827 {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
1828 {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
1829
1830 {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
1831 {"TX SMIC MUX5", "SWR_MIC0", "TX SWR_MIC0"},
1832 {"TX SMIC MUX5", "SWR_MIC1", "TX SWR_MIC1"},
1833 {"TX SMIC MUX5", "SWR_MIC2", "TX SWR_MIC2"},
1834 {"TX SMIC MUX5", "SWR_MIC3", "TX SWR_MIC3"},
1835 {"TX SMIC MUX5", "SWR_MIC4", "TX SWR_MIC4"},
1836 {"TX SMIC MUX5", "SWR_MIC5", "TX SWR_MIC5"},
1837 {"TX SMIC MUX5", "SWR_MIC6", "TX SWR_MIC6"},
1838 {"TX SMIC MUX5", "SWR_MIC7", "TX SWR_MIC7"},
1839 {"TX SMIC MUX5", "SWR_MIC8", "TX SWR_MIC8"},
1840 {"TX SMIC MUX5", "SWR_MIC9", "TX SWR_MIC9"},
1841 {"TX SMIC MUX5", "SWR_MIC10", "TX SWR_MIC10"},
1842 {"TX SMIC MUX5", "SWR_MIC11", "TX SWR_MIC11"},
1843
1844 {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
1845 {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
1846 {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
1847 {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
1848 {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
1849 {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
1850 {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
1851 {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
1852 {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
1853
1854 {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
1855 {"TX SMIC MUX6", "SWR_MIC0", "TX SWR_MIC0"},
1856 {"TX SMIC MUX6", "SWR_MIC1", "TX SWR_MIC1"},
1857 {"TX SMIC MUX6", "SWR_MIC2", "TX SWR_MIC2"},
1858 {"TX SMIC MUX6", "SWR_MIC3", "TX SWR_MIC3"},
1859 {"TX SMIC MUX6", "SWR_MIC4", "TX SWR_MIC4"},
1860 {"TX SMIC MUX6", "SWR_MIC5", "TX SWR_MIC5"},
1861 {"TX SMIC MUX6", "SWR_MIC6", "TX SWR_MIC6"},
1862 {"TX SMIC MUX6", "SWR_MIC7", "TX SWR_MIC7"},
1863 {"TX SMIC MUX6", "SWR_MIC8", "TX SWR_MIC8"},
1864 {"TX SMIC MUX6", "SWR_MIC9", "TX SWR_MIC9"},
1865 {"TX SMIC MUX6", "SWR_MIC10", "TX SWR_MIC10"},
1866 {"TX SMIC MUX6", "SWR_MIC11", "TX SWR_MIC11"},
1867
1868 {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
1869 {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
1870 {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
1871 {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
1872 {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
1873 {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
1874 {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
1875 {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
1876 {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
1877
1878 {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
1879 {"TX SMIC MUX7", "SWR_MIC0", "TX SWR_MIC0"},
1880 {"TX SMIC MUX7", "SWR_MIC1", "TX SWR_MIC1"},
1881 {"TX SMIC MUX7", "SWR_MIC2", "TX SWR_MIC2"},
1882 {"TX SMIC MUX7", "SWR_MIC3", "TX SWR_MIC3"},
1883 {"TX SMIC MUX7", "SWR_MIC4", "TX SWR_MIC4"},
1884 {"TX SMIC MUX7", "SWR_MIC5", "TX SWR_MIC5"},
1885 {"TX SMIC MUX7", "SWR_MIC6", "TX SWR_MIC6"},
1886 {"TX SMIC MUX7", "SWR_MIC7", "TX SWR_MIC7"},
1887 {"TX SMIC MUX7", "SWR_MIC8", "TX SWR_MIC8"},
1888 {"TX SMIC MUX7", "SWR_MIC9", "TX SWR_MIC9"},
1889 {"TX SMIC MUX7", "SWR_MIC10", "TX SWR_MIC10"},
1890 {"TX SMIC MUX7", "SWR_MIC11", "TX SWR_MIC11"},
Laxminath Kasamb03e82d2019-11-05 13:35:01 +05301891
1892 {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
1893 {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
1894 {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
1895 {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
1896 {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
1897 {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
1898 {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
1899 {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05301900};
1901
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301902static const struct snd_soc_dapm_route tx_audio_map[] = {
1903 {"TX_AIF1 CAP", NULL, "TX_MCLK"},
1904 {"TX_AIF2 CAP", NULL, "TX_MCLK"},
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001905 {"TX_AIF3 CAP", NULL, "TX_MCLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301906
1907 {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
1908 {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001909 {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301910
1911 {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1912 {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1913 {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1914 {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1915 {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1916 {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1917 {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1918 {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1919
1920 {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1921 {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1922 {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1923 {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1924 {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1925 {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1926 {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1927 {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1928
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07001929 {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1930 {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1931 {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1932 {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1933 {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1934 {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1935 {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1936 {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1937
Laxminath Kasamfc281ad2018-08-06 20:19:40 +05301938 {"TX DEC0 MUX", NULL, "TX_MCLK"},
1939 {"TX DEC1 MUX", NULL, "TX_MCLK"},
1940 {"TX DEC2 MUX", NULL, "TX_MCLK"},
1941 {"TX DEC3 MUX", NULL, "TX_MCLK"},
1942 {"TX DEC4 MUX", NULL, "TX_MCLK"},
1943 {"TX DEC5 MUX", NULL, "TX_MCLK"},
1944 {"TX DEC6 MUX", NULL, "TX_MCLK"},
1945 {"TX DEC7 MUX", NULL, "TX_MCLK"},
1946
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301947 {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
1948 {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
1949 {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
1950 {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
1951 {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
1952 {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
1953 {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
1954 {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
1955 {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
1956
1957 {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301958 {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301959 {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
1960 {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
1961 {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
1962 {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
1963 {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
1964 {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
1965 {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
1966 {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
1967 {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
1968 {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
1969 {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
1970 {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
1971
1972 {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
1973 {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
1974 {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
1975 {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
1976 {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
1977 {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
1978 {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
1979 {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
1980 {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
1981
1982 {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301983 {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301984 {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
1985 {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
1986 {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
1987 {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
1988 {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
1989 {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
1990 {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
1991 {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
1992 {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
1993 {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
1994 {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
1995 {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
1996
1997 {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
1998 {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
1999 {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
2000 {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
2001 {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
2002 {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
2003 {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
2004 {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
2005 {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
2006
2007 {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05302008 {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302009 {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
2010 {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
2011 {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
2012 {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
2013 {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
2014 {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
2015 {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
2016 {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
2017 {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
2018 {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
2019 {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
2020 {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
2021
2022 {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
2023 {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
2024 {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
2025 {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
2026 {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
2027 {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
2028 {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
2029 {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
2030 {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
2031
2032 {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05302033 {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302034 {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
2035 {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
2036 {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
2037 {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
2038 {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
2039 {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
2040 {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
2041 {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
2042 {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
2043 {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
2044 {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
2045 {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
2046
2047 {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
2048 {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
2049 {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
2050 {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
2051 {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
2052 {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
2053 {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
2054 {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
2055 {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
2056
2057 {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05302058 {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302059 {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
2060 {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
2061 {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
2062 {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
2063 {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
2064 {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
2065 {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
2066 {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
2067 {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
2068 {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
2069 {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
2070 {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
2071
2072 {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
2073 {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
2074 {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
2075 {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
2076 {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
2077 {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
2078 {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
2079 {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
2080 {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
2081
2082 {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05302083 {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302084 {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
2085 {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
2086 {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
2087 {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
2088 {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
2089 {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
2090 {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
2091 {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
2092 {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
2093 {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
2094 {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
2095 {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
2096
2097 {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
2098 {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
2099 {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
2100 {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
2101 {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
2102 {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
2103 {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
2104 {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
2105 {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
2106
2107 {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05302108 {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302109 {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
2110 {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
2111 {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
2112 {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
2113 {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
2114 {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
2115 {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
2116 {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
2117 {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
2118 {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
2119 {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
2120 {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
2121
2122 {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
2123 {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
2124 {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
2125 {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
2126 {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
2127 {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
2128 {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
2129 {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
2130 {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
2131
2132 {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05302133 {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302134 {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
2135 {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
2136 {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
2137 {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
2138 {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
2139 {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
2140 {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
2141 {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
2142 {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
2143 {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
2144 {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
2145 {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
2146};
2147
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05302148static const struct snd_kcontrol_new tx_macro_snd_controls_common[] = {
2149 SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
2150 BOLERO_CDC_TX0_TX_VOL_CTL,
2151 0, -84, 40, digital_gain),
2152 SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
2153 BOLERO_CDC_TX1_TX_VOL_CTL,
2154 0, -84, 40, digital_gain),
2155 SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
2156 BOLERO_CDC_TX2_TX_VOL_CTL,
2157 0, -84, 40, digital_gain),
2158 SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
2159 BOLERO_CDC_TX3_TX_VOL_CTL,
2160 0, -84, 40, digital_gain),
2161
2162 SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
2163 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2164
2165 SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
2166 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2167
2168 SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
2169 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2170
2171 SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
2172 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2173
2174 SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
2175 tx_macro_get_bcs, tx_macro_set_bcs),
2176};
2177
2178static const struct snd_kcontrol_new tx_macro_snd_controls_v3[] = {
2179 SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
2180 BOLERO_CDC_TX4_TX_VOL_CTL,
2181 0, -84, 40, digital_gain),
2182 SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
2183 BOLERO_CDC_TX5_TX_VOL_CTL,
2184 0, -84, 40, digital_gain),
2185 SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
2186 BOLERO_CDC_TX6_TX_VOL_CTL,
2187 0, -84, 40, digital_gain),
2188 SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
2189 BOLERO_CDC_TX7_TX_VOL_CTL,
2190 0, -84, 40, digital_gain),
2191
2192 SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
2193 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2194
2195 SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
2196 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2197
2198 SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
2199 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2200
2201 SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
2202 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2203};
2204
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302205static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
2206 SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
2207 BOLERO_CDC_TX0_TX_VOL_CTL,
2208 0, -84, 40, digital_gain),
2209 SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
2210 BOLERO_CDC_TX1_TX_VOL_CTL,
2211 0, -84, 40, digital_gain),
2212 SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
2213 BOLERO_CDC_TX2_TX_VOL_CTL,
2214 0, -84, 40, digital_gain),
2215 SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
2216 BOLERO_CDC_TX3_TX_VOL_CTL,
2217 0, -84, 40, digital_gain),
2218 SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
2219 BOLERO_CDC_TX4_TX_VOL_CTL,
2220 0, -84, 40, digital_gain),
2221 SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
2222 BOLERO_CDC_TX5_TX_VOL_CTL,
2223 0, -84, 40, digital_gain),
2224 SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
2225 BOLERO_CDC_TX6_TX_VOL_CTL,
2226 0, -84, 40, digital_gain),
2227 SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
2228 BOLERO_CDC_TX7_TX_VOL_CTL,
2229 0, -84, 40, digital_gain),
Karthikeyan Mani765eaab2019-07-18 16:27:01 -07002230
Karthikeyan Mani1dcd5a32019-08-22 14:37:13 -07002231 SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
2232 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2233
2234 SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
2235 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2236
2237 SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
2238 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2239
2240 SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
2241 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2242
2243 SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
2244 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2245
2246 SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
2247 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2248
2249 SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
2250 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2251
2252 SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
2253 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
2254
Karthikeyan Mani765eaab2019-07-18 16:27:01 -07002255 SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
2256 tx_macro_get_bcs, tx_macro_set_bcs),
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302257};
2258
Sudheer Papothi06a4c642019-08-08 05:17:46 +05302259static int tx_macro_register_event_listener(struct snd_soc_component *component,
2260 bool enable)
2261{
2262 struct device *tx_dev = NULL;
2263 struct tx_macro_priv *tx_priv = NULL;
2264 int ret = 0;
2265
2266 if (!component)
2267 return -EINVAL;
2268
2269 tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
2270 if (!tx_dev) {
2271 dev_err(component->dev,
2272 "%s: null device for macro!\n", __func__);
2273 return -EINVAL;
2274 }
2275 tx_priv = dev_get_drvdata(tx_dev);
2276 if (!tx_priv) {
2277 dev_err(component->dev,
2278 "%s: priv is null for macro!\n", __func__);
2279 return -EINVAL;
2280 }
Sudheer Papothifc3adb02019-11-24 10:14:21 +05302281 if (tx_priv->swr_ctrl_data && !tx_priv->tx_swr_clk_cnt) {
Sudheer Papothibc3f1e52019-09-17 04:03:10 +05302282 if (enable) {
Sudheer Papothi06a4c642019-08-08 05:17:46 +05302283 ret = swrm_wcd_notify(
2284 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
2285 SWR_REGISTER_WAKEUP, NULL);
Sudheer Papothibc3f1e52019-09-17 04:03:10 +05302286 msm_cdc_pinctrl_set_wakeup_capable(
2287 tx_priv->tx_swr_gpio_p, false);
2288 } else {
2289 msm_cdc_pinctrl_set_wakeup_capable(
2290 tx_priv->tx_swr_gpio_p, true);
Sudheer Papothi06a4c642019-08-08 05:17:46 +05302291 ret = swrm_wcd_notify(
2292 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
2293 SWR_DEREGISTER_WAKEUP, NULL);
Sudheer Papothibc3f1e52019-09-17 04:03:10 +05302294 }
Sudheer Papothi06a4c642019-08-08 05:17:46 +05302295 }
2296
2297 return ret;
2298}
2299
Sudheer Papothia7397942019-03-19 03:14:23 +05302300static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv,
2301 struct regmap *regmap, int clk_type,
2302 bool enable)
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302303{
Meng Wang69b55c82019-05-29 11:04:29 +08002304 int ret = 0, clk_tx_ret = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302305
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302306 dev_dbg(tx_priv->dev,
2307 "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
Sudheer Papothia7397942019-03-19 03:14:23 +05302308 __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302309 (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
Tanya Dixit8530fb92018-09-14 16:01:25 +05302310
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302311 if (enable) {
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002312 if (tx_priv->swr_clk_users == 0) {
2313 ret = msm_cdc_pinctrl_select_active_state(
Karthikeyan Mani01f1ba42019-02-26 18:48:15 -08002314 tx_priv->tx_swr_gpio_p);
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002315 if (ret < 0) {
2316 dev_err_ratelimited(tx_priv->dev,
2317 "%s: tx swr pinctrl enable failed\n",
2318 __func__);
2319 goto exit;
2320 }
2321 }
Sudheer Papothia7397942019-03-19 03:14:23 +05302322
Meng Wang69b55c82019-05-29 11:04:29 +08002323 clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302324 TX_CORE_CLK,
2325 TX_CORE_CLK,
2326 true);
2327 if (clk_type == TX_MCLK) {
2328 ret = tx_macro_mclk_enable(tx_priv, 1);
2329 if (ret < 0) {
2330 if (tx_priv->swr_clk_users == 0)
2331 msm_cdc_pinctrl_select_sleep_state(
2332 tx_priv->tx_swr_gpio_p);
2333 dev_err_ratelimited(tx_priv->dev,
2334 "%s: request clock enable failed\n",
2335 __func__);
2336 goto done;
2337 }
2338 }
2339 if (clk_type == VA_MCLK) {
Sudheer Papothia7397942019-03-19 03:14:23 +05302340 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
2341 TX_CORE_CLK,
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302342 VA_CORE_CLK,
Sudheer Papothia7397942019-03-19 03:14:23 +05302343 true);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302344 if (ret < 0) {
2345 if (tx_priv->swr_clk_users == 0)
Sudheer Papothia7397942019-03-19 03:14:23 +05302346 msm_cdc_pinctrl_select_sleep_state(
2347 tx_priv->tx_swr_gpio_p);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302348 dev_err_ratelimited(tx_priv->dev,
2349 "%s: swr request clk failed\n",
2350 __func__);
2351 goto done;
Sudheer Papothia7397942019-03-19 03:14:23 +05302352 }
Sudheer Papothi296867b2019-06-20 09:24:09 +05302353 bolero_clk_rsc_fs_gen_request(tx_priv->dev,
2354 true);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302355 if (tx_priv->tx_mclk_users == 0) {
2356 regmap_update_bits(regmap,
2357 BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK,
2358 0x01, 0x01);
2359 regmap_update_bits(regmap,
2360 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
2361 0x01, 0x01);
2362 regmap_update_bits(regmap,
2363 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
2364 0x01, 0x01);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302365 }
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302366 }
2367 if (tx_priv->swr_clk_users == 0) {
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302368 dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n",
2369 __func__, tx_priv->reset_swr);
Ramprasad Katkama4c747b2018-12-11 19:15:53 +05302370 if (tx_priv->reset_swr)
2371 regmap_update_bits(regmap,
2372 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
2373 0x02, 0x02);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302374 regmap_update_bits(regmap,
2375 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
2376 0x01, 0x01);
Ramprasad Katkama4c747b2018-12-11 19:15:53 +05302377 if (tx_priv->reset_swr)
2378 regmap_update_bits(regmap,
2379 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
2380 0x02, 0x00);
2381 tx_priv->reset_swr = false;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302382 }
Meng Wang69b55c82019-05-29 11:04:29 +08002383 if (!clk_tx_ret)
2384 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302385 TX_CORE_CLK,
2386 TX_CORE_CLK,
2387 false);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302388 tx_priv->swr_clk_users++;
2389 } else {
2390 if (tx_priv->swr_clk_users <= 0) {
Sudheer Papothia7397942019-03-19 03:14:23 +05302391 dev_err_ratelimited(tx_priv->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302392 "tx swrm clock users already 0\n");
2393 tx_priv->swr_clk_users = 0;
Sudheer Papothia7397942019-03-19 03:14:23 +05302394 return 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302395 }
Meng Wang69b55c82019-05-29 11:04:29 +08002396 clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302397 TX_CORE_CLK,
2398 TX_CORE_CLK,
2399 true);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302400 tx_priv->swr_clk_users--;
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302401 if (tx_priv->swr_clk_users == 0)
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302402 regmap_update_bits(regmap,
2403 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
2404 0x01, 0x00);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302405 if (clk_type == TX_MCLK)
2406 tx_macro_mclk_enable(tx_priv, 0);
2407 if (clk_type == VA_MCLK) {
2408 if (tx_priv->tx_mclk_users == 0) {
2409 regmap_update_bits(regmap,
2410 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
2411 0x01, 0x00);
2412 regmap_update_bits(regmap,
2413 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
2414 0x01, 0x00);
Sudheer Papothia7397942019-03-19 03:14:23 +05302415 }
Sudheer Papothi296867b2019-06-20 09:24:09 +05302416 bolero_clk_rsc_fs_gen_request(tx_priv->dev,
2417 false);
Sudheer Papothia7397942019-03-19 03:14:23 +05302418 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
2419 TX_CORE_CLK,
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302420 VA_CORE_CLK,
Sudheer Papothia7397942019-03-19 03:14:23 +05302421 false);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302422 if (ret < 0) {
2423 dev_err_ratelimited(tx_priv->dev,
2424 "%s: swr request clk failed\n",
2425 __func__);
2426 goto done;
2427 }
2428 }
Meng Wang69b55c82019-05-29 11:04:29 +08002429 if (!clk_tx_ret)
2430 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302431 TX_CORE_CLK,
2432 TX_CORE_CLK,
2433 false);
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002434 if (tx_priv->swr_clk_users == 0) {
2435 ret = msm_cdc_pinctrl_select_sleep_state(
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302436 tx_priv->tx_swr_gpio_p);
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002437 if (ret < 0) {
2438 dev_err_ratelimited(tx_priv->dev,
2439 "%s: tx swr pinctrl disable failed\n",
2440 __func__);
2441 goto exit;
2442 }
2443 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302444 }
Sudheer Papothia7397942019-03-19 03:14:23 +05302445 return 0;
2446
2447done:
Meng Wang69b55c82019-05-29 11:04:29 +08002448 if (!clk_tx_ret)
2449 bolero_clk_rsc_request_clock(tx_priv->dev,
Sudheer Papothia7397942019-03-19 03:14:23 +05302450 TX_CORE_CLK,
2451 TX_CORE_CLK,
2452 false);
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002453exit:
Sudheer Papothia7397942019-03-19 03:14:23 +05302454 return ret;
2455}
2456
Sudheer Papothid50a5812019-11-21 07:24:42 +05302457static int tx_macro_clk_div_get(struct snd_soc_component *component)
2458{
2459 struct device *tx_dev = NULL;
2460 struct tx_macro_priv *tx_priv = NULL;
2461
2462 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
2463 return -EINVAL;
2464
2465 return tx_priv->dmic_clk_div;
2466}
2467
Sudheer Papothi6cc7f522019-06-28 11:04:03 +05302468static int tx_macro_clk_switch(struct snd_soc_component *component)
2469{
2470 struct device *tx_dev = NULL;
2471 struct tx_macro_priv *tx_priv = NULL;
2472 int ret = 0;
2473
2474 if (!component)
2475 return -EINVAL;
2476
2477 tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
2478 if (!tx_dev) {
2479 dev_err(component->dev,
2480 "%s: null device for macro!\n", __func__);
2481 return -EINVAL;
2482 }
2483 tx_priv = dev_get_drvdata(tx_dev);
2484 if (!tx_priv) {
2485 dev_err(component->dev,
2486 "%s: priv is null for macro!\n", __func__);
2487 return -EINVAL;
2488 }
2489 if (tx_priv->swr_ctrl_data) {
2490 ret = swrm_wcd_notify(
2491 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
2492 SWR_REQ_CLK_SWITCH, NULL);
2493 }
2494
2495 return ret;
2496}
2497
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002498static int tx_macro_core_vote(void *handle, bool enable)
2499{
2500 struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002501
2502 if (tx_priv == NULL) {
2503 pr_err("%s: tx priv data is NULL\n", __func__);
2504 return -EINVAL;
2505 }
2506 if (enable) {
2507 pm_runtime_get_sync(tx_priv->dev);
2508 pm_runtime_put_autosuspend(tx_priv->dev);
2509 pm_runtime_mark_last_busy(tx_priv->dev);
2510 }
2511
Aditya Bavanarid577af92019-10-03 21:09:19 +05302512 if (bolero_check_core_votes(tx_priv->dev))
2513 return 0;
2514 else
2515 return -EINVAL;
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002516}
2517
Sudheer Papothia7397942019-03-19 03:14:23 +05302518static int tx_macro_swrm_clock(void *handle, bool enable)
2519{
2520 struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
2521 struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
2522 int ret = 0;
2523
2524 if (regmap == NULL) {
2525 dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
2526 return -EINVAL;
2527 }
2528
2529 mutex_lock(&tx_priv->swr_clk_lock);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302530 dev_dbg(tx_priv->dev,
2531 "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
2532 __func__, (enable ? "enable" : "disable"),
2533 tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt);
Sudheer Papothia7397942019-03-19 03:14:23 +05302534
2535 if (enable) {
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302536 pm_runtime_get_sync(tx_priv->dev);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302537 if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt) {
Sudheer Papothia7397942019-03-19 03:14:23 +05302538 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
2539 VA_MCLK, enable);
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002540 if (ret) {
2541 pm_runtime_mark_last_busy(tx_priv->dev);
2542 pm_runtime_put_autosuspend(tx_priv->dev);
Sudheer Papothia7397942019-03-19 03:14:23 +05302543 goto done;
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002544 }
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302545 tx_priv->va_clk_status++;
Sudheer Papothia7397942019-03-19 03:14:23 +05302546 } else {
Sudheer Papothia7397942019-03-19 03:14:23 +05302547 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
2548 TX_MCLK, enable);
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002549 if (ret) {
2550 pm_runtime_mark_last_busy(tx_priv->dev);
2551 pm_runtime_put_autosuspend(tx_priv->dev);
Sudheer Papothia7397942019-03-19 03:14:23 +05302552 goto done;
Karthikeyan Mani8d40a062019-09-05 16:44:49 -07002553 }
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302554 tx_priv->tx_clk_status++;
Sudheer Papothia7397942019-03-19 03:14:23 +05302555 }
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302556 pm_runtime_mark_last_busy(tx_priv->dev);
2557 pm_runtime_put_autosuspend(tx_priv->dev);
Sudheer Papothia7397942019-03-19 03:14:23 +05302558 } else {
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302559 if (tx_priv->va_clk_status && !tx_priv->tx_clk_status) {
Sudheer Papothia7397942019-03-19 03:14:23 +05302560 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
2561 VA_MCLK, enable);
2562 if (ret)
2563 goto done;
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302564 --tx_priv->va_clk_status;
2565 } else if (!tx_priv->va_clk_status && tx_priv->tx_clk_status) {
Sudheer Papothia7397942019-03-19 03:14:23 +05302566 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
2567 TX_MCLK, enable);
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302568 if (ret)
2569 goto done;
2570 --tx_priv->tx_clk_status;
2571 } else if (tx_priv->va_clk_status && tx_priv->tx_clk_status) {
2572 if (!tx_priv->va_swr_clk_cnt && tx_priv->tx_swr_clk_cnt) {
2573 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
2574 VA_MCLK, enable);
Sudheer Papothia7397942019-03-19 03:14:23 +05302575 if (ret)
2576 goto done;
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302577 --tx_priv->va_clk_status;
2578 } else {
2579 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
2580 TX_MCLK, enable);
2581 if (ret)
2582 goto done;
2583 --tx_priv->tx_clk_status;
Sudheer Papothia7397942019-03-19 03:14:23 +05302584 }
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302585
2586 } else {
2587 dev_dbg(tx_priv->dev,
2588 "%s: Both clocks are disabled\n", __func__);
Sudheer Papothia7397942019-03-19 03:14:23 +05302589 }
2590 }
Sudheer Papothicf3b4062019-05-10 10:48:43 +05302591
2592 dev_dbg(tx_priv->dev,
2593 "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
2594 __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status,
2595 tx_priv->va_clk_status);
Sudheer Papothia7397942019-03-19 03:14:23 +05302596done:
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302597 mutex_unlock(&tx_priv->swr_clk_lock);
2598 return ret;
2599}
2600
2601static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
2602 struct tx_macro_priv *tx_priv)
2603{
2604 u32 div_factor = TX_MACRO_CLK_DIV_2;
2605 u32 mclk_rate = TX_MACRO_MCLK_FREQ;
2606
2607 if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
2608 mclk_rate % dmic_sample_rate != 0)
2609 goto undefined_rate;
2610
2611 div_factor = mclk_rate / dmic_sample_rate;
2612
2613 switch (div_factor) {
2614 case 2:
2615 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
2616 break;
2617 case 3:
2618 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
2619 break;
2620 case 4:
2621 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
2622 break;
2623 case 6:
2624 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
2625 break;
2626 case 8:
2627 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
2628 break;
2629 case 16:
2630 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
2631 break;
2632 default:
2633 /* Any other DIV factor is invalid */
2634 goto undefined_rate;
2635 }
2636
2637 /* Valid dmic DIV factors */
2638 dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
2639 __func__, div_factor, mclk_rate);
2640
2641 return dmic_sample_rate;
2642
2643undefined_rate:
2644 dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
2645 __func__, dmic_sample_rate, mclk_rate);
2646 dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
2647
2648 return dmic_sample_rate;
2649}
2650
Sudheer Papothi72fef482019-08-30 11:00:20 +05302651static const struct tx_macro_reg_mask_val tx_macro_reg_init[] = {
Vatsal Bucha126be652019-09-11 11:32:55 +05302652 {BOLERO_CDC_TX0_TX_PATH_SEC7, 0x3F, 0x02},
Sudheer Papothi72fef482019-08-30 11:00:20 +05302653};
2654
Meng Wang15c825d2018-09-06 10:49:18 +08002655static int tx_macro_init(struct snd_soc_component *component)
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302656{
Meng Wang15c825d2018-09-06 10:49:18 +08002657 struct snd_soc_dapm_context *dapm =
2658 snd_soc_component_get_dapm(component);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302659 int ret = 0, i = 0;
2660 struct device *tx_dev = NULL;
2661 struct tx_macro_priv *tx_priv = NULL;
2662
Meng Wang15c825d2018-09-06 10:49:18 +08002663 tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302664 if (!tx_dev) {
Meng Wang15c825d2018-09-06 10:49:18 +08002665 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302666 "%s: null device for macro!\n", __func__);
2667 return -EINVAL;
2668 }
2669 tx_priv = dev_get_drvdata(tx_dev);
2670 if (!tx_priv) {
Meng Wang15c825d2018-09-06 10:49:18 +08002671 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302672 "%s: priv is null for macro!\n", __func__);
2673 return -EINVAL;
2674 }
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05302675 tx_priv->version = bolero_get_version(tx_dev);
2676 if (tx_priv->version >= BOLERO_VERSION_2_0) {
2677 ret = snd_soc_dapm_new_controls(dapm,
2678 tx_macro_dapm_widgets_common,
2679 ARRAY_SIZE(tx_macro_dapm_widgets_common));
2680 if (ret < 0) {
2681 dev_err(tx_dev, "%s: Failed to add controls\n",
2682 __func__);
2683 return ret;
2684 }
2685 if (tx_priv->version == BOLERO_VERSION_2_1)
2686 ret = snd_soc_dapm_new_controls(dapm,
2687 tx_macro_dapm_widgets_v2,
2688 ARRAY_SIZE(tx_macro_dapm_widgets_v2));
2689 else if (tx_priv->version == BOLERO_VERSION_2_0)
2690 ret = snd_soc_dapm_new_controls(dapm,
2691 tx_macro_dapm_widgets_v3,
2692 ARRAY_SIZE(tx_macro_dapm_widgets_v3));
2693 if (ret < 0) {
2694 dev_err(tx_dev, "%s: Failed to add controls\n",
2695 __func__);
2696 return ret;
2697 }
2698 } else {
2699 ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302700 ARRAY_SIZE(tx_macro_dapm_widgets));
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05302701 if (ret < 0) {
2702 dev_err(tx_dev, "%s: Failed to add controls\n",
2703 __func__);
2704 return ret;
2705 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302706 }
2707
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05302708 if (tx_priv->version >= BOLERO_VERSION_2_0) {
2709 ret = snd_soc_dapm_add_routes(dapm,
2710 tx_audio_map_common,
2711 ARRAY_SIZE(tx_audio_map_common));
2712 if (ret < 0) {
2713 dev_err(tx_dev, "%s: Failed to add routes\n",
2714 __func__);
2715 return ret;
2716 }
2717 if (tx_priv->version == BOLERO_VERSION_2_0)
2718 ret = snd_soc_dapm_add_routes(dapm,
2719 tx_audio_map_v3,
2720 ARRAY_SIZE(tx_audio_map_v3));
2721 if (ret < 0) {
2722 dev_err(tx_dev, "%s: Failed to add routes\n",
2723 __func__);
2724 return ret;
2725 }
2726 } else {
2727 ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302728 ARRAY_SIZE(tx_audio_map));
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05302729 if (ret < 0) {
2730 dev_err(tx_dev, "%s: Failed to add routes\n",
2731 __func__);
2732 return ret;
2733 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302734 }
2735
2736 ret = snd_soc_dapm_new_widgets(dapm->card);
2737 if (ret < 0) {
2738 dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
2739 return ret;
2740 }
2741
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05302742 if (tx_priv->version >= BOLERO_VERSION_2_0) {
2743 ret = snd_soc_add_component_controls(component,
2744 tx_macro_snd_controls_common,
2745 ARRAY_SIZE(tx_macro_snd_controls_common));
2746 if (ret < 0) {
2747 dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
2748 __func__);
2749 return ret;
2750 }
2751 if (tx_priv->version == BOLERO_VERSION_2_0)
2752 ret = snd_soc_add_component_controls(component,
2753 tx_macro_snd_controls_v3,
2754 ARRAY_SIZE(tx_macro_snd_controls_v3));
2755 if (ret < 0) {
2756 dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
2757 __func__);
2758 return ret;
2759 }
2760 } else {
2761 ret = snd_soc_add_component_controls(component,
2762 tx_macro_snd_controls,
2763 ARRAY_SIZE(tx_macro_snd_controls));
2764 if (ret < 0) {
2765 dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
2766 __func__);
2767 return ret;
2768 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302769 }
Laxminath Kasam638b5602018-09-24 13:19:52 +05302770
2771 snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
2772 snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
Karthikeyan Manif3bb8182019-07-11 14:38:54 -07002773 snd_soc_dapm_ignore_suspend(dapm, "TX_AIF3 Capture");
Laxminath Kasam4651dcb2019-10-10 23:45:21 +05302774 if (tx_priv->version >= BOLERO_VERSION_2_0) {
2775 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC0");
2776 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC1");
2777 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC2");
2778 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC3");
2779 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC4");
2780 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC5");
2781 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC6");
2782 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC7");
2783 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC8");
2784 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC9");
2785 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC10");
2786 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC11");
2787 } else {
2788 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
2789 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
2790 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
2791 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
2792 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0");
2793 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1");
2794 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2");
2795 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3");
2796 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4");
2797 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5");
2798 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6");
2799 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7");
2800 }
Laxminath Kasam638b5602018-09-24 13:19:52 +05302801 snd_soc_dapm_sync(dapm);
2802
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302803 for (i = 0; i < NUM_DECIMATORS; i++) {
2804 tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
2805 tx_priv->tx_hpf_work[i].decimator = i;
2806 INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
2807 tx_macro_tx_hpf_corner_freq_callback);
2808 }
2809
2810 for (i = 0; i < NUM_DECIMATORS; i++) {
2811 tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
2812 tx_priv->tx_mute_dwork[i].decimator = i;
2813 INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
2814 tx_macro_mute_update_callback);
2815 }
Meng Wang15c825d2018-09-06 10:49:18 +08002816 tx_priv->component = component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302817
Sudheer Papothi72fef482019-08-30 11:00:20 +05302818 for (i = 0; i < ARRAY_SIZE(tx_macro_reg_init); i++)
2819 snd_soc_component_update_bits(component,
2820 tx_macro_reg_init[i].reg,
2821 tx_macro_reg_init[i].mask,
2822 tx_macro_reg_init[i].val);
2823
Laxminath Kasamfbd95ed2019-11-05 22:07:06 +05302824 if (tx_priv->version == BOLERO_VERSION_2_1)
2825 snd_soc_component_update_bits(component,
Laxminath Kasam696b14b2019-12-03 22:07:34 +05302826 BOLERO_CDC_VA_TOP_CSR_SWR_CTRL, 0x0F, 0x0A);
Laxminath Kasamfbd95ed2019-11-05 22:07:06 +05302827 else if (tx_priv->version == BOLERO_VERSION_2_0)
2828 snd_soc_component_update_bits(component,
Laxminath Kasam696b14b2019-12-03 22:07:34 +05302829 BOLERO_CDC_TX_TOP_CSR_SWR_CTRL, 0x0F, 0x0A);
Laxminath Kasamfbd95ed2019-11-05 22:07:06 +05302830
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302831 return 0;
2832}
2833
Meng Wang15c825d2018-09-06 10:49:18 +08002834static int tx_macro_deinit(struct snd_soc_component *component)
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302835{
2836 struct device *tx_dev = NULL;
2837 struct tx_macro_priv *tx_priv = NULL;
2838
Meng Wang15c825d2018-09-06 10:49:18 +08002839 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302840 return -EINVAL;
2841
Meng Wang15c825d2018-09-06 10:49:18 +08002842 tx_priv->component = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302843 return 0;
2844}
2845
2846static void tx_macro_add_child_devices(struct work_struct *work)
2847{
2848 struct tx_macro_priv *tx_priv = NULL;
2849 struct platform_device *pdev = NULL;
2850 struct device_node *node = NULL;
2851 struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
2852 int ret = 0;
2853 u16 count = 0, ctrl_num = 0;
2854 struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
2855 char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
2856 bool tx_swr_master_node = false;
2857
2858 tx_priv = container_of(work, struct tx_macro_priv,
2859 tx_macro_add_child_devices_work);
2860 if (!tx_priv) {
2861 pr_err("%s: Memory for tx_priv does not exist\n",
2862 __func__);
2863 return;
2864 }
2865
2866 if (!tx_priv->dev) {
2867 pr_err("%s: tx dev does not exist\n", __func__);
2868 return;
2869 }
2870
2871 if (!tx_priv->dev->of_node) {
2872 dev_err(tx_priv->dev,
2873 "%s: DT node for tx_priv does not exist\n", __func__);
2874 return;
2875 }
2876
2877 platdata = &tx_priv->swr_plat_data;
2878 tx_priv->child_count = 0;
2879
2880 for_each_available_child_of_node(tx_priv->dev->of_node, node) {
2881 tx_swr_master_node = false;
2882 if (strnstr(node->name, "tx_swr_master",
2883 strlen("tx_swr_master")) != NULL)
2884 tx_swr_master_node = true;
2885
2886 if (tx_swr_master_node)
2887 strlcpy(plat_dev_name, "tx_swr_ctrl",
2888 (TX_MACRO_SWR_STRING_LEN - 1));
2889 else
2890 strlcpy(plat_dev_name, node->name,
2891 (TX_MACRO_SWR_STRING_LEN - 1));
2892
2893 pdev = platform_device_alloc(plat_dev_name, -1);
2894 if (!pdev) {
2895 dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
2896 __func__);
2897 ret = -ENOMEM;
2898 goto err;
2899 }
2900 pdev->dev.parent = tx_priv->dev;
2901 pdev->dev.of_node = node;
2902
2903 if (tx_swr_master_node) {
2904 ret = platform_device_add_data(pdev, platdata,
2905 sizeof(*platdata));
2906 if (ret) {
2907 dev_err(&pdev->dev,
2908 "%s: cannot add plat data ctrl:%d\n",
2909 __func__, ctrl_num);
2910 goto fail_pdev_add;
2911 }
2912 }
2913
2914 ret = platform_device_add(pdev);
2915 if (ret) {
2916 dev_err(&pdev->dev,
2917 "%s: Cannot add platform device\n",
2918 __func__);
2919 goto fail_pdev_add;
2920 }
2921
2922 if (tx_swr_master_node) {
2923 temp = krealloc(swr_ctrl_data,
2924 (ctrl_num + 1) * sizeof(
2925 struct tx_macro_swr_ctrl_data),
2926 GFP_KERNEL);
2927 if (!temp) {
2928 ret = -ENOMEM;
2929 goto fail_pdev_add;
2930 }
2931 swr_ctrl_data = temp;
2932 swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
2933 ctrl_num++;
2934 dev_dbg(&pdev->dev,
2935 "%s: Added soundwire ctrl device(s)\n",
2936 __func__);
2937 tx_priv->swr_ctrl_data = swr_ctrl_data;
2938 }
2939 if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
2940 tx_priv->pdev_child_devices[
2941 tx_priv->child_count++] = pdev;
2942 else
2943 goto err;
2944 }
2945 return;
2946fail_pdev_add:
2947 for (count = 0; count < tx_priv->child_count; count++)
2948 platform_device_put(tx_priv->pdev_child_devices[count]);
2949err:
2950 return;
2951}
2952
Sudheer Papothia3e969d2018-10-27 06:22:10 +05302953static int tx_macro_set_port_map(struct snd_soc_component *component,
2954 u32 usecase, u32 size, void *data)
2955{
2956 struct device *tx_dev = NULL;
2957 struct tx_macro_priv *tx_priv = NULL;
2958 struct swrm_port_config port_cfg;
2959 int ret = 0;
2960
2961 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
2962 return -EINVAL;
2963
2964 memset(&port_cfg, 0, sizeof(port_cfg));
2965 port_cfg.uc = usecase;
2966 port_cfg.size = size;
2967 port_cfg.params = data;
2968
Karthikeyan Mani3bd80a52019-06-04 23:40:16 -07002969 if (tx_priv->swr_ctrl_data)
2970 ret = swrm_wcd_notify(
2971 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
2972 SWR_SET_PORT_MAP, &port_cfg);
Sudheer Papothia3e969d2018-10-27 06:22:10 +05302973
2974 return ret;
2975}
2976
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302977static void tx_macro_init_ops(struct macro_ops *ops,
2978 char __iomem *tx_io_base)
2979{
2980 memset(ops, 0, sizeof(struct macro_ops));
2981 ops->init = tx_macro_init;
2982 ops->exit = tx_macro_deinit;
2983 ops->io_base = tx_io_base;
2984 ops->dai_ptr = tx_macro_dai;
2985 ops->num_dais = ARRAY_SIZE(tx_macro_dai);
Laxminath Kasamfb0d6832018-09-22 01:49:52 +05302986 ops->event_handler = tx_macro_event_handler;
Aditya Bavanaric4e96122018-11-14 14:46:38 +05302987 ops->reg_wake_irq = tx_macro_reg_wake_irq;
Sudheer Papothia3e969d2018-10-27 06:22:10 +05302988 ops->set_port_map = tx_macro_set_port_map;
Sudheer Papothid50a5812019-11-21 07:24:42 +05302989 ops->clk_div_get = tx_macro_clk_div_get;
Sudheer Papothi6cc7f522019-06-28 11:04:03 +05302990 ops->clk_switch = tx_macro_clk_switch;
Sudheer Papothi06a4c642019-08-08 05:17:46 +05302991 ops->reg_evt_listener = tx_macro_register_event_listener;
Sudheer Papothifc3adb02019-11-24 10:14:21 +05302992 ops->clk_enable = __tx_macro_mclk_enable;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302993}
2994
2995static int tx_macro_probe(struct platform_device *pdev)
2996{
2997 struct macro_ops ops = {0};
2998 struct tx_macro_priv *tx_priv = NULL;
2999 u32 tx_base_addr = 0, sample_rate = 0;
3000 char __iomem *tx_io_base = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303001 int ret = 0;
3002 const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
Karthikeyan Mani3bd80a52019-06-04 23:40:16 -07003003 u32 is_used_tx_swr_gpio = 1;
3004 const char *is_used_tx_swr_gpio_dt = "qcom,is-used-swr-gpio";
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303005
3006 tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
3007 GFP_KERNEL);
3008 if (!tx_priv)
3009 return -ENOMEM;
3010 platform_set_drvdata(pdev, tx_priv);
3011
3012 tx_priv->dev = &pdev->dev;
3013 ret = of_property_read_u32(pdev->dev.of_node, "reg",
3014 &tx_base_addr);
3015 if (ret) {
3016 dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
3017 __func__, "reg");
3018 return ret;
3019 }
3020 dev_set_drvdata(&pdev->dev, tx_priv);
Karthikeyan Mani3bd80a52019-06-04 23:40:16 -07003021 if (of_find_property(pdev->dev.of_node, is_used_tx_swr_gpio_dt,
3022 NULL)) {
3023 ret = of_property_read_u32(pdev->dev.of_node,
3024 is_used_tx_swr_gpio_dt,
3025 &is_used_tx_swr_gpio);
3026 if (ret) {
3027 dev_err(&pdev->dev, "%s: error reading %s in dt\n",
3028 __func__, is_used_tx_swr_gpio_dt);
3029 is_used_tx_swr_gpio = 1;
3030 }
3031 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303032 tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
3033 "qcom,tx-swr-gpios", 0);
Karthikeyan Mani3bd80a52019-06-04 23:40:16 -07003034 if (!tx_priv->tx_swr_gpio_p && is_used_tx_swr_gpio) {
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303035 dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
3036 __func__);
3037 return -EINVAL;
3038 }
Karthikeyan Manib44e4552019-09-09 23:06:04 -07003039 if (msm_cdc_pinctrl_get_state(tx_priv->tx_swr_gpio_p) < 0 &&
3040 is_used_tx_swr_gpio) {
Karthikeyan Mani326536d2019-06-03 13:29:43 -07003041 dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
3042 __func__);
3043 return -EPROBE_DEFER;
3044 }
3045
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303046 tx_io_base = devm_ioremap(&pdev->dev,
3047 tx_base_addr, TX_MACRO_MAX_OFFSET);
3048 if (!tx_io_base) {
3049 dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
3050 return -ENOMEM;
3051 }
3052 tx_priv->tx_io_base = tx_io_base;
3053 ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
3054 &sample_rate);
3055 if (ret) {
3056 dev_err(&pdev->dev,
3057 "%s: could not find sample_rate entry in dt\n",
3058 __func__);
3059 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
3060 } else {
3061 if (tx_macro_validate_dmic_sample_rate(
3062 sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
3063 return -EINVAL;
3064 }
Laxminath Kasam2e13d642019-10-12 01:36:30 +05303065 if (is_used_tx_swr_gpio) {
3066 tx_priv->reset_swr = true;
3067 INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
3068 tx_macro_add_child_devices);
3069 tx_priv->swr_plat_data.handle = (void *) tx_priv;
3070 tx_priv->swr_plat_data.read = NULL;
3071 tx_priv->swr_plat_data.write = NULL;
3072 tx_priv->swr_plat_data.bulk_write = NULL;
3073 tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
3074 tx_priv->swr_plat_data.core_vote = tx_macro_core_vote;
3075 tx_priv->swr_plat_data.handle_irq = NULL;
3076 mutex_init(&tx_priv->swr_clk_lock);
3077 }
3078 tx_priv->is_used_tx_swr_gpio = is_used_tx_swr_gpio;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303079 mutex_init(&tx_priv->mclk_lock);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303080 tx_macro_init_ops(&ops, tx_io_base);
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -07003081 ops.clk_id_req = TX_CORE_CLK;
3082 ops.default_clk_id = TX_CORE_CLK;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303083 ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
3084 if (ret) {
3085 dev_err(&pdev->dev,
3086 "%s: register macro failed\n", __func__);
3087 goto err_reg_macro;
3088 }
Laxminath Kasam2e13d642019-10-12 01:36:30 +05303089 if (is_used_tx_swr_gpio)
3090 schedule_work(&tx_priv->tx_macro_add_child_devices_work);
Sudheer Papothi7601cc62019-03-30 03:00:52 +05303091 pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
3092 pm_runtime_use_autosuspend(&pdev->dev);
3093 pm_runtime_set_suspended(&pdev->dev);
Sudheer Papothi296867b2019-06-20 09:24:09 +05303094 pm_suspend_ignore_children(&pdev->dev, true);
Sudheer Papothi7601cc62019-03-30 03:00:52 +05303095 pm_runtime_enable(&pdev->dev);
3096
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303097 return 0;
3098err_reg_macro:
3099 mutex_destroy(&tx_priv->mclk_lock);
Laxminath Kasam2e13d642019-10-12 01:36:30 +05303100 if (is_used_tx_swr_gpio)
3101 mutex_destroy(&tx_priv->swr_clk_lock);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303102 return ret;
3103}
3104
3105static int tx_macro_remove(struct platform_device *pdev)
3106{
3107 struct tx_macro_priv *tx_priv = NULL;
3108 u16 count = 0;
3109
3110 tx_priv = platform_get_drvdata(pdev);
3111
3112 if (!tx_priv)
3113 return -EINVAL;
3114
Laxminath Kasam2e13d642019-10-12 01:36:30 +05303115 if (tx_priv->is_used_tx_swr_gpio) {
3116 if (tx_priv->swr_ctrl_data)
3117 kfree(tx_priv->swr_ctrl_data);
3118 for (count = 0; count < tx_priv->child_count &&
3119 count < TX_MACRO_CHILD_DEVICES_MAX; count++)
3120 platform_device_unregister(
3121 tx_priv->pdev_child_devices[count]);
3122 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303123
Sudheer Papothi7601cc62019-03-30 03:00:52 +05303124 pm_runtime_disable(&pdev->dev);
3125 pm_runtime_set_suspended(&pdev->dev);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303126 mutex_destroy(&tx_priv->mclk_lock);
Laxminath Kasam2e13d642019-10-12 01:36:30 +05303127 if (tx_priv->is_used_tx_swr_gpio)
3128 mutex_destroy(&tx_priv->swr_clk_lock);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303129 bolero_unregister_macro(&pdev->dev, TX_MACRO);
3130 return 0;
3131}
3132
3133
3134static const struct of_device_id tx_macro_dt_match[] = {
3135 {.compatible = "qcom,tx-macro"},
3136 {}
3137};
3138
Sudheer Papothi7601cc62019-03-30 03:00:52 +05303139static const struct dev_pm_ops bolero_dev_pm_ops = {
3140 SET_RUNTIME_PM_OPS(
3141 bolero_runtime_suspend,
3142 bolero_runtime_resume,
3143 NULL
3144 )
3145};
3146
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303147static struct platform_driver tx_macro_driver = {
3148 .driver = {
3149 .name = "tx_macro",
3150 .owner = THIS_MODULE,
Sudheer Papothi7601cc62019-03-30 03:00:52 +05303151 .pm = &bolero_dev_pm_ops,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303152 .of_match_table = tx_macro_dt_match,
Xiaojun Sang53cd13a2018-06-29 15:14:37 +08003153 .suppress_bind_attrs = true,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05303154 },
3155 .probe = tx_macro_probe,
3156 .remove = tx_macro_remove,
3157};
3158
3159module_platform_driver(tx_macro_driver);
3160
3161MODULE_DESCRIPTION("TX macro driver");
3162MODULE_LICENSE("GPL v2");