wsa-macro.c 99 KB

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