tx-macro.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. /* Copyright (c) 2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regmap.h>
  18. #include <sound/soc.h>
  19. #include <sound/soc-dapm.h>
  20. #include <sound/tlv.h>
  21. #include "bolero-cdc.h"
  22. #include "bolero-cdc-registers.h"
  23. #include "../msm-cdc-pinctrl.h"
  24. #define TX_MACRO_MAX_OFFSET 0x1000
  25. #define NUM_DECIMATORS 8
  26. #define TX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  27. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  28. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  29. #define TX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  30. SNDRV_PCM_FMTBIT_S24_LE |\
  31. SNDRV_PCM_FMTBIT_S24_3LE)
  32. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  33. #define CF_MIN_3DB_4HZ 0x0
  34. #define CF_MIN_3DB_75HZ 0x1
  35. #define CF_MIN_3DB_150HZ 0x2
  36. #define TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0
  37. #define TX_MACRO_MCLK_FREQ 9600000
  38. #define TX_MACRO_TX_PATH_OFFSET 0x80
  39. #define TX_MACRO_TX_UNMUTE_DELAY_MS 40
  40. static int tx_unmute_delay = TX_MACRO_TX_UNMUTE_DELAY_MS;
  41. module_param(tx_unmute_delay, int, 0664);
  42. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  43. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  44. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  45. struct snd_pcm_hw_params *params,
  46. struct snd_soc_dai *dai);
  47. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  48. unsigned int *tx_num, unsigned int *tx_slot,
  49. unsigned int *rx_num, unsigned int *rx_slot);
  50. #define TX_MACRO_SWR_STRING_LEN 80
  51. #define TX_MACRO_CHILD_DEVICES_MAX 3
  52. /* Hold instance to soundwire platform device */
  53. struct tx_macro_swr_ctrl_data {
  54. struct platform_device *tx_swr_pdev;
  55. };
  56. struct tx_macro_swr_ctrl_platform_data {
  57. void *handle; /* holds codec private data */
  58. int (*read)(void *handle, int reg);
  59. int (*write)(void *handle, int reg, int val);
  60. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  61. int (*clk)(void *handle, bool enable);
  62. int (*handle_irq)(void *handle,
  63. irqreturn_t (*swrm_irq_handler)(int irq,
  64. void *data),
  65. void *swrm_handle,
  66. int action);
  67. };
  68. enum {
  69. TX_MACRO_AIF_INVALID = 0,
  70. TX_MACRO_AIF1_CAP,
  71. TX_MACRO_AIF2_CAP,
  72. TX_MACRO_MAX_DAIS
  73. };
  74. enum {
  75. TX_MACRO_DEC0,
  76. TX_MACRO_DEC1,
  77. TX_MACRO_DEC2,
  78. TX_MACRO_DEC3,
  79. TX_MACRO_DEC4,
  80. TX_MACRO_DEC5,
  81. TX_MACRO_DEC6,
  82. TX_MACRO_DEC7,
  83. TX_MACRO_DEC_MAX,
  84. };
  85. enum {
  86. TX_MACRO_CLK_DIV_2,
  87. TX_MACRO_CLK_DIV_3,
  88. TX_MACRO_CLK_DIV_4,
  89. TX_MACRO_CLK_DIV_6,
  90. TX_MACRO_CLK_DIV_8,
  91. TX_MACRO_CLK_DIV_16,
  92. };
  93. struct tx_mute_work {
  94. struct tx_macro_priv *tx_priv;
  95. u32 decimator;
  96. struct delayed_work dwork;
  97. };
  98. struct hpf_work {
  99. struct tx_macro_priv *tx_priv;
  100. u8 decimator;
  101. u8 hpf_cut_off_freq;
  102. struct delayed_work dwork;
  103. };
  104. struct tx_macro_priv {
  105. struct device *dev;
  106. bool dec_active[NUM_DECIMATORS];
  107. int tx_mclk_users;
  108. int swr_clk_users;
  109. struct clk *tx_core_clk;
  110. struct clk *tx_npl_clk;
  111. struct mutex mclk_lock;
  112. struct mutex swr_clk_lock;
  113. struct snd_soc_codec *codec;
  114. struct device_node *tx_swr_gpio_p;
  115. struct tx_macro_swr_ctrl_data *swr_ctrl_data;
  116. struct tx_macro_swr_ctrl_platform_data swr_plat_data;
  117. struct work_struct tx_macro_add_child_devices_work;
  118. struct hpf_work tx_hpf_work[NUM_DECIMATORS];
  119. struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
  120. s32 dmic_0_1_clk_cnt;
  121. s32 dmic_2_3_clk_cnt;
  122. s32 dmic_4_5_clk_cnt;
  123. s32 dmic_6_7_clk_cnt;
  124. u16 dmic_clk_div;
  125. unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
  126. unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
  127. char __iomem *tx_io_base;
  128. struct platform_device *pdev_child_devices
  129. [TX_MACRO_CHILD_DEVICES_MAX];
  130. int child_count;
  131. };
  132. static bool tx_macro_get_data(struct snd_soc_codec *codec,
  133. struct device **tx_dev,
  134. struct tx_macro_priv **tx_priv,
  135. const char *func_name)
  136. {
  137. *tx_dev = bolero_get_device_ptr(codec->dev, TX_MACRO);
  138. if (!(*tx_dev)) {
  139. dev_err(codec->dev,
  140. "%s: null device for macro!\n", func_name);
  141. return false;
  142. }
  143. *tx_priv = dev_get_drvdata((*tx_dev));
  144. if (!(*tx_priv)) {
  145. dev_err(codec->dev,
  146. "%s: priv is null for macro!\n", func_name);
  147. return false;
  148. }
  149. if (!(*tx_priv)->codec) {
  150. dev_err(codec->dev,
  151. "%s: tx_priv->codec not initialized!\n", func_name);
  152. return false;
  153. }
  154. return true;
  155. }
  156. static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv,
  157. bool mclk_enable)
  158. {
  159. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  160. int ret = 0;
  161. if (regmap == NULL) {
  162. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  163. return -EINVAL;
  164. }
  165. dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n",
  166. __func__, mclk_enable, tx_priv->tx_mclk_users);
  167. mutex_lock(&tx_priv->mclk_lock);
  168. if (mclk_enable) {
  169. if (tx_priv->tx_mclk_users == 0) {
  170. ret = bolero_request_clock(tx_priv->dev,
  171. TX_MACRO, MCLK_MUX0, true);
  172. if (ret < 0) {
  173. dev_err(tx_priv->dev,
  174. "%s: request clock enable failed\n",
  175. __func__);
  176. goto exit;
  177. }
  178. regcache_mark_dirty(regmap);
  179. regcache_sync_region(regmap,
  180. TX_START_OFFSET,
  181. TX_MAX_OFFSET);
  182. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  183. regmap_update_bits(regmap,
  184. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
  185. regmap_update_bits(regmap,
  186. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  187. 0x01, 0x01);
  188. regmap_update_bits(regmap,
  189. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  190. 0x01, 0x01);
  191. }
  192. tx_priv->tx_mclk_users++;
  193. } else {
  194. if (tx_priv->tx_mclk_users <= 0) {
  195. dev_err(tx_priv->dev, "%s: clock already disabled\n",
  196. __func__);
  197. tx_priv->tx_mclk_users = 0;
  198. goto exit;
  199. }
  200. tx_priv->tx_mclk_users--;
  201. if (tx_priv->tx_mclk_users == 0) {
  202. regmap_update_bits(regmap,
  203. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  204. 0x01, 0x00);
  205. regmap_update_bits(regmap,
  206. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  207. 0x01, 0x00);
  208. bolero_request_clock(tx_priv->dev,
  209. TX_MACRO, MCLK_MUX0, false);
  210. }
  211. }
  212. exit:
  213. mutex_unlock(&tx_priv->mclk_lock);
  214. return ret;
  215. }
  216. static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  217. struct snd_kcontrol *kcontrol, int event)
  218. {
  219. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  220. int ret = 0;
  221. struct device *tx_dev = NULL;
  222. struct tx_macro_priv *tx_priv = NULL;
  223. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  224. return -EINVAL;
  225. dev_dbg(tx_dev, "%s: event = %d\n", __func__, event);
  226. switch (event) {
  227. case SND_SOC_DAPM_PRE_PMU:
  228. ret = tx_macro_mclk_enable(tx_priv, 1);
  229. break;
  230. case SND_SOC_DAPM_POST_PMD:
  231. ret = tx_macro_mclk_enable(tx_priv, 0);
  232. break;
  233. default:
  234. dev_err(tx_priv->dev,
  235. "%s: invalid DAPM event %d\n", __func__, event);
  236. ret = -EINVAL;
  237. }
  238. return ret;
  239. }
  240. static int tx_macro_mclk_ctrl(struct device *dev, bool enable)
  241. {
  242. struct tx_macro_priv *tx_priv = dev_get_drvdata(dev);
  243. int ret = 0;
  244. if (enable) {
  245. ret = clk_prepare_enable(tx_priv->tx_core_clk);
  246. if (ret < 0) {
  247. dev_err(dev, "%s:tx mclk enable failed\n", __func__);
  248. goto exit;
  249. }
  250. ret = clk_prepare_enable(tx_priv->tx_npl_clk);
  251. if (ret < 0) {
  252. dev_err(dev, "%s:tx npl_clk enable failed\n",
  253. __func__);
  254. clk_disable_unprepare(tx_priv->tx_core_clk);
  255. goto exit;
  256. }
  257. } else {
  258. clk_disable_unprepare(tx_priv->tx_npl_clk);
  259. clk_disable_unprepare(tx_priv->tx_core_clk);
  260. }
  261. exit:
  262. return ret;
  263. }
  264. static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  265. {
  266. struct delayed_work *hpf_delayed_work = NULL;
  267. struct hpf_work *hpf_work = NULL;
  268. struct tx_macro_priv *tx_priv = NULL;
  269. struct snd_soc_codec *codec = NULL;
  270. u16 dec_cfg_reg = 0, hpf_gate_reg = 0;
  271. u8 hpf_cut_off_freq = 0;
  272. hpf_delayed_work = to_delayed_work(work);
  273. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  274. tx_priv = hpf_work->tx_priv;
  275. codec = tx_priv->codec;
  276. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  277. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  278. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  279. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  280. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  281. dev_dbg(codec->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  282. __func__, hpf_work->decimator, hpf_cut_off_freq);
  283. snd_soc_update_bits(codec, dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  284. hpf_cut_off_freq << 5);
  285. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02);
  286. /* Minimum 1 clk cycle delay is required as per HW spec */
  287. usleep_range(1000, 1010);
  288. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00);
  289. }
  290. static void tx_macro_mute_update_callback(struct work_struct *work)
  291. {
  292. struct tx_mute_work *tx_mute_dwork = NULL;
  293. struct snd_soc_codec *codec = NULL;
  294. struct tx_macro_priv *tx_priv = NULL;
  295. struct delayed_work *delayed_work = NULL;
  296. u16 tx_vol_ctl_reg = 0, hpf_gate_reg = 0;
  297. u8 decimator = 0;
  298. delayed_work = to_delayed_work(work);
  299. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  300. tx_priv = tx_mute_dwork->tx_priv;
  301. codec = tx_priv->codec;
  302. decimator = tx_mute_dwork->decimator;
  303. tx_vol_ctl_reg =
  304. BOLERO_CDC_TX0_TX_PATH_CTL +
  305. TX_MACRO_TX_PATH_OFFSET * decimator;
  306. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  307. TX_MACRO_TX_PATH_OFFSET * decimator;
  308. snd_soc_update_bits(codec, hpf_gate_reg, 0x01, 0x01);
  309. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  310. dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
  311. __func__, decimator);
  312. }
  313. static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  314. struct snd_ctl_elem_value *ucontrol)
  315. {
  316. struct snd_soc_dapm_widget *widget =
  317. snd_soc_dapm_kcontrol_widget(kcontrol);
  318. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  319. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  320. unsigned int val = 0;
  321. u16 mic_sel_reg = 0;
  322. val = ucontrol->value.enumerated.item[0];
  323. if (val > e->items - 1)
  324. return -EINVAL;
  325. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  326. widget->name, val);
  327. switch (e->reg) {
  328. case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
  329. mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
  330. break;
  331. case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
  332. mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
  333. break;
  334. case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
  335. mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
  336. break;
  337. case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
  338. mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
  339. break;
  340. case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
  341. mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
  342. break;
  343. case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
  344. mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
  345. break;
  346. case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
  347. mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
  348. break;
  349. case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
  350. mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
  351. break;
  352. default:
  353. dev_err(codec->dev, "%s: e->reg: 0x%x not expected\n",
  354. __func__, e->reg);
  355. return -EINVAL;
  356. }
  357. if (strnstr(widget->name, "smic", strlen(widget->name))) {
  358. if (val != 0) {
  359. if (val < 5)
  360. snd_soc_update_bits(codec, mic_sel_reg,
  361. 1 << 7, 0x0 << 7);
  362. else
  363. snd_soc_update_bits(codec, mic_sel_reg,
  364. 1 << 7, 0x1 << 7);
  365. }
  366. } else {
  367. /* DMIC selected */
  368. if (val != 0)
  369. snd_soc_update_bits(codec, mic_sel_reg, 1 << 7, 1 << 7);
  370. }
  371. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  372. }
  373. static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  374. struct snd_ctl_elem_value *ucontrol)
  375. {
  376. struct snd_soc_dapm_widget *widget =
  377. snd_soc_dapm_kcontrol_widget(kcontrol);
  378. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  379. struct soc_multi_mixer_control *mixer =
  380. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  381. u32 dai_id = widget->shift;
  382. u32 dec_id = mixer->shift;
  383. struct device *tx_dev = NULL;
  384. struct tx_macro_priv *tx_priv = NULL;
  385. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  386. return -EINVAL;
  387. if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
  388. ucontrol->value.integer.value[0] = 1;
  389. else
  390. ucontrol->value.integer.value[0] = 0;
  391. return 0;
  392. }
  393. static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  394. struct snd_ctl_elem_value *ucontrol)
  395. {
  396. struct snd_soc_dapm_widget *widget =
  397. snd_soc_dapm_kcontrol_widget(kcontrol);
  398. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  399. struct snd_soc_dapm_update *update = NULL;
  400. struct soc_multi_mixer_control *mixer =
  401. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  402. u32 dai_id = widget->shift;
  403. u32 dec_id = mixer->shift;
  404. u32 enable = ucontrol->value.integer.value[0];
  405. struct device *tx_dev = NULL;
  406. struct tx_macro_priv *tx_priv = NULL;
  407. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  408. return -EINVAL;
  409. if (enable) {
  410. set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  411. tx_priv->active_ch_cnt[dai_id]++;
  412. } else {
  413. tx_priv->active_ch_cnt[dai_id]--;
  414. clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  415. }
  416. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  417. return 0;
  418. }
  419. static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  420. struct snd_kcontrol *kcontrol, int event)
  421. {
  422. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  423. u8 dmic_clk_en = 0x01;
  424. u16 dmic_clk_reg = 0;
  425. s32 *dmic_clk_cnt = NULL;
  426. unsigned int dmic = 0;
  427. int ret = 0;
  428. char *wname = NULL;
  429. struct device *tx_dev = NULL;
  430. struct tx_macro_priv *tx_priv = NULL;
  431. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  432. return -EINVAL;
  433. wname = strpbrk(w->name, "01234567");
  434. if (!wname) {
  435. dev_err(codec->dev, "%s: widget not found\n", __func__);
  436. return -EINVAL;
  437. }
  438. ret = kstrtouint(wname, 10, &dmic);
  439. if (ret < 0) {
  440. dev_err(codec->dev, "%s: Invalid DMIC line on the codec\n",
  441. __func__);
  442. return -EINVAL;
  443. }
  444. switch (dmic) {
  445. case 0:
  446. case 1:
  447. dmic_clk_cnt = &(tx_priv->dmic_0_1_clk_cnt);
  448. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL;
  449. break;
  450. case 2:
  451. case 3:
  452. dmic_clk_cnt = &(tx_priv->dmic_2_3_clk_cnt);
  453. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL;
  454. break;
  455. case 4:
  456. case 5:
  457. dmic_clk_cnt = &(tx_priv->dmic_4_5_clk_cnt);
  458. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL;
  459. break;
  460. case 6:
  461. case 7:
  462. dmic_clk_cnt = &(tx_priv->dmic_6_7_clk_cnt);
  463. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL;
  464. break;
  465. default:
  466. dev_err(codec->dev, "%s: Invalid DMIC Selection\n",
  467. __func__);
  468. return -EINVAL;
  469. }
  470. dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  471. __func__, event, dmic, *dmic_clk_cnt);
  472. switch (event) {
  473. case SND_SOC_DAPM_PRE_PMU:
  474. (*dmic_clk_cnt)++;
  475. if (*dmic_clk_cnt == 1) {
  476. snd_soc_update_bits(codec, BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  477. 0x80, 0x00);
  478. snd_soc_update_bits(codec, dmic_clk_reg,
  479. 0x0E, tx_priv->dmic_clk_div << 0x1);
  480. snd_soc_update_bits(codec, dmic_clk_reg,
  481. dmic_clk_en, dmic_clk_en);
  482. }
  483. break;
  484. case SND_SOC_DAPM_POST_PMD:
  485. (*dmic_clk_cnt)--;
  486. if (*dmic_clk_cnt == 0)
  487. snd_soc_update_bits(codec, dmic_clk_reg,
  488. dmic_clk_en, 0);
  489. break;
  490. }
  491. return 0;
  492. }
  493. static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
  494. struct snd_kcontrol *kcontrol, int event)
  495. {
  496. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  497. unsigned int decimator = 0;
  498. u16 tx_vol_ctl_reg = 0;
  499. u16 dec_cfg_reg = 0;
  500. u16 hpf_gate_reg = 0;
  501. u16 tx_gain_ctl_reg = 0;
  502. u8 hpf_cut_off_freq = 0;
  503. struct device *tx_dev = NULL;
  504. struct tx_macro_priv *tx_priv = NULL;
  505. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  506. return -EINVAL;
  507. decimator = w->shift;
  508. dev_dbg(codec->dev, "%s(): widget = %s decimator = %u\n", __func__,
  509. w->name, decimator);
  510. tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  511. TX_MACRO_TX_PATH_OFFSET * decimator;
  512. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  513. TX_MACRO_TX_PATH_OFFSET * decimator;
  514. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  515. TX_MACRO_TX_PATH_OFFSET * decimator;
  516. tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
  517. TX_MACRO_TX_PATH_OFFSET * decimator;
  518. switch (event) {
  519. case SND_SOC_DAPM_PRE_PMU:
  520. /* Enable TX PGA Mute */
  521. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  522. break;
  523. case SND_SOC_DAPM_POST_PMU:
  524. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x20, 0x20);
  525. snd_soc_update_bits(codec, hpf_gate_reg, 0x01, 0x00);
  526. hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) &
  527. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  528. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
  529. hpf_cut_off_freq;
  530. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  531. snd_soc_update_bits(codec, dec_cfg_reg,
  532. TX_HPF_CUT_OFF_FREQ_MASK,
  533. CF_MIN_3DB_150HZ << 5);
  534. /* schedule work queue to Remove Mute */
  535. schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork,
  536. msecs_to_jiffies(tx_unmute_delay));
  537. if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
  538. CF_MIN_3DB_150HZ) {
  539. schedule_delayed_work(
  540. &tx_priv->tx_hpf_work[decimator].dwork,
  541. msecs_to_jiffies(300));
  542. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02);
  543. /*
  544. * Minimum 1 clk cycle delay is required as per HW spec
  545. */
  546. usleep_range(1000, 1010);
  547. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00);
  548. }
  549. /* apply gain after decimator is enabled */
  550. snd_soc_write(codec, tx_gain_ctl_reg,
  551. snd_soc_read(codec, tx_gain_ctl_reg));
  552. break;
  553. case SND_SOC_DAPM_PRE_PMD:
  554. hpf_cut_off_freq =
  555. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
  556. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  557. if (cancel_delayed_work_sync(
  558. &tx_priv->tx_hpf_work[decimator].dwork)) {
  559. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  560. snd_soc_update_bits(codec, dec_cfg_reg,
  561. TX_HPF_CUT_OFF_FREQ_MASK,
  562. hpf_cut_off_freq << 5);
  563. snd_soc_update_bits(codec, hpf_gate_reg,
  564. 0x02, 0x02);
  565. /*
  566. * Minimum 1 clk cycle delay is required
  567. * as per HW spec
  568. */
  569. usleep_range(1000, 1010);
  570. snd_soc_update_bits(codec, hpf_gate_reg,
  571. 0x02, 0x00);
  572. }
  573. }
  574. cancel_delayed_work_sync(
  575. &tx_priv->tx_mute_dwork[decimator].dwork);
  576. break;
  577. case SND_SOC_DAPM_POST_PMD:
  578. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x20, 0x00);
  579. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  580. break;
  581. }
  582. return 0;
  583. }
  584. static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  585. struct snd_kcontrol *kcontrol, int event)
  586. {
  587. return 0;
  588. }
  589. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  590. struct snd_pcm_hw_params *params,
  591. struct snd_soc_dai *dai)
  592. {
  593. int tx_fs_rate = -EINVAL;
  594. struct snd_soc_codec *codec = dai->codec;
  595. u32 decimator = 0;
  596. u32 sample_rate = 0;
  597. u16 tx_fs_reg = 0;
  598. struct device *tx_dev = NULL;
  599. struct tx_macro_priv *tx_priv = NULL;
  600. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  601. return -EINVAL;
  602. pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  603. dai->name, dai->id, params_rate(params),
  604. params_channels(params));
  605. sample_rate = params_rate(params);
  606. switch (sample_rate) {
  607. case 8000:
  608. tx_fs_rate = 0;
  609. break;
  610. case 16000:
  611. tx_fs_rate = 1;
  612. break;
  613. case 32000:
  614. tx_fs_rate = 3;
  615. break;
  616. case 48000:
  617. tx_fs_rate = 4;
  618. break;
  619. case 96000:
  620. tx_fs_rate = 5;
  621. break;
  622. case 192000:
  623. tx_fs_rate = 6;
  624. break;
  625. case 384000:
  626. tx_fs_rate = 7;
  627. break;
  628. default:
  629. dev_err(codec->dev, "%s: Invalid TX sample rate: %d\n",
  630. __func__, params_rate(params));
  631. return -EINVAL;
  632. }
  633. for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
  634. TX_MACRO_DEC_MAX) {
  635. if (decimator >= 0) {
  636. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  637. TX_MACRO_TX_PATH_OFFSET * decimator;
  638. dev_dbg(codec->dev, "%s: set DEC%u rate to %u\n",
  639. __func__, decimator, sample_rate);
  640. snd_soc_update_bits(codec, tx_fs_reg, 0x0F,
  641. tx_fs_rate);
  642. } else {
  643. dev_err(codec->dev,
  644. "%s: ERROR: Invalid decimator: %d\n",
  645. __func__, decimator);
  646. return -EINVAL;
  647. }
  648. }
  649. return 0;
  650. }
  651. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  652. unsigned int *tx_num, unsigned int *tx_slot,
  653. unsigned int *rx_num, unsigned int *rx_slot)
  654. {
  655. struct snd_soc_codec *codec = dai->codec;
  656. struct device *tx_dev = NULL;
  657. struct tx_macro_priv *tx_priv = NULL;
  658. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  659. return -EINVAL;
  660. switch (dai->id) {
  661. case TX_MACRO_AIF1_CAP:
  662. case TX_MACRO_AIF2_CAP:
  663. *tx_slot = tx_priv->active_ch_mask[dai->id];
  664. *tx_num = tx_priv->active_ch_cnt[dai->id];
  665. break;
  666. default:
  667. dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
  668. break;
  669. }
  670. return 0;
  671. }
  672. static struct snd_soc_dai_ops tx_macro_dai_ops = {
  673. .hw_params = tx_macro_hw_params,
  674. .get_channel_map = tx_macro_get_channel_map,
  675. };
  676. static struct snd_soc_dai_driver tx_macro_dai[] = {
  677. {
  678. .name = "tx_macro_tx1",
  679. .id = TX_MACRO_AIF1_CAP,
  680. .capture = {
  681. .stream_name = "TX_AIF1 Capture",
  682. .rates = TX_MACRO_RATES,
  683. .formats = TX_MACRO_FORMATS,
  684. .rate_max = 192000,
  685. .rate_min = 8000,
  686. .channels_min = 1,
  687. .channels_max = 8,
  688. },
  689. .ops = &tx_macro_dai_ops,
  690. },
  691. {
  692. .name = "tx_macro_tx2",
  693. .id = TX_MACRO_AIF2_CAP,
  694. .capture = {
  695. .stream_name = "TX_AIF2 Capture",
  696. .rates = TX_MACRO_RATES,
  697. .formats = TX_MACRO_FORMATS,
  698. .rate_max = 192000,
  699. .rate_min = 8000,
  700. .channels_min = 1,
  701. .channels_max = 8,
  702. },
  703. .ops = &tx_macro_dai_ops,
  704. },
  705. };
  706. #define STRING(name) #name
  707. #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  708. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  709. static const struct snd_kcontrol_new name##_mux = \
  710. SOC_DAPM_ENUM(STRING(name), name##_enum)
  711. #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  712. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  713. static const struct snd_kcontrol_new name##_mux = \
  714. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  715. #define TX_MACRO_DAPM_MUX(name, shift, kctl) \
  716. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  717. static const char * const adc_mux_text[] = {
  718. "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
  719. };
  720. TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
  721. 0, adc_mux_text);
  722. TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
  723. 0, adc_mux_text);
  724. TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
  725. 0, adc_mux_text);
  726. TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
  727. 0, adc_mux_text);
  728. TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
  729. 0, adc_mux_text);
  730. TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
  731. 0, adc_mux_text);
  732. TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
  733. 0, adc_mux_text);
  734. TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
  735. 0, adc_mux_text);
  736. static const char * const dmic_mux_text[] = {
  737. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  738. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  739. };
  740. TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  741. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  742. tx_macro_put_dec_enum);
  743. TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  744. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  745. tx_macro_put_dec_enum);
  746. TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  747. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  748. tx_macro_put_dec_enum);
  749. TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  750. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  751. tx_macro_put_dec_enum);
  752. TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  753. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  754. tx_macro_put_dec_enum);
  755. TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  756. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  757. tx_macro_put_dec_enum);
  758. TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  759. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  760. tx_macro_put_dec_enum);
  761. TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  762. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  763. tx_macro_put_dec_enum);
  764. static const char * const smic_mux_text[] = {
  765. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3",
  766. "SWR_DMIC0", "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3",
  767. "SWR_DMIC4", "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  768. };
  769. TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  770. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  771. tx_macro_put_dec_enum);
  772. TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  773. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  774. tx_macro_put_dec_enum);
  775. TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  776. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  777. tx_macro_put_dec_enum);
  778. TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  779. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  780. tx_macro_put_dec_enum);
  781. TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  782. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  783. tx_macro_put_dec_enum);
  784. TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  785. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  786. tx_macro_put_dec_enum);
  787. TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  788. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  789. tx_macro_put_dec_enum);
  790. TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  791. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  792. tx_macro_put_dec_enum);
  793. static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
  794. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  795. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  796. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  797. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  798. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  799. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  800. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  801. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  802. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  803. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  804. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  805. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  806. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  807. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  808. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  809. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  810. };
  811. static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
  812. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  813. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  814. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  815. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  816. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  817. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  818. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  819. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  820. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  821. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  822. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  823. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  824. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  825. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  826. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  827. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  828. };
  829. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
  830. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  831. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  832. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  833. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  834. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
  835. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  836. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
  837. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  838. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  839. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  840. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  841. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  842. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  843. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  844. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  845. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  846. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
  847. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
  848. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
  849. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
  850. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
  851. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
  852. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
  853. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
  854. SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  855. tx_macro_enable_micbias,
  856. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  857. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  858. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  859. SND_SOC_DAPM_POST_PMD),
  860. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  861. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  862. SND_SOC_DAPM_POST_PMD),
  863. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  864. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  865. SND_SOC_DAPM_POST_PMD),
  866. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  867. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  868. SND_SOC_DAPM_POST_PMD),
  869. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  870. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  871. SND_SOC_DAPM_POST_PMD),
  872. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  873. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  874. SND_SOC_DAPM_POST_PMD),
  875. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  876. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  877. SND_SOC_DAPM_POST_PMD),
  878. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  879. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  880. SND_SOC_DAPM_POST_PMD),
  881. SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
  882. SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
  883. SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
  884. SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
  885. SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
  886. SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
  887. SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
  888. SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
  889. SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
  890. SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
  891. SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
  892. SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
  893. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  894. TX_MACRO_DEC0, 0,
  895. &tx_dec0_mux, tx_macro_enable_dec,
  896. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  897. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  898. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  899. TX_MACRO_DEC1, 0,
  900. &tx_dec1_mux, tx_macro_enable_dec,
  901. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  902. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  903. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  904. TX_MACRO_DEC2, 0,
  905. &tx_dec2_mux, tx_macro_enable_dec,
  906. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  907. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  908. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  909. TX_MACRO_DEC3, 0,
  910. &tx_dec3_mux, tx_macro_enable_dec,
  911. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  912. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  913. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  914. TX_MACRO_DEC4, 0,
  915. &tx_dec4_mux, tx_macro_enable_dec,
  916. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  917. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  918. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  919. TX_MACRO_DEC5, 0,
  920. &tx_dec5_mux, tx_macro_enable_dec,
  921. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  922. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  923. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  924. TX_MACRO_DEC6, 0,
  925. &tx_dec6_mux, tx_macro_enable_dec,
  926. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  927. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  928. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  929. TX_MACRO_DEC7, 0,
  930. &tx_dec7_mux, tx_macro_enable_dec,
  931. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  932. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  933. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  934. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  935. };
  936. static const struct snd_soc_dapm_route tx_audio_map[] = {
  937. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  938. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  939. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  940. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  941. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  942. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  943. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  944. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  945. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  946. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  947. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  948. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  949. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  950. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  951. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  952. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  953. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  954. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  955. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  956. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  957. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  958. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  959. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  960. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  961. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  962. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  963. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  964. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  965. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  966. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  967. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  968. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  969. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  970. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  971. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  972. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  973. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  974. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  975. {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
  976. {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
  977. {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
  978. {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
  979. {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
  980. {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
  981. {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
  982. {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
  983. {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
  984. {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
  985. {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
  986. {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
  987. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  988. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  989. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  990. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  991. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  992. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  993. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  994. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  995. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  996. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  997. {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
  998. {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
  999. {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
  1000. {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
  1001. {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
  1002. {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
  1003. {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
  1004. {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
  1005. {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
  1006. {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
  1007. {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
  1008. {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
  1009. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1010. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1011. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1012. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1013. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1014. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1015. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1016. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1017. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1018. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1019. {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
  1020. {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
  1021. {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
  1022. {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
  1023. {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
  1024. {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
  1025. {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
  1026. {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
  1027. {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
  1028. {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
  1029. {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
  1030. {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
  1031. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1032. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1033. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1034. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1035. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1036. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1037. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1038. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1039. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1040. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1041. {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
  1042. {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
  1043. {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
  1044. {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
  1045. {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
  1046. {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
  1047. {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
  1048. {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
  1049. {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
  1050. {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
  1051. {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
  1052. {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
  1053. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1054. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1055. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1056. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1057. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1058. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1059. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1060. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1061. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1062. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1063. {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
  1064. {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
  1065. {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
  1066. {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
  1067. {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
  1068. {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
  1069. {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
  1070. {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
  1071. {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
  1072. {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
  1073. {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
  1074. {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
  1075. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1076. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1077. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1078. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1079. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1080. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1081. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1082. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1083. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  1084. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  1085. {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
  1086. {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
  1087. {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
  1088. {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
  1089. {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
  1090. {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
  1091. {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
  1092. {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
  1093. {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
  1094. {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
  1095. {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
  1096. {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
  1097. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  1098. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  1099. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  1100. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  1101. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  1102. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  1103. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  1104. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  1105. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  1106. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  1107. {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
  1108. {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
  1109. {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
  1110. {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
  1111. {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
  1112. {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
  1113. {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
  1114. {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
  1115. {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
  1116. {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
  1117. {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
  1118. {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
  1119. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  1120. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  1121. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  1122. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  1123. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  1124. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  1125. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  1126. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  1127. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  1128. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  1129. {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
  1130. {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
  1131. {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
  1132. {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
  1133. {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
  1134. {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
  1135. {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
  1136. {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
  1137. {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
  1138. {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
  1139. {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
  1140. {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
  1141. };
  1142. static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
  1143. SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
  1144. BOLERO_CDC_TX0_TX_VOL_CTL,
  1145. 0, -84, 40, digital_gain),
  1146. SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
  1147. BOLERO_CDC_TX1_TX_VOL_CTL,
  1148. 0, -84, 40, digital_gain),
  1149. SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
  1150. BOLERO_CDC_TX2_TX_VOL_CTL,
  1151. 0, -84, 40, digital_gain),
  1152. SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
  1153. BOLERO_CDC_TX3_TX_VOL_CTL,
  1154. 0, -84, 40, digital_gain),
  1155. SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
  1156. BOLERO_CDC_TX4_TX_VOL_CTL,
  1157. 0, -84, 40, digital_gain),
  1158. SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
  1159. BOLERO_CDC_TX5_TX_VOL_CTL,
  1160. 0, -84, 40, digital_gain),
  1161. SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
  1162. BOLERO_CDC_TX6_TX_VOL_CTL,
  1163. 0, -84, 40, digital_gain),
  1164. SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
  1165. BOLERO_CDC_TX7_TX_VOL_CTL,
  1166. 0, -84, 40, digital_gain),
  1167. };
  1168. static int tx_macro_swrm_clock(void *handle, bool enable)
  1169. {
  1170. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  1171. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  1172. int ret = 0;
  1173. if (regmap == NULL) {
  1174. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  1175. return -EINVAL;
  1176. }
  1177. mutex_lock(&tx_priv->swr_clk_lock);
  1178. dev_dbg(tx_priv->dev, "%s: swrm clock %s\n",
  1179. __func__, (enable ? "enable" : "disable"));
  1180. if (enable) {
  1181. if (tx_priv->swr_clk_users == 0) {
  1182. ret = tx_macro_mclk_enable(tx_priv, 1);
  1183. if (ret < 0) {
  1184. dev_err(tx_priv->dev,
  1185. "%s: request clock enable failed\n",
  1186. __func__);
  1187. goto exit;
  1188. }
  1189. regmap_update_bits(regmap,
  1190. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1191. 0x01, 0x01);
  1192. regmap_update_bits(regmap,
  1193. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1194. 0x1C, 0x0C);
  1195. msm_cdc_pinctrl_select_active_state(
  1196. tx_priv->tx_swr_gpio_p);
  1197. }
  1198. tx_priv->swr_clk_users++;
  1199. } else {
  1200. if (tx_priv->swr_clk_users <= 0) {
  1201. dev_err(tx_priv->dev,
  1202. "tx swrm clock users already 0\n");
  1203. tx_priv->swr_clk_users = 0;
  1204. goto exit;
  1205. }
  1206. tx_priv->swr_clk_users--;
  1207. if (tx_priv->swr_clk_users == 0) {
  1208. regmap_update_bits(regmap,
  1209. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1210. 0x01, 0x00);
  1211. msm_cdc_pinctrl_select_sleep_state(
  1212. tx_priv->tx_swr_gpio_p);
  1213. tx_macro_mclk_enable(tx_priv, 0);
  1214. }
  1215. }
  1216. dev_dbg(tx_priv->dev, "%s: swrm clock users %d\n",
  1217. __func__, tx_priv->swr_clk_users);
  1218. exit:
  1219. mutex_unlock(&tx_priv->swr_clk_lock);
  1220. return ret;
  1221. }
  1222. static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  1223. struct tx_macro_priv *tx_priv)
  1224. {
  1225. u32 div_factor = TX_MACRO_CLK_DIV_2;
  1226. u32 mclk_rate = TX_MACRO_MCLK_FREQ;
  1227. if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  1228. mclk_rate % dmic_sample_rate != 0)
  1229. goto undefined_rate;
  1230. div_factor = mclk_rate / dmic_sample_rate;
  1231. switch (div_factor) {
  1232. case 2:
  1233. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1234. break;
  1235. case 3:
  1236. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
  1237. break;
  1238. case 4:
  1239. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
  1240. break;
  1241. case 6:
  1242. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
  1243. break;
  1244. case 8:
  1245. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
  1246. break;
  1247. case 16:
  1248. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
  1249. break;
  1250. default:
  1251. /* Any other DIV factor is invalid */
  1252. goto undefined_rate;
  1253. }
  1254. /* Valid dmic DIV factors */
  1255. dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  1256. __func__, div_factor, mclk_rate);
  1257. return dmic_sample_rate;
  1258. undefined_rate:
  1259. dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  1260. __func__, dmic_sample_rate, mclk_rate);
  1261. dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  1262. return dmic_sample_rate;
  1263. }
  1264. static int tx_macro_init(struct snd_soc_codec *codec)
  1265. {
  1266. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1267. int ret = 0, i = 0;
  1268. struct device *tx_dev = NULL;
  1269. struct tx_macro_priv *tx_priv = NULL;
  1270. tx_dev = bolero_get_device_ptr(codec->dev, TX_MACRO);
  1271. if (!tx_dev) {
  1272. dev_err(codec->dev,
  1273. "%s: null device for macro!\n", __func__);
  1274. return -EINVAL;
  1275. }
  1276. tx_priv = dev_get_drvdata(tx_dev);
  1277. if (!tx_priv) {
  1278. dev_err(codec->dev,
  1279. "%s: priv is null for macro!\n", __func__);
  1280. return -EINVAL;
  1281. }
  1282. ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
  1283. ARRAY_SIZE(tx_macro_dapm_widgets));
  1284. if (ret < 0) {
  1285. dev_err(tx_dev, "%s: Failed to add controls\n", __func__);
  1286. return ret;
  1287. }
  1288. ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
  1289. ARRAY_SIZE(tx_audio_map));
  1290. if (ret < 0) {
  1291. dev_err(tx_dev, "%s: Failed to add routes\n", __func__);
  1292. return ret;
  1293. }
  1294. ret = snd_soc_dapm_new_widgets(dapm->card);
  1295. if (ret < 0) {
  1296. dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
  1297. return ret;
  1298. }
  1299. ret = snd_soc_add_codec_controls(codec, tx_macro_snd_controls,
  1300. ARRAY_SIZE(tx_macro_snd_controls));
  1301. if (ret < 0) {
  1302. dev_err(tx_dev, "%s: Failed to add snd_ctls\n", __func__);
  1303. return ret;
  1304. }
  1305. for (i = 0; i < NUM_DECIMATORS; i++) {
  1306. tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
  1307. tx_priv->tx_hpf_work[i].decimator = i;
  1308. INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
  1309. tx_macro_tx_hpf_corner_freq_callback);
  1310. }
  1311. for (i = 0; i < NUM_DECIMATORS; i++) {
  1312. tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
  1313. tx_priv->tx_mute_dwork[i].decimator = i;
  1314. INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
  1315. tx_macro_mute_update_callback);
  1316. }
  1317. tx_priv->codec = codec;
  1318. return 0;
  1319. }
  1320. static int tx_macro_deinit(struct snd_soc_codec *codec)
  1321. {
  1322. struct device *tx_dev = NULL;
  1323. struct tx_macro_priv *tx_priv = NULL;
  1324. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  1325. return -EINVAL;
  1326. tx_priv->codec = NULL;
  1327. return 0;
  1328. }
  1329. static void tx_macro_add_child_devices(struct work_struct *work)
  1330. {
  1331. struct tx_macro_priv *tx_priv = NULL;
  1332. struct platform_device *pdev = NULL;
  1333. struct device_node *node = NULL;
  1334. struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  1335. int ret = 0;
  1336. u16 count = 0, ctrl_num = 0;
  1337. struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
  1338. char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
  1339. bool tx_swr_master_node = false;
  1340. tx_priv = container_of(work, struct tx_macro_priv,
  1341. tx_macro_add_child_devices_work);
  1342. if (!tx_priv) {
  1343. pr_err("%s: Memory for tx_priv does not exist\n",
  1344. __func__);
  1345. return;
  1346. }
  1347. if (!tx_priv->dev) {
  1348. pr_err("%s: tx dev does not exist\n", __func__);
  1349. return;
  1350. }
  1351. if (!tx_priv->dev->of_node) {
  1352. dev_err(tx_priv->dev,
  1353. "%s: DT node for tx_priv does not exist\n", __func__);
  1354. return;
  1355. }
  1356. platdata = &tx_priv->swr_plat_data;
  1357. tx_priv->child_count = 0;
  1358. for_each_available_child_of_node(tx_priv->dev->of_node, node) {
  1359. tx_swr_master_node = false;
  1360. if (strnstr(node->name, "tx_swr_master",
  1361. strlen("tx_swr_master")) != NULL)
  1362. tx_swr_master_node = true;
  1363. if (tx_swr_master_node)
  1364. strlcpy(plat_dev_name, "tx_swr_ctrl",
  1365. (TX_MACRO_SWR_STRING_LEN - 1));
  1366. else
  1367. strlcpy(plat_dev_name, node->name,
  1368. (TX_MACRO_SWR_STRING_LEN - 1));
  1369. pdev = platform_device_alloc(plat_dev_name, -1);
  1370. if (!pdev) {
  1371. dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
  1372. __func__);
  1373. ret = -ENOMEM;
  1374. goto err;
  1375. }
  1376. pdev->dev.parent = tx_priv->dev;
  1377. pdev->dev.of_node = node;
  1378. if (tx_swr_master_node) {
  1379. ret = platform_device_add_data(pdev, platdata,
  1380. sizeof(*platdata));
  1381. if (ret) {
  1382. dev_err(&pdev->dev,
  1383. "%s: cannot add plat data ctrl:%d\n",
  1384. __func__, ctrl_num);
  1385. goto fail_pdev_add;
  1386. }
  1387. }
  1388. ret = platform_device_add(pdev);
  1389. if (ret) {
  1390. dev_err(&pdev->dev,
  1391. "%s: Cannot add platform device\n",
  1392. __func__);
  1393. goto fail_pdev_add;
  1394. }
  1395. if (tx_swr_master_node) {
  1396. temp = krealloc(swr_ctrl_data,
  1397. (ctrl_num + 1) * sizeof(
  1398. struct tx_macro_swr_ctrl_data),
  1399. GFP_KERNEL);
  1400. if (!temp) {
  1401. ret = -ENOMEM;
  1402. goto fail_pdev_add;
  1403. }
  1404. swr_ctrl_data = temp;
  1405. swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
  1406. ctrl_num++;
  1407. dev_dbg(&pdev->dev,
  1408. "%s: Added soundwire ctrl device(s)\n",
  1409. __func__);
  1410. tx_priv->swr_ctrl_data = swr_ctrl_data;
  1411. }
  1412. if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
  1413. tx_priv->pdev_child_devices[
  1414. tx_priv->child_count++] = pdev;
  1415. else
  1416. goto err;
  1417. }
  1418. return;
  1419. fail_pdev_add:
  1420. for (count = 0; count < tx_priv->child_count; count++)
  1421. platform_device_put(tx_priv->pdev_child_devices[count]);
  1422. err:
  1423. return;
  1424. }
  1425. static void tx_macro_init_ops(struct macro_ops *ops,
  1426. char __iomem *tx_io_base)
  1427. {
  1428. memset(ops, 0, sizeof(struct macro_ops));
  1429. ops->init = tx_macro_init;
  1430. ops->exit = tx_macro_deinit;
  1431. ops->io_base = tx_io_base;
  1432. ops->dai_ptr = tx_macro_dai;
  1433. ops->num_dais = ARRAY_SIZE(tx_macro_dai);
  1434. ops->mclk_fn = tx_macro_mclk_ctrl;
  1435. }
  1436. static int tx_macro_probe(struct platform_device *pdev)
  1437. {
  1438. struct macro_ops ops = {0};
  1439. struct tx_macro_priv *tx_priv = NULL;
  1440. u32 tx_base_addr = 0, sample_rate = 0;
  1441. char __iomem *tx_io_base = NULL;
  1442. struct clk *tx_core_clk = NULL, *tx_npl_clk = NULL;
  1443. int ret = 0;
  1444. const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
  1445. tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
  1446. GFP_KERNEL);
  1447. if (!tx_priv)
  1448. return -ENOMEM;
  1449. platform_set_drvdata(pdev, tx_priv);
  1450. tx_priv->dev = &pdev->dev;
  1451. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1452. &tx_base_addr);
  1453. if (ret) {
  1454. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1455. __func__, "reg");
  1456. return ret;
  1457. }
  1458. dev_set_drvdata(&pdev->dev, tx_priv);
  1459. tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1460. "qcom,tx-swr-gpios", 0);
  1461. if (!tx_priv->tx_swr_gpio_p) {
  1462. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  1463. __func__);
  1464. return -EINVAL;
  1465. }
  1466. tx_io_base = devm_ioremap(&pdev->dev,
  1467. tx_base_addr, TX_MACRO_MAX_OFFSET);
  1468. if (!tx_io_base) {
  1469. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  1470. return -ENOMEM;
  1471. }
  1472. tx_priv->tx_io_base = tx_io_base;
  1473. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  1474. &sample_rate);
  1475. if (ret) {
  1476. dev_err(&pdev->dev,
  1477. "%s: could not find sample_rate entry in dt\n",
  1478. __func__);
  1479. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1480. } else {
  1481. if (tx_macro_validate_dmic_sample_rate(
  1482. sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  1483. return -EINVAL;
  1484. }
  1485. INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
  1486. tx_macro_add_child_devices);
  1487. tx_priv->swr_plat_data.handle = (void *) tx_priv;
  1488. tx_priv->swr_plat_data.read = NULL;
  1489. tx_priv->swr_plat_data.write = NULL;
  1490. tx_priv->swr_plat_data.bulk_write = NULL;
  1491. tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
  1492. tx_priv->swr_plat_data.handle_irq = NULL;
  1493. /* Register MCLK for tx macro */
  1494. tx_core_clk = devm_clk_get(&pdev->dev, "tx_core_clk");
  1495. if (IS_ERR(tx_core_clk)) {
  1496. ret = PTR_ERR(tx_core_clk);
  1497. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  1498. __func__, "tx_core_clk", ret);
  1499. return ret;
  1500. }
  1501. tx_priv->tx_core_clk = tx_core_clk;
  1502. /* Register npl clk for soundwire */
  1503. tx_npl_clk = devm_clk_get(&pdev->dev, "tx_npl_clk");
  1504. if (IS_ERR(tx_npl_clk)) {
  1505. ret = PTR_ERR(tx_npl_clk);
  1506. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  1507. __func__, "tx_npl_clk", ret);
  1508. return ret;
  1509. }
  1510. tx_priv->tx_npl_clk = tx_npl_clk;
  1511. mutex_init(&tx_priv->mclk_lock);
  1512. mutex_init(&tx_priv->swr_clk_lock);
  1513. tx_macro_init_ops(&ops, tx_io_base);
  1514. ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
  1515. if (ret) {
  1516. dev_err(&pdev->dev,
  1517. "%s: register macro failed\n", __func__);
  1518. goto err_reg_macro;
  1519. }
  1520. schedule_work(&tx_priv->tx_macro_add_child_devices_work);
  1521. return 0;
  1522. err_reg_macro:
  1523. mutex_destroy(&tx_priv->mclk_lock);
  1524. mutex_destroy(&tx_priv->swr_clk_lock);
  1525. return ret;
  1526. }
  1527. static int tx_macro_remove(struct platform_device *pdev)
  1528. {
  1529. struct tx_macro_priv *tx_priv = NULL;
  1530. u16 count = 0;
  1531. tx_priv = platform_get_drvdata(pdev);
  1532. if (!tx_priv)
  1533. return -EINVAL;
  1534. kfree(tx_priv->swr_ctrl_data);
  1535. for (count = 0; count < tx_priv->child_count &&
  1536. count < TX_MACRO_CHILD_DEVICES_MAX; count++)
  1537. platform_device_unregister(tx_priv->pdev_child_devices[count]);
  1538. mutex_destroy(&tx_priv->mclk_lock);
  1539. mutex_destroy(&tx_priv->swr_clk_lock);
  1540. bolero_unregister_macro(&pdev->dev, TX_MACRO);
  1541. return 0;
  1542. }
  1543. static const struct of_device_id tx_macro_dt_match[] = {
  1544. {.compatible = "qcom,tx-macro"},
  1545. {}
  1546. };
  1547. static struct platform_driver tx_macro_driver = {
  1548. .driver = {
  1549. .name = "tx_macro",
  1550. .owner = THIS_MODULE,
  1551. .of_match_table = tx_macro_dt_match,
  1552. },
  1553. .probe = tx_macro_probe,
  1554. .remove = tx_macro_remove,
  1555. };
  1556. module_platform_driver(tx_macro_driver);
  1557. MODULE_DESCRIPTION("TX macro driver");
  1558. MODULE_LICENSE("GPL v2");