tx-macro.c 55 KB

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