tx-macro.c 109 KB

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