wsa-macro.c 99 KB

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