va-macro.c 90 KB

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