tx-macro.c 96 KB

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