wsa-macro.c 97 KB

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