lpass-cdc-wsa2-macro.c 97 KB

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