lpass-cdc-wsa-macro.c 96 KB

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