wsa-macro.c 89 KB

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