wsa-macro.c 97 KB

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