va-macro.c 89 KB

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