blob: 177bab4bdb10ac5a7fedb68c57688d45ae4eb727 [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
Laxminath Kasam989fccf2018-06-15 16:53:31 +053044
45#define TX_MACRO_TX_UNMUTE_DELAY_MS 40
46
47static int tx_unmute_delay = TX_MACRO_TX_UNMUTE_DELAY_MS;
48module_param(tx_unmute_delay, int, 0664);
49MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
50
51static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
52
53static int tx_macro_hw_params(struct snd_pcm_substream *substream,
54 struct snd_pcm_hw_params *params,
55 struct snd_soc_dai *dai);
56static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
57 unsigned int *tx_num, unsigned int *tx_slot,
58 unsigned int *rx_num, unsigned int *rx_slot);
59
60#define TX_MACRO_SWR_STRING_LEN 80
61#define TX_MACRO_CHILD_DEVICES_MAX 3
62
63/* Hold instance to soundwire platform device */
64struct tx_macro_swr_ctrl_data {
65 struct platform_device *tx_swr_pdev;
66};
67
68struct tx_macro_swr_ctrl_platform_data {
69 void *handle; /* holds codec private data */
70 int (*read)(void *handle, int reg);
71 int (*write)(void *handle, int reg, int val);
72 int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
73 int (*clk)(void *handle, bool enable);
74 int (*handle_irq)(void *handle,
75 irqreturn_t (*swrm_irq_handler)(int irq,
76 void *data),
77 void *swrm_handle,
78 int action);
79};
80
81enum {
Laxminath Kasam59c7a1d2018-08-09 16:11:17 +053082 TX_MACRO_AIF_INVALID = 0,
83 TX_MACRO_AIF1_CAP,
Laxminath Kasam989fccf2018-06-15 16:53:31 +053084 TX_MACRO_AIF2_CAP,
85 TX_MACRO_MAX_DAIS
86};
87
88enum {
89 TX_MACRO_DEC0,
90 TX_MACRO_DEC1,
91 TX_MACRO_DEC2,
92 TX_MACRO_DEC3,
93 TX_MACRO_DEC4,
94 TX_MACRO_DEC5,
95 TX_MACRO_DEC6,
96 TX_MACRO_DEC7,
97 TX_MACRO_DEC_MAX,
98};
99
100enum {
101 TX_MACRO_CLK_DIV_2,
102 TX_MACRO_CLK_DIV_3,
103 TX_MACRO_CLK_DIV_4,
104 TX_MACRO_CLK_DIV_6,
105 TX_MACRO_CLK_DIV_8,
106 TX_MACRO_CLK_DIV_16,
107};
108
Laxminath Kasam497a6512018-09-17 16:11:52 +0530109enum {
110 MSM_DMIC,
111 SWR_MIC,
112 ANC_FB_TUNE1
113};
114
Sudheer Papothia7397942019-03-19 03:14:23 +0530115enum {
116 TX_MCLK,
117 VA_MCLK,
118};
119
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530120struct tx_mute_work {
121 struct tx_macro_priv *tx_priv;
122 u32 decimator;
123 struct delayed_work dwork;
124};
125
126struct hpf_work {
127 struct tx_macro_priv *tx_priv;
128 u8 decimator;
129 u8 hpf_cut_off_freq;
130 struct delayed_work dwork;
131};
132
133struct tx_macro_priv {
134 struct device *dev;
135 bool dec_active[NUM_DECIMATORS];
136 int tx_mclk_users;
137 int swr_clk_users;
Ramprasad Katkam452772a2019-01-07 17:30:36 +0530138 bool dapm_mclk_enable;
Ramprasad Katkama4c747b2018-12-11 19:15:53 +0530139 bool reset_swr;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530140 struct mutex mclk_lock;
141 struct mutex swr_clk_lock;
Meng Wang15c825d2018-09-06 10:49:18 +0800142 struct snd_soc_component *component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530143 struct device_node *tx_swr_gpio_p;
144 struct tx_macro_swr_ctrl_data *swr_ctrl_data;
145 struct tx_macro_swr_ctrl_platform_data swr_plat_data;
146 struct work_struct tx_macro_add_child_devices_work;
147 struct hpf_work tx_hpf_work[NUM_DECIMATORS];
148 struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
149 s32 dmic_0_1_clk_cnt;
150 s32 dmic_2_3_clk_cnt;
151 s32 dmic_4_5_clk_cnt;
152 s32 dmic_6_7_clk_cnt;
153 u16 dmic_clk_div;
154 unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
155 unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
156 char __iomem *tx_io_base;
157 struct platform_device *pdev_child_devices
158 [TX_MACRO_CHILD_DEVICES_MAX];
159 int child_count;
Sudheer Papothie456c2c2019-03-05 07:08:45 +0530160 int tx_swr_clk_cnt;
161 int va_swr_clk_cnt;
Sudheer Papothia7397942019-03-19 03:14:23 +0530162 int swr_clk_type;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530163};
164
Meng Wang15c825d2018-09-06 10:49:18 +0800165static bool tx_macro_get_data(struct snd_soc_component *component,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530166 struct device **tx_dev,
167 struct tx_macro_priv **tx_priv,
168 const char *func_name)
169{
Meng Wang15c825d2018-09-06 10:49:18 +0800170 *tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530171 if (!(*tx_dev)) {
Meng Wang15c825d2018-09-06 10:49:18 +0800172 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530173 "%s: null device for macro!\n", func_name);
174 return false;
175 }
176
177 *tx_priv = dev_get_drvdata((*tx_dev));
178 if (!(*tx_priv)) {
Meng Wang15c825d2018-09-06 10:49:18 +0800179 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530180 "%s: priv is null for macro!\n", func_name);
181 return false;
182 }
183
Meng Wang15c825d2018-09-06 10:49:18 +0800184 if (!(*tx_priv)->component) {
185 dev_err(component->dev,
186 "%s: tx_priv->component not initialized!\n", func_name);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530187 return false;
188 }
189
190 return true;
191}
192
193static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv,
194 bool mclk_enable)
195{
196 struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
197 int ret = 0;
198
Tanya Dixit8530fb92018-09-14 16:01:25 +0530199 if (regmap == NULL) {
200 dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
201 return -EINVAL;
202 }
203
Laxminath Kasamb7f823c2018-08-02 13:23:11 +0530204 dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n",
205 __func__, mclk_enable, tx_priv->tx_mclk_users);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530206
207 mutex_lock(&tx_priv->mclk_lock);
208 if (mclk_enable) {
209 if (tx_priv->tx_mclk_users == 0) {
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -0700210 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
211 TX_CORE_CLK,
212 TX_CORE_CLK,
213 true);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530214 if (ret < 0) {
215 dev_err(tx_priv->dev,
216 "%s: request clock enable failed\n",
217 __func__);
218 goto exit;
219 }
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -0700220 bolero_clk_rsc_fs_gen_request(tx_priv->dev,
221 true);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530222 regcache_mark_dirty(regmap);
223 regcache_sync_region(regmap,
224 TX_START_OFFSET,
225 TX_MAX_OFFSET);
226 /* 9.6MHz MCLK, set value 0x00 if other frequency */
227 regmap_update_bits(regmap,
228 BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
229 regmap_update_bits(regmap,
230 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
231 0x01, 0x01);
232 regmap_update_bits(regmap,
233 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
234 0x01, 0x01);
235 }
236 tx_priv->tx_mclk_users++;
237 } else {
238 if (tx_priv->tx_mclk_users <= 0) {
239 dev_err(tx_priv->dev, "%s: clock already disabled\n",
240 __func__);
241 tx_priv->tx_mclk_users = 0;
242 goto exit;
243 }
244 tx_priv->tx_mclk_users--;
245 if (tx_priv->tx_mclk_users == 0) {
246 regmap_update_bits(regmap,
247 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
248 0x01, 0x00);
249 regmap_update_bits(regmap,
250 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
251 0x01, 0x00);
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -0700252 bolero_clk_rsc_fs_gen_request(tx_priv->dev,
253 false);
254
255 bolero_clk_rsc_request_clock(tx_priv->dev,
256 TX_CORE_CLK,
257 TX_CORE_CLK,
258 false);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530259 }
260 }
261exit:
262 mutex_unlock(&tx_priv->mclk_lock);
263 return ret;
264}
265
Sudheer Papothie456c2c2019-03-05 07:08:45 +0530266static int tx_macro_va_swr_clk_event(struct snd_soc_dapm_widget *w,
267 struct snd_kcontrol *kcontrol, int event)
268{
269 struct device *tx_dev = NULL;
270 struct tx_macro_priv *tx_priv = NULL;
271 struct snd_soc_component *component =
272 snd_soc_dapm_to_component(w->dapm);
273
274 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
275 return -EINVAL;
276
277 if (SND_SOC_DAPM_EVENT_ON(event))
278 ++tx_priv->va_swr_clk_cnt;
279 if (SND_SOC_DAPM_EVENT_OFF(event))
280 --tx_priv->va_swr_clk_cnt;
281
282 return 0;
283}
284
285static int tx_macro_tx_swr_clk_event(struct snd_soc_dapm_widget *w,
286 struct snd_kcontrol *kcontrol, int event)
287{
288 struct device *tx_dev = NULL;
289 struct tx_macro_priv *tx_priv = NULL;
290 struct snd_soc_component *component =
291 snd_soc_dapm_to_component(w->dapm);
292
293 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
294 return -EINVAL;
295
296 if (SND_SOC_DAPM_EVENT_ON(event))
297 ++tx_priv->tx_swr_clk_cnt;
298 if (SND_SOC_DAPM_EVENT_OFF(event))
299 --tx_priv->tx_swr_clk_cnt;
300
301 return 0;
302}
303
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530304static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
305 struct snd_kcontrol *kcontrol, int event)
306{
Meng Wang15c825d2018-09-06 10:49:18 +0800307 struct snd_soc_component *component =
308 snd_soc_dapm_to_component(w->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530309 int ret = 0;
310 struct device *tx_dev = NULL;
311 struct tx_macro_priv *tx_priv = NULL;
312
Meng Wang15c825d2018-09-06 10:49:18 +0800313 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530314 return -EINVAL;
315
316 dev_dbg(tx_dev, "%s: event = %d\n", __func__, event);
317 switch (event) {
318 case SND_SOC_DAPM_PRE_PMU:
319 ret = tx_macro_mclk_enable(tx_priv, 1);
Ramprasad Katkam452772a2019-01-07 17:30:36 +0530320 if (ret)
321 tx_priv->dapm_mclk_enable = false;
322 else
323 tx_priv->dapm_mclk_enable = true;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530324 break;
325 case SND_SOC_DAPM_POST_PMD:
Ramprasad Katkam452772a2019-01-07 17:30:36 +0530326 if (tx_priv->dapm_mclk_enable)
327 ret = tx_macro_mclk_enable(tx_priv, 0);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530328 break;
329 default:
330 dev_err(tx_priv->dev,
331 "%s: invalid DAPM event %d\n", __func__, event);
332 ret = -EINVAL;
333 }
334 return ret;
335}
336
Meng Wang15c825d2018-09-06 10:49:18 +0800337static int tx_macro_event_handler(struct snd_soc_component *component,
338 u16 event, u32 data)
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530339{
340 struct device *tx_dev = NULL;
341 struct tx_macro_priv *tx_priv = NULL;
342
Meng Wang15c825d2018-09-06 10:49:18 +0800343 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530344 return -EINVAL;
345
346 switch (event) {
347 case BOLERO_MACRO_EVT_SSR_DOWN:
348 swrm_wcd_notify(
349 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
Ramprasad Katkam5ee54ae2018-12-19 18:56:00 +0530350 SWR_DEVICE_DOWN, NULL);
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530351 swrm_wcd_notify(
352 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
Ramprasad Katkam5ee54ae2018-12-19 18:56:00 +0530353 SWR_DEVICE_SSR_DOWN, NULL);
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530354 break;
355 case BOLERO_MACRO_EVT_SSR_UP:
Ramprasad Katkama4c747b2018-12-11 19:15:53 +0530356 /* reset swr after ssr/pdr */
357 tx_priv->reset_swr = true;
Laxminath Kasamfb0d6832018-09-22 01:49:52 +0530358 swrm_wcd_notify(
359 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
360 SWR_DEVICE_SSR_UP, NULL);
361 break;
362 }
363 return 0;
364}
365
Meng Wang15c825d2018-09-06 10:49:18 +0800366static int tx_macro_reg_wake_irq(struct snd_soc_component *component,
Aditya Bavanaric4e96122018-11-14 14:46:38 +0530367 u32 data)
368{
369 struct device *tx_dev = NULL;
370 struct tx_macro_priv *tx_priv = NULL;
371 u32 ipc_wakeup = data;
372 int ret = 0;
373
Meng Wang15c825d2018-09-06 10:49:18 +0800374 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Aditya Bavanaric4e96122018-11-14 14:46:38 +0530375 return -EINVAL;
376
377 ret = swrm_wcd_notify(
378 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
379 SWR_REGISTER_WAKE_IRQ, &ipc_wakeup);
380
381 return ret;
382}
383
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530384static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
385{
386 struct delayed_work *hpf_delayed_work = NULL;
387 struct hpf_work *hpf_work = NULL;
388 struct tx_macro_priv *tx_priv = NULL;
Meng Wang15c825d2018-09-06 10:49:18 +0800389 struct snd_soc_component *component = NULL;
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530390 u16 dec_cfg_reg = 0, hpf_gate_reg = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530391 u8 hpf_cut_off_freq = 0;
Laxminath Kasam497a6512018-09-17 16:11:52 +0530392 u16 adc_mux_reg = 0, adc_n = 0, adc_reg = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530393
394 hpf_delayed_work = to_delayed_work(work);
395 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
396 tx_priv = hpf_work->tx_priv;
Meng Wang15c825d2018-09-06 10:49:18 +0800397 component = tx_priv->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530398 hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
399
400 dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
401 TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530402 hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
403 TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530404
Meng Wang15c825d2018-09-06 10:49:18 +0800405 dev_dbg(component->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530406 __func__, hpf_work->decimator, hpf_cut_off_freq);
407
Laxminath Kasam497a6512018-09-17 16:11:52 +0530408 adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
409 TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
Meng Wang15c825d2018-09-06 10:49:18 +0800410 if (snd_soc_component_read32(component, adc_mux_reg) & SWR_MIC) {
Laxminath Kasam497a6512018-09-17 16:11:52 +0530411 adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
412 TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
Meng Wang15c825d2018-09-06 10:49:18 +0800413 adc_n = snd_soc_component_read32(component, adc_reg) &
Laxminath Kasam497a6512018-09-17 16:11:52 +0530414 TX_MACRO_SWR_MIC_MUX_SEL_MASK;
415 if (adc_n >= BOLERO_ADC_MAX)
416 goto tx_hpf_set;
417 /* analog mic clear TX hold */
Meng Wang15c825d2018-09-06 10:49:18 +0800418 bolero_clear_amic_tx_hold(component->dev, adc_n);
Laxminath Kasam497a6512018-09-17 16:11:52 +0530419 }
420tx_hpf_set:
Meng Wang15c825d2018-09-06 10:49:18 +0800421 snd_soc_component_update_bits(component,
422 dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
423 hpf_cut_off_freq << 5);
424 snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x02);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530425 /* Minimum 1 clk cycle delay is required as per HW spec */
426 usleep_range(1000, 1010);
Meng Wang15c825d2018-09-06 10:49:18 +0800427 snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x01);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530428}
429
430static void tx_macro_mute_update_callback(struct work_struct *work)
431{
432 struct tx_mute_work *tx_mute_dwork = NULL;
Meng Wang15c825d2018-09-06 10:49:18 +0800433 struct snd_soc_component *component = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530434 struct tx_macro_priv *tx_priv = NULL;
435 struct delayed_work *delayed_work = NULL;
Xiaojun Sangd155fdc2018-10-11 15:11:59 +0800436 u16 tx_vol_ctl_reg = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530437 u8 decimator = 0;
438
439 delayed_work = to_delayed_work(work);
440 tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
441 tx_priv = tx_mute_dwork->tx_priv;
Meng Wang15c825d2018-09-06 10:49:18 +0800442 component = tx_priv->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530443 decimator = tx_mute_dwork->decimator;
444
445 tx_vol_ctl_reg =
446 BOLERO_CDC_TX0_TX_PATH_CTL +
447 TX_MACRO_TX_PATH_OFFSET * decimator;
Meng Wang15c825d2018-09-06 10:49:18 +0800448 snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530449 dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
450 __func__, decimator);
451}
452
453static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
454 struct snd_ctl_elem_value *ucontrol)
455{
456 struct snd_soc_dapm_widget *widget =
457 snd_soc_dapm_kcontrol_widget(kcontrol);
Meng Wang15c825d2018-09-06 10:49:18 +0800458 struct snd_soc_component *component =
459 snd_soc_dapm_to_component(widget->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530460 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
461 unsigned int val = 0;
462 u16 mic_sel_reg = 0;
463
464 val = ucontrol->value.enumerated.item[0];
465 if (val > e->items - 1)
466 return -EINVAL;
467
Meng Wang15c825d2018-09-06 10:49:18 +0800468 dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530469 widget->name, val);
470
471 switch (e->reg) {
472 case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
473 mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
474 break;
475 case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
476 mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
477 break;
478 case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
479 mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
480 break;
481 case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
482 mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
483 break;
484 case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
485 mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
486 break;
487 case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
488 mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
489 break;
490 case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
491 mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
492 break;
493 case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
494 mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
495 break;
496 default:
Meng Wang15c825d2018-09-06 10:49:18 +0800497 dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530498 __func__, e->reg);
499 return -EINVAL;
500 }
Laxminath Kasam497a6512018-09-17 16:11:52 +0530501 if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530502 if (val != 0) {
503 if (val < 5)
Meng Wang15c825d2018-09-06 10:49:18 +0800504 snd_soc_component_update_bits(component,
505 mic_sel_reg,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530506 1 << 7, 0x0 << 7);
507 else
Meng Wang15c825d2018-09-06 10:49:18 +0800508 snd_soc_component_update_bits(component,
509 mic_sel_reg,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530510 1 << 7, 0x1 << 7);
511 }
512 } else {
513 /* DMIC selected */
514 if (val != 0)
Meng Wang15c825d2018-09-06 10:49:18 +0800515 snd_soc_component_update_bits(component, mic_sel_reg,
516 1 << 7, 1 << 7);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530517 }
518
519 return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
520}
521
522static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
523 struct snd_ctl_elem_value *ucontrol)
524{
525 struct snd_soc_dapm_widget *widget =
526 snd_soc_dapm_kcontrol_widget(kcontrol);
Meng Wang15c825d2018-09-06 10:49:18 +0800527 struct snd_soc_component *component =
528 snd_soc_dapm_to_component(widget->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530529 struct soc_multi_mixer_control *mixer =
530 ((struct soc_multi_mixer_control *)kcontrol->private_value);
531 u32 dai_id = widget->shift;
532 u32 dec_id = mixer->shift;
533 struct device *tx_dev = NULL;
534 struct tx_macro_priv *tx_priv = NULL;
535
Meng Wang15c825d2018-09-06 10:49:18 +0800536 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530537 return -EINVAL;
538
539 if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
540 ucontrol->value.integer.value[0] = 1;
541 else
542 ucontrol->value.integer.value[0] = 0;
543 return 0;
544}
545
546static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
548{
549 struct snd_soc_dapm_widget *widget =
550 snd_soc_dapm_kcontrol_widget(kcontrol);
Meng Wang15c825d2018-09-06 10:49:18 +0800551 struct snd_soc_component *component =
552 snd_soc_dapm_to_component(widget->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530553 struct snd_soc_dapm_update *update = NULL;
554 struct soc_multi_mixer_control *mixer =
555 ((struct soc_multi_mixer_control *)kcontrol->private_value);
556 u32 dai_id = widget->shift;
557 u32 dec_id = mixer->shift;
558 u32 enable = ucontrol->value.integer.value[0];
559 struct device *tx_dev = NULL;
560 struct tx_macro_priv *tx_priv = NULL;
561
Meng Wang15c825d2018-09-06 10:49:18 +0800562 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530563 return -EINVAL;
564
565 if (enable) {
566 set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
567 tx_priv->active_ch_cnt[dai_id]++;
568 } else {
569 tx_priv->active_ch_cnt[dai_id]--;
570 clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
571 }
572 snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
573
574 return 0;
575}
576
577static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
578 struct snd_kcontrol *kcontrol, int event)
579{
Meng Wang15c825d2018-09-06 10:49:18 +0800580 struct snd_soc_component *component =
581 snd_soc_dapm_to_component(w->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530582 u8 dmic_clk_en = 0x01;
583 u16 dmic_clk_reg = 0;
584 s32 *dmic_clk_cnt = NULL;
585 unsigned int dmic = 0;
586 int ret = 0;
587 char *wname = NULL;
588 struct device *tx_dev = NULL;
589 struct tx_macro_priv *tx_priv = NULL;
590
Meng Wang15c825d2018-09-06 10:49:18 +0800591 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530592 return -EINVAL;
593
594 wname = strpbrk(w->name, "01234567");
595 if (!wname) {
Meng Wang15c825d2018-09-06 10:49:18 +0800596 dev_err(component->dev, "%s: widget not found\n", __func__);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530597 return -EINVAL;
598 }
599
600 ret = kstrtouint(wname, 10, &dmic);
601 if (ret < 0) {
Meng Wang15c825d2018-09-06 10:49:18 +0800602 dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530603 __func__);
604 return -EINVAL;
605 }
606
607 switch (dmic) {
608 case 0:
609 case 1:
610 dmic_clk_cnt = &(tx_priv->dmic_0_1_clk_cnt);
611 dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL;
612 break;
613 case 2:
614 case 3:
615 dmic_clk_cnt = &(tx_priv->dmic_2_3_clk_cnt);
616 dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL;
617 break;
618 case 4:
619 case 5:
620 dmic_clk_cnt = &(tx_priv->dmic_4_5_clk_cnt);
621 dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL;
622 break;
623 case 6:
624 case 7:
625 dmic_clk_cnt = &(tx_priv->dmic_6_7_clk_cnt);
626 dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL;
627 break;
628 default:
Meng Wang15c825d2018-09-06 10:49:18 +0800629 dev_err(component->dev, "%s: Invalid DMIC Selection\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530630 __func__);
631 return -EINVAL;
632 }
Meng Wang15c825d2018-09-06 10:49:18 +0800633 dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530634 __func__, event, dmic, *dmic_clk_cnt);
635
636 switch (event) {
637 case SND_SOC_DAPM_PRE_PMU:
638 (*dmic_clk_cnt)++;
639 if (*dmic_clk_cnt == 1) {
Meng Wang15c825d2018-09-06 10:49:18 +0800640 snd_soc_component_update_bits(component,
641 BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
Ramprasad Katkam9c2394a2018-08-23 13:13:48 +0530642 0x80, 0x00);
643
Meng Wang15c825d2018-09-06 10:49:18 +0800644 snd_soc_component_update_bits(component, dmic_clk_reg,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530645 0x0E, tx_priv->dmic_clk_div << 0x1);
Meng Wang15c825d2018-09-06 10:49:18 +0800646 snd_soc_component_update_bits(component, dmic_clk_reg,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530647 dmic_clk_en, dmic_clk_en);
648 }
649 break;
650 case SND_SOC_DAPM_POST_PMD:
651 (*dmic_clk_cnt)--;
652 if (*dmic_clk_cnt == 0)
Meng Wang15c825d2018-09-06 10:49:18 +0800653 snd_soc_component_update_bits(component, dmic_clk_reg,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530654 dmic_clk_en, 0);
655 break;
656 }
657
658 return 0;
659}
660
661static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
662 struct snd_kcontrol *kcontrol, int event)
663{
Meng Wang15c825d2018-09-06 10:49:18 +0800664 struct snd_soc_component *component =
665 snd_soc_dapm_to_component(w->dapm);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530666 unsigned int decimator = 0;
667 u16 tx_vol_ctl_reg = 0;
668 u16 dec_cfg_reg = 0;
669 u16 hpf_gate_reg = 0;
670 u16 tx_gain_ctl_reg = 0;
671 u8 hpf_cut_off_freq = 0;
672 struct device *tx_dev = NULL;
673 struct tx_macro_priv *tx_priv = NULL;
674
Meng Wang15c825d2018-09-06 10:49:18 +0800675 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530676 return -EINVAL;
677
678 decimator = w->shift;
679
Meng Wang15c825d2018-09-06 10:49:18 +0800680 dev_dbg(component->dev, "%s(): widget = %s decimator = %u\n", __func__,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530681 w->name, decimator);
682
683 tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
684 TX_MACRO_TX_PATH_OFFSET * decimator;
685 hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
686 TX_MACRO_TX_PATH_OFFSET * decimator;
687 dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
688 TX_MACRO_TX_PATH_OFFSET * decimator;
689 tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
690 TX_MACRO_TX_PATH_OFFSET * decimator;
691
692 switch (event) {
693 case SND_SOC_DAPM_PRE_PMU:
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530694 /* Enable TX PGA Mute */
Meng Wang15c825d2018-09-06 10:49:18 +0800695 snd_soc_component_update_bits(component,
696 tx_vol_ctl_reg, 0x10, 0x10);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530697 break;
698 case SND_SOC_DAPM_POST_PMU:
Meng Wang15c825d2018-09-06 10:49:18 +0800699 snd_soc_component_update_bits(component,
700 tx_vol_ctl_reg, 0x20, 0x20);
701 snd_soc_component_update_bits(component,
702 hpf_gate_reg, 0x01, 0x00);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530703
Meng Wang15c825d2018-09-06 10:49:18 +0800704 hpf_cut_off_freq = (
705 snd_soc_component_read32(component, dec_cfg_reg) &
706 TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
707
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530708 tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
Meng Wang15c825d2018-09-06 10:49:18 +0800709 hpf_cut_off_freq;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530710
711 if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
Meng Wang15c825d2018-09-06 10:49:18 +0800712 snd_soc_component_update_bits(component, dec_cfg_reg,
713 TX_HPF_CUT_OFF_FREQ_MASK,
714 CF_MIN_3DB_150HZ << 5);
715
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530716 /* schedule work queue to Remove Mute */
717 schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork,
718 msecs_to_jiffies(tx_unmute_delay));
719 if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530720 CF_MIN_3DB_150HZ) {
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530721 schedule_delayed_work(
722 &tx_priv->tx_hpf_work[decimator].dwork,
Mangesh Kunchamwar3d4eec42019-03-05 15:06:48 +0530723 msecs_to_jiffies(50));
Meng Wang15c825d2018-09-06 10:49:18 +0800724 snd_soc_component_update_bits(component,
725 hpf_gate_reg, 0x02, 0x02);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530726 /*
727 * Minimum 1 clk cycle delay is required as per HW spec
728 */
729 usleep_range(1000, 1010);
Meng Wang15c825d2018-09-06 10:49:18 +0800730 snd_soc_component_update_bits(component,
731 hpf_gate_reg, 0x02, 0x00);
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530732 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530733 /* apply gain after decimator is enabled */
Meng Wang15c825d2018-09-06 10:49:18 +0800734 snd_soc_component_write(component, tx_gain_ctl_reg,
735 snd_soc_component_read32(component,
736 tx_gain_ctl_reg));
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530737 break;
738 case SND_SOC_DAPM_PRE_PMD:
739 hpf_cut_off_freq =
740 tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
Meng Wang15c825d2018-09-06 10:49:18 +0800741 snd_soc_component_update_bits(component,
742 tx_vol_ctl_reg, 0x10, 0x10);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530743 if (cancel_delayed_work_sync(
744 &tx_priv->tx_hpf_work[decimator].dwork)) {
745 if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
Meng Wang15c825d2018-09-06 10:49:18 +0800746 snd_soc_component_update_bits(
747 component, dec_cfg_reg,
748 TX_HPF_CUT_OFF_FREQ_MASK,
749 hpf_cut_off_freq << 5);
750 snd_soc_component_update_bits(component,
751 hpf_gate_reg,
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530752 0x02, 0x02);
753 /*
754 * Minimum 1 clk cycle delay is required
755 * as per HW spec
756 */
757 usleep_range(1000, 1010);
Meng Wang15c825d2018-09-06 10:49:18 +0800758 snd_soc_component_update_bits(component,
759 hpf_gate_reg,
Laxminath Kasam9eb80222018-08-29 21:53:14 +0530760 0x02, 0x00);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530761 }
762 }
763 cancel_delayed_work_sync(
764 &tx_priv->tx_mute_dwork[decimator].dwork);
765 break;
766 case SND_SOC_DAPM_POST_PMD:
Meng Wang15c825d2018-09-06 10:49:18 +0800767 snd_soc_component_update_bits(component, tx_vol_ctl_reg,
768 0x20, 0x00);
769 snd_soc_component_update_bits(component, tx_vol_ctl_reg,
770 0x10, 0x00);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530771 break;
772 }
773 return 0;
774}
775
776static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
777 struct snd_kcontrol *kcontrol, int event)
778{
779 return 0;
780}
781
782static int tx_macro_hw_params(struct snd_pcm_substream *substream,
783 struct snd_pcm_hw_params *params,
784 struct snd_soc_dai *dai)
785{
786 int tx_fs_rate = -EINVAL;
Meng Wang15c825d2018-09-06 10:49:18 +0800787 struct snd_soc_component *component = dai->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530788 u32 decimator = 0;
Laxminath Kasamb7f823c2018-08-02 13:23:11 +0530789 u32 sample_rate = 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530790 u16 tx_fs_reg = 0;
791 struct device *tx_dev = NULL;
792 struct tx_macro_priv *tx_priv = NULL;
793
Meng Wang15c825d2018-09-06 10:49:18 +0800794 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530795 return -EINVAL;
796
797 pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
798 dai->name, dai->id, params_rate(params),
799 params_channels(params));
800
801 sample_rate = params_rate(params);
802 switch (sample_rate) {
803 case 8000:
804 tx_fs_rate = 0;
805 break;
806 case 16000:
807 tx_fs_rate = 1;
808 break;
809 case 32000:
810 tx_fs_rate = 3;
811 break;
812 case 48000:
813 tx_fs_rate = 4;
814 break;
815 case 96000:
816 tx_fs_rate = 5;
817 break;
818 case 192000:
819 tx_fs_rate = 6;
820 break;
821 case 384000:
822 tx_fs_rate = 7;
823 break;
824 default:
Meng Wang15c825d2018-09-06 10:49:18 +0800825 dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530826 __func__, params_rate(params));
827 return -EINVAL;
828 }
829 for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
830 TX_MACRO_DEC_MAX) {
831 if (decimator >= 0) {
832 tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
833 TX_MACRO_TX_PATH_OFFSET * decimator;
Meng Wang15c825d2018-09-06 10:49:18 +0800834 dev_dbg(component->dev, "%s: set DEC%u rate to %u\n",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530835 __func__, decimator, sample_rate);
Meng Wang15c825d2018-09-06 10:49:18 +0800836 snd_soc_component_update_bits(component, tx_fs_reg,
837 0x0F, tx_fs_rate);
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530838 } else {
Meng Wang15c825d2018-09-06 10:49:18 +0800839 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530840 "%s: ERROR: Invalid decimator: %d\n",
841 __func__, decimator);
842 return -EINVAL;
843 }
844 }
845 return 0;
846}
847
848static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
849 unsigned int *tx_num, unsigned int *tx_slot,
850 unsigned int *rx_num, unsigned int *rx_slot)
851{
Meng Wang15c825d2018-09-06 10:49:18 +0800852 struct snd_soc_component *component = dai->component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530853 struct device *tx_dev = NULL;
854 struct tx_macro_priv *tx_priv = NULL;
855
Meng Wang15c825d2018-09-06 10:49:18 +0800856 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530857 return -EINVAL;
858
859 switch (dai->id) {
860 case TX_MACRO_AIF1_CAP:
861 case TX_MACRO_AIF2_CAP:
862 *tx_slot = tx_priv->active_ch_mask[dai->id];
863 *tx_num = tx_priv->active_ch_cnt[dai->id];
864 break;
865 default:
866 dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
867 break;
868 }
869 return 0;
870}
871
872static struct snd_soc_dai_ops tx_macro_dai_ops = {
873 .hw_params = tx_macro_hw_params,
874 .get_channel_map = tx_macro_get_channel_map,
875};
876
877static struct snd_soc_dai_driver tx_macro_dai[] = {
878 {
879 .name = "tx_macro_tx1",
880 .id = TX_MACRO_AIF1_CAP,
881 .capture = {
882 .stream_name = "TX_AIF1 Capture",
883 .rates = TX_MACRO_RATES,
884 .formats = TX_MACRO_FORMATS,
885 .rate_max = 192000,
886 .rate_min = 8000,
887 .channels_min = 1,
888 .channels_max = 8,
889 },
890 .ops = &tx_macro_dai_ops,
891 },
892 {
893 .name = "tx_macro_tx2",
894 .id = TX_MACRO_AIF2_CAP,
895 .capture = {
896 .stream_name = "TX_AIF2 Capture",
897 .rates = TX_MACRO_RATES,
898 .formats = TX_MACRO_FORMATS,
899 .rate_max = 192000,
900 .rate_min = 8000,
901 .channels_min = 1,
902 .channels_max = 8,
903 },
904 .ops = &tx_macro_dai_ops,
905 },
906};
907
908#define STRING(name) #name
909#define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
910static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
911static const struct snd_kcontrol_new name##_mux = \
912 SOC_DAPM_ENUM(STRING(name), name##_enum)
913
914#define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
915static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
916static const struct snd_kcontrol_new name##_mux = \
917 SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
918
919#define TX_MACRO_DAPM_MUX(name, shift, kctl) \
920 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
921
922static const char * const adc_mux_text[] = {
923 "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
924};
925
926TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
927 0, adc_mux_text);
928TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
929 0, adc_mux_text);
930TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
931 0, adc_mux_text);
932TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
933 0, adc_mux_text);
934TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
935 0, adc_mux_text);
936TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
937 0, adc_mux_text);
938TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
939 0, adc_mux_text);
940TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
941 0, adc_mux_text);
942
943
944static const char * const dmic_mux_text[] = {
945 "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
946 "DMIC4", "DMIC5", "DMIC6", "DMIC7"
947};
948
949TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
950 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
951 tx_macro_put_dec_enum);
952
953TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
954 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
955 tx_macro_put_dec_enum);
956
957TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
958 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
959 tx_macro_put_dec_enum);
960
961TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
962 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
963 tx_macro_put_dec_enum);
964
965TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
966 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
967 tx_macro_put_dec_enum);
968
969TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
970 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
971 tx_macro_put_dec_enum);
972
973TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
974 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
975 tx_macro_put_dec_enum);
976
977TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
978 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
979 tx_macro_put_dec_enum);
980
981static const char * const smic_mux_text[] = {
Karthikeyan Mani1475b592019-02-12 21:27:58 -0800982 "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "ADC4",
Laxminath Kasam989fccf2018-06-15 16:53:31 +0530983 "SWR_DMIC0", "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3",
984 "SWR_DMIC4", "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
985};
986
987TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
988 0, smic_mux_text, snd_soc_dapm_get_enum_double,
989 tx_macro_put_dec_enum);
990
991TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
992 0, smic_mux_text, snd_soc_dapm_get_enum_double,
993 tx_macro_put_dec_enum);
994
995TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
996 0, smic_mux_text, snd_soc_dapm_get_enum_double,
997 tx_macro_put_dec_enum);
998
999TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
1000 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1001 tx_macro_put_dec_enum);
1002
1003TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
1004 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1005 tx_macro_put_dec_enum);
1006
1007TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
1008 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1009 tx_macro_put_dec_enum);
1010
1011TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
1012 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1013 tx_macro_put_dec_enum);
1014
1015TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
1016 0, smic_mux_text, snd_soc_dapm_get_enum_double,
1017 tx_macro_put_dec_enum);
1018
1019static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
1020 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1021 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1022 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1023 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1024 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1025 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1026 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1027 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1028 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1029 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1030 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1031 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1032 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1033 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1034 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1035 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1036};
1037
1038static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
1039 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1040 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1041 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1042 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1043 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1044 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1045 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1046 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1047 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1048 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1049 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1050 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1051 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1052 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1053 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1054 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1055};
1056
1057static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
1058 SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
1059 SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
1060
1061 SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
1062 SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
1063
1064 SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
1065 tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
1066
1067 SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
1068 tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
1069
1070
1071 TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
1072 TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
1073 TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
1074 TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
1075 TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
1076 TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
1077 TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
1078 TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
1079
1080 TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
1081 TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
1082 TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
1083 TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
1084 TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
1085 TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
1086 TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
1087 TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
1088
1089 SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
1090 tx_macro_enable_micbias,
1091 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1092 SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
1093 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1094 SND_SOC_DAPM_POST_PMD),
1095
1096 SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
1097 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1098 SND_SOC_DAPM_POST_PMD),
1099
1100 SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
1101 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1102 SND_SOC_DAPM_POST_PMD),
1103
1104 SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
1105 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1106 SND_SOC_DAPM_POST_PMD),
1107
1108 SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
1109 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1110 SND_SOC_DAPM_POST_PMD),
1111
1112 SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
1113 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1114 SND_SOC_DAPM_POST_PMD),
1115
1116 SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
1117 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1118 SND_SOC_DAPM_POST_PMD),
1119
1120 SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
1121 tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1122 SND_SOC_DAPM_POST_PMD),
1123
1124 SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
1125 SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
1126 SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
1127 SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001128 SND_SOC_DAPM_INPUT("TX SWR_ADC4"),
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301129 SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
1130 SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
1131 SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
1132 SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
1133 SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
1134 SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
1135 SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
1136 SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
1137
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301138 SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301139 TX_MACRO_DEC0, 0,
1140 &tx_dec0_mux, tx_macro_enable_dec,
1141 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1142 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1143
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301144 SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301145 TX_MACRO_DEC1, 0,
1146 &tx_dec1_mux, tx_macro_enable_dec,
1147 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1148 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1149
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301150 SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301151 TX_MACRO_DEC2, 0,
1152 &tx_dec2_mux, tx_macro_enable_dec,
1153 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1154 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1155
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301156 SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301157 TX_MACRO_DEC3, 0,
1158 &tx_dec3_mux, tx_macro_enable_dec,
1159 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1160 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1161
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301162 SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301163 TX_MACRO_DEC4, 0,
1164 &tx_dec4_mux, tx_macro_enable_dec,
1165 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1166 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1167
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301168 SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301169 TX_MACRO_DEC5, 0,
1170 &tx_dec5_mux, tx_macro_enable_dec,
1171 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1172 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1173
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301174 SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301175 TX_MACRO_DEC6, 0,
1176 &tx_dec6_mux, tx_macro_enable_dec,
1177 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1178 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1179
Ramprasad Katkamf83acfb2018-08-11 23:28:57 +05301180 SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301181 TX_MACRO_DEC7, 0,
1182 &tx_dec7_mux, tx_macro_enable_dec,
1183 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1184 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1185
1186 SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
1187 tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301188
1189 SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
1190 tx_macro_tx_swr_clk_event,
1191 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1192
1193 SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
1194 tx_macro_va_swr_clk_event,
1195 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301196};
1197
1198static const struct snd_soc_dapm_route tx_audio_map[] = {
1199 {"TX_AIF1 CAP", NULL, "TX_MCLK"},
1200 {"TX_AIF2 CAP", NULL, "TX_MCLK"},
1201
1202 {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
1203 {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
1204
1205 {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1206 {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1207 {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1208 {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1209 {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1210 {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1211 {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1212 {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1213
1214 {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1215 {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1216 {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1217 {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1218 {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1219 {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1220 {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1221 {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1222
Laxminath Kasamfc281ad2018-08-06 20:19:40 +05301223 {"TX DEC0 MUX", NULL, "TX_MCLK"},
1224 {"TX DEC1 MUX", NULL, "TX_MCLK"},
1225 {"TX DEC2 MUX", NULL, "TX_MCLK"},
1226 {"TX DEC3 MUX", NULL, "TX_MCLK"},
1227 {"TX DEC4 MUX", NULL, "TX_MCLK"},
1228 {"TX DEC5 MUX", NULL, "TX_MCLK"},
1229 {"TX DEC6 MUX", NULL, "TX_MCLK"},
1230 {"TX DEC7 MUX", NULL, "TX_MCLK"},
1231
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301232 {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
1233 {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
1234 {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
1235 {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
1236 {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
1237 {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
1238 {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
1239 {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
1240 {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
1241
1242 {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301243 {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301244 {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
1245 {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
1246 {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
1247 {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001248 {"TX SMIC MUX0", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301249 {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
1250 {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
1251 {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
1252 {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
1253 {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
1254 {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
1255 {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
1256 {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
1257
1258 {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
1259 {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
1260 {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
1261 {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
1262 {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
1263 {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
1264 {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
1265 {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
1266 {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
1267
1268 {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301269 {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301270 {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
1271 {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
1272 {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
1273 {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001274 {"TX SMIC MUX1", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301275 {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
1276 {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
1277 {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
1278 {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
1279 {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
1280 {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
1281 {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
1282 {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
1283
1284 {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
1285 {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
1286 {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
1287 {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
1288 {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
1289 {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
1290 {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
1291 {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
1292 {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
1293
1294 {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301295 {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301296 {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
1297 {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
1298 {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
1299 {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001300 {"TX SMIC MUX2", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301301 {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
1302 {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
1303 {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
1304 {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
1305 {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
1306 {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
1307 {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
1308 {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
1309
1310 {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
1311 {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
1312 {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
1313 {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
1314 {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
1315 {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
1316 {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
1317 {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
1318 {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
1319
1320 {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301321 {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301322 {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
1323 {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
1324 {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
1325 {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001326 {"TX SMIC MUX3", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301327 {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
1328 {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
1329 {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
1330 {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
1331 {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
1332 {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
1333 {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
1334 {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
1335
1336 {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
1337 {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
1338 {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
1339 {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
1340 {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
1341 {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
1342 {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
1343 {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
1344 {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
1345
1346 {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301347 {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301348 {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
1349 {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
1350 {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
1351 {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001352 {"TX SMIC MUX4", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301353 {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
1354 {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
1355 {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
1356 {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
1357 {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
1358 {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
1359 {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
1360 {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
1361
1362 {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
1363 {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
1364 {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
1365 {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
1366 {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
1367 {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
1368 {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
1369 {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
1370 {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
1371
1372 {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301373 {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301374 {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
1375 {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
1376 {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
1377 {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001378 {"TX SMIC MUX5", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301379 {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
1380 {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
1381 {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
1382 {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
1383 {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
1384 {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
1385 {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
1386 {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
1387
1388 {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
1389 {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
1390 {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
1391 {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
1392 {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
1393 {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
1394 {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
1395 {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
1396 {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
1397
1398 {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301399 {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301400 {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
1401 {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
1402 {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
1403 {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001404 {"TX SMIC MUX6", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301405 {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
1406 {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
1407 {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
1408 {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
1409 {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
1410 {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
1411 {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
1412 {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
1413
1414 {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
1415 {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
1416 {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
1417 {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
1418 {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
1419 {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
1420 {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
1421 {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
1422 {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
1423
1424 {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
Sudheer Papothie456c2c2019-03-05 07:08:45 +05301425 {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301426 {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
1427 {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
1428 {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
1429 {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001430 {"TX SMIC MUX7", "ADC4", "TX SWR_ADC4"},
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301431 {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
1432 {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
1433 {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
1434 {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
1435 {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
1436 {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
1437 {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
1438 {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
1439};
1440
1441static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
1442 SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
1443 BOLERO_CDC_TX0_TX_VOL_CTL,
1444 0, -84, 40, digital_gain),
1445 SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
1446 BOLERO_CDC_TX1_TX_VOL_CTL,
1447 0, -84, 40, digital_gain),
1448 SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
1449 BOLERO_CDC_TX2_TX_VOL_CTL,
1450 0, -84, 40, digital_gain),
1451 SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
1452 BOLERO_CDC_TX3_TX_VOL_CTL,
1453 0, -84, 40, digital_gain),
1454 SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
1455 BOLERO_CDC_TX4_TX_VOL_CTL,
1456 0, -84, 40, digital_gain),
1457 SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
1458 BOLERO_CDC_TX5_TX_VOL_CTL,
1459 0, -84, 40, digital_gain),
1460 SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
1461 BOLERO_CDC_TX6_TX_VOL_CTL,
1462 0, -84, 40, digital_gain),
1463 SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
1464 BOLERO_CDC_TX7_TX_VOL_CTL,
1465 0, -84, 40, digital_gain),
1466};
1467
Sudheer Papothia7397942019-03-19 03:14:23 +05301468static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv,
1469 struct regmap *regmap, int clk_type,
1470 bool enable)
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301471{
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301472 int ret = 0;
1473
Sudheer Papothi7601cc62019-03-30 03:00:52 +05301474 dev_dbg(tx_priv->dev,
1475 "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
Sudheer Papothia7397942019-03-19 03:14:23 +05301476 __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
Sudheer Papothi7601cc62019-03-30 03:00:52 +05301477 (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
Tanya Dixit8530fb92018-09-14 16:01:25 +05301478
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301479 if (enable) {
1480 if (tx_priv->swr_clk_users == 0) {
Karthikeyan Mani01f1ba42019-02-26 18:48:15 -08001481 msm_cdc_pinctrl_select_active_state(
1482 tx_priv->tx_swr_gpio_p);
Sudheer Papothia7397942019-03-19 03:14:23 +05301483
1484 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
1485 TX_CORE_CLK,
1486 TX_CORE_CLK,
1487 true);
1488 if (clk_type == TX_MCLK) {
1489 ret = tx_macro_mclk_enable(tx_priv, 1);
1490 if (ret < 0) {
1491 msm_cdc_pinctrl_select_sleep_state(
1492 tx_priv->tx_swr_gpio_p);
1493 dev_err_ratelimited(tx_priv->dev,
1494 "%s: request clock enable failed\n",
1495 __func__);
1496 goto done;
1497 }
1498 }
1499 if (clk_type == VA_MCLK) {
1500 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
1501 TX_CORE_CLK,
1502 VA_CORE_CLK,
1503 true);
1504 if (ret < 0) {
1505 msm_cdc_pinctrl_select_sleep_state(
1506 tx_priv->tx_swr_gpio_p);
1507 dev_err_ratelimited(tx_priv->dev,
1508 "%s: swr request clk failed\n",
1509 __func__);
1510 goto done;
1511 }
1512 if (tx_priv->tx_mclk_users == 0) {
1513 regmap_update_bits(regmap,
1514 BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK,
1515 0x01, 0x01);
1516 regmap_update_bits(regmap,
1517 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
1518 0x01, 0x01);
1519 regmap_update_bits(regmap,
1520 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
1521 0x01, 0x01);
1522 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301523 }
Sudheer Papothi7601cc62019-03-30 03:00:52 +05301524 dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n",
1525 __func__, tx_priv->reset_swr);
Ramprasad Katkama4c747b2018-12-11 19:15:53 +05301526 if (tx_priv->reset_swr)
1527 regmap_update_bits(regmap,
1528 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1529 0x02, 0x02);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301530 regmap_update_bits(regmap,
1531 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1532 0x01, 0x01);
Ramprasad Katkama4c747b2018-12-11 19:15:53 +05301533 if (tx_priv->reset_swr)
1534 regmap_update_bits(regmap,
1535 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1536 0x02, 0x00);
Sudheer Papothia7397942019-03-19 03:14:23 +05301537 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
1538 TX_CORE_CLK,
1539 TX_CORE_CLK,
1540 false);
Ramprasad Katkama4c747b2018-12-11 19:15:53 +05301541 tx_priv->reset_swr = false;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301542 }
1543 tx_priv->swr_clk_users++;
1544 } else {
1545 if (tx_priv->swr_clk_users <= 0) {
Sudheer Papothia7397942019-03-19 03:14:23 +05301546 dev_err_ratelimited(tx_priv->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301547 "tx swrm clock users already 0\n");
1548 tx_priv->swr_clk_users = 0;
Sudheer Papothia7397942019-03-19 03:14:23 +05301549 return 0;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301550 }
1551 tx_priv->swr_clk_users--;
1552 if (tx_priv->swr_clk_users == 0) {
Sudheer Papothia7397942019-03-19 03:14:23 +05301553 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
1554 TX_CORE_CLK,
1555 TX_CORE_CLK,
1556 true);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301557 regmap_update_bits(regmap,
1558 BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1559 0x01, 0x00);
Sudheer Papothia7397942019-03-19 03:14:23 +05301560 if (clk_type == TX_MCLK)
1561 tx_macro_mclk_enable(tx_priv, 0);
1562 if (clk_type == VA_MCLK) {
1563 if (tx_priv->tx_mclk_users == 0) {
1564 regmap_update_bits(regmap,
1565 BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
1566 0x01, 0x00);
1567 regmap_update_bits(regmap,
1568 BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
1569 0x01, 0x00);
1570 }
1571 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
1572 TX_CORE_CLK,
1573 VA_CORE_CLK,
1574 false);
1575 if (ret < 0) {
1576 dev_err_ratelimited(tx_priv->dev,
1577 "%s: swr request clk failed\n",
1578 __func__);
1579 goto done;
1580 }
1581 }
1582 ret = bolero_clk_rsc_request_clock(tx_priv->dev,
1583 TX_CORE_CLK,
1584 TX_CORE_CLK,
1585 false);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301586 msm_cdc_pinctrl_select_sleep_state(
1587 tx_priv->tx_swr_gpio_p);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301588 }
1589 }
Sudheer Papothia7397942019-03-19 03:14:23 +05301590 return 0;
1591
1592done:
1593 bolero_clk_rsc_request_clock(tx_priv->dev,
1594 TX_CORE_CLK,
1595 TX_CORE_CLK,
1596 false);
1597 return ret;
1598}
1599
1600static int tx_macro_swrm_clock(void *handle, bool enable)
1601{
1602 struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
1603 struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
1604 int ret = 0;
1605
1606 if (regmap == NULL) {
1607 dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
1608 return -EINVAL;
1609 }
1610
1611 mutex_lock(&tx_priv->swr_clk_lock);
1612 dev_dbg(tx_priv->dev, "%s: swrm clock %s\n",
1613 __func__, (enable ? "enable" : "disable"));
1614
1615 if (enable) {
Sudheer Papothi7601cc62019-03-30 03:00:52 +05301616 pm_runtime_get_sync(tx_priv->dev);
Sudheer Papothia7397942019-03-19 03:14:23 +05301617 /*For standalone VA usecase, enable VA macro clock */
1618 if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt
1619 && (tx_priv->swr_clk_type == TX_MCLK)) {
1620 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
1621 VA_MCLK, enable);
1622 if (ret)
1623 goto done;
1624 tx_priv->swr_clk_type = VA_MCLK;
1625 } else {
1626 /* Disable VA MCLK if its already enabled */
1627 if (tx_priv->swr_clk_type == VA_MCLK)
1628 tx_macro_tx_va_mclk_enable(tx_priv,
1629 regmap, VA_MCLK, false);
1630 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
1631 TX_MCLK, enable);
1632 if (ret)
1633 goto done;
1634 tx_priv->swr_clk_type = TX_MCLK;
1635 }
Sudheer Papothi7601cc62019-03-30 03:00:52 +05301636 pm_runtime_mark_last_busy(tx_priv->dev);
1637 pm_runtime_put_autosuspend(tx_priv->dev);
Sudheer Papothia7397942019-03-19 03:14:23 +05301638 } else {
1639 if (tx_priv->swr_clk_type == VA_MCLK) {
1640 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
1641 VA_MCLK, enable);
1642 if (ret)
1643 goto done;
1644 tx_priv->swr_clk_type = TX_MCLK;
1645 } else {
1646 ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
1647 TX_MCLK, enable);
1648 if (tx_priv->va_swr_clk_cnt) {
1649 ret = tx_macro_tx_va_mclk_enable(tx_priv,
1650 regmap, VA_MCLK, true);
1651 if (ret)
1652 goto done;
1653 tx_priv->swr_clk_type = VA_MCLK;
1654 }
1655 }
1656 }
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301657 dev_dbg(tx_priv->dev, "%s: swrm clock users %d\n",
1658 __func__, tx_priv->swr_clk_users);
Sudheer Papothia7397942019-03-19 03:14:23 +05301659done:
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301660 mutex_unlock(&tx_priv->swr_clk_lock);
1661 return ret;
1662}
1663
1664static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
1665 struct tx_macro_priv *tx_priv)
1666{
1667 u32 div_factor = TX_MACRO_CLK_DIV_2;
1668 u32 mclk_rate = TX_MACRO_MCLK_FREQ;
1669
1670 if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
1671 mclk_rate % dmic_sample_rate != 0)
1672 goto undefined_rate;
1673
1674 div_factor = mclk_rate / dmic_sample_rate;
1675
1676 switch (div_factor) {
1677 case 2:
1678 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
1679 break;
1680 case 3:
1681 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
1682 break;
1683 case 4:
1684 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
1685 break;
1686 case 6:
1687 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
1688 break;
1689 case 8:
1690 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
1691 break;
1692 case 16:
1693 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
1694 break;
1695 default:
1696 /* Any other DIV factor is invalid */
1697 goto undefined_rate;
1698 }
1699
1700 /* Valid dmic DIV factors */
1701 dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
1702 __func__, div_factor, mclk_rate);
1703
1704 return dmic_sample_rate;
1705
1706undefined_rate:
1707 dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
1708 __func__, dmic_sample_rate, mclk_rate);
1709 dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
1710
1711 return dmic_sample_rate;
1712}
1713
Meng Wang15c825d2018-09-06 10:49:18 +08001714static int tx_macro_init(struct snd_soc_component *component)
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301715{
Meng Wang15c825d2018-09-06 10:49:18 +08001716 struct snd_soc_dapm_context *dapm =
1717 snd_soc_component_get_dapm(component);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301718 int ret = 0, i = 0;
1719 struct device *tx_dev = NULL;
1720 struct tx_macro_priv *tx_priv = NULL;
1721
Meng Wang15c825d2018-09-06 10:49:18 +08001722 tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301723 if (!tx_dev) {
Meng Wang15c825d2018-09-06 10:49:18 +08001724 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301725 "%s: null device for macro!\n", __func__);
1726 return -EINVAL;
1727 }
1728 tx_priv = dev_get_drvdata(tx_dev);
1729 if (!tx_priv) {
Meng Wang15c825d2018-09-06 10:49:18 +08001730 dev_err(component->dev,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301731 "%s: priv is null for macro!\n", __func__);
1732 return -EINVAL;
1733 }
1734 ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
1735 ARRAY_SIZE(tx_macro_dapm_widgets));
1736 if (ret < 0) {
1737 dev_err(tx_dev, "%s: Failed to add controls\n", __func__);
1738 return ret;
1739 }
1740
1741 ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
1742 ARRAY_SIZE(tx_audio_map));
1743 if (ret < 0) {
1744 dev_err(tx_dev, "%s: Failed to add routes\n", __func__);
1745 return ret;
1746 }
1747
1748 ret = snd_soc_dapm_new_widgets(dapm->card);
1749 if (ret < 0) {
1750 dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
1751 return ret;
1752 }
1753
Meng Wang15c825d2018-09-06 10:49:18 +08001754 ret = snd_soc_add_component_controls(component, tx_macro_snd_controls,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301755 ARRAY_SIZE(tx_macro_snd_controls));
1756 if (ret < 0) {
1757 dev_err(tx_dev, "%s: Failed to add snd_ctls\n", __func__);
1758 return ret;
1759 }
Laxminath Kasam638b5602018-09-24 13:19:52 +05301760
1761 snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
1762 snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
1763 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
1764 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
1765 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
1766 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
Karthikeyan Mani1475b592019-02-12 21:27:58 -08001767 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC4");
Vatsal Bucha39ead2c2018-12-14 12:22:46 +05301768 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0");
1769 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1");
1770 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2");
1771 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3");
1772 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4");
1773 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5");
1774 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6");
1775 snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7");
Laxminath Kasam638b5602018-09-24 13:19:52 +05301776 snd_soc_dapm_sync(dapm);
1777
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301778 for (i = 0; i < NUM_DECIMATORS; i++) {
1779 tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
1780 tx_priv->tx_hpf_work[i].decimator = i;
1781 INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
1782 tx_macro_tx_hpf_corner_freq_callback);
1783 }
1784
1785 for (i = 0; i < NUM_DECIMATORS; i++) {
1786 tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
1787 tx_priv->tx_mute_dwork[i].decimator = i;
1788 INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
1789 tx_macro_mute_update_callback);
1790 }
Meng Wang15c825d2018-09-06 10:49:18 +08001791 tx_priv->component = component;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301792
1793 return 0;
1794}
1795
Meng Wang15c825d2018-09-06 10:49:18 +08001796static int tx_macro_deinit(struct snd_soc_component *component)
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301797{
1798 struct device *tx_dev = NULL;
1799 struct tx_macro_priv *tx_priv = NULL;
1800
Meng Wang15c825d2018-09-06 10:49:18 +08001801 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301802 return -EINVAL;
1803
Meng Wang15c825d2018-09-06 10:49:18 +08001804 tx_priv->component = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301805 return 0;
1806}
1807
1808static void tx_macro_add_child_devices(struct work_struct *work)
1809{
1810 struct tx_macro_priv *tx_priv = NULL;
1811 struct platform_device *pdev = NULL;
1812 struct device_node *node = NULL;
1813 struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
1814 int ret = 0;
1815 u16 count = 0, ctrl_num = 0;
1816 struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
1817 char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
1818 bool tx_swr_master_node = false;
1819
1820 tx_priv = container_of(work, struct tx_macro_priv,
1821 tx_macro_add_child_devices_work);
1822 if (!tx_priv) {
1823 pr_err("%s: Memory for tx_priv does not exist\n",
1824 __func__);
1825 return;
1826 }
1827
1828 if (!tx_priv->dev) {
1829 pr_err("%s: tx dev does not exist\n", __func__);
1830 return;
1831 }
1832
1833 if (!tx_priv->dev->of_node) {
1834 dev_err(tx_priv->dev,
1835 "%s: DT node for tx_priv does not exist\n", __func__);
1836 return;
1837 }
1838
1839 platdata = &tx_priv->swr_plat_data;
1840 tx_priv->child_count = 0;
1841
1842 for_each_available_child_of_node(tx_priv->dev->of_node, node) {
1843 tx_swr_master_node = false;
1844 if (strnstr(node->name, "tx_swr_master",
1845 strlen("tx_swr_master")) != NULL)
1846 tx_swr_master_node = true;
1847
1848 if (tx_swr_master_node)
1849 strlcpy(plat_dev_name, "tx_swr_ctrl",
1850 (TX_MACRO_SWR_STRING_LEN - 1));
1851 else
1852 strlcpy(plat_dev_name, node->name,
1853 (TX_MACRO_SWR_STRING_LEN - 1));
1854
1855 pdev = platform_device_alloc(plat_dev_name, -1);
1856 if (!pdev) {
1857 dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
1858 __func__);
1859 ret = -ENOMEM;
1860 goto err;
1861 }
1862 pdev->dev.parent = tx_priv->dev;
1863 pdev->dev.of_node = node;
1864
1865 if (tx_swr_master_node) {
1866 ret = platform_device_add_data(pdev, platdata,
1867 sizeof(*platdata));
1868 if (ret) {
1869 dev_err(&pdev->dev,
1870 "%s: cannot add plat data ctrl:%d\n",
1871 __func__, ctrl_num);
1872 goto fail_pdev_add;
1873 }
1874 }
1875
1876 ret = platform_device_add(pdev);
1877 if (ret) {
1878 dev_err(&pdev->dev,
1879 "%s: Cannot add platform device\n",
1880 __func__);
1881 goto fail_pdev_add;
1882 }
1883
1884 if (tx_swr_master_node) {
1885 temp = krealloc(swr_ctrl_data,
1886 (ctrl_num + 1) * sizeof(
1887 struct tx_macro_swr_ctrl_data),
1888 GFP_KERNEL);
1889 if (!temp) {
1890 ret = -ENOMEM;
1891 goto fail_pdev_add;
1892 }
1893 swr_ctrl_data = temp;
1894 swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
1895 ctrl_num++;
1896 dev_dbg(&pdev->dev,
1897 "%s: Added soundwire ctrl device(s)\n",
1898 __func__);
1899 tx_priv->swr_ctrl_data = swr_ctrl_data;
1900 }
1901 if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
1902 tx_priv->pdev_child_devices[
1903 tx_priv->child_count++] = pdev;
1904 else
1905 goto err;
1906 }
1907 return;
1908fail_pdev_add:
1909 for (count = 0; count < tx_priv->child_count; count++)
1910 platform_device_put(tx_priv->pdev_child_devices[count]);
1911err:
1912 return;
1913}
1914
Sudheer Papothia3e969d2018-10-27 06:22:10 +05301915static int tx_macro_set_port_map(struct snd_soc_component *component,
1916 u32 usecase, u32 size, void *data)
1917{
1918 struct device *tx_dev = NULL;
1919 struct tx_macro_priv *tx_priv = NULL;
1920 struct swrm_port_config port_cfg;
1921 int ret = 0;
1922
1923 if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
1924 return -EINVAL;
1925
1926 memset(&port_cfg, 0, sizeof(port_cfg));
1927 port_cfg.uc = usecase;
1928 port_cfg.size = size;
1929 port_cfg.params = data;
1930
1931 ret = swrm_wcd_notify(
1932 tx_priv->swr_ctrl_data[0].tx_swr_pdev,
1933 SWR_SET_PORT_MAP, &port_cfg);
1934
1935 return ret;
1936}
1937
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301938static void tx_macro_init_ops(struct macro_ops *ops,
1939 char __iomem *tx_io_base)
1940{
1941 memset(ops, 0, sizeof(struct macro_ops));
1942 ops->init = tx_macro_init;
1943 ops->exit = tx_macro_deinit;
1944 ops->io_base = tx_io_base;
1945 ops->dai_ptr = tx_macro_dai;
1946 ops->num_dais = ARRAY_SIZE(tx_macro_dai);
Laxminath Kasamfb0d6832018-09-22 01:49:52 +05301947 ops->event_handler = tx_macro_event_handler;
Aditya Bavanaric4e96122018-11-14 14:46:38 +05301948 ops->reg_wake_irq = tx_macro_reg_wake_irq;
Sudheer Papothia3e969d2018-10-27 06:22:10 +05301949 ops->set_port_map = tx_macro_set_port_map;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301950}
1951
1952static int tx_macro_probe(struct platform_device *pdev)
1953{
1954 struct macro_ops ops = {0};
1955 struct tx_macro_priv *tx_priv = NULL;
1956 u32 tx_base_addr = 0, sample_rate = 0;
1957 char __iomem *tx_io_base = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05301958 int ret = 0;
1959 const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
1960
1961 tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
1962 GFP_KERNEL);
1963 if (!tx_priv)
1964 return -ENOMEM;
1965 platform_set_drvdata(pdev, tx_priv);
1966
1967 tx_priv->dev = &pdev->dev;
1968 ret = of_property_read_u32(pdev->dev.of_node, "reg",
1969 &tx_base_addr);
1970 if (ret) {
1971 dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
1972 __func__, "reg");
1973 return ret;
1974 }
1975 dev_set_drvdata(&pdev->dev, tx_priv);
1976 tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
1977 "qcom,tx-swr-gpios", 0);
1978 if (!tx_priv->tx_swr_gpio_p) {
1979 dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
1980 __func__);
1981 return -EINVAL;
1982 }
1983 tx_io_base = devm_ioremap(&pdev->dev,
1984 tx_base_addr, TX_MACRO_MAX_OFFSET);
1985 if (!tx_io_base) {
1986 dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
1987 return -ENOMEM;
1988 }
1989 tx_priv->tx_io_base = tx_io_base;
1990 ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
1991 &sample_rate);
1992 if (ret) {
1993 dev_err(&pdev->dev,
1994 "%s: could not find sample_rate entry in dt\n",
1995 __func__);
1996 tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
1997 } else {
1998 if (tx_macro_validate_dmic_sample_rate(
1999 sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
2000 return -EINVAL;
2001 }
Ramprasad Katkama4c747b2018-12-11 19:15:53 +05302002 tx_priv->reset_swr = true;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302003 INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
2004 tx_macro_add_child_devices);
2005 tx_priv->swr_plat_data.handle = (void *) tx_priv;
2006 tx_priv->swr_plat_data.read = NULL;
2007 tx_priv->swr_plat_data.write = NULL;
2008 tx_priv->swr_plat_data.bulk_write = NULL;
2009 tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
2010 tx_priv->swr_plat_data.handle_irq = NULL;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302011
2012 mutex_init(&tx_priv->mclk_lock);
2013 mutex_init(&tx_priv->swr_clk_lock);
2014 tx_macro_init_ops(&ops, tx_io_base);
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -07002015 ops.clk_id_req = TX_CORE_CLK;
2016 ops.default_clk_id = TX_CORE_CLK;
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302017 ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
2018 if (ret) {
2019 dev_err(&pdev->dev,
2020 "%s: register macro failed\n", __func__);
2021 goto err_reg_macro;
2022 }
Vidyakumar Athota5d45f4c2019-03-10 22:35:07 -07002023
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302024 schedule_work(&tx_priv->tx_macro_add_child_devices_work);
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302025 pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
2026 pm_runtime_use_autosuspend(&pdev->dev);
2027 pm_runtime_set_suspended(&pdev->dev);
2028 pm_runtime_enable(&pdev->dev);
2029
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302030 return 0;
2031err_reg_macro:
2032 mutex_destroy(&tx_priv->mclk_lock);
2033 mutex_destroy(&tx_priv->swr_clk_lock);
2034 return ret;
2035}
2036
2037static int tx_macro_remove(struct platform_device *pdev)
2038{
2039 struct tx_macro_priv *tx_priv = NULL;
2040 u16 count = 0;
2041
2042 tx_priv = platform_get_drvdata(pdev);
2043
2044 if (!tx_priv)
2045 return -EINVAL;
2046
2047 kfree(tx_priv->swr_ctrl_data);
2048 for (count = 0; count < tx_priv->child_count &&
2049 count < TX_MACRO_CHILD_DEVICES_MAX; count++)
2050 platform_device_unregister(tx_priv->pdev_child_devices[count]);
2051
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302052 pm_runtime_disable(&pdev->dev);
2053 pm_runtime_set_suspended(&pdev->dev);
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302054 mutex_destroy(&tx_priv->mclk_lock);
2055 mutex_destroy(&tx_priv->swr_clk_lock);
2056 bolero_unregister_macro(&pdev->dev, TX_MACRO);
2057 return 0;
2058}
2059
2060
2061static const struct of_device_id tx_macro_dt_match[] = {
2062 {.compatible = "qcom,tx-macro"},
2063 {}
2064};
2065
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302066static const struct dev_pm_ops bolero_dev_pm_ops = {
2067 SET_RUNTIME_PM_OPS(
2068 bolero_runtime_suspend,
2069 bolero_runtime_resume,
2070 NULL
2071 )
2072};
2073
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302074static struct platform_driver tx_macro_driver = {
2075 .driver = {
2076 .name = "tx_macro",
2077 .owner = THIS_MODULE,
Sudheer Papothi7601cc62019-03-30 03:00:52 +05302078 .pm = &bolero_dev_pm_ops,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302079 .of_match_table = tx_macro_dt_match,
Xiaojun Sang53cd13a2018-06-29 15:14:37 +08002080 .suppress_bind_attrs = true,
Laxminath Kasam989fccf2018-06-15 16:53:31 +05302081 },
2082 .probe = tx_macro_probe,
2083 .remove = tx_macro_remove,
2084};
2085
2086module_platform_driver(tx_macro_driver);
2087
2088MODULE_DESCRIPTION("TX macro driver");
2089MODULE_LICENSE("GPL v2");