wsa-macro.c 97 KB

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