tx-macro.c 72 KB

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