tx-macro.c 63 KB

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