tx-macro.c 67 KB

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