wsa-macro.c 96 KB

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