wsa-macro.c 97 KB

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