va-macro.c 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286
  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/bitops.h>
  7. #include <linux/clk.h>
  8. #include <linux/io.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regmap.h>
  11. #include <linux/regulator/consumer.h>
  12. #include <sound/soc.h>
  13. #include <sound/soc-dapm.h>
  14. #include <sound/tlv.h>
  15. #include <linux/pm_runtime.h>
  16. #include <asoc/msm-cdc-pinctrl.h>
  17. #include <soc/swr-common.h>
  18. #include <soc/swr-wcd.h>
  19. #include <dsp/digital-cdc-rsc-mgr.h>
  20. #include "bolero-cdc.h"
  21. #include "bolero-cdc-registers.h"
  22. #include "bolero-clk-rsc.h"
  23. /* pm runtime auto suspend timer in msecs */
  24. #define VA_AUTO_SUSPEND_DELAY 100 /* delay in msec */
  25. #define VA_MACRO_MAX_OFFSET 0x1000
  26. #define VA_MACRO_NUM_DECIMATORS 8
  27. #define VA_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  28. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  29. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  30. #define VA_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  31. SNDRV_PCM_FMTBIT_S24_LE |\
  32. SNDRV_PCM_FMTBIT_S24_3LE)
  33. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  34. #define CF_MIN_3DB_4HZ 0x0
  35. #define CF_MIN_3DB_75HZ 0x1
  36. #define CF_MIN_3DB_150HZ 0x2
  37. #define VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0
  38. #define VA_MACRO_MCLK_FREQ 9600000
  39. #define VA_MACRO_TX_PATH_OFFSET 0x80
  40. #define VA_MACRO_TX_DMIC_CLK_DIV_MASK 0x0E
  41. #define VA_MACRO_TX_DMIC_CLK_DIV_SHFT 0x01
  42. #define VA_MACRO_SWR_MIC_MUX_SEL_MASK 0xF
  43. #define VA_MACRO_ADC_MUX_CFG_OFFSET 0x8
  44. #define VA_MACRO_ADC_MODE_CFG0_SHIFT 1
  45. #define BOLERO_CDC_VA_TX_DMIC_UNMUTE_DELAY_MS 40
  46. #define BOLERO_CDC_VA_TX_AMIC_UNMUTE_DELAY_MS 100
  47. #define BOLERO_CDC_VA_TX_DMIC_HPF_DELAY_MS 300
  48. #define BOLERO_CDC_VA_TX_AMIC_HPF_DELAY_MS 300
  49. #define MAX_RETRY_ATTEMPTS 500
  50. #define VA_MACRO_SWR_STRING_LEN 80
  51. #define VA_MACRO_CHILD_DEVICES_MAX 3
  52. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  53. static int va_tx_unmute_delay = BOLERO_CDC_VA_TX_DMIC_UNMUTE_DELAY_MS;
  54. module_param(va_tx_unmute_delay, int, 0664);
  55. MODULE_PARM_DESC(va_tx_unmute_delay, "delay to unmute the tx path");
  56. static int va_macro_core_vote(void *handle, bool enable);
  57. enum {
  58. VA_MACRO_AIF_INVALID = 0,
  59. VA_MACRO_AIF1_CAP,
  60. VA_MACRO_AIF2_CAP,
  61. VA_MACRO_AIF3_CAP,
  62. VA_MACRO_MAX_DAIS,
  63. };
  64. enum {
  65. VA_MACRO_DEC0,
  66. VA_MACRO_DEC1,
  67. VA_MACRO_DEC2,
  68. VA_MACRO_DEC3,
  69. VA_MACRO_DEC4,
  70. VA_MACRO_DEC5,
  71. VA_MACRO_DEC6,
  72. VA_MACRO_DEC7,
  73. VA_MACRO_DEC_MAX,
  74. };
  75. enum {
  76. VA_MACRO_CLK_DIV_2,
  77. VA_MACRO_CLK_DIV_3,
  78. VA_MACRO_CLK_DIV_4,
  79. VA_MACRO_CLK_DIV_6,
  80. VA_MACRO_CLK_DIV_8,
  81. VA_MACRO_CLK_DIV_16,
  82. };
  83. enum {
  84. MSM_DMIC,
  85. SWR_MIC,
  86. };
  87. enum {
  88. TX_MCLK,
  89. VA_MCLK,
  90. };
  91. struct va_mute_work {
  92. struct va_macro_priv *va_priv;
  93. u32 decimator;
  94. struct delayed_work dwork;
  95. };
  96. struct hpf_work {
  97. struct va_macro_priv *va_priv;
  98. u8 decimator;
  99. u8 hpf_cut_off_freq;
  100. struct delayed_work dwork;
  101. };
  102. /* Hold instance to soundwire platform device */
  103. struct va_macro_swr_ctrl_data {
  104. struct platform_device *va_swr_pdev;
  105. };
  106. struct va_macro_swr_ctrl_platform_data {
  107. void *handle; /* holds codec private data */
  108. int (*read)(void *handle, int reg);
  109. int (*write)(void *handle, int reg, int val);
  110. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  111. int (*clk)(void *handle, bool enable);
  112. int (*core_vote)(void *handle, bool enable);
  113. int (*handle_irq)(void *handle,
  114. irqreturn_t (*swrm_irq_handler)(int irq,
  115. void *data),
  116. void *swrm_handle,
  117. int action);
  118. };
  119. struct va_macro_priv {
  120. struct device *dev;
  121. bool dec_active[VA_MACRO_NUM_DECIMATORS];
  122. bool va_without_decimation;
  123. struct clk *lpass_audio_hw_vote;
  124. struct mutex mclk_lock;
  125. struct mutex swr_clk_lock;
  126. struct snd_soc_component *component;
  127. struct hpf_work va_hpf_work[VA_MACRO_NUM_DECIMATORS];
  128. struct va_mute_work va_mute_dwork[VA_MACRO_NUM_DECIMATORS];
  129. unsigned long active_ch_mask[VA_MACRO_MAX_DAIS];
  130. u16 dmic_clk_div;
  131. u16 va_mclk_users;
  132. int swr_clk_users;
  133. bool reset_swr;
  134. struct device_node *va_swr_gpio_p;
  135. struct va_macro_swr_ctrl_data *swr_ctrl_data;
  136. struct va_macro_swr_ctrl_platform_data swr_plat_data;
  137. struct work_struct va_macro_add_child_devices_work;
  138. int child_count;
  139. u16 mclk_mux_sel;
  140. char __iomem *va_io_base;
  141. char __iomem *va_island_mode_muxsel;
  142. struct platform_device *pdev_child_devices
  143. [VA_MACRO_CHILD_DEVICES_MAX];
  144. struct regulator *micb_supply;
  145. u32 micb_voltage;
  146. u32 micb_current;
  147. u32 version;
  148. u32 is_used_va_swr_gpio;
  149. int micb_users;
  150. u16 default_clk_id;
  151. u16 clk_id;
  152. int tx_swr_clk_cnt;
  153. int va_swr_clk_cnt;
  154. int va_clk_status;
  155. int tx_clk_status;
  156. int dapm_tx_clk_status;
  157. bool lpi_enable;
  158. bool register_event_listener;
  159. bool clk_div_switch;
  160. int dec_mode[VA_MACRO_NUM_DECIMATORS];
  161. u16 current_clk_id;
  162. };
  163. static bool va_macro_get_data(struct snd_soc_component *component,
  164. struct device **va_dev,
  165. struct va_macro_priv **va_priv,
  166. const char *func_name)
  167. {
  168. *va_dev = bolero_get_device_ptr(component->dev, VA_MACRO);
  169. if (!(*va_dev)) {
  170. dev_err(component->dev,
  171. "%s: null device for macro!\n", func_name);
  172. return false;
  173. }
  174. *va_priv = dev_get_drvdata((*va_dev));
  175. if (!(*va_priv) || !(*va_priv)->component) {
  176. dev_err(component->dev,
  177. "%s: priv is null for macro!\n", func_name);
  178. return false;
  179. }
  180. return true;
  181. }
  182. static int va_macro_clk_div_get(struct snd_soc_component *component)
  183. {
  184. struct device *va_dev = NULL;
  185. struct va_macro_priv *va_priv = NULL;
  186. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  187. return -EINVAL;
  188. if ((va_priv->version >= BOLERO_VERSION_2_0)
  189. && va_priv->clk_div_switch
  190. && (va_priv->dmic_clk_div == VA_MACRO_CLK_DIV_16))
  191. return VA_MACRO_CLK_DIV_8;
  192. return va_priv->dmic_clk_div;
  193. }
  194. static int va_macro_mclk_enable(struct va_macro_priv *va_priv,
  195. bool mclk_enable, bool dapm)
  196. {
  197. struct regmap *regmap = dev_get_regmap(va_priv->dev->parent, NULL);
  198. int ret = 0;
  199. if (regmap == NULL) {
  200. dev_err(va_priv->dev, "%s: regmap is NULL\n", __func__);
  201. return -EINVAL;
  202. }
  203. dev_dbg(va_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  204. __func__, mclk_enable, dapm, va_priv->va_mclk_users);
  205. mutex_lock(&va_priv->mclk_lock);
  206. if (mclk_enable) {
  207. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  208. va_priv->default_clk_id,
  209. va_priv->clk_id,
  210. true);
  211. if (ret < 0) {
  212. dev_err(va_priv->dev,
  213. "%s: va request clock en failed\n",
  214. __func__);
  215. goto exit;
  216. }
  217. bolero_clk_rsc_fs_gen_request(va_priv->dev,
  218. true);
  219. if (va_priv->va_mclk_users == 0) {
  220. regcache_mark_dirty(regmap);
  221. regcache_sync_region(regmap,
  222. VA_START_OFFSET,
  223. VA_MAX_OFFSET);
  224. }
  225. va_priv->va_mclk_users++;
  226. } else {
  227. if (va_priv->va_mclk_users <= 0) {
  228. dev_err(va_priv->dev, "%s: clock already disabled\n",
  229. __func__);
  230. va_priv->va_mclk_users = 0;
  231. goto exit;
  232. }
  233. va_priv->va_mclk_users--;
  234. bolero_clk_rsc_fs_gen_request(va_priv->dev,
  235. false);
  236. bolero_clk_rsc_request_clock(va_priv->dev,
  237. va_priv->default_clk_id,
  238. va_priv->clk_id,
  239. false);
  240. }
  241. exit:
  242. mutex_unlock(&va_priv->mclk_lock);
  243. return ret;
  244. }
  245. static int va_macro_event_handler(struct snd_soc_component *component,
  246. u16 event, u32 data)
  247. {
  248. struct device *va_dev = NULL;
  249. struct va_macro_priv *va_priv = NULL;
  250. int retry_cnt = MAX_RETRY_ATTEMPTS;
  251. int ret = 0;
  252. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  253. return -EINVAL;
  254. switch (event) {
  255. case BOLERO_MACRO_EVT_WAIT_VA_CLK_RESET:
  256. while ((va_priv->va_mclk_users != 0) && (retry_cnt != 0)) {
  257. dev_dbg_ratelimited(va_dev, "%s:retry_cnt: %d\n",
  258. __func__, retry_cnt);
  259. /*
  260. * Userspace takes 10 seconds to close
  261. * the session when pcm_start fails due to concurrency
  262. * with PDR/SSR. Loop and check every 20ms till 10
  263. * seconds for va_mclk user count to get reset to 0
  264. * which ensures userspace teardown is done and SSR
  265. * powerup seq can proceed.
  266. */
  267. msleep(20);
  268. retry_cnt--;
  269. }
  270. if (retry_cnt == 0)
  271. dev_err(va_dev,
  272. "%s: va_mclk_users is non-zero still, audio SSR fail!!\n",
  273. __func__);
  274. break;
  275. case BOLERO_MACRO_EVT_PRE_SSR_UP:
  276. /* enable&disable VA_CORE_CLK to reset GFMUX reg */
  277. va_macro_core_vote(va_priv, true);
  278. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  279. va_priv->default_clk_id,
  280. VA_CORE_CLK, true);
  281. if (ret < 0)
  282. dev_err_ratelimited(va_priv->dev,
  283. "%s, failed to enable clk, ret:%d\n",
  284. __func__, ret);
  285. else
  286. bolero_clk_rsc_request_clock(va_priv->dev,
  287. va_priv->default_clk_id,
  288. VA_CORE_CLK, false);
  289. va_macro_core_vote(va_priv, false);
  290. break;
  291. case BOLERO_MACRO_EVT_SSR_UP:
  292. trace_printk("%s, enter SSR up\n", __func__);
  293. /* reset swr after ssr/pdr */
  294. va_priv->reset_swr = true;
  295. if (va_priv->swr_ctrl_data)
  296. swrm_wcd_notify(
  297. va_priv->swr_ctrl_data[0].va_swr_pdev,
  298. SWR_DEVICE_SSR_UP, NULL);
  299. break;
  300. case BOLERO_MACRO_EVT_CLK_RESET:
  301. bolero_rsc_clk_reset(va_dev, VA_CORE_CLK);
  302. break;
  303. case BOLERO_MACRO_EVT_SSR_DOWN:
  304. if (va_priv->swr_ctrl_data) {
  305. swrm_wcd_notify(
  306. va_priv->swr_ctrl_data[0].va_swr_pdev,
  307. SWR_DEVICE_SSR_DOWN, NULL);
  308. }
  309. if ((!pm_runtime_enabled(va_dev) ||
  310. !pm_runtime_suspended(va_dev))) {
  311. ret = bolero_runtime_suspend(va_dev);
  312. if (!ret) {
  313. pm_runtime_disable(va_dev);
  314. pm_runtime_set_suspended(va_dev);
  315. pm_runtime_enable(va_dev);
  316. }
  317. }
  318. break;
  319. default:
  320. break;
  321. }
  322. return 0;
  323. }
  324. static int va_macro_swr_clk_event_v2(struct snd_soc_dapm_widget *w,
  325. struct snd_kcontrol *kcontrol, int event)
  326. {
  327. struct snd_soc_component *component =
  328. snd_soc_dapm_to_component(w->dapm);
  329. struct device *va_dev = NULL;
  330. struct va_macro_priv *va_priv = NULL;
  331. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  332. return -EINVAL;
  333. dev_dbg(va_dev, "%s: event = %d\n", __func__, event);
  334. switch (event) {
  335. case SND_SOC_DAPM_PRE_PMU:
  336. va_priv->va_swr_clk_cnt++;
  337. break;
  338. case SND_SOC_DAPM_POST_PMD:
  339. va_priv->va_swr_clk_cnt--;
  340. break;
  341. default:
  342. break;
  343. }
  344. return 0;
  345. }
  346. static int va_macro_swr_pwr_event_v2(struct snd_soc_dapm_widget *w,
  347. struct snd_kcontrol *kcontrol, int event)
  348. {
  349. struct snd_soc_component *component =
  350. snd_soc_dapm_to_component(w->dapm);
  351. int ret = 0;
  352. struct device *va_dev = NULL;
  353. struct va_macro_priv *va_priv = NULL;
  354. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  355. return -EINVAL;
  356. dev_dbg(va_dev, "%s: event = %d, lpi_enable = %d\n",
  357. __func__, event, va_priv->lpi_enable);
  358. if (!va_priv->lpi_enable)
  359. return ret;
  360. switch (event) {
  361. case SND_SOC_DAPM_PRE_PMU:
  362. dev_dbg(component->dev,
  363. "%s: va_swr_clk_cnt %d, tx_swr_clk_cnt %d, tx_clk_status %d\n",
  364. __func__, va_priv->va_swr_clk_cnt,
  365. va_priv->tx_swr_clk_cnt, va_priv->tx_clk_status);
  366. if (va_priv->current_clk_id == VA_CORE_CLK) {
  367. return 0;
  368. } else if ( va_priv->va_swr_clk_cnt != 0 &&
  369. va_priv->tx_clk_status) {
  370. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  371. va_priv->default_clk_id,
  372. VA_CORE_CLK,
  373. true);
  374. if (ret) {
  375. dev_dbg(component->dev,
  376. "%s: request clock VA_CLK enable failed\n",
  377. __func__);
  378. break;
  379. }
  380. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  381. va_priv->default_clk_id,
  382. TX_CORE_CLK,
  383. false);
  384. if (ret) {
  385. dev_dbg(component->dev,
  386. "%s: request clock TX_CLK enable failed\n",
  387. __func__);
  388. bolero_clk_rsc_request_clock(va_priv->dev,
  389. va_priv->default_clk_id,
  390. VA_CORE_CLK,
  391. false);
  392. break;
  393. }
  394. va_priv->current_clk_id = VA_CORE_CLK;
  395. }
  396. break;
  397. case SND_SOC_DAPM_POST_PMD:
  398. if (va_priv->current_clk_id == VA_CORE_CLK &&
  399. va_priv->va_swr_clk_cnt != 0 &&
  400. va_priv->tx_clk_status) {
  401. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  402. va_priv->default_clk_id,
  403. TX_CORE_CLK,
  404. true);
  405. if (ret) {
  406. dev_dbg(component->dev,
  407. "%s: request clock TX_CLK disable failed\n",
  408. __func__);
  409. break;
  410. }
  411. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  412. va_priv->default_clk_id,
  413. VA_CORE_CLK,
  414. false);
  415. if (ret) {
  416. dev_dbg(component->dev,
  417. "%s: request clock VA_CLK disable failed\n",
  418. __func__);
  419. bolero_clk_rsc_request_clock(va_priv->dev,
  420. TX_CORE_CLK,
  421. TX_CORE_CLK,
  422. false);
  423. break;
  424. }
  425. va_priv->current_clk_id = TX_CORE_CLK;
  426. }
  427. break;
  428. default:
  429. dev_err(va_priv->dev,
  430. "%s: invalid DAPM event %d\n", __func__, event);
  431. ret = -EINVAL;
  432. }
  433. return ret;
  434. }
  435. static int va_macro_swr_pwr_event(struct snd_soc_dapm_widget *w,
  436. struct snd_kcontrol *kcontrol, int event)
  437. {
  438. struct snd_soc_component *component =
  439. snd_soc_dapm_to_component(w->dapm);
  440. int ret = 0;
  441. struct device *va_dev = NULL;
  442. struct va_macro_priv *va_priv = NULL;
  443. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  444. return -EINVAL;
  445. dev_dbg(va_dev, "%s: event = %d, lpi_enable = %d\n",
  446. __func__, event, va_priv->lpi_enable);
  447. if (!va_priv->lpi_enable)
  448. return ret;
  449. switch (event) {
  450. case SND_SOC_DAPM_PRE_PMU:
  451. if (va_priv->lpass_audio_hw_vote) {
  452. ret = digital_cdc_rsc_mgr_hw_vote_enable(
  453. va_priv->lpass_audio_hw_vote);
  454. if (ret)
  455. dev_err(va_dev,
  456. "%s: lpass audio hw enable failed\n",
  457. __func__);
  458. }
  459. if (!ret) {
  460. if (bolero_tx_clk_switch(component, VA_CORE_CLK))
  461. dev_dbg(va_dev, "%s: clock switch failed\n",
  462. __func__);
  463. }
  464. if (va_priv->lpi_enable) {
  465. bolero_register_event_listener(component, true);
  466. va_priv->register_event_listener = true;
  467. }
  468. break;
  469. case SND_SOC_DAPM_POST_PMD:
  470. if (va_priv->register_event_listener) {
  471. va_priv->register_event_listener = false;
  472. bolero_register_event_listener(component, false);
  473. }
  474. if (bolero_tx_clk_switch(component, TX_CORE_CLK))
  475. dev_dbg(va_dev, "%s: clock switch failed\n",__func__);
  476. if (va_priv->lpass_audio_hw_vote)
  477. digital_cdc_rsc_mgr_hw_vote_disable(
  478. va_priv->lpass_audio_hw_vote);
  479. break;
  480. default:
  481. dev_err(va_priv->dev,
  482. "%s: invalid DAPM event %d\n", __func__, event);
  483. ret = -EINVAL;
  484. }
  485. return ret;
  486. }
  487. static int va_macro_tx_swr_clk_event_v2(struct snd_soc_dapm_widget *w,
  488. struct snd_kcontrol *kcontrol, int event)
  489. {
  490. struct device *va_dev = NULL;
  491. struct va_macro_priv *va_priv = NULL;
  492. struct snd_soc_component *component =
  493. snd_soc_dapm_to_component(w->dapm);
  494. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  495. return -EINVAL;
  496. if (SND_SOC_DAPM_EVENT_ON(event))
  497. ++va_priv->tx_swr_clk_cnt;
  498. if (SND_SOC_DAPM_EVENT_OFF(event))
  499. --va_priv->tx_swr_clk_cnt;
  500. return 0;
  501. }
  502. static int va_macro_mclk_event(struct snd_soc_dapm_widget *w,
  503. struct snd_kcontrol *kcontrol, int event)
  504. {
  505. struct snd_soc_component *component =
  506. snd_soc_dapm_to_component(w->dapm);
  507. int ret = 0;
  508. struct device *va_dev = NULL;
  509. struct va_macro_priv *va_priv = NULL;
  510. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  511. return -EINVAL;
  512. dev_dbg(va_dev, "%s: event = %d\n", __func__, event);
  513. switch (event) {
  514. case SND_SOC_DAPM_PRE_PMU:
  515. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  516. va_priv->default_clk_id,
  517. TX_CORE_CLK,
  518. true);
  519. if (!ret)
  520. va_priv->dapm_tx_clk_status++;
  521. if (va_priv->lpi_enable)
  522. ret = va_macro_mclk_enable(va_priv, 1, true);
  523. else
  524. ret = bolero_tx_mclk_enable(component, 1);
  525. break;
  526. case SND_SOC_DAPM_POST_PMD:
  527. if (va_priv->lpi_enable) {
  528. va_macro_mclk_enable(va_priv, 0, true);
  529. } else {
  530. bolero_tx_mclk_enable(component, 0);
  531. }
  532. if (va_priv->dapm_tx_clk_status > 0) {
  533. bolero_clk_rsc_request_clock(va_priv->dev,
  534. va_priv->default_clk_id,
  535. TX_CORE_CLK,
  536. false);
  537. va_priv->dapm_tx_clk_status--;
  538. }
  539. break;
  540. default:
  541. dev_err(va_priv->dev,
  542. "%s: invalid DAPM event %d\n", __func__, event);
  543. ret = -EINVAL;
  544. }
  545. return ret;
  546. }
  547. static int va_macro_tx_va_mclk_enable(struct va_macro_priv *va_priv,
  548. struct regmap *regmap, int clk_type,
  549. bool enable)
  550. {
  551. int ret = 0, clk_tx_ret = 0;
  552. dev_dbg(va_priv->dev,
  553. "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
  554. __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
  555. (enable ? "enable" : "disable"), va_priv->va_mclk_users);
  556. if (enable) {
  557. if (va_priv->swr_clk_users == 0) {
  558. msm_cdc_pinctrl_select_active_state(
  559. va_priv->va_swr_gpio_p);
  560. msm_cdc_pinctrl_set_wakeup_capable(
  561. va_priv->va_swr_gpio_p, false);
  562. }
  563. clk_tx_ret = bolero_clk_rsc_request_clock(va_priv->dev,
  564. TX_CORE_CLK,
  565. TX_CORE_CLK,
  566. true);
  567. if (clk_type == TX_MCLK) {
  568. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  569. TX_CORE_CLK,
  570. TX_CORE_CLK,
  571. true);
  572. if (ret < 0) {
  573. if (va_priv->swr_clk_users == 0)
  574. msm_cdc_pinctrl_select_sleep_state(
  575. va_priv->va_swr_gpio_p);
  576. dev_err_ratelimited(va_priv->dev,
  577. "%s: swr request clk failed\n",
  578. __func__);
  579. goto done;
  580. }
  581. bolero_clk_rsc_fs_gen_request(va_priv->dev,
  582. true);
  583. }
  584. if (clk_type == VA_MCLK) {
  585. ret = va_macro_mclk_enable(va_priv, 1, true);
  586. if (ret < 0) {
  587. if (va_priv->swr_clk_users == 0)
  588. msm_cdc_pinctrl_select_sleep_state(
  589. va_priv->va_swr_gpio_p);
  590. dev_err_ratelimited(va_priv->dev,
  591. "%s: request clock enable failed\n",
  592. __func__);
  593. goto done;
  594. }
  595. }
  596. if (va_priv->swr_clk_users == 0) {
  597. dev_dbg(va_priv->dev, "%s: reset_swr: %d\n",
  598. __func__, va_priv->reset_swr);
  599. if (va_priv->reset_swr)
  600. regmap_update_bits(regmap,
  601. BOLERO_CDC_VA_CLK_RST_CTRL_SWR_CONTROL,
  602. 0x02, 0x02);
  603. regmap_update_bits(regmap,
  604. BOLERO_CDC_VA_CLK_RST_CTRL_SWR_CONTROL,
  605. 0x01, 0x01);
  606. if (va_priv->reset_swr)
  607. regmap_update_bits(regmap,
  608. BOLERO_CDC_VA_CLK_RST_CTRL_SWR_CONTROL,
  609. 0x02, 0x00);
  610. va_priv->reset_swr = false;
  611. }
  612. if (!clk_tx_ret)
  613. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  614. TX_CORE_CLK,
  615. TX_CORE_CLK,
  616. false);
  617. va_priv->swr_clk_users++;
  618. } else {
  619. if (va_priv->swr_clk_users <= 0) {
  620. dev_err_ratelimited(va_priv->dev,
  621. "va swrm clock users already 0\n");
  622. va_priv->swr_clk_users = 0;
  623. return 0;
  624. }
  625. clk_tx_ret = bolero_clk_rsc_request_clock(va_priv->dev,
  626. TX_CORE_CLK,
  627. TX_CORE_CLK,
  628. true);
  629. va_priv->swr_clk_users--;
  630. if (va_priv->swr_clk_users == 0)
  631. regmap_update_bits(regmap,
  632. BOLERO_CDC_VA_CLK_RST_CTRL_SWR_CONTROL,
  633. 0x01, 0x00);
  634. if (clk_type == VA_MCLK)
  635. va_macro_mclk_enable(va_priv, 0, true);
  636. if (clk_type == TX_MCLK) {
  637. bolero_clk_rsc_fs_gen_request(va_priv->dev,
  638. false);
  639. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  640. TX_CORE_CLK,
  641. TX_CORE_CLK,
  642. false);
  643. if (ret < 0) {
  644. dev_err_ratelimited(va_priv->dev,
  645. "%s: swr request clk failed\n",
  646. __func__);
  647. goto done;
  648. }
  649. }
  650. if (!clk_tx_ret)
  651. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  652. TX_CORE_CLK,
  653. TX_CORE_CLK,
  654. false);
  655. if (va_priv->swr_clk_users == 0) {
  656. msm_cdc_pinctrl_set_wakeup_capable(
  657. va_priv->va_swr_gpio_p, true);
  658. msm_cdc_pinctrl_select_sleep_state(
  659. va_priv->va_swr_gpio_p);
  660. }
  661. }
  662. return 0;
  663. done:
  664. if (!clk_tx_ret)
  665. bolero_clk_rsc_request_clock(va_priv->dev,
  666. TX_CORE_CLK,
  667. TX_CORE_CLK,
  668. false);
  669. return ret;
  670. }
  671. static int va_macro_core_vote(void *handle, bool enable)
  672. {
  673. int rc = 0;
  674. struct va_macro_priv *va_priv = (struct va_macro_priv *) handle;
  675. if (va_priv == NULL) {
  676. pr_err("%s: va priv data is NULL\n", __func__);
  677. return -EINVAL;
  678. }
  679. if (enable) {
  680. pm_runtime_get_sync(va_priv->dev);
  681. if (bolero_check_core_votes(va_priv->dev))
  682. rc = 0;
  683. else
  684. rc = -ENOTSYNC;
  685. } else {
  686. pm_runtime_put_autosuspend(va_priv->dev);
  687. pm_runtime_mark_last_busy(va_priv->dev);
  688. }
  689. return rc;
  690. }
  691. static int va_macro_swrm_clock(void *handle, bool enable)
  692. {
  693. struct va_macro_priv *va_priv = (struct va_macro_priv *) handle;
  694. struct regmap *regmap = dev_get_regmap(va_priv->dev->parent, NULL);
  695. int ret = 0;
  696. if (regmap == NULL) {
  697. dev_err(va_priv->dev, "%s: regmap is NULL\n", __func__);
  698. return -EINVAL;
  699. }
  700. mutex_lock(&va_priv->swr_clk_lock);
  701. dev_dbg(va_priv->dev,
  702. "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
  703. __func__, (enable ? "enable" : "disable"),
  704. va_priv->tx_swr_clk_cnt, va_priv->va_swr_clk_cnt);
  705. if (enable) {
  706. pm_runtime_get_sync(va_priv->dev);
  707. if (va_priv->va_swr_clk_cnt && !va_priv->tx_swr_clk_cnt) {
  708. ret = va_macro_tx_va_mclk_enable(va_priv, regmap,
  709. VA_MCLK, enable);
  710. if (ret) {
  711. pm_runtime_mark_last_busy(va_priv->dev);
  712. pm_runtime_put_autosuspend(va_priv->dev);
  713. goto done;
  714. }
  715. va_priv->va_clk_status++;
  716. } else {
  717. ret = va_macro_tx_va_mclk_enable(va_priv, regmap,
  718. TX_MCLK, enable);
  719. if (ret) {
  720. pm_runtime_mark_last_busy(va_priv->dev);
  721. pm_runtime_put_autosuspend(va_priv->dev);
  722. goto done;
  723. }
  724. va_priv->tx_clk_status++;
  725. }
  726. pm_runtime_mark_last_busy(va_priv->dev);
  727. pm_runtime_put_autosuspend(va_priv->dev);
  728. } else {
  729. if (va_priv->va_clk_status && !va_priv->tx_clk_status) {
  730. ret = va_macro_tx_va_mclk_enable(va_priv, regmap,
  731. VA_MCLK, enable);
  732. if (ret)
  733. goto done;
  734. --va_priv->va_clk_status;
  735. } else if (!va_priv->va_clk_status && va_priv->tx_clk_status) {
  736. ret = va_macro_tx_va_mclk_enable(va_priv, regmap,
  737. TX_MCLK, enable);
  738. if (ret)
  739. goto done;
  740. --va_priv->tx_clk_status;
  741. } else if (va_priv->va_clk_status && va_priv->tx_clk_status) {
  742. if (!va_priv->va_swr_clk_cnt && va_priv->tx_swr_clk_cnt) {
  743. ret = va_macro_tx_va_mclk_enable(va_priv, regmap,
  744. VA_MCLK, enable);
  745. if (ret)
  746. goto done;
  747. --va_priv->va_clk_status;
  748. } else {
  749. ret = va_macro_tx_va_mclk_enable(va_priv, regmap,
  750. TX_MCLK, enable);
  751. if (ret)
  752. goto done;
  753. --va_priv->tx_clk_status;
  754. }
  755. } else {
  756. dev_dbg(va_priv->dev,
  757. "%s: Both clocks are disabled\n", __func__);
  758. }
  759. }
  760. dev_dbg(va_priv->dev,
  761. "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
  762. __func__, va_priv->swr_clk_users, va_priv->tx_clk_status,
  763. va_priv->va_clk_status);
  764. done:
  765. mutex_unlock(&va_priv->swr_clk_lock);
  766. return ret;
  767. }
  768. static bool is_amic_enabled(struct snd_soc_component *component, int decimator)
  769. {
  770. u16 adc_mux_reg = 0, adc_reg = 0;
  771. u16 adc_n = BOLERO_ADC_MAX;
  772. bool ret = false;
  773. struct device *va_dev = NULL;
  774. struct va_macro_priv *va_priv = NULL;
  775. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  776. return ret;
  777. adc_mux_reg = BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG1 +
  778. VA_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  779. if (snd_soc_component_read(component, adc_mux_reg) & SWR_MIC) {
  780. if (va_priv->version == BOLERO_VERSION_2_1)
  781. return true;
  782. adc_reg = BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0 +
  783. VA_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  784. adc_n = snd_soc_component_read(component, adc_reg) &
  785. VA_MACRO_SWR_MIC_MUX_SEL_MASK;
  786. if (adc_n < BOLERO_ADC_MAX)
  787. return true;
  788. }
  789. return ret;
  790. }
  791. static void va_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  792. {
  793. struct delayed_work *hpf_delayed_work;
  794. struct hpf_work *hpf_work;
  795. struct va_macro_priv *va_priv;
  796. struct snd_soc_component *component;
  797. u16 dec_cfg_reg, hpf_gate_reg;
  798. u8 hpf_cut_off_freq;
  799. u16 adc_reg = 0, adc_n = 0;
  800. hpf_delayed_work = to_delayed_work(work);
  801. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  802. va_priv = hpf_work->va_priv;
  803. component = va_priv->component;
  804. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  805. dec_cfg_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0 +
  806. VA_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  807. hpf_gate_reg = BOLERO_CDC_VA_TX0_TX_PATH_SEC2 +
  808. VA_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  809. dev_dbg(va_priv->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  810. __func__, hpf_work->decimator, hpf_cut_off_freq);
  811. if (is_amic_enabled(component, hpf_work->decimator)) {
  812. adc_reg = BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0 +
  813. VA_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  814. adc_n = snd_soc_component_read(component, adc_reg) &
  815. VA_MACRO_SWR_MIC_MUX_SEL_MASK;
  816. /* analog mic clear TX hold */
  817. bolero_clear_amic_tx_hold(component->dev, adc_n);
  818. snd_soc_component_update_bits(component,
  819. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  820. hpf_cut_off_freq << 5);
  821. snd_soc_component_update_bits(component, hpf_gate_reg,
  822. 0x03, 0x02);
  823. /* Minimum 1 clk cycle delay is required as per HW spec */
  824. usleep_range(1000, 1010);
  825. snd_soc_component_update_bits(component, hpf_gate_reg,
  826. 0x03, 0x01);
  827. } else {
  828. snd_soc_component_update_bits(component,
  829. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  830. hpf_cut_off_freq << 5);
  831. snd_soc_component_update_bits(component, hpf_gate_reg,
  832. 0x02, 0x02);
  833. /* Minimum 1 clk cycle delay is required as per HW spec */
  834. usleep_range(1000, 1010);
  835. snd_soc_component_update_bits(component, hpf_gate_reg,
  836. 0x02, 0x00);
  837. }
  838. }
  839. static void va_macro_mute_update_callback(struct work_struct *work)
  840. {
  841. struct va_mute_work *va_mute_dwork;
  842. struct snd_soc_component *component = NULL;
  843. struct va_macro_priv *va_priv;
  844. struct delayed_work *delayed_work;
  845. u16 tx_vol_ctl_reg, decimator;
  846. delayed_work = to_delayed_work(work);
  847. va_mute_dwork = container_of(delayed_work, struct va_mute_work, dwork);
  848. va_priv = va_mute_dwork->va_priv;
  849. component = va_priv->component;
  850. decimator = va_mute_dwork->decimator;
  851. tx_vol_ctl_reg =
  852. BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  853. VA_MACRO_TX_PATH_OFFSET * decimator;
  854. snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
  855. dev_dbg(va_priv->dev, "%s: decimator %u unmute\n",
  856. __func__, decimator);
  857. }
  858. static int va_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  859. struct snd_ctl_elem_value *ucontrol)
  860. {
  861. struct snd_soc_dapm_widget *widget =
  862. snd_soc_dapm_kcontrol_widget(kcontrol);
  863. struct snd_soc_component *component =
  864. snd_soc_dapm_to_component(widget->dapm);
  865. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  866. unsigned int val;
  867. u16 mic_sel_reg, dmic_clk_reg;
  868. struct device *va_dev = NULL;
  869. struct va_macro_priv *va_priv = NULL;
  870. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  871. return -EINVAL;
  872. val = ucontrol->value.enumerated.item[0];
  873. if (val > e->items - 1)
  874. return -EINVAL;
  875. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  876. widget->name, val);
  877. switch (e->reg) {
  878. case BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0:
  879. mic_sel_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0;
  880. break;
  881. case BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0:
  882. mic_sel_reg = BOLERO_CDC_VA_TX1_TX_PATH_CFG0;
  883. break;
  884. case BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0:
  885. mic_sel_reg = BOLERO_CDC_VA_TX2_TX_PATH_CFG0;
  886. break;
  887. case BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0:
  888. mic_sel_reg = BOLERO_CDC_VA_TX3_TX_PATH_CFG0;
  889. break;
  890. case BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0:
  891. mic_sel_reg = BOLERO_CDC_VA_TX4_TX_PATH_CFG0;
  892. break;
  893. case BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0:
  894. mic_sel_reg = BOLERO_CDC_VA_TX5_TX_PATH_CFG0;
  895. break;
  896. case BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0:
  897. mic_sel_reg = BOLERO_CDC_VA_TX6_TX_PATH_CFG0;
  898. break;
  899. case BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0:
  900. mic_sel_reg = BOLERO_CDC_VA_TX7_TX_PATH_CFG0;
  901. break;
  902. default:
  903. dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
  904. __func__, e->reg);
  905. return -EINVAL;
  906. }
  907. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  908. if (val != 0) {
  909. if (val < 5) {
  910. snd_soc_component_update_bits(component,
  911. mic_sel_reg,
  912. 1 << 7, 0x0 << 7);
  913. } else {
  914. snd_soc_component_update_bits(component,
  915. mic_sel_reg,
  916. 1 << 7, 0x1 << 7);
  917. snd_soc_component_update_bits(component,
  918. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  919. 0x80, 0x00);
  920. dmic_clk_reg =
  921. BOLERO_CDC_TX_TOP_CSR_SWR_DMIC0_CTL +
  922. ((val - 5)/2) * 4;
  923. snd_soc_component_update_bits(component,
  924. dmic_clk_reg,
  925. 0x0E, va_priv->dmic_clk_div << 0x1);
  926. }
  927. }
  928. } else {
  929. /* DMIC selected */
  930. if (val != 0)
  931. snd_soc_component_update_bits(component, mic_sel_reg,
  932. 1 << 7, 1 << 7);
  933. }
  934. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  935. }
  936. static int va_macro_lpi_get(struct snd_kcontrol *kcontrol,
  937. struct snd_ctl_elem_value *ucontrol)
  938. {
  939. struct snd_soc_component *component =
  940. snd_soc_kcontrol_component(kcontrol);
  941. struct device *va_dev = NULL;
  942. struct va_macro_priv *va_priv = NULL;
  943. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  944. return -EINVAL;
  945. ucontrol->value.integer.value[0] = va_priv->lpi_enable;
  946. return 0;
  947. }
  948. static int va_macro_lpi_put(struct snd_kcontrol *kcontrol,
  949. struct snd_ctl_elem_value *ucontrol)
  950. {
  951. struct snd_soc_component *component =
  952. snd_soc_kcontrol_component(kcontrol);
  953. struct device *va_dev = NULL;
  954. struct va_macro_priv *va_priv = NULL;
  955. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  956. return -EINVAL;
  957. va_priv->lpi_enable = ucontrol->value.integer.value[0];
  958. return 0;
  959. }
  960. static int va_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  961. struct snd_ctl_elem_value *ucontrol)
  962. {
  963. struct snd_soc_dapm_widget *widget =
  964. snd_soc_dapm_kcontrol_widget(kcontrol);
  965. struct snd_soc_component *component =
  966. snd_soc_dapm_to_component(widget->dapm);
  967. struct soc_multi_mixer_control *mixer =
  968. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  969. u32 dai_id = widget->shift;
  970. u32 dec_id = mixer->shift;
  971. struct device *va_dev = NULL;
  972. struct va_macro_priv *va_priv = NULL;
  973. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  974. return -EINVAL;
  975. if (test_bit(dec_id, &va_priv->active_ch_mask[dai_id]))
  976. ucontrol->value.integer.value[0] = 1;
  977. else
  978. ucontrol->value.integer.value[0] = 0;
  979. return 0;
  980. }
  981. static int va_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  982. struct snd_ctl_elem_value *ucontrol)
  983. {
  984. struct snd_soc_dapm_widget *widget =
  985. snd_soc_dapm_kcontrol_widget(kcontrol);
  986. struct snd_soc_component *component =
  987. snd_soc_dapm_to_component(widget->dapm);
  988. struct snd_soc_dapm_update *update = NULL;
  989. struct soc_multi_mixer_control *mixer =
  990. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  991. u32 dai_id = widget->shift;
  992. u32 dec_id = mixer->shift;
  993. u32 enable = ucontrol->value.integer.value[0];
  994. struct device *va_dev = NULL;
  995. struct va_macro_priv *va_priv = NULL;
  996. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  997. return -EINVAL;
  998. if (enable)
  999. set_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
  1000. else
  1001. clear_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
  1002. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  1003. return 0;
  1004. }
  1005. static int va_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  1006. struct snd_kcontrol *kcontrol, int event)
  1007. {
  1008. struct snd_soc_component *component =
  1009. snd_soc_dapm_to_component(w->dapm);
  1010. unsigned int dmic = 0;
  1011. int ret = 0;
  1012. char *wname;
  1013. wname = strpbrk(w->name, "01234567");
  1014. if (!wname) {
  1015. dev_err(component->dev, "%s: widget not found\n", __func__);
  1016. return -EINVAL;
  1017. }
  1018. ret = kstrtouint(wname, 10, &dmic);
  1019. if (ret < 0) {
  1020. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  1021. __func__);
  1022. return -EINVAL;
  1023. }
  1024. dev_dbg(component->dev, "%s: event %d DMIC%d\n",
  1025. __func__, event, dmic);
  1026. switch (event) {
  1027. case SND_SOC_DAPM_PRE_PMU:
  1028. bolero_dmic_clk_enable(component, dmic, DMIC_VA, true);
  1029. break;
  1030. case SND_SOC_DAPM_POST_PMD:
  1031. bolero_dmic_clk_enable(component, dmic, DMIC_VA, false);
  1032. break;
  1033. }
  1034. return 0;
  1035. }
  1036. static int va_macro_enable_dec(struct snd_soc_dapm_widget *w,
  1037. struct snd_kcontrol *kcontrol, int event)
  1038. {
  1039. struct snd_soc_component *component =
  1040. snd_soc_dapm_to_component(w->dapm);
  1041. unsigned int decimator;
  1042. u16 tx_vol_ctl_reg, dec_cfg_reg, hpf_gate_reg;
  1043. u16 tx_gain_ctl_reg;
  1044. u8 hpf_cut_off_freq;
  1045. u16 adc_mux_reg = 0;
  1046. struct device *va_dev = NULL;
  1047. struct va_macro_priv *va_priv = NULL;
  1048. int hpf_delay = BOLERO_CDC_VA_TX_DMIC_HPF_DELAY_MS;
  1049. int unmute_delay = BOLERO_CDC_VA_TX_DMIC_UNMUTE_DELAY_MS;
  1050. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  1051. return -EINVAL;
  1052. decimator = w->shift;
  1053. dev_dbg(va_dev, "%s(): widget = %s decimator = %u\n", __func__,
  1054. w->name, decimator);
  1055. tx_vol_ctl_reg = BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  1056. VA_MACRO_TX_PATH_OFFSET * decimator;
  1057. hpf_gate_reg = BOLERO_CDC_VA_TX0_TX_PATH_SEC2 +
  1058. VA_MACRO_TX_PATH_OFFSET * decimator;
  1059. dec_cfg_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0 +
  1060. VA_MACRO_TX_PATH_OFFSET * decimator;
  1061. tx_gain_ctl_reg = BOLERO_CDC_VA_TX0_TX_VOL_CTL +
  1062. VA_MACRO_TX_PATH_OFFSET * decimator;
  1063. adc_mux_reg = BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG1 +
  1064. VA_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  1065. switch (event) {
  1066. case SND_SOC_DAPM_PRE_PMU:
  1067. snd_soc_component_update_bits(component,
  1068. dec_cfg_reg, 0x06, va_priv->dec_mode[decimator] <<
  1069. VA_MACRO_ADC_MODE_CFG0_SHIFT);
  1070. /* Enable TX PGA Mute */
  1071. snd_soc_component_update_bits(component,
  1072. tx_vol_ctl_reg, 0x10, 0x10);
  1073. break;
  1074. case SND_SOC_DAPM_POST_PMU:
  1075. /* Enable TX CLK */
  1076. snd_soc_component_update_bits(component,
  1077. tx_vol_ctl_reg, 0x20, 0x20);
  1078. if (!is_amic_enabled(component, decimator)) {
  1079. snd_soc_component_update_bits(component,
  1080. hpf_gate_reg, 0x01, 0x00);
  1081. /*
  1082. * Minimum 1 clk cycle delay is required as per HW spec
  1083. */
  1084. usleep_range(1000, 1010);
  1085. }
  1086. hpf_cut_off_freq = (snd_soc_component_read(
  1087. component, dec_cfg_reg) &
  1088. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  1089. va_priv->va_hpf_work[decimator].hpf_cut_off_freq =
  1090. hpf_cut_off_freq;
  1091. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  1092. snd_soc_component_update_bits(component, dec_cfg_reg,
  1093. TX_HPF_CUT_OFF_FREQ_MASK,
  1094. CF_MIN_3DB_150HZ << 5);
  1095. }
  1096. if (is_amic_enabled(component, decimator) < BOLERO_ADC_MAX) {
  1097. hpf_delay = BOLERO_CDC_VA_TX_AMIC_HPF_DELAY_MS;
  1098. unmute_delay = BOLERO_CDC_VA_TX_AMIC_UNMUTE_DELAY_MS;
  1099. if (va_tx_unmute_delay < unmute_delay)
  1100. va_tx_unmute_delay = unmute_delay;
  1101. }
  1102. snd_soc_component_update_bits(component,
  1103. hpf_gate_reg, 0x03, 0x02);
  1104. if (!is_amic_enabled(component, decimator))
  1105. snd_soc_component_update_bits(component,
  1106. hpf_gate_reg, 0x03, 0x00);
  1107. /*
  1108. * Minimum 1 clk cycle delay is required as per HW spec
  1109. */
  1110. usleep_range(1000, 1010);
  1111. snd_soc_component_update_bits(component,
  1112. hpf_gate_reg, 0x03, 0x01);
  1113. /*
  1114. * 6ms delay is required as per HW spec
  1115. */
  1116. usleep_range(6000, 6010);
  1117. /* schedule work queue to Remove Mute */
  1118. queue_delayed_work(system_freezable_wq,
  1119. &va_priv->va_mute_dwork[decimator].dwork,
  1120. msecs_to_jiffies(va_tx_unmute_delay));
  1121. if (va_priv->va_hpf_work[decimator].hpf_cut_off_freq !=
  1122. CF_MIN_3DB_150HZ)
  1123. queue_delayed_work(system_freezable_wq,
  1124. &va_priv->va_hpf_work[decimator].dwork,
  1125. msecs_to_jiffies(hpf_delay));
  1126. /* apply gain after decimator is enabled */
  1127. snd_soc_component_write(component, tx_gain_ctl_reg,
  1128. snd_soc_component_read(component, tx_gain_ctl_reg));
  1129. if (va_priv->version == BOLERO_VERSION_2_0) {
  1130. if (snd_soc_component_read(component, adc_mux_reg)
  1131. & SWR_MIC) {
  1132. snd_soc_component_update_bits(component,
  1133. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL,
  1134. 0x01, 0x01);
  1135. snd_soc_component_update_bits(component,
  1136. BOLERO_CDC_TX_TOP_CSR_SWR_MIC0_CTL,
  1137. 0x0E, 0x0C);
  1138. snd_soc_component_update_bits(component,
  1139. BOLERO_CDC_TX_TOP_CSR_SWR_MIC1_CTL,
  1140. 0x0E, 0x0C);
  1141. snd_soc_component_update_bits(component,
  1142. BOLERO_CDC_TX_TOP_CSR_SWR_MIC2_CTL,
  1143. 0x0E, 0x00);
  1144. snd_soc_component_update_bits(component,
  1145. BOLERO_CDC_TX_TOP_CSR_SWR_MIC3_CTL,
  1146. 0x0E, 0x00);
  1147. snd_soc_component_update_bits(component,
  1148. BOLERO_CDC_TX_TOP_CSR_SWR_MIC4_CTL,
  1149. 0x0E, 0x00);
  1150. snd_soc_component_update_bits(component,
  1151. BOLERO_CDC_TX_TOP_CSR_SWR_MIC5_CTL,
  1152. 0x0E, 0x00);
  1153. }
  1154. }
  1155. break;
  1156. case SND_SOC_DAPM_PRE_PMD:
  1157. hpf_cut_off_freq =
  1158. va_priv->va_hpf_work[decimator].hpf_cut_off_freq;
  1159. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1160. 0x10, 0x10);
  1161. if (cancel_delayed_work_sync(
  1162. &va_priv->va_hpf_work[decimator].dwork)) {
  1163. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  1164. snd_soc_component_update_bits(component,
  1165. dec_cfg_reg,
  1166. TX_HPF_CUT_OFF_FREQ_MASK,
  1167. hpf_cut_off_freq << 5);
  1168. if (is_amic_enabled(component, decimator))
  1169. snd_soc_component_update_bits(component,
  1170. hpf_gate_reg,
  1171. 0x03, 0x02);
  1172. else
  1173. snd_soc_component_update_bits(component,
  1174. hpf_gate_reg,
  1175. 0x03, 0x03);
  1176. /*
  1177. * Minimum 1 clk cycle delay is required
  1178. * as per HW spec
  1179. */
  1180. usleep_range(1000, 1010);
  1181. snd_soc_component_update_bits(component,
  1182. hpf_gate_reg,
  1183. 0x03, 0x01);
  1184. }
  1185. }
  1186. cancel_delayed_work_sync(
  1187. &va_priv->va_mute_dwork[decimator].dwork);
  1188. if (va_priv->version == BOLERO_VERSION_2_0) {
  1189. if (snd_soc_component_read(component, adc_mux_reg)
  1190. & SWR_MIC)
  1191. snd_soc_component_update_bits(component,
  1192. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL,
  1193. 0x01, 0x00);
  1194. }
  1195. break;
  1196. case SND_SOC_DAPM_POST_PMD:
  1197. /* Disable TX CLK */
  1198. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1199. 0x20, 0x00);
  1200. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1201. 0x10, 0x00);
  1202. break;
  1203. }
  1204. return 0;
  1205. }
  1206. static int va_macro_enable_tx(struct snd_soc_dapm_widget *w,
  1207. struct snd_kcontrol *kcontrol, int event)
  1208. {
  1209. struct snd_soc_component *component =
  1210. snd_soc_dapm_to_component(w->dapm);
  1211. struct device *va_dev = NULL;
  1212. struct va_macro_priv *va_priv = NULL;
  1213. int ret = 0;
  1214. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  1215. return -EINVAL;
  1216. dev_dbg(va_dev, "%s: event = %d\n", __func__, event);
  1217. switch (event) {
  1218. case SND_SOC_DAPM_POST_PMU:
  1219. if (va_priv->dapm_tx_clk_status > 0) {
  1220. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  1221. va_priv->default_clk_id,
  1222. TX_CORE_CLK,
  1223. false);
  1224. va_priv->dapm_tx_clk_status--;
  1225. }
  1226. break;
  1227. case SND_SOC_DAPM_PRE_PMD:
  1228. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  1229. va_priv->default_clk_id,
  1230. TX_CORE_CLK,
  1231. true);
  1232. if (!ret)
  1233. va_priv->dapm_tx_clk_status++;
  1234. break;
  1235. default:
  1236. dev_err(va_priv->dev,
  1237. "%s: invalid DAPM event %d\n", __func__, event);
  1238. ret = -EINVAL;
  1239. break;
  1240. }
  1241. return ret;
  1242. }
  1243. static int va_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  1244. struct snd_kcontrol *kcontrol, int event)
  1245. {
  1246. struct snd_soc_component *component =
  1247. snd_soc_dapm_to_component(w->dapm);
  1248. struct device *va_dev = NULL;
  1249. struct va_macro_priv *va_priv = NULL;
  1250. int ret = 0;
  1251. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  1252. return -EINVAL;
  1253. if (!va_priv->micb_supply) {
  1254. dev_err(va_dev,
  1255. "%s:regulator not provided in dtsi\n", __func__);
  1256. return -EINVAL;
  1257. }
  1258. switch (event) {
  1259. case SND_SOC_DAPM_PRE_PMU:
  1260. if (va_priv->micb_users++ > 0)
  1261. return 0;
  1262. ret = regulator_set_voltage(va_priv->micb_supply,
  1263. va_priv->micb_voltage,
  1264. va_priv->micb_voltage);
  1265. if (ret) {
  1266. dev_err(va_dev, "%s: Setting voltage failed, err = %d\n",
  1267. __func__, ret);
  1268. return ret;
  1269. }
  1270. ret = regulator_set_load(va_priv->micb_supply,
  1271. va_priv->micb_current);
  1272. if (ret) {
  1273. dev_err(va_dev, "%s: Setting current failed, err = %d\n",
  1274. __func__, ret);
  1275. return ret;
  1276. }
  1277. ret = regulator_enable(va_priv->micb_supply);
  1278. if (ret) {
  1279. dev_err(va_dev, "%s: regulator enable failed, err = %d\n",
  1280. __func__, ret);
  1281. return ret;
  1282. }
  1283. break;
  1284. case SND_SOC_DAPM_POST_PMD:
  1285. if (--va_priv->micb_users > 0)
  1286. return 0;
  1287. if (va_priv->micb_users < 0) {
  1288. va_priv->micb_users = 0;
  1289. dev_dbg(va_dev, "%s: regulator already disabled\n",
  1290. __func__);
  1291. return 0;
  1292. }
  1293. ret = regulator_disable(va_priv->micb_supply);
  1294. if (ret) {
  1295. dev_err(va_dev, "%s: regulator disable failed, err = %d\n",
  1296. __func__, ret);
  1297. return ret;
  1298. }
  1299. regulator_set_voltage(va_priv->micb_supply, 0,
  1300. va_priv->micb_voltage);
  1301. regulator_set_load(va_priv->micb_supply, 0);
  1302. break;
  1303. }
  1304. return 0;
  1305. }
  1306. static inline int va_macro_path_get(const char *wname,
  1307. unsigned int *path_num)
  1308. {
  1309. int ret = 0;
  1310. char *widget_name = NULL;
  1311. char *w_name = NULL;
  1312. char *path_num_char = NULL;
  1313. char *path_name = NULL;
  1314. widget_name = kstrndup(wname, 10, GFP_KERNEL);
  1315. if (!widget_name)
  1316. return -EINVAL;
  1317. w_name = widget_name;
  1318. path_name = strsep(&widget_name, " ");
  1319. if (!path_name) {
  1320. pr_err("%s: Invalid widget name = %s\n",
  1321. __func__, widget_name);
  1322. ret = -EINVAL;
  1323. goto err;
  1324. }
  1325. path_num_char = strpbrk(path_name, "01234567");
  1326. if (!path_num_char) {
  1327. pr_err("%s: va path index not found\n",
  1328. __func__);
  1329. ret = -EINVAL;
  1330. goto err;
  1331. }
  1332. ret = kstrtouint(path_num_char, 10, path_num);
  1333. if (ret < 0)
  1334. pr_err("%s: Invalid tx path = %s\n",
  1335. __func__, w_name);
  1336. err:
  1337. kfree(w_name);
  1338. return ret;
  1339. }
  1340. static int va_macro_dec_mode_get(struct snd_kcontrol *kcontrol,
  1341. struct snd_ctl_elem_value *ucontrol)
  1342. {
  1343. struct snd_soc_component *component =
  1344. snd_soc_kcontrol_component(kcontrol);
  1345. struct va_macro_priv *priv = NULL;
  1346. struct device *va_dev = NULL;
  1347. int ret = 0;
  1348. int path = 0;
  1349. if (!va_macro_get_data(component, &va_dev, &priv, __func__))
  1350. return -EINVAL;
  1351. ret = va_macro_path_get(kcontrol->id.name, &path);
  1352. if (ret)
  1353. return ret;
  1354. ucontrol->value.integer.value[0] = priv->dec_mode[path];
  1355. return 0;
  1356. }
  1357. static int va_macro_dec_mode_put(struct snd_kcontrol *kcontrol,
  1358. struct snd_ctl_elem_value *ucontrol)
  1359. {
  1360. struct snd_soc_component *component =
  1361. snd_soc_kcontrol_component(kcontrol);
  1362. struct va_macro_priv *priv = NULL;
  1363. struct device *va_dev = NULL;
  1364. int value = ucontrol->value.integer.value[0];
  1365. int ret = 0;
  1366. int path = 0;
  1367. if (!va_macro_get_data(component, &va_dev, &priv, __func__))
  1368. return -EINVAL;
  1369. ret = va_macro_path_get(kcontrol->id.name, &path);
  1370. if (ret)
  1371. return ret;
  1372. priv->dec_mode[path] = value;
  1373. return 0;
  1374. }
  1375. static int va_macro_hw_params(struct snd_pcm_substream *substream,
  1376. struct snd_pcm_hw_params *params,
  1377. struct snd_soc_dai *dai)
  1378. {
  1379. int tx_fs_rate = -EINVAL;
  1380. struct snd_soc_component *component = dai->component;
  1381. u32 decimator, sample_rate;
  1382. u16 tx_fs_reg = 0;
  1383. struct device *va_dev = NULL;
  1384. struct va_macro_priv *va_priv = NULL;
  1385. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  1386. return -EINVAL;
  1387. dev_dbg(va_dev,
  1388. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  1389. dai->name, dai->id, params_rate(params),
  1390. params_channels(params));
  1391. sample_rate = params_rate(params);
  1392. if (sample_rate > 16000)
  1393. va_priv->clk_div_switch = true;
  1394. else
  1395. va_priv->clk_div_switch = false;
  1396. switch (sample_rate) {
  1397. case 8000:
  1398. tx_fs_rate = 0;
  1399. break;
  1400. case 16000:
  1401. tx_fs_rate = 1;
  1402. break;
  1403. case 32000:
  1404. tx_fs_rate = 3;
  1405. break;
  1406. case 48000:
  1407. tx_fs_rate = 4;
  1408. break;
  1409. case 96000:
  1410. tx_fs_rate = 5;
  1411. break;
  1412. case 192000:
  1413. tx_fs_rate = 6;
  1414. break;
  1415. case 384000:
  1416. tx_fs_rate = 7;
  1417. break;
  1418. default:
  1419. dev_err(va_dev, "%s: Invalid TX sample rate: %d\n",
  1420. __func__, params_rate(params));
  1421. return -EINVAL;
  1422. }
  1423. for_each_set_bit(decimator, &va_priv->active_ch_mask[dai->id],
  1424. VA_MACRO_DEC_MAX) {
  1425. if (decimator >= 0) {
  1426. tx_fs_reg = BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  1427. VA_MACRO_TX_PATH_OFFSET * decimator;
  1428. dev_dbg(va_dev, "%s: set DEC%u rate to %u\n",
  1429. __func__, decimator, sample_rate);
  1430. snd_soc_component_update_bits(component, tx_fs_reg,
  1431. 0x0F, tx_fs_rate);
  1432. } else {
  1433. dev_err(va_dev,
  1434. "%s: ERROR: Invalid decimator: %d\n",
  1435. __func__, decimator);
  1436. return -EINVAL;
  1437. }
  1438. }
  1439. return 0;
  1440. }
  1441. static int va_macro_get_channel_map(struct snd_soc_dai *dai,
  1442. unsigned int *tx_num, unsigned int *tx_slot,
  1443. unsigned int *rx_num, unsigned int *rx_slot)
  1444. {
  1445. struct snd_soc_component *component = dai->component;
  1446. struct device *va_dev = NULL;
  1447. struct va_macro_priv *va_priv = NULL;
  1448. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  1449. return -EINVAL;
  1450. switch (dai->id) {
  1451. case VA_MACRO_AIF1_CAP:
  1452. case VA_MACRO_AIF2_CAP:
  1453. case VA_MACRO_AIF3_CAP:
  1454. *tx_slot = va_priv->active_ch_mask[dai->id];
  1455. *tx_num = hweight_long(va_priv->active_ch_mask[dai->id]);
  1456. break;
  1457. default:
  1458. dev_err(va_dev, "%s: Invalid AIF\n", __func__);
  1459. break;
  1460. }
  1461. return 0;
  1462. }
  1463. static struct snd_soc_dai_ops va_macro_dai_ops = {
  1464. .hw_params = va_macro_hw_params,
  1465. .get_channel_map = va_macro_get_channel_map,
  1466. };
  1467. static struct snd_soc_dai_driver va_macro_dai[] = {
  1468. {
  1469. .name = "va_macro_tx1",
  1470. .id = VA_MACRO_AIF1_CAP,
  1471. .capture = {
  1472. .stream_name = "VA_AIF1 Capture",
  1473. .rates = VA_MACRO_RATES,
  1474. .formats = VA_MACRO_FORMATS,
  1475. .rate_max = 192000,
  1476. .rate_min = 8000,
  1477. .channels_min = 1,
  1478. .channels_max = 8,
  1479. },
  1480. .ops = &va_macro_dai_ops,
  1481. },
  1482. {
  1483. .name = "va_macro_tx2",
  1484. .id = VA_MACRO_AIF2_CAP,
  1485. .capture = {
  1486. .stream_name = "VA_AIF2 Capture",
  1487. .rates = VA_MACRO_RATES,
  1488. .formats = VA_MACRO_FORMATS,
  1489. .rate_max = 192000,
  1490. .rate_min = 8000,
  1491. .channels_min = 1,
  1492. .channels_max = 8,
  1493. },
  1494. .ops = &va_macro_dai_ops,
  1495. },
  1496. {
  1497. .name = "va_macro_tx3",
  1498. .id = VA_MACRO_AIF3_CAP,
  1499. .capture = {
  1500. .stream_name = "VA_AIF3 Capture",
  1501. .rates = VA_MACRO_RATES,
  1502. .formats = VA_MACRO_FORMATS,
  1503. .rate_max = 192000,
  1504. .rate_min = 8000,
  1505. .channels_min = 1,
  1506. .channels_max = 8,
  1507. },
  1508. .ops = &va_macro_dai_ops,
  1509. },
  1510. };
  1511. #define STRING(name) #name
  1512. #define VA_MACRO_DAPM_ENUM(name, reg, offset, text) \
  1513. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1514. static const struct snd_kcontrol_new name##_mux = \
  1515. SOC_DAPM_ENUM(STRING(name), name##_enum)
  1516. #define VA_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  1517. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1518. static const struct snd_kcontrol_new name##_mux = \
  1519. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  1520. #define VA_MACRO_DAPM_MUX(name, shift, kctl) \
  1521. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  1522. static const char * const adc_mux_text[] = {
  1523. "MSM_DMIC", "SWR_MIC"
  1524. };
  1525. VA_MACRO_DAPM_ENUM(va_dec0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG1,
  1526. 0, adc_mux_text);
  1527. VA_MACRO_DAPM_ENUM(va_dec1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG1,
  1528. 0, adc_mux_text);
  1529. VA_MACRO_DAPM_ENUM(va_dec2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG1,
  1530. 0, adc_mux_text);
  1531. VA_MACRO_DAPM_ENUM(va_dec3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG1,
  1532. 0, adc_mux_text);
  1533. VA_MACRO_DAPM_ENUM(va_dec4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG1,
  1534. 0, adc_mux_text);
  1535. VA_MACRO_DAPM_ENUM(va_dec5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG1,
  1536. 0, adc_mux_text);
  1537. VA_MACRO_DAPM_ENUM(va_dec6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG1,
  1538. 0, adc_mux_text);
  1539. VA_MACRO_DAPM_ENUM(va_dec7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG1,
  1540. 0, adc_mux_text);
  1541. static const char * const dmic_mux_text[] = {
  1542. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  1543. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  1544. };
  1545. VA_MACRO_DAPM_ENUM_EXT(va_dmic0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0,
  1546. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1547. va_macro_put_dec_enum);
  1548. VA_MACRO_DAPM_ENUM_EXT(va_dmic1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0,
  1549. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1550. va_macro_put_dec_enum);
  1551. VA_MACRO_DAPM_ENUM_EXT(va_dmic2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0,
  1552. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1553. va_macro_put_dec_enum);
  1554. VA_MACRO_DAPM_ENUM_EXT(va_dmic3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0,
  1555. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1556. va_macro_put_dec_enum);
  1557. VA_MACRO_DAPM_ENUM_EXT(va_dmic4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0,
  1558. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1559. va_macro_put_dec_enum);
  1560. VA_MACRO_DAPM_ENUM_EXT(va_dmic5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0,
  1561. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1562. va_macro_put_dec_enum);
  1563. VA_MACRO_DAPM_ENUM_EXT(va_dmic6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0,
  1564. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1565. va_macro_put_dec_enum);
  1566. VA_MACRO_DAPM_ENUM_EXT(va_dmic7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0,
  1567. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1568. va_macro_put_dec_enum);
  1569. static const char * const smic_mux_text[] = {
  1570. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3",
  1571. "SWR_DMIC0", "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3",
  1572. "SWR_DMIC4", "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  1573. };
  1574. VA_MACRO_DAPM_ENUM_EXT(va_smic0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0,
  1575. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1576. va_macro_put_dec_enum);
  1577. VA_MACRO_DAPM_ENUM_EXT(va_smic1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0,
  1578. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1579. va_macro_put_dec_enum);
  1580. VA_MACRO_DAPM_ENUM_EXT(va_smic2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0,
  1581. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1582. va_macro_put_dec_enum);
  1583. VA_MACRO_DAPM_ENUM_EXT(va_smic3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0,
  1584. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1585. va_macro_put_dec_enum);
  1586. VA_MACRO_DAPM_ENUM_EXT(va_smic4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0,
  1587. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1588. va_macro_put_dec_enum);
  1589. VA_MACRO_DAPM_ENUM_EXT(va_smic5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0,
  1590. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1591. va_macro_put_dec_enum);
  1592. VA_MACRO_DAPM_ENUM_EXT(va_smic6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0,
  1593. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1594. va_macro_put_dec_enum);
  1595. VA_MACRO_DAPM_ENUM_EXT(va_smic7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0,
  1596. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1597. va_macro_put_dec_enum);
  1598. static const char * const smic_mux_text_v2[] = {
  1599. "ZERO", "SWR_MIC0", "SWR_MIC1", "SWR_MIC2", "SWR_MIC3",
  1600. "SWR_MIC4", "SWR_MIC5", "SWR_MIC6", "SWR_MIC7",
  1601. "SWR_MIC8", "SWR_MIC9", "SWR_MIC10", "SWR_MIC11"
  1602. };
  1603. VA_MACRO_DAPM_ENUM_EXT(va_smic0_v2, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0,
  1604. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1605. va_macro_put_dec_enum);
  1606. VA_MACRO_DAPM_ENUM_EXT(va_smic1_v2, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0,
  1607. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1608. va_macro_put_dec_enum);
  1609. VA_MACRO_DAPM_ENUM_EXT(va_smic2_v3, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0,
  1610. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1611. va_macro_put_dec_enum);
  1612. VA_MACRO_DAPM_ENUM_EXT(va_smic3_v3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0,
  1613. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1614. va_macro_put_dec_enum);
  1615. static const struct snd_kcontrol_new va_aif1_cap_mixer[] = {
  1616. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1617. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1618. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1619. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1620. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1621. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1622. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1623. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1624. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  1625. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1626. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  1627. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1628. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  1629. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1630. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  1631. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1632. };
  1633. static const struct snd_kcontrol_new va_aif2_cap_mixer[] = {
  1634. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1635. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1636. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1637. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1638. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1639. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1640. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1641. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1642. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  1643. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1644. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  1645. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1646. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  1647. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1648. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  1649. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1650. };
  1651. static const struct snd_kcontrol_new va_aif3_cap_mixer[] = {
  1652. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1653. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1654. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1655. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1656. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1657. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1658. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1659. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1660. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  1661. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1662. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  1663. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1664. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  1665. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1666. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  1667. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1668. };
  1669. static const struct snd_kcontrol_new va_aif1_cap_mixer_v2[] = {
  1670. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1671. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1672. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1673. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1674. };
  1675. static const struct snd_kcontrol_new va_aif2_cap_mixer_v2[] = {
  1676. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1677. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1678. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1679. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1680. };
  1681. static const struct snd_kcontrol_new va_aif3_cap_mixer_v2[] = {
  1682. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1683. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1684. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1685. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1686. };
  1687. static const struct snd_kcontrol_new va_aif1_cap_mixer_v3[] = {
  1688. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1689. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1690. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1691. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1692. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1693. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1694. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1695. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1696. };
  1697. static const struct snd_kcontrol_new va_aif2_cap_mixer_v3[] = {
  1698. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1699. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1700. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1701. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1702. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1703. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1704. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1705. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1706. };
  1707. static const struct snd_kcontrol_new va_aif3_cap_mixer_v3[] = {
  1708. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1709. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1710. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1711. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1712. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1713. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1714. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1715. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1716. };
  1717. static const struct snd_soc_dapm_widget va_macro_dapm_widgets_common[] = {
  1718. SND_SOC_DAPM_AIF_OUT_E("VA_AIF1 CAP", "VA_AIF1 Capture", 0,
  1719. SND_SOC_NOPM, VA_MACRO_AIF1_CAP, 0,
  1720. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1721. SND_SOC_DAPM_PRE_PMD),
  1722. SND_SOC_DAPM_AIF_OUT_E("VA_AIF2 CAP", "VA_AIF2 Capture", 0,
  1723. SND_SOC_NOPM, VA_MACRO_AIF2_CAP, 0,
  1724. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1725. SND_SOC_DAPM_PRE_PMD),
  1726. SND_SOC_DAPM_AIF_OUT_E("VA_AIF3 CAP", "VA_AIF3 Capture", 0,
  1727. SND_SOC_NOPM, VA_MACRO_AIF3_CAP, 0,
  1728. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1729. SND_SOC_DAPM_PRE_PMD),
  1730. VA_MACRO_DAPM_MUX("VA DMIC MUX0", 0, va_dmic0),
  1731. VA_MACRO_DAPM_MUX("VA DMIC MUX1", 0, va_dmic1),
  1732. VA_MACRO_DAPM_MUX("VA SMIC MUX0", 0, va_smic0_v2),
  1733. VA_MACRO_DAPM_MUX("VA SMIC MUX1", 0, va_smic1_v2),
  1734. SND_SOC_DAPM_INPUT("VA SWR_INPUT"),
  1735. SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1736. va_macro_enable_micbias,
  1737. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1738. SND_SOC_DAPM_ADC_E("VA DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1739. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1740. SND_SOC_DAPM_POST_PMD),
  1741. SND_SOC_DAPM_ADC_E("VA DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1742. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1743. SND_SOC_DAPM_POST_PMD),
  1744. SND_SOC_DAPM_ADC_E("VA DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1745. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1746. SND_SOC_DAPM_POST_PMD),
  1747. SND_SOC_DAPM_ADC_E("VA DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1748. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1749. SND_SOC_DAPM_POST_PMD),
  1750. SND_SOC_DAPM_ADC_E("VA DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1751. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1752. SND_SOC_DAPM_POST_PMD),
  1753. SND_SOC_DAPM_ADC_E("VA DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1754. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1755. SND_SOC_DAPM_POST_PMD),
  1756. SND_SOC_DAPM_ADC_E("VA DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1757. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1758. SND_SOC_DAPM_POST_PMD),
  1759. SND_SOC_DAPM_ADC_E("VA DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1760. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1761. SND_SOC_DAPM_POST_PMD),
  1762. SND_SOC_DAPM_MUX_E("VA DEC0 MUX", SND_SOC_NOPM, VA_MACRO_DEC0, 0,
  1763. &va_dec0_mux, va_macro_enable_dec,
  1764. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1765. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1766. SND_SOC_DAPM_MUX_E("VA DEC1 MUX", SND_SOC_NOPM, VA_MACRO_DEC1, 0,
  1767. &va_dec1_mux, va_macro_enable_dec,
  1768. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1769. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1770. SND_SOC_DAPM_SUPPLY_S("VA_MCLK", -1, SND_SOC_NOPM, 0, 0,
  1771. va_macro_mclk_event,
  1772. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1773. };
  1774. static const struct snd_soc_dapm_widget va_macro_dapm_widgets_v2[] = {
  1775. SND_SOC_DAPM_MIXER("VA_AIF1_CAP Mixer", SND_SOC_NOPM,
  1776. VA_MACRO_AIF1_CAP, 0,
  1777. va_aif1_cap_mixer_v2, ARRAY_SIZE(va_aif1_cap_mixer_v2)),
  1778. SND_SOC_DAPM_MIXER("VA_AIF2_CAP Mixer", SND_SOC_NOPM,
  1779. VA_MACRO_AIF2_CAP, 0,
  1780. va_aif2_cap_mixer_v2, ARRAY_SIZE(va_aif2_cap_mixer_v2)),
  1781. SND_SOC_DAPM_MIXER("VA_AIF3_CAP Mixer", SND_SOC_NOPM,
  1782. VA_MACRO_AIF3_CAP, 0,
  1783. va_aif3_cap_mixer_v2, ARRAY_SIZE(va_aif3_cap_mixer_v2)),
  1784. SND_SOC_DAPM_SUPPLY_S("VA_SWR_PWR", 0, SND_SOC_NOPM, 0, 0,
  1785. va_macro_swr_pwr_event_v2,
  1786. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1787. SND_SOC_DAPM_SUPPLY_S("VA_TX_SWR_CLK", -1, SND_SOC_NOPM, 0, 0,
  1788. va_macro_tx_swr_clk_event_v2,
  1789. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1790. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", -1, SND_SOC_NOPM, 0, 0,
  1791. va_macro_swr_clk_event_v2,
  1792. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1793. };
  1794. static const struct snd_soc_dapm_widget va_macro_dapm_widgets_v3[] = {
  1795. SND_SOC_DAPM_MIXER("VA_AIF1_CAP Mixer", SND_SOC_NOPM,
  1796. VA_MACRO_AIF1_CAP, 0,
  1797. va_aif1_cap_mixer_v3, ARRAY_SIZE(va_aif1_cap_mixer_v3)),
  1798. SND_SOC_DAPM_MIXER("VA_AIF2_CAP Mixer", SND_SOC_NOPM,
  1799. VA_MACRO_AIF2_CAP, 0,
  1800. va_aif2_cap_mixer_v3, ARRAY_SIZE(va_aif2_cap_mixer_v3)),
  1801. SND_SOC_DAPM_MIXER("VA_AIF3_CAP Mixer", SND_SOC_NOPM,
  1802. VA_MACRO_AIF3_CAP, 0,
  1803. va_aif3_cap_mixer_v3, ARRAY_SIZE(va_aif3_cap_mixer_v3)),
  1804. VA_MACRO_DAPM_MUX("VA DMIC MUX2", 0, va_dmic2),
  1805. VA_MACRO_DAPM_MUX("VA DMIC MUX3", 0, va_dmic3),
  1806. VA_MACRO_DAPM_MUX("VA SMIC MUX2", 0, va_smic2_v3),
  1807. VA_MACRO_DAPM_MUX("VA SMIC MUX3", 0, va_smic3_v3),
  1808. SND_SOC_DAPM_MUX_E("VA DEC2 MUX", SND_SOC_NOPM, VA_MACRO_DEC2, 0,
  1809. &va_dec2_mux, va_macro_enable_dec,
  1810. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1811. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1812. SND_SOC_DAPM_MUX_E("VA DEC3 MUX", SND_SOC_NOPM, VA_MACRO_DEC3, 0,
  1813. &va_dec3_mux, va_macro_enable_dec,
  1814. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1815. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1816. SND_SOC_DAPM_SUPPLY_S("VA_SWR_PWR", 0, SND_SOC_NOPM, 0, 0,
  1817. va_macro_swr_pwr_event,
  1818. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1819. };
  1820. static const struct snd_soc_dapm_widget va_macro_dapm_widgets[] = {
  1821. SND_SOC_DAPM_AIF_OUT_E("VA_AIF1 CAP", "VA_AIF1 Capture", 0,
  1822. SND_SOC_NOPM, VA_MACRO_AIF1_CAP, 0,
  1823. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1824. SND_SOC_DAPM_PRE_PMD),
  1825. SND_SOC_DAPM_AIF_OUT_E("VA_AIF2 CAP", "VA_AIF2 Capture", 0,
  1826. SND_SOC_NOPM, VA_MACRO_AIF2_CAP, 0,
  1827. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1828. SND_SOC_DAPM_PRE_PMD),
  1829. SND_SOC_DAPM_AIF_OUT_E("VA_AIF3 CAP", "VA_AIF3 Capture", 0,
  1830. SND_SOC_NOPM, VA_MACRO_AIF3_CAP, 0,
  1831. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1832. SND_SOC_DAPM_PRE_PMD),
  1833. SND_SOC_DAPM_MIXER("VA_AIF1_CAP Mixer", SND_SOC_NOPM,
  1834. VA_MACRO_AIF1_CAP, 0,
  1835. va_aif1_cap_mixer, ARRAY_SIZE(va_aif1_cap_mixer)),
  1836. SND_SOC_DAPM_MIXER("VA_AIF2_CAP Mixer", SND_SOC_NOPM,
  1837. VA_MACRO_AIF2_CAP, 0,
  1838. va_aif2_cap_mixer, ARRAY_SIZE(va_aif2_cap_mixer)),
  1839. SND_SOC_DAPM_MIXER("VA_AIF3_CAP Mixer", SND_SOC_NOPM,
  1840. VA_MACRO_AIF3_CAP, 0,
  1841. va_aif3_cap_mixer, ARRAY_SIZE(va_aif3_cap_mixer)),
  1842. VA_MACRO_DAPM_MUX("VA DMIC MUX0", 0, va_dmic0),
  1843. VA_MACRO_DAPM_MUX("VA DMIC MUX1", 0, va_dmic1),
  1844. VA_MACRO_DAPM_MUX("VA DMIC MUX2", 0, va_dmic2),
  1845. VA_MACRO_DAPM_MUX("VA DMIC MUX3", 0, va_dmic3),
  1846. VA_MACRO_DAPM_MUX("VA DMIC MUX4", 0, va_dmic4),
  1847. VA_MACRO_DAPM_MUX("VA DMIC MUX5", 0, va_dmic5),
  1848. VA_MACRO_DAPM_MUX("VA DMIC MUX6", 0, va_dmic6),
  1849. VA_MACRO_DAPM_MUX("VA DMIC MUX7", 0, va_dmic7),
  1850. VA_MACRO_DAPM_MUX("VA SMIC MUX0", 0, va_smic0),
  1851. VA_MACRO_DAPM_MUX("VA SMIC MUX1", 0, va_smic1),
  1852. VA_MACRO_DAPM_MUX("VA SMIC MUX2", 0, va_smic2),
  1853. VA_MACRO_DAPM_MUX("VA SMIC MUX3", 0, va_smic3),
  1854. VA_MACRO_DAPM_MUX("VA SMIC MUX4", 0, va_smic4),
  1855. VA_MACRO_DAPM_MUX("VA SMIC MUX5", 0, va_smic5),
  1856. VA_MACRO_DAPM_MUX("VA SMIC MUX6", 0, va_smic6),
  1857. VA_MACRO_DAPM_MUX("VA SMIC MUX7", 0, va_smic7),
  1858. SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1859. va_macro_enable_micbias,
  1860. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1861. SND_SOC_DAPM_ADC_E("VA DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1862. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1863. SND_SOC_DAPM_POST_PMD),
  1864. SND_SOC_DAPM_ADC_E("VA DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1865. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1866. SND_SOC_DAPM_POST_PMD),
  1867. SND_SOC_DAPM_ADC_E("VA DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1868. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1869. SND_SOC_DAPM_POST_PMD),
  1870. SND_SOC_DAPM_ADC_E("VA DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1871. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1872. SND_SOC_DAPM_POST_PMD),
  1873. SND_SOC_DAPM_ADC_E("VA DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1874. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1875. SND_SOC_DAPM_POST_PMD),
  1876. SND_SOC_DAPM_ADC_E("VA DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1877. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1878. SND_SOC_DAPM_POST_PMD),
  1879. SND_SOC_DAPM_ADC_E("VA DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1880. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1881. SND_SOC_DAPM_POST_PMD),
  1882. SND_SOC_DAPM_ADC_E("VA DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1883. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1884. SND_SOC_DAPM_POST_PMD),
  1885. SND_SOC_DAPM_INPUT("VA SWR_ADC0"),
  1886. SND_SOC_DAPM_INPUT("VA SWR_ADC1"),
  1887. SND_SOC_DAPM_INPUT("VA SWR_ADC2"),
  1888. SND_SOC_DAPM_INPUT("VA SWR_ADC3"),
  1889. SND_SOC_DAPM_INPUT("VA SWR_MIC0"),
  1890. SND_SOC_DAPM_INPUT("VA SWR_MIC1"),
  1891. SND_SOC_DAPM_INPUT("VA SWR_MIC2"),
  1892. SND_SOC_DAPM_INPUT("VA SWR_MIC3"),
  1893. SND_SOC_DAPM_INPUT("VA SWR_MIC4"),
  1894. SND_SOC_DAPM_INPUT("VA SWR_MIC5"),
  1895. SND_SOC_DAPM_INPUT("VA SWR_MIC6"),
  1896. SND_SOC_DAPM_INPUT("VA SWR_MIC7"),
  1897. SND_SOC_DAPM_MUX_E("VA DEC0 MUX", SND_SOC_NOPM, VA_MACRO_DEC0, 0,
  1898. &va_dec0_mux, va_macro_enable_dec,
  1899. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1900. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1901. SND_SOC_DAPM_MUX_E("VA DEC1 MUX", SND_SOC_NOPM, VA_MACRO_DEC1, 0,
  1902. &va_dec1_mux, va_macro_enable_dec,
  1903. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1904. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1905. SND_SOC_DAPM_MUX_E("VA DEC2 MUX", SND_SOC_NOPM, VA_MACRO_DEC2, 0,
  1906. &va_dec2_mux, va_macro_enable_dec,
  1907. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1908. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1909. SND_SOC_DAPM_MUX_E("VA DEC3 MUX", SND_SOC_NOPM, VA_MACRO_DEC3, 0,
  1910. &va_dec3_mux, va_macro_enable_dec,
  1911. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1912. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1913. SND_SOC_DAPM_MUX_E("VA DEC4 MUX", SND_SOC_NOPM, VA_MACRO_DEC4, 0,
  1914. &va_dec4_mux, va_macro_enable_dec,
  1915. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1916. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1917. SND_SOC_DAPM_MUX_E("VA DEC5 MUX", SND_SOC_NOPM, VA_MACRO_DEC5, 0,
  1918. &va_dec5_mux, va_macro_enable_dec,
  1919. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1920. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1921. SND_SOC_DAPM_MUX_E("VA DEC6 MUX", SND_SOC_NOPM, VA_MACRO_DEC6, 0,
  1922. &va_dec6_mux, va_macro_enable_dec,
  1923. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1924. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1925. SND_SOC_DAPM_MUX_E("VA DEC7 MUX", SND_SOC_NOPM, VA_MACRO_DEC7, 0,
  1926. &va_dec7_mux, va_macro_enable_dec,
  1927. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1928. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1929. SND_SOC_DAPM_SUPPLY_S("VA_SWR_PWR", -1, SND_SOC_NOPM, 0, 0,
  1930. va_macro_swr_pwr_event,
  1931. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1932. SND_SOC_DAPM_SUPPLY_S("VA_MCLK", -1, SND_SOC_NOPM, 0, 0,
  1933. va_macro_mclk_event,
  1934. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1935. };
  1936. static const struct snd_soc_dapm_widget va_macro_wod_dapm_widgets[] = {
  1937. SND_SOC_DAPM_SUPPLY_S("VA_MCLK", -1, SND_SOC_NOPM, 0, 0,
  1938. va_macro_mclk_event,
  1939. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1940. };
  1941. static const struct snd_soc_dapm_route va_audio_map_common[] = {
  1942. {"VA_AIF1 CAP", NULL, "VA_MCLK"},
  1943. {"VA_AIF2 CAP", NULL, "VA_MCLK"},
  1944. {"VA_AIF3 CAP", NULL, "VA_MCLK"},
  1945. {"VA_AIF1 CAP", NULL, "VA_AIF1_CAP Mixer"},
  1946. {"VA_AIF2 CAP", NULL, "VA_AIF2_CAP Mixer"},
  1947. {"VA_AIF3 CAP", NULL, "VA_AIF3_CAP Mixer"},
  1948. {"VA_AIF1_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  1949. {"VA_AIF1_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  1950. {"VA_AIF2_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  1951. {"VA_AIF2_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  1952. {"VA_AIF3_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  1953. {"VA_AIF3_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  1954. {"VA DEC0 MUX", "MSM_DMIC", "VA DMIC MUX0"},
  1955. {"VA DMIC MUX0", "DMIC0", "VA DMIC0"},
  1956. {"VA DMIC MUX0", "DMIC1", "VA DMIC1"},
  1957. {"VA DMIC MUX0", "DMIC2", "VA DMIC2"},
  1958. {"VA DMIC MUX0", "DMIC3", "VA DMIC3"},
  1959. {"VA DMIC MUX0", "DMIC4", "VA DMIC4"},
  1960. {"VA DMIC MUX0", "DMIC5", "VA DMIC5"},
  1961. {"VA DMIC MUX0", "DMIC6", "VA DMIC6"},
  1962. {"VA DMIC MUX0", "DMIC7", "VA DMIC7"},
  1963. {"VA DEC0 MUX", "SWR_MIC", "VA SMIC MUX0"},
  1964. {"VA SMIC MUX0", "SWR_MIC0", "VA SWR_INPUT"},
  1965. {"VA SMIC MUX0", "SWR_MIC1", "VA SWR_INPUT"},
  1966. {"VA SMIC MUX0", "SWR_MIC2", "VA SWR_INPUT"},
  1967. {"VA SMIC MUX0", "SWR_MIC3", "VA SWR_INPUT"},
  1968. {"VA SMIC MUX0", "SWR_MIC4", "VA SWR_INPUT"},
  1969. {"VA SMIC MUX0", "SWR_MIC5", "VA SWR_INPUT"},
  1970. {"VA SMIC MUX0", "SWR_MIC6", "VA SWR_INPUT"},
  1971. {"VA SMIC MUX0", "SWR_MIC7", "VA SWR_INPUT"},
  1972. {"VA SMIC MUX0", "SWR_MIC8", "VA SWR_INPUT"},
  1973. {"VA SMIC MUX0", "SWR_MIC9", "VA SWR_INPUT"},
  1974. {"VA SMIC MUX0", "SWR_MIC10", "VA SWR_INPUT"},
  1975. {"VA SMIC MUX0", "SWR_MIC11", "VA SWR_INPUT"},
  1976. {"VA DEC1 MUX", "MSM_DMIC", "VA DMIC MUX1"},
  1977. {"VA DMIC MUX1", "DMIC0", "VA DMIC0"},
  1978. {"VA DMIC MUX1", "DMIC1", "VA DMIC1"},
  1979. {"VA DMIC MUX1", "DMIC2", "VA DMIC2"},
  1980. {"VA DMIC MUX1", "DMIC3", "VA DMIC3"},
  1981. {"VA DMIC MUX1", "DMIC4", "VA DMIC4"},
  1982. {"VA DMIC MUX1", "DMIC5", "VA DMIC5"},
  1983. {"VA DMIC MUX1", "DMIC6", "VA DMIC6"},
  1984. {"VA DMIC MUX1", "DMIC7", "VA DMIC7"},
  1985. {"VA DEC1 MUX", "SWR_MIC", "VA SMIC MUX1"},
  1986. {"VA SMIC MUX1", "SWR_MIC0", "VA SWR_INPUT"},
  1987. {"VA SMIC MUX1", "SWR_MIC1", "VA SWR_INPUT"},
  1988. {"VA SMIC MUX1", "SWR_MIC2", "VA SWR_INPUT"},
  1989. {"VA SMIC MUX1", "SWR_MIC3", "VA SWR_INPUT"},
  1990. {"VA SMIC MUX1", "SWR_MIC4", "VA SWR_INPUT"},
  1991. {"VA SMIC MUX1", "SWR_MIC5", "VA SWR_INPUT"},
  1992. {"VA SMIC MUX1", "SWR_MIC6", "VA SWR_INPUT"},
  1993. {"VA SMIC MUX1", "SWR_MIC7", "VA SWR_INPUT"},
  1994. {"VA SMIC MUX1", "SWR_MIC8", "VA SWR_INPUT"},
  1995. {"VA SMIC MUX1", "SWR_MIC9", "VA SWR_INPUT"},
  1996. {"VA SMIC MUX1", "SWR_MIC10", "VA SWR_INPUT"},
  1997. {"VA SMIC MUX1", "SWR_MIC11", "VA SWR_INPUT"},
  1998. {"VA SWR_INPUT", NULL, "VA_SWR_PWR"},
  1999. };
  2000. static const struct snd_soc_dapm_route va_audio_map_v3[] = {
  2001. {"VA_AIF1_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  2002. {"VA_AIF1_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  2003. {"VA_AIF2_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  2004. {"VA_AIF2_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  2005. {"VA_AIF3_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  2006. {"VA_AIF3_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  2007. {"VA DEC2 MUX", "MSM_DMIC", "VA DMIC MUX2"},
  2008. {"VA DMIC MUX2", "DMIC0", "VA DMIC0"},
  2009. {"VA DMIC MUX2", "DMIC1", "VA DMIC1"},
  2010. {"VA DMIC MUX2", "DMIC2", "VA DMIC2"},
  2011. {"VA DMIC MUX2", "DMIC3", "VA DMIC3"},
  2012. {"VA DMIC MUX2", "DMIC4", "VA DMIC4"},
  2013. {"VA DMIC MUX2", "DMIC5", "VA DMIC5"},
  2014. {"VA DMIC MUX2", "DMIC6", "VA DMIC6"},
  2015. {"VA DMIC MUX2", "DMIC7", "VA DMIC7"},
  2016. {"VA DEC2 MUX", "SWR_MIC", "VA SMIC MUX2"},
  2017. {"VA SMIC MUX2", "SWR_MIC0", "VA SWR_INPUT"},
  2018. {"VA SMIC MUX2", "SWR_MIC1", "VA SWR_INPUT"},
  2019. {"VA SMIC MUX2", "SWR_MIC2", "VA SWR_INPUT"},
  2020. {"VA SMIC MUX2", "SWR_MIC3", "VA SWR_INPUT"},
  2021. {"VA SMIC MUX2", "SWR_MIC4", "VA SWR_INPUT"},
  2022. {"VA SMIC MUX2", "SWR_MIC5", "VA SWR_INPUT"},
  2023. {"VA SMIC MUX2", "SWR_MIC6", "VA SWR_INPUT"},
  2024. {"VA SMIC MUX2", "SWR_MIC7", "VA SWR_INPUT"},
  2025. {"VA SMIC MUX2", "SWR_MIC8", "VA SWR_INPUT"},
  2026. {"VA SMIC MUX2", "SWR_MIC9", "VA SWR_INPUT"},
  2027. {"VA SMIC MUX2", "SWR_MIC10", "VA SWR_INPUT"},
  2028. {"VA SMIC MUX2", "SWR_MIC11", "VA SWR_INPUT"},
  2029. {"VA DEC3 MUX", "MSM_DMIC", "VA DMIC MUX3"},
  2030. {"VA DMIC MUX3", "DMIC0", "VA DMIC0"},
  2031. {"VA DMIC MUX3", "DMIC1", "VA DMIC1"},
  2032. {"VA DMIC MUX3", "DMIC2", "VA DMIC2"},
  2033. {"VA DMIC MUX3", "DMIC3", "VA DMIC3"},
  2034. {"VA DMIC MUX3", "DMIC4", "VA DMIC4"},
  2035. {"VA DMIC MUX3", "DMIC5", "VA DMIC5"},
  2036. {"VA DMIC MUX3", "DMIC6", "VA DMIC6"},
  2037. {"VA DMIC MUX3", "DMIC7", "VA DMIC7"},
  2038. {"VA DEC3 MUX", "SWR_MIC", "VA SMIC MUX3"},
  2039. {"VA SMIC MUX3", "SWR_MIC0", "VA SWR_INPUT"},
  2040. {"VA SMIC MUX3", "SWR_MIC1", "VA SWR_INPUT"},
  2041. {"VA SMIC MUX3", "SWR_MIC2", "VA SWR_INPUT"},
  2042. {"VA SMIC MUX3", "SWR_MIC3", "VA SWR_INPUT"},
  2043. {"VA SMIC MUX3", "SWR_MIC4", "VA SWR_INPUT"},
  2044. {"VA SMIC MUX3", "SWR_MIC5", "VA SWR_INPUT"},
  2045. {"VA SMIC MUX3", "SWR_MIC6", "VA SWR_INPUT"},
  2046. {"VA SMIC MUX3", "SWR_MIC7", "VA SWR_INPUT"},
  2047. {"VA SMIC MUX3", "SWR_MIC8", "VA SWR_INPUT"},
  2048. {"VA SMIC MUX3", "SWR_MIC9", "VA SWR_INPUT"},
  2049. {"VA SMIC MUX3", "SWR_MIC10", "VA SWR_INPUT"},
  2050. {"VA SMIC MUX3", "SWR_MIC11", "VA SWR_INPUT"},
  2051. };
  2052. static const struct snd_soc_dapm_route va_audio_map_v2[] = {
  2053. {"VA SWR_INPUT", NULL, "VA_SWR_CLK"},
  2054. };
  2055. static const struct snd_soc_dapm_route va_audio_map[] = {
  2056. {"VA_AIF1 CAP", NULL, "VA_MCLK"},
  2057. {"VA_AIF2 CAP", NULL, "VA_MCLK"},
  2058. {"VA_AIF3 CAP", NULL, "VA_MCLK"},
  2059. {"VA_AIF1 CAP", NULL, "VA_AIF1_CAP Mixer"},
  2060. {"VA_AIF2 CAP", NULL, "VA_AIF2_CAP Mixer"},
  2061. {"VA_AIF3 CAP", NULL, "VA_AIF3_CAP Mixer"},
  2062. {"VA_AIF1_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  2063. {"VA_AIF1_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  2064. {"VA_AIF1_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  2065. {"VA_AIF1_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  2066. {"VA_AIF1_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  2067. {"VA_AIF1_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  2068. {"VA_AIF1_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  2069. {"VA_AIF1_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  2070. {"VA_AIF2_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  2071. {"VA_AIF2_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  2072. {"VA_AIF2_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  2073. {"VA_AIF2_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  2074. {"VA_AIF2_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  2075. {"VA_AIF2_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  2076. {"VA_AIF2_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  2077. {"VA_AIF2_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  2078. {"VA_AIF3_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  2079. {"VA_AIF3_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  2080. {"VA_AIF3_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  2081. {"VA_AIF3_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  2082. {"VA_AIF3_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  2083. {"VA_AIF3_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  2084. {"VA_AIF3_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  2085. {"VA_AIF3_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  2086. {"VA DEC0 MUX", "MSM_DMIC", "VA DMIC MUX0"},
  2087. {"VA DMIC MUX0", "DMIC0", "VA DMIC0"},
  2088. {"VA DMIC MUX0", "DMIC1", "VA DMIC1"},
  2089. {"VA DMIC MUX0", "DMIC2", "VA DMIC2"},
  2090. {"VA DMIC MUX0", "DMIC3", "VA DMIC3"},
  2091. {"VA DMIC MUX0", "DMIC4", "VA DMIC4"},
  2092. {"VA DMIC MUX0", "DMIC5", "VA DMIC5"},
  2093. {"VA DMIC MUX0", "DMIC6", "VA DMIC6"},
  2094. {"VA DMIC MUX0", "DMIC7", "VA DMIC7"},
  2095. {"VA DEC0 MUX", "SWR_MIC", "VA SMIC MUX0"},
  2096. {"VA SMIC MUX0", "ADC0", "VA SWR_ADC0"},
  2097. {"VA SMIC MUX0", "ADC1", "VA SWR_ADC1"},
  2098. {"VA SMIC MUX0", "ADC2", "VA SWR_ADC2"},
  2099. {"VA SMIC MUX0", "ADC3", "VA SWR_ADC3"},
  2100. {"VA SMIC MUX0", "SWR_DMIC0", "VA SWR_MIC0"},
  2101. {"VA SMIC MUX0", "SWR_DMIC1", "VA SWR_MIC1"},
  2102. {"VA SMIC MUX0", "SWR_DMIC2", "VA SWR_MIC2"},
  2103. {"VA SMIC MUX0", "SWR_DMIC3", "VA SWR_MIC3"},
  2104. {"VA SMIC MUX0", "SWR_DMIC4", "VA SWR_MIC4"},
  2105. {"VA SMIC MUX0", "SWR_DMIC5", "VA SWR_MIC5"},
  2106. {"VA SMIC MUX0", "SWR_DMIC6", "VA SWR_MIC6"},
  2107. {"VA SMIC MUX0", "SWR_DMIC7", "VA SWR_MIC7"},
  2108. {"VA DEC1 MUX", "MSM_DMIC", "VA DMIC MUX1"},
  2109. {"VA DMIC MUX1", "DMIC0", "VA DMIC0"},
  2110. {"VA DMIC MUX1", "DMIC1", "VA DMIC1"},
  2111. {"VA DMIC MUX1", "DMIC2", "VA DMIC2"},
  2112. {"VA DMIC MUX1", "DMIC3", "VA DMIC3"},
  2113. {"VA DMIC MUX1", "DMIC4", "VA DMIC4"},
  2114. {"VA DMIC MUX1", "DMIC5", "VA DMIC5"},
  2115. {"VA DMIC MUX1", "DMIC6", "VA DMIC6"},
  2116. {"VA DMIC MUX1", "DMIC7", "VA DMIC7"},
  2117. {"VA DEC1 MUX", "SWR_MIC", "VA SMIC MUX1"},
  2118. {"VA SMIC MUX1", "ADC0", "VA SWR_ADC0"},
  2119. {"VA SMIC MUX1", "ADC1", "VA SWR_ADC1"},
  2120. {"VA SMIC MUX1", "ADC2", "VA SWR_ADC2"},
  2121. {"VA SMIC MUX1", "ADC3", "VA SWR_ADC3"},
  2122. {"VA SMIC MUX1", "SWR_DMIC0", "VA SWR_MIC0"},
  2123. {"VA SMIC MUX1", "SWR_DMIC1", "VA SWR_MIC1"},
  2124. {"VA SMIC MUX1", "SWR_DMIC2", "VA SWR_MIC2"},
  2125. {"VA SMIC MUX1", "SWR_DMIC3", "VA SWR_MIC3"},
  2126. {"VA SMIC MUX1", "SWR_DMIC4", "VA SWR_MIC4"},
  2127. {"VA SMIC MUX1", "SWR_DMIC5", "VA SWR_MIC5"},
  2128. {"VA SMIC MUX1", "SWR_DMIC6", "VA SWR_MIC6"},
  2129. {"VA SMIC MUX1", "SWR_DMIC7", "VA SWR_MIC7"},
  2130. {"VA DEC2 MUX", "MSM_DMIC", "VA DMIC MUX2"},
  2131. {"VA DMIC MUX2", "DMIC0", "VA DMIC0"},
  2132. {"VA DMIC MUX2", "DMIC1", "VA DMIC1"},
  2133. {"VA DMIC MUX2", "DMIC2", "VA DMIC2"},
  2134. {"VA DMIC MUX2", "DMIC3", "VA DMIC3"},
  2135. {"VA DMIC MUX2", "DMIC4", "VA DMIC4"},
  2136. {"VA DMIC MUX2", "DMIC5", "VA DMIC5"},
  2137. {"VA DMIC MUX2", "DMIC6", "VA DMIC6"},
  2138. {"VA DMIC MUX2", "DMIC7", "VA DMIC7"},
  2139. {"VA DEC2 MUX", "SWR_MIC", "VA SMIC MUX2"},
  2140. {"VA SMIC MUX2", "ADC0", "VA SWR_ADC0"},
  2141. {"VA SMIC MUX2", "ADC1", "VA SWR_ADC1"},
  2142. {"VA SMIC MUX2", "ADC2", "VA SWR_ADC2"},
  2143. {"VA SMIC MUX2", "ADC3", "VA SWR_ADC3"},
  2144. {"VA SMIC MUX2", "SWR_DMIC0", "VA SWR_MIC0"},
  2145. {"VA SMIC MUX2", "SWR_DMIC1", "VA SWR_MIC1"},
  2146. {"VA SMIC MUX2", "SWR_DMIC2", "VA SWR_MIC2"},
  2147. {"VA SMIC MUX2", "SWR_DMIC3", "VA SWR_MIC3"},
  2148. {"VA SMIC MUX2", "SWR_DMIC4", "VA SWR_MIC4"},
  2149. {"VA SMIC MUX2", "SWR_DMIC5", "VA SWR_MIC5"},
  2150. {"VA SMIC MUX2", "SWR_DMIC6", "VA SWR_MIC6"},
  2151. {"VA SMIC MUX2", "SWR_DMIC7", "VA SWR_MIC7"},
  2152. {"VA DEC3 MUX", "MSM_DMIC", "VA DMIC MUX3"},
  2153. {"VA DMIC MUX3", "DMIC0", "VA DMIC0"},
  2154. {"VA DMIC MUX3", "DMIC1", "VA DMIC1"},
  2155. {"VA DMIC MUX3", "DMIC2", "VA DMIC2"},
  2156. {"VA DMIC MUX3", "DMIC3", "VA DMIC3"},
  2157. {"VA DMIC MUX3", "DMIC4", "VA DMIC4"},
  2158. {"VA DMIC MUX3", "DMIC5", "VA DMIC5"},
  2159. {"VA DMIC MUX3", "DMIC6", "VA DMIC6"},
  2160. {"VA DMIC MUX3", "DMIC7", "VA DMIC7"},
  2161. {"VA DEC3 MUX", "SWR_MIC", "VA SMIC MUX3"},
  2162. {"VA SMIC MUX3", "ADC0", "VA SWR_ADC0"},
  2163. {"VA SMIC MUX3", "ADC1", "VA SWR_ADC1"},
  2164. {"VA SMIC MUX3", "ADC2", "VA SWR_ADC2"},
  2165. {"VA SMIC MUX3", "ADC3", "VA SWR_ADC3"},
  2166. {"VA SMIC MUX3", "SWR_DMIC0", "VA SWR_MIC0"},
  2167. {"VA SMIC MUX3", "SWR_DMIC1", "VA SWR_MIC1"},
  2168. {"VA SMIC MUX3", "SWR_DMIC2", "VA SWR_MIC2"},
  2169. {"VA SMIC MUX3", "SWR_DMIC3", "VA SWR_MIC3"},
  2170. {"VA SMIC MUX3", "SWR_DMIC4", "VA SWR_MIC4"},
  2171. {"VA SMIC MUX3", "SWR_DMIC5", "VA SWR_MIC5"},
  2172. {"VA SMIC MUX3", "SWR_DMIC6", "VA SWR_MIC6"},
  2173. {"VA SMIC MUX3", "SWR_DMIC7", "VA SWR_MIC7"},
  2174. {"VA DEC4 MUX", "MSM_DMIC", "VA DMIC MUX4"},
  2175. {"VA DMIC MUX4", "DMIC0", "VA DMIC0"},
  2176. {"VA DMIC MUX4", "DMIC1", "VA DMIC1"},
  2177. {"VA DMIC MUX4", "DMIC2", "VA DMIC2"},
  2178. {"VA DMIC MUX4", "DMIC3", "VA DMIC3"},
  2179. {"VA DMIC MUX4", "DMIC4", "VA DMIC4"},
  2180. {"VA DMIC MUX4", "DMIC5", "VA DMIC5"},
  2181. {"VA DMIC MUX4", "DMIC6", "VA DMIC6"},
  2182. {"VA DMIC MUX4", "DMIC7", "VA DMIC7"},
  2183. {"VA DEC4 MUX", "SWR_MIC", "VA SMIC MUX4"},
  2184. {"VA SMIC MUX4", "ADC0", "VA SWR_ADC0"},
  2185. {"VA SMIC MUX4", "ADC1", "VA SWR_ADC1"},
  2186. {"VA SMIC MUX4", "ADC2", "VA SWR_ADC2"},
  2187. {"VA SMIC MUX4", "ADC3", "VA SWR_ADC3"},
  2188. {"VA SMIC MUX4", "SWR_DMIC0", "VA SWR_MIC0"},
  2189. {"VA SMIC MUX4", "SWR_DMIC1", "VA SWR_MIC1"},
  2190. {"VA SMIC MUX4", "SWR_DMIC2", "VA SWR_MIC2"},
  2191. {"VA SMIC MUX4", "SWR_DMIC3", "VA SWR_MIC3"},
  2192. {"VA SMIC MUX4", "SWR_DMIC4", "VA SWR_MIC4"},
  2193. {"VA SMIC MUX4", "SWR_DMIC5", "VA SWR_MIC5"},
  2194. {"VA SMIC MUX4", "SWR_DMIC6", "VA SWR_MIC6"},
  2195. {"VA SMIC MUX4", "SWR_DMIC7", "VA SWR_MIC7"},
  2196. {"VA DEC5 MUX", "MSM_DMIC", "VA DMIC MUX5"},
  2197. {"VA DMIC MUX5", "DMIC0", "VA DMIC0"},
  2198. {"VA DMIC MUX5", "DMIC1", "VA DMIC1"},
  2199. {"VA DMIC MUX5", "DMIC2", "VA DMIC2"},
  2200. {"VA DMIC MUX5", "DMIC3", "VA DMIC3"},
  2201. {"VA DMIC MUX5", "DMIC4", "VA DMIC4"},
  2202. {"VA DMIC MUX5", "DMIC5", "VA DMIC5"},
  2203. {"VA DMIC MUX5", "DMIC6", "VA DMIC6"},
  2204. {"VA DMIC MUX5", "DMIC7", "VA DMIC7"},
  2205. {"VA DEC5 MUX", "SWR_MIC", "VA SMIC MUX5"},
  2206. {"VA SMIC MUX5", "ADC0", "VA SWR_ADC0"},
  2207. {"VA SMIC MUX5", "ADC1", "VA SWR_ADC1"},
  2208. {"VA SMIC MUX5", "ADC2", "VA SWR_ADC2"},
  2209. {"VA SMIC MUX5", "ADC3", "VA SWR_ADC3"},
  2210. {"VA SMIC MUX5", "SWR_DMIC0", "VA SWR_MIC0"},
  2211. {"VA SMIC MUX5", "SWR_DMIC1", "VA SWR_MIC1"},
  2212. {"VA SMIC MUX5", "SWR_DMIC2", "VA SWR_MIC2"},
  2213. {"VA SMIC MUX5", "SWR_DMIC3", "VA SWR_MIC3"},
  2214. {"VA SMIC MUX5", "SWR_DMIC4", "VA SWR_MIC4"},
  2215. {"VA SMIC MUX5", "SWR_DMIC5", "VA SWR_MIC5"},
  2216. {"VA SMIC MUX5", "SWR_DMIC6", "VA SWR_MIC6"},
  2217. {"VA SMIC MUX5", "SWR_DMIC7", "VA SWR_MIC7"},
  2218. {"VA DEC6 MUX", "MSM_DMIC", "VA DMIC MUX6"},
  2219. {"VA DMIC MUX6", "DMIC0", "VA DMIC0"},
  2220. {"VA DMIC MUX6", "DMIC1", "VA DMIC1"},
  2221. {"VA DMIC MUX6", "DMIC2", "VA DMIC2"},
  2222. {"VA DMIC MUX6", "DMIC3", "VA DMIC3"},
  2223. {"VA DMIC MUX6", "DMIC4", "VA DMIC4"},
  2224. {"VA DMIC MUX6", "DMIC5", "VA DMIC5"},
  2225. {"VA DMIC MUX6", "DMIC6", "VA DMIC6"},
  2226. {"VA DMIC MUX6", "DMIC7", "VA DMIC7"},
  2227. {"VA DEC6 MUX", "SWR_MIC", "VA SMIC MUX6"},
  2228. {"VA SMIC MUX6", "ADC0", "VA SWR_ADC0"},
  2229. {"VA SMIC MUX6", "ADC1", "VA SWR_ADC1"},
  2230. {"VA SMIC MUX6", "ADC2", "VA SWR_ADC2"},
  2231. {"VA SMIC MUX6", "ADC3", "VA SWR_ADC3"},
  2232. {"VA SMIC MUX6", "SWR_DMIC0", "VA SWR_MIC0"},
  2233. {"VA SMIC MUX6", "SWR_DMIC1", "VA SWR_MIC1"},
  2234. {"VA SMIC MUX6", "SWR_DMIC2", "VA SWR_MIC2"},
  2235. {"VA SMIC MUX6", "SWR_DMIC3", "VA SWR_MIC3"},
  2236. {"VA SMIC MUX6", "SWR_DMIC4", "VA SWR_MIC4"},
  2237. {"VA SMIC MUX6", "SWR_DMIC5", "VA SWR_MIC5"},
  2238. {"VA SMIC MUX6", "SWR_DMIC6", "VA SWR_MIC6"},
  2239. {"VA SMIC MUX6", "SWR_DMIC7", "VA SWR_MIC7"},
  2240. {"VA DEC7 MUX", "MSM_DMIC", "VA DMIC MUX7"},
  2241. {"VA DMIC MUX7", "DMIC0", "VA DMIC0"},
  2242. {"VA DMIC MUX7", "DMIC1", "VA DMIC1"},
  2243. {"VA DMIC MUX7", "DMIC2", "VA DMIC2"},
  2244. {"VA DMIC MUX7", "DMIC3", "VA DMIC3"},
  2245. {"VA DMIC MUX7", "DMIC4", "VA DMIC4"},
  2246. {"VA DMIC MUX7", "DMIC5", "VA DMIC5"},
  2247. {"VA DMIC MUX7", "DMIC6", "VA DMIC6"},
  2248. {"VA DMIC MUX7", "DMIC7", "VA DMIC7"},
  2249. {"VA DEC7 MUX", "SWR_MIC", "VA SMIC MUX7"},
  2250. {"VA SMIC MUX7", "ADC0", "VA SWR_ADC0"},
  2251. {"VA SMIC MUX7", "ADC1", "VA SWR_ADC1"},
  2252. {"VA SMIC MUX7", "ADC2", "VA SWR_ADC2"},
  2253. {"VA SMIC MUX7", "ADC3", "VA SWR_ADC3"},
  2254. {"VA SMIC MUX7", "SWR_DMIC0", "VA SWR_MIC0"},
  2255. {"VA SMIC MUX7", "SWR_DMIC1", "VA SWR_MIC1"},
  2256. {"VA SMIC MUX7", "SWR_DMIC2", "VA SWR_MIC2"},
  2257. {"VA SMIC MUX7", "SWR_DMIC3", "VA SWR_MIC3"},
  2258. {"VA SMIC MUX7", "SWR_DMIC4", "VA SWR_MIC4"},
  2259. {"VA SMIC MUX7", "SWR_DMIC5", "VA SWR_MIC5"},
  2260. {"VA SMIC MUX7", "SWR_DMIC6", "VA SWR_MIC6"},
  2261. {"VA SMIC MUX7", "SWR_DMIC7", "VA SWR_MIC7"},
  2262. {"VA SWR_ADC0", NULL, "VA_SWR_PWR"},
  2263. {"VA SWR_ADC1", NULL, "VA_SWR_PWR"},
  2264. {"VA SWR_ADC2", NULL, "VA_SWR_PWR"},
  2265. {"VA SWR_ADC3", NULL, "VA_SWR_PWR"},
  2266. {"VA SWR_MIC0", NULL, "VA_SWR_PWR"},
  2267. {"VA SWR_MIC1", NULL, "VA_SWR_PWR"},
  2268. {"VA SWR_MIC2", NULL, "VA_SWR_PWR"},
  2269. {"VA SWR_MIC3", NULL, "VA_SWR_PWR"},
  2270. {"VA SWR_MIC4", NULL, "VA_SWR_PWR"},
  2271. {"VA SWR_MIC5", NULL, "VA_SWR_PWR"},
  2272. {"VA SWR_MIC6", NULL, "VA_SWR_PWR"},
  2273. {"VA SWR_MIC7", NULL, "VA_SWR_PWR"},
  2274. };
  2275. static const char * const dec_mode_mux_text[] = {
  2276. "ADC_DEFAULT", "ADC_LOW_PWR", "ADC_HIGH_PERF",
  2277. };
  2278. static const struct soc_enum dec_mode_mux_enum =
  2279. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dec_mode_mux_text),
  2280. dec_mode_mux_text);
  2281. static const struct snd_kcontrol_new va_macro_snd_controls[] = {
  2282. SOC_SINGLE_S8_TLV("VA_DEC0 Volume",
  2283. BOLERO_CDC_VA_TX0_TX_VOL_CTL,
  2284. -84, 40, digital_gain),
  2285. SOC_SINGLE_S8_TLV("VA_DEC1 Volume",
  2286. BOLERO_CDC_VA_TX1_TX_VOL_CTL,
  2287. -84, 40, digital_gain),
  2288. SOC_SINGLE_S8_TLV("VA_DEC2 Volume",
  2289. BOLERO_CDC_VA_TX2_TX_VOL_CTL,
  2290. -84, 40, digital_gain),
  2291. SOC_SINGLE_S8_TLV("VA_DEC3 Volume",
  2292. BOLERO_CDC_VA_TX3_TX_VOL_CTL,
  2293. -84, 40, digital_gain),
  2294. SOC_SINGLE_S8_TLV("VA_DEC4 Volume",
  2295. BOLERO_CDC_VA_TX4_TX_VOL_CTL,
  2296. -84, 40, digital_gain),
  2297. SOC_SINGLE_S8_TLV("VA_DEC5 Volume",
  2298. BOLERO_CDC_VA_TX5_TX_VOL_CTL,
  2299. -84, 40, digital_gain),
  2300. SOC_SINGLE_S8_TLV("VA_DEC6 Volume",
  2301. BOLERO_CDC_VA_TX6_TX_VOL_CTL,
  2302. -84, 40, digital_gain),
  2303. SOC_SINGLE_S8_TLV("VA_DEC7 Volume",
  2304. BOLERO_CDC_VA_TX7_TX_VOL_CTL,
  2305. -84, 40, digital_gain),
  2306. SOC_SINGLE_EXT("LPI Enable", 0, 0, 1, 0,
  2307. va_macro_lpi_get, va_macro_lpi_put),
  2308. SOC_ENUM_EXT("VA_DEC0 MODE", dec_mode_mux_enum,
  2309. va_macro_dec_mode_get, va_macro_dec_mode_put),
  2310. SOC_ENUM_EXT("VA_DEC1 MODE", dec_mode_mux_enum,
  2311. va_macro_dec_mode_get, va_macro_dec_mode_put),
  2312. SOC_ENUM_EXT("VA_DEC2 MODE", dec_mode_mux_enum,
  2313. va_macro_dec_mode_get, va_macro_dec_mode_put),
  2314. SOC_ENUM_EXT("VA_DEC3 MODE", dec_mode_mux_enum,
  2315. va_macro_dec_mode_get, va_macro_dec_mode_put),
  2316. };
  2317. static const struct snd_kcontrol_new va_macro_snd_controls_common[] = {
  2318. SOC_SINGLE_S8_TLV("VA_DEC0 Volume",
  2319. BOLERO_CDC_VA_TX0_TX_VOL_CTL,
  2320. -84, 40, digital_gain),
  2321. SOC_SINGLE_S8_TLV("VA_DEC1 Volume",
  2322. BOLERO_CDC_VA_TX1_TX_VOL_CTL,
  2323. -84, 40, digital_gain),
  2324. SOC_SINGLE_EXT("LPI Enable", 0, 0, 1, 0,
  2325. va_macro_lpi_get, va_macro_lpi_put),
  2326. };
  2327. static const struct snd_kcontrol_new va_macro_snd_controls_v3[] = {
  2328. SOC_SINGLE_S8_TLV("VA_DEC2 Volume",
  2329. BOLERO_CDC_VA_TX2_TX_VOL_CTL,
  2330. -84, 40, digital_gain),
  2331. SOC_SINGLE_S8_TLV("VA_DEC3 Volume",
  2332. BOLERO_CDC_VA_TX3_TX_VOL_CTL,
  2333. -84, 40, digital_gain),
  2334. };
  2335. static int va_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  2336. struct va_macro_priv *va_priv)
  2337. {
  2338. u32 div_factor;
  2339. u32 mclk_rate = VA_MACRO_MCLK_FREQ;
  2340. if (dmic_sample_rate == VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  2341. mclk_rate % dmic_sample_rate != 0)
  2342. goto undefined_rate;
  2343. div_factor = mclk_rate / dmic_sample_rate;
  2344. switch (div_factor) {
  2345. case 2:
  2346. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_2;
  2347. break;
  2348. case 3:
  2349. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_3;
  2350. break;
  2351. case 4:
  2352. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_4;
  2353. break;
  2354. case 6:
  2355. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_6;
  2356. break;
  2357. case 8:
  2358. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_8;
  2359. break;
  2360. case 16:
  2361. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_16;
  2362. break;
  2363. default:
  2364. /* Any other DIV factor is invalid */
  2365. goto undefined_rate;
  2366. }
  2367. /* Valid dmic DIV factors */
  2368. dev_dbg(va_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  2369. __func__, div_factor, mclk_rate);
  2370. return dmic_sample_rate;
  2371. undefined_rate:
  2372. dev_dbg(va_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  2373. __func__, dmic_sample_rate, mclk_rate);
  2374. dmic_sample_rate = VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  2375. return dmic_sample_rate;
  2376. }
  2377. static int va_macro_init(struct snd_soc_component *component)
  2378. {
  2379. struct snd_soc_dapm_context *dapm =
  2380. snd_soc_component_get_dapm(component);
  2381. int ret, i;
  2382. struct device *va_dev = NULL;
  2383. struct va_macro_priv *va_priv = NULL;
  2384. va_dev = bolero_get_device_ptr(component->dev, VA_MACRO);
  2385. if (!va_dev) {
  2386. dev_err(component->dev,
  2387. "%s: null device for macro!\n", __func__);
  2388. return -EINVAL;
  2389. }
  2390. va_priv = dev_get_drvdata(va_dev);
  2391. if (!va_priv) {
  2392. dev_err(component->dev,
  2393. "%s: priv is null for macro!\n", __func__);
  2394. return -EINVAL;
  2395. }
  2396. va_priv->lpi_enable = false;
  2397. va_priv->register_event_listener = false;
  2398. if (va_priv->va_without_decimation) {
  2399. ret = snd_soc_dapm_new_controls(dapm, va_macro_wod_dapm_widgets,
  2400. ARRAY_SIZE(va_macro_wod_dapm_widgets));
  2401. if (ret < 0) {
  2402. dev_err(va_dev,
  2403. "%s: Failed to add without dec controls\n",
  2404. __func__);
  2405. return ret;
  2406. }
  2407. va_priv->component = component;
  2408. return 0;
  2409. }
  2410. va_priv->version = bolero_get_version(va_dev);
  2411. if (va_priv->version >= BOLERO_VERSION_2_0) {
  2412. ret = snd_soc_dapm_new_controls(dapm,
  2413. va_macro_dapm_widgets_common,
  2414. ARRAY_SIZE(va_macro_dapm_widgets_common));
  2415. if (ret < 0) {
  2416. dev_err(va_dev, "%s: Failed to add controls\n",
  2417. __func__);
  2418. return ret;
  2419. }
  2420. if (va_priv->version == BOLERO_VERSION_2_1)
  2421. ret = snd_soc_dapm_new_controls(dapm,
  2422. va_macro_dapm_widgets_v2,
  2423. ARRAY_SIZE(va_macro_dapm_widgets_v2));
  2424. else if (va_priv->version == BOLERO_VERSION_2_0)
  2425. ret = snd_soc_dapm_new_controls(dapm,
  2426. va_macro_dapm_widgets_v3,
  2427. ARRAY_SIZE(va_macro_dapm_widgets_v3));
  2428. if (ret < 0) {
  2429. dev_err(va_dev, "%s: Failed to add controls\n",
  2430. __func__);
  2431. return ret;
  2432. }
  2433. } else {
  2434. ret = snd_soc_dapm_new_controls(dapm, va_macro_dapm_widgets,
  2435. ARRAY_SIZE(va_macro_dapm_widgets));
  2436. if (ret < 0) {
  2437. dev_err(va_dev, "%s: Failed to add controls\n",
  2438. __func__);
  2439. return ret;
  2440. }
  2441. }
  2442. if (va_priv->version >= BOLERO_VERSION_2_0) {
  2443. ret = snd_soc_dapm_add_routes(dapm,
  2444. va_audio_map_common,
  2445. ARRAY_SIZE(va_audio_map_common));
  2446. if (ret < 0) {
  2447. dev_err(va_dev, "%s: Failed to add routes\n",
  2448. __func__);
  2449. return ret;
  2450. }
  2451. if (va_priv->version == BOLERO_VERSION_2_0) {
  2452. ret = snd_soc_dapm_add_routes(dapm,
  2453. va_audio_map_v3,
  2454. ARRAY_SIZE(va_audio_map_v3));
  2455. if (ret < 0) {
  2456. dev_err(va_dev, "%s: Failed to add routes\n",
  2457. __func__);
  2458. return ret;
  2459. }
  2460. }
  2461. if (va_priv->version == BOLERO_VERSION_2_1) {
  2462. ret = snd_soc_dapm_add_routes(dapm,
  2463. va_audio_map_v2,
  2464. ARRAY_SIZE(va_audio_map_v2));
  2465. if (ret < 0) {
  2466. dev_err(va_dev, "%s: Failed to add routes\n",
  2467. __func__);
  2468. return ret;
  2469. }
  2470. }
  2471. } else {
  2472. ret = snd_soc_dapm_add_routes(dapm, va_audio_map,
  2473. ARRAY_SIZE(va_audio_map));
  2474. if (ret < 0) {
  2475. dev_err(va_dev, "%s: Failed to add routes\n",
  2476. __func__);
  2477. return ret;
  2478. }
  2479. }
  2480. ret = snd_soc_dapm_new_widgets(dapm->card);
  2481. if (ret < 0) {
  2482. dev_err(va_dev, "%s: Failed to add widgets\n", __func__);
  2483. return ret;
  2484. }
  2485. if (va_priv->version >= BOLERO_VERSION_2_0) {
  2486. ret = snd_soc_add_component_controls(component,
  2487. va_macro_snd_controls_common,
  2488. ARRAY_SIZE(va_macro_snd_controls_common));
  2489. if (ret < 0) {
  2490. dev_err(va_dev, "%s: Failed to add snd_ctls\n",
  2491. __func__);
  2492. return ret;
  2493. }
  2494. if (va_priv->version == BOLERO_VERSION_2_0)
  2495. ret = snd_soc_add_component_controls(component,
  2496. va_macro_snd_controls_v3,
  2497. ARRAY_SIZE(va_macro_snd_controls_v3));
  2498. if (ret < 0) {
  2499. dev_err(va_dev, "%s: Failed to add snd_ctls\n",
  2500. __func__);
  2501. return ret;
  2502. }
  2503. } else {
  2504. ret = snd_soc_add_component_controls(component,
  2505. va_macro_snd_controls,
  2506. ARRAY_SIZE(va_macro_snd_controls));
  2507. if (ret < 0) {
  2508. dev_err(va_dev, "%s: Failed to add snd_ctls\n",
  2509. __func__);
  2510. return ret;
  2511. }
  2512. }
  2513. snd_soc_dapm_ignore_suspend(dapm, "VA_AIF1 Capture");
  2514. snd_soc_dapm_ignore_suspend(dapm, "VA_AIF2 Capture");
  2515. snd_soc_dapm_ignore_suspend(dapm, "VA_AIF3 Capture");
  2516. if (va_priv->version >= BOLERO_VERSION_2_0) {
  2517. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_INPUT");
  2518. } else {
  2519. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC0");
  2520. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC1");
  2521. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC2");
  2522. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC3");
  2523. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC0");
  2524. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC1");
  2525. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC2");
  2526. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC3");
  2527. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC4");
  2528. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC5");
  2529. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC6");
  2530. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC7");
  2531. }
  2532. snd_soc_dapm_sync(dapm);
  2533. for (i = 0; i < VA_MACRO_NUM_DECIMATORS; i++) {
  2534. va_priv->va_hpf_work[i].va_priv = va_priv;
  2535. va_priv->va_hpf_work[i].decimator = i;
  2536. INIT_DELAYED_WORK(&va_priv->va_hpf_work[i].dwork,
  2537. va_macro_tx_hpf_corner_freq_callback);
  2538. }
  2539. for (i = 0; i < VA_MACRO_NUM_DECIMATORS; i++) {
  2540. va_priv->va_mute_dwork[i].va_priv = va_priv;
  2541. va_priv->va_mute_dwork[i].decimator = i;
  2542. INIT_DELAYED_WORK(&va_priv->va_mute_dwork[i].dwork,
  2543. va_macro_mute_update_callback);
  2544. }
  2545. va_priv->component = component;
  2546. if (va_priv->version == BOLERO_VERSION_2_1) {
  2547. snd_soc_component_update_bits(component,
  2548. BOLERO_CDC_VA_TOP_CSR_SWR_MIC_CTL0, 0xEE, 0xCC);
  2549. snd_soc_component_update_bits(component,
  2550. BOLERO_CDC_VA_TOP_CSR_SWR_MIC_CTL1, 0xEE, 0xCC);
  2551. snd_soc_component_update_bits(component,
  2552. BOLERO_CDC_VA_TOP_CSR_SWR_MIC_CTL2, 0xEE, 0xCC);
  2553. }
  2554. return 0;
  2555. }
  2556. static int va_macro_deinit(struct snd_soc_component *component)
  2557. {
  2558. struct device *va_dev = NULL;
  2559. struct va_macro_priv *va_priv = NULL;
  2560. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  2561. return -EINVAL;
  2562. va_priv->component = NULL;
  2563. return 0;
  2564. }
  2565. static void va_macro_add_child_devices(struct work_struct *work)
  2566. {
  2567. struct va_macro_priv *va_priv = NULL;
  2568. struct platform_device *pdev = NULL;
  2569. struct device_node *node = NULL;
  2570. struct va_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  2571. int ret = 0;
  2572. u16 count = 0, ctrl_num = 0;
  2573. struct va_macro_swr_ctrl_platform_data *platdata = NULL;
  2574. char plat_dev_name[VA_MACRO_SWR_STRING_LEN] = "";
  2575. bool va_swr_master_node = false;
  2576. va_priv = container_of(work, struct va_macro_priv,
  2577. va_macro_add_child_devices_work);
  2578. if (!va_priv) {
  2579. pr_err("%s: Memory for va_priv does not exist\n",
  2580. __func__);
  2581. return;
  2582. }
  2583. if (!va_priv->dev) {
  2584. pr_err("%s: VA dev does not exist\n", __func__);
  2585. return;
  2586. }
  2587. if (!va_priv->dev->of_node) {
  2588. dev_err(va_priv->dev,
  2589. "%s: DT node for va_priv does not exist\n", __func__);
  2590. return;
  2591. }
  2592. platdata = &va_priv->swr_plat_data;
  2593. va_priv->child_count = 0;
  2594. for_each_available_child_of_node(va_priv->dev->of_node, node) {
  2595. va_swr_master_node = false;
  2596. if (strnstr(node->name, "va_swr_master",
  2597. strlen("va_swr_master")) != NULL)
  2598. va_swr_master_node = true;
  2599. if (va_swr_master_node)
  2600. strlcpy(plat_dev_name, "va_swr_ctrl",
  2601. (VA_MACRO_SWR_STRING_LEN - 1));
  2602. else
  2603. strlcpy(plat_dev_name, node->name,
  2604. (VA_MACRO_SWR_STRING_LEN - 1));
  2605. pdev = platform_device_alloc(plat_dev_name, -1);
  2606. if (!pdev) {
  2607. dev_err(va_priv->dev, "%s: pdev memory alloc failed\n",
  2608. __func__);
  2609. ret = -ENOMEM;
  2610. goto err;
  2611. }
  2612. pdev->dev.parent = va_priv->dev;
  2613. pdev->dev.of_node = node;
  2614. if (va_swr_master_node) {
  2615. ret = platform_device_add_data(pdev, platdata,
  2616. sizeof(*platdata));
  2617. if (ret) {
  2618. dev_err(&pdev->dev,
  2619. "%s: cannot add plat data ctrl:%d\n",
  2620. __func__, ctrl_num);
  2621. goto fail_pdev_add;
  2622. }
  2623. }
  2624. ret = platform_device_add(pdev);
  2625. if (ret) {
  2626. dev_err(&pdev->dev,
  2627. "%s: Cannot add platform device\n",
  2628. __func__);
  2629. goto fail_pdev_add;
  2630. }
  2631. if (va_swr_master_node) {
  2632. temp = krealloc(swr_ctrl_data,
  2633. (ctrl_num + 1) * sizeof(
  2634. struct va_macro_swr_ctrl_data),
  2635. GFP_KERNEL);
  2636. if (!temp) {
  2637. ret = -ENOMEM;
  2638. goto fail_pdev_add;
  2639. }
  2640. swr_ctrl_data = temp;
  2641. swr_ctrl_data[ctrl_num].va_swr_pdev = pdev;
  2642. ctrl_num++;
  2643. dev_dbg(&pdev->dev,
  2644. "%s: Added soundwire ctrl device(s)\n",
  2645. __func__);
  2646. va_priv->swr_ctrl_data = swr_ctrl_data;
  2647. }
  2648. if (va_priv->child_count < VA_MACRO_CHILD_DEVICES_MAX)
  2649. va_priv->pdev_child_devices[
  2650. va_priv->child_count++] = pdev;
  2651. else
  2652. goto err;
  2653. }
  2654. return;
  2655. fail_pdev_add:
  2656. for (count = 0; count < va_priv->child_count; count++)
  2657. platform_device_put(va_priv->pdev_child_devices[count]);
  2658. err:
  2659. return;
  2660. }
  2661. static int va_macro_set_port_map(struct snd_soc_component *component,
  2662. u32 usecase, u32 size, void *data)
  2663. {
  2664. struct device *va_dev = NULL;
  2665. struct va_macro_priv *va_priv = NULL;
  2666. struct swrm_port_config port_cfg;
  2667. int ret = 0;
  2668. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  2669. return -EINVAL;
  2670. memset(&port_cfg, 0, sizeof(port_cfg));
  2671. port_cfg.uc = usecase;
  2672. port_cfg.size = size;
  2673. port_cfg.params = data;
  2674. if (va_priv->swr_ctrl_data)
  2675. ret = swrm_wcd_notify(
  2676. va_priv->swr_ctrl_data[0].va_swr_pdev,
  2677. SWR_SET_PORT_MAP, &port_cfg);
  2678. return ret;
  2679. }
  2680. static int va_macro_reg_wake_irq(struct snd_soc_component *component,
  2681. u32 data)
  2682. {
  2683. struct device *va_dev = NULL;
  2684. struct va_macro_priv *va_priv = NULL;
  2685. u32 ipc_wakeup = data;
  2686. int ret = 0;
  2687. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  2688. return -EINVAL;
  2689. if (va_priv->swr_ctrl_data)
  2690. ret = swrm_wcd_notify(
  2691. va_priv->swr_ctrl_data[0].va_swr_pdev,
  2692. SWR_REGISTER_WAKE_IRQ, &ipc_wakeup);
  2693. return ret;
  2694. }
  2695. static void va_macro_init_ops(struct macro_ops *ops,
  2696. char __iomem *va_io_base,
  2697. bool va_without_decimation)
  2698. {
  2699. memset(ops, 0, sizeof(struct macro_ops));
  2700. if (!va_without_decimation) {
  2701. ops->dai_ptr = va_macro_dai;
  2702. ops->num_dais = ARRAY_SIZE(va_macro_dai);
  2703. } else {
  2704. ops->dai_ptr = NULL;
  2705. ops->num_dais = 0;
  2706. }
  2707. ops->init = va_macro_init;
  2708. ops->exit = va_macro_deinit;
  2709. ops->io_base = va_io_base;
  2710. ops->event_handler = va_macro_event_handler;
  2711. ops->set_port_map = va_macro_set_port_map;
  2712. ops->reg_wake_irq = va_macro_reg_wake_irq;
  2713. ops->clk_div_get = va_macro_clk_div_get;
  2714. }
  2715. static int va_macro_probe(struct platform_device *pdev)
  2716. {
  2717. struct macro_ops ops;
  2718. struct va_macro_priv *va_priv;
  2719. u32 va_base_addr, sample_rate = 0;
  2720. char __iomem *va_io_base;
  2721. bool va_without_decimation = false;
  2722. const char *micb_supply_str = "va-vdd-micb-supply";
  2723. const char *micb_supply_str1 = "va-vdd-micb";
  2724. const char *micb_voltage_str = "qcom,va-vdd-micb-voltage";
  2725. const char *micb_current_str = "qcom,va-vdd-micb-current";
  2726. int ret = 0;
  2727. const char *dmic_sample_rate = "qcom,va-dmic-sample-rate";
  2728. u32 default_clk_id = 0;
  2729. struct clk *lpass_audio_hw_vote = NULL;
  2730. u32 is_used_va_swr_gpio = 0;
  2731. const char *is_used_va_swr_gpio_dt = "qcom,is-used-swr-gpio";
  2732. va_priv = devm_kzalloc(&pdev->dev, sizeof(struct va_macro_priv),
  2733. GFP_KERNEL);
  2734. if (!va_priv)
  2735. return -ENOMEM;
  2736. va_priv->dev = &pdev->dev;
  2737. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2738. &va_base_addr);
  2739. if (ret) {
  2740. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2741. __func__, "reg");
  2742. return ret;
  2743. }
  2744. va_without_decimation = of_property_read_bool(pdev->dev.parent->of_node,
  2745. "qcom,va-without-decimation");
  2746. va_priv->va_without_decimation = va_without_decimation;
  2747. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  2748. &sample_rate);
  2749. if (ret) {
  2750. dev_err(&pdev->dev, "%s: could not find %d entry in dt\n",
  2751. __func__, sample_rate);
  2752. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_2;
  2753. } else {
  2754. if (va_macro_validate_dmic_sample_rate(
  2755. sample_rate, va_priv) == VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  2756. return -EINVAL;
  2757. }
  2758. if (of_find_property(pdev->dev.of_node, is_used_va_swr_gpio_dt,
  2759. NULL)) {
  2760. ret = of_property_read_u32(pdev->dev.of_node,
  2761. is_used_va_swr_gpio_dt,
  2762. &is_used_va_swr_gpio);
  2763. if (ret) {
  2764. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  2765. __func__, is_used_va_swr_gpio_dt);
  2766. is_used_va_swr_gpio = 0;
  2767. }
  2768. }
  2769. va_priv->va_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2770. "qcom,va-swr-gpios", 0);
  2771. if (!va_priv->va_swr_gpio_p && is_used_va_swr_gpio) {
  2772. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2773. __func__);
  2774. return -EINVAL;
  2775. }
  2776. if ((msm_cdc_pinctrl_get_state(va_priv->va_swr_gpio_p) < 0) &&
  2777. is_used_va_swr_gpio) {
  2778. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  2779. __func__);
  2780. return -EPROBE_DEFER;
  2781. }
  2782. va_io_base = devm_ioremap(&pdev->dev, va_base_addr,
  2783. VA_MACRO_MAX_OFFSET);
  2784. if (!va_io_base) {
  2785. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2786. return -EINVAL;
  2787. }
  2788. va_priv->va_io_base = va_io_base;
  2789. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  2790. if (IS_ERR(lpass_audio_hw_vote)) {
  2791. ret = PTR_ERR(lpass_audio_hw_vote);
  2792. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  2793. __func__, "lpass_audio_hw_vote", ret);
  2794. lpass_audio_hw_vote = NULL;
  2795. ret = 0;
  2796. }
  2797. va_priv->lpass_audio_hw_vote = lpass_audio_hw_vote;
  2798. if (of_parse_phandle(pdev->dev.of_node, micb_supply_str, 0)) {
  2799. va_priv->micb_supply = devm_regulator_get(&pdev->dev,
  2800. micb_supply_str1);
  2801. if (IS_ERR(va_priv->micb_supply)) {
  2802. ret = PTR_ERR(va_priv->micb_supply);
  2803. dev_err(&pdev->dev,
  2804. "%s:Failed to get micbias supply for VA Mic %d\n",
  2805. __func__, ret);
  2806. return ret;
  2807. }
  2808. ret = of_property_read_u32(pdev->dev.of_node,
  2809. micb_voltage_str,
  2810. &va_priv->micb_voltage);
  2811. if (ret) {
  2812. dev_err(&pdev->dev,
  2813. "%s:Looking up %s property in node %s failed\n",
  2814. __func__, micb_voltage_str,
  2815. pdev->dev.of_node->full_name);
  2816. return ret;
  2817. }
  2818. ret = of_property_read_u32(pdev->dev.of_node,
  2819. micb_current_str,
  2820. &va_priv->micb_current);
  2821. if (ret) {
  2822. dev_err(&pdev->dev,
  2823. "%s:Looking up %s property in node %s failed\n",
  2824. __func__, micb_current_str,
  2825. pdev->dev.of_node->full_name);
  2826. return ret;
  2827. }
  2828. }
  2829. ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
  2830. &default_clk_id);
  2831. if (ret) {
  2832. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2833. __func__, "qcom,default-clk-id");
  2834. default_clk_id = VA_CORE_CLK;
  2835. }
  2836. va_priv->clk_id = VA_CORE_CLK;
  2837. va_priv->default_clk_id = default_clk_id;
  2838. va_priv->current_clk_id = TX_CORE_CLK;
  2839. if (is_used_va_swr_gpio) {
  2840. va_priv->reset_swr = true;
  2841. INIT_WORK(&va_priv->va_macro_add_child_devices_work,
  2842. va_macro_add_child_devices);
  2843. va_priv->swr_plat_data.handle = (void *) va_priv;
  2844. va_priv->swr_plat_data.read = NULL;
  2845. va_priv->swr_plat_data.write = NULL;
  2846. va_priv->swr_plat_data.bulk_write = NULL;
  2847. va_priv->swr_plat_data.clk = va_macro_swrm_clock;
  2848. va_priv->swr_plat_data.core_vote = va_macro_core_vote;
  2849. va_priv->swr_plat_data.handle_irq = NULL;
  2850. mutex_init(&va_priv->swr_clk_lock);
  2851. }
  2852. va_priv->is_used_va_swr_gpio = is_used_va_swr_gpio;
  2853. mutex_init(&va_priv->mclk_lock);
  2854. dev_set_drvdata(&pdev->dev, va_priv);
  2855. va_macro_init_ops(&ops, va_io_base, va_without_decimation);
  2856. ops.clk_id_req = va_priv->default_clk_id;
  2857. ops.default_clk_id = va_priv->default_clk_id;
  2858. ret = bolero_register_macro(&pdev->dev, VA_MACRO, &ops);
  2859. if (ret < 0) {
  2860. dev_err(&pdev->dev, "%s: register macro failed\n", __func__);
  2861. goto reg_macro_fail;
  2862. }
  2863. pm_runtime_set_autosuspend_delay(&pdev->dev, VA_AUTO_SUSPEND_DELAY);
  2864. pm_runtime_use_autosuspend(&pdev->dev);
  2865. pm_runtime_set_suspended(&pdev->dev);
  2866. pm_suspend_ignore_children(&pdev->dev, true);
  2867. pm_runtime_enable(&pdev->dev);
  2868. if (is_used_va_swr_gpio)
  2869. schedule_work(&va_priv->va_macro_add_child_devices_work);
  2870. return ret;
  2871. reg_macro_fail:
  2872. mutex_destroy(&va_priv->mclk_lock);
  2873. if (is_used_va_swr_gpio)
  2874. mutex_destroy(&va_priv->swr_clk_lock);
  2875. return ret;
  2876. }
  2877. static int va_macro_remove(struct platform_device *pdev)
  2878. {
  2879. struct va_macro_priv *va_priv;
  2880. int count = 0;
  2881. va_priv = dev_get_drvdata(&pdev->dev);
  2882. if (!va_priv)
  2883. return -EINVAL;
  2884. if (va_priv->is_used_va_swr_gpio) {
  2885. if (va_priv->swr_ctrl_data)
  2886. kfree(va_priv->swr_ctrl_data);
  2887. for (count = 0; count < va_priv->child_count &&
  2888. count < VA_MACRO_CHILD_DEVICES_MAX; count++)
  2889. platform_device_unregister(
  2890. va_priv->pdev_child_devices[count]);
  2891. }
  2892. pm_runtime_disable(&pdev->dev);
  2893. pm_runtime_set_suspended(&pdev->dev);
  2894. bolero_unregister_macro(&pdev->dev, VA_MACRO);
  2895. mutex_destroy(&va_priv->mclk_lock);
  2896. if (va_priv->is_used_va_swr_gpio)
  2897. mutex_destroy(&va_priv->swr_clk_lock);
  2898. return 0;
  2899. }
  2900. static const struct of_device_id va_macro_dt_match[] = {
  2901. {.compatible = "qcom,va-macro"},
  2902. {}
  2903. };
  2904. static const struct dev_pm_ops bolero_dev_pm_ops = {
  2905. SET_SYSTEM_SLEEP_PM_OPS(
  2906. pm_runtime_force_suspend,
  2907. pm_runtime_force_resume
  2908. )
  2909. SET_RUNTIME_PM_OPS(
  2910. bolero_runtime_suspend,
  2911. bolero_runtime_resume,
  2912. NULL
  2913. )
  2914. };
  2915. static struct platform_driver va_macro_driver = {
  2916. .driver = {
  2917. .name = "va_macro",
  2918. .owner = THIS_MODULE,
  2919. .pm = &bolero_dev_pm_ops,
  2920. .of_match_table = va_macro_dt_match,
  2921. .suppress_bind_attrs = true,
  2922. },
  2923. .probe = va_macro_probe,
  2924. .remove = va_macro_remove,
  2925. };
  2926. module_platform_driver(va_macro_driver);
  2927. MODULE_DESCRIPTION("VA macro driver");
  2928. MODULE_LICENSE("GPL v2");