wsa-macro.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300
  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. if (mute)
  745. return 0;
  746. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  747. return -EINVAL;
  748. switch (dai->id) {
  749. case WSA_MACRO_AIF1_PB:
  750. case WSA_MACRO_AIF_MIX1_PB:
  751. for (j = 0; j < NUM_INTERPOLATORS; j++) {
  752. reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
  753. (j * WSA_MACRO_RX_PATH_OFFSET);
  754. mix_reg = BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL +
  755. (j * WSA_MACRO_RX_PATH_OFFSET);
  756. dsm_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
  757. (j * WSA_MACRO_RX_PATH_OFFSET) +
  758. WSA_MACRO_RX_PATH_DSMDEM_OFFSET;
  759. int_mux_cfg0 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0 + j * 8;
  760. int_mux_cfg1 = int_mux_cfg0 + 4;
  761. int_mux_cfg0_val = snd_soc_component_read32(component,
  762. int_mux_cfg0);
  763. int_mux_cfg1_val = snd_soc_component_read32(component,
  764. int_mux_cfg1);
  765. if (snd_soc_component_read32(component, dsm_reg) & 0x01) {
  766. if (int_mux_cfg0_val || (int_mux_cfg1_val & 0x38))
  767. snd_soc_component_update_bits(component, reg,
  768. 0x20, 0x20);
  769. if (int_mux_cfg1_val & 0x07) {
  770. snd_soc_component_update_bits(component, reg,
  771. 0x20, 0x20);
  772. snd_soc_component_update_bits(component,
  773. mix_reg, 0x20, 0x20);
  774. }
  775. }
  776. }
  777. bolero_wsa_pa_on(wsa_dev);
  778. break;
  779. default:
  780. break;
  781. }
  782. return 0;
  783. }
  784. static int wsa_macro_mclk_enable(struct wsa_macro_priv *wsa_priv,
  785. bool mclk_enable, bool dapm)
  786. {
  787. struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
  788. int ret = 0;
  789. if (regmap == NULL) {
  790. dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
  791. return -EINVAL;
  792. }
  793. dev_dbg(wsa_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  794. __func__, mclk_enable, dapm, wsa_priv->wsa_mclk_users);
  795. mutex_lock(&wsa_priv->mclk_lock);
  796. if (mclk_enable) {
  797. if (wsa_priv->wsa_mclk_users == 0) {
  798. ret = bolero_clk_rsc_request_clock(wsa_priv->dev,
  799. wsa_priv->default_clk_id,
  800. wsa_priv->default_clk_id,
  801. true);
  802. if (ret < 0) {
  803. dev_err_ratelimited(wsa_priv->dev,
  804. "%s: wsa request clock enable failed\n",
  805. __func__);
  806. goto exit;
  807. }
  808. bolero_clk_rsc_fs_gen_request(wsa_priv->dev,
  809. true);
  810. regcache_mark_dirty(regmap);
  811. regcache_sync_region(regmap,
  812. WSA_START_OFFSET,
  813. WSA_MAX_OFFSET);
  814. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  815. regmap_update_bits(regmap,
  816. BOLERO_CDC_WSA_TOP_FREQ_MCLK, 0x01, 0x01);
  817. regmap_update_bits(regmap,
  818. BOLERO_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
  819. 0x01, 0x01);
  820. regmap_update_bits(regmap,
  821. BOLERO_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
  822. 0x01, 0x01);
  823. }
  824. wsa_priv->wsa_mclk_users++;
  825. } else {
  826. if (wsa_priv->wsa_mclk_users <= 0) {
  827. dev_err(wsa_priv->dev, "%s: clock already disabled\n",
  828. __func__);
  829. wsa_priv->wsa_mclk_users = 0;
  830. goto exit;
  831. }
  832. wsa_priv->wsa_mclk_users--;
  833. if (wsa_priv->wsa_mclk_users == 0) {
  834. regmap_update_bits(regmap,
  835. BOLERO_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
  836. 0x01, 0x00);
  837. regmap_update_bits(regmap,
  838. BOLERO_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
  839. 0x01, 0x00);
  840. bolero_clk_rsc_fs_gen_request(wsa_priv->dev,
  841. false);
  842. bolero_clk_rsc_request_clock(wsa_priv->dev,
  843. wsa_priv->default_clk_id,
  844. wsa_priv->default_clk_id,
  845. false);
  846. }
  847. }
  848. exit:
  849. mutex_unlock(&wsa_priv->mclk_lock);
  850. return ret;
  851. }
  852. static int wsa_macro_mclk_event(struct snd_soc_dapm_widget *w,
  853. struct snd_kcontrol *kcontrol, int event)
  854. {
  855. struct snd_soc_component *component =
  856. snd_soc_dapm_to_component(w->dapm);
  857. int ret = 0;
  858. struct device *wsa_dev = NULL;
  859. struct wsa_macro_priv *wsa_priv = NULL;
  860. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  861. return -EINVAL;
  862. dev_dbg(wsa_dev, "%s: event = %d\n", __func__, event);
  863. switch (event) {
  864. case SND_SOC_DAPM_PRE_PMU:
  865. ret = wsa_macro_mclk_enable(wsa_priv, 1, true);
  866. if (ret)
  867. wsa_priv->dapm_mclk_enable = false;
  868. else
  869. wsa_priv->dapm_mclk_enable = true;
  870. break;
  871. case SND_SOC_DAPM_POST_PMD:
  872. if (wsa_priv->dapm_mclk_enable)
  873. wsa_macro_mclk_enable(wsa_priv, 0, true);
  874. break;
  875. default:
  876. dev_err(wsa_priv->dev,
  877. "%s: invalid DAPM event %d\n", __func__, event);
  878. ret = -EINVAL;
  879. }
  880. return ret;
  881. }
  882. static int wsa_macro_event_handler(struct snd_soc_component *component,
  883. u16 event, u32 data)
  884. {
  885. struct device *wsa_dev = NULL;
  886. struct wsa_macro_priv *wsa_priv = NULL;
  887. int ret = 0;
  888. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  889. return -EINVAL;
  890. switch (event) {
  891. case BOLERO_MACRO_EVT_SSR_DOWN:
  892. trace_printk("%s, enter SSR down\n", __func__);
  893. if (wsa_priv->swr_ctrl_data) {
  894. swrm_wcd_notify(
  895. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  896. SWR_DEVICE_SSR_DOWN, NULL);
  897. }
  898. if ((!pm_runtime_enabled(wsa_dev) ||
  899. !pm_runtime_suspended(wsa_dev))) {
  900. ret = bolero_runtime_suspend(wsa_dev);
  901. if (!ret) {
  902. pm_runtime_disable(wsa_dev);
  903. pm_runtime_set_suspended(wsa_dev);
  904. pm_runtime_enable(wsa_dev);
  905. }
  906. }
  907. break;
  908. case BOLERO_MACRO_EVT_PRE_SSR_UP:
  909. /* enable&disable WSA_CORE_CLK to reset GFMUX reg */
  910. ret = bolero_clk_rsc_request_clock(wsa_priv->dev,
  911. wsa_priv->default_clk_id,
  912. WSA_CORE_CLK, true);
  913. if (ret < 0)
  914. dev_err_ratelimited(wsa_priv->dev,
  915. "%s, failed to enable clk, ret:%d\n",
  916. __func__, ret);
  917. else
  918. bolero_clk_rsc_request_clock(wsa_priv->dev,
  919. wsa_priv->default_clk_id,
  920. WSA_CORE_CLK, false);
  921. break;
  922. case BOLERO_MACRO_EVT_SSR_UP:
  923. trace_printk("%s, enter SSR up\n", __func__);
  924. /* reset swr after ssr/pdr */
  925. wsa_priv->reset_swr = true;
  926. if (wsa_priv->swr_ctrl_data)
  927. swrm_wcd_notify(
  928. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  929. SWR_DEVICE_SSR_UP, NULL);
  930. break;
  931. case BOLERO_MACRO_EVT_CLK_RESET:
  932. bolero_rsc_clk_reset(wsa_dev, WSA_CORE_CLK);
  933. break;
  934. }
  935. return 0;
  936. }
  937. static int wsa_macro_enable_vi_feedback(struct snd_soc_dapm_widget *w,
  938. struct snd_kcontrol *kcontrol,
  939. int event)
  940. {
  941. struct snd_soc_component *component =
  942. snd_soc_dapm_to_component(w->dapm);
  943. struct device *wsa_dev = NULL;
  944. struct wsa_macro_priv *wsa_priv = NULL;
  945. u8 val = 0x0;
  946. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  947. return -EINVAL;
  948. switch (wsa_priv->pcm_rate_vi) {
  949. case 48000:
  950. val = 0x04;
  951. break;
  952. case 24000:
  953. val = 0x02;
  954. break;
  955. case 8000:
  956. default:
  957. val = 0x00;
  958. break;
  959. }
  960. switch (event) {
  961. case SND_SOC_DAPM_POST_PMU:
  962. if (test_bit(WSA_MACRO_TX0,
  963. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  964. dev_dbg(wsa_dev, "%s: spkr1 enabled\n", __func__);
  965. /* Enable V&I sensing */
  966. snd_soc_component_update_bits(component,
  967. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  968. 0x20, 0x20);
  969. snd_soc_component_update_bits(component,
  970. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  971. 0x20, 0x20);
  972. snd_soc_component_update_bits(component,
  973. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  974. 0x0F, val);
  975. snd_soc_component_update_bits(component,
  976. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  977. 0x0F, val);
  978. snd_soc_component_update_bits(component,
  979. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  980. 0x10, 0x10);
  981. snd_soc_component_update_bits(component,
  982. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  983. 0x10, 0x10);
  984. snd_soc_component_update_bits(component,
  985. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  986. 0x20, 0x00);
  987. snd_soc_component_update_bits(component,
  988. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  989. 0x20, 0x00);
  990. }
  991. if (test_bit(WSA_MACRO_TX1,
  992. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  993. dev_dbg(wsa_dev, "%s: spkr2 enabled\n", __func__);
  994. /* Enable V&I sensing */
  995. snd_soc_component_update_bits(component,
  996. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  997. 0x20, 0x20);
  998. snd_soc_component_update_bits(component,
  999. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  1000. 0x20, 0x20);
  1001. snd_soc_component_update_bits(component,
  1002. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  1003. 0x0F, val);
  1004. snd_soc_component_update_bits(component,
  1005. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  1006. 0x0F, val);
  1007. snd_soc_component_update_bits(component,
  1008. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  1009. 0x10, 0x10);
  1010. snd_soc_component_update_bits(component,
  1011. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  1012. 0x10, 0x10);
  1013. snd_soc_component_update_bits(component,
  1014. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  1015. 0x20, 0x00);
  1016. snd_soc_component_update_bits(component,
  1017. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  1018. 0x20, 0x00);
  1019. }
  1020. break;
  1021. case SND_SOC_DAPM_POST_PMD:
  1022. if (test_bit(WSA_MACRO_TX0,
  1023. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  1024. /* Disable V&I sensing */
  1025. snd_soc_component_update_bits(component,
  1026. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  1027. 0x20, 0x20);
  1028. snd_soc_component_update_bits(component,
  1029. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  1030. 0x20, 0x20);
  1031. dev_dbg(wsa_dev, "%s: spkr1 disabled\n", __func__);
  1032. snd_soc_component_update_bits(component,
  1033. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  1034. 0x10, 0x00);
  1035. snd_soc_component_update_bits(component,
  1036. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  1037. 0x10, 0x00);
  1038. }
  1039. if (test_bit(WSA_MACRO_TX1,
  1040. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  1041. /* Disable V&I sensing */
  1042. dev_dbg(wsa_dev, "%s: spkr2 disabled\n", __func__);
  1043. snd_soc_component_update_bits(component,
  1044. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  1045. 0x20, 0x20);
  1046. snd_soc_component_update_bits(component,
  1047. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  1048. 0x20, 0x20);
  1049. snd_soc_component_update_bits(component,
  1050. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  1051. 0x10, 0x00);
  1052. snd_soc_component_update_bits(component,
  1053. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  1054. 0x10, 0x00);
  1055. }
  1056. break;
  1057. }
  1058. return 0;
  1059. }
  1060. static void wsa_macro_hd2_control(struct snd_soc_component *component,
  1061. u16 reg, int event)
  1062. {
  1063. u16 hd2_scale_reg;
  1064. u16 hd2_enable_reg = 0;
  1065. if (reg == BOLERO_CDC_WSA_RX0_RX_PATH_CTL) {
  1066. hd2_scale_reg = BOLERO_CDC_WSA_RX0_RX_PATH_SEC3;
  1067. hd2_enable_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG0;
  1068. }
  1069. if (reg == BOLERO_CDC_WSA_RX1_RX_PATH_CTL) {
  1070. hd2_scale_reg = BOLERO_CDC_WSA_RX1_RX_PATH_SEC3;
  1071. hd2_enable_reg = BOLERO_CDC_WSA_RX1_RX_PATH_CFG0;
  1072. }
  1073. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1074. snd_soc_component_update_bits(component, hd2_scale_reg,
  1075. 0x3C, 0x10);
  1076. snd_soc_component_update_bits(component, hd2_scale_reg,
  1077. 0x03, 0x01);
  1078. snd_soc_component_update_bits(component, hd2_enable_reg,
  1079. 0x04, 0x04);
  1080. }
  1081. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1082. snd_soc_component_update_bits(component, hd2_enable_reg,
  1083. 0x04, 0x00);
  1084. snd_soc_component_update_bits(component, hd2_scale_reg,
  1085. 0x03, 0x00);
  1086. snd_soc_component_update_bits(component, hd2_scale_reg,
  1087. 0x3C, 0x00);
  1088. }
  1089. }
  1090. static int wsa_macro_enable_swr(struct snd_soc_dapm_widget *w,
  1091. struct snd_kcontrol *kcontrol, int event)
  1092. {
  1093. struct snd_soc_component *component =
  1094. snd_soc_dapm_to_component(w->dapm);
  1095. int ch_cnt;
  1096. struct device *wsa_dev = NULL;
  1097. struct wsa_macro_priv *wsa_priv = NULL;
  1098. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1099. return -EINVAL;
  1100. switch (event) {
  1101. case SND_SOC_DAPM_PRE_PMU:
  1102. if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
  1103. !wsa_priv->rx_0_count)
  1104. wsa_priv->rx_0_count++;
  1105. if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
  1106. !wsa_priv->rx_1_count)
  1107. wsa_priv->rx_1_count++;
  1108. ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
  1109. if (wsa_priv->swr_ctrl_data) {
  1110. swrm_wcd_notify(
  1111. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  1112. SWR_DEVICE_UP, NULL);
  1113. swrm_wcd_notify(
  1114. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  1115. SWR_SET_NUM_RX_CH, &ch_cnt);
  1116. }
  1117. break;
  1118. case SND_SOC_DAPM_POST_PMD:
  1119. if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
  1120. wsa_priv->rx_0_count)
  1121. wsa_priv->rx_0_count--;
  1122. if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
  1123. wsa_priv->rx_1_count)
  1124. wsa_priv->rx_1_count--;
  1125. ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
  1126. if (wsa_priv->swr_ctrl_data)
  1127. swrm_wcd_notify(
  1128. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  1129. SWR_SET_NUM_RX_CH, &ch_cnt);
  1130. break;
  1131. }
  1132. dev_dbg(wsa_priv->dev, "%s: current swr ch cnt: %d\n",
  1133. __func__, wsa_priv->rx_0_count + wsa_priv->rx_1_count);
  1134. return 0;
  1135. }
  1136. static int wsa_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  1137. struct snd_kcontrol *kcontrol, int event)
  1138. {
  1139. struct snd_soc_component *component =
  1140. snd_soc_dapm_to_component(w->dapm);
  1141. u16 gain_reg;
  1142. int offset_val = 0;
  1143. int val = 0;
  1144. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1145. if (!(strcmp(w->name, "WSA_RX0 MIX INP"))) {
  1146. gain_reg = BOLERO_CDC_WSA_RX0_RX_VOL_MIX_CTL;
  1147. } else if (!(strcmp(w->name, "WSA_RX1 MIX INP"))) {
  1148. gain_reg = BOLERO_CDC_WSA_RX1_RX_VOL_MIX_CTL;
  1149. } else {
  1150. dev_err(component->dev, "%s: No gain register avail for %s\n",
  1151. __func__, w->name);
  1152. return 0;
  1153. }
  1154. switch (event) {
  1155. case SND_SOC_DAPM_PRE_PMU:
  1156. wsa_macro_enable_swr(w, kcontrol, event);
  1157. val = snd_soc_component_read32(component, gain_reg);
  1158. val += offset_val;
  1159. snd_soc_component_write(component, gain_reg, val);
  1160. break;
  1161. case SND_SOC_DAPM_POST_PMD:
  1162. snd_soc_component_update_bits(component,
  1163. w->reg, 0x20, 0x00);
  1164. wsa_macro_enable_swr(w, kcontrol, event);
  1165. break;
  1166. }
  1167. return 0;
  1168. }
  1169. static int wsa_macro_config_compander(struct snd_soc_component *component,
  1170. int comp, int event)
  1171. {
  1172. u16 comp_ctl0_reg, rx_path_cfg0_reg;
  1173. struct device *wsa_dev = NULL;
  1174. struct wsa_macro_priv *wsa_priv = NULL;
  1175. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1176. return -EINVAL;
  1177. dev_dbg(component->dev, "%s: event %d compander %d, enabled %d\n",
  1178. __func__, event, comp + 1, wsa_priv->comp_enabled[comp]);
  1179. if (!wsa_priv->comp_enabled[comp])
  1180. return 0;
  1181. comp_ctl0_reg = BOLERO_CDC_WSA_COMPANDER0_CTL0 +
  1182. (comp * WSA_MACRO_RX_COMP_OFFSET);
  1183. rx_path_cfg0_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG0 +
  1184. (comp * WSA_MACRO_RX_PATH_OFFSET);
  1185. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1186. /* Enable Compander Clock */
  1187. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1188. 0x01, 0x01);
  1189. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1190. 0x02, 0x02);
  1191. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1192. 0x02, 0x00);
  1193. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1194. 0x02, 0x02);
  1195. }
  1196. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1197. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1198. 0x04, 0x04);
  1199. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1200. 0x02, 0x00);
  1201. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1202. 0x02, 0x02);
  1203. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1204. 0x02, 0x00);
  1205. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1206. 0x01, 0x00);
  1207. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1208. 0x04, 0x00);
  1209. }
  1210. return 0;
  1211. }
  1212. static void wsa_macro_enable_softclip_clk(struct snd_soc_component *component,
  1213. struct wsa_macro_priv *wsa_priv,
  1214. int path,
  1215. bool enable)
  1216. {
  1217. u16 softclip_clk_reg = BOLERO_CDC_WSA_SOFTCLIP0_CRC +
  1218. (path * WSA_MACRO_RX_SOFTCLIP_OFFSET);
  1219. u8 softclip_mux_mask = (1 << path);
  1220. u8 softclip_mux_value = (1 << path);
  1221. dev_dbg(component->dev, "%s: path %d, enable %d\n",
  1222. __func__, path, enable);
  1223. if (enable) {
  1224. if (wsa_priv->softclip_clk_users[path] == 0) {
  1225. snd_soc_component_update_bits(component,
  1226. softclip_clk_reg, 0x01, 0x01);
  1227. snd_soc_component_update_bits(component,
  1228. BOLERO_CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
  1229. softclip_mux_mask, softclip_mux_value);
  1230. }
  1231. wsa_priv->softclip_clk_users[path]++;
  1232. } else {
  1233. wsa_priv->softclip_clk_users[path]--;
  1234. if (wsa_priv->softclip_clk_users[path] == 0) {
  1235. snd_soc_component_update_bits(component,
  1236. softclip_clk_reg, 0x01, 0x00);
  1237. snd_soc_component_update_bits(component,
  1238. BOLERO_CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
  1239. softclip_mux_mask, 0x00);
  1240. }
  1241. }
  1242. }
  1243. static int wsa_macro_config_softclip(struct snd_soc_component *component,
  1244. int path, int event)
  1245. {
  1246. u16 softclip_ctrl_reg = 0;
  1247. struct device *wsa_dev = NULL;
  1248. struct wsa_macro_priv *wsa_priv = NULL;
  1249. int softclip_path = 0;
  1250. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1251. return -EINVAL;
  1252. if (path == WSA_MACRO_COMP1)
  1253. softclip_path = WSA_MACRO_SOFTCLIP0;
  1254. else if (path == WSA_MACRO_COMP2)
  1255. softclip_path = WSA_MACRO_SOFTCLIP1;
  1256. dev_dbg(component->dev, "%s: event %d path %d, enabled %d\n",
  1257. __func__, event, softclip_path,
  1258. wsa_priv->is_softclip_on[softclip_path]);
  1259. if (!wsa_priv->is_softclip_on[softclip_path])
  1260. return 0;
  1261. softclip_ctrl_reg = BOLERO_CDC_WSA_SOFTCLIP0_SOFTCLIP_CTRL +
  1262. (softclip_path * WSA_MACRO_RX_SOFTCLIP_OFFSET);
  1263. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1264. /* Enable Softclip clock and mux */
  1265. wsa_macro_enable_softclip_clk(component, wsa_priv,
  1266. softclip_path, true);
  1267. /* Enable Softclip control */
  1268. snd_soc_component_update_bits(component, softclip_ctrl_reg,
  1269. 0x01, 0x01);
  1270. }
  1271. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1272. snd_soc_component_update_bits(component, softclip_ctrl_reg,
  1273. 0x01, 0x00);
  1274. wsa_macro_enable_softclip_clk(component, wsa_priv,
  1275. softclip_path, false);
  1276. }
  1277. return 0;
  1278. }
  1279. static bool wsa_macro_adie_lb(struct snd_soc_component *component,
  1280. int interp_idx)
  1281. {
  1282. u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
  1283. u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
  1284. u8 int_n_inp0 = 0, int_n_inp1 = 0, int_n_inp2 = 0;
  1285. int_mux_cfg0 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0 + interp_idx * 8;
  1286. int_mux_cfg1 = int_mux_cfg0 + 4;
  1287. int_mux_cfg0_val = snd_soc_component_read32(component, int_mux_cfg0);
  1288. int_mux_cfg1_val = snd_soc_component_read32(component, int_mux_cfg1);
  1289. int_n_inp0 = int_mux_cfg0_val & 0x0F;
  1290. if (int_n_inp0 == INTn_1_INP_SEL_DEC0 ||
  1291. int_n_inp0 == INTn_1_INP_SEL_DEC1)
  1292. return true;
  1293. int_n_inp1 = int_mux_cfg0_val >> 4;
  1294. if (int_n_inp1 == INTn_1_INP_SEL_DEC0 ||
  1295. int_n_inp1 == INTn_1_INP_SEL_DEC1)
  1296. return true;
  1297. int_n_inp2 = int_mux_cfg1_val >> 4;
  1298. if (int_n_inp2 == INTn_1_INP_SEL_DEC0 ||
  1299. int_n_inp2 == INTn_1_INP_SEL_DEC1)
  1300. return true;
  1301. return false;
  1302. }
  1303. static int wsa_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  1304. struct snd_kcontrol *kcontrol,
  1305. int event)
  1306. {
  1307. struct snd_soc_component *component =
  1308. snd_soc_dapm_to_component(w->dapm);
  1309. u16 reg = 0;
  1310. struct device *wsa_dev = NULL;
  1311. struct wsa_macro_priv *wsa_priv = NULL;
  1312. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1313. return -EINVAL;
  1314. reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
  1315. WSA_MACRO_RX_PATH_OFFSET * w->shift;
  1316. switch (event) {
  1317. case SND_SOC_DAPM_PRE_PMU:
  1318. if (wsa_macro_adie_lb(component, w->shift)) {
  1319. snd_soc_component_update_bits(component,
  1320. reg, 0x20, 0x20);
  1321. bolero_wsa_pa_on(wsa_dev);
  1322. }
  1323. break;
  1324. default:
  1325. break;
  1326. }
  1327. return 0;
  1328. }
  1329. static int wsa_macro_interp_get_primary_reg(u16 reg, u16 *ind)
  1330. {
  1331. u16 prim_int_reg = 0;
  1332. switch (reg) {
  1333. case BOLERO_CDC_WSA_RX0_RX_PATH_CTL:
  1334. case BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL:
  1335. prim_int_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
  1336. *ind = 0;
  1337. break;
  1338. case BOLERO_CDC_WSA_RX1_RX_PATH_CTL:
  1339. case BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL:
  1340. prim_int_reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
  1341. *ind = 1;
  1342. break;
  1343. }
  1344. return prim_int_reg;
  1345. }
  1346. static int wsa_macro_enable_prim_interpolator(
  1347. struct snd_soc_component *component,
  1348. u16 reg, int event)
  1349. {
  1350. u16 prim_int_reg;
  1351. u16 ind = 0;
  1352. struct device *wsa_dev = NULL;
  1353. struct wsa_macro_priv *wsa_priv = NULL;
  1354. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1355. return -EINVAL;
  1356. prim_int_reg = wsa_macro_interp_get_primary_reg(reg, &ind);
  1357. switch (event) {
  1358. case SND_SOC_DAPM_PRE_PMU:
  1359. wsa_priv->prim_int_users[ind]++;
  1360. if (wsa_priv->prim_int_users[ind] == 1) {
  1361. snd_soc_component_update_bits(component,
  1362. prim_int_reg + WSA_MACRO_RX_PATH_CFG3_OFFSET,
  1363. 0x03, 0x03);
  1364. snd_soc_component_update_bits(component, prim_int_reg,
  1365. 0x10, 0x10);
  1366. wsa_macro_hd2_control(component, prim_int_reg, event);
  1367. snd_soc_component_update_bits(component,
  1368. prim_int_reg + WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
  1369. 0x1, 0x1);
  1370. }
  1371. if ((reg != prim_int_reg) &&
  1372. ((snd_soc_component_read32(
  1373. component, prim_int_reg)) & 0x10))
  1374. snd_soc_component_update_bits(component, reg,
  1375. 0x10, 0x10);
  1376. break;
  1377. case SND_SOC_DAPM_POST_PMD:
  1378. wsa_priv->prim_int_users[ind]--;
  1379. if (wsa_priv->prim_int_users[ind] == 0) {
  1380. snd_soc_component_update_bits(component, prim_int_reg,
  1381. 1 << 0x5, 0 << 0x5);
  1382. snd_soc_component_update_bits(component,
  1383. prim_int_reg + WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
  1384. 0x1, 0x0);
  1385. snd_soc_component_update_bits(component, prim_int_reg,
  1386. 0x40, 0x40);
  1387. snd_soc_component_update_bits(component, prim_int_reg,
  1388. 0x40, 0x00);
  1389. wsa_macro_hd2_control(component, prim_int_reg, event);
  1390. }
  1391. break;
  1392. }
  1393. dev_dbg(component->dev, "%s: primary interpolator: INT%d, users: %d\n",
  1394. __func__, ind, wsa_priv->prim_int_users[ind]);
  1395. return 0;
  1396. }
  1397. static int wsa_macro_enable_interpolator(struct snd_soc_dapm_widget *w,
  1398. struct snd_kcontrol *kcontrol,
  1399. int event)
  1400. {
  1401. struct snd_soc_component *component =
  1402. snd_soc_dapm_to_component(w->dapm);
  1403. u16 gain_reg;
  1404. u16 reg;
  1405. int val;
  1406. int offset_val = 0;
  1407. struct device *wsa_dev = NULL;
  1408. struct wsa_macro_priv *wsa_priv = NULL;
  1409. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1410. return -EINVAL;
  1411. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1412. if (!(strcmp(w->name, "WSA_RX INT0 INTERP"))) {
  1413. reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
  1414. gain_reg = BOLERO_CDC_WSA_RX0_RX_VOL_CTL;
  1415. } else if (!(strcmp(w->name, "WSA_RX INT1 INTERP"))) {
  1416. reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
  1417. gain_reg = BOLERO_CDC_WSA_RX1_RX_VOL_CTL;
  1418. } else {
  1419. dev_err(component->dev, "%s: Interpolator reg not found\n",
  1420. __func__);
  1421. return -EINVAL;
  1422. }
  1423. switch (event) {
  1424. case SND_SOC_DAPM_PRE_PMU:
  1425. /* Reset if needed */
  1426. wsa_macro_enable_prim_interpolator(component, reg, event);
  1427. break;
  1428. case SND_SOC_DAPM_POST_PMU:
  1429. wsa_macro_config_compander(component, w->shift, event);
  1430. wsa_macro_config_softclip(component, w->shift, event);
  1431. /* apply gain after int clk is enabled */
  1432. if ((wsa_priv->spkr_gain_offset ==
  1433. WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
  1434. (wsa_priv->comp_enabled[WSA_MACRO_COMP1] ||
  1435. wsa_priv->comp_enabled[WSA_MACRO_COMP2]) &&
  1436. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL ||
  1437. gain_reg == BOLERO_CDC_WSA_RX1_RX_VOL_CTL)) {
  1438. snd_soc_component_update_bits(component,
  1439. BOLERO_CDC_WSA_RX0_RX_PATH_SEC1,
  1440. 0x01, 0x01);
  1441. snd_soc_component_update_bits(component,
  1442. BOLERO_CDC_WSA_RX0_RX_PATH_MIX_SEC0,
  1443. 0x01, 0x01);
  1444. snd_soc_component_update_bits(component,
  1445. BOLERO_CDC_WSA_RX1_RX_PATH_SEC1,
  1446. 0x01, 0x01);
  1447. snd_soc_component_update_bits(component,
  1448. BOLERO_CDC_WSA_RX1_RX_PATH_MIX_SEC0,
  1449. 0x01, 0x01);
  1450. offset_val = -2;
  1451. }
  1452. val = snd_soc_component_read32(component, gain_reg);
  1453. val += offset_val;
  1454. snd_soc_component_write(component, gain_reg, val);
  1455. wsa_macro_config_ear_spkr_gain(component, wsa_priv,
  1456. event, gain_reg);
  1457. break;
  1458. case SND_SOC_DAPM_POST_PMD:
  1459. wsa_macro_config_compander(component, w->shift, event);
  1460. wsa_macro_config_softclip(component, w->shift, event);
  1461. wsa_macro_enable_prim_interpolator(component, reg, event);
  1462. if ((wsa_priv->spkr_gain_offset ==
  1463. WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
  1464. (wsa_priv->comp_enabled[WSA_MACRO_COMP1] ||
  1465. wsa_priv->comp_enabled[WSA_MACRO_COMP2]) &&
  1466. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL ||
  1467. gain_reg == BOLERO_CDC_WSA_RX1_RX_VOL_CTL)) {
  1468. snd_soc_component_update_bits(component,
  1469. BOLERO_CDC_WSA_RX0_RX_PATH_SEC1,
  1470. 0x01, 0x00);
  1471. snd_soc_component_update_bits(component,
  1472. BOLERO_CDC_WSA_RX0_RX_PATH_MIX_SEC0,
  1473. 0x01, 0x00);
  1474. snd_soc_component_update_bits(component,
  1475. BOLERO_CDC_WSA_RX1_RX_PATH_SEC1,
  1476. 0x01, 0x00);
  1477. snd_soc_component_update_bits(component,
  1478. BOLERO_CDC_WSA_RX1_RX_PATH_MIX_SEC0,
  1479. 0x01, 0x00);
  1480. offset_val = 2;
  1481. val = snd_soc_component_read32(component, gain_reg);
  1482. val += offset_val;
  1483. snd_soc_component_write(component, gain_reg, val);
  1484. }
  1485. wsa_macro_config_ear_spkr_gain(component, wsa_priv,
  1486. event, gain_reg);
  1487. break;
  1488. }
  1489. return 0;
  1490. }
  1491. static int wsa_macro_config_ear_spkr_gain(struct snd_soc_component *component,
  1492. struct wsa_macro_priv *wsa_priv,
  1493. int event, int gain_reg)
  1494. {
  1495. int comp_gain_offset, val;
  1496. switch (wsa_priv->spkr_mode) {
  1497. /* Compander gain in WSA_MACRO_SPKR_MODE1 case is 12 dB */
  1498. case WSA_MACRO_SPKR_MODE_1:
  1499. comp_gain_offset = -12;
  1500. break;
  1501. /* Default case compander gain is 15 dB */
  1502. default:
  1503. comp_gain_offset = -15;
  1504. break;
  1505. }
  1506. switch (event) {
  1507. case SND_SOC_DAPM_POST_PMU:
  1508. /* Apply ear spkr gain only if compander is enabled */
  1509. if (wsa_priv->comp_enabled[WSA_MACRO_COMP1] &&
  1510. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL) &&
  1511. (wsa_priv->ear_spkr_gain != 0)) {
  1512. /* For example, val is -8(-12+5-1) for 4dB of gain */
  1513. val = comp_gain_offset + wsa_priv->ear_spkr_gain - 1;
  1514. snd_soc_component_write(component, gain_reg, val);
  1515. dev_dbg(wsa_priv->dev, "%s: RX0 Volume %d dB\n",
  1516. __func__, val);
  1517. }
  1518. break;
  1519. case SND_SOC_DAPM_POST_PMD:
  1520. /*
  1521. * Reset RX0 volume to 0 dB if compander is enabled and
  1522. * ear_spkr_gain is non-zero.
  1523. */
  1524. if (wsa_priv->comp_enabled[WSA_MACRO_COMP1] &&
  1525. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL) &&
  1526. (wsa_priv->ear_spkr_gain != 0)) {
  1527. snd_soc_component_write(component, gain_reg, 0x0);
  1528. dev_dbg(wsa_priv->dev, "%s: Reset RX0 Volume to 0 dB\n",
  1529. __func__);
  1530. }
  1531. break;
  1532. }
  1533. return 0;
  1534. }
  1535. static int wsa_macro_spk_boost_event(struct snd_soc_dapm_widget *w,
  1536. struct snd_kcontrol *kcontrol,
  1537. int event)
  1538. {
  1539. struct snd_soc_component *component =
  1540. snd_soc_dapm_to_component(w->dapm);
  1541. u16 boost_path_ctl, boost_path_cfg1;
  1542. u16 reg, reg_mix;
  1543. dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
  1544. if (!strcmp(w->name, "WSA_RX INT0 CHAIN")) {
  1545. boost_path_ctl = BOLERO_CDC_WSA_BOOST0_BOOST_PATH_CTL;
  1546. boost_path_cfg1 = BOLERO_CDC_WSA_RX0_RX_PATH_CFG1;
  1547. reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
  1548. reg_mix = BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL;
  1549. } else if (!strcmp(w->name, "WSA_RX INT1 CHAIN")) {
  1550. boost_path_ctl = BOLERO_CDC_WSA_BOOST1_BOOST_PATH_CTL;
  1551. boost_path_cfg1 = BOLERO_CDC_WSA_RX1_RX_PATH_CFG1;
  1552. reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
  1553. reg_mix = BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL;
  1554. } else {
  1555. dev_err(component->dev, "%s: unknown widget: %s\n",
  1556. __func__, w->name);
  1557. return -EINVAL;
  1558. }
  1559. switch (event) {
  1560. case SND_SOC_DAPM_PRE_PMU:
  1561. snd_soc_component_update_bits(component, boost_path_cfg1,
  1562. 0x01, 0x01);
  1563. snd_soc_component_update_bits(component, boost_path_ctl,
  1564. 0x10, 0x10);
  1565. if ((snd_soc_component_read32(component, reg_mix)) & 0x10)
  1566. snd_soc_component_update_bits(component, reg_mix,
  1567. 0x10, 0x00);
  1568. break;
  1569. case SND_SOC_DAPM_POST_PMU:
  1570. snd_soc_component_update_bits(component, reg, 0x10, 0x00);
  1571. break;
  1572. case SND_SOC_DAPM_POST_PMD:
  1573. snd_soc_component_update_bits(component, boost_path_ctl,
  1574. 0x10, 0x00);
  1575. snd_soc_component_update_bits(component, boost_path_cfg1,
  1576. 0x01, 0x00);
  1577. break;
  1578. }
  1579. return 0;
  1580. }
  1581. static int wsa_macro_enable_vbat(struct snd_soc_dapm_widget *w,
  1582. struct snd_kcontrol *kcontrol,
  1583. int event)
  1584. {
  1585. struct snd_soc_component *component =
  1586. snd_soc_dapm_to_component(w->dapm);
  1587. struct device *wsa_dev = NULL;
  1588. struct wsa_macro_priv *wsa_priv = NULL;
  1589. u16 vbat_path_cfg = 0;
  1590. int softclip_path = 0;
  1591. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1592. return -EINVAL;
  1593. dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
  1594. if (!strcmp(w->name, "WSA_RX INT0 VBAT")) {
  1595. vbat_path_cfg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG1;
  1596. softclip_path = WSA_MACRO_SOFTCLIP0;
  1597. } else if (!strcmp(w->name, "WSA_RX INT1 VBAT")) {
  1598. vbat_path_cfg = BOLERO_CDC_WSA_RX1_RX_PATH_CFG1;
  1599. softclip_path = WSA_MACRO_SOFTCLIP1;
  1600. }
  1601. switch (event) {
  1602. case SND_SOC_DAPM_PRE_PMU:
  1603. /* Enable clock for VBAT block */
  1604. snd_soc_component_update_bits(component,
  1605. BOLERO_CDC_WSA_VBAT_BCL_VBAT_PATH_CTL, 0x10, 0x10);
  1606. /* Enable VBAT block */
  1607. snd_soc_component_update_bits(component,
  1608. BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x01, 0x01);
  1609. /* Update interpolator with 384K path */
  1610. snd_soc_component_update_bits(component, vbat_path_cfg,
  1611. 0x80, 0x80);
  1612. /* Use attenuation mode */
  1613. snd_soc_component_update_bits(component,
  1614. BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x02, 0x00);
  1615. /*
  1616. * BCL block needs softclip clock and mux config to be enabled
  1617. */
  1618. wsa_macro_enable_softclip_clk(component, wsa_priv,
  1619. softclip_path, true);
  1620. /* Enable VBAT at channel level */
  1621. snd_soc_component_update_bits(component, vbat_path_cfg,
  1622. 0x02, 0x02);
  1623. /* Set the ATTK1 gain */
  1624. snd_soc_component_update_bits(component,
  1625. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD1,
  1626. 0xFF, 0xFF);
  1627. snd_soc_component_update_bits(component,
  1628. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD2,
  1629. 0xFF, 0x03);
  1630. snd_soc_component_update_bits(component,
  1631. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD3,
  1632. 0xFF, 0x00);
  1633. /* Set the ATTK2 gain */
  1634. snd_soc_component_update_bits(component,
  1635. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD4,
  1636. 0xFF, 0xFF);
  1637. snd_soc_component_update_bits(component,
  1638. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD5,
  1639. 0xFF, 0x03);
  1640. snd_soc_component_update_bits(component,
  1641. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD6,
  1642. 0xFF, 0x00);
  1643. /* Set the ATTK3 gain */
  1644. snd_soc_component_update_bits(component,
  1645. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD7,
  1646. 0xFF, 0xFF);
  1647. snd_soc_component_update_bits(component,
  1648. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD8,
  1649. 0xFF, 0x03);
  1650. snd_soc_component_update_bits(component,
  1651. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD9,
  1652. 0xFF, 0x00);
  1653. break;
  1654. case SND_SOC_DAPM_POST_PMD:
  1655. snd_soc_component_update_bits(component, vbat_path_cfg,
  1656. 0x80, 0x00);
  1657. snd_soc_component_update_bits(component,
  1658. BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG,
  1659. 0x02, 0x02);
  1660. snd_soc_component_update_bits(component, vbat_path_cfg,
  1661. 0x02, 0x00);
  1662. snd_soc_component_update_bits(component,
  1663. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD1,
  1664. 0xFF, 0x00);
  1665. snd_soc_component_update_bits(component,
  1666. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD2,
  1667. 0xFF, 0x00);
  1668. snd_soc_component_update_bits(component,
  1669. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD3,
  1670. 0xFF, 0x00);
  1671. snd_soc_component_update_bits(component,
  1672. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD4,
  1673. 0xFF, 0x00);
  1674. snd_soc_component_update_bits(component,
  1675. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD5,
  1676. 0xFF, 0x00);
  1677. snd_soc_component_update_bits(component,
  1678. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD6,
  1679. 0xFF, 0x00);
  1680. snd_soc_component_update_bits(component,
  1681. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD7,
  1682. 0xFF, 0x00);
  1683. snd_soc_component_update_bits(component,
  1684. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD8,
  1685. 0xFF, 0x00);
  1686. snd_soc_component_update_bits(component,
  1687. BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD9,
  1688. 0xFF, 0x00);
  1689. wsa_macro_enable_softclip_clk(component, wsa_priv,
  1690. softclip_path, false);
  1691. snd_soc_component_update_bits(component,
  1692. BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x01, 0x00);
  1693. snd_soc_component_update_bits(component,
  1694. BOLERO_CDC_WSA_VBAT_BCL_VBAT_PATH_CTL, 0x10, 0x00);
  1695. break;
  1696. default:
  1697. dev_err(wsa_dev, "%s: Invalid event %d\n", __func__, event);
  1698. break;
  1699. }
  1700. return 0;
  1701. }
  1702. static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
  1703. struct snd_kcontrol *kcontrol,
  1704. int event)
  1705. {
  1706. struct snd_soc_component *component =
  1707. snd_soc_dapm_to_component(w->dapm);
  1708. struct device *wsa_dev = NULL;
  1709. struct wsa_macro_priv *wsa_priv = NULL;
  1710. u16 val, ec_tx = 0, ec_hq_reg;
  1711. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1712. return -EINVAL;
  1713. dev_dbg(wsa_dev, "%s %d %s\n", __func__, event, w->name);
  1714. val = snd_soc_component_read32(component,
  1715. BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
  1716. if (!(strcmp(w->name, "WSA RX_MIX EC0_MUX")))
  1717. ec_tx = (val & 0x07) - 1;
  1718. else
  1719. ec_tx = ((val & 0x38) >> 0x3) - 1;
  1720. if (ec_tx < 0 || ec_tx >= (WSA_MACRO_RX1 + 1)) {
  1721. dev_err(wsa_dev, "%s: EC mix control not set correctly\n",
  1722. __func__);
  1723. return -EINVAL;
  1724. }
  1725. if (wsa_priv->ec_hq[ec_tx]) {
  1726. snd_soc_component_update_bits(component,
  1727. BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
  1728. 0x1 << ec_tx, 0x1 << ec_tx);
  1729. ec_hq_reg = BOLERO_CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL +
  1730. 0x40 * ec_tx;
  1731. snd_soc_component_update_bits(component, ec_hq_reg, 0x01, 0x01);
  1732. ec_hq_reg = BOLERO_CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0 +
  1733. 0x40 * ec_tx;
  1734. /* default set to 48k */
  1735. snd_soc_component_update_bits(component, ec_hq_reg, 0x1E, 0x08);
  1736. }
  1737. return 0;
  1738. }
  1739. static int wsa_macro_get_ec_hq(struct snd_kcontrol *kcontrol,
  1740. struct snd_ctl_elem_value *ucontrol)
  1741. {
  1742. struct snd_soc_component *component =
  1743. snd_soc_kcontrol_component(kcontrol);
  1744. int ec_tx = ((struct soc_multi_mixer_control *)
  1745. kcontrol->private_value)->shift;
  1746. struct device *wsa_dev = NULL;
  1747. struct wsa_macro_priv *wsa_priv = NULL;
  1748. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1749. return -EINVAL;
  1750. ucontrol->value.integer.value[0] = wsa_priv->ec_hq[ec_tx];
  1751. return 0;
  1752. }
  1753. static int wsa_macro_set_ec_hq(struct snd_kcontrol *kcontrol,
  1754. struct snd_ctl_elem_value *ucontrol)
  1755. {
  1756. struct snd_soc_component *component =
  1757. snd_soc_kcontrol_component(kcontrol);
  1758. int ec_tx = ((struct soc_multi_mixer_control *)
  1759. kcontrol->private_value)->shift;
  1760. int value = ucontrol->value.integer.value[0];
  1761. struct device *wsa_dev = NULL;
  1762. struct wsa_macro_priv *wsa_priv = NULL;
  1763. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1764. return -EINVAL;
  1765. dev_dbg(wsa_dev, "%s: enable current %d, new %d\n",
  1766. __func__, wsa_priv->ec_hq[ec_tx], value);
  1767. wsa_priv->ec_hq[ec_tx] = value;
  1768. return 0;
  1769. }
  1770. static int wsa_macro_get_rx_mute_status(struct snd_kcontrol *kcontrol,
  1771. struct snd_ctl_elem_value *ucontrol)
  1772. {
  1773. struct snd_soc_component *component =
  1774. snd_soc_kcontrol_component(kcontrol);
  1775. struct device *wsa_dev = NULL;
  1776. struct wsa_macro_priv *wsa_priv = NULL;
  1777. int wsa_rx_shift = ((struct soc_multi_mixer_control *)
  1778. kcontrol->private_value)->shift;
  1779. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1780. return -EINVAL;
  1781. ucontrol->value.integer.value[0] =
  1782. wsa_priv->wsa_digital_mute_status[wsa_rx_shift];
  1783. return 0;
  1784. }
  1785. static int wsa_macro_set_rx_mute_status(struct snd_kcontrol *kcontrol,
  1786. struct snd_ctl_elem_value *ucontrol)
  1787. {
  1788. struct snd_soc_component *component =
  1789. snd_soc_kcontrol_component(kcontrol);
  1790. struct device *wsa_dev = NULL;
  1791. struct wsa_macro_priv *wsa_priv = NULL;
  1792. int value = ucontrol->value.integer.value[0];
  1793. int wsa_rx_shift = ((struct soc_multi_mixer_control *)
  1794. kcontrol->private_value)->shift;
  1795. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1796. return -EINVAL;
  1797. switch (wsa_rx_shift) {
  1798. case 0:
  1799. snd_soc_component_update_bits(component,
  1800. BOLERO_CDC_WSA_RX0_RX_PATH_CTL,
  1801. 0x10, value << 4);
  1802. break;
  1803. case 1:
  1804. snd_soc_component_update_bits(component,
  1805. BOLERO_CDC_WSA_RX1_RX_PATH_CTL,
  1806. 0x10, value << 4);
  1807. break;
  1808. case 2:
  1809. snd_soc_component_update_bits(component,
  1810. BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL,
  1811. 0x10, value << 4);
  1812. break;
  1813. case 3:
  1814. snd_soc_component_update_bits(component,
  1815. BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL,
  1816. 0x10, value << 4);
  1817. break;
  1818. default:
  1819. pr_err("%s: invalid argument rx_shift = %d\n", __func__,
  1820. wsa_rx_shift);
  1821. return -EINVAL;
  1822. }
  1823. dev_dbg(component->dev, "%s: WSA Digital Mute RX %d Enable %d\n",
  1824. __func__, wsa_rx_shift, value);
  1825. wsa_priv->wsa_digital_mute_status[wsa_rx_shift] = value;
  1826. return 0;
  1827. }
  1828. static int wsa_macro_get_compander(struct snd_kcontrol *kcontrol,
  1829. struct snd_ctl_elem_value *ucontrol)
  1830. {
  1831. struct snd_soc_component *component =
  1832. snd_soc_kcontrol_component(kcontrol);
  1833. int comp = ((struct soc_multi_mixer_control *)
  1834. kcontrol->private_value)->shift;
  1835. struct device *wsa_dev = NULL;
  1836. struct wsa_macro_priv *wsa_priv = NULL;
  1837. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1838. return -EINVAL;
  1839. ucontrol->value.integer.value[0] = wsa_priv->comp_enabled[comp];
  1840. return 0;
  1841. }
  1842. static int wsa_macro_set_compander(struct snd_kcontrol *kcontrol,
  1843. struct snd_ctl_elem_value *ucontrol)
  1844. {
  1845. struct snd_soc_component *component =
  1846. snd_soc_kcontrol_component(kcontrol);
  1847. int comp = ((struct soc_multi_mixer_control *)
  1848. kcontrol->private_value)->shift;
  1849. int value = ucontrol->value.integer.value[0];
  1850. struct device *wsa_dev = NULL;
  1851. struct wsa_macro_priv *wsa_priv = NULL;
  1852. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1853. return -EINVAL;
  1854. dev_dbg(component->dev, "%s: Compander %d enable current %d, new %d\n",
  1855. __func__, comp + 1, wsa_priv->comp_enabled[comp], value);
  1856. wsa_priv->comp_enabled[comp] = value;
  1857. return 0;
  1858. }
  1859. static int wsa_macro_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
  1860. struct snd_ctl_elem_value *ucontrol)
  1861. {
  1862. struct snd_soc_component *component =
  1863. snd_soc_kcontrol_component(kcontrol);
  1864. struct device *wsa_dev = NULL;
  1865. struct wsa_macro_priv *wsa_priv = NULL;
  1866. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1867. return -EINVAL;
  1868. ucontrol->value.integer.value[0] = wsa_priv->ear_spkr_gain;
  1869. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1870. __func__, ucontrol->value.integer.value[0]);
  1871. return 0;
  1872. }
  1873. static int wsa_macro_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
  1874. struct snd_ctl_elem_value *ucontrol)
  1875. {
  1876. struct snd_soc_component *component =
  1877. snd_soc_kcontrol_component(kcontrol);
  1878. struct device *wsa_dev = NULL;
  1879. struct wsa_macro_priv *wsa_priv = NULL;
  1880. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1881. return -EINVAL;
  1882. wsa_priv->ear_spkr_gain = ucontrol->value.integer.value[0];
  1883. dev_dbg(component->dev, "%s: gain = %d\n", __func__,
  1884. wsa_priv->ear_spkr_gain);
  1885. return 0;
  1886. }
  1887. static int wsa_macro_spkr_left_boost_stage_get(struct snd_kcontrol *kcontrol,
  1888. struct snd_ctl_elem_value *ucontrol)
  1889. {
  1890. u8 bst_state_max = 0;
  1891. struct snd_soc_component *component =
  1892. snd_soc_kcontrol_component(kcontrol);
  1893. bst_state_max = snd_soc_component_read32(component,
  1894. BOLERO_CDC_WSA_BOOST0_BOOST_CTL);
  1895. bst_state_max = (bst_state_max & 0x0c) >> 2;
  1896. ucontrol->value.integer.value[0] = bst_state_max;
  1897. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1898. __func__, ucontrol->value.integer.value[0]);
  1899. return 0;
  1900. }
  1901. static int wsa_macro_spkr_left_boost_stage_put(struct snd_kcontrol *kcontrol,
  1902. struct snd_ctl_elem_value *ucontrol)
  1903. {
  1904. u8 bst_state_max;
  1905. struct snd_soc_component *component =
  1906. snd_soc_kcontrol_component(kcontrol);
  1907. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1908. __func__, ucontrol->value.integer.value[0]);
  1909. bst_state_max = ucontrol->value.integer.value[0] << 2;
  1910. /* bolero does not need to limit the boost levels */
  1911. return 0;
  1912. }
  1913. static int wsa_macro_spkr_right_boost_stage_get(struct snd_kcontrol *kcontrol,
  1914. struct snd_ctl_elem_value *ucontrol)
  1915. {
  1916. u8 bst_state_max = 0;
  1917. struct snd_soc_component *component =
  1918. snd_soc_kcontrol_component(kcontrol);
  1919. bst_state_max = snd_soc_component_read32(component,
  1920. BOLERO_CDC_WSA_BOOST1_BOOST_CTL);
  1921. bst_state_max = (bst_state_max & 0x0c) >> 2;
  1922. ucontrol->value.integer.value[0] = bst_state_max;
  1923. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1924. __func__, ucontrol->value.integer.value[0]);
  1925. return 0;
  1926. }
  1927. static int wsa_macro_spkr_right_boost_stage_put(struct snd_kcontrol *kcontrol,
  1928. struct snd_ctl_elem_value *ucontrol)
  1929. {
  1930. u8 bst_state_max;
  1931. struct snd_soc_component *component =
  1932. snd_soc_kcontrol_component(kcontrol);
  1933. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1934. __func__, ucontrol->value.integer.value[0]);
  1935. bst_state_max = ucontrol->value.integer.value[0] << 2;
  1936. /* bolero does not need to limit the boost levels */
  1937. return 0;
  1938. }
  1939. static int wsa_macro_rx_mux_get(struct snd_kcontrol *kcontrol,
  1940. struct snd_ctl_elem_value *ucontrol)
  1941. {
  1942. struct snd_soc_dapm_widget *widget =
  1943. snd_soc_dapm_kcontrol_widget(kcontrol);
  1944. struct snd_soc_component *component =
  1945. snd_soc_dapm_to_component(widget->dapm);
  1946. struct device *wsa_dev = NULL;
  1947. struct wsa_macro_priv *wsa_priv = NULL;
  1948. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1949. return -EINVAL;
  1950. ucontrol->value.integer.value[0] =
  1951. wsa_priv->rx_port_value[widget->shift];
  1952. return 0;
  1953. }
  1954. static int wsa_macro_rx_mux_put(struct snd_kcontrol *kcontrol,
  1955. struct snd_ctl_elem_value *ucontrol)
  1956. {
  1957. struct snd_soc_dapm_widget *widget =
  1958. snd_soc_dapm_kcontrol_widget(kcontrol);
  1959. struct snd_soc_component *component =
  1960. snd_soc_dapm_to_component(widget->dapm);
  1961. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1962. struct snd_soc_dapm_update *update = NULL;
  1963. u32 rx_port_value = ucontrol->value.integer.value[0];
  1964. u32 bit_input = 0;
  1965. u32 aif_rst;
  1966. struct device *wsa_dev = NULL;
  1967. struct wsa_macro_priv *wsa_priv = NULL;
  1968. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  1969. return -EINVAL;
  1970. aif_rst = wsa_priv->rx_port_value[widget->shift];
  1971. if (!rx_port_value) {
  1972. if (aif_rst == 0) {
  1973. dev_err(wsa_dev, "%s: AIF reset already\n", __func__);
  1974. return 0;
  1975. }
  1976. if (aif_rst >= WSA_MACRO_RX_MAX) {
  1977. dev_err(wsa_dev, "%s: Invalid AIF reset\n", __func__);
  1978. return 0;
  1979. }
  1980. }
  1981. wsa_priv->rx_port_value[widget->shift] = rx_port_value;
  1982. bit_input = widget->shift;
  1983. dev_dbg(wsa_dev,
  1984. "%s: mux input: %d, mux output: %d, bit: %d\n",
  1985. __func__, rx_port_value, widget->shift, bit_input);
  1986. switch (rx_port_value) {
  1987. case 0:
  1988. if (wsa_priv->active_ch_cnt[aif_rst]) {
  1989. clear_bit(bit_input,
  1990. &wsa_priv->active_ch_mask[aif_rst]);
  1991. wsa_priv->active_ch_cnt[aif_rst]--;
  1992. }
  1993. break;
  1994. case 1:
  1995. case 2:
  1996. set_bit(bit_input,
  1997. &wsa_priv->active_ch_mask[rx_port_value]);
  1998. wsa_priv->active_ch_cnt[rx_port_value]++;
  1999. break;
  2000. default:
  2001. dev_err(wsa_dev,
  2002. "%s: Invalid AIF_ID for WSA RX MUX %d\n",
  2003. __func__, rx_port_value);
  2004. return -EINVAL;
  2005. }
  2006. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  2007. rx_port_value, e, update);
  2008. return 0;
  2009. }
  2010. static int wsa_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
  2011. struct snd_ctl_elem_value *ucontrol)
  2012. {
  2013. struct snd_soc_component *component =
  2014. snd_soc_kcontrol_component(kcontrol);
  2015. ucontrol->value.integer.value[0] =
  2016. ((snd_soc_component_read32(
  2017. component, BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG) & 0x04) ?
  2018. 1 : 0);
  2019. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  2020. ucontrol->value.integer.value[0]);
  2021. return 0;
  2022. }
  2023. static int wsa_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
  2024. struct snd_ctl_elem_value *ucontrol)
  2025. {
  2026. struct snd_soc_component *component =
  2027. snd_soc_kcontrol_component(kcontrol);
  2028. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  2029. ucontrol->value.integer.value[0]);
  2030. /* Set Vbat register configuration for GSM mode bit based on value */
  2031. if (ucontrol->value.integer.value[0])
  2032. snd_soc_component_update_bits(component,
  2033. BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG,
  2034. 0x04, 0x04);
  2035. else
  2036. snd_soc_component_update_bits(component,
  2037. BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG,
  2038. 0x04, 0x00);
  2039. return 0;
  2040. }
  2041. static int wsa_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
  2042. struct snd_ctl_elem_value *ucontrol)
  2043. {
  2044. struct snd_soc_component *component =
  2045. snd_soc_kcontrol_component(kcontrol);
  2046. struct device *wsa_dev = NULL;
  2047. struct wsa_macro_priv *wsa_priv = NULL;
  2048. int path = ((struct soc_multi_mixer_control *)
  2049. kcontrol->private_value)->shift;
  2050. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2051. return -EINVAL;
  2052. ucontrol->value.integer.value[0] = wsa_priv->is_softclip_on[path];
  2053. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  2054. __func__, ucontrol->value.integer.value[0]);
  2055. return 0;
  2056. }
  2057. static int wsa_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
  2058. struct snd_ctl_elem_value *ucontrol)
  2059. {
  2060. struct snd_soc_component *component =
  2061. snd_soc_kcontrol_component(kcontrol);
  2062. struct device *wsa_dev = NULL;
  2063. struct wsa_macro_priv *wsa_priv = NULL;
  2064. int path = ((struct soc_multi_mixer_control *)
  2065. kcontrol->private_value)->shift;
  2066. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2067. return -EINVAL;
  2068. wsa_priv->is_softclip_on[path] = ucontrol->value.integer.value[0];
  2069. dev_dbg(component->dev, "%s: soft clip enable for %d: %d\n", __func__,
  2070. path, wsa_priv->is_softclip_on[path]);
  2071. return 0;
  2072. }
  2073. static const struct snd_kcontrol_new wsa_macro_snd_controls[] = {
  2074. SOC_ENUM_EXT("EAR SPKR PA Gain", wsa_macro_ear_spkr_pa_gain_enum,
  2075. wsa_macro_ear_spkr_pa_gain_get,
  2076. wsa_macro_ear_spkr_pa_gain_put),
  2077. SOC_ENUM_EXT("SPKR Left Boost Max State",
  2078. wsa_macro_spkr_boost_stage_enum,
  2079. wsa_macro_spkr_left_boost_stage_get,
  2080. wsa_macro_spkr_left_boost_stage_put),
  2081. SOC_ENUM_EXT("SPKR Right Boost Max State",
  2082. wsa_macro_spkr_boost_stage_enum,
  2083. wsa_macro_spkr_right_boost_stage_get,
  2084. wsa_macro_spkr_right_boost_stage_put),
  2085. SOC_ENUM_EXT("GSM mode Enable", wsa_macro_vbat_bcl_gsm_mode_enum,
  2086. wsa_macro_vbat_bcl_gsm_mode_func_get,
  2087. wsa_macro_vbat_bcl_gsm_mode_func_put),
  2088. SOC_SINGLE_EXT("WSA_Softclip0 Enable", SND_SOC_NOPM,
  2089. WSA_MACRO_SOFTCLIP0, 1, 0,
  2090. wsa_macro_soft_clip_enable_get,
  2091. wsa_macro_soft_clip_enable_put),
  2092. SOC_SINGLE_EXT("WSA_Softclip1 Enable", SND_SOC_NOPM,
  2093. WSA_MACRO_SOFTCLIP1, 1, 0,
  2094. wsa_macro_soft_clip_enable_get,
  2095. wsa_macro_soft_clip_enable_put),
  2096. SOC_SINGLE_S8_TLV("WSA_RX0 Digital Volume",
  2097. BOLERO_CDC_WSA_RX0_RX_VOL_CTL,
  2098. -84, 40, digital_gain),
  2099. SOC_SINGLE_S8_TLV("WSA_RX1 Digital Volume",
  2100. BOLERO_CDC_WSA_RX1_RX_VOL_CTL,
  2101. -84, 40, digital_gain),
  2102. SOC_SINGLE_EXT("WSA_RX0 Digital Mute", SND_SOC_NOPM, WSA_MACRO_RX0, 1,
  2103. 0, wsa_macro_get_rx_mute_status,
  2104. wsa_macro_set_rx_mute_status),
  2105. SOC_SINGLE_EXT("WSA_RX1 Digital Mute", SND_SOC_NOPM, WSA_MACRO_RX1, 1,
  2106. 0, wsa_macro_get_rx_mute_status,
  2107. wsa_macro_set_rx_mute_status),
  2108. SOC_SINGLE_EXT("WSA_RX0_MIX Digital Mute", SND_SOC_NOPM,
  2109. WSA_MACRO_RX_MIX0, 1, 0, wsa_macro_get_rx_mute_status,
  2110. wsa_macro_set_rx_mute_status),
  2111. SOC_SINGLE_EXT("WSA_RX1_MIX Digital Mute", SND_SOC_NOPM,
  2112. WSA_MACRO_RX_MIX1, 1, 0, wsa_macro_get_rx_mute_status,
  2113. wsa_macro_set_rx_mute_status),
  2114. SOC_SINGLE_EXT("WSA_COMP1 Switch", SND_SOC_NOPM, WSA_MACRO_COMP1, 1, 0,
  2115. wsa_macro_get_compander, wsa_macro_set_compander),
  2116. SOC_SINGLE_EXT("WSA_COMP2 Switch", SND_SOC_NOPM, WSA_MACRO_COMP2, 1, 0,
  2117. wsa_macro_get_compander, wsa_macro_set_compander),
  2118. SOC_SINGLE_EXT("WSA_RX0 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX0,
  2119. 1, 0, wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
  2120. SOC_SINGLE_EXT("WSA_RX1 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX1,
  2121. 1, 0, wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
  2122. };
  2123. static const struct soc_enum rx_mux_enum =
  2124. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_mux_text), rx_mux_text);
  2125. static const struct snd_kcontrol_new rx_mux[WSA_MACRO_RX_MAX] = {
  2126. SOC_DAPM_ENUM_EXT("WSA RX0 Mux", rx_mux_enum,
  2127. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  2128. SOC_DAPM_ENUM_EXT("WSA RX1 Mux", rx_mux_enum,
  2129. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  2130. SOC_DAPM_ENUM_EXT("WSA RX_MIX0 Mux", rx_mux_enum,
  2131. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  2132. SOC_DAPM_ENUM_EXT("WSA RX_MIX1 Mux", rx_mux_enum,
  2133. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  2134. };
  2135. static int wsa_macro_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
  2136. struct snd_ctl_elem_value *ucontrol)
  2137. {
  2138. struct snd_soc_dapm_widget *widget =
  2139. snd_soc_dapm_kcontrol_widget(kcontrol);
  2140. struct snd_soc_component *component =
  2141. snd_soc_dapm_to_component(widget->dapm);
  2142. struct soc_multi_mixer_control *mixer =
  2143. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  2144. u32 dai_id = widget->shift;
  2145. u32 spk_tx_id = mixer->shift;
  2146. struct device *wsa_dev = NULL;
  2147. struct wsa_macro_priv *wsa_priv = NULL;
  2148. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2149. return -EINVAL;
  2150. if (test_bit(spk_tx_id, &wsa_priv->active_ch_mask[dai_id]))
  2151. ucontrol->value.integer.value[0] = 1;
  2152. else
  2153. ucontrol->value.integer.value[0] = 0;
  2154. return 0;
  2155. }
  2156. static int wsa_macro_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
  2157. struct snd_ctl_elem_value *ucontrol)
  2158. {
  2159. struct snd_soc_dapm_widget *widget =
  2160. snd_soc_dapm_kcontrol_widget(kcontrol);
  2161. struct snd_soc_component *component =
  2162. snd_soc_dapm_to_component(widget->dapm);
  2163. struct soc_multi_mixer_control *mixer =
  2164. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  2165. u32 spk_tx_id = mixer->shift;
  2166. u32 enable = ucontrol->value.integer.value[0];
  2167. struct device *wsa_dev = NULL;
  2168. struct wsa_macro_priv *wsa_priv = NULL;
  2169. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2170. return -EINVAL;
  2171. wsa_priv->vi_feed_value = ucontrol->value.integer.value[0];
  2172. if (enable) {
  2173. if (spk_tx_id == WSA_MACRO_TX0 &&
  2174. !test_bit(WSA_MACRO_TX0,
  2175. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  2176. set_bit(WSA_MACRO_TX0,
  2177. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  2178. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]++;
  2179. }
  2180. if (spk_tx_id == WSA_MACRO_TX1 &&
  2181. !test_bit(WSA_MACRO_TX1,
  2182. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  2183. set_bit(WSA_MACRO_TX1,
  2184. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  2185. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]++;
  2186. }
  2187. } else {
  2188. if (spk_tx_id == WSA_MACRO_TX0 &&
  2189. test_bit(WSA_MACRO_TX0,
  2190. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  2191. clear_bit(WSA_MACRO_TX0,
  2192. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  2193. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]--;
  2194. }
  2195. if (spk_tx_id == WSA_MACRO_TX1 &&
  2196. test_bit(WSA_MACRO_TX1,
  2197. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  2198. clear_bit(WSA_MACRO_TX1,
  2199. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  2200. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]--;
  2201. }
  2202. }
  2203. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
  2204. return 0;
  2205. }
  2206. static const struct snd_kcontrol_new aif_vi_mixer[] = {
  2207. SOC_SINGLE_EXT("WSA_SPKR_VI_1", SND_SOC_NOPM, WSA_MACRO_TX0, 1, 0,
  2208. wsa_macro_vi_feed_mixer_get,
  2209. wsa_macro_vi_feed_mixer_put),
  2210. SOC_SINGLE_EXT("WSA_SPKR_VI_2", SND_SOC_NOPM, WSA_MACRO_TX1, 1, 0,
  2211. wsa_macro_vi_feed_mixer_get,
  2212. wsa_macro_vi_feed_mixer_put),
  2213. };
  2214. static const struct snd_soc_dapm_widget wsa_macro_dapm_widgets[] = {
  2215. SND_SOC_DAPM_AIF_IN("WSA AIF1 PB", "WSA_AIF1 Playback", 0,
  2216. SND_SOC_NOPM, 0, 0),
  2217. SND_SOC_DAPM_AIF_IN("WSA AIF_MIX1 PB", "WSA_AIF_MIX1 Playback", 0,
  2218. SND_SOC_NOPM, 0, 0),
  2219. SND_SOC_DAPM_AIF_OUT_E("WSA AIF_VI", "WSA_AIF_VI Capture", 0,
  2220. SND_SOC_NOPM, WSA_MACRO_AIF_VI, 0,
  2221. wsa_macro_enable_vi_feedback,
  2222. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2223. SND_SOC_DAPM_AIF_OUT("WSA AIF_ECHO", "WSA_AIF_ECHO Capture", 0,
  2224. SND_SOC_NOPM, 0, 0),
  2225. SND_SOC_DAPM_MIXER("WSA_AIF_VI Mixer", SND_SOC_NOPM, WSA_MACRO_AIF_VI,
  2226. 0, aif_vi_mixer, ARRAY_SIZE(aif_vi_mixer)),
  2227. SND_SOC_DAPM_MUX_E("WSA RX_MIX EC0_MUX", SND_SOC_NOPM,
  2228. WSA_MACRO_EC0_MUX, 0,
  2229. &rx_mix_ec0_mux, wsa_macro_enable_echo,
  2230. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2231. SND_SOC_DAPM_MUX_E("WSA RX_MIX EC1_MUX", SND_SOC_NOPM,
  2232. WSA_MACRO_EC1_MUX, 0,
  2233. &rx_mix_ec1_mux, wsa_macro_enable_echo,
  2234. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2235. SND_SOC_DAPM_MUX("WSA RX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX0, 0,
  2236. &rx_mux[WSA_MACRO_RX0]),
  2237. SND_SOC_DAPM_MUX("WSA RX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX1, 0,
  2238. &rx_mux[WSA_MACRO_RX1]),
  2239. SND_SOC_DAPM_MUX("WSA RX_MIX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX0, 0,
  2240. &rx_mux[WSA_MACRO_RX_MIX0]),
  2241. SND_SOC_DAPM_MUX("WSA RX_MIX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX1, 0,
  2242. &rx_mux[WSA_MACRO_RX_MIX1]),
  2243. SND_SOC_DAPM_MIXER("WSA RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2244. SND_SOC_DAPM_MIXER("WSA RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2245. SND_SOC_DAPM_MIXER("WSA RX_MIX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2246. SND_SOC_DAPM_MIXER("WSA RX_MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2247. SND_SOC_DAPM_MUX_E("WSA_RX0 INP0", SND_SOC_NOPM, 0, 0,
  2248. &rx0_prim_inp0_mux, wsa_macro_enable_swr,
  2249. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2250. SND_SOC_DAPM_MUX_E("WSA_RX0 INP1", SND_SOC_NOPM, 0, 0,
  2251. &rx0_prim_inp1_mux, wsa_macro_enable_swr,
  2252. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2253. SND_SOC_DAPM_MUX_E("WSA_RX0 INP2", SND_SOC_NOPM, 0, 0,
  2254. &rx0_prim_inp2_mux, wsa_macro_enable_swr,
  2255. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2256. SND_SOC_DAPM_MUX_E("WSA_RX0 MIX INP", SND_SOC_NOPM,
  2257. 0, 0, &rx0_mix_mux, wsa_macro_enable_mix_path,
  2258. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2259. SND_SOC_DAPM_MUX_E("WSA_RX1 INP0", SND_SOC_NOPM, 0, 0,
  2260. &rx1_prim_inp0_mux, wsa_macro_enable_swr,
  2261. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2262. SND_SOC_DAPM_MUX_E("WSA_RX1 INP1", SND_SOC_NOPM, 0, 0,
  2263. &rx1_prim_inp1_mux, wsa_macro_enable_swr,
  2264. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2265. SND_SOC_DAPM_MUX_E("WSA_RX1 INP2", SND_SOC_NOPM, 0, 0,
  2266. &rx1_prim_inp2_mux, wsa_macro_enable_swr,
  2267. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2268. SND_SOC_DAPM_MUX_E("WSA_RX1 MIX INP", SND_SOC_NOPM,
  2269. 0, 0, &rx1_mix_mux, wsa_macro_enable_mix_path,
  2270. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2271. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 MIX", SND_SOC_NOPM,
  2272. 0, 0, NULL, 0, wsa_macro_enable_main_path,
  2273. SND_SOC_DAPM_PRE_PMU),
  2274. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 MIX", SND_SOC_NOPM,
  2275. 1, 0, NULL, 0, wsa_macro_enable_main_path,
  2276. SND_SOC_DAPM_PRE_PMU),
  2277. SND_SOC_DAPM_MIXER("WSA_RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2278. SND_SOC_DAPM_MIXER("WSA_RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2279. SND_SOC_DAPM_MUX_E("WSA_RX0 INT0 SIDETONE MIX",
  2280. BOLERO_CDC_WSA_RX0_RX_PATH_CFG1, 4, 0,
  2281. &rx0_sidetone_mix_mux, wsa_macro_enable_swr,
  2282. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2283. SND_SOC_DAPM_INPUT("WSA SRC0_INP"),
  2284. SND_SOC_DAPM_INPUT("WSA_TX DEC0_INP"),
  2285. SND_SOC_DAPM_INPUT("WSA_TX DEC1_INP"),
  2286. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 INTERP", SND_SOC_NOPM,
  2287. WSA_MACRO_COMP1, 0, NULL, 0, wsa_macro_enable_interpolator,
  2288. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2289. SND_SOC_DAPM_POST_PMD),
  2290. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 INTERP", SND_SOC_NOPM,
  2291. WSA_MACRO_COMP2, 0, NULL, 0, wsa_macro_enable_interpolator,
  2292. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2293. SND_SOC_DAPM_POST_PMD),
  2294. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 CHAIN", SND_SOC_NOPM, 0, 0,
  2295. NULL, 0, wsa_macro_spk_boost_event,
  2296. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2297. SND_SOC_DAPM_POST_PMD),
  2298. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 CHAIN", SND_SOC_NOPM, 0, 0,
  2299. NULL, 0, wsa_macro_spk_boost_event,
  2300. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2301. SND_SOC_DAPM_POST_PMD),
  2302. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 VBAT", SND_SOC_NOPM,
  2303. 0, 0, wsa_int0_vbat_mix_switch,
  2304. ARRAY_SIZE(wsa_int0_vbat_mix_switch),
  2305. wsa_macro_enable_vbat,
  2306. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2307. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 VBAT", SND_SOC_NOPM,
  2308. 0, 0, wsa_int1_vbat_mix_switch,
  2309. ARRAY_SIZE(wsa_int1_vbat_mix_switch),
  2310. wsa_macro_enable_vbat,
  2311. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2312. SND_SOC_DAPM_INPUT("VIINPUT_WSA"),
  2313. SND_SOC_DAPM_OUTPUT("WSA_SPK1 OUT"),
  2314. SND_SOC_DAPM_OUTPUT("WSA_SPK2 OUT"),
  2315. SND_SOC_DAPM_SUPPLY_S("WSA_MCLK", 0, SND_SOC_NOPM, 0, 0,
  2316. wsa_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2317. };
  2318. static const struct snd_soc_dapm_route wsa_audio_map[] = {
  2319. /* VI Feedback */
  2320. {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_1", "VIINPUT_WSA"},
  2321. {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_2", "VIINPUT_WSA"},
  2322. {"WSA AIF_VI", NULL, "WSA_AIF_VI Mixer"},
  2323. {"WSA AIF_VI", NULL, "WSA_MCLK"},
  2324. {"WSA RX_MIX EC0_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
  2325. {"WSA RX_MIX EC1_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
  2326. {"WSA RX_MIX EC0_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
  2327. {"WSA RX_MIX EC1_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
  2328. {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC0_MUX"},
  2329. {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC1_MUX"},
  2330. {"WSA AIF_ECHO", NULL, "WSA_MCLK"},
  2331. {"WSA AIF1 PB", NULL, "WSA_MCLK"},
  2332. {"WSA AIF_MIX1 PB", NULL, "WSA_MCLK"},
  2333. {"WSA RX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2334. {"WSA RX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2335. {"WSA RX_MIX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2336. {"WSA RX_MIX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
  2337. {"WSA RX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2338. {"WSA RX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2339. {"WSA RX_MIX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2340. {"WSA RX_MIX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  2341. {"WSA RX0", NULL, "WSA RX0 MUX"},
  2342. {"WSA RX1", NULL, "WSA RX1 MUX"},
  2343. {"WSA RX_MIX0", NULL, "WSA RX_MIX0 MUX"},
  2344. {"WSA RX_MIX1", NULL, "WSA RX_MIX1 MUX"},
  2345. {"WSA_RX0 INP0", "RX0", "WSA RX0"},
  2346. {"WSA_RX0 INP0", "RX1", "WSA RX1"},
  2347. {"WSA_RX0 INP0", "RX_MIX0", "WSA RX_MIX0"},
  2348. {"WSA_RX0 INP0", "RX_MIX1", "WSA RX_MIX1"},
  2349. {"WSA_RX0 INP0", "DEC0", "WSA_TX DEC0_INP"},
  2350. {"WSA_RX0 INP0", "DEC1", "WSA_TX DEC1_INP"},
  2351. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP0"},
  2352. {"WSA_RX0 INP1", "RX0", "WSA RX0"},
  2353. {"WSA_RX0 INP1", "RX1", "WSA RX1"},
  2354. {"WSA_RX0 INP1", "RX_MIX0", "WSA RX_MIX0"},
  2355. {"WSA_RX0 INP1", "RX_MIX1", "WSA RX_MIX1"},
  2356. {"WSA_RX0 INP1", "DEC0", "WSA_TX DEC0_INP"},
  2357. {"WSA_RX0 INP1", "DEC1", "WSA_TX DEC1_INP"},
  2358. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP1"},
  2359. {"WSA_RX0 INP2", "RX0", "WSA RX0"},
  2360. {"WSA_RX0 INP2", "RX1", "WSA RX1"},
  2361. {"WSA_RX0 INP2", "RX_MIX0", "WSA RX_MIX0"},
  2362. {"WSA_RX0 INP2", "RX_MIX1", "WSA RX_MIX1"},
  2363. {"WSA_RX0 INP2", "DEC0", "WSA_TX DEC0_INP"},
  2364. {"WSA_RX0 INP2", "DEC1", "WSA_TX DEC1_INP"},
  2365. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP2"},
  2366. {"WSA_RX0 MIX INP", "RX0", "WSA RX0"},
  2367. {"WSA_RX0 MIX INP", "RX1", "WSA RX1"},
  2368. {"WSA_RX0 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
  2369. {"WSA_RX0 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
  2370. {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX0 MIX INP"},
  2371. {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX INT0 MIX"},
  2372. {"WSA_RX INT0 INTERP", NULL, "WSA_RX INT0 SEC MIX"},
  2373. {"WSA_RX0 INT0 SIDETONE MIX", "SRC0", "WSA SRC0_INP"},
  2374. {"WSA_RX INT0 INTERP", NULL, "WSA_RX0 INT0 SIDETONE MIX"},
  2375. {"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 INTERP"},
  2376. {"WSA_RX INT0 VBAT", "WSA RX0 VBAT Enable", "WSA_RX INT0 INTERP"},
  2377. {"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 VBAT"},
  2378. {"WSA_SPK1 OUT", NULL, "WSA_RX INT0 CHAIN"},
  2379. {"WSA_SPK1 OUT", NULL, "WSA_MCLK"},
  2380. {"WSA_RX1 INP0", "RX0", "WSA RX0"},
  2381. {"WSA_RX1 INP0", "RX1", "WSA RX1"},
  2382. {"WSA_RX1 INP0", "RX_MIX0", "WSA RX_MIX0"},
  2383. {"WSA_RX1 INP0", "RX_MIX1", "WSA RX_MIX1"},
  2384. {"WSA_RX1 INP0", "DEC0", "WSA_TX DEC0_INP"},
  2385. {"WSA_RX1 INP0", "DEC1", "WSA_TX DEC1_INP"},
  2386. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP0"},
  2387. {"WSA_RX1 INP1", "RX0", "WSA RX0"},
  2388. {"WSA_RX1 INP1", "RX1", "WSA RX1"},
  2389. {"WSA_RX1 INP1", "RX_MIX0", "WSA RX_MIX0"},
  2390. {"WSA_RX1 INP1", "RX_MIX1", "WSA RX_MIX1"},
  2391. {"WSA_RX1 INP1", "DEC0", "WSA_TX DEC0_INP"},
  2392. {"WSA_RX1 INP1", "DEC1", "WSA_TX DEC1_INP"},
  2393. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP1"},
  2394. {"WSA_RX1 INP2", "RX0", "WSA RX0"},
  2395. {"WSA_RX1 INP2", "RX1", "WSA RX1"},
  2396. {"WSA_RX1 INP2", "RX_MIX0", "WSA RX_MIX0"},
  2397. {"WSA_RX1 INP2", "RX_MIX1", "WSA RX_MIX1"},
  2398. {"WSA_RX1 INP2", "DEC0", "WSA_TX DEC0_INP"},
  2399. {"WSA_RX1 INP2", "DEC1", "WSA_TX DEC1_INP"},
  2400. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP2"},
  2401. {"WSA_RX1 MIX INP", "RX0", "WSA RX0"},
  2402. {"WSA_RX1 MIX INP", "RX1", "WSA RX1"},
  2403. {"WSA_RX1 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
  2404. {"WSA_RX1 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
  2405. {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX1 MIX INP"},
  2406. {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX INT1 MIX"},
  2407. {"WSA_RX INT1 INTERP", NULL, "WSA_RX INT1 SEC MIX"},
  2408. {"WSA_RX INT1 VBAT", "WSA RX1 VBAT Enable", "WSA_RX INT1 INTERP"},
  2409. {"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 VBAT"},
  2410. {"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 INTERP"},
  2411. {"WSA_SPK2 OUT", NULL, "WSA_RX INT1 CHAIN"},
  2412. {"WSA_SPK2 OUT", NULL, "WSA_MCLK"},
  2413. };
  2414. static const struct wsa_macro_reg_mask_val wsa_macro_reg_init[] = {
  2415. {BOLERO_CDC_WSA_BOOST0_BOOST_CFG1, 0x3F, 0x12},
  2416. {BOLERO_CDC_WSA_BOOST0_BOOST_CFG2, 0x1C, 0x08},
  2417. {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x1E, 0x0C},
  2418. {BOLERO_CDC_WSA_BOOST1_BOOST_CFG1, 0x3F, 0x12},
  2419. {BOLERO_CDC_WSA_BOOST1_BOOST_CFG2, 0x1C, 0x08},
  2420. {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x1E, 0x0C},
  2421. {BOLERO_CDC_WSA_BOOST0_BOOST_CTL, 0x70, 0x58},
  2422. {BOLERO_CDC_WSA_BOOST1_BOOST_CTL, 0x70, 0x58},
  2423. {BOLERO_CDC_WSA_RX0_RX_PATH_CFG1, 0x08, 0x08},
  2424. {BOLERO_CDC_WSA_RX1_RX_PATH_CFG1, 0x08, 0x08},
  2425. {BOLERO_CDC_WSA_TOP_TOP_CFG1, 0x02, 0x02},
  2426. {BOLERO_CDC_WSA_TOP_TOP_CFG1, 0x01, 0x01},
  2427. {BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2428. {BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2429. {BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2430. {BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  2431. {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01},
  2432. {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x01},
  2433. {BOLERO_CDC_WSA_RX0_RX_PATH_CFG0, 0x01, 0x01},
  2434. {BOLERO_CDC_WSA_RX1_RX_PATH_CFG0, 0x01, 0x01},
  2435. {BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CFG, 0x01, 0x01},
  2436. {BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CFG, 0x01, 0x01},
  2437. };
  2438. static void wsa_macro_init_bcl_pmic_reg(struct snd_soc_component *component)
  2439. {
  2440. struct device *wsa_dev = NULL;
  2441. struct wsa_macro_priv *wsa_priv = NULL;
  2442. if (!component) {
  2443. pr_err("%s: NULL component pointer!\n", __func__);
  2444. return;
  2445. }
  2446. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2447. return;
  2448. switch (wsa_priv->bcl_pmic_params.id) {
  2449. case 0:
  2450. /* Enable ID0 to listen to respective PMIC group interrupts */
  2451. snd_soc_component_update_bits(component,
  2452. BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CTL1, 0x02, 0x02);
  2453. /* Update MC_SID0 */
  2454. snd_soc_component_update_bits(component,
  2455. BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG1, 0x0F,
  2456. wsa_priv->bcl_pmic_params.sid);
  2457. /* Update MC_PPID0 */
  2458. snd_soc_component_update_bits(component,
  2459. BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG2, 0xFF,
  2460. wsa_priv->bcl_pmic_params.ppid);
  2461. break;
  2462. case 1:
  2463. /* Enable ID1 to listen to respective PMIC group interrupts */
  2464. snd_soc_component_update_bits(component,
  2465. BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CTL1, 0x01, 0x01);
  2466. /* Update MC_SID1 */
  2467. snd_soc_component_update_bits(component,
  2468. BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG3, 0x0F,
  2469. wsa_priv->bcl_pmic_params.sid);
  2470. /* Update MC_PPID1 */
  2471. snd_soc_component_update_bits(component,
  2472. BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG4, 0xFF,
  2473. wsa_priv->bcl_pmic_params.ppid);
  2474. break;
  2475. default:
  2476. dev_err(wsa_dev, "%s: PMIC ID is invalid %d\n",
  2477. __func__, wsa_priv->bcl_pmic_params.id);
  2478. break;
  2479. }
  2480. }
  2481. static void wsa_macro_init_reg(struct snd_soc_component *component)
  2482. {
  2483. int i;
  2484. for (i = 0; i < ARRAY_SIZE(wsa_macro_reg_init); i++)
  2485. snd_soc_component_update_bits(component,
  2486. wsa_macro_reg_init[i].reg,
  2487. wsa_macro_reg_init[i].mask,
  2488. wsa_macro_reg_init[i].val);
  2489. wsa_macro_init_bcl_pmic_reg(component);
  2490. }
  2491. static int wsa_macro_core_vote(void *handle, bool enable)
  2492. {
  2493. struct wsa_macro_priv *wsa_priv = (struct wsa_macro_priv *) handle;
  2494. if (wsa_priv == NULL) {
  2495. pr_err("%s: wsa priv data is NULL\n", __func__);
  2496. return -EINVAL;
  2497. }
  2498. if (enable) {
  2499. pm_runtime_get_sync(wsa_priv->dev);
  2500. pm_runtime_put_autosuspend(wsa_priv->dev);
  2501. pm_runtime_mark_last_busy(wsa_priv->dev);
  2502. }
  2503. if (bolero_check_core_votes(wsa_priv->dev))
  2504. return 0;
  2505. else
  2506. return -EINVAL;
  2507. }
  2508. static int wsa_swrm_clock(void *handle, bool enable)
  2509. {
  2510. struct wsa_macro_priv *wsa_priv = (struct wsa_macro_priv *) handle;
  2511. struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
  2512. int ret = 0;
  2513. if (regmap == NULL) {
  2514. dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
  2515. return -EINVAL;
  2516. }
  2517. mutex_lock(&wsa_priv->swr_clk_lock);
  2518. trace_printk("%s: %s swrm clock %s\n",
  2519. dev_name(wsa_priv->dev), __func__,
  2520. (enable ? "enable" : "disable"));
  2521. dev_dbg(wsa_priv->dev, "%s: swrm clock %s\n",
  2522. __func__, (enable ? "enable" : "disable"));
  2523. if (enable) {
  2524. pm_runtime_get_sync(wsa_priv->dev);
  2525. if (wsa_priv->swr_clk_users == 0) {
  2526. ret = msm_cdc_pinctrl_select_active_state(
  2527. wsa_priv->wsa_swr_gpio_p);
  2528. if (ret < 0) {
  2529. dev_err_ratelimited(wsa_priv->dev,
  2530. "%s: wsa swr pinctrl enable failed\n",
  2531. __func__);
  2532. pm_runtime_mark_last_busy(wsa_priv->dev);
  2533. pm_runtime_put_autosuspend(wsa_priv->dev);
  2534. goto exit;
  2535. }
  2536. ret = wsa_macro_mclk_enable(wsa_priv, 1, true);
  2537. if (ret < 0) {
  2538. msm_cdc_pinctrl_select_sleep_state(
  2539. wsa_priv->wsa_swr_gpio_p);
  2540. dev_err_ratelimited(wsa_priv->dev,
  2541. "%s: wsa request clock enable failed\n",
  2542. __func__);
  2543. pm_runtime_mark_last_busy(wsa_priv->dev);
  2544. pm_runtime_put_autosuspend(wsa_priv->dev);
  2545. goto exit;
  2546. }
  2547. if (wsa_priv->reset_swr)
  2548. regmap_update_bits(regmap,
  2549. BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2550. 0x02, 0x02);
  2551. regmap_update_bits(regmap,
  2552. BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2553. 0x01, 0x01);
  2554. if (wsa_priv->reset_swr)
  2555. regmap_update_bits(regmap,
  2556. BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2557. 0x02, 0x00);
  2558. wsa_priv->reset_swr = false;
  2559. }
  2560. wsa_priv->swr_clk_users++;
  2561. pm_runtime_mark_last_busy(wsa_priv->dev);
  2562. pm_runtime_put_autosuspend(wsa_priv->dev);
  2563. } else {
  2564. if (wsa_priv->swr_clk_users <= 0) {
  2565. dev_err(wsa_priv->dev, "%s: clock already disabled\n",
  2566. __func__);
  2567. wsa_priv->swr_clk_users = 0;
  2568. goto exit;
  2569. }
  2570. wsa_priv->swr_clk_users--;
  2571. if (wsa_priv->swr_clk_users == 0) {
  2572. regmap_update_bits(regmap,
  2573. BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  2574. 0x01, 0x00);
  2575. wsa_macro_mclk_enable(wsa_priv, 0, true);
  2576. ret = msm_cdc_pinctrl_select_sleep_state(
  2577. wsa_priv->wsa_swr_gpio_p);
  2578. if (ret < 0) {
  2579. dev_err_ratelimited(wsa_priv->dev,
  2580. "%s: wsa swr pinctrl disable failed\n",
  2581. __func__);
  2582. goto exit;
  2583. }
  2584. }
  2585. }
  2586. trace_printk("%s: %s swrm clock users: %d\n",
  2587. dev_name(wsa_priv->dev), __func__,
  2588. wsa_priv->swr_clk_users);
  2589. dev_dbg(wsa_priv->dev, "%s: swrm clock users %d\n",
  2590. __func__, wsa_priv->swr_clk_users);
  2591. exit:
  2592. mutex_unlock(&wsa_priv->swr_clk_lock);
  2593. return ret;
  2594. }
  2595. static int wsa_macro_init(struct snd_soc_component *component)
  2596. {
  2597. struct snd_soc_dapm_context *dapm =
  2598. snd_soc_component_get_dapm(component);
  2599. int ret;
  2600. struct device *wsa_dev = NULL;
  2601. struct wsa_macro_priv *wsa_priv = NULL;
  2602. wsa_dev = bolero_get_device_ptr(component->dev, WSA_MACRO);
  2603. if (!wsa_dev) {
  2604. dev_err(component->dev,
  2605. "%s: null device for macro!\n", __func__);
  2606. return -EINVAL;
  2607. }
  2608. wsa_priv = dev_get_drvdata(wsa_dev);
  2609. if (!wsa_priv) {
  2610. dev_err(component->dev,
  2611. "%s: priv is null for macro!\n", __func__);
  2612. return -EINVAL;
  2613. }
  2614. ret = snd_soc_dapm_new_controls(dapm, wsa_macro_dapm_widgets,
  2615. ARRAY_SIZE(wsa_macro_dapm_widgets));
  2616. if (ret < 0) {
  2617. dev_err(wsa_dev, "%s: Failed to add controls\n", __func__);
  2618. return ret;
  2619. }
  2620. ret = snd_soc_dapm_add_routes(dapm, wsa_audio_map,
  2621. ARRAY_SIZE(wsa_audio_map));
  2622. if (ret < 0) {
  2623. dev_err(wsa_dev, "%s: Failed to add routes\n", __func__);
  2624. return ret;
  2625. }
  2626. ret = snd_soc_dapm_new_widgets(dapm->card);
  2627. if (ret < 0) {
  2628. dev_err(wsa_dev, "%s: Failed to add widgets\n", __func__);
  2629. return ret;
  2630. }
  2631. ret = snd_soc_add_component_controls(component, wsa_macro_snd_controls,
  2632. ARRAY_SIZE(wsa_macro_snd_controls));
  2633. if (ret < 0) {
  2634. dev_err(wsa_dev, "%s: Failed to add snd_ctls\n", __func__);
  2635. return ret;
  2636. }
  2637. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF1 Playback");
  2638. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_MIX1 Playback");
  2639. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_VI Capture");
  2640. snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_ECHO Capture");
  2641. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
  2642. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
  2643. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
  2644. snd_soc_dapm_ignore_suspend(dapm, "WSA SRC0_INP");
  2645. snd_soc_dapm_ignore_suspend(dapm, "WSA_TX DEC0_INP");
  2646. snd_soc_dapm_ignore_suspend(dapm, "WSA_TX DEC1_INP");
  2647. snd_soc_dapm_sync(dapm);
  2648. wsa_priv->component = component;
  2649. wsa_priv->spkr_gain_offset = WSA_MACRO_GAIN_OFFSET_0_DB;
  2650. wsa_macro_init_reg(component);
  2651. return 0;
  2652. }
  2653. static int wsa_macro_deinit(struct snd_soc_component *component)
  2654. {
  2655. struct device *wsa_dev = NULL;
  2656. struct wsa_macro_priv *wsa_priv = NULL;
  2657. if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
  2658. return -EINVAL;
  2659. wsa_priv->component = NULL;
  2660. return 0;
  2661. }
  2662. static void wsa_macro_add_child_devices(struct work_struct *work)
  2663. {
  2664. struct wsa_macro_priv *wsa_priv;
  2665. struct platform_device *pdev;
  2666. struct device_node *node;
  2667. struct wsa_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp;
  2668. int ret;
  2669. u16 count = 0, ctrl_num = 0;
  2670. struct wsa_macro_swr_ctrl_platform_data *platdata;
  2671. char plat_dev_name[WSA_MACRO_SWR_STRING_LEN];
  2672. wsa_priv = container_of(work, struct wsa_macro_priv,
  2673. wsa_macro_add_child_devices_work);
  2674. if (!wsa_priv) {
  2675. pr_err("%s: Memory for wsa_priv does not exist\n",
  2676. __func__);
  2677. return;
  2678. }
  2679. if (!wsa_priv->dev || !wsa_priv->dev->of_node) {
  2680. dev_err(wsa_priv->dev,
  2681. "%s: DT node for wsa_priv does not exist\n", __func__);
  2682. return;
  2683. }
  2684. platdata = &wsa_priv->swr_plat_data;
  2685. wsa_priv->child_count = 0;
  2686. for_each_available_child_of_node(wsa_priv->dev->of_node, node) {
  2687. if (strnstr(node->name, "wsa_swr_master",
  2688. strlen("wsa_swr_master")) != NULL)
  2689. strlcpy(plat_dev_name, "wsa_swr_ctrl",
  2690. (WSA_MACRO_SWR_STRING_LEN - 1));
  2691. else if (strnstr(node->name, "msm_cdc_pinctrl",
  2692. strlen("msm_cdc_pinctrl")) != NULL)
  2693. strlcpy(plat_dev_name, node->name,
  2694. (WSA_MACRO_SWR_STRING_LEN - 1));
  2695. else
  2696. continue;
  2697. pdev = platform_device_alloc(plat_dev_name, -1);
  2698. if (!pdev) {
  2699. dev_err(wsa_priv->dev, "%s: pdev memory alloc failed\n",
  2700. __func__);
  2701. ret = -ENOMEM;
  2702. goto err;
  2703. }
  2704. pdev->dev.parent = wsa_priv->dev;
  2705. pdev->dev.of_node = node;
  2706. if (strnstr(node->name, "wsa_swr_master",
  2707. strlen("wsa_swr_master")) != NULL) {
  2708. ret = platform_device_add_data(pdev, platdata,
  2709. sizeof(*platdata));
  2710. if (ret) {
  2711. dev_err(&pdev->dev,
  2712. "%s: cannot add plat data ctrl:%d\n",
  2713. __func__, ctrl_num);
  2714. goto fail_pdev_add;
  2715. }
  2716. }
  2717. ret = platform_device_add(pdev);
  2718. if (ret) {
  2719. dev_err(&pdev->dev,
  2720. "%s: Cannot add platform device\n",
  2721. __func__);
  2722. goto fail_pdev_add;
  2723. }
  2724. if (!strcmp(node->name, "wsa_swr_master")) {
  2725. temp = krealloc(swr_ctrl_data,
  2726. (ctrl_num + 1) * sizeof(
  2727. struct wsa_macro_swr_ctrl_data),
  2728. GFP_KERNEL);
  2729. if (!temp) {
  2730. dev_err(&pdev->dev, "out of memory\n");
  2731. ret = -ENOMEM;
  2732. goto err;
  2733. }
  2734. swr_ctrl_data = temp;
  2735. swr_ctrl_data[ctrl_num].wsa_swr_pdev = pdev;
  2736. ctrl_num++;
  2737. dev_dbg(&pdev->dev,
  2738. "%s: Added soundwire ctrl device(s)\n",
  2739. __func__);
  2740. wsa_priv->swr_ctrl_data = swr_ctrl_data;
  2741. }
  2742. if (wsa_priv->child_count < WSA_MACRO_CHILD_DEVICES_MAX)
  2743. wsa_priv->pdev_child_devices[
  2744. wsa_priv->child_count++] = pdev;
  2745. else
  2746. goto err;
  2747. }
  2748. return;
  2749. fail_pdev_add:
  2750. for (count = 0; count < wsa_priv->child_count; count++)
  2751. platform_device_put(wsa_priv->pdev_child_devices[count]);
  2752. err:
  2753. return;
  2754. }
  2755. static void wsa_macro_init_ops(struct macro_ops *ops,
  2756. char __iomem *wsa_io_base)
  2757. {
  2758. memset(ops, 0, sizeof(struct macro_ops));
  2759. ops->init = wsa_macro_init;
  2760. ops->exit = wsa_macro_deinit;
  2761. ops->io_base = wsa_io_base;
  2762. ops->dai_ptr = wsa_macro_dai;
  2763. ops->num_dais = ARRAY_SIZE(wsa_macro_dai);
  2764. ops->event_handler = wsa_macro_event_handler;
  2765. ops->set_port_map = wsa_macro_set_port_map;
  2766. }
  2767. static int wsa_macro_probe(struct platform_device *pdev)
  2768. {
  2769. struct macro_ops ops;
  2770. struct wsa_macro_priv *wsa_priv;
  2771. u32 wsa_base_addr, default_clk_id;
  2772. char __iomem *wsa_io_base;
  2773. int ret = 0;
  2774. u8 bcl_pmic_params[3];
  2775. u32 is_used_wsa_swr_gpio = 1;
  2776. const char *is_used_wsa_swr_gpio_dt = "qcom,is-used-swr-gpio";
  2777. wsa_priv = devm_kzalloc(&pdev->dev, sizeof(struct wsa_macro_priv),
  2778. GFP_KERNEL);
  2779. if (!wsa_priv)
  2780. return -ENOMEM;
  2781. wsa_priv->dev = &pdev->dev;
  2782. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2783. &wsa_base_addr);
  2784. if (ret) {
  2785. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2786. __func__, "reg");
  2787. return ret;
  2788. }
  2789. if (of_find_property(pdev->dev.of_node, is_used_wsa_swr_gpio_dt,
  2790. NULL)) {
  2791. ret = of_property_read_u32(pdev->dev.of_node,
  2792. is_used_wsa_swr_gpio_dt,
  2793. &is_used_wsa_swr_gpio);
  2794. if (ret) {
  2795. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  2796. __func__, is_used_wsa_swr_gpio_dt);
  2797. is_used_wsa_swr_gpio = 1;
  2798. }
  2799. }
  2800. wsa_priv->wsa_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2801. "qcom,wsa-swr-gpios", 0);
  2802. if (!wsa_priv->wsa_swr_gpio_p && is_used_wsa_swr_gpio) {
  2803. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2804. __func__);
  2805. return -EINVAL;
  2806. }
  2807. if (msm_cdc_pinctrl_get_state(wsa_priv->wsa_swr_gpio_p) < 0 &&
  2808. is_used_wsa_swr_gpio) {
  2809. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  2810. __func__);
  2811. return -EPROBE_DEFER;
  2812. }
  2813. msm_cdc_pinctrl_set_wakeup_capable(
  2814. wsa_priv->wsa_swr_gpio_p, false);
  2815. wsa_io_base = devm_ioremap(&pdev->dev,
  2816. wsa_base_addr, WSA_MACRO_MAX_OFFSET);
  2817. if (!wsa_io_base) {
  2818. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2819. return -EINVAL;
  2820. }
  2821. wsa_priv->wsa_io_base = wsa_io_base;
  2822. wsa_priv->reset_swr = true;
  2823. INIT_WORK(&wsa_priv->wsa_macro_add_child_devices_work,
  2824. wsa_macro_add_child_devices);
  2825. wsa_priv->swr_plat_data.handle = (void *) wsa_priv;
  2826. wsa_priv->swr_plat_data.read = NULL;
  2827. wsa_priv->swr_plat_data.write = NULL;
  2828. wsa_priv->swr_plat_data.bulk_write = NULL;
  2829. wsa_priv->swr_plat_data.clk = wsa_swrm_clock;
  2830. wsa_priv->swr_plat_data.core_vote = wsa_macro_core_vote;
  2831. wsa_priv->swr_plat_data.handle_irq = NULL;
  2832. ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
  2833. &default_clk_id);
  2834. if (ret) {
  2835. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2836. __func__, "qcom,mux0-clk-id");
  2837. default_clk_id = WSA_CORE_CLK;
  2838. }
  2839. ret = of_property_read_u8_array(pdev->dev.of_node,
  2840. "qcom,wsa-bcl-pmic-params", bcl_pmic_params,
  2841. sizeof(bcl_pmic_params));
  2842. if (ret) {
  2843. dev_dbg(&pdev->dev, "%s: could not find %s entry in dt\n",
  2844. __func__, "qcom,wsa-bcl-pmic-params");
  2845. } else {
  2846. wsa_priv->bcl_pmic_params.id = bcl_pmic_params[0];
  2847. wsa_priv->bcl_pmic_params.sid = bcl_pmic_params[1];
  2848. wsa_priv->bcl_pmic_params.ppid = bcl_pmic_params[2];
  2849. }
  2850. wsa_priv->default_clk_id = default_clk_id;
  2851. dev_set_drvdata(&pdev->dev, wsa_priv);
  2852. mutex_init(&wsa_priv->mclk_lock);
  2853. mutex_init(&wsa_priv->swr_clk_lock);
  2854. wsa_macro_init_ops(&ops, wsa_io_base);
  2855. ops.clk_id_req = wsa_priv->default_clk_id;
  2856. ops.default_clk_id = wsa_priv->default_clk_id;
  2857. ret = bolero_register_macro(&pdev->dev, WSA_MACRO, &ops);
  2858. if (ret < 0) {
  2859. dev_err(&pdev->dev, "%s: register macro failed\n", __func__);
  2860. goto reg_macro_fail;
  2861. }
  2862. schedule_work(&wsa_priv->wsa_macro_add_child_devices_work);
  2863. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  2864. pm_runtime_use_autosuspend(&pdev->dev);
  2865. pm_runtime_set_suspended(&pdev->dev);
  2866. pm_suspend_ignore_children(&pdev->dev, true);
  2867. pm_runtime_enable(&pdev->dev);
  2868. return ret;
  2869. reg_macro_fail:
  2870. mutex_destroy(&wsa_priv->mclk_lock);
  2871. mutex_destroy(&wsa_priv->swr_clk_lock);
  2872. return ret;
  2873. }
  2874. static int wsa_macro_remove(struct platform_device *pdev)
  2875. {
  2876. struct wsa_macro_priv *wsa_priv;
  2877. u16 count = 0;
  2878. wsa_priv = dev_get_drvdata(&pdev->dev);
  2879. if (!wsa_priv)
  2880. return -EINVAL;
  2881. for (count = 0; count < wsa_priv->child_count &&
  2882. count < WSA_MACRO_CHILD_DEVICES_MAX; count++)
  2883. platform_device_unregister(wsa_priv->pdev_child_devices[count]);
  2884. pm_runtime_disable(&pdev->dev);
  2885. pm_runtime_set_suspended(&pdev->dev);
  2886. bolero_unregister_macro(&pdev->dev, WSA_MACRO);
  2887. mutex_destroy(&wsa_priv->mclk_lock);
  2888. mutex_destroy(&wsa_priv->swr_clk_lock);
  2889. return 0;
  2890. }
  2891. static const struct of_device_id wsa_macro_dt_match[] = {
  2892. {.compatible = "qcom,wsa-macro"},
  2893. {}
  2894. };
  2895. static const struct dev_pm_ops bolero_dev_pm_ops = {
  2896. SET_SYSTEM_SLEEP_PM_OPS(
  2897. pm_runtime_force_suspend,
  2898. pm_runtime_force_resume
  2899. )
  2900. SET_RUNTIME_PM_OPS(
  2901. bolero_runtime_suspend,
  2902. bolero_runtime_resume,
  2903. NULL
  2904. )
  2905. };
  2906. static struct platform_driver wsa_macro_driver = {
  2907. .driver = {
  2908. .name = "wsa_macro",
  2909. .owner = THIS_MODULE,
  2910. .pm = &bolero_dev_pm_ops,
  2911. .of_match_table = wsa_macro_dt_match,
  2912. .suppress_bind_attrs = true,
  2913. },
  2914. .probe = wsa_macro_probe,
  2915. .remove = wsa_macro_remove,
  2916. };
  2917. module_platform_driver(wsa_macro_driver);
  2918. MODULE_DESCRIPTION("WSA macro driver");
  2919. MODULE_LICENSE("GPL v2");