va-macro.c 96 KB

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