va-macro.c 98 KB

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