wsa-macro.c 96 KB

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