va-macro.c 98 KB

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