va-macro.c 89 KB

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