va-macro.c 98 KB

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