va-macro.c 99 KB

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