va-macro.c 93 KB

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