lpass-cdc-wsa-macro.c 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/io.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/clk.h>
  9. #include <linux/thermal.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 "lpass-cdc.h"
  18. #include "lpass-cdc-comp.h"
  19. #include "lpass-cdc-registers.h"
  20. #include "lpass-cdc-wsa-macro.h"
  21. #include "lpass-cdc-clk-rsc.h"
  22. #define AUTO_SUSPEND_DELAY 50 /* delay in msec */
  23. #define LPASS_CDC_WSA_MACRO_MAX_OFFSET 0x1000
  24. #define LPASS_CDC_WSA_MACRO_RX_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  25. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  26. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  27. #define LPASS_CDC_WSA_MACRO_RX_MIX_RATES (SNDRV_PCM_RATE_48000 |\
  28. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  29. #define LPASS_CDC_WSA_MACRO_RX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  30. SNDRV_PCM_FMTBIT_S24_LE |\
  31. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  32. #define LPASS_CDC_WSA_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  33. SNDRV_PCM_RATE_48000)
  34. #define LPASS_CDC_WSA_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  35. SNDRV_PCM_FMTBIT_S24_LE |\
  36. SNDRV_PCM_FMTBIT_S24_3LE)
  37. #define NUM_INTERPOLATORS 2
  38. #define LPASS_CDC_WSA_MACRO_MUX_INP_SHFT 0x3
  39. #define LPASS_CDC_WSA_MACRO_MUX_INP_MASK1 0x07
  40. #define LPASS_CDC_WSA_MACRO_MUX_INP_MASK2 0x38
  41. #define LPASS_CDC_WSA_MACRO_MUX_CFG_OFFSET 0x8
  42. #define LPASS_CDC_WSA_MACRO_MUX_CFG1_OFFSET 0x4
  43. #define LPASS_CDC_WSA_MACRO_RX_COMP_OFFSET 0x40
  44. #define LPASS_CDC_WSA_MACRO_RX_SOFTCLIP_OFFSET 0x40
  45. #define LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET 0x80
  46. #define LPASS_CDC_WSA_MACRO_RX_PATH_CFG3_OFFSET 0x10
  47. #define LPASS_CDC_WSA_MACRO_RX_PATH_DSMDEM_OFFSET 0x4C
  48. #define LPASS_CDC_WSA_MACRO_FS_RATE_MASK 0x0F
  49. #define LPASS_CDC_WSA_MACRO_EC_MIX_TX0_MASK 0x03
  50. #define LPASS_CDC_WSA_MACRO_EC_MIX_TX1_MASK 0x18
  51. #define LPASS_CDC_WSA_MACRO_MAX_DMA_CH_PER_PORT 0x2
  52. #define LPASS_CDC_WSA_MACRO_THERMAL_MAX_STATE 11
  53. enum {
  54. LPASS_CDC_WSA_MACRO_RX0 = 0,
  55. LPASS_CDC_WSA_MACRO_RX1,
  56. LPASS_CDC_WSA_MACRO_RX_MIX,
  57. LPASS_CDC_WSA_MACRO_RX_MIX0 = LPASS_CDC_WSA_MACRO_RX_MIX,
  58. LPASS_CDC_WSA_MACRO_RX_MIX1,
  59. LPASS_CDC_WSA_MACRO_RX4,
  60. LPASS_CDC_WSA_MACRO_RX5,
  61. LPASS_CDC_WSA_MACRO_RX_MAX,
  62. };
  63. enum {
  64. LPASS_CDC_WSA_MACRO_TX0 = 0,
  65. LPASS_CDC_WSA_MACRO_TX1,
  66. LPASS_CDC_WSA_MACRO_TX_MAX,
  67. };
  68. enum {
  69. LPASS_CDC_WSA_MACRO_EC0_MUX = 0,
  70. LPASS_CDC_WSA_MACRO_EC1_MUX,
  71. LPASS_CDC_WSA_MACRO_EC_MUX_MAX,
  72. };
  73. enum {
  74. LPASS_CDC_WSA_MACRO_COMP1, /* SPK_L */
  75. LPASS_CDC_WSA_MACRO_COMP2, /* SPK_R */
  76. LPASS_CDC_WSA_MACRO_COMP_MAX
  77. };
  78. enum {
  79. LPASS_CDC_WSA_MACRO_SOFTCLIP0, /* RX0 */
  80. LPASS_CDC_WSA_MACRO_SOFTCLIP1, /* RX1 */
  81. LPASS_CDC_WSA_MACRO_SOFTCLIP_MAX
  82. };
  83. enum {
  84. INTn_1_INP_SEL_ZERO = 0,
  85. INTn_1_INP_SEL_RX0,
  86. INTn_1_INP_SEL_RX1,
  87. INTn_1_INP_SEL_RX2,
  88. INTn_1_INP_SEL_RX3,
  89. INTn_1_INP_SEL_RX4,
  90. INTn_1_INP_SEL_RX5,
  91. INTn_1_INP_SEL_DEC0,
  92. INTn_1_INP_SEL_DEC1,
  93. };
  94. enum {
  95. INTn_2_INP_SEL_ZERO = 0,
  96. INTn_2_INP_SEL_RX0,
  97. INTn_2_INP_SEL_RX1,
  98. INTn_2_INP_SEL_RX2,
  99. INTn_2_INP_SEL_RX3,
  100. INTn_2_INP_SEL_RX4,
  101. INTn_2_INP_SEL_RX5,
  102. };
  103. enum {
  104. WSA_MODE_21DB,
  105. WSA_MODE_19P5DB,
  106. WSA_MODE_18DB,
  107. WSA_MODE_16P5DB,
  108. WSA_MODE_15DB,
  109. WSA_MODE_13P5DB,
  110. WSA_MODE_12DB,
  111. WSA_MODE_10P5DB,
  112. WSA_MODE_9DB,
  113. WSA_MODE_MAX
  114. };
  115. static struct lpass_cdc_comp_setting comp_setting_table[WSA_MODE_MAX] =
  116. {
  117. {42, 0, 42},
  118. {39, 0, 42},
  119. {36, 0, 42},
  120. {33, 0, 42},
  121. {30, 0, 42},
  122. {27, 0, 42},
  123. {24, 0, 42},
  124. {21, 0, 42},
  125. {18, 0, 42},
  126. };
  127. struct interp_sample_rate {
  128. int sample_rate;
  129. int rate_val;
  130. };
  131. /*
  132. * Structure used to update codec
  133. * register defaults after reset
  134. */
  135. struct lpass_cdc_wsa_macro_reg_mask_val {
  136. u16 reg;
  137. u8 mask;
  138. u8 val;
  139. };
  140. static struct interp_sample_rate int_prim_sample_rate_val[] = {
  141. {8000, 0x0}, /* 8K */
  142. {16000, 0x1}, /* 16K */
  143. {24000, -EINVAL},/* 24K */
  144. {32000, 0x3}, /* 32K */
  145. {48000, 0x4}, /* 48K */
  146. {96000, 0x5}, /* 96K */
  147. {192000, 0x6}, /* 192K */
  148. {384000, 0x7}, /* 384K */
  149. {44100, 0x8}, /* 44.1K */
  150. };
  151. static struct interp_sample_rate int_mix_sample_rate_val[] = {
  152. {48000, 0x4}, /* 48K */
  153. {96000, 0x5}, /* 96K */
  154. {192000, 0x6}, /* 192K */
  155. };
  156. #define LPASS_CDC_WSA_MACRO_SWR_STRING_LEN 80
  157. static int lpass_cdc_wsa_macro_core_vote(void *handle, bool enable);
  158. static int lpass_cdc_wsa_macro_hw_params(struct snd_pcm_substream *substream,
  159. struct snd_pcm_hw_params *params,
  160. struct snd_soc_dai *dai);
  161. static int lpass_cdc_wsa_macro_get_channel_map(struct snd_soc_dai *dai,
  162. unsigned int *tx_num, unsigned int *tx_slot,
  163. unsigned int *rx_num, unsigned int *rx_slot);
  164. static int lpass_cdc_wsa_macro_mute_stream(struct snd_soc_dai *dai, int mute, int stream);
  165. /* Hold instance to soundwire platform device */
  166. struct lpass_cdc_wsa_macro_swr_ctrl_data {
  167. struct platform_device *wsa_swr_pdev;
  168. };
  169. struct lpass_cdc_wsa_macro_swr_ctrl_platform_data {
  170. void *handle; /* holds codec private data */
  171. int (*read)(void *handle, int reg);
  172. int (*write)(void *handle, int reg, int val);
  173. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  174. int (*clk)(void *handle, bool enable);
  175. int (*core_vote)(void *handle, bool enable);
  176. int (*handle_irq)(void *handle,
  177. irqreturn_t (*swrm_irq_handler)(int irq,
  178. void *data),
  179. void *swrm_handle,
  180. int action);
  181. };
  182. enum {
  183. LPASS_CDC_WSA_MACRO_AIF_INVALID = 0,
  184. LPASS_CDC_WSA_MACRO_AIF1_PB,
  185. LPASS_CDC_WSA_MACRO_AIF_MIX1_PB,
  186. LPASS_CDC_WSA_MACRO_AIF_VI,
  187. LPASS_CDC_WSA_MACRO_AIF_ECHO,
  188. LPASS_CDC_WSA_MACRO_MAX_DAIS,
  189. };
  190. #define LPASS_CDC_WSA_MACRO_CHILD_DEVICES_MAX 3
  191. /*
  192. * @dev: wsa macro device pointer
  193. * @comp_enabled: compander enable mixer value set
  194. * @ec_hq: echo HQ enable mixer value set
  195. * @prim_int_users: Users of interpolator
  196. * @wsa_mclk_users: WSA MCLK users count
  197. * @swr_clk_users: SWR clk users count
  198. * @vi_feed_value: VI sense mask
  199. * @mclk_lock: to lock mclk operations
  200. * @swr_clk_lock: to lock swr master clock operations
  201. * @swr_ctrl_data: SoundWire data structure
  202. * @swr_plat_data: Soundwire platform data
  203. * @lpass_cdc_wsa_macro_add_child_devices_work: work for adding child devices
  204. * @wsa_swr_gpio_p: used by pinctrl API
  205. * @component: codec handle
  206. * @rx_0_count: RX0 interpolation users
  207. * @rx_1_count: RX1 interpolation users
  208. * @active_ch_mask: channel mask for all AIF DAIs
  209. * @active_ch_cnt: channel count of all AIF DAIs
  210. * @rx_port_value: mixer ctl value of WSA RX MUXes
  211. * @wsa_io_base: Base address of WSA macro addr space
  212. */
  213. struct lpass_cdc_wsa_macro_priv {
  214. struct device *dev;
  215. int comp_enabled[LPASS_CDC_WSA_MACRO_COMP_MAX];
  216. int comp_mode[LPASS_CDC_WSA_MACRO_COMP_MAX];
  217. int ec_hq[LPASS_CDC_WSA_MACRO_RX1 + 1];
  218. u16 prim_int_users[LPASS_CDC_WSA_MACRO_RX1 + 1];
  219. u16 wsa_mclk_users;
  220. u16 swr_clk_users;
  221. bool dapm_mclk_enable;
  222. bool reset_swr;
  223. unsigned int vi_feed_value;
  224. struct mutex mclk_lock;
  225. struct mutex swr_clk_lock;
  226. struct lpass_cdc_wsa_macro_swr_ctrl_data *swr_ctrl_data;
  227. struct lpass_cdc_wsa_macro_swr_ctrl_platform_data swr_plat_data;
  228. struct work_struct lpass_cdc_wsa_macro_add_child_devices_work;
  229. struct device_node *wsa_swr_gpio_p;
  230. struct snd_soc_component *component;
  231. int rx_0_count;
  232. int rx_1_count;
  233. unsigned long active_ch_mask[LPASS_CDC_WSA_MACRO_MAX_DAIS];
  234. unsigned long active_ch_cnt[LPASS_CDC_WSA_MACRO_MAX_DAIS];
  235. int rx_port_value[LPASS_CDC_WSA_MACRO_RX_MAX];
  236. char __iomem *wsa_io_base;
  237. struct platform_device *pdev_child_devices
  238. [LPASS_CDC_WSA_MACRO_CHILD_DEVICES_MAX];
  239. int child_count;
  240. int ear_spkr_gain;
  241. int spkr_gain_offset;
  242. int spkr_mode;
  243. int is_softclip_on[LPASS_CDC_WSA_MACRO_SOFTCLIP_MAX];
  244. int softclip_clk_users[LPASS_CDC_WSA_MACRO_SOFTCLIP_MAX];
  245. char __iomem *mclk_mode_muxsel;
  246. u16 default_clk_id;
  247. u32 pcm_rate_vi;
  248. int wsa_digital_mute_status[LPASS_CDC_WSA_MACRO_RX_MAX];
  249. struct thermal_cooling_device *tcdev;
  250. uint32_t thermal_cur_state;
  251. uint32_t thermal_max_state;
  252. };
  253. static struct snd_soc_dai_driver lpass_cdc_wsa_macro_dai[];
  254. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  255. static const char *const rx_text[] = {
  256. "ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1", "RX4", "RX5", "DEC0", "DEC1"
  257. };
  258. static const char *const rx_mix_text[] = {
  259. "ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1", "RX4", "RX5",
  260. };
  261. static const char *const rx_mix_ec_text[] = {
  262. "ZERO", "RX_MIX_TX0", "RX_MIX_TX1"
  263. };
  264. static const char *const rx_mux_text[] = {
  265. "ZERO", "AIF1_PB", "AIF_MIX1_PB"
  266. };
  267. static const char *const rx_sidetone_mix_text[] = {
  268. "ZERO", "SRC0"
  269. };
  270. static const char * const lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_text[] = {
  271. "OFF", "ON"
  272. };
  273. static const char * const lpass_cdc_wsa_macro_comp_mode_text[] = {
  274. "G_21_DB", "G_19P5_DB", "G_18_DB", "G_16P5_DB", "G_15_DB",
  275. "G_13P5_DB", "G_12_DB", "G_10P5_DB", "G_9_DB"
  276. };
  277. static const struct snd_kcontrol_new wsa_int0_vbat_mix_switch[] = {
  278. SOC_DAPM_SINGLE("WSA RX0 VBAT Enable", SND_SOC_NOPM, 0, 1, 0)
  279. };
  280. static const struct snd_kcontrol_new wsa_int1_vbat_mix_switch[] = {
  281. SOC_DAPM_SINGLE("WSA RX1 VBAT Enable", SND_SOC_NOPM, 0, 1, 0)
  282. };
  283. static SOC_ENUM_SINGLE_EXT_DECL(lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_enum,
  284. lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_text);
  285. static SOC_ENUM_SINGLE_EXT_DECL(lpass_cdc_wsa_macro_comp_mode_enum,
  286. lpass_cdc_wsa_macro_comp_mode_text);
  287. /* RX INT0 */
  288. static const struct soc_enum rx0_prim_inp0_chain_enum =
  289. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
  290. 0, 9, rx_text);
  291. static const struct soc_enum rx0_prim_inp1_chain_enum =
  292. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
  293. 3, 9, rx_text);
  294. static const struct soc_enum rx0_prim_inp2_chain_enum =
  295. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
  296. 3, 9, rx_text);
  297. static const struct soc_enum rx0_mix_chain_enum =
  298. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
  299. 0, 7, rx_mix_text);
  300. static const struct soc_enum rx0_sidetone_mix_enum =
  301. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, 2, rx_sidetone_mix_text);
  302. static const struct snd_kcontrol_new rx0_prim_inp0_mux =
  303. SOC_DAPM_ENUM("WSA_RX0 INP0 Mux", rx0_prim_inp0_chain_enum);
  304. static const struct snd_kcontrol_new rx0_prim_inp1_mux =
  305. SOC_DAPM_ENUM("WSA_RX0 INP1 Mux", rx0_prim_inp1_chain_enum);
  306. static const struct snd_kcontrol_new rx0_prim_inp2_mux =
  307. SOC_DAPM_ENUM("WSA_RX0 INP2 Mux", rx0_prim_inp2_chain_enum);
  308. static const struct snd_kcontrol_new rx0_mix_mux =
  309. SOC_DAPM_ENUM("WSA_RX0 MIX Mux", rx0_mix_chain_enum);
  310. static const struct snd_kcontrol_new rx0_sidetone_mix_mux =
  311. SOC_DAPM_ENUM("WSA_RX0 SIDETONE MIX Mux", rx0_sidetone_mix_enum);
  312. /* RX INT1 */
  313. static const struct soc_enum rx1_prim_inp0_chain_enum =
  314. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
  315. 0, 9, rx_text);
  316. static const struct soc_enum rx1_prim_inp1_chain_enum =
  317. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
  318. 3, 9, rx_text);
  319. static const struct soc_enum rx1_prim_inp2_chain_enum =
  320. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
  321. 3, 9, rx_text);
  322. static const struct soc_enum rx1_mix_chain_enum =
  323. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
  324. 0, 7, rx_mix_text);
  325. static const struct snd_kcontrol_new rx1_prim_inp0_mux =
  326. SOC_DAPM_ENUM("WSA_RX1 INP0 Mux", rx1_prim_inp0_chain_enum);
  327. static const struct snd_kcontrol_new rx1_prim_inp1_mux =
  328. SOC_DAPM_ENUM("WSA_RX1 INP1 Mux", rx1_prim_inp1_chain_enum);
  329. static const struct snd_kcontrol_new rx1_prim_inp2_mux =
  330. SOC_DAPM_ENUM("WSA_RX1 INP2 Mux", rx1_prim_inp2_chain_enum);
  331. static const struct snd_kcontrol_new rx1_mix_mux =
  332. SOC_DAPM_ENUM("WSA_RX1 MIX Mux", rx1_mix_chain_enum);
  333. static const struct soc_enum rx_mix_ec0_enum =
  334. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
  335. 0, 3, rx_mix_ec_text);
  336. static const struct soc_enum rx_mix_ec1_enum =
  337. SOC_ENUM_SINGLE(LPASS_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
  338. 3, 3, rx_mix_ec_text);
  339. static const struct snd_kcontrol_new rx_mix_ec0_mux =
  340. SOC_DAPM_ENUM("WSA RX_MIX EC0_Mux", rx_mix_ec0_enum);
  341. static const struct snd_kcontrol_new rx_mix_ec1_mux =
  342. SOC_DAPM_ENUM("WSA RX_MIX EC1_Mux", rx_mix_ec1_enum);
  343. static struct snd_soc_dai_ops lpass_cdc_wsa_macro_dai_ops = {
  344. .hw_params = lpass_cdc_wsa_macro_hw_params,
  345. .get_channel_map = lpass_cdc_wsa_macro_get_channel_map,
  346. .mute_stream = lpass_cdc_wsa_macro_mute_stream,
  347. };
  348. static struct snd_soc_dai_driver lpass_cdc_wsa_macro_dai[] = {
  349. {
  350. .name = "wsa_macro_rx1",
  351. .id = LPASS_CDC_WSA_MACRO_AIF1_PB,
  352. .playback = {
  353. .stream_name = "WSA_AIF1 Playback",
  354. .rates = LPASS_CDC_WSA_MACRO_RX_RATES,
  355. .formats = LPASS_CDC_WSA_MACRO_RX_FORMATS,
  356. .rate_max = 384000,
  357. .rate_min = 8000,
  358. .channels_min = 1,
  359. .channels_max = 2,
  360. },
  361. .ops = &lpass_cdc_wsa_macro_dai_ops,
  362. },
  363. {
  364. .name = "wsa_macro_rx_mix",
  365. .id = LPASS_CDC_WSA_MACRO_AIF_MIX1_PB,
  366. .playback = {
  367. .stream_name = "WSA_AIF_MIX1 Playback",
  368. .rates = LPASS_CDC_WSA_MACRO_RX_MIX_RATES,
  369. .formats = LPASS_CDC_WSA_MACRO_RX_FORMATS,
  370. .rate_max = 192000,
  371. .rate_min = 48000,
  372. .channels_min = 1,
  373. .channels_max = 2,
  374. },
  375. .ops = &lpass_cdc_wsa_macro_dai_ops,
  376. },
  377. {
  378. .name = "wsa_macro_vifeedback",
  379. .id = LPASS_CDC_WSA_MACRO_AIF_VI,
  380. .capture = {
  381. .stream_name = "WSA_AIF_VI Capture",
  382. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  383. .formats = LPASS_CDC_WSA_MACRO_RX_FORMATS,
  384. .rate_max = 48000,
  385. .rate_min = 8000,
  386. .channels_min = 1,
  387. .channels_max = 4,
  388. },
  389. .ops = &lpass_cdc_wsa_macro_dai_ops,
  390. },
  391. {
  392. .name = "wsa_macro_echo",
  393. .id = LPASS_CDC_WSA_MACRO_AIF_ECHO,
  394. .capture = {
  395. .stream_name = "WSA_AIF_ECHO Capture",
  396. .rates = LPASS_CDC_WSA_MACRO_ECHO_RATES,
  397. .formats = LPASS_CDC_WSA_MACRO_ECHO_FORMATS,
  398. .rate_max = 48000,
  399. .rate_min = 8000,
  400. .channels_min = 1,
  401. .channels_max = 2,
  402. },
  403. .ops = &lpass_cdc_wsa_macro_dai_ops,
  404. },
  405. };
  406. static bool lpass_cdc_wsa_macro_get_data(struct snd_soc_component *component,
  407. struct device **wsa_dev,
  408. struct lpass_cdc_wsa_macro_priv **wsa_priv,
  409. const char *func_name)
  410. {
  411. *wsa_dev = lpass_cdc_get_device_ptr(component->dev,
  412. WSA_MACRO);
  413. if (!(*wsa_dev)) {
  414. dev_err(component->dev,
  415. "%s: null device for macro!\n", func_name);
  416. return false;
  417. }
  418. *wsa_priv = dev_get_drvdata((*wsa_dev));
  419. if (!(*wsa_priv) || !(*wsa_priv)->component) {
  420. dev_err(component->dev,
  421. "%s: priv is null for macro!\n", func_name);
  422. return false;
  423. }
  424. return true;
  425. }
  426. static int lpass_cdc_wsa_macro_set_port_map(struct snd_soc_component *component,
  427. u32 usecase, u32 size, void *data)
  428. {
  429. struct device *wsa_dev = NULL;
  430. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  431. struct swrm_port_config port_cfg;
  432. int ret = 0;
  433. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  434. return -EINVAL;
  435. memset(&port_cfg, 0, sizeof(port_cfg));
  436. port_cfg.uc = usecase;
  437. port_cfg.size = size;
  438. port_cfg.params = data;
  439. if (wsa_priv->swr_ctrl_data)
  440. ret = swrm_wcd_notify(
  441. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  442. SWR_SET_PORT_MAP, &port_cfg);
  443. return ret;
  444. }
  445. static int lpass_cdc_wsa_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  446. u8 int_prim_fs_rate_reg_val,
  447. u32 sample_rate)
  448. {
  449. u8 int_1_mix1_inp;
  450. u32 j, port;
  451. u16 int_mux_cfg0, int_mux_cfg1;
  452. u16 int_fs_reg;
  453. u8 int_mux_cfg0_val, int_mux_cfg1_val;
  454. u8 inp0_sel, inp1_sel, inp2_sel;
  455. struct snd_soc_component *component = dai->component;
  456. struct device *wsa_dev = NULL;
  457. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  458. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  459. return -EINVAL;
  460. for_each_set_bit(port, &wsa_priv->active_ch_mask[dai->id],
  461. LPASS_CDC_WSA_MACRO_RX_MAX) {
  462. int_1_mix1_inp = port;
  463. if ((int_1_mix1_inp < LPASS_CDC_WSA_MACRO_RX0) ||
  464. (int_1_mix1_inp > LPASS_CDC_WSA_MACRO_RX_MIX1)) {
  465. dev_err(wsa_dev,
  466. "%s: Invalid RX port, Dai ID is %d\n",
  467. __func__, dai->id);
  468. return -EINVAL;
  469. }
  470. int_mux_cfg0 = LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0;
  471. /*
  472. * Loop through all interpolator MUX inputs and find out
  473. * to which interpolator input, the cdc_dma rx port
  474. * is connected
  475. */
  476. for (j = 0; j < NUM_INTERPOLATORS; j++) {
  477. int_mux_cfg1 = int_mux_cfg0 + LPASS_CDC_WSA_MACRO_MUX_CFG1_OFFSET;
  478. int_mux_cfg0_val = snd_soc_component_read(component,
  479. int_mux_cfg0);
  480. int_mux_cfg1_val = snd_soc_component_read(component,
  481. int_mux_cfg1);
  482. inp0_sel = int_mux_cfg0_val & LPASS_CDC_WSA_MACRO_MUX_INP_MASK1;
  483. inp1_sel = (int_mux_cfg0_val >>
  484. LPASS_CDC_WSA_MACRO_MUX_INP_SHFT) &
  485. LPASS_CDC_WSA_MACRO_MUX_INP_MASK1;
  486. inp2_sel = (int_mux_cfg1_val >>
  487. LPASS_CDC_WSA_MACRO_MUX_INP_SHFT) &
  488. LPASS_CDC_WSA_MACRO_MUX_INP_MASK1;
  489. if ((inp0_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0) ||
  490. (inp1_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0) ||
  491. (inp2_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0)) {
  492. int_fs_reg = LPASS_CDC_WSA_RX0_RX_PATH_CTL +
  493. LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET * j;
  494. dev_dbg(wsa_dev,
  495. "%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  496. __func__, dai->id, j);
  497. dev_dbg(wsa_dev,
  498. "%s: set INT%u_1 sample rate to %u\n",
  499. __func__, j, sample_rate);
  500. /* sample_rate is in Hz */
  501. snd_soc_component_update_bits(component,
  502. int_fs_reg,
  503. LPASS_CDC_WSA_MACRO_FS_RATE_MASK,
  504. int_prim_fs_rate_reg_val);
  505. }
  506. int_mux_cfg0 += LPASS_CDC_WSA_MACRO_MUX_CFG_OFFSET;
  507. }
  508. }
  509. return 0;
  510. }
  511. static int lpass_cdc_wsa_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  512. u8 int_mix_fs_rate_reg_val,
  513. u32 sample_rate)
  514. {
  515. u8 int_2_inp;
  516. u32 j, port;
  517. u16 int_mux_cfg1, int_fs_reg;
  518. u8 int_mux_cfg1_val;
  519. struct snd_soc_component *component = dai->component;
  520. struct device *wsa_dev = NULL;
  521. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  522. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  523. return -EINVAL;
  524. for_each_set_bit(port, &wsa_priv->active_ch_mask[dai->id],
  525. LPASS_CDC_WSA_MACRO_RX_MAX) {
  526. int_2_inp = port;
  527. if ((int_2_inp < LPASS_CDC_WSA_MACRO_RX0) ||
  528. (int_2_inp > LPASS_CDC_WSA_MACRO_RX_MIX1)) {
  529. dev_err(wsa_dev,
  530. "%s: Invalid RX port, Dai ID is %d\n",
  531. __func__, dai->id);
  532. return -EINVAL;
  533. }
  534. int_mux_cfg1 = LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1;
  535. for (j = 0; j < NUM_INTERPOLATORS; j++) {
  536. int_mux_cfg1_val = snd_soc_component_read(component,
  537. int_mux_cfg1) &
  538. LPASS_CDC_WSA_MACRO_MUX_INP_MASK1;
  539. if (int_mux_cfg1_val == int_2_inp +
  540. INTn_2_INP_SEL_RX0) {
  541. int_fs_reg =
  542. LPASS_CDC_WSA_RX0_RX_PATH_MIX_CTL +
  543. LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET * j;
  544. dev_dbg(wsa_dev,
  545. "%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  546. __func__, dai->id, j);
  547. dev_dbg(wsa_dev,
  548. "%s: set INT%u_2 sample rate to %u\n",
  549. __func__, j, sample_rate);
  550. snd_soc_component_update_bits(component,
  551. int_fs_reg,
  552. LPASS_CDC_WSA_MACRO_FS_RATE_MASK,
  553. int_mix_fs_rate_reg_val);
  554. }
  555. int_mux_cfg1 += LPASS_CDC_WSA_MACRO_MUX_CFG_OFFSET;
  556. }
  557. }
  558. return 0;
  559. }
  560. static int lpass_cdc_wsa_macro_set_interpolator_rate(struct snd_soc_dai *dai,
  561. u32 sample_rate)
  562. {
  563. int rate_val = 0;
  564. int i, ret;
  565. /* set mixing path rate */
  566. for (i = 0; i < ARRAY_SIZE(int_mix_sample_rate_val); i++) {
  567. if (sample_rate ==
  568. int_mix_sample_rate_val[i].sample_rate) {
  569. rate_val =
  570. int_mix_sample_rate_val[i].rate_val;
  571. break;
  572. }
  573. }
  574. if ((i == ARRAY_SIZE(int_mix_sample_rate_val)) ||
  575. (rate_val < 0))
  576. goto prim_rate;
  577. ret = lpass_cdc_wsa_macro_set_mix_interpolator_rate(dai,
  578. (u8) rate_val, sample_rate);
  579. prim_rate:
  580. /* set primary path sample rate */
  581. for (i = 0; i < ARRAY_SIZE(int_prim_sample_rate_val); i++) {
  582. if (sample_rate ==
  583. int_prim_sample_rate_val[i].sample_rate) {
  584. rate_val =
  585. int_prim_sample_rate_val[i].rate_val;
  586. break;
  587. }
  588. }
  589. if ((i == ARRAY_SIZE(int_prim_sample_rate_val)) ||
  590. (rate_val < 0))
  591. return -EINVAL;
  592. ret = lpass_cdc_wsa_macro_set_prim_interpolator_rate(dai,
  593. (u8) rate_val, sample_rate);
  594. return ret;
  595. }
  596. static int lpass_cdc_wsa_macro_hw_params(struct snd_pcm_substream *substream,
  597. struct snd_pcm_hw_params *params,
  598. struct snd_soc_dai *dai)
  599. {
  600. struct snd_soc_component *component = dai->component;
  601. int ret;
  602. struct device *wsa_dev = NULL;
  603. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  604. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  605. return -EINVAL;
  606. wsa_priv = dev_get_drvdata(wsa_dev);
  607. if (!wsa_priv)
  608. return -EINVAL;
  609. dev_dbg(component->dev,
  610. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  611. dai->name, dai->id, params_rate(params),
  612. params_channels(params));
  613. switch (substream->stream) {
  614. case SNDRV_PCM_STREAM_PLAYBACK:
  615. ret = lpass_cdc_wsa_macro_set_interpolator_rate(dai, params_rate(params));
  616. if (ret) {
  617. dev_err(component->dev,
  618. "%s: cannot set sample rate: %u\n",
  619. __func__, params_rate(params));
  620. return ret;
  621. }
  622. break;
  623. case SNDRV_PCM_STREAM_CAPTURE:
  624. if (dai->id == LPASS_CDC_WSA_MACRO_AIF_VI)
  625. wsa_priv->pcm_rate_vi = params_rate(params);
  626. default:
  627. break;
  628. }
  629. return 0;
  630. }
  631. static int lpass_cdc_wsa_macro_get_channel_map(struct snd_soc_dai *dai,
  632. unsigned int *tx_num, unsigned int *tx_slot,
  633. unsigned int *rx_num, unsigned int *rx_slot)
  634. {
  635. struct snd_soc_component *component = dai->component;
  636. struct device *wsa_dev = NULL;
  637. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  638. u16 val = 0, mask = 0, cnt = 0, temp = 0;
  639. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  640. return -EINVAL;
  641. wsa_priv = dev_get_drvdata(wsa_dev);
  642. if (!wsa_priv)
  643. return -EINVAL;
  644. switch (dai->id) {
  645. case LPASS_CDC_WSA_MACRO_AIF_VI:
  646. *tx_slot = wsa_priv->active_ch_mask[dai->id];
  647. *tx_num = wsa_priv->active_ch_cnt[dai->id];
  648. break;
  649. case LPASS_CDC_WSA_MACRO_AIF1_PB:
  650. case LPASS_CDC_WSA_MACRO_AIF_MIX1_PB:
  651. for_each_set_bit(temp, &wsa_priv->active_ch_mask[dai->id],
  652. LPASS_CDC_WSA_MACRO_RX_MAX) {
  653. mask |= (1 << temp);
  654. if (++cnt == LPASS_CDC_WSA_MACRO_MAX_DMA_CH_PER_PORT)
  655. break;
  656. }
  657. if (mask & 0x0C)
  658. mask = mask >> 0x2;
  659. *rx_slot = mask;
  660. *rx_num = cnt;
  661. break;
  662. case LPASS_CDC_WSA_MACRO_AIF_ECHO:
  663. val = snd_soc_component_read(component,
  664. LPASS_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
  665. if (val & LPASS_CDC_WSA_MACRO_EC_MIX_TX1_MASK) {
  666. mask |= 0x2;
  667. cnt++;
  668. }
  669. if (val & LPASS_CDC_WSA_MACRO_EC_MIX_TX0_MASK) {
  670. mask |= 0x1;
  671. cnt++;
  672. }
  673. *tx_slot = mask;
  674. *tx_num = cnt;
  675. break;
  676. default:
  677. dev_err(wsa_dev, "%s: Invalid AIF\n", __func__);
  678. break;
  679. }
  680. return 0;
  681. }
  682. static int lpass_cdc_wsa_macro_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
  683. {
  684. struct snd_soc_component *component = dai->component;
  685. struct device *wsa_dev = NULL;
  686. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  687. uint16_t j = 0, reg = 0, mix_reg = 0, dsm_reg = 0;
  688. u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
  689. u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
  690. bool adie_lb = false;
  691. if (mute)
  692. return 0;
  693. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  694. return -EINVAL;
  695. switch (dai->id) {
  696. case LPASS_CDC_WSA_MACRO_AIF1_PB:
  697. case LPASS_CDC_WSA_MACRO_AIF_MIX1_PB:
  698. for (j = 0; j < NUM_INTERPOLATORS; j++) {
  699. reg = LPASS_CDC_WSA_RX0_RX_PATH_CTL +
  700. (j * LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET);
  701. mix_reg = LPASS_CDC_WSA_RX0_RX_PATH_MIX_CTL +
  702. (j * LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET);
  703. dsm_reg = LPASS_CDC_WSA_RX0_RX_PATH_CTL +
  704. (j * LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET) +
  705. LPASS_CDC_WSA_MACRO_RX_PATH_DSMDEM_OFFSET;
  706. int_mux_cfg0 = LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0 + j * 8;
  707. int_mux_cfg1 = int_mux_cfg0 + 4;
  708. int_mux_cfg0_val = snd_soc_component_read(component,
  709. int_mux_cfg0);
  710. int_mux_cfg1_val = snd_soc_component_read(component,
  711. int_mux_cfg1);
  712. if (snd_soc_component_read(component, dsm_reg) & 0x01) {
  713. if (int_mux_cfg0_val || (int_mux_cfg1_val & 0x38))
  714. snd_soc_component_update_bits(component, reg,
  715. 0x20, 0x20);
  716. if (int_mux_cfg1_val & 0x07) {
  717. snd_soc_component_update_bits(component, reg,
  718. 0x20, 0x20);
  719. snd_soc_component_update_bits(component,
  720. mix_reg, 0x20, 0x20);
  721. }
  722. }
  723. }
  724. lpass_cdc_wsa_pa_on(wsa_dev, adie_lb);
  725. break;
  726. default:
  727. break;
  728. }
  729. return 0;
  730. }
  731. static int lpass_cdc_wsa_macro_mclk_enable(
  732. struct lpass_cdc_wsa_macro_priv *wsa_priv,
  733. bool mclk_enable, bool dapm)
  734. {
  735. struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
  736. int ret = 0;
  737. if (regmap == NULL) {
  738. dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
  739. return -EINVAL;
  740. }
  741. dev_dbg(wsa_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  742. __func__, mclk_enable, dapm, wsa_priv->wsa_mclk_users);
  743. mutex_lock(&wsa_priv->mclk_lock);
  744. if (mclk_enable) {
  745. if (wsa_priv->wsa_mclk_users == 0) {
  746. ret = lpass_cdc_clk_rsc_request_clock(wsa_priv->dev,
  747. wsa_priv->default_clk_id,
  748. wsa_priv->default_clk_id,
  749. true);
  750. if (ret < 0) {
  751. dev_err_ratelimited(wsa_priv->dev,
  752. "%s: wsa request clock enable failed\n",
  753. __func__);
  754. goto exit;
  755. }
  756. lpass_cdc_clk_rsc_fs_gen_request(wsa_priv->dev,
  757. true);
  758. regcache_mark_dirty(regmap);
  759. regcache_sync_region(regmap,
  760. WSA_START_OFFSET,
  761. WSA_MAX_OFFSET);
  762. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  763. regmap_update_bits(regmap,
  764. LPASS_CDC_WSA_TOP_FREQ_MCLK, 0x01, 0x01);
  765. regmap_update_bits(regmap,
  766. LPASS_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
  767. 0x01, 0x01);
  768. regmap_update_bits(regmap,
  769. LPASS_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
  770. 0x01, 0x01);
  771. }
  772. wsa_priv->wsa_mclk_users++;
  773. } else {
  774. if (wsa_priv->wsa_mclk_users <= 0) {
  775. dev_err(wsa_priv->dev, "%s: clock already disabled\n",
  776. __func__);
  777. wsa_priv->wsa_mclk_users = 0;
  778. goto exit;
  779. }
  780. wsa_priv->wsa_mclk_users--;
  781. if (wsa_priv->wsa_mclk_users == 0) {
  782. regmap_update_bits(regmap,
  783. LPASS_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
  784. 0x01, 0x00);
  785. regmap_update_bits(regmap,
  786. LPASS_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
  787. 0x01, 0x00);
  788. lpass_cdc_clk_rsc_fs_gen_request(wsa_priv->dev,
  789. false);
  790. lpass_cdc_clk_rsc_request_clock(wsa_priv->dev,
  791. wsa_priv->default_clk_id,
  792. wsa_priv->default_clk_id,
  793. false);
  794. }
  795. }
  796. exit:
  797. mutex_unlock(&wsa_priv->mclk_lock);
  798. return ret;
  799. }
  800. static int lpass_cdc_wsa_macro_mclk_event(struct snd_soc_dapm_widget *w,
  801. struct snd_kcontrol *kcontrol, int event)
  802. {
  803. struct snd_soc_component *component =
  804. snd_soc_dapm_to_component(w->dapm);
  805. int ret = 0;
  806. struct device *wsa_dev = NULL;
  807. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  808. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  809. return -EINVAL;
  810. dev_dbg(wsa_dev, "%s: event = %d\n", __func__, event);
  811. switch (event) {
  812. case SND_SOC_DAPM_PRE_PMU:
  813. ret = lpass_cdc_wsa_macro_mclk_enable(wsa_priv, 1, true);
  814. if (ret)
  815. wsa_priv->dapm_mclk_enable = false;
  816. else
  817. wsa_priv->dapm_mclk_enable = true;
  818. break;
  819. case SND_SOC_DAPM_POST_PMD:
  820. if (wsa_priv->dapm_mclk_enable)
  821. lpass_cdc_wsa_macro_mclk_enable(wsa_priv, 0, true);
  822. break;
  823. default:
  824. dev_err(wsa_priv->dev,
  825. "%s: invalid DAPM event %d\n", __func__, event);
  826. ret = -EINVAL;
  827. }
  828. return ret;
  829. }
  830. static int lpass_cdc_wsa_macro_event_handler(struct snd_soc_component *component,
  831. u16 event, u32 data)
  832. {
  833. struct device *wsa_dev = NULL;
  834. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  835. int ret = 0;
  836. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  837. return -EINVAL;
  838. switch (event) {
  839. case LPASS_CDC_MACRO_EVT_SSR_DOWN:
  840. trace_printk("%s, enter SSR down\n", __func__);
  841. if (wsa_priv->swr_ctrl_data) {
  842. swrm_wcd_notify(
  843. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  844. SWR_DEVICE_SSR_DOWN, NULL);
  845. }
  846. if ((!pm_runtime_enabled(wsa_dev) ||
  847. !pm_runtime_suspended(wsa_dev))) {
  848. ret = lpass_cdc_runtime_suspend(wsa_dev);
  849. if (!ret) {
  850. pm_runtime_disable(wsa_dev);
  851. pm_runtime_set_suspended(wsa_dev);
  852. pm_runtime_enable(wsa_dev);
  853. }
  854. }
  855. break;
  856. case LPASS_CDC_MACRO_EVT_PRE_SSR_UP:
  857. /* enable&disable WSA_CORE_CLK to reset GFMUX reg */
  858. lpass_cdc_wsa_macro_core_vote(wsa_priv, true);
  859. ret = lpass_cdc_clk_rsc_request_clock(wsa_priv->dev,
  860. wsa_priv->default_clk_id,
  861. WSA_CORE_CLK, true);
  862. if (ret < 0)
  863. dev_err_ratelimited(wsa_priv->dev,
  864. "%s, failed to enable clk, ret:%d\n",
  865. __func__, ret);
  866. else
  867. lpass_cdc_clk_rsc_request_clock(wsa_priv->dev,
  868. wsa_priv->default_clk_id,
  869. WSA_CORE_CLK, false);
  870. lpass_cdc_wsa_macro_core_vote(wsa_priv, false);
  871. break;
  872. case LPASS_CDC_MACRO_EVT_SSR_UP:
  873. trace_printk("%s, enter SSR up\n", __func__);
  874. /* reset swr after ssr/pdr */
  875. wsa_priv->reset_swr = true;
  876. if (wsa_priv->swr_ctrl_data)
  877. swrm_wcd_notify(
  878. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  879. SWR_DEVICE_SSR_UP, NULL);
  880. break;
  881. case LPASS_CDC_MACRO_EVT_CLK_RESET:
  882. lpass_cdc_rsc_clk_reset(wsa_dev, WSA_CORE_CLK);
  883. break;
  884. }
  885. return 0;
  886. }
  887. static int lpass_cdc_wsa_macro_enable_vi_feedback(struct snd_soc_dapm_widget *w,
  888. struct snd_kcontrol *kcontrol,
  889. int event)
  890. {
  891. struct snd_soc_component *component =
  892. snd_soc_dapm_to_component(w->dapm);
  893. struct device *wsa_dev = NULL;
  894. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  895. u8 val = 0x0;
  896. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  897. return -EINVAL;
  898. switch (wsa_priv->pcm_rate_vi) {
  899. case 48000:
  900. val = 0x04;
  901. break;
  902. case 24000:
  903. val = 0x02;
  904. break;
  905. case 8000:
  906. default:
  907. val = 0x00;
  908. break;
  909. }
  910. switch (event) {
  911. case SND_SOC_DAPM_POST_PMU:
  912. if (test_bit(LPASS_CDC_WSA_MACRO_TX0,
  913. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  914. dev_dbg(wsa_dev, "%s: spkr1 enabled\n", __func__);
  915. /* Enable V&I sensing */
  916. snd_soc_component_update_bits(component,
  917. LPASS_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  918. 0x20, 0x20);
  919. snd_soc_component_update_bits(component,
  920. LPASS_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  921. 0x20, 0x20);
  922. snd_soc_component_update_bits(component,
  923. LPASS_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  924. 0x0F, val);
  925. snd_soc_component_update_bits(component,
  926. LPASS_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  927. 0x0F, val);
  928. snd_soc_component_update_bits(component,
  929. LPASS_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  930. 0x10, 0x10);
  931. snd_soc_component_update_bits(component,
  932. LPASS_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  933. 0x10, 0x10);
  934. snd_soc_component_update_bits(component,
  935. LPASS_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  936. 0x20, 0x00);
  937. snd_soc_component_update_bits(component,
  938. LPASS_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  939. 0x20, 0x00);
  940. }
  941. if (test_bit(LPASS_CDC_WSA_MACRO_TX1,
  942. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  943. dev_dbg(wsa_dev, "%s: spkr2 enabled\n", __func__);
  944. /* Enable V&I sensing */
  945. snd_soc_component_update_bits(component,
  946. LPASS_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  947. 0x20, 0x20);
  948. snd_soc_component_update_bits(component,
  949. LPASS_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  950. 0x20, 0x20);
  951. snd_soc_component_update_bits(component,
  952. LPASS_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  953. 0x0F, val);
  954. snd_soc_component_update_bits(component,
  955. LPASS_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  956. 0x0F, val);
  957. snd_soc_component_update_bits(component,
  958. LPASS_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  959. 0x10, 0x10);
  960. snd_soc_component_update_bits(component,
  961. LPASS_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  962. 0x10, 0x10);
  963. snd_soc_component_update_bits(component,
  964. LPASS_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  965. 0x20, 0x00);
  966. snd_soc_component_update_bits(component,
  967. LPASS_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  968. 0x20, 0x00);
  969. }
  970. break;
  971. case SND_SOC_DAPM_POST_PMD:
  972. if (test_bit(LPASS_CDC_WSA_MACRO_TX0,
  973. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  974. /* Disable V&I sensing */
  975. snd_soc_component_update_bits(component,
  976. LPASS_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  977. 0x20, 0x20);
  978. snd_soc_component_update_bits(component,
  979. LPASS_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  980. 0x20, 0x20);
  981. dev_dbg(wsa_dev, "%s: spkr1 disabled\n", __func__);
  982. snd_soc_component_update_bits(component,
  983. LPASS_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  984. 0x10, 0x00);
  985. snd_soc_component_update_bits(component,
  986. LPASS_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  987. 0x10, 0x00);
  988. }
  989. if (test_bit(LPASS_CDC_WSA_MACRO_TX1,
  990. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  991. /* Disable V&I sensing */
  992. dev_dbg(wsa_dev, "%s: spkr2 disabled\n", __func__);
  993. snd_soc_component_update_bits(component,
  994. LPASS_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  995. 0x20, 0x20);
  996. snd_soc_component_update_bits(component,
  997. LPASS_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  998. 0x20, 0x20);
  999. snd_soc_component_update_bits(component,
  1000. LPASS_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  1001. 0x10, 0x00);
  1002. snd_soc_component_update_bits(component,
  1003. LPASS_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  1004. 0x10, 0x00);
  1005. }
  1006. break;
  1007. }
  1008. return 0;
  1009. }
  1010. static void lpass_cdc_wsa_macro_hd2_control(struct snd_soc_component *component,
  1011. u16 reg, int event)
  1012. {
  1013. u16 hd2_scale_reg;
  1014. u16 hd2_enable_reg = 0;
  1015. if (reg == LPASS_CDC_WSA_RX0_RX_PATH_CTL) {
  1016. hd2_scale_reg = LPASS_CDC_WSA_RX0_RX_PATH_SEC3;
  1017. hd2_enable_reg = LPASS_CDC_WSA_RX0_RX_PATH_CFG0;
  1018. }
  1019. if (reg == LPASS_CDC_WSA_RX1_RX_PATH_CTL) {
  1020. hd2_scale_reg = LPASS_CDC_WSA_RX1_RX_PATH_SEC3;
  1021. hd2_enable_reg = LPASS_CDC_WSA_RX1_RX_PATH_CFG0;
  1022. }
  1023. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1024. snd_soc_component_update_bits(component, hd2_scale_reg,
  1025. 0x3C, 0x10);
  1026. snd_soc_component_update_bits(component, hd2_scale_reg,
  1027. 0x03, 0x01);
  1028. snd_soc_component_update_bits(component, hd2_enable_reg,
  1029. 0x04, 0x04);
  1030. }
  1031. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1032. snd_soc_component_update_bits(component, hd2_enable_reg,
  1033. 0x04, 0x00);
  1034. snd_soc_component_update_bits(component, hd2_scale_reg,
  1035. 0x03, 0x00);
  1036. snd_soc_component_update_bits(component, hd2_scale_reg,
  1037. 0x3C, 0x00);
  1038. }
  1039. }
  1040. static int lpass_cdc_wsa_macro_enable_swr(struct snd_soc_dapm_widget *w,
  1041. struct snd_kcontrol *kcontrol, int event)
  1042. {
  1043. struct snd_soc_component *component =
  1044. snd_soc_dapm_to_component(w->dapm);
  1045. int ch_cnt;
  1046. struct device *wsa_dev = NULL;
  1047. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1048. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1049. return -EINVAL;
  1050. switch (event) {
  1051. case SND_SOC_DAPM_PRE_PMU:
  1052. if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
  1053. !wsa_priv->rx_0_count)
  1054. wsa_priv->rx_0_count++;
  1055. if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
  1056. !wsa_priv->rx_1_count)
  1057. wsa_priv->rx_1_count++;
  1058. ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
  1059. if (wsa_priv->swr_ctrl_data) {
  1060. swrm_wcd_notify(
  1061. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  1062. SWR_DEVICE_UP, NULL);
  1063. swrm_wcd_notify(
  1064. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  1065. SWR_SET_NUM_RX_CH, &ch_cnt);
  1066. }
  1067. break;
  1068. case SND_SOC_DAPM_POST_PMD:
  1069. if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
  1070. wsa_priv->rx_0_count)
  1071. wsa_priv->rx_0_count--;
  1072. if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
  1073. wsa_priv->rx_1_count)
  1074. wsa_priv->rx_1_count--;
  1075. ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
  1076. if (wsa_priv->swr_ctrl_data)
  1077. swrm_wcd_notify(
  1078. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  1079. SWR_SET_NUM_RX_CH, &ch_cnt);
  1080. break;
  1081. }
  1082. dev_dbg(wsa_priv->dev, "%s: current swr ch cnt: %d\n",
  1083. __func__, wsa_priv->rx_0_count + wsa_priv->rx_1_count);
  1084. return 0;
  1085. }
  1086. static int lpass_cdc_wsa_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  1087. struct snd_kcontrol *kcontrol, int event)
  1088. {
  1089. struct snd_soc_component *component =
  1090. snd_soc_dapm_to_component(w->dapm);
  1091. u16 gain_reg;
  1092. int offset_val = 0;
  1093. int val = 0;
  1094. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1095. if (!(strcmp(w->name, "WSA_RX0 MIX INP"))) {
  1096. gain_reg = LPASS_CDC_WSA_RX0_RX_VOL_MIX_CTL;
  1097. } else if (!(strcmp(w->name, "WSA_RX1 MIX INP"))) {
  1098. gain_reg = LPASS_CDC_WSA_RX1_RX_VOL_MIX_CTL;
  1099. } else {
  1100. dev_err(component->dev, "%s: No gain register avail for %s\n",
  1101. __func__, w->name);
  1102. return 0;
  1103. }
  1104. switch (event) {
  1105. case SND_SOC_DAPM_PRE_PMU:
  1106. lpass_cdc_wsa_macro_enable_swr(w, kcontrol, event);
  1107. val = snd_soc_component_read(component, gain_reg);
  1108. val += offset_val;
  1109. snd_soc_component_write(component, gain_reg, val);
  1110. break;
  1111. case SND_SOC_DAPM_POST_PMD:
  1112. snd_soc_component_update_bits(component,
  1113. w->reg, 0x20, 0x00);
  1114. lpass_cdc_wsa_macro_enable_swr(w, kcontrol, event);
  1115. break;
  1116. }
  1117. return 0;
  1118. }
  1119. static int lpass_cdc_wsa_macro_config_compander(struct snd_soc_component *component,
  1120. int comp, int event)
  1121. {
  1122. u16 comp_ctl0_reg, comp_ctl8_reg, rx_path_cfg0_reg;
  1123. struct device *wsa_dev = NULL;
  1124. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1125. u16 mode = 0;
  1126. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1127. return -EINVAL;
  1128. dev_dbg(component->dev, "%s: event %d compander %d, enabled %d\n",
  1129. __func__, event, comp + 1, wsa_priv->comp_enabled[comp]);
  1130. if (!wsa_priv->comp_enabled[comp])
  1131. return 0;
  1132. mode = wsa_priv->comp_mode[comp];
  1133. comp_ctl0_reg = LPASS_CDC_WSA_COMPANDER0_CTL0 +
  1134. (comp * LPASS_CDC_WSA_MACRO_RX_COMP_OFFSET);
  1135. comp_ctl8_reg = LPASS_CDC_WSA_COMPANDER0_CTL8 +
  1136. (comp * LPASS_CDC_WSA_MACRO_RX_COMP_OFFSET);
  1137. rx_path_cfg0_reg = LPASS_CDC_WSA_RX0_RX_PATH_CFG0 +
  1138. (comp * LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET);
  1139. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1140. lpass_cdc_update_compander_setting(component,
  1141. comp_ctl8_reg,
  1142. &comp_setting_table[mode]);
  1143. /* Enable Compander Clock */
  1144. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1145. 0x01, 0x01);
  1146. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1147. 0x02, 0x02);
  1148. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1149. 0x02, 0x00);
  1150. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1151. 0x02, 0x02);
  1152. }
  1153. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1154. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1155. 0x04, 0x04);
  1156. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1157. 0x02, 0x00);
  1158. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1159. 0x02, 0x02);
  1160. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1161. 0x02, 0x00);
  1162. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1163. 0x01, 0x00);
  1164. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1165. 0x04, 0x00);
  1166. }
  1167. return 0;
  1168. }
  1169. static void lpass_cdc_wsa_macro_enable_softclip_clk(struct snd_soc_component *component,
  1170. struct lpass_cdc_wsa_macro_priv *wsa_priv,
  1171. int path,
  1172. bool enable)
  1173. {
  1174. u16 softclip_clk_reg = LPASS_CDC_WSA_SOFTCLIP0_CRC +
  1175. (path * LPASS_CDC_WSA_MACRO_RX_SOFTCLIP_OFFSET);
  1176. u8 softclip_mux_mask = (1 << path);
  1177. u8 softclip_mux_value = (1 << path);
  1178. dev_dbg(component->dev, "%s: path %d, enable %d\n",
  1179. __func__, path, enable);
  1180. if (enable) {
  1181. if (wsa_priv->softclip_clk_users[path] == 0) {
  1182. snd_soc_component_update_bits(component,
  1183. softclip_clk_reg, 0x01, 0x01);
  1184. snd_soc_component_update_bits(component,
  1185. LPASS_CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
  1186. softclip_mux_mask, softclip_mux_value);
  1187. }
  1188. wsa_priv->softclip_clk_users[path]++;
  1189. } else {
  1190. wsa_priv->softclip_clk_users[path]--;
  1191. if (wsa_priv->softclip_clk_users[path] == 0) {
  1192. snd_soc_component_update_bits(component,
  1193. softclip_clk_reg, 0x01, 0x00);
  1194. snd_soc_component_update_bits(component,
  1195. LPASS_CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
  1196. softclip_mux_mask, 0x00);
  1197. }
  1198. }
  1199. }
  1200. static int lpass_cdc_wsa_macro_config_softclip(struct snd_soc_component *component,
  1201. int path, int event)
  1202. {
  1203. u16 softclip_ctrl_reg = 0;
  1204. struct device *wsa_dev = NULL;
  1205. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1206. int softclip_path = 0;
  1207. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1208. return -EINVAL;
  1209. if (path == LPASS_CDC_WSA_MACRO_COMP1)
  1210. softclip_path = LPASS_CDC_WSA_MACRO_SOFTCLIP0;
  1211. else if (path == LPASS_CDC_WSA_MACRO_COMP2)
  1212. softclip_path = LPASS_CDC_WSA_MACRO_SOFTCLIP1;
  1213. dev_dbg(component->dev, "%s: event %d path %d, enabled %d\n",
  1214. __func__, event, softclip_path,
  1215. wsa_priv->is_softclip_on[softclip_path]);
  1216. if (!wsa_priv->is_softclip_on[softclip_path])
  1217. return 0;
  1218. softclip_ctrl_reg = LPASS_CDC_WSA_SOFTCLIP0_SOFTCLIP_CTRL +
  1219. (softclip_path * LPASS_CDC_WSA_MACRO_RX_SOFTCLIP_OFFSET);
  1220. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1221. /* Enable Softclip clock and mux */
  1222. lpass_cdc_wsa_macro_enable_softclip_clk(component, wsa_priv,
  1223. softclip_path, true);
  1224. /* Enable Softclip control */
  1225. snd_soc_component_update_bits(component, softclip_ctrl_reg,
  1226. 0x01, 0x01);
  1227. }
  1228. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1229. snd_soc_component_update_bits(component, softclip_ctrl_reg,
  1230. 0x01, 0x00);
  1231. lpass_cdc_wsa_macro_enable_softclip_clk(component, wsa_priv,
  1232. softclip_path, false);
  1233. }
  1234. return 0;
  1235. }
  1236. static bool lpass_cdc_wsa_macro_adie_lb(struct snd_soc_component *component,
  1237. int interp_idx)
  1238. {
  1239. u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
  1240. u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
  1241. u8 int_n_inp0 = 0, int_n_inp1 = 0, int_n_inp2 = 0;
  1242. int_mux_cfg0 = LPASS_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0 + interp_idx * 8;
  1243. int_mux_cfg1 = int_mux_cfg0 + 4;
  1244. int_mux_cfg0_val = snd_soc_component_read(component, int_mux_cfg0);
  1245. int_mux_cfg1_val = snd_soc_component_read(component, int_mux_cfg1);
  1246. int_n_inp0 = int_mux_cfg0_val & 0x0F;
  1247. if (int_n_inp0 == INTn_1_INP_SEL_DEC0 ||
  1248. int_n_inp0 == INTn_1_INP_SEL_DEC1)
  1249. return true;
  1250. int_n_inp1 = int_mux_cfg0_val >> 4;
  1251. if (int_n_inp1 == INTn_1_INP_SEL_DEC0 ||
  1252. int_n_inp1 == INTn_1_INP_SEL_DEC1)
  1253. return true;
  1254. int_n_inp2 = int_mux_cfg1_val >> 4;
  1255. if (int_n_inp2 == INTn_1_INP_SEL_DEC0 ||
  1256. int_n_inp2 == INTn_1_INP_SEL_DEC1)
  1257. return true;
  1258. return false;
  1259. }
  1260. static int lpass_cdc_wsa_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  1261. struct snd_kcontrol *kcontrol,
  1262. int event)
  1263. {
  1264. struct snd_soc_component *component =
  1265. snd_soc_dapm_to_component(w->dapm);
  1266. u16 reg = 0;
  1267. struct device *wsa_dev = NULL;
  1268. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1269. bool adie_lb = false;
  1270. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1271. return -EINVAL;
  1272. reg = LPASS_CDC_WSA_RX0_RX_PATH_CTL +
  1273. LPASS_CDC_WSA_MACRO_RX_PATH_OFFSET * w->shift;
  1274. switch (event) {
  1275. case SND_SOC_DAPM_PRE_PMU:
  1276. if (lpass_cdc_wsa_macro_adie_lb(component, w->shift)) {
  1277. adie_lb = true;
  1278. snd_soc_component_update_bits(component,
  1279. reg, 0x20, 0x20);
  1280. lpass_cdc_wsa_pa_on(wsa_dev, adie_lb);
  1281. }
  1282. break;
  1283. default:
  1284. break;
  1285. }
  1286. return 0;
  1287. }
  1288. static int lpass_cdc_wsa_macro_interp_get_primary_reg(u16 reg, u16 *ind)
  1289. {
  1290. u16 prim_int_reg = 0;
  1291. switch (reg) {
  1292. case LPASS_CDC_WSA_RX0_RX_PATH_CTL:
  1293. case LPASS_CDC_WSA_RX0_RX_PATH_MIX_CTL:
  1294. prim_int_reg = LPASS_CDC_WSA_RX0_RX_PATH_CTL;
  1295. *ind = 0;
  1296. break;
  1297. case LPASS_CDC_WSA_RX1_RX_PATH_CTL:
  1298. case LPASS_CDC_WSA_RX1_RX_PATH_MIX_CTL:
  1299. prim_int_reg = LPASS_CDC_WSA_RX1_RX_PATH_CTL;
  1300. *ind = 1;
  1301. break;
  1302. }
  1303. return prim_int_reg;
  1304. }
  1305. static int lpass_cdc_wsa_macro_enable_prim_interpolator(
  1306. struct snd_soc_component *component,
  1307. u16 reg, int event)
  1308. {
  1309. u16 prim_int_reg;
  1310. u16 ind = 0;
  1311. struct device *wsa_dev = NULL;
  1312. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1313. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1314. return -EINVAL;
  1315. prim_int_reg = lpass_cdc_wsa_macro_interp_get_primary_reg(reg, &ind);
  1316. switch (event) {
  1317. case SND_SOC_DAPM_PRE_PMU:
  1318. wsa_priv->prim_int_users[ind]++;
  1319. if (wsa_priv->prim_int_users[ind] == 1) {
  1320. snd_soc_component_update_bits(component,
  1321. prim_int_reg + LPASS_CDC_WSA_MACRO_RX_PATH_CFG3_OFFSET,
  1322. 0x03, 0x03);
  1323. snd_soc_component_update_bits(component, prim_int_reg,
  1324. 0x10, 0x10);
  1325. lpass_cdc_wsa_macro_hd2_control(component, prim_int_reg, event);
  1326. snd_soc_component_update_bits(component,
  1327. prim_int_reg + LPASS_CDC_WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
  1328. 0x1, 0x1);
  1329. }
  1330. if ((reg != prim_int_reg) &&
  1331. ((snd_soc_component_read(
  1332. component, prim_int_reg)) & 0x10))
  1333. snd_soc_component_update_bits(component, reg,
  1334. 0x10, 0x10);
  1335. break;
  1336. case SND_SOC_DAPM_POST_PMD:
  1337. wsa_priv->prim_int_users[ind]--;
  1338. if (wsa_priv->prim_int_users[ind] == 0) {
  1339. snd_soc_component_update_bits(component, prim_int_reg,
  1340. 1 << 0x5, 0 << 0x5);
  1341. snd_soc_component_update_bits(component,
  1342. prim_int_reg + LPASS_CDC_WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
  1343. 0x1, 0x0);
  1344. snd_soc_component_update_bits(component, prim_int_reg,
  1345. 0x40, 0x40);
  1346. snd_soc_component_update_bits(component, prim_int_reg,
  1347. 0x40, 0x00);
  1348. lpass_cdc_wsa_macro_hd2_control(component, prim_int_reg, event);
  1349. }
  1350. break;
  1351. }
  1352. dev_dbg(component->dev, "%s: primary interpolator: INT%d, users: %d\n",
  1353. __func__, ind, wsa_priv->prim_int_users[ind]);
  1354. return 0;
  1355. }
  1356. static int lpass_cdc_wsa_macro_enable_interpolator(struct snd_soc_dapm_widget *w,
  1357. struct snd_kcontrol *kcontrol,
  1358. int event)
  1359. {
  1360. struct snd_soc_component *component =
  1361. snd_soc_dapm_to_component(w->dapm);
  1362. u16 reg = 0;
  1363. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1364. if (!(strcmp(w->name, "WSA_RX INT0 INTERP"))) {
  1365. reg = LPASS_CDC_WSA_RX0_RX_PATH_CTL;
  1366. } else if (!(strcmp(w->name, "WSA_RX INT1 INTERP"))) {
  1367. reg = LPASS_CDC_WSA_RX1_RX_PATH_CTL;
  1368. } else {
  1369. dev_err(component->dev, "%s: Interpolator reg not found\n",
  1370. __func__);
  1371. return -EINVAL;
  1372. }
  1373. switch (event) {
  1374. case SND_SOC_DAPM_PRE_PMU:
  1375. /* Reset if needed */
  1376. lpass_cdc_wsa_macro_enable_prim_interpolator(component, reg, event);
  1377. break;
  1378. case SND_SOC_DAPM_POST_PMU:
  1379. lpass_cdc_wsa_macro_config_compander(component, w->shift, event);
  1380. lpass_cdc_wsa_macro_config_softclip(component, w->shift, event);
  1381. break;
  1382. case SND_SOC_DAPM_POST_PMD:
  1383. lpass_cdc_wsa_macro_config_compander(component, w->shift, event);
  1384. lpass_cdc_wsa_macro_config_softclip(component, w->shift, event);
  1385. lpass_cdc_wsa_macro_enable_prim_interpolator(component, reg, event);
  1386. break;
  1387. }
  1388. return 0;
  1389. }
  1390. static int lpass_cdc_wsa_macro_spk_boost_event(struct snd_soc_dapm_widget *w,
  1391. struct snd_kcontrol *kcontrol,
  1392. int event)
  1393. {
  1394. struct snd_soc_component *component =
  1395. snd_soc_dapm_to_component(w->dapm);
  1396. u16 boost_path_ctl, boost_path_cfg1;
  1397. u16 reg, reg_mix;
  1398. dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
  1399. if (!strcmp(w->name, "WSA_RX INT0 CHAIN")) {
  1400. boost_path_ctl = LPASS_CDC_WSA_BOOST0_BOOST_PATH_CTL;
  1401. boost_path_cfg1 = LPASS_CDC_WSA_RX0_RX_PATH_CFG1;
  1402. reg = LPASS_CDC_WSA_RX0_RX_PATH_CTL;
  1403. reg_mix = LPASS_CDC_WSA_RX0_RX_PATH_MIX_CTL;
  1404. } else if (!strcmp(w->name, "WSA_RX INT1 CHAIN")) {
  1405. boost_path_ctl = LPASS_CDC_WSA_BOOST1_BOOST_PATH_CTL;
  1406. boost_path_cfg1 = LPASS_CDC_WSA_RX1_RX_PATH_CFG1;
  1407. reg = LPASS_CDC_WSA_RX1_RX_PATH_CTL;
  1408. reg_mix = LPASS_CDC_WSA_RX1_RX_PATH_MIX_CTL;
  1409. } else {
  1410. dev_err(component->dev, "%s: unknown widget: %s\n",
  1411. __func__, w->name);
  1412. return -EINVAL;
  1413. }
  1414. switch (event) {
  1415. case SND_SOC_DAPM_PRE_PMU:
  1416. snd_soc_component_update_bits(component, boost_path_cfg1,
  1417. 0x01, 0x01);
  1418. snd_soc_component_update_bits(component, boost_path_ctl,
  1419. 0x10, 0x10);
  1420. if ((snd_soc_component_read(component, reg_mix)) & 0x10)
  1421. snd_soc_component_update_bits(component, reg_mix,
  1422. 0x10, 0x00);
  1423. break;
  1424. case SND_SOC_DAPM_POST_PMU:
  1425. snd_soc_component_update_bits(component, reg, 0x10, 0x00);
  1426. break;
  1427. case SND_SOC_DAPM_POST_PMD:
  1428. snd_soc_component_update_bits(component, boost_path_ctl,
  1429. 0x10, 0x00);
  1430. snd_soc_component_update_bits(component, boost_path_cfg1,
  1431. 0x01, 0x00);
  1432. break;
  1433. }
  1434. return 0;
  1435. }
  1436. static int lpass_cdc_wsa_macro_enable_vbat(struct snd_soc_dapm_widget *w,
  1437. struct snd_kcontrol *kcontrol,
  1438. int event)
  1439. {
  1440. struct snd_soc_component *component =
  1441. snd_soc_dapm_to_component(w->dapm);
  1442. struct device *wsa_dev = NULL;
  1443. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1444. u16 vbat_path_cfg = 0;
  1445. int softclip_path = 0;
  1446. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1447. return -EINVAL;
  1448. dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
  1449. if (!strcmp(w->name, "WSA_RX INT0 VBAT")) {
  1450. vbat_path_cfg = LPASS_CDC_WSA_RX0_RX_PATH_CFG1;
  1451. softclip_path = LPASS_CDC_WSA_MACRO_SOFTCLIP0;
  1452. } else if (!strcmp(w->name, "WSA_RX INT1 VBAT")) {
  1453. vbat_path_cfg = LPASS_CDC_WSA_RX1_RX_PATH_CFG1;
  1454. softclip_path = LPASS_CDC_WSA_MACRO_SOFTCLIP1;
  1455. }
  1456. switch (event) {
  1457. case SND_SOC_DAPM_PRE_PMU:
  1458. /* Enable clock for VBAT block */
  1459. snd_soc_component_update_bits(component,
  1460. LPASS_CDC_WSA_VBAT_BCL_VBAT_PATH_CTL, 0x10, 0x10);
  1461. /* Enable VBAT block */
  1462. snd_soc_component_update_bits(component,
  1463. LPASS_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x01, 0x01);
  1464. /* Update interpolator with 384K path */
  1465. snd_soc_component_update_bits(component, vbat_path_cfg,
  1466. 0x80, 0x80);
  1467. /* Use attenuation mode */
  1468. snd_soc_component_update_bits(component,
  1469. LPASS_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x02, 0x00);
  1470. /*
  1471. * BCL block needs softclip clock and mux config to be enabled
  1472. */
  1473. lpass_cdc_wsa_macro_enable_softclip_clk(component, wsa_priv,
  1474. softclip_path, true);
  1475. /* Enable VBAT at channel level */
  1476. snd_soc_component_update_bits(component, vbat_path_cfg,
  1477. 0x02, 0x02);
  1478. /* Set the ATTK1 gain */
  1479. snd_soc_component_update_bits(component,
  1480. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD1,
  1481. 0xFF, 0xFF);
  1482. snd_soc_component_update_bits(component,
  1483. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD2,
  1484. 0xFF, 0x03);
  1485. snd_soc_component_update_bits(component,
  1486. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD3,
  1487. 0xFF, 0x00);
  1488. /* Set the ATTK2 gain */
  1489. snd_soc_component_update_bits(component,
  1490. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD4,
  1491. 0xFF, 0xFF);
  1492. snd_soc_component_update_bits(component,
  1493. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD5,
  1494. 0xFF, 0x03);
  1495. snd_soc_component_update_bits(component,
  1496. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD6,
  1497. 0xFF, 0x00);
  1498. /* Set the ATTK3 gain */
  1499. snd_soc_component_update_bits(component,
  1500. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD7,
  1501. 0xFF, 0xFF);
  1502. snd_soc_component_update_bits(component,
  1503. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD8,
  1504. 0xFF, 0x03);
  1505. snd_soc_component_update_bits(component,
  1506. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD9,
  1507. 0xFF, 0x00);
  1508. /* Enable CB decode block clock */
  1509. snd_soc_component_update_bits(component,
  1510. LPASS_CDC_WSA_CB_DECODE_CB_DECODE_CTL1, 0x01, 0x01);
  1511. /* Enable BCL path */
  1512. snd_soc_component_update_bits(component,
  1513. LPASS_CDC_WSA_CB_DECODE_CB_DECODE_CTL3, 0x01, 0x01);
  1514. /* Request for BCL data */
  1515. snd_soc_component_update_bits(component,
  1516. LPASS_CDC_WSA_CB_DECODE_CB_DECODE_CTL3, 0x01, 0x01);
  1517. break;
  1518. case SND_SOC_DAPM_POST_PMD:
  1519. snd_soc_component_update_bits(component,
  1520. LPASS_CDC_WSA_CB_DECODE_CB_DECODE_CTL3, 0x01, 0x00);
  1521. snd_soc_component_update_bits(component,
  1522. LPASS_CDC_WSA_CB_DECODE_CB_DECODE_CTL2, 0x01, 0x00);
  1523. snd_soc_component_update_bits(component,
  1524. LPASS_CDC_WSA_CB_DECODE_CB_DECODE_CTL1, 0x01, 0x00);
  1525. snd_soc_component_update_bits(component, vbat_path_cfg,
  1526. 0x80, 0x00);
  1527. snd_soc_component_update_bits(component,
  1528. LPASS_CDC_WSA_VBAT_BCL_VBAT_CFG,
  1529. 0x02, 0x02);
  1530. snd_soc_component_update_bits(component, vbat_path_cfg,
  1531. 0x02, 0x00);
  1532. snd_soc_component_update_bits(component,
  1533. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD1,
  1534. 0xFF, 0x00);
  1535. snd_soc_component_update_bits(component,
  1536. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD2,
  1537. 0xFF, 0x00);
  1538. snd_soc_component_update_bits(component,
  1539. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD3,
  1540. 0xFF, 0x00);
  1541. snd_soc_component_update_bits(component,
  1542. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD4,
  1543. 0xFF, 0x00);
  1544. snd_soc_component_update_bits(component,
  1545. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD5,
  1546. 0xFF, 0x00);
  1547. snd_soc_component_update_bits(component,
  1548. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD6,
  1549. 0xFF, 0x00);
  1550. snd_soc_component_update_bits(component,
  1551. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD7,
  1552. 0xFF, 0x00);
  1553. snd_soc_component_update_bits(component,
  1554. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD8,
  1555. 0xFF, 0x00);
  1556. snd_soc_component_update_bits(component,
  1557. LPASS_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD9,
  1558. 0xFF, 0x00);
  1559. lpass_cdc_wsa_macro_enable_softclip_clk(component, wsa_priv,
  1560. softclip_path, false);
  1561. snd_soc_component_update_bits(component,
  1562. LPASS_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x01, 0x00);
  1563. snd_soc_component_update_bits(component,
  1564. LPASS_CDC_WSA_VBAT_BCL_VBAT_PATH_CTL, 0x10, 0x00);
  1565. break;
  1566. default:
  1567. dev_err(wsa_dev, "%s: Invalid event %d\n", __func__, event);
  1568. break;
  1569. }
  1570. return 0;
  1571. }
  1572. static int lpass_cdc_wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
  1573. struct snd_kcontrol *kcontrol,
  1574. int event)
  1575. {
  1576. struct snd_soc_component *component =
  1577. snd_soc_dapm_to_component(w->dapm);
  1578. struct device *wsa_dev = NULL;
  1579. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1580. u16 val, ec_tx = 0, ec_hq_reg;
  1581. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1582. return -EINVAL;
  1583. dev_dbg(wsa_dev, "%s %d %s\n", __func__, event, w->name);
  1584. val = snd_soc_component_read(component,
  1585. LPASS_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
  1586. if (!(strcmp(w->name, "WSA RX_MIX EC0_MUX")))
  1587. ec_tx = (val & 0x07) - 1;
  1588. else
  1589. ec_tx = ((val & 0x38) >> 0x3) - 1;
  1590. if (ec_tx < 0 || ec_tx >= (LPASS_CDC_WSA_MACRO_RX1 + 1)) {
  1591. dev_err(wsa_dev, "%s: EC mix control not set correctly\n",
  1592. __func__);
  1593. return -EINVAL;
  1594. }
  1595. if (wsa_priv->ec_hq[ec_tx]) {
  1596. snd_soc_component_update_bits(component,
  1597. LPASS_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
  1598. 0x1 << ec_tx, 0x1 << ec_tx);
  1599. ec_hq_reg = LPASS_CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL +
  1600. 0x40 * ec_tx;
  1601. snd_soc_component_update_bits(component, ec_hq_reg, 0x01, 0x01);
  1602. ec_hq_reg = LPASS_CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0 +
  1603. 0x40 * ec_tx;
  1604. /* default set to 48k */
  1605. snd_soc_component_update_bits(component, ec_hq_reg, 0x1E, 0x08);
  1606. }
  1607. return 0;
  1608. }
  1609. static int lpass_cdc_wsa_macro_get_ec_hq(struct snd_kcontrol *kcontrol,
  1610. struct snd_ctl_elem_value *ucontrol)
  1611. {
  1612. struct snd_soc_component *component =
  1613. snd_soc_kcontrol_component(kcontrol);
  1614. int ec_tx = ((struct soc_multi_mixer_control *)
  1615. kcontrol->private_value)->shift;
  1616. struct device *wsa_dev = NULL;
  1617. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1618. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1619. return -EINVAL;
  1620. ucontrol->value.integer.value[0] = wsa_priv->ec_hq[ec_tx];
  1621. return 0;
  1622. }
  1623. static int lpass_cdc_wsa_macro_set_ec_hq(struct snd_kcontrol *kcontrol,
  1624. struct snd_ctl_elem_value *ucontrol)
  1625. {
  1626. struct snd_soc_component *component =
  1627. snd_soc_kcontrol_component(kcontrol);
  1628. int ec_tx = ((struct soc_multi_mixer_control *)
  1629. kcontrol->private_value)->shift;
  1630. int value = ucontrol->value.integer.value[0];
  1631. struct device *wsa_dev = NULL;
  1632. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1633. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1634. return -EINVAL;
  1635. dev_dbg(wsa_dev, "%s: enable current %d, new %d\n",
  1636. __func__, wsa_priv->ec_hq[ec_tx], value);
  1637. wsa_priv->ec_hq[ec_tx] = value;
  1638. return 0;
  1639. }
  1640. static int lpass_cdc_wsa_macro_get_rx_mute_status(struct snd_kcontrol *kcontrol,
  1641. struct snd_ctl_elem_value *ucontrol)
  1642. {
  1643. struct snd_soc_component *component =
  1644. snd_soc_kcontrol_component(kcontrol);
  1645. struct device *wsa_dev = NULL;
  1646. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1647. int wsa_rx_shift = ((struct soc_multi_mixer_control *)
  1648. kcontrol->private_value)->shift;
  1649. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1650. return -EINVAL;
  1651. ucontrol->value.integer.value[0] =
  1652. wsa_priv->wsa_digital_mute_status[wsa_rx_shift];
  1653. return 0;
  1654. }
  1655. static int lpass_cdc_wsa_macro_set_rx_mute_status(struct snd_kcontrol *kcontrol,
  1656. struct snd_ctl_elem_value *ucontrol)
  1657. {
  1658. struct snd_soc_component *component =
  1659. snd_soc_kcontrol_component(kcontrol);
  1660. struct device *wsa_dev = NULL;
  1661. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1662. int value = ucontrol->value.integer.value[0];
  1663. int wsa_rx_shift = ((struct soc_multi_mixer_control *)
  1664. kcontrol->private_value)->shift;
  1665. int ret = 0;
  1666. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1667. return -EINVAL;
  1668. pm_runtime_get_sync(wsa_priv->dev);
  1669. switch (wsa_rx_shift) {
  1670. case 0:
  1671. snd_soc_component_update_bits(component,
  1672. LPASS_CDC_WSA_RX0_RX_PATH_CTL,
  1673. 0x10, value << 4);
  1674. break;
  1675. case 1:
  1676. snd_soc_component_update_bits(component,
  1677. LPASS_CDC_WSA_RX1_RX_PATH_CTL,
  1678. 0x10, value << 4);
  1679. break;
  1680. case 2:
  1681. snd_soc_component_update_bits(component,
  1682. LPASS_CDC_WSA_RX0_RX_PATH_MIX_CTL,
  1683. 0x10, value << 4);
  1684. break;
  1685. case 3:
  1686. snd_soc_component_update_bits(component,
  1687. LPASS_CDC_WSA_RX1_RX_PATH_MIX_CTL,
  1688. 0x10, value << 4);
  1689. break;
  1690. default:
  1691. pr_err("%s: invalid argument rx_shift = %d\n", __func__,
  1692. wsa_rx_shift);
  1693. ret = -EINVAL;
  1694. }
  1695. pm_runtime_mark_last_busy(wsa_priv->dev);
  1696. pm_runtime_put_autosuspend(wsa_priv->dev);
  1697. dev_dbg(component->dev, "%s: WSA Digital Mute RX %d Enable %d\n",
  1698. __func__, wsa_rx_shift, value);
  1699. wsa_priv->wsa_digital_mute_status[wsa_rx_shift] = value;
  1700. return ret;
  1701. }
  1702. static int lpass_cdc_wsa_macro_get_compander(struct snd_kcontrol *kcontrol,
  1703. struct snd_ctl_elem_value *ucontrol)
  1704. {
  1705. struct snd_soc_component *component =
  1706. snd_soc_kcontrol_component(kcontrol);
  1707. int comp = ((struct soc_multi_mixer_control *)
  1708. kcontrol->private_value)->shift;
  1709. struct device *wsa_dev = NULL;
  1710. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1711. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1712. return -EINVAL;
  1713. ucontrol->value.integer.value[0] = wsa_priv->comp_enabled[comp];
  1714. return 0;
  1715. }
  1716. static int lpass_cdc_wsa_macro_set_compander(struct snd_kcontrol *kcontrol,
  1717. struct snd_ctl_elem_value *ucontrol)
  1718. {
  1719. struct snd_soc_component *component =
  1720. snd_soc_kcontrol_component(kcontrol);
  1721. int comp = ((struct soc_multi_mixer_control *)
  1722. kcontrol->private_value)->shift;
  1723. int value = ucontrol->value.integer.value[0];
  1724. struct device *wsa_dev = NULL;
  1725. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1726. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1727. return -EINVAL;
  1728. dev_dbg(component->dev, "%s: Compander %d enable current %d, new %d\n",
  1729. __func__, comp + 1, wsa_priv->comp_enabled[comp], value);
  1730. wsa_priv->comp_enabled[comp] = value;
  1731. return 0;
  1732. }
  1733. static int lpass_cdc_wsa_macro_comp_mode_get(struct snd_kcontrol *kcontrol,
  1734. struct snd_ctl_elem_value *ucontrol)
  1735. {
  1736. struct snd_soc_component *component =
  1737. snd_soc_kcontrol_component(kcontrol);
  1738. struct device *wsa_dev = NULL;
  1739. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1740. u16 idx = 0;
  1741. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1742. return -EINVAL;
  1743. if (strnstr(kcontrol->id.name, "RX0", sizeof("WSA_RX0")))
  1744. idx = LPASS_CDC_WSA_MACRO_COMP1;
  1745. if (strnstr(kcontrol->id.name, "RX1", sizeof("WSA_RX1")))
  1746. idx = LPASS_CDC_WSA_MACRO_COMP2;
  1747. ucontrol->value.integer.value[0] = wsa_priv->comp_mode[idx];
  1748. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1749. __func__, ucontrol->value.integer.value[0]);
  1750. return 0;
  1751. }
  1752. static int lpass_cdc_wsa_macro_comp_mode_put(struct snd_kcontrol *kcontrol,
  1753. struct snd_ctl_elem_value *ucontrol)
  1754. {
  1755. struct snd_soc_component *component =
  1756. snd_soc_kcontrol_component(kcontrol);
  1757. struct device *wsa_dev = NULL;
  1758. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1759. u16 idx = 0;
  1760. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1761. return -EINVAL;
  1762. if (strnstr(kcontrol->id.name, "RX0", sizeof("WSA_RX0")))
  1763. idx = LPASS_CDC_WSA_MACRO_COMP1;
  1764. if (strnstr(kcontrol->id.name, "RX1", sizeof("WSA_RX1")))
  1765. idx = LPASS_CDC_WSA_MACRO_COMP2;
  1766. wsa_priv->comp_mode[idx] = ucontrol->value.integer.value[0];
  1767. dev_dbg(component->dev, "%s: comp_mode = %d\n", __func__,
  1768. wsa_priv->comp_mode[idx]);
  1769. return 0;
  1770. }
  1771. static int lpass_cdc_wsa_macro_rx_mux_get(struct snd_kcontrol *kcontrol,
  1772. struct snd_ctl_elem_value *ucontrol)
  1773. {
  1774. struct snd_soc_dapm_widget *widget =
  1775. snd_soc_dapm_kcontrol_widget(kcontrol);
  1776. struct snd_soc_component *component =
  1777. snd_soc_dapm_to_component(widget->dapm);
  1778. struct device *wsa_dev = NULL;
  1779. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1780. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1781. return -EINVAL;
  1782. ucontrol->value.integer.value[0] =
  1783. wsa_priv->rx_port_value[widget->shift];
  1784. return 0;
  1785. }
  1786. static int lpass_cdc_wsa_macro_rx_mux_put(struct snd_kcontrol *kcontrol,
  1787. struct snd_ctl_elem_value *ucontrol)
  1788. {
  1789. struct snd_soc_dapm_widget *widget =
  1790. snd_soc_dapm_kcontrol_widget(kcontrol);
  1791. struct snd_soc_component *component =
  1792. snd_soc_dapm_to_component(widget->dapm);
  1793. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1794. struct snd_soc_dapm_update *update = NULL;
  1795. u32 rx_port_value = ucontrol->value.integer.value[0];
  1796. u32 bit_input = 0;
  1797. u32 aif_rst;
  1798. struct device *wsa_dev = NULL;
  1799. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1800. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1801. return -EINVAL;
  1802. aif_rst = wsa_priv->rx_port_value[widget->shift];
  1803. if (!rx_port_value) {
  1804. if (aif_rst == 0) {
  1805. dev_err(wsa_dev, "%s: AIF reset already\n", __func__);
  1806. return 0;
  1807. }
  1808. if (aif_rst >= LPASS_CDC_WSA_MACRO_RX_MAX) {
  1809. dev_err(wsa_dev, "%s: Invalid AIF reset\n", __func__);
  1810. return 0;
  1811. }
  1812. }
  1813. wsa_priv->rx_port_value[widget->shift] = rx_port_value;
  1814. bit_input = widget->shift;
  1815. dev_dbg(wsa_dev,
  1816. "%s: mux input: %d, mux output: %d, bit: %d\n",
  1817. __func__, rx_port_value, widget->shift, bit_input);
  1818. switch (rx_port_value) {
  1819. case 0:
  1820. if (wsa_priv->active_ch_cnt[aif_rst]) {
  1821. clear_bit(bit_input,
  1822. &wsa_priv->active_ch_mask[aif_rst]);
  1823. wsa_priv->active_ch_cnt[aif_rst]--;
  1824. }
  1825. break;
  1826. case 1:
  1827. case 2:
  1828. set_bit(bit_input,
  1829. &wsa_priv->active_ch_mask[rx_port_value]);
  1830. wsa_priv->active_ch_cnt[rx_port_value]++;
  1831. break;
  1832. default:
  1833. dev_err(wsa_dev,
  1834. "%s: Invalid AIF_ID for WSA RX MUX %d\n",
  1835. __func__, rx_port_value);
  1836. return -EINVAL;
  1837. }
  1838. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1839. rx_port_value, e, update);
  1840. return 0;
  1841. }
  1842. static int lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
  1843. struct snd_ctl_elem_value *ucontrol)
  1844. {
  1845. struct snd_soc_component *component =
  1846. snd_soc_kcontrol_component(kcontrol);
  1847. ucontrol->value.integer.value[0] =
  1848. ((snd_soc_component_read(
  1849. component, LPASS_CDC_WSA_VBAT_BCL_VBAT_CFG) & 0x04) ?
  1850. 1 : 0);
  1851. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1852. ucontrol->value.integer.value[0]);
  1853. return 0;
  1854. }
  1855. static int lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
  1856. struct snd_ctl_elem_value *ucontrol)
  1857. {
  1858. struct snd_soc_component *component =
  1859. snd_soc_kcontrol_component(kcontrol);
  1860. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1861. ucontrol->value.integer.value[0]);
  1862. /* Set Vbat register configuration for GSM mode bit based on value */
  1863. if (ucontrol->value.integer.value[0])
  1864. snd_soc_component_update_bits(component,
  1865. LPASS_CDC_WSA_VBAT_BCL_VBAT_CFG,
  1866. 0x04, 0x04);
  1867. else
  1868. snd_soc_component_update_bits(component,
  1869. LPASS_CDC_WSA_VBAT_BCL_VBAT_CFG,
  1870. 0x04, 0x00);
  1871. return 0;
  1872. }
  1873. static int lpass_cdc_wsa_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
  1874. struct snd_ctl_elem_value *ucontrol)
  1875. {
  1876. struct snd_soc_component *component =
  1877. snd_soc_kcontrol_component(kcontrol);
  1878. struct device *wsa_dev = NULL;
  1879. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1880. int path = ((struct soc_multi_mixer_control *)
  1881. kcontrol->private_value)->shift;
  1882. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1883. return -EINVAL;
  1884. ucontrol->value.integer.value[0] = wsa_priv->is_softclip_on[path];
  1885. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1886. __func__, ucontrol->value.integer.value[0]);
  1887. return 0;
  1888. }
  1889. static int lpass_cdc_wsa_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
  1890. struct snd_ctl_elem_value *ucontrol)
  1891. {
  1892. struct snd_soc_component *component =
  1893. snd_soc_kcontrol_component(kcontrol);
  1894. struct device *wsa_dev = NULL;
  1895. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1896. int path = ((struct soc_multi_mixer_control *)
  1897. kcontrol->private_value)->shift;
  1898. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1899. return -EINVAL;
  1900. wsa_priv->is_softclip_on[path] = ucontrol->value.integer.value[0];
  1901. dev_dbg(component->dev, "%s: soft clip enable for %d: %d\n", __func__,
  1902. path, wsa_priv->is_softclip_on[path]);
  1903. return 0;
  1904. }
  1905. static const struct snd_kcontrol_new lpass_cdc_wsa_macro_snd_controls[] = {
  1906. SOC_ENUM_EXT("GSM mode Enable", lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_enum,
  1907. lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_func_get,
  1908. lpass_cdc_wsa_macro_vbat_bcl_gsm_mode_func_put),
  1909. SOC_ENUM_EXT("WSA_RX0 comp_mode", lpass_cdc_wsa_macro_comp_mode_enum,
  1910. lpass_cdc_wsa_macro_comp_mode_get,
  1911. lpass_cdc_wsa_macro_comp_mode_put),
  1912. SOC_ENUM_EXT("WSA_RX1 comp_mode", lpass_cdc_wsa_macro_comp_mode_enum,
  1913. lpass_cdc_wsa_macro_comp_mode_get,
  1914. lpass_cdc_wsa_macro_comp_mode_put),
  1915. SOC_SINGLE_EXT("WSA_Softclip0 Enable", SND_SOC_NOPM,
  1916. LPASS_CDC_WSA_MACRO_SOFTCLIP0, 1, 0,
  1917. lpass_cdc_wsa_macro_soft_clip_enable_get,
  1918. lpass_cdc_wsa_macro_soft_clip_enable_put),
  1919. SOC_SINGLE_EXT("WSA_Softclip1 Enable", SND_SOC_NOPM,
  1920. LPASS_CDC_WSA_MACRO_SOFTCLIP1, 1, 0,
  1921. lpass_cdc_wsa_macro_soft_clip_enable_get,
  1922. lpass_cdc_wsa_macro_soft_clip_enable_put),
  1923. SOC_SINGLE_S8_TLV("WSA_RX0 Digital Volume",
  1924. LPASS_CDC_WSA_RX0_RX_VOL_CTL,
  1925. -84, 40, digital_gain),
  1926. SOC_SINGLE_S8_TLV("WSA_RX1 Digital Volume",
  1927. LPASS_CDC_WSA_RX1_RX_VOL_CTL,
  1928. -84, 40, digital_gain),
  1929. SOC_SINGLE_EXT("WSA_RX0 Digital Mute", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX0, 1,
  1930. 0, lpass_cdc_wsa_macro_get_rx_mute_status,
  1931. lpass_cdc_wsa_macro_set_rx_mute_status),
  1932. SOC_SINGLE_EXT("WSA_RX1 Digital Mute", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX1, 1,
  1933. 0, lpass_cdc_wsa_macro_get_rx_mute_status,
  1934. lpass_cdc_wsa_macro_set_rx_mute_status),
  1935. SOC_SINGLE_EXT("WSA_RX0_MIX Digital Mute", SND_SOC_NOPM,
  1936. LPASS_CDC_WSA_MACRO_RX_MIX0, 1, 0, lpass_cdc_wsa_macro_get_rx_mute_status,
  1937. lpass_cdc_wsa_macro_set_rx_mute_status),
  1938. SOC_SINGLE_EXT("WSA_RX1_MIX Digital Mute", SND_SOC_NOPM,
  1939. LPASS_CDC_WSA_MACRO_RX_MIX1, 1, 0, lpass_cdc_wsa_macro_get_rx_mute_status,
  1940. lpass_cdc_wsa_macro_set_rx_mute_status),
  1941. SOC_SINGLE_EXT("WSA_COMP1 Switch", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_COMP1, 1, 0,
  1942. lpass_cdc_wsa_macro_get_compander, lpass_cdc_wsa_macro_set_compander),
  1943. SOC_SINGLE_EXT("WSA_COMP2 Switch", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_COMP2, 1, 0,
  1944. lpass_cdc_wsa_macro_get_compander, lpass_cdc_wsa_macro_set_compander),
  1945. SOC_SINGLE_EXT("WSA_RX0 EC_HQ Switch", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX0,
  1946. 1, 0, lpass_cdc_wsa_macro_get_ec_hq, lpass_cdc_wsa_macro_set_ec_hq),
  1947. SOC_SINGLE_EXT("WSA_RX1 EC_HQ Switch", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX1,
  1948. 1, 0, lpass_cdc_wsa_macro_get_ec_hq, lpass_cdc_wsa_macro_set_ec_hq),
  1949. };
  1950. static const struct soc_enum rx_mux_enum =
  1951. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_mux_text), rx_mux_text);
  1952. static const struct snd_kcontrol_new rx_mux[LPASS_CDC_WSA_MACRO_RX_MAX] = {
  1953. SOC_DAPM_ENUM_EXT("WSA RX0 Mux", rx_mux_enum,
  1954. lpass_cdc_wsa_macro_rx_mux_get, lpass_cdc_wsa_macro_rx_mux_put),
  1955. SOC_DAPM_ENUM_EXT("WSA RX1 Mux", rx_mux_enum,
  1956. lpass_cdc_wsa_macro_rx_mux_get, lpass_cdc_wsa_macro_rx_mux_put),
  1957. SOC_DAPM_ENUM_EXT("WSA RX_MIX0 Mux", rx_mux_enum,
  1958. lpass_cdc_wsa_macro_rx_mux_get, lpass_cdc_wsa_macro_rx_mux_put),
  1959. SOC_DAPM_ENUM_EXT("WSA RX_MIX1 Mux", rx_mux_enum,
  1960. lpass_cdc_wsa_macro_rx_mux_get, lpass_cdc_wsa_macro_rx_mux_put),
  1961. SOC_DAPM_ENUM_EXT("WSA RX4 Mux", rx_mux_enum,
  1962. lpass_cdc_wsa_macro_rx_mux_get, lpass_cdc_wsa_macro_rx_mux_put),
  1963. SOC_DAPM_ENUM_EXT("WSA RX5 Mux", rx_mux_enum,
  1964. lpass_cdc_wsa_macro_rx_mux_get, lpass_cdc_wsa_macro_rx_mux_put),
  1965. };
  1966. static int lpass_cdc_wsa_macro_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
  1967. struct snd_ctl_elem_value *ucontrol)
  1968. {
  1969. struct snd_soc_dapm_widget *widget =
  1970. snd_soc_dapm_kcontrol_widget(kcontrol);
  1971. struct snd_soc_component *component =
  1972. snd_soc_dapm_to_component(widget->dapm);
  1973. struct soc_multi_mixer_control *mixer =
  1974. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1975. u32 dai_id = widget->shift;
  1976. u32 spk_tx_id = mixer->shift;
  1977. struct device *wsa_dev = NULL;
  1978. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  1979. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1980. return -EINVAL;
  1981. if (test_bit(spk_tx_id, &wsa_priv->active_ch_mask[dai_id]))
  1982. ucontrol->value.integer.value[0] = 1;
  1983. else
  1984. ucontrol->value.integer.value[0] = 0;
  1985. return 0;
  1986. }
  1987. static int lpass_cdc_wsa_macro_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
  1988. struct snd_ctl_elem_value *ucontrol)
  1989. {
  1990. struct snd_soc_dapm_widget *widget =
  1991. snd_soc_dapm_kcontrol_widget(kcontrol);
  1992. struct snd_soc_component *component =
  1993. snd_soc_dapm_to_component(widget->dapm);
  1994. struct soc_multi_mixer_control *mixer =
  1995. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1996. u32 spk_tx_id = mixer->shift;
  1997. u32 enable = ucontrol->value.integer.value[0];
  1998. struct device *wsa_dev = NULL;
  1999. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  2000. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2001. return -EINVAL;
  2002. wsa_priv->vi_feed_value = ucontrol->value.integer.value[0];
  2003. if (enable) {
  2004. if (spk_tx_id == LPASS_CDC_WSA_MACRO_TX0 &&
  2005. !test_bit(LPASS_CDC_WSA_MACRO_TX0,
  2006. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  2007. set_bit(LPASS_CDC_WSA_MACRO_TX0,
  2008. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI]);
  2009. wsa_priv->active_ch_cnt[LPASS_CDC_WSA_MACRO_AIF_VI]++;
  2010. }
  2011. if (spk_tx_id == LPASS_CDC_WSA_MACRO_TX1 &&
  2012. !test_bit(LPASS_CDC_WSA_MACRO_TX1,
  2013. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  2014. set_bit(LPASS_CDC_WSA_MACRO_TX1,
  2015. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI]);
  2016. wsa_priv->active_ch_cnt[LPASS_CDC_WSA_MACRO_AIF_VI]++;
  2017. }
  2018. } else {
  2019. if (spk_tx_id == LPASS_CDC_WSA_MACRO_TX0 &&
  2020. test_bit(LPASS_CDC_WSA_MACRO_TX0,
  2021. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  2022. clear_bit(LPASS_CDC_WSA_MACRO_TX0,
  2023. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI]);
  2024. wsa_priv->active_ch_cnt[LPASS_CDC_WSA_MACRO_AIF_VI]--;
  2025. }
  2026. if (spk_tx_id == LPASS_CDC_WSA_MACRO_TX1 &&
  2027. test_bit(LPASS_CDC_WSA_MACRO_TX1,
  2028. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI])) {
  2029. clear_bit(LPASS_CDC_WSA_MACRO_TX1,
  2030. &wsa_priv->active_ch_mask[LPASS_CDC_WSA_MACRO_AIF_VI]);
  2031. wsa_priv->active_ch_cnt[LPASS_CDC_WSA_MACRO_AIF_VI]--;
  2032. }
  2033. }
  2034. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
  2035. return 0;
  2036. }
  2037. static const struct snd_kcontrol_new aif_vi_mixer[] = {
  2038. SOC_SINGLE_EXT("WSA_SPKR_VI_1", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_TX0, 1, 0,
  2039. lpass_cdc_wsa_macro_vi_feed_mixer_get,
  2040. lpass_cdc_wsa_macro_vi_feed_mixer_put),
  2041. SOC_SINGLE_EXT("WSA_SPKR_VI_2", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_TX1, 1, 0,
  2042. lpass_cdc_wsa_macro_vi_feed_mixer_get,
  2043. lpass_cdc_wsa_macro_vi_feed_mixer_put),
  2044. };
  2045. static const struct snd_soc_dapm_widget lpass_cdc_wsa_macro_dapm_widgets[] = {
  2046. SND_SOC_DAPM_AIF_IN("WSA AIF1 PB", "WSA_AIF1 Playback", 0,
  2047. SND_SOC_NOPM, 0, 0),
  2048. SND_SOC_DAPM_AIF_IN("WSA AIF_MIX1 PB", "WSA_AIF_MIX1 Playback", 0,
  2049. SND_SOC_NOPM, 0, 0),
  2050. SND_SOC_DAPM_AIF_OUT_E("WSA AIF_VI", "WSA_AIF_VI Capture", 0,
  2051. SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_AIF_VI, 0,
  2052. lpass_cdc_wsa_macro_enable_vi_feedback,
  2053. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2054. SND_SOC_DAPM_AIF_OUT("WSA AIF_ECHO", "WSA_AIF_ECHO Capture", 0,
  2055. SND_SOC_NOPM, 0, 0),
  2056. SND_SOC_DAPM_MIXER("WSA_AIF_VI Mixer", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_AIF_VI,
  2057. 0, aif_vi_mixer, ARRAY_SIZE(aif_vi_mixer)),
  2058. SND_SOC_DAPM_MUX_E("WSA RX_MIX EC0_MUX", SND_SOC_NOPM,
  2059. LPASS_CDC_WSA_MACRO_EC0_MUX, 0,
  2060. &rx_mix_ec0_mux, lpass_cdc_wsa_macro_enable_echo,
  2061. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2062. SND_SOC_DAPM_MUX_E("WSA RX_MIX EC1_MUX", SND_SOC_NOPM,
  2063. LPASS_CDC_WSA_MACRO_EC1_MUX, 0,
  2064. &rx_mix_ec1_mux, lpass_cdc_wsa_macro_enable_echo,
  2065. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2066. SND_SOC_DAPM_MUX("WSA RX0 MUX", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX0, 0,
  2067. &rx_mux[LPASS_CDC_WSA_MACRO_RX0]),
  2068. SND_SOC_DAPM_MUX("WSA RX1 MUX", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX1, 0,
  2069. &rx_mux[LPASS_CDC_WSA_MACRO_RX1]),
  2070. SND_SOC_DAPM_MUX("WSA RX_MIX0 MUX", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX_MIX0, 0,
  2071. &rx_mux[LPASS_CDC_WSA_MACRO_RX_MIX0]),
  2072. SND_SOC_DAPM_MUX("WSA RX_MIX1 MUX", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX_MIX1, 0,
  2073. &rx_mux[LPASS_CDC_WSA_MACRO_RX_MIX1]),
  2074. SND_SOC_DAPM_MUX("WSA RX4 MUX", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX4, 0,
  2075. &rx_mux[LPASS_CDC_WSA_MACRO_RX4]),
  2076. SND_SOC_DAPM_MUX("WSA RX5 MUX", SND_SOC_NOPM, LPASS_CDC_WSA_MACRO_RX5, 0,
  2077. &rx_mux[LPASS_CDC_WSA_MACRO_RX5]),
  2078. SND_SOC_DAPM_MIXER("WSA RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2079. SND_SOC_DAPM_MIXER("WSA RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2080. SND_SOC_DAPM_MIXER("WSA RX_MIX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2081. SND_SOC_DAPM_MIXER("WSA RX_MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2082. SND_SOC_DAPM_MIXER("WSA RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  2083. SND_SOC_DAPM_MIXER("WSA RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  2084. SND_SOC_DAPM_MUX_E("WSA_RX0 INP0", SND_SOC_NOPM, 0, 0,
  2085. &rx0_prim_inp0_mux, lpass_cdc_wsa_macro_enable_swr,
  2086. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2087. SND_SOC_DAPM_MUX_E("WSA_RX0 INP1", SND_SOC_NOPM, 0, 0,
  2088. &rx0_prim_inp1_mux, lpass_cdc_wsa_macro_enable_swr,
  2089. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2090. SND_SOC_DAPM_MUX_E("WSA_RX0 INP2", SND_SOC_NOPM, 0, 0,
  2091. &rx0_prim_inp2_mux, lpass_cdc_wsa_macro_enable_swr,
  2092. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2093. SND_SOC_DAPM_MUX_E("WSA_RX0 MIX INP", SND_SOC_NOPM,
  2094. 0, 0, &rx0_mix_mux, lpass_cdc_wsa_macro_enable_mix_path,
  2095. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2096. SND_SOC_DAPM_MUX_E("WSA_RX1 INP0", SND_SOC_NOPM, 0, 0,
  2097. &rx1_prim_inp0_mux, lpass_cdc_wsa_macro_enable_swr,
  2098. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2099. SND_SOC_DAPM_MUX_E("WSA_RX1 INP1", SND_SOC_NOPM, 0, 0,
  2100. &rx1_prim_inp1_mux, lpass_cdc_wsa_macro_enable_swr,
  2101. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2102. SND_SOC_DAPM_MUX_E("WSA_RX1 INP2", SND_SOC_NOPM, 0, 0,
  2103. &rx1_prim_inp2_mux, lpass_cdc_wsa_macro_enable_swr,
  2104. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2105. SND_SOC_DAPM_MUX_E("WSA_RX1 MIX INP", SND_SOC_NOPM,
  2106. 0, 0, &rx1_mix_mux, lpass_cdc_wsa_macro_enable_mix_path,
  2107. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2108. SND_SOC_DAPM_PGA_E("WSA_RX INT0 MIX", SND_SOC_NOPM,
  2109. 0, 0, NULL, 0, lpass_cdc_wsa_macro_enable_main_path,
  2110. SND_SOC_DAPM_PRE_PMU),
  2111. SND_SOC_DAPM_PGA_E("WSA_RX INT1 MIX", SND_SOC_NOPM,
  2112. 1, 0, NULL, 0, lpass_cdc_wsa_macro_enable_main_path,
  2113. SND_SOC_DAPM_PRE_PMU),
  2114. SND_SOC_DAPM_MIXER("WSA_RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2115. SND_SOC_DAPM_MIXER("WSA_RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2116. SND_SOC_DAPM_MUX_E("WSA_RX0 INT0 SIDETONE MIX",
  2117. LPASS_CDC_WSA_RX0_RX_PATH_CFG1, 4, 0,
  2118. &rx0_sidetone_mix_mux, lpass_cdc_wsa_macro_enable_swr,
  2119. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2120. SND_SOC_DAPM_INPUT("WSA SRC0_INP"),
  2121. SND_SOC_DAPM_INPUT("WSA_TX DEC0_INP"),
  2122. SND_SOC_DAPM_INPUT("WSA_TX DEC1_INP"),
  2123. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 INTERP", SND_SOC_NOPM,
  2124. LPASS_CDC_WSA_MACRO_COMP1, 0, NULL, 0, lpass_cdc_wsa_macro_enable_interpolator,
  2125. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2126. SND_SOC_DAPM_POST_PMD),
  2127. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 INTERP", SND_SOC_NOPM,
  2128. LPASS_CDC_WSA_MACRO_COMP2, 0, NULL, 0, lpass_cdc_wsa_macro_enable_interpolator,
  2129. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2130. SND_SOC_DAPM_POST_PMD),
  2131. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 CHAIN", SND_SOC_NOPM, 0, 0,
  2132. NULL, 0, lpass_cdc_wsa_macro_spk_boost_event,
  2133. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2134. SND_SOC_DAPM_POST_PMD),
  2135. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 CHAIN", SND_SOC_NOPM, 0, 0,
  2136. NULL, 0, lpass_cdc_wsa_macro_spk_boost_event,
  2137. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2138. SND_SOC_DAPM_POST_PMD),
  2139. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 VBAT", SND_SOC_NOPM,
  2140. 0, 0, wsa_int0_vbat_mix_switch,
  2141. ARRAY_SIZE(wsa_int0_vbat_mix_switch),
  2142. lpass_cdc_wsa_macro_enable_vbat,
  2143. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2144. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 VBAT", SND_SOC_NOPM,
  2145. 0, 0, wsa_int1_vbat_mix_switch,
  2146. ARRAY_SIZE(wsa_int1_vbat_mix_switch),
  2147. lpass_cdc_wsa_macro_enable_vbat,
  2148. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2149. SND_SOC_DAPM_INPUT("VIINPUT_WSA"),
  2150. SND_SOC_DAPM_OUTPUT("WSA_SPK1 OUT"),
  2151. SND_SOC_DAPM_OUTPUT("WSA_SPK2 OUT"),
  2152. SND_SOC_DAPM_SUPPLY_S("WSA_MCLK", 0, SND_SOC_NOPM, 0, 0,
  2153. lpass_cdc_wsa_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2154. };
  2155. static const struct snd_soc_dapm_route wsa_audio_map[] = {
  2156. /* VI Feedback */
  2157. {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_1", "VIINPUT_WSA"},
  2158. {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_2", "VIINPUT_WSA"},
  2159. {"WSA AIF_VI", NULL, "WSA_AIF_VI Mixer"},
  2160. {"WSA AIF_VI", NULL, "WSA_MCLK"},
  2161. {"WSA RX_MIX EC0_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
  2162. {"WSA RX_MIX EC1_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
  2163. {"WSA RX_MIX EC0_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
  2164. {"WSA RX_MIX EC1_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
  2165. {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC0_MUX"},
  2166. {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC1_MUX"},
  2167. {"WSA AIF_ECHO", NULL, "WSA_MCLK"},
  2168. {"WSA AIF1 PB", NULL, "WSA_MCLK"},
  2169. {"WSA AIF_MIX1 PB", NULL, "WSA_MCLK"},
  2170. {"WSA RX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2171. {"WSA RX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2172. {"WSA RX_MIX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2173. {"WSA RX_MIX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2174. {"WSA RX4 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2175. {"WSA RX5 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2176. {"WSA RX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2177. {"WSA RX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2178. {"WSA RX_MIX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2179. {"WSA RX_MIX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2180. {"WSA RX4 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2181. {"WSA RX5 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2182. {"WSA RX0", NULL, "WSA RX0 MUX"},
  2183. {"WSA RX1", NULL, "WSA RX1 MUX"},
  2184. {"WSA RX_MIX0", NULL, "WSA RX_MIX0 MUX"},
  2185. {"WSA RX_MIX1", NULL, "WSA RX_MIX1 MUX"},
  2186. {"WSA RX4", NULL, "WSA RX4 MUX"},
  2187. {"WSA RX5", NULL, "WSA RX5 MUX"},
  2188. {"WSA_RX0 INP0", "RX0", "WSA RX0"},
  2189. {"WSA_RX0 INP0", "RX1", "WSA RX1"},
  2190. {"WSA_RX0 INP0", "RX_MIX0", "WSA RX_MIX0"},
  2191. {"WSA_RX0 INP0", "RX_MIX1", "WSA RX_MIX1"},
  2192. {"WSA_RX0 INP0", "RX4", "WSA RX4"},
  2193. {"WSA_RX0 INP0", "RX5", "WSA RX5"},
  2194. {"WSA_RX0 INP0", "DEC0", "WSA_TX DEC0_INP"},
  2195. {"WSA_RX0 INP0", "DEC1", "WSA_TX DEC1_INP"},
  2196. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP0"},
  2197. {"WSA_RX0 INP1", "RX0", "WSA RX0"},
  2198. {"WSA_RX0 INP1", "RX1", "WSA RX1"},
  2199. {"WSA_RX0 INP1", "RX_MIX0", "WSA RX_MIX0"},
  2200. {"WSA_RX0 INP1", "RX_MIX1", "WSA RX_MIX1"},
  2201. {"WSA_RX0 INP1", "RX4", "WSA RX4"},
  2202. {"WSA_RX0 INP1", "RX5", "WSA RX5"},
  2203. {"WSA_RX0 INP1", "DEC0", "WSA_TX DEC0_INP"},
  2204. {"WSA_RX0 INP1", "DEC1", "WSA_TX DEC1_INP"},
  2205. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP1"},
  2206. {"WSA_RX0 INP2", "RX0", "WSA RX0"},
  2207. {"WSA_RX0 INP2", "RX1", "WSA RX1"},
  2208. {"WSA_RX0 INP2", "RX_MIX0", "WSA RX_MIX0"},
  2209. {"WSA_RX0 INP2", "RX_MIX1", "WSA RX_MIX1"},
  2210. {"WSA_RX0 INP2", "RX4", "WSA RX4"},
  2211. {"WSA_RX0 INP2", "RX5", "WSA RX5"},
  2212. {"WSA_RX0 INP2", "DEC0", "WSA_TX DEC0_INP"},
  2213. {"WSA_RX0 INP2", "DEC1", "WSA_TX DEC1_INP"},
  2214. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP2"},
  2215. {"WSA_RX0 MIX INP", "RX0", "WSA RX0"},
  2216. {"WSA_RX0 MIX INP", "RX1", "WSA RX1"},
  2217. {"WSA_RX0 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
  2218. {"WSA_RX0 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
  2219. {"WSA_RX0 MIX INP", "RX4", "WSA RX4"},
  2220. {"WSA_RX0 MIX INP", "RX5", "WSA RX5"},
  2221. {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX0 MIX INP"},
  2222. {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX INT0 MIX"},
  2223. {"WSA_RX INT0 INTERP", NULL, "WSA_RX INT0 SEC MIX"},
  2224. {"WSA_RX0 INT0 SIDETONE MIX", "SRC0", "WSA SRC0_INP"},
  2225. {"WSA_RX INT0 INTERP", NULL, "WSA_RX0 INT0 SIDETONE MIX"},
  2226. {"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 INTERP"},
  2227. {"WSA_RX INT0 VBAT", "WSA RX0 VBAT Enable", "WSA_RX INT0 INTERP"},
  2228. {"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 VBAT"},
  2229. {"WSA_SPK1 OUT", NULL, "WSA_RX INT0 CHAIN"},
  2230. {"WSA_SPK1 OUT", NULL, "WSA_MCLK"},
  2231. {"WSA_RX1 INP0", "RX0", "WSA RX0"},
  2232. {"WSA_RX1 INP0", "RX1", "WSA RX1"},
  2233. {"WSA_RX1 INP0", "RX_MIX0", "WSA RX_MIX0"},
  2234. {"WSA_RX1 INP0", "RX_MIX1", "WSA RX_MIX1"},
  2235. {"WSA_RX1 INP0", "RX4", "WSA RX4"},
  2236. {"WSA_RX1 INP0", "RX5", "WSA RX5"},
  2237. {"WSA_RX1 INP0", "DEC0", "WSA_TX DEC0_INP"},
  2238. {"WSA_RX1 INP0", "DEC1", "WSA_TX DEC1_INP"},
  2239. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP0"},
  2240. {"WSA_RX1 INP1", "RX0", "WSA RX0"},
  2241. {"WSA_RX1 INP1", "RX1", "WSA RX1"},
  2242. {"WSA_RX1 INP1", "RX_MIX0", "WSA RX_MIX0"},
  2243. {"WSA_RX1 INP1", "RX_MIX1", "WSA RX_MIX1"},
  2244. {"WSA_RX1 INP1", "RX4", "WSA RX4"},
  2245. {"WSA_RX1 INP1", "RX5", "WSA RX5"},
  2246. {"WSA_RX1 INP1", "DEC0", "WSA_TX DEC0_INP"},
  2247. {"WSA_RX1 INP1", "DEC1", "WSA_TX DEC1_INP"},
  2248. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP1"},
  2249. {"WSA_RX1 INP2", "RX0", "WSA RX0"},
  2250. {"WSA_RX1 INP2", "RX1", "WSA RX1"},
  2251. {"WSA_RX1 INP2", "RX_MIX0", "WSA RX_MIX0"},
  2252. {"WSA_RX1 INP2", "RX_MIX1", "WSA RX_MIX1"},
  2253. {"WSA_RX1 INP2", "RX4", "WSA RX4"},
  2254. {"WSA_RX1 INP2", "RX5", "WSA RX5"},
  2255. {"WSA_RX1 INP2", "DEC0", "WSA_TX DEC0_INP"},
  2256. {"WSA_RX1 INP2", "DEC1", "WSA_TX DEC1_INP"},
  2257. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP2"},
  2258. {"WSA_RX1 MIX INP", "RX0", "WSA RX0"},
  2259. {"WSA_RX1 MIX INP", "RX1", "WSA RX1"},
  2260. {"WSA_RX1 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
  2261. {"WSA_RX1 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
  2262. {"WSA_RX1 MIX INP", "RX4", "WSA RX4"},
  2263. {"WSA_RX1 MIX INP", "RX5", "WSA RX5"},
  2264. {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX1 MIX INP"},
  2265. {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX INT1 MIX"},
  2266. {"WSA_RX INT1 INTERP", NULL, "WSA_RX INT1 SEC MIX"},
  2267. {"WSA_RX INT1 VBAT", "WSA RX1 VBAT Enable", "WSA_RX INT1 INTERP"},
  2268. {"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 VBAT"},
  2269. {"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 INTERP"},
  2270. {"WSA_SPK2 OUT", NULL, "WSA_RX INT1 CHAIN"},
  2271. {"WSA_SPK2 OUT", NULL, "WSA_MCLK"},
  2272. };
  2273. static const struct lpass_cdc_wsa_macro_reg_mask_val
  2274. lpass_cdc_wsa_macro_reg_init[] = {
  2275. {LPASS_CDC_WSA_BOOST0_BOOST_CFG1, 0x3F, 0x12},
  2276. {LPASS_CDC_WSA_BOOST0_BOOST_CFG2, 0x1C, 0x08},
  2277. {LPASS_CDC_WSA_COMPANDER0_CTL7, 0x1E, 0x0C},
  2278. {LPASS_CDC_WSA_BOOST1_BOOST_CFG1, 0x3F, 0x12},
  2279. {LPASS_CDC_WSA_BOOST1_BOOST_CFG2, 0x1C, 0x08},
  2280. {LPASS_CDC_WSA_COMPANDER1_CTL7, 0x1E, 0x0C},
  2281. {LPASS_CDC_WSA_BOOST0_BOOST_CTL, 0x70, 0x58},
  2282. {LPASS_CDC_WSA_BOOST1_BOOST_CTL, 0x70, 0x58},
  2283. {LPASS_CDC_WSA_RX0_RX_PATH_CFG1, 0x08, 0x08},
  2284. {LPASS_CDC_WSA_RX1_RX_PATH_CFG1, 0x08, 0x08},
  2285. {LPASS_CDC_WSA_TOP_TOP_CFG1, 0x02, 0x02},
  2286. {LPASS_CDC_WSA_TOP_TOP_CFG1, 0x01, 0x01},
  2287. {LPASS_CDC_WSA_TX0_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2288. {LPASS_CDC_WSA_TX1_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2289. {LPASS_CDC_WSA_TX2_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2290. {LPASS_CDC_WSA_TX3_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2291. {LPASS_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01},
  2292. {LPASS_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x01},
  2293. {LPASS_CDC_WSA_RX0_RX_PATH_CFG0, 0x01, 0x01},
  2294. {LPASS_CDC_WSA_RX1_RX_PATH_CFG0, 0x01, 0x01},
  2295. {LPASS_CDC_WSA_RX0_RX_PATH_MIX_CFG, 0x01, 0x01},
  2296. {LPASS_CDC_WSA_RX1_RX_PATH_MIX_CFG, 0x01, 0x01},
  2297. };
  2298. static void lpass_cdc_wsa_macro_init_reg(struct snd_soc_component *component)
  2299. {
  2300. int i;
  2301. for (i = 0; i < ARRAY_SIZE(lpass_cdc_wsa_macro_reg_init); i++)
  2302. snd_soc_component_update_bits(component,
  2303. lpass_cdc_wsa_macro_reg_init[i].reg,
  2304. lpass_cdc_wsa_macro_reg_init[i].mask,
  2305. lpass_cdc_wsa_macro_reg_init[i].val);
  2306. }
  2307. static int lpass_cdc_wsa_macro_core_vote(void *handle, bool enable)
  2308. {
  2309. int rc = 0;
  2310. struct lpass_cdc_wsa_macro_priv *wsa_priv = (struct lpass_cdc_wsa_macro_priv *) handle;
  2311. if (wsa_priv == NULL) {
  2312. pr_err("%s: wsa priv data is NULL\n", __func__);
  2313. return -EINVAL;
  2314. }
  2315. if (enable) {
  2316. pm_runtime_get_sync(wsa_priv->dev);
  2317. if (lpass_cdc_check_core_votes(wsa_priv->dev))
  2318. rc = 0;
  2319. else
  2320. rc = -ENOTSYNC;
  2321. } else {
  2322. pm_runtime_put_autosuspend(wsa_priv->dev);
  2323. pm_runtime_mark_last_busy(wsa_priv->dev);
  2324. }
  2325. return rc;
  2326. }
  2327. static int wsa_swrm_clock(void *handle, bool enable)
  2328. {
  2329. struct lpass_cdc_wsa_macro_priv *wsa_priv = (struct lpass_cdc_wsa_macro_priv *) handle;
  2330. struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
  2331. int ret = 0;
  2332. if (regmap == NULL) {
  2333. dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
  2334. return -EINVAL;
  2335. }
  2336. mutex_lock(&wsa_priv->swr_clk_lock);
  2337. trace_printk("%s: %s swrm clock %s\n",
  2338. dev_name(wsa_priv->dev), __func__,
  2339. (enable ? "enable" : "disable"));
  2340. dev_dbg(wsa_priv->dev, "%s: swrm clock %s\n",
  2341. __func__, (enable ? "enable" : "disable"));
  2342. if (enable) {
  2343. pm_runtime_get_sync(wsa_priv->dev);
  2344. if (wsa_priv->swr_clk_users == 0) {
  2345. ret = msm_cdc_pinctrl_select_active_state(
  2346. wsa_priv->wsa_swr_gpio_p);
  2347. if (ret < 0) {
  2348. dev_err_ratelimited(wsa_priv->dev,
  2349. "%s: wsa swr pinctrl enable failed\n",
  2350. __func__);
  2351. pm_runtime_mark_last_busy(wsa_priv->dev);
  2352. pm_runtime_put_autosuspend(wsa_priv->dev);
  2353. goto exit;
  2354. }
  2355. ret = lpass_cdc_wsa_macro_mclk_enable(wsa_priv, 1, true);
  2356. if (ret < 0) {
  2357. msm_cdc_pinctrl_select_sleep_state(
  2358. wsa_priv->wsa_swr_gpio_p);
  2359. dev_err_ratelimited(wsa_priv->dev,
  2360. "%s: wsa request clock enable failed\n",
  2361. __func__);
  2362. pm_runtime_mark_last_busy(wsa_priv->dev);
  2363. pm_runtime_put_autosuspend(wsa_priv->dev);
  2364. goto exit;
  2365. }
  2366. if (wsa_priv->reset_swr)
  2367. regmap_update_bits(regmap,
  2368. LPASS_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2369. 0x02, 0x02);
  2370. regmap_update_bits(regmap,
  2371. LPASS_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2372. 0x01, 0x01);
  2373. if (wsa_priv->reset_swr)
  2374. regmap_update_bits(regmap,
  2375. LPASS_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2376. 0x02, 0x00);
  2377. regmap_update_bits(regmap,
  2378. LPASS_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2379. 0x1C, 0x0C);
  2380. wsa_priv->reset_swr = false;
  2381. }
  2382. wsa_priv->swr_clk_users++;
  2383. pm_runtime_mark_last_busy(wsa_priv->dev);
  2384. pm_runtime_put_autosuspend(wsa_priv->dev);
  2385. } else {
  2386. if (wsa_priv->swr_clk_users <= 0) {
  2387. dev_err(wsa_priv->dev, "%s: clock already disabled\n",
  2388. __func__);
  2389. wsa_priv->swr_clk_users = 0;
  2390. goto exit;
  2391. }
  2392. wsa_priv->swr_clk_users--;
  2393. if (wsa_priv->swr_clk_users == 0) {
  2394. regmap_update_bits(regmap,
  2395. LPASS_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2396. 0x01, 0x00);
  2397. lpass_cdc_wsa_macro_mclk_enable(wsa_priv, 0, true);
  2398. ret = msm_cdc_pinctrl_select_sleep_state(
  2399. wsa_priv->wsa_swr_gpio_p);
  2400. if (ret < 0) {
  2401. dev_err_ratelimited(wsa_priv->dev,
  2402. "%s: wsa swr pinctrl disable failed\n",
  2403. __func__);
  2404. goto exit;
  2405. }
  2406. }
  2407. }
  2408. trace_printk("%s: %s swrm clock users: %d\n",
  2409. dev_name(wsa_priv->dev), __func__,
  2410. wsa_priv->swr_clk_users);
  2411. dev_dbg(wsa_priv->dev, "%s: swrm clock users %d\n",
  2412. __func__, wsa_priv->swr_clk_users);
  2413. exit:
  2414. mutex_unlock(&wsa_priv->swr_clk_lock);
  2415. return ret;
  2416. }
  2417. /* Thermal Functions */
  2418. static int lpass_cdc_wsa_macro_get_max_state(
  2419. struct thermal_cooling_device *cdev,
  2420. unsigned long *state)
  2421. {
  2422. struct lpass_cdc_wsa_macro_priv *wsa_priv = cdev->devdata;
  2423. if (!wsa_priv) {
  2424. pr_err("%s: cdev->devdata is NULL\n", __func__);
  2425. return -EINVAL;
  2426. }
  2427. *state = wsa_priv->thermal_max_state;
  2428. return 0;
  2429. }
  2430. static int lpass_cdc_wsa_macro_get_cur_state(
  2431. struct thermal_cooling_device *cdev,
  2432. unsigned long *state)
  2433. {
  2434. struct lpass_cdc_wsa_macro_priv *wsa_priv = cdev->devdata;
  2435. if (!wsa_priv) {
  2436. pr_err("%s: cdev->devdata is NULL\n", __func__);
  2437. return -EINVAL;
  2438. }
  2439. *state = wsa_priv->thermal_cur_state;
  2440. pr_debug("%s: thermal current state:%lu\n", __func__, *state);
  2441. return 0;
  2442. }
  2443. static int lpass_cdc_wsa_macro_set_cur_state(
  2444. struct thermal_cooling_device *cdev,
  2445. unsigned long state)
  2446. {
  2447. struct lpass_cdc_wsa_macro_priv *wsa_priv = cdev->devdata;
  2448. u8 gain = 0;
  2449. if (!wsa_priv) {
  2450. pr_err("%s: cdev->devdata is NULL\n", __func__);
  2451. return -EINVAL;
  2452. }
  2453. if (state < wsa_priv->thermal_max_state)
  2454. wsa_priv->thermal_cur_state = state;
  2455. else
  2456. wsa_priv->thermal_cur_state = wsa_priv->thermal_max_state;
  2457. gain = (u8)(gain - wsa_priv->thermal_cur_state);
  2458. dev_dbg(wsa_priv->dev,
  2459. "%s: requested state:%d, actual state: %d, gain: %#x\n",
  2460. __func__, state, wsa_priv->thermal_cur_state, gain);
  2461. snd_soc_component_update_bits(wsa_priv->component,
  2462. LPASS_CDC_WSA_RX0_RX_VOL_CTL, 0xFF, gain);
  2463. snd_soc_component_update_bits(wsa_priv->component,
  2464. LPASS_CDC_WSA_RX1_RX_VOL_CTL, 0xFF, gain);
  2465. return 0;
  2466. }
  2467. static struct thermal_cooling_device_ops wsa_cooling_ops = {
  2468. .get_max_state = lpass_cdc_wsa_macro_get_max_state,
  2469. .get_cur_state = lpass_cdc_wsa_macro_get_cur_state,
  2470. .set_cur_state = lpass_cdc_wsa_macro_set_cur_state,
  2471. };
  2472. static int lpass_cdc_wsa_macro_init(struct snd_soc_component *component)
  2473. {
  2474. struct snd_soc_dapm_context *dapm =
  2475. snd_soc_component_get_dapm(component);
  2476. int ret;
  2477. struct device *wsa_dev = NULL;
  2478. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  2479. wsa_dev = lpass_cdc_get_device_ptr(component->dev, WSA_MACRO);
  2480. if (!wsa_dev) {
  2481. dev_err(component->dev,
  2482. "%s: null device for macro!\n", __func__);
  2483. return -EINVAL;
  2484. }
  2485. wsa_priv = dev_get_drvdata(wsa_dev);
  2486. if (!wsa_priv) {
  2487. dev_err(component->dev,
  2488. "%s: priv is null for macro!\n", __func__);
  2489. return -EINVAL;
  2490. }
  2491. ret = snd_soc_dapm_new_controls(dapm, lpass_cdc_wsa_macro_dapm_widgets,
  2492. ARRAY_SIZE(lpass_cdc_wsa_macro_dapm_widgets));
  2493. if (ret < 0) {
  2494. dev_err(wsa_dev, "%s: Failed to add controls\n", __func__);
  2495. return ret;
  2496. }
  2497. ret = snd_soc_dapm_add_routes(dapm, wsa_audio_map,
  2498. ARRAY_SIZE(wsa_audio_map));
  2499. if (ret < 0) {
  2500. dev_err(wsa_dev, "%s: Failed to add routes\n", __func__);
  2501. return ret;
  2502. }
  2503. ret = snd_soc_dapm_new_widgets(dapm->card);
  2504. if (ret < 0) {
  2505. dev_err(wsa_dev, "%s: Failed to add widgets\n", __func__);
  2506. return ret;
  2507. }
  2508. ret = snd_soc_add_component_controls(component, lpass_cdc_wsa_macro_snd_controls,
  2509. ARRAY_SIZE(lpass_cdc_wsa_macro_snd_controls));
  2510. if (ret < 0) {
  2511. dev_err(wsa_dev, "%s: Failed to add snd_ctls\n", __func__);
  2512. return ret;
  2513. }
  2514. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF1 Playback");
  2515. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_MIX1 Playback");
  2516. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_VI Capture");
  2517. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_ECHO Capture");
  2518. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
  2519. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
  2520. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
  2521. snd_soc_dapm_ignore_suspend(dapm, "WSA SRC0_INP");
  2522. snd_soc_dapm_ignore_suspend(dapm, "WSA_TX DEC0_INP");
  2523. snd_soc_dapm_ignore_suspend(dapm, "WSA_TX DEC1_INP");
  2524. snd_soc_dapm_sync(dapm);
  2525. wsa_priv->component = component;
  2526. wsa_priv->spkr_gain_offset = LPASS_CDC_WSA_MACRO_GAIN_OFFSET_0_DB;
  2527. lpass_cdc_wsa_macro_init_reg(component);
  2528. return 0;
  2529. }
  2530. static int lpass_cdc_wsa_macro_deinit(struct snd_soc_component *component)
  2531. {
  2532. struct device *wsa_dev = NULL;
  2533. struct lpass_cdc_wsa_macro_priv *wsa_priv = NULL;
  2534. if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2535. return -EINVAL;
  2536. wsa_priv->component = NULL;
  2537. return 0;
  2538. }
  2539. static void lpass_cdc_wsa_macro_add_child_devices(struct work_struct *work)
  2540. {
  2541. struct lpass_cdc_wsa_macro_priv *wsa_priv;
  2542. struct platform_device *pdev;
  2543. struct device_node *node;
  2544. struct lpass_cdc_wsa_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp;
  2545. int ret;
  2546. u16 count = 0, ctrl_num = 0;
  2547. struct lpass_cdc_wsa_macro_swr_ctrl_platform_data *platdata;
  2548. char plat_dev_name[LPASS_CDC_WSA_MACRO_SWR_STRING_LEN];
  2549. wsa_priv = container_of(work, struct lpass_cdc_wsa_macro_priv,
  2550. lpass_cdc_wsa_macro_add_child_devices_work);
  2551. if (!wsa_priv) {
  2552. pr_err("%s: Memory for wsa_priv does not exist\n",
  2553. __func__);
  2554. return;
  2555. }
  2556. if (!wsa_priv->dev || !wsa_priv->dev->of_node) {
  2557. dev_err(wsa_priv->dev,
  2558. "%s: DT node for wsa_priv does not exist\n", __func__);
  2559. return;
  2560. }
  2561. platdata = &wsa_priv->swr_plat_data;
  2562. wsa_priv->child_count = 0;
  2563. for_each_available_child_of_node(wsa_priv->dev->of_node, node) {
  2564. if (strnstr(node->name, "wsa_swr_master",
  2565. strlen("wsa_swr_master")) != NULL)
  2566. strlcpy(plat_dev_name, "wsa_swr_ctrl",
  2567. (LPASS_CDC_WSA_MACRO_SWR_STRING_LEN - 1));
  2568. else if (strnstr(node->name, "msm_cdc_pinctrl",
  2569. strlen("msm_cdc_pinctrl")) != NULL)
  2570. strlcpy(plat_dev_name, node->name,
  2571. (LPASS_CDC_WSA_MACRO_SWR_STRING_LEN - 1));
  2572. else
  2573. continue;
  2574. pdev = platform_device_alloc(plat_dev_name, -1);
  2575. if (!pdev) {
  2576. dev_err(wsa_priv->dev, "%s: pdev memory alloc failed\n",
  2577. __func__);
  2578. ret = -ENOMEM;
  2579. goto err;
  2580. }
  2581. pdev->dev.parent = wsa_priv->dev;
  2582. pdev->dev.of_node = node;
  2583. if (strnstr(node->name, "wsa_swr_master",
  2584. strlen("wsa_swr_master")) != NULL) {
  2585. ret = platform_device_add_data(pdev, platdata,
  2586. sizeof(*platdata));
  2587. if (ret) {
  2588. dev_err(&pdev->dev,
  2589. "%s: cannot add plat data ctrl:%d\n",
  2590. __func__, ctrl_num);
  2591. goto fail_pdev_add;
  2592. }
  2593. }
  2594. ret = platform_device_add(pdev);
  2595. if (ret) {
  2596. dev_err(&pdev->dev,
  2597. "%s: Cannot add platform device\n",
  2598. __func__);
  2599. goto fail_pdev_add;
  2600. }
  2601. if (!strcmp(node->name, "wsa_swr_master")) {
  2602. temp = krealloc(swr_ctrl_data,
  2603. (ctrl_num + 1) * sizeof(
  2604. struct lpass_cdc_wsa_macro_swr_ctrl_data),
  2605. GFP_KERNEL);
  2606. if (!temp) {
  2607. dev_err(&pdev->dev, "out of memory\n");
  2608. ret = -ENOMEM;
  2609. goto err;
  2610. }
  2611. swr_ctrl_data = temp;
  2612. swr_ctrl_data[ctrl_num].wsa_swr_pdev = pdev;
  2613. ctrl_num++;
  2614. dev_dbg(&pdev->dev,
  2615. "%s: Added soundwire ctrl device(s)\n",
  2616. __func__);
  2617. wsa_priv->swr_ctrl_data = swr_ctrl_data;
  2618. }
  2619. if (wsa_priv->child_count < LPASS_CDC_WSA_MACRO_CHILD_DEVICES_MAX)
  2620. wsa_priv->pdev_child_devices[
  2621. wsa_priv->child_count++] = pdev;
  2622. else
  2623. goto err;
  2624. }
  2625. return;
  2626. fail_pdev_add:
  2627. for (count = 0; count < wsa_priv->child_count; count++)
  2628. platform_device_put(wsa_priv->pdev_child_devices[count]);
  2629. err:
  2630. return;
  2631. }
  2632. static void lpass_cdc_wsa_macro_init_ops(struct macro_ops *ops,
  2633. char __iomem *wsa_io_base)
  2634. {
  2635. memset(ops, 0, sizeof(struct macro_ops));
  2636. ops->init = lpass_cdc_wsa_macro_init;
  2637. ops->exit = lpass_cdc_wsa_macro_deinit;
  2638. ops->io_base = wsa_io_base;
  2639. ops->dai_ptr = lpass_cdc_wsa_macro_dai;
  2640. ops->num_dais = ARRAY_SIZE(lpass_cdc_wsa_macro_dai);
  2641. ops->event_handler = lpass_cdc_wsa_macro_event_handler;
  2642. ops->set_port_map = lpass_cdc_wsa_macro_set_port_map;
  2643. }
  2644. static int lpass_cdc_wsa_macro_probe(struct platform_device *pdev)
  2645. {
  2646. struct macro_ops ops;
  2647. struct lpass_cdc_wsa_macro_priv *wsa_priv;
  2648. u32 wsa_base_addr, default_clk_id, thermal_max_state;
  2649. char __iomem *wsa_io_base;
  2650. int ret = 0;
  2651. u32 is_used_wsa_swr_gpio = 1;
  2652. const char *is_used_wsa_swr_gpio_dt = "qcom,is-used-swr-gpio";
  2653. if (!lpass_cdc_is_va_macro_registered(&pdev->dev)) {
  2654. dev_err(&pdev->dev,
  2655. "%s: va-macro not registered yet, defer\n", __func__);
  2656. return -EPROBE_DEFER;
  2657. }
  2658. wsa_priv = devm_kzalloc(&pdev->dev, sizeof(struct lpass_cdc_wsa_macro_priv),
  2659. GFP_KERNEL);
  2660. if (!wsa_priv)
  2661. return -ENOMEM;
  2662. wsa_priv->dev = &pdev->dev;
  2663. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2664. &wsa_base_addr);
  2665. if (ret) {
  2666. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2667. __func__, "reg");
  2668. return ret;
  2669. }
  2670. if (of_find_property(pdev->dev.of_node, is_used_wsa_swr_gpio_dt,
  2671. NULL)) {
  2672. ret = of_property_read_u32(pdev->dev.of_node,
  2673. is_used_wsa_swr_gpio_dt,
  2674. &is_used_wsa_swr_gpio);
  2675. if (ret) {
  2676. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  2677. __func__, is_used_wsa_swr_gpio_dt);
  2678. is_used_wsa_swr_gpio = 1;
  2679. }
  2680. }
  2681. wsa_priv->wsa_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2682. "qcom,wsa-swr-gpios", 0);
  2683. if (!wsa_priv->wsa_swr_gpio_p && is_used_wsa_swr_gpio) {
  2684. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2685. __func__);
  2686. return -EINVAL;
  2687. }
  2688. if (msm_cdc_pinctrl_get_state(wsa_priv->wsa_swr_gpio_p) < 0 &&
  2689. is_used_wsa_swr_gpio) {
  2690. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  2691. __func__);
  2692. return -EPROBE_DEFER;
  2693. }
  2694. msm_cdc_pinctrl_set_wakeup_capable(
  2695. wsa_priv->wsa_swr_gpio_p, false);
  2696. wsa_io_base = devm_ioremap(&pdev->dev,
  2697. wsa_base_addr, LPASS_CDC_WSA_MACRO_MAX_OFFSET);
  2698. if (!wsa_io_base) {
  2699. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2700. return -EINVAL;
  2701. }
  2702. wsa_priv->wsa_io_base = wsa_io_base;
  2703. wsa_priv->reset_swr = true;
  2704. INIT_WORK(&wsa_priv->lpass_cdc_wsa_macro_add_child_devices_work,
  2705. lpass_cdc_wsa_macro_add_child_devices);
  2706. wsa_priv->swr_plat_data.handle = (void *) wsa_priv;
  2707. wsa_priv->swr_plat_data.read = NULL;
  2708. wsa_priv->swr_plat_data.write = NULL;
  2709. wsa_priv->swr_plat_data.bulk_write = NULL;
  2710. wsa_priv->swr_plat_data.clk = wsa_swrm_clock;
  2711. wsa_priv->swr_plat_data.core_vote = lpass_cdc_wsa_macro_core_vote;
  2712. wsa_priv->swr_plat_data.handle_irq = NULL;
  2713. ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
  2714. &default_clk_id);
  2715. if (ret) {
  2716. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2717. __func__, "qcom,mux0-clk-id");
  2718. default_clk_id = WSA_CORE_CLK;
  2719. }
  2720. wsa_priv->default_clk_id = default_clk_id;
  2721. dev_set_drvdata(&pdev->dev, wsa_priv);
  2722. mutex_init(&wsa_priv->mclk_lock);
  2723. mutex_init(&wsa_priv->swr_clk_lock);
  2724. lpass_cdc_wsa_macro_init_ops(&ops, wsa_io_base);
  2725. ops.clk_id_req = wsa_priv->default_clk_id;
  2726. ops.default_clk_id = wsa_priv->default_clk_id;
  2727. ret = lpass_cdc_register_macro(&pdev->dev, WSA_MACRO, &ops);
  2728. if (ret < 0) {
  2729. dev_err(&pdev->dev, "%s: register macro failed\n", __func__);
  2730. goto reg_macro_fail;
  2731. }
  2732. if (of_find_property(wsa_priv->dev->of_node, "#cooling-cells", NULL)) {
  2733. ret = of_property_read_u32(pdev->dev.of_node,
  2734. "qcom,thermal-max-state",
  2735. &thermal_max_state);
  2736. if (ret) {
  2737. dev_info(&pdev->dev, "%s: could not find %s entry in dt\n",
  2738. __func__, "qcom,thermal-max-state");
  2739. wsa_priv->thermal_max_state =
  2740. LPASS_CDC_WSA_MACRO_THERMAL_MAX_STATE;
  2741. } else {
  2742. wsa_priv->thermal_max_state = thermal_max_state;
  2743. }
  2744. wsa_priv->tcdev = devm_thermal_of_cooling_device_register(
  2745. &pdev->dev,
  2746. wsa_priv->dev->of_node,
  2747. "wsa", wsa_priv,
  2748. &wsa_cooling_ops);
  2749. if (IS_ERR(wsa_priv->tcdev)) {
  2750. dev_err(&pdev->dev,
  2751. "%s: failed to register wsa macro as cooling device\n",
  2752. __func__);
  2753. wsa_priv->tcdev = NULL;
  2754. }
  2755. }
  2756. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  2757. pm_runtime_use_autosuspend(&pdev->dev);
  2758. pm_runtime_set_suspended(&pdev->dev);
  2759. pm_suspend_ignore_children(&pdev->dev, true);
  2760. pm_runtime_enable(&pdev->dev);
  2761. schedule_work(&wsa_priv->lpass_cdc_wsa_macro_add_child_devices_work);
  2762. return ret;
  2763. reg_macro_fail:
  2764. mutex_destroy(&wsa_priv->mclk_lock);
  2765. mutex_destroy(&wsa_priv->swr_clk_lock);
  2766. return ret;
  2767. }
  2768. static int lpass_cdc_wsa_macro_remove(struct platform_device *pdev)
  2769. {
  2770. struct lpass_cdc_wsa_macro_priv *wsa_priv;
  2771. u16 count = 0;
  2772. wsa_priv = dev_get_drvdata(&pdev->dev);
  2773. if (!wsa_priv)
  2774. return -EINVAL;
  2775. if (wsa_priv->tcdev)
  2776. thermal_cooling_device_unregister(wsa_priv->tcdev);
  2777. for (count = 0; count < wsa_priv->child_count &&
  2778. count < LPASS_CDC_WSA_MACRO_CHILD_DEVICES_MAX; count++)
  2779. platform_device_unregister(wsa_priv->pdev_child_devices[count]);
  2780. pm_runtime_disable(&pdev->dev);
  2781. pm_runtime_set_suspended(&pdev->dev);
  2782. lpass_cdc_unregister_macro(&pdev->dev, WSA_MACRO);
  2783. mutex_destroy(&wsa_priv->mclk_lock);
  2784. mutex_destroy(&wsa_priv->swr_clk_lock);
  2785. return 0;
  2786. }
  2787. static const struct of_device_id lpass_cdc_wsa_macro_dt_match[] = {
  2788. {.compatible = "qcom,lpass-cdc-wsa-macro"},
  2789. {}
  2790. };
  2791. static const struct dev_pm_ops lpass_cdc_dev_pm_ops = {
  2792. SET_SYSTEM_SLEEP_PM_OPS(
  2793. pm_runtime_force_suspend,
  2794. pm_runtime_force_resume
  2795. )
  2796. SET_RUNTIME_PM_OPS(
  2797. lpass_cdc_runtime_suspend,
  2798. lpass_cdc_runtime_resume,
  2799. NULL
  2800. )
  2801. };
  2802. static struct platform_driver lpass_cdc_wsa_macro_driver = {
  2803. .driver = {
  2804. .name = "lpass_cdc_wsa_macro",
  2805. .owner = THIS_MODULE,
  2806. .pm = &lpass_cdc_dev_pm_ops,
  2807. .of_match_table = lpass_cdc_wsa_macro_dt_match,
  2808. .suppress_bind_attrs = true,
  2809. },
  2810. .probe = lpass_cdc_wsa_macro_probe,
  2811. .remove = lpass_cdc_wsa_macro_remove,
  2812. };
  2813. module_platform_driver(lpass_cdc_wsa_macro_driver);
  2814. MODULE_DESCRIPTION("WSA macro driver");
  2815. MODULE_LICENSE("GPL v2");