va-macro.c 98 KB

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