tx-macro.c 108 KB

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